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
1.82k stars 94 forks source link

Warn user if Photos path cannot be accessed #1539

Open torarnv opened 1 month ago

torarnv commented 1 month ago

After having tried --download-missing unsuccessfully from an ssh session with both AppleScript and PhotoKit, I then tried on the machine itself, and got:

Database locked, creating temporary copy.
Error copying/Users/torarne/Pictures/Photos Library.photoslibrary/database/photos.db to /var/folders/vp/j9r0pczs6_9_jq3wqnztmj9w0000gn/T/osxphotos_b6w27ele/photos.db
Something went wrong and osxphotos encountered an error:
torarnv commented 1 month ago
Error:
Traceback (most recent call last):
  File "/Users/torarne/dev/osxphotos/osxphotos/fileutil.py", line 308, in copy
    shutil.copy(str(src), str(dest))
  File "/opt/homebrew/Cellar/python@3.11/3.11.7_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/shutil.py", line 419, in copy
    copyfile(src, dst, follow_symlinks=follow_symlinks)
  File "/opt/homebrew/Cellar/python@3.11/3.11.7_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/shutil.py", line 256, in copyfile
    with open(src, 'rb') as fsrc:
         ^^^^^^^^^^^^^^^
PermissionError: [Errno 1] Operation not permitted: '/Users/torarne/Pictures/Photos Library.photoslibrary/database/photos.db'
torarnv commented 1 month ago

Worked after giving iTerm permission to access Photos in the system settings. Worth an explicit check in the code for this scenario with a user-friendly error message perhaps?

RhetTbull commented 1 month ago

Worked after giving iTerm permission to access Photos in the system settings. Worth an explicit check in the code for this scenario with a user-friendly error message perhaps?

I'll look into this but iTerm should have popped up a dialog asking for permission. In macOS it's the responsibility of the calling app (in this case iTerm, not Python or osxphotos which cannot, as a command line tool, request the necessary permissions). I've had problems with iTerm in the past though -- they fixed it in nightly build but I don't know if it's fixed in the regular build.

torarnv commented 1 month ago

Ah, right. I had probably run some command prior to this that tried to access the photo library directory, and I had denied it. Perhaps osxphotos can stat or touch the library directory to somehow figure out if it has permissions to access it, before going down the code paths that then fail on assumptions about reading the actual library database?