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.17k stars 100 forks source link

--preview, --preview-if-missing result in copy errors if item with same name exists #516

Closed RhetTbull closed 3 years ago

RhetTbull commented 3 years ago

Did the upgrade, thank you.

tried download missing and got this error for every photo. Two videos did come through though. Very weird.

This was repeated for over 1000 photos. I ended up downloading the previews, which worked. I guess the iCloud is probably the main culprit

Error exporting photo (C82DF29C-E0E5-42E2-93E8-43A5872F1DF5: IMG_3310.HEIC) as IMG_3310.HEIC: Error Domain=NSCocoaErrorDomain Code=516 "“C82DF29C-E0E5-42E2-93E8-43A5872F1DF5_1_105_c.jpeg” couldn’t be copied to “photos” because an item with the same name already exists." UserInfo={NSSourceFilePathErrorKey=/Volumes/STORAGE/Editor/Photos Library.photoslibrary/resources/derivatives/C/C82DF29C-E0E5-42E2-93E8-43A5872F1DF5_1_105_c.jpeg, NSUserStringVariant=( Copy ), NSDestinationFilePath=/Users/j****/desktop/photos/IMG_3310_preview.jpeg, NSFilePath=/Volumes/STORAGE/Editor/Photos Library.photoslibrary/resources/derivatives/C/C82DF29C-E0E5-42E2-93E8-43A5872F1DF5_1_105_c.jpeg, NSUnderlyingError=0x7fbda9b3e600 {Error Domain=NSPOSIXErrorDomain Code=17 "File exists"}}

Originally posted by @digital821 in https://github.com/RhetTbull/osxphotos/discussions/435#discussioncomment-1360870

RhetTbull commented 3 years ago

This only happens if the original is missing

RhetTbull commented 3 years ago

If original is missing, the logic to increment the filename never increments because the original file is missing:

https://github.com/RhetTbull/osxphotos/blob/c429a860b1ebeb77f3c3e36e9660fc9153d85d11/osxphotos/photoinfo/_photoinfo_export.py#L687-L697

But when the code gets to here, the preview file does exist and name never got incremented:

https://github.com/RhetTbull/osxphotos/blob/c429a860b1ebeb77f3c3e36e9660fc9153d85d11/osxphotos/photoinfo/_photoinfo_export.py#L936-L958

The code should check to see if a preview is needed (and if the original is missing and download_missing isn't true) as part of the increment check. If so and preview is present, increment the file name.