Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

using a better replacement (rename) method for staging a completed pn…

…gcrush result, also keeping the pngcrush result in cache dir while processing
  • Loading branch information...
commit 37e0ae15ed0b6794ae148ae0a9133901dca14b2f 1 parent ef01b43
Rasmus authored
Showing with 10 additions and 9 deletions.
  1. +10 −9 src/DPAppDelegate.m
19 src/DPAppDelegate.m
View
@@ -1181,7 +1181,7 @@ -(BOOL)pngcrushPNGImageAtPath:(NSString *)path brute:(BOOL)brute {
"/tmp/output"
};
argv[PNCARGC-2] = (char *)/* this is safe -- it won't be altered */[path UTF8String];
- tmppath = [[path stringByDeletingLastPathComponent] stringByAppendingString:@".pngcrush.XXXXXX"];
+ tmppath = [cacheDir stringByAppendingString:@"pngcrush.XXXXXX"];
tmpntpl = strdup([tmppath UTF8String]);
argv[PNCARGC-1] = mktemp(tmpntpl);
@@ -1200,16 +1200,17 @@ -(BOOL)pngcrushPNGImageAtPath:(NSString *)path brute:(BOOL)brute {
else
[log debug:@"debug: [pngcrush] crushed \"%@\"", path];
- if (![fm removeItemAtPath:path error:&err]){
- [log error:@"[pngcrush] unlink(\"%@\") failed -- %@", path, err];
- }
- if (![fm moveItemAtPath:tmppath toPath:path error:&err]) {
- [log error:@"error: [pngcrush] rename(\"%s\", \"%@\") failed -- %@", argv[PNCARGC-1], path, err];
+ NSURL *resultingURL = nil;
+ success = [fm replaceItemAtURL:[NSURL fileURLWithPath:path]
+ withItemAtURL:[NSURL fileURLWithPath:tmppath]
+ backupItemName:nil
+ options:0
+ resultingItemURL:&resultingURL
+ error:&err];
+ if (!success) {
+ [log error:@"error: [pngcrush] atomic/safe rename \"%s\" --> \"%@\" failed: %@", argv[PNCARGC-1], path, err];
[fm removeItemAtPath:tmppath error:nil];
}
- else {
- success = YES;
- }
}
else {
[log error:@"error: [pngcrush] pngcrush_main(<%d args>) failed with code %d", PNCARGC, pncr];
Please sign in to comment.
Something went wrong with that request. Please try again.