[llvm] dbc468d - [split-file] Fix sys::fs::remove() on Solaris after D83834

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 11 08:06:21 PDT 2020


Author: Fangrui Song
Date: 2020-08-11T08:05:10-07:00
New Revision: dbc468dc319953c86c2c564475f4939f66572810

URL: https://github.com/llvm/llvm-project/commit/dbc468dc319953c86c2c564475f4939f66572810
DIFF: https://github.com/llvm/llvm-project/commit/dbc468dc319953c86c2c564475f4939f66572810.diff

LOG: [split-file] Fix sys::fs::remove() on Solaris after D83834

where stdio.h ::remove() may set errno to EEXIST instead of ENOTEMPTY.

POSIX.1-2017 allows EEXIST for unlink() (which is called by remove()):

> [EEXIST] or [ENOTEMPTY]
> The flag parameter has the AT_REMOVEDIR bit set and the path argument names a directory that is not an empty directory, or there are hard links to the directory other than dot or a single entry in dot-dot.

Reviewed By: ro

Differential Revision: https://reviews.llvm.org/D85690

Added: 
    

Modified: 
    llvm/tools/split-file/split-file.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/tools/split-file/split-file.cpp b/llvm/tools/split-file/split-file.cpp
index 772a19164dc4..a012b4a190f8 100644
--- a/llvm/tools/split-file/split-file.cpp
+++ b/llvm/tools/split-file/split-file.cpp
@@ -166,7 +166,8 @@ int main(int argc, const char **argv) {
       status.type() != sys::fs::file_type::regular_file)
     fatal(output, "output cannot be a special file");
   if (std::error_code ec = sys::fs::remove(output, /*IgnoreNonExisting=*/true))
-    if (ec.value() != static_cast<int>(std::errc::directory_not_empty))
+    if (ec.value() != static_cast<int>(std::errc::directory_not_empty) &&
+        ec.value() != static_cast<int>(std::errc::file_exists))
       fatal(output, ec.message());
   return handle(**bufferOrErr, input);
 }


        


More information about the llvm-commits mailing list