aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTor Egge <Tor.Egge@online.no>2023-07-20 12:07:32 +0200
committerTor Egge <Tor.Egge@online.no>2023-07-20 12:07:32 +0200
commitd204d68fc019e2b8884d64b9107524c142ecd924 (patch)
tree56430815e2e80fbc2edeaf5175062bd08d24cf77
parent55965f0014ebcf000b680e5464fa7ee7c3c06029 (diff)
Remove vespalib::unlink.
-rw-r--r--vespalib/src/tests/io/fileutil/fileutiltest.cpp37
-rw-r--r--vespalib/src/vespa/vespalib/io/fileutil.cpp18
-rw-r--r--vespalib/src/vespa/vespalib/io/fileutil.h9
3 files changed, 5 insertions, 59 deletions
diff --git a/vespalib/src/tests/io/fileutil/fileutiltest.cpp b/vespalib/src/tests/io/fileutil/fileutiltest.cpp
index 5a62e257032..1f398c8e026 100644
--- a/vespalib/src/tests/io/fileutil/fileutiltest.cpp
+++ b/vespalib/src/tests/io/fileutil/fileutiltest.cpp
@@ -34,7 +34,7 @@ TEST("require that vespalib::File::open works")
{
// Opening non-existing file for reading should fail.
try{
- unlink("myfile"); // Just in case
+ std::filesystem::remove(std::filesystem::path("myfile")); // Just in case
File f("myfile");
f.open(File::READONLY);
TEST_FATAL("Opening non-existing file for reading should fail.");
@@ -155,7 +155,7 @@ TEST("require that vespalib::File::isOpen works")
TEST("require that vespalib::File::stat works")
{
- unlink("myfile");
+ std::filesystem::remove(std::filesystem::path("myfile"));
std::filesystem::remove_all(std::filesystem::path("mydir"));
EXPECT_EQUAL(false, fileExists("myfile"));
EXPECT_EQUAL(false, fileExists("mydir"));
@@ -188,7 +188,7 @@ TEST("require that vespalib::File::stat works")
TEST("require that vespalib::File::resize works")
{
- unlink("myfile");
+ std::filesystem::remove(std::filesystem::path("myfile"));
File f("myfile");
f.open(File::CREATE, false);
f.write("foobar", 6, 0);
@@ -206,35 +206,6 @@ TEST("require that vespalib::File::resize works")
EXPECT_EQUAL(std::string("foo"), std::string(&vec[0], 3));
}
-TEST("require that vespalib::unlink works")
-{
- // Fails on directory
- try{
- std::filesystem::create_directory(std::filesystem::path("mydir"));
- unlink("mydir");
- TEST_FATAL("Should work on directories.");
- } catch (IoException& e) {
- //std::cerr << e.what() << "\n";
-#ifdef __APPLE__
- EXPECT_EQUAL(IoException::NO_PERMISSION, e.getType());
-#else
- EXPECT_EQUAL(IoException::ILLEGAL_PATH, e.getType());
-#endif
- }
- // Works for file
- {
- {
- File f("myfile");
- f.open(File::CREATE);
- f.write("foo", 3, 0);
- }
- ASSERT_TRUE(fileExists("myfile"));
- ASSERT_TRUE(unlink("myfile"));
- ASSERT_TRUE(!fileExists("myfile"));
- ASSERT_TRUE(!unlink("myfile"));
- }
-}
-
TEST("require that copy constructor and assignment for vespalib::File works")
{
// Copy file not opened.
@@ -341,7 +312,7 @@ TEST("require that vespalib::symlink works")
TEST("require that we can read all data written to file")
{
// Write text into a file.
- unlink("myfile");
+ std::filesystem::remove(std::filesystem::path("myfile"));
File fileForWriting("myfile");
fileForWriting.open(File::CREATE);
vespalib::string text = "This is some text. ";
diff --git a/vespalib/src/vespa/vespalib/io/fileutil.cpp b/vespalib/src/vespa/vespalib/io/fileutil.cpp
index 491e07e2491..8e074744d15 100644
--- a/vespalib/src/vespa/vespalib/io/fileutil.cpp
+++ b/vespalib/src/vespa/vespalib/io/fileutil.cpp
@@ -433,7 +433,7 @@ bool
File::unlink()
{
close();
- return vespalib::unlink(_filename);
+ return std::filesystem::remove(std::filesystem::path(_filename));
}
string
@@ -507,22 +507,6 @@ fileExists(const string & path) {
return (stat(path).get() != 0);
}
-bool
-unlink(const string & filename)
-{
- if (::unlink(filename.c_str()) != 0) {
- if (errno == ENOENT) {
- return false;
- }
- asciistream ost;
- ost << "unlink(" << filename << "): Failed, errno(" << errno << "): "
- << safeStrerror(errno);
- throw IoException(ost.str(), IoException::getErrorType(errno), VESPA_STRLOC);
- }
- LOG(debug, "unlink(%s): File deleted.", filename.c_str());
- return true;
-}
-
namespace {
uint32_t diskAlignmentSize = 4_Ki;
diff --git a/vespalib/src/vespa/vespalib/io/fileutil.h b/vespalib/src/vespa/vespalib/io/fileutil.h
index faffc739720..d06ecd05ca9 100644
--- a/vespalib/src/vespa/vespalib/io/fileutil.h
+++ b/vespalib/src/vespa/vespalib/io/fileutil.h
@@ -325,15 +325,6 @@ extern void symlink(const vespalib::string & oldPath,
extern vespalib::string readLink(const vespalib::string & path);
/**
- * Remove the given file.
- *
- * @param filename name of file.
- * @return True if file was removed, false if it did not exist.
- * @throw IoException If we failed to unlink the file.
- */
-extern bool unlink(const vespalib::string & filename);
-
-/**
* List the contents of the given directory.
*/
using DirectoryList = std::vector<vespalib::string>;