Skip to content

[upstream-update] Do not specify OpenFlags since it was removed upstr… #18472

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/swift/Basic/FileSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ namespace swift {
/// As a special case, an output path of "-" is treated as referring to
/// stdout.
std::error_code atomicallyWritingToFile(
llvm::StringRef outputPath, bool binaryMode,
llvm::StringRef outputPath,
llvm::function_ref<void(llvm::raw_pwrite_stream &)> action);

/// Moves a file from \p source to \p destination, unless there is already
Expand Down
15 changes: 5 additions & 10 deletions lib/Basic/FileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,12 @@ canUseTemporaryForWrite(const StringRef outputPath) {
/// temporary file that was just created.
/// \param outputPath The path to the final output file, which is used to decide
/// where to put the temporary.
/// \param openFlags Controls how the output stream will be opened.
///
/// \returns The path to the temporary file that was opened, or \c None if the
/// file couldn't be created.
static Optional<std::string>
tryToOpenTemporaryFile(Optional<llvm::raw_fd_ostream> &openedStream,
const StringRef outputPath,
const llvm::sys::fs::OpenFlags openFlags) {
const StringRef outputPath) {
namespace fs = llvm::sys::fs;

// Create a temporary file path.
Expand All @@ -102,8 +100,7 @@ tryToOpenTemporaryFile(Optional<llvm::raw_fd_ostream> &openedStream,

int fd;
const unsigned perms = fs::all_read | fs::all_write;
std::error_code EC = fs::createUniqueFile(tempPath, fd, tempPath, perms,
openFlags);
std::error_code EC = fs::createUniqueFile(tempPath, fd, tempPath, perms);

if (EC) {
// Ignore the specific error; the caller has to fall back to not using a
Expand All @@ -118,7 +115,7 @@ tryToOpenTemporaryFile(Optional<llvm::raw_fd_ostream> &openedStream,
}

std::error_code swift::atomicallyWritingToFile(
const StringRef outputPath, const bool binaryMode,
const StringRef outputPath,
const llvm::function_ref<void(llvm::raw_pwrite_stream &)> action) {
namespace fs = llvm::sys::fs;

Expand All @@ -133,11 +130,9 @@ std::error_code swift::atomicallyWritingToFile(

Optional<std::string> temporaryPath;
{
const fs::OpenFlags openFlags = (binaryMode ? fs::F_None : fs::F_Text);

Optional<llvm::raw_fd_ostream> OS;
if (canUseTemporary.get()) {
temporaryPath = tryToOpenTemporaryFile(OS, outputPath, openFlags);
temporaryPath = tryToOpenTemporaryFile(OS, outputPath);

if (!temporaryPath) {
assert(!OS.hasValue());
Expand All @@ -149,7 +144,7 @@ std::error_code swift::atomicallyWritingToFile(

if (!OS.hasValue()) {
std::error_code error;
OS.emplace(outputPath, error, openFlags);
OS.emplace(outputPath, error, fs::F_None);
if (error)
return error;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/FrontendTool/FrontendTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ static bool atomicallyWritingToTextFile(

bool actionFailed = false;
std::error_code EC =
swift::atomicallyWritingToFile(outputPath, /*binary*/false,
swift::atomicallyWritingToFile(outputPath,
[&](llvm::raw_pwrite_stream &out) {
actionFailed = action(out);
});
Expand Down
1 change: 0 additions & 1 deletion lib/Serialization/Serialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5084,7 +5084,6 @@ static inline bool
withOutputFile(ASTContext &ctx, StringRef outputPath,
llvm::function_ref<void(raw_ostream &)> action){
std::error_code EC = swift::atomicallyWritingToFile(outputPath,
/*binary*/true,
action);
if (!EC)
return false;
Expand Down