From 0ebf3b90e39e1e1cd1c48ed40facfd7456bcf524 Mon Sep 17 00:00:00 2001 From: spycrab Date: Tue, 26 Feb 2019 16:29:34 +0100 Subject: [PATCH] MacUpdater: Fix permissions some more --- Source/Core/MacUpdater/AppDelegate.mm | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Source/Core/MacUpdater/AppDelegate.mm b/Source/Core/MacUpdater/AppDelegate.mm index d9f58e4362..79251571ba 100644 --- a/Source/Core/MacUpdater/AppDelegate.mm +++ b/Source/Core/MacUpdater/AppDelegate.mm @@ -563,10 +563,17 @@ bool UpdateFiles(const std::vector& to_update, // TODO: A new updater protocol version is required to properly mark executable files. For // now, copy executable bits from existing files. This will break for newly added executables. - mode_t permission; + std::optional permission; if (File::Exists(path)) { + struct stat file_stats; + + if (stat(path.c_str(), &file_stats) != 0) + return false; + + permission = file_stats.st_mode; + std::string contents; if (!File::ReadFileToString(path, contents)) { @@ -581,13 +588,6 @@ bool UpdateFiles(const std::vector& to_update, } else if (!op.old_hash || contents_hash != *op.old_hash) { - struct stat file_stats; - - if (stat(path.c_str(), &file_stats) != 0) - return false; - - permission = file_stats.st_mode; - if (!BackupFile(path)) return false; } @@ -604,7 +604,7 @@ bool UpdateFiles(const std::vector& to_update, return false; } - if (chmod(path.c_str(), permission) != 0) + if (permission.has_value() && chmod(path.c_str(), permission.value()) != 0) return false; } return true;