aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Support/FileOutputBuffer.cpp
diff options
context:
space:
mode:
authorAlexey Lapshin <a.v.lapshin@mail.ru>2021-03-12 16:31:35 +0300
committerAlexey Lapshin <a.v.lapshin@mail.ru>2021-03-17 17:27:00 +0300
commit021de7cf80268091cf13485a538b611b37d0b33e (patch)
tree6d3eb17b90adc172c53618def5d89a2946284743 /llvm/lib/Support/FileOutputBuffer.cpp
parentd9ef6bc42643ae4feab3f9eca97864d72034f2ce (diff)
downloadllvm-021de7cf80268091cf13485a538b611b37d0b33e.zip
llvm-021de7cf80268091cf13485a538b611b37d0b33e.tar.gz
llvm-021de7cf80268091cf13485a538b611b37d0b33e.tar.bz2
[llvm-objcopy][NFC] Move ownership keeping code into restoreStatOnFile().
The D93881 added functionality which preserve ownership for output file if llvm-objcopy is called under root. That code was added into the place where output file is created. The llvm-objcopy already has a function which sets/restores rights/permissions for the output file. That is the restoreStatOnFile() function. This patch moves code (preserving ownershipping) into the restoreStatOnFile() function. Differential Revision: https://reviews.llvm.org/D98511
Diffstat (limited to 'llvm/lib/Support/FileOutputBuffer.cpp')
-rw-r--r--llvm/lib/Support/FileOutputBuffer.cpp16
1 files changed, 3 insertions, 13 deletions
diff --git a/llvm/lib/Support/FileOutputBuffer.cpp b/llvm/lib/Support/FileOutputBuffer.cpp
index 7b2a512..3342682 100644
--- a/llvm/lib/Support/FileOutputBuffer.cpp
+++ b/llvm/lib/Support/FileOutputBuffer.cpp
@@ -125,8 +125,7 @@ createInMemoryBuffer(StringRef Path, size_t Size, unsigned Mode) {
}
static Expected<std::unique_ptr<FileOutputBuffer>>
-createOnDiskBuffer(StringRef Path, size_t Size, unsigned Mode,
- bool KeepOwnership, unsigned UserID, unsigned GroupID) {
+createOnDiskBuffer(StringRef Path, size_t Size, unsigned Mode) {
Expected<fs::TempFile> FileOrErr =
fs::TempFile::create(Path + ".tmp%%%%%%%", Mode);
if (!FileOrErr)
@@ -134,13 +133,6 @@ createOnDiskBuffer(StringRef Path, size_t Size, unsigned Mode,
fs::TempFile File = std::move(*FileOrErr);
#ifndef _WIN32
- // Try to preserve file ownership if requested.
- if (KeepOwnership) {
- fs::file_status Stat;
- if (!fs::status(File.FD, Stat) && Stat.getUser() == 0)
- fs::changeFileOwnership(File.FD, UserID, GroupID);
- }
-
// On Windows, CreateFileMapping (the mmap function on Windows)
// automatically extends the underlying file. We don't need to
// extend the file beforehand. _chsize (ftruncate on Windows) is
@@ -171,8 +163,7 @@ createOnDiskBuffer(StringRef Path, size_t Size, unsigned Mode,
// Create an instance of FileOutputBuffer.
Expected<std::unique_ptr<FileOutputBuffer>>
-FileOutputBuffer::create(StringRef Path, size_t Size, unsigned Flags,
- unsigned UserID, unsigned GroupID) {
+FileOutputBuffer::create(StringRef Path, size_t Size, unsigned Flags) {
// Handle "-" as stdout just like llvm::raw_ostream does.
if (Path == "-")
return createInMemoryBuffer("-", Size, /*Mode=*/0);
@@ -205,8 +196,7 @@ FileOutputBuffer::create(StringRef Path, size_t Size, unsigned Flags,
if (Flags & F_no_mmap)
return createInMemoryBuffer(Path, Size, Mode);
else
- return createOnDiskBuffer(Path, Size, Mode, Flags & F_keep_ownership,
- UserID, GroupID);
+ return createOnDiskBuffer(Path, Size, Mode);
default:
return createInMemoryBuffer(Path, Size, Mode);
}