From d5f1dcc7c31d928752bf02a7431cfb64d64725d3 Mon Sep 17 00:00:00 2001 From: Zorg Date: Mon, 11 Apr 2016 00:18:32 -0400 Subject: [PATCH] Use futimes() when updating mod times recursively --- Sparkle/SUFileManager.m | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/Sparkle/SUFileManager.m b/Sparkle/SUFileManager.m index 3a5aac68..2ee4c4e5 100644 --- a/Sparkle/SUFileManager.m +++ b/Sparkle/SUFileManager.m @@ -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] }]; }