Revision: 3573
          http://skim-app.svn.sourceforge.net/skim-app/?rev=3573&view=rev
Author:   hofman
Date:     2008-03-28 10:26:59 -0700 (Fri, 28 Mar 2008)

Log Message:
-----------
Move extra files in a pdfd bundle out of the way when saving to preserve 
version control info rather than doing the saving ourselves. Leopard registers 
the wrong app as modifying the bundle otherwise and warns at every save.

Modified Paths:
--------------
    trunk/SKDocument.m

Modified: trunk/SKDocument.m
===================================================================
--- trunk/SKDocument.m  2008-03-28 16:21:39 UTC (rev 3572)
+++ trunk/SKDocument.m  2008-03-28 17:26:59 UTC (rev 3573)
@@ -320,61 +320,31 @@
         
         NSFileManager *fm = [NSFileManager defaultManager];
         NSString *path = [absoluteURL path];
+        NSString *tmpPath = nil;
         BOOL isDir = NO;
+        NSEnumerator *fileEnum;
+        NSString *file;
         
-        if ([fm fileExistsAtPath:path isDirectory:&isDir] == NO || isDir == 
NO) {
-            success = [super saveToURL:absoluteURL ofType:typeName 
forSaveOperation:saveOperation error:&error];
-        } else {
-            NSString *filename = [path lastPathComponent];
-            NSString *tmpDir = 
SKUniqueDirectoryCreating(NSTemporaryDirectory(), YES);
-            NSString *tmpPath = [tmpDir 
stringByAppendingPathComponent:filename];
-            NSURL *tmpURL = [NSURL fileURLWithPath:tmpPath];
-            
-            if (success = [self writeToURL:tmpURL ofType:typeName 
error:&error]) {
-                
-                NSSet *ourExtensions = [NSSet setWithObjects:@"pdf", @"skim", 
@"fdf", @"txt", @"text", @"rtf", @"plist", nil];
-                NSSet *ourImportantExtensions = [NSSet setWithObjects:@"pdf", 
@"skim", nil];
-                NSEnumerator *fileEnum;
-                NSString *file;
-                NSMutableDictionary *attributes = [[fm 
fileAttributesAtPath:path traverseLink:YES] mutableCopy];
-                [attributes addEntriesFromDictionary:[self 
fileAttributesToWriteToURL:absoluteURL ofType:typeName 
forSaveOperation:saveOperation originalContentsURL:[self fileURL] error:NULL]];
-                unsigned long permissions = [[attributes 
objectForKey:NSFilePosixPermissions] unsignedLongValue];
-               
-                [attributes setObject:[NSNumber 
numberWithUnsignedLong:permissions | 0200] forKey:NSFilePosixPermissions];
-                if ([attributes fileIsImmutable])
-                    [attributes setObject:[NSNumber numberWithBool:NO] 
forKey:NSFileImmutable];
-                [fm changeFileAttributes:attributes atPath:path];
-                [attributes release];
-                
-                fileEnum = [[fm directoryContentsAtPath:path] 
objectEnumerator];
-                while (file = [fileEnum nextObject]) {
-                    if ([ourExtensions containsObject:[[file pathExtension] 
lowercaseString]])
-                        [fm removeFileAtPath:[path 
stringByAppendingPathComponent:file] handler:nil];
-                }
-                
-                fileEnum = [[fm directoryContentsAtPath:tmpPath] 
objectEnumerator];
-                while (success && (file = [fileEnum nextObject])) {
-                    NSString *filePath = [path 
stringByAppendingPathComponent:file];
-                    if ([fm movePath:[tmpPath 
stringByAppendingPathComponent:file] toPath:filePath handler:nil]) {
-                        NSURL *fileURL = [NSURL fileURLWithPath:filePath];
-                        NSString *fileType = [[NSDocumentController 
sharedDocumentController] typeForContentsOfURL:fileURL error:NULL];
-                        NSDictionary *fileAttributes = [self 
fileAttributesToWriteToURL:fileURL ofType:fileType 
forSaveOperation:saveOperation originalContentsURL:[self fileURL] error:NULL];
-                        [fm changeFileAttributes:fileAttributes 
atPath:filePath];
-                    } else if ([ourImportantExtensions containsObject:[[file 
pathExtension] lowercaseString]]) {
-                        success = NO;
-                    }
-                }
-                
-                if (success)
-                    [NSTask launchedTaskWithLaunchPath:@"/usr/bin/touch" 
arguments:[NSArray arrayWithObjects:@"-fm", path, nil]];
-                
-                if (saveOperation == NSSaveAsOperation)
-                    [self setFileURL:absoluteURL];
+        // we move everything that's not ours out of the way, so we can 
preserve version control info
+        if ([fm fileExistsAtPath:path isDirectory:&isDir] && isDir) {
+            NSSet *ourExtensions = [NSSet setWithObjects:@"pdf", @"skim", 
@"fdf", @"txt", @"text", @"rtf", @"plist", nil];
+            tmpPath = SKUniqueDirectoryCreating(NSTemporaryDirectory(), YES);
+            fileEnum = [[fm directoryContentsAtPath:path] objectEnumerator];
+            while (file = [fileEnum nextObject]) {
+                if ([ourExtensions containsObject:[[file pathExtension] 
lowercaseString]] == NO)
+                    [fm movePath:[path stringByAppendingPathComponent:file] 
toPath:[tmpPath stringByAppendingPathComponent:file] handler:nil];
             }
-            
-            [fm removeFileAtPath:tmpDir handler:nil];
         }
         
+        success = [super saveToURL:absoluteURL ofType:typeName 
forSaveOperation:saveOperation error:&error];
+        
+        if (tmpPath) {
+            fileEnum = [[fm directoryContentsAtPath:tmpPath] objectEnumerator];
+            while (file = [fileEnum nextObject])
+                [fm movePath:[tmpPath stringByAppendingPathComponent:file] 
toPath:[path stringByAppendingPathComponent:file] handler:nil];
+            [fm removeFileAtPath:tmpPath handler:nil];
+        }
+        
         if (success)
             [[NSDistributedNotificationCenter defaultCenter]
                 postNotificationName:SKSkimFileDidSaveNotification 
object:[absoluteURL path]];


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

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to