Tapestry Will Crash on Encountering a File It Cannot Copy #31

Closed
opened 2021-07-01 03:13:39 +00:00 by ZAdamMac · 3 comments
ZAdamMac commented 2021-07-01 03:13:39 +00:00 (Migrated from github.com)

Describe the bug
Tapestry Will Crash on Encountering a File It Cannot Copy. Normally this shouldn't happen, but can in the event that you're copying out (e.g.) system directories or other tools.

To Reproduce
Steps to reproduce the behavior:

  1. Add a file to a directory and remove your own read permissions from it.
  2. Run tapestry in the default or --inc modes.

Expected behavior
It would be better to skip and log such files, possibly with a displayed warning indicating that the script encountered files it cannot remove.

Log/Console Output

patches@Chimera-Coruscant:~$ python3 -m tapestry --inc -c tapestry.cfg
Welcome to Tapestry Backup Tool Version 2.1.1
Automatic updates are not currently a function of this script.
Please refer to the repo for updates: https://www.github.com/ZAdamMac/Tapestry
Gathering a list of files to archive - this could take a few minutes.
Traceback (most recent call last):
  File "/usr/lib/python3.8/runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.8/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/home/patches/.local/lib/python3.8/site-packages/tapestry/__main__.py", line 13, in <module>
    tapestry.runtime()
  File "/home/patches/.local/lib/python3.8/site-packages/tapestry/functions.py", line 1211, in runtime
    do_main(state, gpg_conn)
  File "/home/patches/.local/lib/python3.8/site-packages/tapestry/functions.py", line 328, in do_main
    ops_list = build_ops_list(namespace)
  File "/home/patches/.local/lib/python3.8/site-packages/tapestry/functions.py", line 102, in build_ops_list
    with open(absolute_path, "rb") as contents:
PermissionError: [Errno 13] Permission denied: '/home/patches/server/piminder/test/db/ibtmp1'

Desktop (please complete the following information):

  • OS: [e.g. iOS] Ubuntu 20.04
  • Version [e.g. 22]: 2.1.1

Additional context
Add any other context about the problem here.

**Describe the bug** Tapestry Will Crash on Encountering a File It Cannot Copy. Normally this shouldn't happen, but can in the event that you're copying out (e.g.) system directories or other tools. **To Reproduce** Steps to reproduce the behavior: 1. Add a file to a directory and remove your own read permissions from it. 2. Run tapestry in the default or `--inc` modes. **Expected behavior** It would be better to skip and log such files, possibly with a displayed warning indicating that the script encountered files it cannot remove. **Log/Console Output** ``` patches@Chimera-Coruscant:~$ python3 -m tapestry --inc -c tapestry.cfg Welcome to Tapestry Backup Tool Version 2.1.1 Automatic updates are not currently a function of this script. Please refer to the repo for updates: https://www.github.com/ZAdamMac/Tapestry Gathering a list of files to archive - this could take a few minutes. Traceback (most recent call last): File "/usr/lib/python3.8/runpy.py", line 194, in _run_module_as_main return _run_code(code, main_globals, None, File "/usr/lib/python3.8/runpy.py", line 87, in _run_code exec(code, run_globals) File "/home/patches/.local/lib/python3.8/site-packages/tapestry/__main__.py", line 13, in <module> tapestry.runtime() File "/home/patches/.local/lib/python3.8/site-packages/tapestry/functions.py", line 1211, in runtime do_main(state, gpg_conn) File "/home/patches/.local/lib/python3.8/site-packages/tapestry/functions.py", line 328, in do_main ops_list = build_ops_list(namespace) File "/home/patches/.local/lib/python3.8/site-packages/tapestry/functions.py", line 102, in build_ops_list with open(absolute_path, "rb") as contents: PermissionError: [Errno 13] Permission denied: '/home/patches/server/piminder/test/db/ibtmp1' ``` **Desktop (please complete the following information):** - OS: [e.g. iOS] Ubuntu 20.04 - Version [e.g. 22]: 2.1.1 **Additional context** Add any other context about the problem here.
ZAdamMac commented 2021-07-03 21:56:03 +00:00 (Migrated from github.com)

This bug actually gets more complicated than originally thought.

Thanks to the work of the mighty @EricaPomme we have an access_test function built in to Tapestry since at least 2.1.

This test returns a tuple of true, false, or none for each of the POSIX file permissions (read, write, execute) as well as if the file itself exists.

In the above-stated case, the access_test (which is fundamentally powered by os.access) returns true for the read permission on the file in question. However, the file instead creates an error when it attempts to be opened.

The shortcut solution would still be a try/except that catches the permission error but I want to have a crack at fixing the access_test function first as this evidentially came up at least once before.

This bug actually gets more complicated than originally thought. Thanks to the work of the mighty @EricaPomme we have an access_test function built in to Tapestry since at least 2.1. This test returns a tuple of true, false, or none for each of the POSIX file permissions (read, write, execute) as well as if the file itself exists. In the above-stated case, the access_test (which is fundamentally powered by `os.access`) returns true for the read permission on the file in question. However, the file instead creates an error when it attempts to be opened. The shortcut solution would still be a try/except that catches the permission error but I want to have a crack at fixing the access_test function first as this evidentially came up at least once before.
ZAdamMac commented 2021-07-03 22:02:04 +00:00 (Migrated from github.com)

The following is a direct quotation from the os module documentation:

I/O operations may fail even when access() indicates that they would succeed, particularly for operations on network filesystems which may have permissions semantics beyond the usual POSIX permission-bit model.

This is the more or less exact use case that caused this issue. To be fair, I should not have been using Tapestry in this way; this was a lazy shortcut to avoid having to setup and configure tapestry on a remote headless system.

Given that we are already checking for local access permissions and alerting on failure, I will still add a small code change to catch this bug, but it is not considered a high priority bug any longer and will definitely not be patched until the 2.2 release.

The following is a direct quotation from the os module documentation: > I/O operations may fail even when access() indicates that they would succeed, particularly for operations on network filesystems which may have permissions semantics beyond the usual POSIX permission-bit model. This is the more or less exact use case that caused this issue. To be fair, I should not have been using Tapestry in this way; this was a lazy shortcut to avoid having to setup and configure tapestry on a remote headless system. Given that we are already checking for local access permissions and alerting on failure, I will still add a small code change to catch this bug, but it is not considered a high priority bug any longer and will definitely not be patched until the 2.2 release.
ZAdamMac commented 2021-07-03 22:13:28 +00:00 (Migrated from github.com)

7c78998 is the commit that contains those changes.

Closing now though of course the fix won't be in a release version until 2.2.0. 2.1.X users who need this functionality should compile and install the version of Tapestry currently available in the "Development" directory.

7c78998 is the commit that contains those changes. Closing now though of course the fix won't be in a release version until 2.2.0. 2.1.X users who need this functionality should compile and install the version of Tapestry currently available in the "Development" directory.
This discussion has been locked. Commenting is limited to contributors.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
zadammac/Tapestry#31
No description provided.