Package: trash-cli
Version: 0.17.1.14-3
Severity: normal
Tags: patch upstream
Forwarded: https://github.com/andreafrancia/trash-cli/pull/170

Doesn't look like trash-cli was really ready for Python 3 :)

It fails on big-endian architectures with:

| $ trash-list
| Traceback (most recent call last):
|   File "/usr/bin/trash-list", line 5, in <module>
|     sys.exit(main())
|   File "/usr/lib/python3/dist-packages/trashcli/cmds.py", line 45, in list
|     ListCmd(
|   File "/usr/lib/python3/dist-packages/trashcli/list.py", line 37, in run
|     parse(argv)
|   File "/usr/lib/python3/dist-packages/trashcli/trash.py", line 110, in 
__call__
|     self.default_action()
|   File "/usr/lib/python3/dist-packages/trashcli/list.py", line 51, in 
list_trash
|     trashdirs.list_trashdirs()
|   File "/usr/lib/python3/dist-packages/trashcli/trash.py", line 151, in 
list_trashdirs
|     self._for_each_volume_trashcan()
|   File "/usr/lib/python3/dist-packages/trashcli/trash.py", line 157, in 
_for_each_volume_trashcan
|     for volume in self.mount_points():
|   File "/usr/lib/python3/dist-packages/trashcli/list_mount_points.py", line 
5, in mount_points
|     return list(mount_points_from_getmnt())
|   File "/usr/lib/python3/dist-packages/trashcli/list_mount_points.py", line 
10, in mount_points_from_getmnt
|     for elem in _mounted_filesystems_from_getmnt():
|   File "/usr/lib/python3/dist-packages/trashcli/list_mount_points.py", line 
67, in _mounted_filesystems_from_getmnt
|     raise IOError("Unable to open /proc/mounts nor /etc/mtab")
| OSError: Unable to open /proc/mounts nor /etc/mtab

That seems to be be caused by passing a unicode string as an argument to
ctypes, under Python 3.

On little-endian architectures, I think an empty list was returned from
mount_points() most of the time.

Patch attached.

SR
From 0a54191a51bbf78bbcadacc26b3a5c760aadc879 Mon Sep 17 00:00:00 2001
From: Stefano Rivera <stef...@rivera.za.net>
Date: Wed, 13 May 2020 18:43:21 -0700
Subject: [PATCH] Python 3 compatibility in list_mount_points

ctypes requires byte strings for arguments and return values.

This will return unicode strings under Python 2. But that's EoL now.
---
 trashcli/list_mount_points.py | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/trashcli/list_mount_points.py b/trashcli/list_mount_points.py
index f0f9cb8..a757b8d 100644
--- a/trashcli/list_mount_points.py
+++ b/trashcli/list_mount_points.py
@@ -60,17 +60,20 @@ def _mounted_filesystems_from_getmnt() :
     libc.fopen.restype = c_void_p
     libc.fclose.argtypes = [c_void_p]
 
-    f = libc.fopen("/proc/mounts", "r")
+    f = libc.fopen(b"/proc/mounts", "r")
     if f==None:
-        f = libc.fopen("/etc/mtab", "r")
+        f = libc.fopen(b"/etc/mtab", "r")
         if f == None:
             raise IOError("Unable to open /proc/mounts nor /etc/mtab")
 
+    fse = sys.getfilesystemencoding()
+
     while True:
         entry = libc.getmntent(f)
         if bool(entry) == False:
             libc.fclose(f)
             break
-        yield Filesystem(entry.contents.mnt_dir,
-                         entry.contents.mnt_type,
-                         entry.contents.mnt_fsname)
+        yield Filesystem(
+            entry.contents.mnt_dir.decode(fse, 'surrogateescape'),
+            entry.contents.mnt_type.decode('ascii'),
+            entry.contents.mnt_fsname.decode(fse, 'surrogateescape'))
-- 
2.26.2

Reply via email to