Revision: 25238 http://sourceforge.net/p/bibdesk/svn/25238 Author: hofman Date: 2020-12-22 19:09:27 +0000 (Tue, 22 Dec 2020) Log Message: ----------- Update relative path directly and separate method to update the alias, rename method to set the alias
Modified Paths: -------------- trunk/bibdesk/BDSKLinkedFile.m Modified: trunk/bibdesk/BDSKLinkedFile.m =================================================================== --- trunk/bibdesk/BDSKLinkedFile.m 2020-12-22 17:56:44 UTC (rev 25237) +++ trunk/bibdesk/BDSKLinkedFile.m 2020-12-22 19:09:27 UTC (rev 25238) @@ -93,8 +93,6 @@ - (NSData *)aliasDataRelativeToPath:(NSString *)newBasePath; -- (void)updateWithPath:(NSString *)path basePath:(NSString *)basePath baseRef:(const FSRef *)baseRef; - @end #pragma mark - @@ -506,6 +504,29 @@ } } +- (void)updateAliasWithBaseRef:(const FSRef *)baseRef { + BDSKASSERT(baseRef != NULL); + BDSKASSERT(fileRef != NULL); + + // update the alias + if (isBookmark == NO && locator.alias != NULL) { + Boolean didUpdate; +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" + FSUpdateAlias(BDSKBaseRefIfOnSameVolume(baseRef, fileRef), fileRef, locator.alias, &didUpdate); +#pragma clang diagnostic pop + } else { + AliasHandle anAlias = BDSKFSRefToAliasHandle(fileRef, baseRef); + if (anAlias) { + if (isBookmark) { + BDSKDESTROY(locator.bookmark); + isBookmark = NO; + } + locator.alias = anAlias; + } + } +} + - (void)updateFileRef; { NSString *basePath = [delegate basePathForLinkedFile:self]; @@ -549,8 +570,11 @@ if (aURL != nil) { if (fileURL == nil) fileURL = [aURL retain]; - if (shouldUpdate) - [self updateWithPath:[aURL path] basePath:basePath baseRef:&baseRef]; + if (shouldUpdate) { + [self updateAliasWithBaseRef:&baseRef]; + [relativePath release]; + relativePath = [[[aURL path] relativePathFromPath:basePath] retain]; + } [aURL release]; } } @@ -582,8 +606,11 @@ [aURL release]; aURL = BDSKCreateURLFromFSRef(fileRef); NSString *basePath = [delegate basePathForLinkedFile:self]; - if (BDSKPathToFSRef(basePath, &aRef)) - [self updateWithPath:[aURL path] basePath:basePath baseRef:&aRef]; + if (BDSKPathToFSRef(basePath, &aRef)) { + [self updateAliasWithBaseRef:&aRef]; + [relativePath release]; + relativePath = [[[aURL path] relativePathFromPath:basePath] retain]; + } } [self setFileURL:aURL]; } @@ -661,7 +688,7 @@ return [[NSPropertyListSerialization dataWithPropertyList:dictionary format:NSPropertyListBinaryFormat_v1_0 options:0 error:NULL] base64String]; } -- (void)updateAliasWithPath:(NSString *)aPath basePath:(NSString *)basePath { +- (void)setAliasWithPath:(NSString *)aPath basePath:(NSString *)basePath { AliasHandle anAlias = BDSKPathToAliasHandle(aPath, basePath); if (anAlias != NULL) { BOOL saveIsBookmark = isBookmark; @@ -693,8 +720,11 @@ NSURL *aURL = BDSKCreateURLFromFSRef(fileRef); if (aURL != nil) { FSRef baseRef; - if (BDSKPathToFSRef(basePath, &baseRef)) - [self updateWithPath:[aURL path] basePath:basePath baseRef:&baseRef]; + if (BDSKPathToFSRef(basePath, &baseRef)) { + [self updateAliasWithBaseRef:&baseRef]; + [relativePath release]; + relativePath = [[[aURL path] relativePathFromPath:basePath] retain]; + } [aURL release]; } else { // the fileRef was invalid, reset it and update @@ -702,7 +732,7 @@ [self updateFileRef]; if (fileRef == NULL && aPath) // this can happen after an auto file to a volume, as the file is actually not moved but copied - [self updateAliasWithPath:aPath basePath:basePath]; + [self setAliasWithPath:aPath basePath:basePath]; } } if (aPath) { @@ -721,44 +751,18 @@ [aURL release]; } if (needsUpdate) { - if (BDSKPathToFSRef(basePath, &aRef)) - [self updateWithPath:aPath basePath:basePath baseRef:&aRef]; - else - [self updateAliasWithPath:aPath basePath:basePath]; + if (BDSKPathToFSRef(basePath, &aRef)) { + [self updateAliasWithBaseRef:&aRef]; + [relativePath release]; + relativePath = [[aPath relativePathFromPath:basePath] retain]; + } else { + [self setAliasWithPath:aPath basePath:basePath]; + } } } } } -- (void)updateWithPath:(NSString *)path basePath:(NSString *)basePath baseRef:(const FSRef *)baseRef { - BDSKASSERT(path != nil); - BDSKASSERT(basePath != nil); - BDSKASSERT(baseRef != NULL); - BDSKASSERT(fileRef != NULL); - - // update the alias - if (isBookmark == NO && locator.alias != NULL) { - Boolean didUpdate; -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" - FSUpdateAlias(BDSKBaseRefIfOnSameVolume(baseRef, fileRef), fileRef, locator.alias, &didUpdate); -#pragma clang diagnostic pop - } else { - AliasHandle anAlias = BDSKFSRefToAliasHandle(fileRef, baseRef); - if (anAlias) { - if (isBookmark) { - BDSKDESTROY(locator.bookmark); - isBookmark = NO; - } - locator.alias = anAlias; - } - } - - // update the relative path - [relativePath autorelease]; - relativePath = [[path relativePathFromPath:basePath] retain]; -} - - (void)updateHasSkimNotes { hasSkimNotesNeedsUpdate = YES; if (isInitial == NO) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. _______________________________________________ Bibdesk-commit mailing list Bibdesk-commit@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/bibdesk-commit