Skip to content

Commit cba3c23

Browse files
authored
Merge pull request #31865 from pi1024e/Clang-Fix
Invert if statement in filesystem for clearer intent.
2 parents f3cc6a5 + 67a98c5 commit cba3c23

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

lib/Basic/FileSystem.cpp

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,9 @@ std::error_code swift::atomicallyWritingToFile(
146146
if (!OS.hasValue()) {
147147
std::error_code error;
148148
OS.emplace(outputPath, error, fs::F_None);
149-
if (error)
149+
if (error) {
150150
return error;
151+
}
151152
}
152153

153154
action(OS.getValue());
@@ -169,8 +170,9 @@ swift::areFilesDifferent(const llvm::Twine &source,
169170
bool allowDestinationErrors) {
170171
namespace fs = llvm::sys::fs;
171172

172-
if (fs::equivalent(source, destination))
173+
if (fs::equivalent(source, destination)) {
173174
return FileDifference::IdenticalFile;
175+
}
174176

175177
OpenFileRAII sourceFile;
176178
fs::file_status sourceStatus;
@@ -187,8 +189,9 @@ swift::areFilesDifferent(const llvm::Twine &source,
187189
/// DifferentContents return, depending on `allowDestinationErrors`.
188190
auto convertDestinationError = [=](std::error_code error) ->
189191
llvm::ErrorOr<FileDifference> {
190-
if (allowDestinationErrors)
192+
if (allowDestinationErrors){
191193
return FileDifference::DifferentContents;
194+
}
192195
return error;
193196
};
194197

@@ -204,34 +207,39 @@ swift::areFilesDifferent(const llvm::Twine &source,
204207
}
205208

206209
uint64_t size = sourceStatus.getSize();
207-
if (size != destStatus.getSize())
210+
if (size != destStatus.getSize()) {
208211
// If the files are different sizes, they must be different.
209212
return FileDifference::DifferentContents;
210-
if (size == 0)
213+
}
214+
if (size == 0) {
211215
// If both files are zero size, they must be the same.
212216
return FileDifference::SameContents;
217+
}
213218

214219
// The two files match in size, so we have to compare the bytes to determine
215220
// if they're the same.
216221
std::error_code sourceRegionErr;
217222
fs::mapped_file_region sourceRegion(fs::convertFDToNativeFile(sourceFile.fd),
218223
fs::mapped_file_region::readonly,
219224
size, 0, sourceRegionErr);
220-
if (sourceRegionErr)
225+
if (sourceRegionErr) {
221226
return sourceRegionErr;
227+
}
222228

223229
std::error_code destRegionErr;
224230
fs::mapped_file_region destRegion(fs::convertFDToNativeFile(destFile.fd),
225231
fs::mapped_file_region::readonly,
226232
size, 0, destRegionErr);
227233

228-
if (destRegionErr)
234+
if (destRegionErr) {
229235
return convertDestinationError(destRegionErr);
236+
}
230237

231-
if (0 == memcmp(sourceRegion.const_data(), destRegion.const_data(), size))
232-
return FileDifference::SameContents;
238+
if (memcmp(sourceRegion.const_data(), destRegion.const_data(), size) != 0) {
239+
return FileDifference::DifferentContents;
240+
}
233241

234-
return FileDifference::DifferentContents;
242+
return FileDifference::SameContents;
235243
}
236244

237245
std::error_code swift::moveFileIfDifferent(const llvm::Twine &source,

0 commit comments

Comments
 (0)