summaryrefslogtreecommitdiff
path: root/Source/Core
diff options
context:
space:
mode:
authorspycrab <spycrab@users.noreply.github.com>2019-02-25 10:57:45 +0100
committerGitHub <noreply@github.com>2019-02-25 10:57:45 +0100
commit1ba4fd875f0b4e3f37ea4ebb6d91862a3be1f26d (patch)
tree528d80da4ff2776b36adc353a444f32275d187b1 /Source/Core
parent83ff3aa69140cae852d7eca68af3112280669ff5 (diff)
parent96786d05011811d0adeee02e9697141730f29190 (diff)
Merge pull request #7819 from spycrab/keep_permissions
MacUpdater: Retain file permissions
Diffstat (limited to 'Source/Core')
-rw-r--r--Source/Core/MacUpdater/AppDelegate.mm18
1 files changed, 18 insertions, 0 deletions
diff --git a/Source/Core/MacUpdater/AppDelegate.mm b/Source/Core/MacUpdater/AppDelegate.mm
index 02a4992321..d9f58e4362 100644
--- a/Source/Core/MacUpdater/AppDelegate.mm
+++ b/Source/Core/MacUpdater/AppDelegate.mm
@@ -22,6 +22,9 @@
#include <vector>
#include <zlib.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+
#include "Common/CommonPaths.h"
#include "Common/CommonTypes.h"
#include "Common/FileUtil.h"
@@ -558,6 +561,10 @@ bool UpdateFiles(const std::vector<TodoList::UpdateOp>& to_update,
return false;
}
+ // 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;
+
if (File::Exists(path))
{
std::string contents;
@@ -574,6 +581,13 @@ bool UpdateFiles(const std::vector<TodoList::UpdateOp>& 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;
}
@@ -586,8 +600,12 @@ bool UpdateFiles(const std::vector<TodoList::UpdateOp>& to_update,
if (!File::Copy(temp_path + DIR_SEP + content_filename, path))
{
fprintf(log_fp, "Could not update file %s.\n", op.filename.c_str());
+
return false;
}
+
+ if (chmod(path.c_str(), permission) != 0)
+ return false;
}
return true;
}