Revision: 26824
          http://sourceforge.net/p/bibdesk/svn/26824
Author:   hofman
Date:     2021-09-08 09:31:51 +0000 (Wed, 08 Sep 2021)
Log Message:
-----------
Revert earlier commit, we need to check whether fileURL is valid before trying 
relative path or alias

Modified Paths:
--------------
    trunk/bibdesk/BDSKLinkedFile.m

Modified: trunk/bibdesk/BDSKLinkedFile.m
===================================================================
--- trunk/bibdesk/BDSKLinkedFile.m      2021-09-08 06:30:32 UTC (rev 26823)
+++ trunk/bibdesk/BDSKLinkedFile.m      2021-09-08 09:31:51 UTC (rev 26824)
@@ -546,39 +546,44 @@
     if (wantsBookmark) {
         // using bookmark and NSURL
         if (fileRef == nil) {
-            NSURL *aURL = nil;
+            NSURL *refURL = nil;
 
             if (fileURL) {
-                aURL = [fileURL retain];
-                shouldUpdate = basePath != nil && aURL != nil;
+                refURL = (NSURL 
*)CFURLCreateFileReferenceURL(kCFAllocatorDefault, (CFURLRef)fileURL, NULL);
+                shouldUpdate = basePath != nil && refURL != nil;
             }
             
-            if (aURL == nil && basePath && relativePath) {
-                aURL = [[NSURL alloc] initFileURLWithPath:[relativePath 
isAbsolutePath] ? relativePath : [basePath 
stringByAppendingPathComponent:relativePath]];
-                shouldUpdate = aURL != nil;
+            if (refURL == nil && basePath && relativePath) {
+                NSURL *aURL = [NSURL fileURLWithPath:[relativePath 
isAbsolutePath] ? relativePath : [basePath 
stringByAppendingPathComponent:relativePath]];
+                refURL = (NSURL 
*)CFURLCreateFileReferenceURL(kCFAllocatorDefault, (CFURLRef)aURL, NULL);
+                shouldUpdate = refURL != nil;
             }
             
-            if (aURL == nil) {
+            if (refURL == nil) {
                 if ([alias isKindOfClass:[NSData class]]) {
-                    aURL = (NSURL 
*)CFURLCreateByResolvingBookmarkData(kCFAllocatorDefault, (CFDataRef)alias, 
kCFURLBookmarkResolutionWithoutUIMask | 
kCFURLBookmarkResolutionWithoutMountingMask, NULL, NULL, (Boolean 
*)&shouldUpdate, NULL);
-                    shouldUpdate = shouldUpdate && basePath != nil && aURL != 
nil;
+                    NSURL *aURL = (NSURL 
*)CFURLCreateByResolvingBookmarkData(kCFAllocatorDefault, (CFDataRef)alias, 
kCFURLBookmarkResolutionWithoutUIMask | 
kCFURLBookmarkResolutionWithoutMountingMask, NULL, NULL, (Boolean 
*)&shouldUpdate, NULL);
+                    if (aURL) {
+                        refURL = (NSURL 
*)CFURLCreateFileReferenceURL(kCFAllocatorDefault, (CFURLRef)aURL, NULL);
+                        [aURL release];
+                    }
+                    shouldUpdate = shouldUpdate && basePath != nil && refURL 
!= nil;
                 } else if ([alias isKindOfClass:[BDSKAlias class]]) {
                     FSRef aRef, baseRef;
                     BOOL ignored, hasBaseRef = BDSKPathToFSRef(basePath, 
&baseRef);
-                    if ([alias getFSRef:&aRef baseRef:hasBaseRef ? &baseRef : 
NULL shouldUpdate:&ignored])
-                        aURL = BDSKCreateURLFromFSRef(&aRef);
-                    shouldUpdate = hasBaseRef && aURL != nil;
+                    if ([alias getFSRef:&aRef baseRef:hasBaseRef ? &baseRef : 
NULL shouldUpdate:&ignored]){
+                        NSURL *aURL = BDSKCreateURLFromFSRef(&aRef);
+                        if (aURL) {
+                            refURL = (NSURL 
*)CFURLCreateFileReferenceURL(kCFAllocatorDefault, (CFURLRef)aURL, NULL);
+                            [aURL release];
+                        }
+                    }
+                    shouldUpdate = hasBaseRef && refURL != nil;
                 }
             }
             
-            if (aURL != nil) {
-                NSURL *refURL = (NSURL 
*)CFURLCreateFileReferenceURL(kCFAllocatorDefault, (CFURLRef)aURL, NULL);
-                [aURL release];
-                shouldUpdate = shouldUpdate && refURL != nil;
-                if (refURL != nil) {
-                    [fileRef release];
-                    fileRef = refURL;
-                }
+            if (refURL != nil) {
+                [fileRef release];
+                fileRef = refURL;
             }
         } else if (relativePath == nil) {
             shouldUpdate = basePath != nil;

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

Reply via email to