Backups on MAC – Sync issue

Viewing 13 reply threads
  • Author
    Posts
  • January 18, 2022 at 9:47 AM #46335

    John McArthur
    Participant

    Hi,

    I have incorporated File Attachment fields into my DB & used the option to insert the files as Alias’s. I am aware that these files cannot be viewed on my other Mac due to the ‘Alias’ status.

    I am currently updating many records on MAC1 with File Attachment entries but when finished I would like MAC2 to mirror the File Attachment ‘alias’ changes on MAC1.

    Is it simply a case of backing up the DB on MAC1 and restoring on MAC2 to get the File Attachment mirrored effect? Or would this cause issues with future syncing on both MAC’s? Or would the LINK’s be broken on the restore?

    nb; All alias files are held on a NAS box so not locally on either MAC.

    Many thanks

    January 18, 2022 at 1:37 PM #46338

    Brendan
    Keymaster

    Hi John,

    I’m not sure if the aliases will work actually when they’re on a different Mac. Certainly worth giving it a try. But it might not work due to security issues with bookmarks in macOS. Tap Forms uses bookmarks to store the aliases and bookmarks have special security requirements on macOS.

    January 19, 2022 at 5:40 AM #46343

    John McArthur
    Participant

    Thanks Brendan.

    Here’s my test plan:

    1 – MAC1 – Backup FormA
    2 – MAC1 – Remove ‘Nearby’ sync for MAC2
    3 – MAC2 – Rename FormA to FormB
    (This is to retain original form, assuming if the restore doesn’t work, that if I rename FormB back to FormA the application will continue to sync both MAC’s as normal?)
    4 – MAC2 – Restore backup from step 1
    5 – MAC2 – Check File Location links still work
    If success, then; 6 – MAC1 – Restart Nearby Sync & Remove FormB from MAC2
    If Fail – then; 6 – MAC2 – Delete FormA, rename FormB to FormA & Restart Nearby Sync on MAC1

    Can anyone see any issues before I proceed?

    January 20, 2022 at 2:43 AM #46353

    Brendan
    Keymaster

    I don’t think you need to do all that just to test to see if aliases to your NAS works from different Macs for the same document.

    Just send a copy of your document over to another Mac and open it up. If the aliases work, you’re good to go with sync.

    January 20, 2022 at 3:11 PM #46364

    John McArthur
    Participant

    Hi,

    Unfortunately, the copied file when moved to a different Mac doesn’t retain the link.
    The files/folders show up within the File Attachment box but they do nothing when selected.
    Not looking forward to creating hundreds of new link entries on the other Mac. :-(

    Can you divulge how the DB add (+) vs the ‘Alias’ works with regards to where the files are stored?
    The Alias is obviously just a link-to option but are you saying that when the ‘+’ insert file option is chosen, the DB stores the actual linked file in the DB itself? If so, what happens to the original file? (Especially when it was originally stored on say a NAS box. Is this superseded when new updates occur and the DB file is now the master file?)

    Thanks

    January 20, 2022 at 10:02 PM #46368

    Sam Moffatt
    Participant

    Partially I wonder if the issue isn’t the MacOS security model hurting things. Presumably the NAS is mounted at the same place so if the bookmarks behave similar to the old aliases, they should work. What won’t be there is the security ACL entry that says Tap Forms can read the file from your NAS because you haven’t granted it access.

    Shot in the dark suggestion: go into System Preferences and then find Security and Privacy. Hit up the Privacy tab and on the list in the left scroll down to “Full Disk Access”. You’ll need to unlock the preference pane and then you should be able to add Tap Forms to that privilege. It’ll tell you that you need to restart Tap Forms to make it work, so if you’ve got it open restart Tap Forms. See if once you’ve done that it makes a difference.

    When you add the file to the database, Tap Forms creates a copy of the original file and stores it within the Tap Forms document. Alias obviously just stores a pointer to where the file is on disk (or NAS in this case). When you update the original file, the copy within Tap Forms isn’t updated when it is added to the database and you would have to delete the old file and re-attach the new one. Benefit of storing it within the Tap Forms document is that the files are copied to all devices and the downside of storing it within the Tap Forms document is that the files are copied to all devices.

    Something I’ve wanted for a while was the ability to offload file attachment data to an S3 compatible file store which can store thumbnails of the images and trigger on demand pull of full blobs. This would mean the individual documents don’t store a copy of the file but instead can reference a web service that stores them, similar to your NAS use case.

    January 21, 2022 at 12:33 AM #46370

    Brendan
    Keymaster

    So, to get all technical here, when I create an alias, what I’m really doing is creating a bookmark using the following code:

    + (NSData *)securityScopedBookmarkFromURL:(NSURL *)url {
    	NSError *error = nil;
    	NSData *bookmark = nil;
    	
    	bookmark = [url bookmarkDataWithOptions:NSURLBookmarkCreationWithSecurityScope
    			 includingResourceValuesForKeys:nil
    							  relativeToURL:nil
    									  error:&error];
    	
    	if (!bookmark) {
    		TFFLog(@"Utilities:securityScopedBookmarkFromURL Error: %@", error);
    	}
    	
    	return bookmark;
    }

    Then when I want to retrieve the URL to the file from the bookmark, I use this code:

    + (NSURL *)securityScopedUrlFromBookmark:(NSData *)bookmark {
    	NSError *error = nil;
    	BOOL isStale = NO;
    	NSURL *url = [NSURL URLByResolvingBookmarkData:bookmark
    										   options:NSURLBookmarkResolutionWithoutUI | NSURLBookmarkResolutionWithSecurityScope
    									 relativeToURL:nil
    							   bookmarkDataIsStale:&isStale
    											 error:&error];
    	
    	if (!url) {
    		TFFLog(@"securityScopedUrlFromBookmark error: %@", error);
    	}
    	
    	return url;
    }
    

    Essentially, all aliases are security scoped bookmarks. They’re not the same as Finder aliases and not the same as Unix hard or soft links.

    So it would seem that macOS is restricting access to the files because they weren’t created on the other device you’re trying to access them from.

    If you right-click on a .tapforms document and select Show Package Contents you’ll see an Attachments folder (not to be confused with the attachments folder inside the database folder.

    That’s where the bookmark files are actually stored.

    I used to store Finder compatible bookmarks there, but then those stopped working after a while when Apple upgraded the security in newer macOS versions. So now I store these bookmark files which are essentially just binary data files that resolve to URLs using the code above.

    And as Sam has already described, Tap Forms copies the attachments into the database, which eventually become .blob files stored in the attachments folder, not the Attachments folder. Note the case difference.

    January 22, 2022 at 12:52 PM #46375

    Sam Moffatt
    Participant

    I still wonder if granting full access to TF might mitigate the security issue and let it go through at least.

    January 22, 2022 at 3:16 PM #46377

    John McArthur
    Participant

    Hi Sam/Brendan,

    Many thanks for your replies.

    Sam, I attempted your Permissions suggestion but without success. The links still don’t activate.

    Out of curiosity, I did attempt to open the files within the Package Contents area and errors occurred. (See attachment) It reported possible unsupported or corrupt files.

    Brendan, just to clarify the ‘add’ option…the file is just a copy? So, if I need to update the NAS file, I would need to remove the original attached file from the DB and add the new updated file from NAS?

    BTW: I accidentally discovered that its possible to add Folders as alias’s! Bonus! You kept that one quiet. :-)

    Attachments:
    You must be logged in to view attached files.
    January 22, 2022 at 4:20 PM #46379

    Sam Moffatt
    Participant

    The files themselves have the same name and extension of the target but the contents are the secure bookmark metadata so double clicking on it directly won’t work because the file needs to be resolved by the owning application (in this case Tap Forms) which then opens the actual file. Finder doesn’t seem to handle this, I ran into this when I was toying with things trying to figure stuff out.

    I was looking at the file, it should have the metadata needed to reconnect the file assuming the paths are the same but I guess the security store (TCC maybe?) needs to validate it or something.

    If you do the add, it’s just a copy. If you update the NAS file you need to delete it from the Tap Forms document and re-add it. Maybe with a newer version (TF6?) an expanded scripting API for interacting with the local file system might work where you could detect that and process it. I think you can sort of do some of it today but it’s more geared towards web stuff.

    January 22, 2022 at 4:42 PM #46381

    Sam Moffatt
    Participant

    Background processing this, I wonder if the ability to use aliases again instead of secure bookmarks with the caveat that full disk access is enabled to make sure they work would solve your use case properly.

    January 23, 2022 at 12:52 AM #46382

    Daniel Leu
    Participant

    Maybe using web links instead of ‘alias attachments’ might be an option. Usingfile://nas_mounted/path/to/file.pdfas theURLopens the file, assuming that the directory is selected asScript folder access in the preferences.

    In one of my uses where I have to link to several files, I use a table. Each row will point to a separate file.

    In Finder, if you ctrl-click on the filename and then press the alt key, you can copy the pathname for the file. Then you can use a simple form script to set the URL field based on the just copied pathname using Utils.copyTextFromClipboard()

    • This reply was modified 3 months, 4 weeks ago by Daniel Leu.
    January 23, 2022 at 11:34 PM #46398

    Brendan
    Keymaster

    There’s a property when creating bookmarks called NSURLBookmarkCreationSuitableForBookmarkFile. In the docs it says:

    Specifies that the bookmark data should include properties required to create Finder alias files.

    I had been using that a long time ago and it made it possible to double-click on the bookmark file in the Finder and that would correctly resolve the alias.

    However, it stopped working at some point from within Tap Forms after a macOS update. I think it might have been Catalina. So then I had to switch to the security scoped version. And those options just don’t work together. Wish it did.

    January 24, 2022 at 6:02 AM #46414

    John McArthur
    Participant

    Hi,

    I decided to go down the ‘Table / Web link’ route to solve the problem (thanks Daniel) and all ok now.

    Thanks to all for all your help!

Viewing 13 reply threads

You must be logged in to reply to this topic.