aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTor Egge <Tor.Egge@online.no>2023-07-20 13:15:09 +0200
committerTor Egge <Tor.Egge@online.no>2023-07-20 13:15:09 +0200
commite4a9289e8caed1188b2c86a4535f0d7cf9d527a3 (patch)
tree8f2bc3b24df5d91e772c7689a5c1714b077bec6b
parent40117441c9553ee926309a86095452e3b330a2ab (diff)
Remove vespalib::symlink and vespalib::readLink
-rw-r--r--vespalib/src/tests/io/fileutil/fileutiltest.cpp62
-rw-r--r--vespalib/src/vespa/vespalib/io/fileutil.cpp28
-rw-r--r--vespalib/src/vespa/vespalib/io/fileutil.h25
3 files changed, 0 insertions, 115 deletions
diff --git a/vespalib/src/tests/io/fileutil/fileutiltest.cpp b/vespalib/src/tests/io/fileutil/fileutiltest.cpp
index 1f398c8e026..337c9052a66 100644
--- a/vespalib/src/tests/io/fileutil/fileutiltest.cpp
+++ b/vespalib/src/tests/io/fileutil/fileutiltest.cpp
@@ -247,68 +247,6 @@ TEST("require that copy constructor and assignment for vespalib::File works")
}
}
-TEST("require that vespalib::symlink works")
-{
- // Target exists
- {
- std::filesystem::remove_all(std::filesystem::path("mydir"));
- std::filesystem::create_directory(std::filesystem::path("mydir"));
-
- File f("mydir/myfile");
- f.open(File::CREATE | File::TRUNC);
- f.write("Hello World!\n", 13, 0);
- f.close();
-
- symlink("myfile", "mydir/linkyfile");
- EXPECT_TRUE(fileExists("mydir/linkyfile"));
-
- File f2("mydir/linkyfile");
- f2.open(File::READONLY);
- std::vector<char> vec(20, ' ');
- size_t read = f2.read(&vec[0], 20, 0);
- EXPECT_EQUAL(13u, read);
- EXPECT_EQUAL(std::string("Hello World!\n"), std::string(&vec[0], 13));
- }
-
- // POSIX symlink() fails
- {
- std::filesystem::remove_all(std::filesystem::path("mydir"));
- std::filesystem::create_directories(std::filesystem::path("mydir/a"));
- std::filesystem::create_directory(std::filesystem::path("mydir/b"));
- try {
- // Link already exists
- symlink("a", "mydir/b");
- TEST_FATAL("Exception not thrown on already existing link");
- } catch (IoException& e) {
- EXPECT_EQUAL(IoException::ALREADY_EXISTS, e.getType());
- }
- }
-
- {
- std::filesystem::remove_all(std::filesystem::path("mydir"));
- std::filesystem::create_directory(std::filesystem::path("mydir"));
-
- File f("mydir/myfile");
- f.open(File::CREATE | File::TRUNC);
- f.write("Hello World!\n", 13, 0);
- f.close();
- }
-
- // readLink success
- {
- symlink("myfile", "mydir/linkyfile");
- EXPECT_EQUAL("myfile", readLink("mydir/linkyfile"));
- }
- // readLink failure
- {
- try {
- readLink("no/such/link");
- } catch (IoException& e) {
- EXPECT_EQUAL(IoException::NOT_FOUND, e.getType());
- }
- }
-}
-
TEST("require that we can read all data written to file")
{
// Write text into a file.
diff --git a/vespalib/src/vespa/vespalib/io/fileutil.cpp b/vespalib/src/vespa/vespalib/io/fileutil.cpp
index 8e074744d15..1ff2d3434f7 100644
--- a/vespalib/src/vespa/vespalib/io/fileutil.cpp
+++ b/vespalib/src/vespa/vespalib/io/fileutil.cpp
@@ -449,34 +449,6 @@ getCurrentDirectory()
}
void
-symlink(const string & oldPath, const string & newPath)
-{
- if (::symlink(oldPath.c_str(), newPath.c_str())) {
- asciistream ss;
- const int err = errno;
- ss << "symlink(" << oldPath << ", " << newPath
- << "): Failed, errno(" << err << "): "
- << safeStrerror(err);
- throw IoException(ss.str(), IoException::getErrorType(err), VESPA_STRLOC);
- }
-}
-
-string
-readLink(const string & path)
-{
- char buf[256];
- ssize_t bytes(::readlink(path.c_str(), buf, sizeof(buf)));
- if (bytes < 0) {
- asciistream ss;
- const int err = errno;
- ss << "readlink(" << path << "): Failed, errno(" << err << "): "
- << safeStrerror(err);
- throw IoException(ss.str(), IoException::getErrorType(err), VESPA_STRLOC);
- }
- return string(buf, bytes);
-}
-
-void
chdir(const string & directory)
{
if (::chdir(directory.c_str()) != 0) {
diff --git a/vespalib/src/vespa/vespalib/io/fileutil.h b/vespalib/src/vespa/vespalib/io/fileutil.h
index d06ecd05ca9..6214bf3e60d 100644
--- a/vespalib/src/vespa/vespalib/io/fileutil.h
+++ b/vespalib/src/vespa/vespalib/io/fileutil.h
@@ -300,31 +300,6 @@ extern inline bool isSymLink(const vespalib::string & path) {
}
/**
- * Creates a symbolic link named newPath which contains the string oldPath.
- *
- * IMPORTANT: from the spec:
- * "Symbolic links are interpreted at run time as if the contents of the link had
- * been substituted into the path being followed to find a file or directory."
- *
- * This means oldPath is _relative_ to the directory in which newPath resides!
- *
- * @param oldPath Target of symbolic link.
- * @param newPath Relative link to be created. See above note for semantics.
- * @throw IoException if we fail to create the symlink.
- */
-extern void symlink(const vespalib::string & oldPath,
- const vespalib::string & newPath);
-
-/**
- * Read and return the contents of symbolic link at the given path.
- *
- * @param path Path to symbolic link.
- * @return Contents of symbolic link.
- * @throw IoException if we cannot read the link.
- */
-extern vespalib::string readLink(const vespalib::string & path);
-
-/**
* List the contents of the given directory.
*/
using DirectoryList = std::vector<vespalib::string>;