diff --git a/Sparkle/SUFileManager.h b/Sparkle/SUFileManager.h index f06bf3e1..7837c61b 100644 --- a/Sparkle/SUFileManager.h +++ b/Sparkle/SUFileManager.h @@ -147,8 +147,19 @@ NS_ASSUME_NONNULL_BEGIN */ - (BOOL)updateModificationAndAccessTimeOfItemAtURL:(NSURL *)targetURL error:(NSError **)error; -// TODO: document me. Note this does *not* attempt authorization -- (BOOL)updateAccessTimeOfItemsRecursivelyAtURL:(NSURL *)targetURL error:(NSError * __autoreleasing *)error; +/** + * Updates the access time of an item at a specified root URL to the current time + * @param targetURL A URL pointing to the target item whose access time to update to the current time. + * This will be applied recursively if the item is a directory. The item at this URL must exist. + * @param error If an error occurs, upon returns contains an NSError object that describes the problem. If you are not interested in possible errors, you may pass in NULL. + * @return YES if the target item's access times have been updated, otherwise NO along with a populated error object + * + * This method updates the access time of an item to the current time, ideal for letting the system know not to remove a file or directory when placing it + * at a temporary directory. + * + * This is not an atomic operation. No authorization is performed for this method. + */ +- (BOOL)updateAccessTimeOfItemAtRootURL:(NSURL *)targetURL error:(NSError * __autoreleasing *)error; /** * Releases Apple's quarantine extended attribute from the item at the specified root URL diff --git a/Sparkle/SUFileManager.m b/Sparkle/SUFileManager.m index f8de6fbf..63c1e294 100644 --- a/Sparkle/SUFileManager.m +++ b/Sparkle/SUFileManager.m @@ -812,7 +812,7 @@ static BOOL SUMakeRefFromURL(NSURL *url, FSRef *ref, NSError **error) { return YES; } -- (BOOL)updateAccessTimeOfItemsRecursivelyAtURL:(NSURL *)targetURL error:(NSError * __autoreleasing *)error +- (BOOL)updateAccessTimeOfItemAtRootURL:(NSURL *)targetURL error:(NSError * __autoreleasing *)error { if (![self _itemExistsAtURL:targetURL]) { if (error != NULL) { diff --git a/Sparkle/SUPlainInstaller.m b/Sparkle/SUPlainInstaller.m index af60c459..cdca4669 100644 --- a/Sparkle/SUPlainInstaller.m +++ b/Sparkle/SUPlainInstaller.m @@ -90,7 +90,7 @@ // The system periodically cleans up files by looking at the mod & access times, so we have to make sure they're up to date // They could be potentially be preserved when archiving an application, but also an update could just be sitting on the system for a long time // before being installed - if (![fileManager updateAccessTimeOfItemsRecursivelyAtURL:newURL error:error]) { + if (![fileManager updateAccessTimeOfItemAtRootURL:newURL error:error]) { SULog(@"Failed to recursively update new application's modification time before moving into temporary directory"); return NO; } diff --git a/Tests/SUFileManagerTest.swift b/Tests/SUFileManagerTest.swift index 72948a26..3d9dbe7a 100644 --- a/Tests/SUFileManagerTest.swift +++ b/Tests/SUFileManagerTest.swift @@ -278,7 +278,7 @@ class SUFileManagerTest: XCTestCase } makeTempFiles() { fileManager, rootURL, ordinaryFileURL, directoryURL, fileInDirectoryURL, validSymlinkURL, invalidSymlinkURL in - XCTAssertNil(try? fileManager.updateAccessTimeOfItemsRecursivelyAtURL(rootURL.URLByAppendingPathComponent("does not exist"))) + XCTAssertNil(try? fileManager.updateAccessTimeOfItemAtRootURL(rootURL.URLByAppendingPathComponent("does not exist"))) let oldOrdinaryFileTime = accessTime(ordinaryFileURL)! let oldDirectoryTime = accessTime(directoryURL)! @@ -292,16 +292,16 @@ class SUFileManagerTest: XCTestCase XCTAssertTrue(timespecEqual(oldValidSymlinkTime, accessTime(validSymlinkURL)!)) // Test the symlink and make sure the target directory doesn't change - try! fileManager.updateAccessTimeOfItemsRecursivelyAtURL(validSymlinkURL) + try! fileManager.updateAccessTimeOfItemAtRootURL(validSymlinkURL) XCTAssertFalse(timespecEqual(oldValidSymlinkTime, accessTime(validSymlinkURL)!)) XCTAssertTrue(timespecEqual(oldDirectoryTime, accessTime(directoryURL)!)) // Test an ordinary file - try! fileManager.updateAccessTimeOfItemsRecursivelyAtURL(ordinaryFileURL) + try! fileManager.updateAccessTimeOfItemAtRootURL(ordinaryFileURL) XCTAssertFalse(timespecEqual(oldOrdinaryFileTime, accessTime(ordinaryFileURL)!)) // Test the directory and file inside the directory - try! fileManager.updateAccessTimeOfItemsRecursivelyAtURL(directoryURL) + try! fileManager.updateAccessTimeOfItemAtRootURL(directoryURL) let newDirectoryTime = accessTime(directoryURL)! XCTAssertFalse(timespecEqual(oldDirectoryTime, newDirectoryTime)) XCTAssertTrue(timespecEqual(newDirectoryTime, accessTime(fileInDirectoryURL)!))