aboutsummaryrefslogtreecommitdiff
path: root/llvm/tools/llvm-objcopy/llvm-objcopy.cpp
diff options
context:
space:
mode:
authorAlexey Lapshin <a.v.lapshin@mail.ru>2021-04-12 14:27:14 +0300
committerAlexey Lapshin <a.v.lapshin@mail.ru>2021-04-12 15:28:32 +0300
commitee8a5e4bc2c986b8e6c07e81fb58dc1e5a5c2d17 (patch)
tree2c8e5889316dc1807130351ed9755fc1ccd4fcc7 /llvm/tools/llvm-objcopy/llvm-objcopy.cpp
parent6cc91adf1e61769e6c39059f8d88bbcb4d1773bc (diff)
downloadllvm-ee8a5e4bc2c986b8e6c07e81fb58dc1e5a5c2d17.zip
llvm-ee8a5e4bc2c986b8e6c07e81fb58dc1e5a5c2d17.tar.gz
llvm-ee8a5e4bc2c986b8e6c07e81fb58dc1e5a5c2d17.tar.bz2
Fix chrome os failure after 021de7cf80268091cf13485a538b611b37d0b33e.
chrome os build failed after D98511: https://bugs.chromium.org/p/chromium/issues/detail?id=1197970 This patch fixes permission issue appeared after D98511.
Diffstat (limited to 'llvm/tools/llvm-objcopy/llvm-objcopy.cpp')
-rw-r--r--llvm/tools/llvm-objcopy/llvm-objcopy.cpp12
1 files changed, 6 insertions, 6 deletions
diff --git a/llvm/tools/llvm-objcopy/llvm-objcopy.cpp b/llvm/tools/llvm-objcopy/llvm-objcopy.cpp
index 6c6b26b3..d3cc947 100644
--- a/llvm/tools/llvm-objcopy/llvm-objcopy.cpp
+++ b/llvm/tools/llvm-objcopy/llvm-objcopy.cpp
@@ -259,6 +259,12 @@ static Error restoreStatOnFile(StringRef Filename,
if (std::error_code EC = sys::fs::status(FD, OStat))
return createFileError(Filename, EC);
if (OStat.type() == sys::fs::file_type::regular_file) {
+#ifndef _WIN32
+ // Keep ownership if llvm-objcopy is called under root.
+ if (Config.InputFilename == Config.OutputFilename && OStat.getUser() == 0)
+ sys::fs::changeFileOwnership(FD, Stat.getUser(), Stat.getGroup());
+#endif
+
sys::fs::perms Perm = Stat.permissions();
if (Config.InputFilename != Config.OutputFilename)
Perm = static_cast<sys::fs::perms>(Perm & ~sys::fs::getUmask() & ~06000);
@@ -268,12 +274,6 @@ static Error restoreStatOnFile(StringRef Filename,
if (auto EC = sys::fs::setPermissions(FD, Perm))
#endif
return createFileError(Filename, EC);
-
-#ifndef _WIN32
- // Keep ownership if llvm-objcopy is called under root.
- if (Config.InputFilename == Config.OutputFilename && OStat.getUser() == 0)
- sys::fs::changeFileOwnership(FD, Stat.getUser(), Stat.getGroup());
-#endif
}
if (auto EC = sys::Process::SafelyCloseFileDescriptor(FD))