diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2023-09-02 21:17:18 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2023-12-08 17:34:50 +0000 |
commit | 06c3fb2749bda94cb5201f81ffdb8fa6c3161b2e (patch) | |
tree | 62f873df87c7c675557a179e0c4c83fe9f3087bc /contrib/llvm-project/llvm/lib/Support/FileUtilities.cpp | |
parent | cf037972ea8863e2bab7461d77345367d2c1e054 (diff) | |
parent | 7fa27ce4a07f19b07799a767fc29416f3b625afb (diff) |
Diffstat (limited to 'contrib/llvm-project/llvm/lib/Support/FileUtilities.cpp')
-rw-r--r-- | contrib/llvm-project/llvm/lib/Support/FileUtilities.cpp | 62 |
1 files changed, 1 insertions, 61 deletions
diff --git a/contrib/llvm-project/llvm/lib/Support/FileUtilities.cpp b/contrib/llvm-project/llvm/lib/Support/FileUtilities.cpp index d01a41a46489..dbd6c324cf4d 100644 --- a/contrib/llvm-project/llvm/lib/Support/FileUtilities.cpp +++ b/contrib/llvm-project/llvm/lib/Support/FileUtilities.cpp @@ -169,7 +169,7 @@ static bool CompareNumbers(const char *&F1P, const char *&F2P, /// DiffFilesWithTolerance - Compare the two files specified, returning 0 if the /// files match, 1 if they are different, and 2 if there is a file error. This -/// function differs from DiffFiles in that you can specify an absolete and +/// function differs from DiffFiles in that you can specify an absolute and /// relative FP error that is allowed to exist. If you specify a string to fill /// in for the error option, it will set the string to an error message if an /// error occurs, allowing the caller to distinguish between a failed diff and a @@ -267,64 +267,6 @@ int llvm::DiffFilesWithTolerance(StringRef NameA, return CompareFailed; } -void llvm::AtomicFileWriteError::log(raw_ostream &OS) const { - OS << "atomic_write_error: "; - switch (Error) { - case atomic_write_error::failed_to_create_uniq_file: - OS << "failed_to_create_uniq_file"; - return; - case atomic_write_error::output_stream_error: - OS << "output_stream_error"; - return; - case atomic_write_error::failed_to_rename_temp_file: - OS << "failed_to_rename_temp_file"; - return; - } - llvm_unreachable("unknown atomic_write_error value in " - "failed_to_rename_temp_file::log()"); -} - -llvm::Error llvm::writeFileAtomically(StringRef TempPathModel, - StringRef FinalPath, StringRef Buffer) { - return writeFileAtomically(TempPathModel, FinalPath, - [&Buffer](llvm::raw_ostream &OS) { - OS.write(Buffer.data(), Buffer.size()); - return llvm::Error::success(); - }); -} - -llvm::Error llvm::writeFileAtomically( - StringRef TempPathModel, StringRef FinalPath, - std::function<llvm::Error(llvm::raw_ostream &)> Writer) { - SmallString<128> GeneratedUniqPath; - int TempFD; - if (sys::fs::createUniqueFile(TempPathModel, TempFD, GeneratedUniqPath)) { - return llvm::make_error<AtomicFileWriteError>( - atomic_write_error::failed_to_create_uniq_file); - } - llvm::FileRemover RemoveTmpFileOnFail(GeneratedUniqPath); - - raw_fd_ostream OS(TempFD, /*shouldClose=*/true); - if (llvm::Error Err = Writer(OS)) { - return Err; - } - - OS.close(); - if (OS.has_error()) { - OS.clear_error(); - return llvm::make_error<AtomicFileWriteError>( - atomic_write_error::output_stream_error); - } - - if (sys::fs::rename(/*from=*/GeneratedUniqPath, /*to=*/FinalPath)) { - return llvm::make_error<AtomicFileWriteError>( - atomic_write_error::failed_to_rename_temp_file); - } - - RemoveTmpFileOnFail.releaseFile(); - return Error::success(); -} - Expected<FilePermissionsApplier> FilePermissionsApplier::create(StringRef InputFilename) { sys::fs::file_status Status; @@ -389,5 +331,3 @@ Error FilePermissionsApplier::apply( return Error::success(); } - -char llvm::AtomicFileWriteError::ID; |