From e4a9289e8caed1188b2c86a4535f0d7cf9d527a3 Mon Sep 17 00:00:00 2001 From: Tor Egge Date: Thu, 20 Jul 2023 13:15:09 +0200 Subject: Remove vespalib::symlink and vespalib::readLink --- vespalib/src/tests/io/fileutil/fileutiltest.cpp | 62 ------------------------- vespalib/src/vespa/vespalib/io/fileutil.cpp | 28 ----------- vespalib/src/vespa/vespalib/io/fileutil.h | 25 ---------- 3 files changed, 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 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 @@ -448,34 +448,6 @@ getCurrentDirectory() throw IoException(ost.str(), IoException::getErrorType(errno), VESPA_STRLOC); } -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) { 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 @@ -299,31 +299,6 @@ extern inline bool isSymLink(const vespalib::string & path) { return (info.get() && info->_symlink); } -/** - * 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. */ -- cgit v1.2.3