Revision: 14125
          http://sourceforge.net/p/skim-app/code/14125
Author:   hofman
Date:     2024-03-22 17:39:09 +0000 (Fri, 22 Mar 2024)
Log Message:
-----------
Get file mod date from URL getResourceValueForKey: to avoid getting all 
attributes

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

Modified: trunk/SKFileUpdateChecker.m
===================================================================
--- trunk/SKFileUpdateChecker.m 2024-03-22 17:11:51 UTC (rev 14124)
+++ trunk/SKFileUpdateChecker.m 2024-03-22 17:39:09 UTC (rev 14125)
@@ -290,7 +290,9 @@
 
 - (void)didUpdateFromURL:(NSURL *)fileURL {
     fucFlags.fileChangedOnDisk = NO;
-    lastModifiedDate = [[[NSFileManager defaultManager] 
attributesOfItemAtPath:[[fileURL URLByResolvingSymlinksInPath] path] 
error:NULL] fileModificationDate];
+    NSDate *modDate = nil;
+    [[fileURL URLByResolvingSymlinksInPath] getResourceValue:&modDate 
forKey:NSURLAttributeModificationDateKey error:NULL];
+    lastModifiedDate = modDate;
 }
 
 - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object 
change:(NSDictionary *)change context:(void *)context {

Modified: trunk/SKMainDocument.m
===================================================================
--- trunk/SKMainDocument.m      2024-03-22 17:11:51 UTC (rev 14124)
+++ trunk/SKMainDocument.m      2024-03-22 17:39:09 UTC (rev 14125)
@@ -1316,12 +1316,18 @@
     } else NSBeep();
 }
 
+static NSDate *fileModificationDate(NSURL *fileURL) {
+    NSDate *modDate = nil;
+    [fileURL getResourceValue:&modDate 
forKey:NSURLAttributeModificationDateKey error:NULL];
+    return modDate;
+}
+
 - (void)revertDocumentToSaved:(id)sender {      
      if ([self fileURL]) {
          if ([self isDocumentEdited]) {
              [super revertDocumentToSaved:sender];      
          } else if ([fileUpdateChecker fileChangedOnDisk] || 
-                    NSOrderedAscending == [[self fileModificationDate] 
compare:[[[NSFileManager defaultManager] attributesOfItemAtPath:[[self fileURL] 
path] error:NULL] fileModificationDate]]) {
+                    NSOrderedAscending == [[self fileModificationDate] 
compare:fileModificationDate([self fileURL])]) {
              NSAlert *alert = [[NSAlert alloc] init];
              [alert setMessageText:[NSString 
stringWithFormat:NSLocalizedString(@"Do you want to revert to the version of 
the document \"%@\" on disk?", @"Message in alert dialog"), [[self fileURL] 
lastPathComponent]]];
              [alert setInformativeText:NSLocalizedString(@"Your current 
changes will be lost.", @"Informative text in alert dialog")];
@@ -1351,7 +1357,7 @@
         if ([self fileURL] == nil || [[self fileURL] 
checkResourceIsReachableAndReturnError:NULL] == NO)
             return NO;
         if ([self isDocumentEdited] || [fileUpdateChecker fileChangedOnDisk] ||
-               NSOrderedAscending == [[self fileModificationDate] 
compare:[[[NSFileManager defaultManager] attributesOfItemAtPath:[[self fileURL] 
path] error:NULL] fileModificationDate]])
+               NSOrderedAscending == [[self fileModificationDate] 
compare:fileModificationDate([self fileURL])])
             return YES;
         return [super validateUserInterfaceItem:anItem];
     } else if ([anItem action] == @selector(printDocument:)) {

Modified: trunk/SKPDFSynchronizer.m
===================================================================
--- trunk/SKPDFSynchronizer.m   2024-03-22 17:11:51 UTC (rev 14124)
+++ trunk/SKPDFSynchronizer.m   2024-03-22 17:39:09 UTC (rev 14125)
@@ -142,7 +142,10 @@
     if (syncFileName != newSyncFileName) {
         syncFileName = newSyncFileName;
     }
-    lastModDate = (syncFileName ? [[fileManager 
attributesOfItemAtPath:syncFileName error:NULL] fileModificationDate] : nil);
+    NSDate *modDate = nil;
+    if (syncFileName)
+        [[NSURL fileURLWithPath:syncFileName isDirectory:NO] 
getResourceValue:&modDate forKey:NSURLAttributeModificationDateKey error:NULL];
+    lastModDate = modDate;
     [lock unlock];
 }
 
@@ -515,8 +518,9 @@
         NSString *theSyncFileName = [self syncFileName];
         
         if (theSyncFileName && [fileManager fileExistsAtPath:theSyncFileName]) 
{
-            NSDate *modDate = [[fileManager attributesOfItemAtPath:theFileName 
error:NULL] fileModificationDate];
             NSDate *currentModDate = [self lastModDate];
+            NSDate *modDate = nil;
+            [[NSURL fileURLWithPath:syncFileName isDirectory:NO] 
getResourceValue:&modDate forKey:NSURLAttributeModificationDateKey error:NULL];
         
             if (currentModDate && [modDate compare:currentModDate] != 
NSOrderedDescending)
                 rv = YES;

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



_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to