Revision: 11382
          http://bibdesk.svn.sourceforge.net/bibdesk/?rev=11382&view=rev
Author:   hofman
Date:     2007-10-25 02:21:51 -0700 (Thu, 25 Oct 2007)

Log Message:
-----------
Update alias and relative path also when the relative path was not yet set. 
Pass relative path to BDAlias initializer.

Modified Paths:
--------------
    branches/TRY_ARM_FILE_INTERFACE/bibdesk/BDSKFile.h
    branches/TRY_ARM_FILE_INTERFACE/bibdesk/BDSKFile.m

Modified: branches/TRY_ARM_FILE_INTERFACE/bibdesk/BDSKFile.h
===================================================================
--- branches/TRY_ARM_FILE_INTERFACE/bibdesk/BDSKFile.h  2007-10-25 08:56:47 UTC 
(rev 11381)
+++ branches/TRY_ARM_FILE_INTERFACE/bibdesk/BDSKFile.h  2007-10-25 09:21:51 UTC 
(rev 11382)
@@ -80,5 +80,6 @@
 - (NSString *)base64StringRelativeToPath:(NSString *)basePath 
convertedRelativeToPath:(NSString *)newBasePath;
 
 - (NSString *)relativePath;
+- (void)setRelativePath:(NSString *)newRelativePath;
 
 @end

Modified: branches/TRY_ARM_FILE_INTERFACE/bibdesk/BDSKFile.m
===================================================================
--- branches/TRY_ARM_FILE_INTERFACE/bibdesk/BDSKFile.m  2007-10-25 08:56:47 UTC 
(rev 11381)
+++ branches/TRY_ARM_FILE_INTERFACE/bibdesk/BDSKFile.m  2007-10-25 09:21:51 UTC 
(rev 11382)
@@ -421,13 +421,14 @@
 
 - (id)initWithPath:(NSString *)aPath relativeToPath:(NSString *)basePath;
 {
+    NSParameterAssert(nil != aPath);
     BDAlias *anAlias = nil;
     NSURL *baseURL;
     NSString *relPath = nil;
     // BDAlias has a different interpretation of aPath, which is inconsistent 
with the way it handles FSRef
     if (basePath) {
-        anAlias = [[BDAlias alloc] initWithPath:aPath relativeToPath:basePath];
         relPath = [basePath relativePathToFilename:aPath];
+        anAlias = [[BDAlias alloc] initWithPath:relPath 
relativeToPath:basePath];
     } else {
         anAlias = [[BDAlias alloc] initWithPath:aPath];
     }
@@ -480,50 +481,56 @@
 
 - (const FSRef *)fsRefRelativeToURL:(NSURL *)baseURL;
 {
+    FSRef baseRef;
+    Boolean hasBaseRef = baseURL && CFURLGetFSRef((CFURLRef)baseURL, &baseRef);
+    Boolean shouldUpdate = false;
+    
     if (fileRef == NULL) {
         FSRef aRef;
-        FSRef baseRef;
         short aliasCount = 1;
-        Boolean shouldUpdate = false;
-        Boolean success = false;
+        Boolean hasRef = false;
         
         if (baseURL && relativePath) {
             NSString *path = [[baseURL path] 
stringByAppendingPathComponent:relativePath];
-            NSURL *theURL = [NSURL fileURLWithPath:path];
+            NSURL *tmpURL = [NSURL fileURLWithPath:path];
             
-            if (theURL != NULL) {
-                shouldUpdate = success = CFURLGetFSRef((CFURLRef)theURL, 
&aRef);
-            }
+            shouldUpdate = hasRef = hasBaseRef && tmpURL && 
CFURLGetFSRef((CFURLRef)tmpURL, &aRef);
         }
         
-        if (success == false && alias) {
-            if (baseURL && CFURLGetFSRef((CFURLRef)baseURL, &baseRef)) {
-                success = noErr == FSMatchAliasNoUI(&baseRef, kARMNoUI | 
kARMSearch | kARMSearchRelFirst, [alias alias], &aliasCount, &aRef, 
&shouldUpdate, NULL, NULL);
+        if (hasRef == false && alias) {
+            if (hasBaseRef) {
+                hasRef = noErr == FSMatchAliasNoUI(&baseRef, kARMNoUI | 
kARMSearch | kARMSearchRelFirst, [alias alias], &aliasCount, &aRef, 
&shouldUpdate, NULL, NULL);
+                shouldUpdate = shouldUpdate && succes;
             } else {
-                success = noErr == FSMatchAliasNoUI(NULL, kARMNoUI | 
kARMSearch | kARMSearchRelFirst, [alias alias], &aliasCount, &aRef, 
&shouldUpdate, NULL, NULL);
+                hasRef = noErr == FSMatchAliasNoUI(NULL, kARMNoUI | kARMSearch 
| kARMSearchRelFirst, [alias alias], &aliasCount, &aRef, &shouldUpdate, NULL, 
NULL);
                 shouldUpdate = false;
             }
         }
         
-        if (success && shouldUpdate) {
-            FSUpdateAlias(&baseRef, &aRef, [alias alias], &shouldUpdate);
-            if (baseURL) {
-                CFURLRef tmpURL = 
CFURLCreateFromFSRef(CFAllocatorGetDefault(), &aRef);
-                if (tmpURL) {
-                    [relativePath release];
-                    relativePath = [[[baseURL path] 
relativePathToFilename:[(NSURL *)tmpURL path]] retain];
-                    CFRelease(tmpURL);
-                }
-            }
-        }
-        
-        if (success) {
+        if (hasRef) {
             FSRef *newRef = (FSRef *)NSZoneMalloc([self zone], sizeof(FSRef));
             if(newRef)
                 bcopy(&aRef, newRef, sizeof(FSRef));
             fileRef = newRef;
         }
+    } else if (relativePath == nil) {
+        shouldUpdate = hasBaseRef;
     }
+    
+    if (shouldUpdate) {
+        if (alias)
+            FSUpdateAlias(&baseRef, fileRef, [alias alias], &shouldUpdate);
+        else
+            alias = [[BDAlias alloc] initWithFSRef:(FSRef *)fileRef 
relativeToFSRef:&baseRef];
+        if (baseURL) {
+            CFURLRef tmpURL = CFURLCreateFromFSRef(CFAllocatorGetDefault(), 
fileRef);
+            if (tmpURL) {
+                [self setRelativePath:[[baseURL path] 
relativePathToFilename:[(NSURL *)tmpURL path]]];
+                CFRelease(tmpURL);
+            }
+        }
+    }
+    
     return fileRef;
 }
 
@@ -626,4 +633,11 @@
     return relativePath;
 }
 
+- (void)setRelativePath:(NSString *)newRelativePath {
+    if (relativePath != newRelativePath) {
+        [relativePath release];
+        relativePath = [newRelativePath retain];
+    }
+}
+
 @end


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Bibdesk-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit

Reply via email to