Referenced Photos #319
Replies: 16 comments 35 replies
-
osxphotos doesn't currently distinguish between referenced files or imported files but does handle them both transparently. It would be probably be helpful to have an You're right that referenced files is a mess on Photos 5+. I would recommend no one use this feature as it's completely broken. In osxphotos, I detect referenced files by looking at Internally, Photos 5 doesn't use this column though for referenced files. It uses the It would be easy to read either ZDIRECTORY or deserialize the CFURL to find where the original file should be. Finding where it moved would be more challenging but likely could be implemented. The problem is fixing this. I tried, unsuccessfully, to write a utility to help someone who stored their Photos library on an external USB drive to move between different Macs. This worked fine on Mojave but on Catalina/BigSur, because Photos uses a CFURL bookmark unique to the machine, it absolutely breaks the library. Photos imported on one Mac can only be found on that Mac and vice versa. Theoretically it would be possible to read the bookmark, find where the photo should be and write a new bookmark to the Photos.sqlite file. I wasn't able to successfully to write a bookmark that Photos would read. However, I didn't spend a great deal of time on it and this is theoretically possible. |
Beta Was this translation helpful? Give feedback.
-
Yes I have a companion project (PhotoScript) used internally by osxphotos that allows full scripting of Photos via AppleScript interface. This could be used to automate the re-import of files with broken links. |
Beta Was this translation helpful? Give feedback.
-
In Photos 5, referenced photos appear to be identified by
|
Beta Was this translation helpful? Give feedback.
-
I was originally quite interested in this feature to basically "show me the path/filename of a photo or video." The reason was this: I had an older library which had videos encoded in a codec which I no longer had, so they would not play in Photos. But, I found I could copy them out of the library package, re-encoded them with Quicktime (which would Quicktime play the file but not Photos? I have no idea.) and then import them back into Photos. The problem was, I didn't want to have to go an figure out all the albums and slideshows the original file was part of, so I though if I could sneakily just copy the new file over the original file inside the package, all would be good. Alas, I used a different method (manually copy/dragging into albums) as it was only 18 files. |
Beta Was this translation helpful? Give feedback.
-
RhetTbull, if you have any of your code that you tried to make the bookmark, could you possibly share? I've been trying to work out how to do this to move my referenced photo library from an old Intel Mac to a new M1 Mac, but also move the photos to a new SSD. In this case, the photos path stays the same, but none of the photos ecosystem works because of the dependency on this darn bookmark data to pass around access information. (This results in absolutely maddening errors... constant Photo app beachballs and all sorts of craziness... ironically, completely deleting the contents of the ZFILESYSTEMBOOKMARK table makes Photos work great in this scenario, but then all sorts of other things don't work, like videos and Live Photos.) [Sidenote, this appears to be all about App Sandboxing, photos needs to tell other things -- like the video player -- about the file data, but because of all the sandboxing, the only way to get them this info securely is through the bookmarks, cool system when it works, and awfully opaque when it fails.] Since I don't want to give up just yet...
After reading your notes and discovering your photoscript package, it seems like another option would be: On the new computer...
I fear you might have already tried this, however. As a simple test of (2), I was going to try and move a bookmark data structure between two libraries to see if that might actually work. |
Beta Was this translation helpful? Give feedback.
-
One thing that helped is giving photos and photolibraryd full disk access.
More later :)
…On Sun, Nov 21, 2021 at 12:27 Rhet Turnbull ***@***.***> wrote:
I've been playing with this and suspect it's the security scope of the
bookmark that my code is creating. Reference CFURLCreateBookmarkData
<https://developer.apple.com/documentation/corefoundation/1542923-cfurlcreatebookmarkdata?language=objc>.
I did confirm that the bookmark created by my script is not identical to
the bookmark created by Photos even if the volume hasn't changed so there's
clearly something different but I can't tell yet what it is. Again, I
suspect it's the security scope or some other option passed to the call to
CFURLCreateBookmarkData.
Also, the volume for a photo is stored in
ZINTERNALRESOURCE.ZFILESYSTEMVOLUME which points to ZFILESYSTEMVOLUME.Z_PK
which stores the UUID of the file system volume in
ZFILESYSTEMVOLUME.ZVOLUMEUUIDSTRING (which can be found with diskutil
info /dev/disk2s1 | grep "UUID" where /dev/disk2s1 is the volume mount
point for where the photos are stored. I tried updating the volume ID when
switching disks but no luck -- that's not the issue. (But likely for a
robust solution, we'll need to update or add a new entry in the
ZFILESYSTEMVOLUME table for the new mount point and then update
ZINTERNALRESOURCE table as well. The volume ID is part of the bookmark as
well.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#319 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAIJS3ZB2MY4LIYP636ZM3UNETVHANCNFSM4VRCPSDQ>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
|
Beta Was this translation helpful? Give feedback.
-
Here's one that might be helpful...
https://github.com/w0lfschild/macOS_headers/blob/master/macOS/PrivateFrameworks/PhotoLibraryServices/101.9.122/PLFileSystemBookmark.h
…On Mon, Nov 22, 2021 at 1:59 PM Rhet Turnbull ***@***.***> wrote:
Also, this might be useful: headers for PhotoLibraryServices
<https://github.com/w0lfschild/macOS_headers/tree/master/macOS/PrivateFrameworks/PhotoLibraryServices>
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#319 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAIJS2BHVITVNA2UE4NGU3UNKHJZANCNFSM4VRCPSDQ>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
|
Beta Was this translation helpful? Give feedback.
-
Would the following approach not work?
1) Copy the source folders containing all the photos to the new SSD. On the
M1 Mac, create a new empty library, in Preferences uncheck 'Copy items to
the Photos library', then drag and drop the folder onto the Photos icon in
the dock (This preserves organization).
2) If the Photos library on the old Mac has referenced as well as managed
or iCloud-based photos, temporarily delete all the referenced items (Create
a smart album containing all the referenced items, and delete); copy the
library across to the new Mac, then copy the referenced items folders to
SSD and add them to the library on the M1 Mac as in (1) above.
On Tue, Nov 23, 2021 at 2:18 AM David Gleich ***@***.***>
wrote:
… Here's one that might be helpful...
https://github.com/w0lfschild/macOS_headers/blob/master/macOS/PrivateFrameworks/PhotoLibraryServices/101.9.122/PLFileSystemBookmark.h
On Mon, Nov 22, 2021 at 1:59 PM Rhet Turnbull ***@***.***>
wrote:
> Also, this might be useful: headers for PhotoLibraryServices
> <
https://github.com/w0lfschild/macOS_headers/tree/master/macOS/PrivateFrameworks/PhotoLibraryServices
>
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <
#319 (reply in thread)
>,
> or unsubscribe
> <
https://github.com/notifications/unsubscribe-auth/AAAIJS2BHVITVNA2UE4NGU3UNKHJZANCNFSM4VRCPSDQ
>
> .
> Triage notifications on the go with GitHub Mobile for iOS
> <
https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675
>
> or Android
> <
https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub
>.
>
>
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#319 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AQF3F4VYH36GKEIBYHVBUUDUNKJQDANCNFSM4VRCPSDQ>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
|
Beta Was this translation helpful? Give feedback.
-
I fear I may have misunderstood this call. This call may be the one that
looks up the bookmark given a photos path. (i.e. this is photos own
internal interface to the ZFILESYSTEMBOOKMARK table…) but i’m honestly not
sure. (e.g. the docs all point to managed object graph data… which
definitely seems like this is somem type of coredata table…)
…On Tue, Nov 23, 2021 at 9:49 AM Rhet Turnbull ***@***.***> wrote:
I managed to get the PLFileSystemBookmark class loaded but can't figure
out how to use it. I think the second argument to
fileSystemBookmarkFromURL:context: is a CoreData NSManagedObjectContext
but don't know enough about CoreData (I know nothing, actually) to do
anything with that. Can we create a CoreData context and pass it in and
it'll just work or does this blow up if it doesn't have Photos' actual
context?
"""Attempting to create a bookmark that Photos can use for accessing referenced files"""import CoreFoundationimport objcfrom CoreData import NSManagedObjectContext
# from CoreFoundation import CFUUIDCreateFromStringfrom Foundation import NSURL
framework = objc.pathForFramework(
"/System/Library/PrivateFrameworks/PhotoLibraryServices.framework/"
)objc.loadBundle("PhotoLibraryServices", globals(), framework)
# PLFileSystemBookmark.fileSystemBookmarkFromURL_context_# Reference: https://github.com/w0lfschild/macOS_headers/blob/master/macOS/PrivateFrameworks/PhotoLibraryServices/101.9.122/PLFileSystemBookmark.h# second argument is a context, which I think is an NSManagedObjectContext# ...but I don't know anything about CoreData and hence what to do with it.
url = NSURL.fileURLWithPath_("/Users/rhet/Desktop/mosaic.jpg")context = NSManagedObjectContext.alloc().init()bkmk = PLFileSystemBookmark.fileSystemBookmarkFromURL_context_(url, context)
# fails with:# Traceback (most recent call last):# File "/Users/rhet/Dropbox/Code/tempworking/pls.py", line 27, in <module># bkmk = PLFileSystemBookmark.fileSystemBookmarkFromURL_context_(# ValueError: NSInvalidArgumentException - +entityForName: nil is not a legal NSPersistentStoreCoordinator for searching for entity name 'FileSystemBookmark'
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#319 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAIJS3RSV2VSXKBJ4ZECQLUNOSWTANCNFSM4VRCPSDQ>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
|
Beta Was this translation helpful? Give feedback.
-
I've done some additional research looking at the original proposal by @dgleich and this appears to be feasible. I've confirmed the following:
|
Beta Was this translation helpful? Give feedback.
-
I have a very rough but working implementation as originally proposed by @dgleich in a new repo for easier collaboration and testing. I have tested this on a small library on Catalina and it works but does require several manual steps by the user (prompted by the script). This is a rough proof-of-concept at the moment with no error handling, etc. |
Beta Was this translation helpful? Give feedback.
-
Will try tonight!
…On Wed, Nov 24, 2021 at 12:36 Rhet Turnbull ***@***.***> wrote:
I have a *very rough* but working implementation as originally proposed
by @dgleich <https://github.com/dgleich> in a new repo
<https://github.com/RhetTbull/RepairPhotosBookmarks> for easier
collaboration and testing. I have tested this on a small library on
Catalina and it works but does require several manual steps by the user
(prompted by the script). This is a rough proof-of-concept at the moment
with no error handling, etc.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#319 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAIJS6AZVTVG6MV6O66RXLUNUPDRANCNFSM4VRCPSDQ>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
|
Beta Was this translation helpful? Give feedback.
-
Okay, this works great! There was one typo that I fixed that I needed to get things working. ... One of the dictionary keys should have been pathstr (no volume to match ZFILESYSTEMBOOKMARK) instead of bookmark_path (has the volume path...) There were a few things I threw into the script, but it worked for a small test library I made to debug things. Handled a Live Photo, Portrait photo, movie, and mixed volumes... everything worked after running the script. I had to make a few edits since I'm on big sur, but... it's all downhill from here. I want to try doing this on my 60k photo library to see what happens there. (Tomorrow? Maybe later because of the holiday?) But... so far so good... ! It's now 'amazing' to see things work when moving between computers. |
Beta Was this translation helpful? Give feedback.
-
Alright, more info. I have a script I can pretty much leave unattended that will handle about 100k items (60k photos, 5k videos, lots of Live Photos, etc.) One key tool was a small step to move AAE files away so Photos doesn't try and do something that causes the import to fail. (Basically, the script will check for AAE files, if it finds them, it moves them to AAE.bak, does the import, then reverse the rename... I don't like this though as a crash at the wrong point would cause a change to the underlying directories... albeit minor -- as this tool seems destined for expert-users only, this is probably okay. ) Once everything was imported, Photos was very happy with the new library. Memories, etc, worked great. All the facial analysis worked... etc. One big surprise to me: photos will rewrite the relevant entries in the photo library journal / property list journal files based on the new SQLite entries in Photos.db. (For those who use TimeMachine, the Photos.db file isn't actually backed up, only the files in resoucses/journals... which will allow one to recreate this... more on these files in https://github.com/dgleich/apple-plj-format.) I had thought I would have to do this myself, so this was a nice surprise! I also tested upgrading from BigSur to Monterey. That... ran into problems with my external disk that I'm still debugging. (I believe everything will work fine once I get the disk issues sorted out, basically Monterey won't mount my external SSD!) |
Beta Was this translation helpful? Give feedback.
-
Yes — give me about a week or so and I’ll try and get it back to you. It’s
mostly cleaned up … just wanted to double check a few things before sending
it in, and then… well, everything else intruded :)
If it’s more than a week and I haven’t done anything, I’ll just send
everything I have right then.
David
…On Apr 25, 2022 at 3:21:45 PM, Rhet Turnbull ***@***.***> wrote:
@dgleich <https://github.com/dgleich> do you have code you can share on
the fixed you implemented to get RepairPhotosBookmarks working? I'd like to
get those incorporated into the tool. Cheers!
—
Reply to this email directly, view it on GitHub
<#319 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAIJS3KDJGWET4UFHX6CZ3VG3WETANCNFSM4VRCPSDQ>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Hi. I am struggling with a similar issue I think. Some time ago I moved a library to a different disk as part of dealing with a broken machine, and since then many photos are disconnected. When I look at RKMASTER I can see a few hundred where volumeID is NULL, whereas others have a volumeID pointing to what looks like the correct disk. The imagePath looks OK. Is it safe to update volumeID (I was thinking to do this direct in the database, not sure if volume info is exposed via osxphotos?), or would this not really fix the problem anyway? Reading this thread it appears that it could be significantly more tangled than that! Related question - which uuid is the main uuid that osxphotos exposes - is it RKVersion.uuid? I am on v4.0 of Photos and Mojave on an older Mini. |
Beta Was this translation helpful? Give feedback.
-
Referenced files were problematic in Photos 3 and 4 for Mac because 1) Moving the original photos didn't update the file paths in the Photos database, 3) Fixing broken links between such moved files and the Photos Library was fiddly, 3) Deleting referenced photos from the Photos library didn’t delete the originals at external location, 4) iCloud Photo Library didn’t import referenced files. It's got worse in Photos 5 and 6, as explained here.
A tool to find all the broken links in Photos, and locate the corresponding original files on the Mac or in connected locations e.g. external HD, thumb drive, Dropbox etc. might be useful. Would need a test library to see what happens on deleting a referenced photo from (a) Photos (b) external location; see what in ZASSET, ZGENERICALBUM, etc. is updated: Presumably, (a) changes ASSET.ZTRASHEDSTATE to 1, while for (b), flag(s) update only when user tries to access the photos.
Wondering if any such tool already exists, and whether you have looked closely at how Photos handles these up to Mojave and for Catalina / Big Sur. Previously, referenced files were identified by RKMASTER.FILEISREFERENCE (Yes = 1, No = 0); not sure what identifies them in newer version (I guess ZASSET.ZCLOUDLOCALSTATE = 1 includes all non-iCloud files i.e. in Photos library as well as referenced?)
Beta Was this translation helpful? Give feedback.
All reactions