Fix chrome os failure after 021de7cf80.

chrome os build failed after D98511:
https://bugs.chromium.org/p/chromium/issues/detail?id=1197970

This patch fixes permission issue appeared after D98511.
This commit is contained in:
Alexey Lapshin 2021-04-12 14:27:14 +03:00
parent 6cc91adf1e
commit ee8a5e4bc2
1 changed files with 6 additions and 6 deletions

View File

@ -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))