diff options
author | Tor Egge <Tor.Egge@online.no> | 2023-07-21 10:26:58 +0200 |
---|---|---|
committer | Tor Egge <Tor.Egge@online.no> | 2023-07-21 10:26:58 +0200 |
commit | a0a6e0137cc3741160a2d4d12905d65fac927cb0 (patch) | |
tree | 7dd49f685d04f92844cb65dae5cb9ce9bab32a25 /vespalib | |
parent | 535a452f4a968a73a1f3c1e6a18a1edb2d4ff2c2 (diff) |
Use std::filesystem::current_path
Diffstat (limited to 'vespalib')
-rw-r--r-- | vespalib/src/tests/fastos/file_test.cpp | 10 | ||||
-rw-r--r-- | vespalib/src/vespa/fastos/unix_file.cpp | 25 | ||||
-rw-r--r-- | vespalib/src/vespa/fastos/unix_file.h | 3 | ||||
-rw-r--r-- | vespalib/src/vespa/vespalib/io/fileutil.cpp | 24 | ||||
-rw-r--r-- | vespalib/src/vespa/vespalib/io/fileutil.h | 15 |
5 files changed, 0 insertions, 77 deletions
diff --git a/vespalib/src/tests/fastos/file_test.cpp b/vespalib/src/tests/fastos/file_test.cpp index 464861f5784..99c7b858723 100644 --- a/vespalib/src/tests/fastos/file_test.cpp +++ b/vespalib/src/tests/fastos/file_test.cpp @@ -18,16 +18,6 @@ struct Generated { ~Generated() { std::filesystem::remove_all(std::filesystem::path("generated")); } }; -TEST(FileTest, GetCurrentDirTest) { - std::string currentDir = FastOS_File::getCurrentDirectory(); - EXPECT_FALSE(currentDir.empty()); - EXPECT_TRUE(FastOS_File::SetCurrentDirectory("..")); - std::string parentDir = FastOS_File::getCurrentDirectory(); - EXPECT_FALSE(parentDir.empty()); - EXPECT_NE(currentDir, parentDir); - EXPECT_TRUE(FastOS_File::SetCurrentDirectory(currentDir.c_str())); -} - void MemoryMapTestImpl(int mmap_flags) { Generated guard; const int bufSize = 1000; diff --git a/vespalib/src/vespa/fastos/unix_file.cpp b/vespalib/src/vespa/fastos/unix_file.cpp index 9f61f6d517f..692674b95bd 100644 --- a/vespalib/src/vespa/fastos/unix_file.cpp +++ b/vespalib/src/vespa/fastos/unix_file.cpp @@ -116,9 +116,6 @@ FastOS_UNIX_File::Stat(const char *filename, FastOS_StatInfo *statInfo) return rc; } -bool FastOS_UNIX_File::SetCurrentDirectory (const char *pathName) { return (chdir(pathName) == 0); } - - int FastOS_UNIX_File::GetMaximumFilenameLength (const char *pathName) { return pathconf(pathName, _PC_NAME_MAX); @@ -129,28 +126,6 @@ int FastOS_UNIX_File::GetMaximumPathLength(const char *pathName) return pathconf(pathName, _PC_PATH_MAX); } -std::string -FastOS_UNIX_File::getCurrentDirectory() -{ - std::string res; - int maxPathLen = FastOS_File::GetMaximumPathLength("."); - if (maxPathLen == -1) { - maxPathLen = 16384; - } else if (maxPathLen < 512) { - maxPathLen = 512; - } - - char *currentDir = new char [maxPathLen + 1]; - - if (getcwd(currentDir, maxPathLen) != nullptr) { - res = currentDir; - } - delete [] currentDir; - - return res; -} - - unsigned int FastOS_UNIX_File::CalcAccessFlags(unsigned int openFlags) { diff --git a/vespalib/src/vespa/fastos/unix_file.h b/vespalib/src/vespa/fastos/unix_file.h index fc8d1ced69b..dad75dc561f 100644 --- a/vespalib/src/vespa/fastos/unix_file.h +++ b/vespalib/src/vespa/fastos/unix_file.h @@ -33,9 +33,6 @@ protected: public: static bool Stat(const char *filename, FastOS_StatInfo *statInfo); - static std::string getCurrentDirectory(); - - static bool SetCurrentDirectory (const char *pathName); static int GetMaximumFilenameLength (const char *pathName); static int GetMaximumPathLength (const char *pathName); diff --git a/vespalib/src/vespa/vespalib/io/fileutil.cpp b/vespalib/src/vespa/vespalib/io/fileutil.cpp index 2c817a2789b..6c169ab8d98 100644 --- a/vespalib/src/vespa/vespalib/io/fileutil.cpp +++ b/vespalib/src/vespa/vespalib/io/fileutil.cpp @@ -436,30 +436,6 @@ File::unlink() return std::filesystem::remove(std::filesystem::path(_filename)); } -string -getCurrentDirectory() -{ - MallocAutoPtr ptr = getcwd(0, 0); - if (ptr.get() != 0) { - return string(static_cast<char*>(ptr.get())); - } - asciistream ost; - ost << "getCurrentDirectory(): Failed, errno(" << errno << "): " << safeStrerror(errno); - throw IoException(ost.str(), IoException::getErrorType(errno), VESPA_STRLOC); -} - -void -chdir(const string & directory) -{ - if (::chdir(directory.c_str()) != 0) { - asciistream ost; - ost << "chdir(" << directory << "): Failed, errno(" << errno << "): " - << safeStrerror(errno); - throw IoException(ost.str(), IoException::getErrorType(errno), VESPA_STRLOC); - } - LOG(debug, "chdir(%s): Working directory changed.", directory.c_str()); -} - 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 f9769936122..4de36daa85f 100644 --- a/vespalib/src/vespa/vespalib/io/fileutil.h +++ b/vespalib/src/vespa/vespalib/io/fileutil.h @@ -209,21 +209,6 @@ public: }; /** - * Get the current working directory. - * - * @throw IoException On failure. - */ -extern vespalib::string getCurrentDirectory(); - -/** - * Change working directory. - * - * @param directory The directory to change to. - * @throw IoException If we failed to change to the new working directory. - */ -extern void chdir(const vespalib::string & directory); - -/** * List the contents of the given directory. */ using DirectoryList = std::vector<vespalib::string>; |