Revision: 5950
          http://skim-app.svn.sourceforge.net/skim-app/?rev=5950&view=rev
Author:   hofman
Date:     2009-10-26 12:13:46 +0000 (Mon, 26 Oct 2009)

Log Message:
-----------
also set write permission flag temporarily when saving notes

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

Modified: trunk/SKMainDocument.m
===================================================================
--- trunk/SKMainDocument.m      2009-10-26 09:47:39 UTC (rev 5949)
+++ trunk/SKMainDocument.m      2009-10-26 12:13:46 UTC (rev 5950)
@@ -384,14 +384,36 @@
             }
             
             BOOL isLocked = NO;
+            BOOL isReadOnly = NO;
             FSRef fileRef;
             FSCatalogInfo catalogInfo;
+            FSCatalogInfoBitmap whichInfo = kFSCatInfoNone;
             if (CFURLGetFSRef((CFURLRef)absoluteURL, &fileRef) &&
-                noErr == FSGetCatalogInfo(&fileRef, kFSCatInfoNodeFlags, 
&catalogInfo, NULL, NULL, NULL)) {
-                if (isLocked = (catalogInfo.nodeFlags & kFSNodeLockedMask) != 
0) {
-                    FSCatalogInfo unlockedCatalogInfo = catalogInfo;
-                    unlockedCatalogInfo.nodeFlags &= ~kFSNodeLockedMask;
-                    (void)FSSetCatalogInfo(&fileRef, kFSCatInfoNodeFlags, 
&unlockedCatalogInfo);
+                noErr == FSGetCatalogInfo(&fileRef, kFSCatInfoNodeFlags | 
kFSCatInfoPermissions, &catalogInfo, NULL, NULL, NULL)) {
+                FSPermissionInfo *permissions;
+#ifdef __LP64__
+                permissions = &catalogInfo.permissions;
+#else
+                permissions = (FSPermissionInfo *)catalogInfo.permissions;
+#endif
+                isLocked = (catalogInfo.nodeFlags & kFSNodeLockedMask) != 0;
+                isReadOnly = (permissions->mode & 0x80) == 0;
+                
+                if (isLocked || isReadOnly) {
+                    FSCatalogInfo tmpCatalogInfo = catalogInfo;
+                    if (isLocked) {
+                        tmpCatalogInfo.nodeFlags &= ~kFSNodeLockedMask;
+                        whichInfo |= kFSNodeLockedMask;
+                    }
+                    if (isReadOnly) {
+#ifdef __LP64__
+                        tmpCatalogInfo.permissions.mode |= 0x80;
+#else
+                        ((FSPermissionInfo *)tmpCatalogInfo.permissions)->mode 
|= 0x80;
+#endif
+                        whichInfo |= kFSCatInfoPermissions;
+                    }
+                    (void)FSSetCatalogInfo(&fileRef, whichInfo, 
&tmpCatalogInfo);
                 }
             }
             
@@ -411,8 +433,8 @@
             if (options)
                 [[SKNExtendedAttributeManager sharedManager] 
setExtendedAttributeNamed:PRESENTATION_OPTIONS_KEY toPropertyListValue:options 
atPath:[absoluteURL path] options:kSKNXattrDefault error:NULL];
             
-            if (isLocked)
-                (void)FSSetCatalogInfo(&fileRef, kFSCatInfoNodeFlags, 
&catalogInfo);
+            if (isLocked || isReadOnly)
+                (void)FSSetCatalogInfo(&fileRef, whichInfo, &catalogInfo);
             
             [[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.

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to