RhetTbull / osxphotos

Python app to work with pictures and associated metadata from Apple Photos on macOS. Also includes a package to provide programmatic access to the Photos library, pictures, and metadata.
MIT License
2.19k stars 101 forks source link

Stale NFS file handle #1674

Open scottrobertson opened 3 months ago

scottrobertson commented 3 months ago

Using CloudMounter, I have a Cloudflare R2 bucket mounted. I am trying to backup to that. It works perfectly, but at the end of the process, it tries to do something with .Trash and fails.

osxphotos export --ramdb --retry 3 --download-missing --update --export-by-date --limit 100 /Users/scottrobertson/Library/CloudStorage/CloudMounter-Cloudfare
Exception ignored in atexit callback: <function export_cli.<locals>.cleanup_lock_files at 0x109ac98a0>
Traceback (most recent call last):
  File "/Users/scottrobertson/.local/pipx/venvs/osxphotos/lib/python3.12/site-packages/osxphotos/cli/export.py", line 1952, in cleanup_lock_files
    for lock_file in pathlib.Path(dest).rglob("*.osxphotos.lock"):
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.12/3.12.5/Frameworks/Python.framework/Versions/3.12/lib/python3.12/pathlib.py", line 1109, in rglob
    for p in selector.select_from(self):
             ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.12/3.12.5/Frameworks/Python.framework/Versions/3.12/lib/python3.12/pathlib.py", line 236, in _select_from
    for starting_point in self._iterate_directories(parent_path):
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.12/3.12.5/Frameworks/Python.framework/Versions/3.12/lib/python3.12/pathlib.py", line 230, in _iterate_directories
    for dirpath, dirnames, _ in parent_path.walk():
                                ^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.12/3.12.5/Frameworks/Python.framework/Versions/3.12/lib/python3.12/pathlib.py", line 1138, in walk
    for entry in scandir_it:
                 ^^^^^^^^^^
OSError: [Errno 70] Stale NFS file handle: '/Users/scottrobertson/Library/CloudStorage/CloudMounter-Cloudfare/.Trash'
RhetTbull commented 3 months ago

This is getting called in an atexit handler that cleans up any remaining OSXPhotos lock files. OSXPhotos isn't doing anything with the .Trash folder but looks like the crash is happening when the code tries to read the folder (looking for lock files to cleanup). This error is from your filesystem, not OSXPhotos. The .Trash folder is the macOS recycle bin which the OS creates on every volume you mount so it makes sense to skip the folder but the real issue is with CloudMounter I suspect. I would file a bug report with them as the .Trash folder should be accessible.

I'll look at wrapping this section of code in an exception handler so it doesn't crash OSXPhotos. In the meantime, this happens right before OSXPhotos is going to exit and after the export is done. That means the export should have worked as expected.

scottrobertson commented 2 months ago

Awesome, thank you for the reply. I figured it would be something odd they are doing. I am glad it's right at the end too. No need to rush to handle anything on your end.