[PATCH] D41830: [libc++] Fix PR#35780 - make std::experimental::filesystem::remove return false if the file doesn't exist
Ekaterina Vaartis via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Jan 8 11:48:11 PST 2018
TyanNN created this revision.
TyanNN added a reviewer: EricWF.
Herald added a subscriber: cfe-commits.
Previously it thrown an error if the file didn't exist.
PR#35780
Repository:
rCXX libc++
https://reviews.llvm.org/D41830
Files:
src/experimental/filesystem/operations.cpp
test/libcxx/experimental/filesystem/class.path/path.remove/remove_should_not_throw.pass.cpp
Index: test/libcxx/experimental/filesystem/class.path/path.remove/remove_should_not_throw.pass.cpp
===================================================================
--- test/libcxx/experimental/filesystem/class.path/path.remove/remove_should_not_throw.pass.cpp
+++ test/libcxx/experimental/filesystem/class.path/path.remove/remove_should_not_throw.pass.cpp
@@ -0,0 +1,42 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++98, c++03
+
+// <experimental/filesystem>
+
+// class path
+
+#define _LIBCPP_DEBUG 0
+#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : (void)::AssertCount++)
+int AssertCount = 0;
+
+#include <experimental/filesystem>
+#include <cassert>
+#include <fstream>
+
+namespace fs = std::experimental::filesystem;
+
+int main()
+{
+ using namespace fs;
+
+ path nFile("nonexistant.file");
+ assert(remove(nFile) == false);
+
+ path tempFilePath = temp_directory_path();
+ tempFilePath += path("existingFile");
+
+ std::ofstream theTempFile(tempFilePath);
+ theTempFile.close();
+
+ assert(remove(tempFilePath) == true);
+
+ return 0;
+}
Index: src/experimental/filesystem/operations.cpp
===================================================================
--- src/experimental/filesystem/operations.cpp
+++ src/experimental/filesystem/operations.cpp
@@ -661,8 +661,9 @@
bool __remove(const path& p, std::error_code *ec) {
if (ec) ec->clear();
+
if (::remove(p.c_str()) == -1) {
- set_or_throw(ec, "remove", p);
+ if (errno != ENOENT) set_or_throw(ec, "remove", p);
return false;
}
return true;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D41830.128958.patch
Type: text/x-patch
Size: 1919 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180108/25d11829/attachment-0001.bin>
More information about the cfe-commits
mailing list