andreafrancia / trash-cli

Command line interface to the freedesktop.org trashcan.
GNU General Public License v2.0
3.59k stars 178 forks source link

Permission denied: '/proc/filesystems' on Termux #348

Open mizzunet opened 3 weeks ago

mizzunet commented 3 weeks ago

Describe the bug trash-empty fails to run with following on Termux(Android 14)

Traceback (most recent call last):
  File "/data/data/com.termux/files/usr/bin/trash-empty", line 5, in <module>
    sys.exit(main())
             ^^^^^^
  File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/trashcli/empty/main.py", line 35, in main
    return empty_cmd.run_cmd(sys.argv[1:], os.environ, os.getuid())
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/trashcli/empty/empty_cmd.py", line 75, in run_cmd
    return self.empty_action.run_action(args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/trashcli/empty/empty_action.py", line 68, in run_action
    delete_pass = self.guard.ask_the_user(args.interactive,
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/trashcli/empty/guard.py", line 21, in ask_the_user
    return self._interactive(trash_dirs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/trashcli/empty/guard.py", line 27, in _interactive
    trash_dirs_list = list(trash_dirs)  # type: Iterable[TrashDir]
                      ^^^^^^^^^^^^^^^^
  File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/trashcli/list/trash_dir_selector.py", line 33, in select
    for dir in self.current_user_dirs.scan_trash_dirs(environ, uid):
  File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/trashcli/trash_dirs_scanner.py", line 81, in scan_trash_dirs
    for volume in self.volumes_listing.list_volumes(environ):
  File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/trashcli/fstab/mount_points_listing.py", line 47, in os_mount_points
    fstypes += set([p.fstype for p in psutil.disk_partitions()])
                                      ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/psutil/__init__.py", line 2052, in disk_partitions
    return _psplatform.disk_partitions(all)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/psutil/_pslinux.py", line 1338, in disk_partitions
    with open_text("%s/filesystems" % procfs_path) as f:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/psutil/_common.py", line 813, in open_text
    fobj = open(
           ^^^^^
PermissionError: [Errno 13] Permission denied: '/proc/filesystems'

trash-cli version 0.24.5.26

Are you using the latest version of trash-cli? Yes

Operating system:

$ trash-empty

Expected behavior Run command and empty trays directory

Volumes detail Seems trash-list --debug-volumes too has the same error

Traceback (most recent call last):
  File "/data/data/com.termux/files/usr/bin/trash-list", line 5, in <module>
    sys.exit(main())
             ^^^^^^
  File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/trashcli/list/main.py", line 41, in main
    ).run(sys.argv)
      ^^^^^^^^^^^^^
  File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/trashcli/list/main.py", line 92, in run
    action.run_action(args)
  File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/trashcli/list/minor_actions/debug_volumes.py", line 16, in run_action
    physical = sorted([p for p in psutil.disk_partitions()],
                                  ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/psutil/__init__.py", line 2052, in disk_partitions
    return _psplatform.disk_partitions(all)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/psutil/_pslinux.py", line 1338, in disk_partitions
    with open_text("%s/filesystems" % procfs_path) as f:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/psutil/_common.py", line 813, in open_text
    fobj = open(
           ^^^^^
PermissionError: [Errno 13] Permission denied: '/proc/filesystems'
andreafrancia commented 3 weeks ago

This seem be caused by this issue of psutil https://github.com/giampaolo/psutil/issues/2191

I need help for this problem from someone that has access to an Termux PRoot Ubuntu installation and knows how it work.

A possible workaround is to add a flag in trash-empty to disable the search of partitions:

$ trash-empty --current-volume-only

@mizzunet Thank you for your detailed submission! @mizzunet can you please send me the output of the command "df" on your Termux system?

mizzunet commented 3 weeks ago

$ trash-empty --current-volume-only

I'm afraid this one doesn't work either

...
 trash-empty: error: unrecognized arguments: --current-volume-only

So is trash-list

"df" on your Termux system?

Filesystem        1K-blocks     Used Available Use% Mounted on
/dev/block/dm-8      830984   828468         0 100% /
tmpfs               2852040     1576   2850464   1% /dev
tmpfs               2852040        0   2852040   0% /mnt
/dev/block/dm-9      313240   312288         0 100% /system_ext
/dev/block/dm-10     621844   619940         0 100% /vendor
/dev/block/dm-11    2496876  2489324         0 100% /product
tmpfs               2852040       56   2851984   1% /apex
/dev/block/dm-38      51656    51612         0 100% /apex/com.android.art@341913000
/dev/block/dm-40        776      748        12  99% /apex/com.android.ipsec@341611000
/dev/block/dm-37      18804    18772         0 100% /apex/com.android.permission@341810000
/dev/block/dm-36       4000     3972         0 100% /apex/com.android.resolv@341810000
/dev/block/loop10      7868     7832         0 100% /apex/com.android.runtime@1
/dev/block/loop8       1616     1588         0 100% /apex/com.google.mainline.primary.libs@331434000
/dev/block/dm-35       1648     1620         0 100% /apex/com.google.mainline.primary.libs@341919000
/dev/block/dm-31       7524     7492         0 100% /apex/com.android.neuralnetworks@341510000
/dev/block/dm-32      16560    16528         0 100% /apex/com.android.cellbroadcast@341810000
/dev/block/dm-30       3744     3716         0 100% /apex/com.android.appsearch@341810000
/dev/block/dm-28       5892     5864         0 100% /apex/com.android.conscrypt@341911000
/dev/block/dm-29        720      692        16  98% /apex/com.android.sdkext@341710000
/dev/block/dm-27        780      752        12  99% /apex/com.android.tzdata@332714010
/dev/block/dm-25       3920     3892         0 100% /apex/com.android.uwb@341710010
/dev/block/dm-24       7688     7660         0 100% /apex/com.android.extservices@341911003
/dev/block/dm-23       8236     8208         0 100% /apex/com.android.adbd@341520010
/dev/block/dm-22      26332    26304         0 100% /apex/com.android.media.swcodec@341711000
/dev/block/loop21       516      488        20  97% /apex/com.android.vibrator.sunfish@1
/dev/block/loop22     22764    22732         0 100% /apex/com.android.btservices@331716000
/dev/block/dm-20       8368     8336         0 100% /apex/com.android.wifi@341810030
/dev/block/dm-16       6264     6232         0 100% /apex/com.android.media@341917000
/dev/block/dm-15        232      104       124  46% /apex/com.android.scheduling@341510000
/dev/block/loop25     46464    46436         0 100% /apex/com.android.vndk.v33@1
/dev/block/dm-13      21372    21344         0 100% /apex/com.android.tethering@341810050
/dev/block/loop28     36808    36780         0 100% /apex/com.android.i18n@1
/dev/block/loop30       232       96       132  43% /apex/com.android.apex.cts.shim@1
/dev/block/dm-26      11052    11024         0 100% /apex/com.android.mediaprovider@341914020
/dev/block/dm-39        232       88       140  39% /apex/com.android.ondevicepersonalization@330442000
/dev/block/dm-33      19216    19188         0 100% /apex/com.android.adservices@331418080
/dev/block/dm-17       1880     1852         0 100% /apex/com.android.os.statsd@331311000
/dev/block/dm-41  114915308 61879628  52904608  54% /data
/dev/fuse         114915308 61879628  52904608  54% /storage/emulated
andreafrancia commented 3 weeks ago

@mizzunet The workaround I mentioned earlier is something I think we need to have in trash-cli to workaround the problem in psutils under Termux. Sorry if weren't clear.

The option --current-volume-only yet is not available in your trash-cli installation because I started working on after I sent my last message.

I have finished it yet but during the working I discovered a possible temporary solution for you.

Try to prepend this the setting of the variable TRASH_VOLUMES before launching the trash-empty command.

$ TRASH_VOLUMES=$PWD trash-empty

It should at least empty the trash directory in the current volume. The TRASH_VOLUMES variable works with trash-empy, trash-rm, and trash-list.

Please let me know if it works and also please send me the output of the following command on Termux

$ uname -a

So I can add a warning in trash-cli when it detects that is running under Termux if problems arises when searching for volumes.

mizzunet commented 3 weeks ago

Please let me know if it works

It does. Thanks :)

uname -a

Linux localhost 4.14.302-g6ff6ddc33f7d-ab10092322 #1 SMP PREEMPT Tue May 9 09:35:06 UTC 2023 aarch64 Android