Skip to content

Commit

Permalink
Preserve the original creation and modification dates.
Browse files Browse the repository at this point in the history
This is an attempt to tackle
#133 , although I still
can't build the whole app locally yet.
  • Loading branch information
lgarron committed Oct 10, 2021
1 parent 4fabd93 commit 09ba212
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions imageoptim/Backend/Job.m
Expand Up @@ -346,6 +346,11 @@ -(BOOL)saveResult {
}
}

NSDictionary *originalAttributes = [fm attributesOfItemAtPath:filePath.path error:&error];
if (error != NULL) {
IOWarn("Can't get attributes for %@ %@", filePath.path, error);
return NO;
}

// move destination to temporary location that will be overwritten
if (![fm moveItemAtURL:filePath toURL:writeToURL error:&error]) {
Expand Down Expand Up @@ -386,6 +391,14 @@ -(BOOL)saveResult {
[writehandle truncateFileAtOffset:[data length]];
[writehandle closeFile];

NSDictionary* attributesToTransfer = [NSDictionary dictionaryWithObjectsAndKeys: [originalAttributes fileCreationDate], NSFileCreationDate, [originalAttributes fileModificationDate], NSFileModificationDate, NULL];
[fm setAttributes: attributesToTransfer ofItemAtPath: writeToURL.path error: &error];
if (error != NULL) {
IOWarn("Could not set creation and modification date for %@ %@", filePath.path, error);
return NO;
}


moveFromPath = writeToURL;
}

Expand Down

0 comments on commit 09ba212

Please sign in to comment.