Last active
January 6, 2024 07:31
-
-
Save mikeabdullah/4740463 to your computer and use it in GitHub Desktop.
Revisions
-
mikeabdullah revised this gist
Feb 9, 2013 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -38,7 +38,7 @@ - (BOOL)atomicCopyItemAtURL:(NSURL *)sourceURL // Clean up NSError *error; if (![manager removeItemAtURL:tempDir error:&error]) { NSLog(@"Failed to remove temp directory after atomic copy: %@", error); } -
mikeabdullah revised this gist
Feb 8, 2013 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4,6 +4,7 @@ - (BOOL)atomicCopyItemAtURL:(NSURL *)sourceURL { NSFileManager *manager = [NSFileManager defaultManager]; // First copy into a temporary location where failure doesn't matter NSURL *tempDir = [manager URLForDirectory:NSItemReplacementDirectory inDomain:NSUserDomainMask appropriateForURL:destinationURL @@ -17,6 +18,7 @@ - (BOOL)atomicCopyItemAtURL:(NSURL *)sourceURL BOOL result = [manager copyItemAtURL:sourceURL toURL:tempURL error:outError]; if (result) { // Move the complete item into place, replacing any existing item in the process NSURL *resultingURL; result = [manager replaceItemAtURL:destinationURL withItemAtURL:tempURL -
mikeabdullah revised this gist
Feb 8, 2013 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -38,7 +38,7 @@ - (BOOL)atomicCopyItemAtURL:(NSURL *)sourceURL NSError *error; if (![manager removeItemAtURL:tempDir error:NULL]) { NSLog(@"Failed to remove temp directory after atomic copy: %@", error); } return result; -
mikeabdullah revised this gist
Feb 8, 2013 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -38,7 +38,7 @@ - (BOOL)atomicCopyItemAtURL:(NSURL *)sourceURL NSError *error; if (![manager removeItemAtURL:tempDir error:NULL]) { NSLog(@"Failed to remove temp directory after atomic copywriting: %@", error); } return result; -
mikeabdullah revised this gist
Feb 8, 2013 . 1 changed file with 4 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -27,7 +27,10 @@ - (BOOL)atomicCopyItemAtURL:(NSURL *)sourceURL if (result) { NSAssert([resultingURL.absoluteString isEqualToString:destinationURL.absoluteString], @"URL unexpectedly changed during replacement from:\n%@\nto:\n%@", destinationURL, resultingURL); } } -
mikeabdullah revised this gist
Feb 8, 2013 . 1 changed file with 18 additions and 14 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,25 +1,29 @@ - (BOOL)atomicCopyItemAtURL:(NSURL *)sourceURL toURL:(NSURL *)destinationURL error:(NSError **)outError { NSFileManager *manager = [NSFileManager defaultManager]; NSURL *tempDir = [manager URLForDirectory:NSItemReplacementDirectory inDomain:NSUserDomainMask appropriateForURL:destinationURL create:YES error:outError]; if (!tempDir) return NO; NSURL *tempURL = [tempDir URLByAppendingPathComponent:[destinationURL lastPathComponent]]; BOOL result = [manager copyItemAtURL:sourceURL toURL:tempURL error:outError]; if (result) { NSURL *resultingURL; result = [manager replaceItemAtURL:destinationURL withItemAtURL:tempURL backupItemName:nil options:NSFileManagerItemReplacementUsingNewMetadataOnly resultingItemURL:&resultingURL error:outError]; if (result) { @@ -29,7 +33,7 @@ - (BOOL)atomicCopyItemAtURL:(NSURL *)sourceURL toURL:(NSURL *)destinationURL err // Clean up NSError *error; if (![manager removeItemAtURL:tempDir error:NULL]) { NSLog(@"Failed to remove temp directory after atomic media record writing: %@", error); } -
mikeabdullah created this gist
Feb 8, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,38 @@ - (BOOL)atomicCopyItemAtURL:(NSURL *)sourceURL toURL:(NSURL *)destinationURL error:(NSError **)outError { NSURL *tempDir = [[NSFileManager defaultManager] URLForDirectory:NSItemReplacementDirectory inDomain:NSUserDomainMask appropriateForURL:destinationURL create:YES error:outError]; if (!tempDir) return NO; NSURL *tempURL = [tempDir URLByAppendingPathComponent:[destinationURL lastPathComponent]]; BOOL result = [[NSFileManager defaultManager] copyItemAtURL:sourceURL toURL:tempURL error:outError]; if (result) { NSURL *resultingURL; result = [[NSFileManager defaultManager] replaceItemAtURL:destinationURL withItemAtURL:tempURL backupItemName:nil options:NSFileManagerItemReplacementUsingNewMetadataOnly resultingItemURL:&resultingURL error:outError]; if (result) { OBASSERT([[resultingURL absoluteString] isEqualToString:[destinationURL absoluteString]]); } } // Clean up NSError *error; if (![[NSFileManager defaultManager] removeItemAtURL:tempDir error:NULL]) { NSLog(@"Failed to remove temp directory after atomic media record writing: %@", error); } return result; }