Use futimes() when updating mod times recursively

This commit is contained in:
Zorg committed 2016-04-11 00:18:32 -04:00
1 parent 88f5d9a6d9
commit d5f1dcc7c3
1 file changed
+15 -1
+15 -1
View File
@@ -723,7 +723,21 @@ static BOOL SUMakeRefFromURL(NSURL *url, FSRef *ref, NSError **error) {
}
const struct timeval timeInputs[] = {timeValue, timeValue};
if (utimes(path, timeInputs) != 0) {
int fileDescriptor = open(path, O_RDONLY | O_SYMLINK);
if (fileDescriptor == -1) {
if (error != NULL) {
*error = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to open file descriptor to %@", targetURL.path.lastPathComponent] }];
}
return NO;
}
// Using futimes() because utimes() follows symbolic links
BOOL updatedTime = (futimes(fileDescriptor, timeInputs) == 0);
close(fileDescriptor);
if (!updatedTime) {
if (error != NULL) {
*error = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to update modification & access time for %@", targetURL.path.lastPathComponent] }];
}