diff options
author | Vlad Yaroslavlev <vladon@vladon.com> | 2022-02-10 16:46:23 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:46:23 +0300 |
commit | 706b83ed7de5a473436620367af31fc0ceecde07 (patch) | |
tree | 103305d30dec77e8f6367753367f59b3cd68f9f1 /util/folder | |
parent | 918e8a1574070d0ec733f0b76cfad8f8892ad2e5 (diff) | |
download | ydb-706b83ed7de5a473436620367af31fc0ceecde07.tar.gz |
Restoring authorship annotation for Vlad Yaroslavlev <vladon@vladon.com>. Commit 1 of 2.
Diffstat (limited to 'util/folder')
-rw-r--r-- | util/folder/dirut.cpp | 44 | ||||
-rw-r--r-- | util/folder/dirut.h | 36 | ||||
-rw-r--r-- | util/folder/dirut_ut.cpp | 2 | ||||
-rw-r--r-- | util/folder/filelist.cpp | 2 | ||||
-rw-r--r-- | util/folder/filelist.h | 8 | ||||
-rw-r--r-- | util/folder/filelist_ut.cpp | 12 | ||||
-rw-r--r-- | util/folder/fts_ut.cpp | 2 | ||||
-rw-r--r-- | util/folder/iterator.cpp | 2 | ||||
-rw-r--r-- | util/folder/iterator.h | 14 | ||||
-rw-r--r-- | util/folder/iterator_ut.cpp | 42 | ||||
-rw-r--r-- | util/folder/path.cpp | 36 | ||||
-rw-r--r-- | util/folder/path.h | 34 | ||||
-rw-r--r-- | util/folder/path_ut.cpp | 56 | ||||
-rw-r--r-- | util/folder/pathsplit.cpp | 6 | ||||
-rw-r--r-- | util/folder/pathsplit.h | 12 | ||||
-rw-r--r-- | util/folder/tempdir.cpp | 2 | ||||
-rw-r--r-- | util/folder/tempdir.h | 8 |
17 files changed, 159 insertions, 159 deletions
diff --git a/util/folder/dirut.cpp b/util/folder/dirut.cpp index ffc9b09f96..84d0093241 100644 --- a/util/folder/dirut.cpp +++ b/util/folder/dirut.cpp @@ -11,12 +11,12 @@ #include <util/system/maxlen.h> #include <util/system/yassert.h> -void SlashFolderLocal(TString& folder) { +void SlashFolderLocal(TString& folder) { if (!folder) return; #ifdef _win32_ size_t pos; - while ((pos = folder.find('/')) != TString::npos) + while ((pos = folder.find('/')) != TString::npos) folder.replace(pos, 1, LOCSLASH_S); #endif if (folder[folder.size() - 1] != LOCSLASH_C) @@ -25,11 +25,11 @@ void SlashFolderLocal(TString& folder) { #ifndef _win32_ -bool correctpath(TString& folder) { +bool correctpath(TString& folder) { return resolvepath(folder, "/"); } -bool resolvepath(TString& folder, const TString& home) { +bool resolvepath(TString& folder, const TString& home) { Y_ASSERT(home && home.at(0) == '/'); if (!folder) { return false; @@ -348,7 +348,7 @@ int resolvepath(char* apath, const char* rpath, const char* cpath) { return correctpath(apath, tpath); } -bool correctpath(TString& filename) { +bool correctpath(TString& filename) { char* ptr = (char*)alloca(filename.size() + 2); if (correctpath(ptr, filename.data())) { filename = ptr; @@ -357,7 +357,7 @@ bool correctpath(TString& filename) { return false; } -bool resolvepath(TString& folder, const TString& home) { +bool resolvepath(TString& folder, const TString& home) { char* ptr = (char*)alloca(folder.size() + 3 + home.size()); if (resolvepath(ptr, folder.data(), home.data())) { folder = ptr; @@ -376,7 +376,7 @@ const char* GetDirectorySeparatorS() { return LOCSLASH_S; } -void RemoveDirWithContents(TString dirName) { +void RemoveDirWithContents(TString dirName) { SlashFolderLocal(dirName); TDirIterator dir(dirName, TDirIterator::TOptions(FTS_NOSTAT)); @@ -402,7 +402,7 @@ int mkpath(char* path, int mode) { // Implementation of realpath in FreeBSD (version 9.0 and less) and GetFullPathName in Windows // did not require last component of the file name to exist (other implementations will fail // if it does not). Use RealLocation if that behaviour is required. -TString RealPath(const TString& path) { +TString RealPath(const TString& path) { TTempBuf result; Y_ASSERT(result.Size() > MAX_PATH); //TMP_BUF_LEN > MAX_PATH #ifdef _win_ @@ -414,10 +414,10 @@ TString RealPath(const TString& path) { return result.Data(); } -TString RealLocation(const TString& path) { +TString RealLocation(const TString& path) { if (NFs::Exists(path)) return RealPath(path); - TString dirpath = GetDirName(path); + TString dirpath = GetDirName(path); if (NFs::Exists(dirpath)) return RealPath(dirpath) + GetDirectorySeparatorS() + GetFileNameComponent(path.data()); ythrow TFileError() << "RealLocation failed \"" << path << "\""; @@ -426,7 +426,7 @@ TString RealLocation(const TString& path) { int MakeTempDir(char path[/*FILENAME_MAX*/], const char* prefix) { int ret; - TString sysTmp; + TString sysTmp; #ifdef _win32_ if (!prefix || *prefix == '/') { @@ -449,12 +449,12 @@ int MakeTempDir(char path[/*FILENAME_MAX*/], const char* prefix) { return 0; } -bool IsDir(const TString& path) { +bool IsDir(const TString& path) { return TFileStat(path).IsDir(); } -TString GetHomeDir() { - TString s(getenv("HOME")); +TString GetHomeDir() { + TString s(getenv("HOME")); if (!s) { #ifndef _win32_ passwd* pw = nullptr; @@ -505,14 +505,14 @@ const char* GetFileNameComponent(const char* f) { return f; } -TString GetSystemTempDir() { +TString GetSystemTempDir() { #ifdef _win_ char buffer[1024]; DWORD size = GetTempPath(1024, buffer); if (!size) { ythrow TSystemError() << "failed to get system temporary directory"; } - return TString(buffer, size); + return TString(buffer, size); #else const char* var = "TMPDIR"; const char* def = "/tmp"; @@ -522,11 +522,11 @@ TString GetSystemTempDir() { #endif } -TString ResolveDir(const char* path) { +TString ResolveDir(const char* path) { return ResolvePath(path, true); } -bool SafeResolveDir(const char* path, TString& result) { +bool SafeResolveDir(const char* path, TString& result) { try { result = ResolvePath(path, true); return true; @@ -535,7 +535,7 @@ bool SafeResolveDir(const char* path, TString& result) { } } -TString GetDirName(const TString& path) { +TString GetDirName(const TString& path) { return TFsPath(path).Dirname(); } @@ -548,7 +548,7 @@ char* realpath(const char* pathname, char resolved_path[MAXPATHLEN]) { #endif -TString GetBaseName(const TString& path) { +TString GetBaseName(const TString& path) { return TFsPath(path).Basename(); } @@ -612,8 +612,8 @@ TString ResolvePath(const char* path, bool isDir) { return ResolvePath(path, nullptr, isDir); } -TString StripFileComponent(const TString& fileName) { - TString dir = IsDir(fileName) ? fileName : GetDirName(fileName); +TString StripFileComponent(const TString& fileName) { + TString dir = IsDir(fileName) ? fileName : GetDirName(fileName); if (!dir.empty() && dir.back() != GetDirectorySeparator()) { dir.append(GetDirectorySeparator()); } diff --git a/util/folder/dirut.h b/util/folder/dirut.h index 2537027b12..f523aa085e 100644 --- a/util/folder/dirut.h +++ b/util/folder/dirut.h @@ -3,7 +3,7 @@ #include <util/system/defaults.h> #include <util/system/sysstat.h> #include <util/system/fs.h> -#include <util/generic/string.h> +#include <util/generic/string.h> #include <util/generic/yexception.h> #include <sys/types.h> @@ -37,57 +37,57 @@ char* mkdtemp(char* path); #endif #endif -bool IsDir(const TString& path); +bool IsDir(const TString& path); int mkpath(char* path, int mode = 0777); -TString GetHomeDir(); +TString GetHomeDir(); void MakeDirIfNotExist(const char* path, int mode = 0777); -inline void MakeDirIfNotExist(const TString& path, int mode = 0777) { +inline void MakeDirIfNotExist(const TString& path, int mode = 0777) { MakeDirIfNotExist(path.data(), mode); } /// Create path making parent directories as needed void MakePathIfNotExist(const char* path, int mode = 0777); -void SlashFolderLocal(TString& folder); -bool correctpath(TString& filename); -bool resolvepath(TString& folder, const TString& home); +void SlashFolderLocal(TString& folder); +bool correctpath(TString& filename); +bool resolvepath(TString& folder, const TString& home); char GetDirectorySeparator(); const char* GetDirectorySeparatorS(); -void RemoveDirWithContents(TString dirName); +void RemoveDirWithContents(TString dirName); const char* GetFileNameComponent(const char* f); -inline TString GetFileNameComponent(const TString& f) { +inline TString GetFileNameComponent(const TString& f) { return GetFileNameComponent(f.data()); } /// RealPath doesn't guarantee trailing separator to be stripped or left in place for directories. -TString RealPath(const TString& path); // throws -TString RealLocation(const TString& path); /// throws; last file name component doesn't need to exist +TString RealPath(const TString& path); // throws +TString RealLocation(const TString& path); /// throws; last file name component doesn't need to exist -TString GetSystemTempDir(); +TString GetSystemTempDir(); int MakeTempDir(char path[/*FILENAME_MAX*/], const char* prefix); int ResolvePath(const char* rel, const char* abs, char res[/*FILENAME_MAX*/], bool isdir = false); TString ResolvePath(const char* rel, const char* abs, bool isdir = false); -TString ResolvePath(const char* path, bool isDir = false); +TString ResolvePath(const char* path, bool isDir = false); -TString ResolveDir(const char* path); +TString ResolveDir(const char* path); -bool SafeResolveDir(const char* path, TString& result); +bool SafeResolveDir(const char* path, TString& result); -TString GetDirName(const TString& path); +TString GetDirName(const TString& path); -TString GetBaseName(const TString& path); +TString GetBaseName(const TString& path); -TString StripFileComponent(const TString& fileName); +TString StripFileComponent(const TString& fileName); class TExistenceChecker { public: diff --git a/util/folder/dirut_ut.cpp b/util/folder/dirut_ut.cpp index 45ebfc842c..9afcf03621 100644 --- a/util/folder/dirut_ut.cpp +++ b/util/folder/dirut_ut.cpp @@ -3,7 +3,7 @@ #include <library/cpp/testing/unittest/registar.h> -#include <util/generic/string.h> +#include <util/generic/string.h> #include <util/memory/tempbuf.h> #include <util/stream/file.h> #include <util/system/platform.h> diff --git a/util/folder/filelist.cpp b/util/folder/filelist.cpp index b21fcdbf20..beb543734c 100644 --- a/util/folder/filelist.cpp +++ b/util/folder/filelist.cpp @@ -4,7 +4,7 @@ #include <util/system/defaults.h> -void TFileEntitiesList::Fill(const TString& dirname, TStringBuf prefix, TStringBuf suffix, int depth, bool sort) { +void TFileEntitiesList::Fill(const TString& dirname, TStringBuf prefix, TStringBuf suffix, int depth, bool sort) { TDirIterator::TOptions opts; opts.SetMaxLevel(depth); if (sort) { diff --git a/util/folder/filelist.h b/util/folder/filelist.h index 3f615fa4c2..1228a08613 100644 --- a/util/folder/filelist.h +++ b/util/folder/filelist.h @@ -1,7 +1,7 @@ #pragma once #include <util/generic/buffer.h> -#include <util/generic/string.h> +#include <util/generic/string.h> #include <util/generic/strbuf.h> #include <util/generic/flags.h> @@ -40,15 +40,15 @@ public: return FileNamesSize; } - inline void Fill(const TString& dirname, bool sort = false) { + inline void Fill(const TString& dirname, bool sort = false) { Fill(dirname, TStringBuf(), sort); } - inline void Fill(const TString& dirname, TStringBuf prefix, bool sort = false) { + inline void Fill(const TString& dirname, TStringBuf prefix, bool sort = false) { Fill(dirname, prefix, TStringBuf(), 1, sort); } - void Fill(const TString& dirname, TStringBuf prefix, TStringBuf suffix, int depth, bool sort = false); + void Fill(const TString& dirname, TStringBuf prefix, TStringBuf suffix, int depth, bool sort = false); void Restart() { Cur = FileNames.Data(); diff --git a/util/folder/filelist_ut.cpp b/util/folder/filelist_ut.cpp index 0cdcdf3d00..60db164e56 100644 --- a/util/folder/filelist_ut.cpp +++ b/util/folder/filelist_ut.cpp @@ -5,7 +5,7 @@ #include <library/cpp/testing/unittest/registar.h> #include <util/system/file.h> -#include <util/generic/string.h> +#include <util/generic/string.h> class TFileListTest: public TTestBase { UNIT_TEST_SUITE(TFileListTest); @@ -25,7 +25,7 @@ void TFileListTest::TestSimple() { TFileList fileList; fileList.Fill(tempDir().data(), "", "", 1000); - TString fileName(fileList.Next()); + TString fileName(fileList.Next()); UNIT_ASSERT_EQUAL(fileName, "subdir" LOCSLASH_S "file"); UNIT_ASSERT_EQUAL(fileList.Next(), nullptr); } @@ -41,14 +41,14 @@ void TFileListTest::TestPrefix() { TFileList fileList; { fileList.Fill(tempDir().data(), "good_file", SORT); - UNIT_ASSERT_EQUAL(TString(fileList.Next()), "good_file1"); - UNIT_ASSERT_EQUAL(TString(fileList.Next()), "good_file2"); + UNIT_ASSERT_EQUAL(TString(fileList.Next()), "good_file1"); + UNIT_ASSERT_EQUAL(TString(fileList.Next()), "good_file2"); UNIT_ASSERT_EQUAL(fileList.Next(), nullptr); } { fileList.Fill(tempDir().data(), "bad_file", SORT); - UNIT_ASSERT_EQUAL(TString(fileList.Next()), "bad_file1"); - UNIT_ASSERT_EQUAL(TString(fileList.Next()), "bad_file2"); + UNIT_ASSERT_EQUAL(TString(fileList.Next()), "bad_file1"); + UNIT_ASSERT_EQUAL(TString(fileList.Next()), "bad_file2"); UNIT_ASSERT_EQUAL(fileList.Next(), nullptr); } } diff --git a/util/folder/fts_ut.cpp b/util/folder/fts_ut.cpp index c5d59e35f4..a628efd90e 100644 --- a/util/folder/fts_ut.cpp +++ b/util/folder/fts_ut.cpp @@ -7,7 +7,7 @@ #include <util/system/file.h> #include <util/system/tempfile.h> -#include <util/generic/string.h> +#include <util/generic/string.h> class TFtsTest: public TTestBase { UNIT_TEST_SUITE(TFtsTest); diff --git a/util/folder/iterator.cpp b/util/folder/iterator.cpp index 73703d31f9..722238c67b 100644 --- a/util/folder/iterator.cpp +++ b/util/folder/iterator.cpp @@ -6,6 +6,6 @@ static int SortFTSENTByName(const FTSENT** a, const FTSENT** b) { return strcmp((*a)->fts_name, (*b)->fts_name); } -TDirIterator::TOptions& TDirIterator::TOptions::SetSortByName() noexcept { +TDirIterator::TOptions& TDirIterator::TOptions::SetSortByName() noexcept { return SetSortFunctor(SortFTSENTByName); } diff --git a/util/folder/iterator.h b/util/folder/iterator.h index 69e025b9c4..cce6aee8d4 100644 --- a/util/folder/iterator.h +++ b/util/folder/iterator.h @@ -11,7 +11,7 @@ class TDirIterator: public TInputRangeAdaptor<TDirIterator> { struct TFtsDestroy { - static inline void Destroy(FTS* f) noexcept { + static inline void Destroy(FTS* f) noexcept { yfts_close(f); } }; @@ -36,33 +36,33 @@ public: Init(opts); } - inline TOptions& SetMaxLevel(size_t level) noexcept { + inline TOptions& SetMaxLevel(size_t level) noexcept { MaxLevel = level; return *this; } - inline TOptions& SetSortFunctor(TCompare cmp) noexcept { + inline TOptions& SetSortFunctor(TCompare cmp) noexcept { Cmp = cmp; return *this; } - TOptions& SetSortByName() noexcept; + TOptions& SetSortByName() noexcept; int FtsOptions; size_t MaxLevel; TCompare Cmp; private: - inline void Init(int opts) noexcept { + inline void Init(int opts) noexcept { FtsOptions = opts | FTS_NOCHDIR; MaxLevel = Max<size_t>(); Cmp = nullptr; } }; - inline TDirIterator(const TString& path, const TOptions& options = TOptions()) + inline TDirIterator(const TString& path, const TOptions& options = TOptions()) : Options_(options) , Path_(path) { @@ -103,7 +103,7 @@ public: private: TOptions Options_; - TString Path_; + TString Path_; char* Trees_[2]; THolder<FTS, TFtsDestroy> FileTree_; }; diff --git a/util/folder/iterator_ut.cpp b/util/folder/iterator_ut.cpp index 936becd139..0cae693ef6 100644 --- a/util/folder/iterator_ut.cpp +++ b/util/folder/iterator_ut.cpp @@ -9,7 +9,7 @@ #include <util/generic/algorithm.h> #include <util/random/mersenne.h> -static TString JoinWithNewline(const TVector<TString>& strings) { +static TString JoinWithNewline(const TVector<TString>& strings) { TStringStream ss; for (const auto& string : strings) { ss << string << "\n"; @@ -30,19 +30,19 @@ private: class TDirHier { public: struct TPath { - TString Path; + TString Path; int Type; }; - inline void AddFile(const TString& path) { + inline void AddFile(const TString& path) { Add(path, 0); } - inline void AddDir(const TString& path) { + inline void AddDir(const TString& path) { Add(path, 1); } - inline void Add(const TString& path, int type) { + inline void Add(const TString& path, int type) { const TPath p = { path, type}; @@ -67,15 +67,15 @@ private: Srch_[path.Path] = path; } - inline int Type(const TString& path) { - THashMap<TString, TPath>::const_iterator it = Srch_.find(path); + inline int Type(const TString& path) { + THashMap<TString, TPath>::const_iterator it = Srch_.find(path); UNIT_ASSERT(it != Srch_.end()); return it->second.Type; } - inline bool Have(const TString& path, int type) { + inline bool Have(const TString& path, int type) { return Type(path) == type; } @@ -86,12 +86,12 @@ private: } private: - TVector<TPath> Paths_; - THashMap<TString, TPath> Srch_; + TVector<TPath> Paths_; + THashMap<TString, TPath> Srch_; }; inline void TestLocal() { - TString dirname("." LOCSLASH_S); + TString dirname("." LOCSLASH_S); TDirIterator d(dirname, FTS_NOCHDIR); for (auto it = d.begin(); it != d.end(); ++it) { } @@ -100,26 +100,26 @@ private: inline void TestIt() { TDirHier hier; - const TString dir = "tmpdir"; + const TString dir = "tmpdir"; const TDirHier::TPath path = {dir, 1}; hier.Add(path); for (size_t i = 0; i < 10; ++i) { - const TString dir1 = dir + LOCSLASH_C + ToString(i); + const TString dir1 = dir + LOCSLASH_C + ToString(i); const TDirHier::TPath path1 = {dir1, 1}; hier.Add(path1); for (size_t j = 0; j < 10; ++j) { - const TString subdir2 = ToString(j); - const TString dir2 = dir1 + LOCSLASH_C + subdir2; + const TString subdir2 = ToString(j); + const TString dir2 = dir1 + LOCSLASH_C + subdir2; const TDirHier::TPath path2 = {dir2, 1}; hier.Add(path2); for (size_t k = 0; k < 3; ++k) { - const TString file = dir2 + LOCSLASH_C + "file" + ToString(k); + const TString file = dir2 + LOCSLASH_C + "file" + ToString(k); const TDirHier::TPath fpath = {file, 0}; hier.Add(fpath); @@ -175,24 +175,24 @@ private: inline void TestSort() { TDirHier dh; - const TString dir("tmpdir"); + const TString dir("tmpdir"); //prepare fs { TMersenne<ui32> rnd; - const TString prefixes[] = { + const TString prefixes[] = { "a", "b", "xxx", "111", ""}; dh.AddDir(dir); for (size_t i = 0; i < 100; ++i) { - const TString fname = dir + LOCSLASH_C + prefixes[i % Y_ARRAY_SIZE(prefixes)] + ToString(rnd.GenRand()); + const TString fname = dir + LOCSLASH_C + prefixes[i % Y_ARRAY_SIZE(prefixes)] + ToString(rnd.GenRand()); dh.AddFile(fname); } } - TVector<TString> fnames; + TVector<TString> fnames; { TDirIterator d(dir, TDirIterator::TOptions().SetSortByName()); @@ -204,7 +204,7 @@ private: } } - TVector<TString> sorted(fnames); + TVector<TString> sorted(fnames); Sort(sorted.begin(), sorted.end()); UNIT_ASSERT_VALUES_EQUAL(JoinWithNewline(fnames), JoinWithNewline(sorted)); diff --git a/util/folder/path.cpp b/util/folder/path.cpp index bfe0c67d68..e239276067 100644 --- a/util/folder/path.cpp +++ b/util/folder/path.cpp @@ -89,7 +89,7 @@ TFsPath TFsPath::RelativePath(const TFsPath& root) const { if (cnt == 0 && !absboth) { ythrow TIoException() << "No common parts in " << *this << " and " << root; } - TString r; + TString r; for (size_t i = 0; i < rsplit.size() - cnt; i++) { r += i == 0 ? ".." : "/.."; } @@ -139,16 +139,16 @@ TFsPath& TFsPath::Fix() { return *this; } -TString TFsPath::GetName() const { +TString TFsPath::GetName() const { if (!IsDefined()) { - return TString(); + return TString(); } const TSplit& split = GetSplit(); if (split.size() > 0) { if (split.back() != "..") { - return TString(split.back()); + return TString(split.back()); } else { // cannot just drop last component, because path itself may be a symlink return RealPath().GetName(); @@ -162,8 +162,8 @@ TString TFsPath::GetName() const { } } -TString TFsPath::GetExtension() const { - return TString(GetSplit().Extension()); +TString TFsPath::GetExtension() const { + return TString(GetSplit().Extension()); } bool TFsPath::IsAbsolute() const { @@ -193,7 +193,7 @@ static Y_FORCE_INLINE void VerifyPath(const TStringBuf path) { TFsPath::TFsPath() { } -TFsPath::TFsPath(const TString& path) +TFsPath::TFsPath(const TString& path) : Path_(path) { VerifyPath(Path_); @@ -210,7 +210,7 @@ TFsPath::TFsPath(const char* path) { } -TFsPath TFsPath::Child(const TString& name) const { +TFsPath TFsPath::Child(const TString& name) const { if (!name) { ythrow TIoException() << "child name must not be empty"; } @@ -228,7 +228,7 @@ struct TClosedir { } }; -void TFsPath::ListNames(TVector<TString>& children) const { +void TFsPath::ListNames(TVector<TString>& children) const { CheckDefined(); THolder<DIR, TClosedir> dir(opendir(this->c_str())); if (!dir) { @@ -250,7 +250,7 @@ void TFsPath::ListNames(TVector<TString>& children) const { if (ok == nullptr) { return; } - TString name(de.d_name); + TString name(de.d_name); if (name == "." || name == "..") { continue; } @@ -275,15 +275,15 @@ bool TFsPath::Contains(const TString& component) const { return false; } -void TFsPath::List(TVector<TFsPath>& files) const { - TVector<TString> names; +void TFsPath::List(TVector<TFsPath>& files) const { + TVector<TString> names; ListNames(names); for (auto& name : names) { files.push_back(Child(name)); } } -void TFsPath::RenameTo(const TString& newPath) const { +void TFsPath::RenameTo(const TString& newPath) const { CheckDefined(); if (!newPath) { ythrow TIoException() << "bad new file name"; @@ -294,7 +294,7 @@ void TFsPath::RenameTo(const TString& newPath) const { } void TFsPath::RenameTo(const char* newPath) const { - RenameTo(TString(newPath)); + RenameTo(TString(newPath)); } void TFsPath::RenameTo(const TFsPath& newPath) const { @@ -407,7 +407,7 @@ void TFsPath::ForceDelete() const { ClearLastSystemError(); if (stat.IsDir()) { - TVector<TFsPath> children; + TVector<TFsPath> children; List(children); for (auto& i : children) { i.ForceDelete(); @@ -422,14 +422,14 @@ void TFsPath::ForceDelete() const { } } -void TFsPath::CopyTo(const TString& newPath, bool force) const { +void TFsPath::CopyTo(const TString& newPath, bool force) const { if (IsDirectory()) { if (force) { TFsPath(newPath).MkDirs(); } else if (!TFsPath(newPath).IsDirectory()) { ythrow TIoException() << "Target path is not a directory " << newPath; } - TVector<TFsPath> children; + TVector<TFsPath> children; List(children); for (auto&& i : children) { i.CopyTo(newPath + "/" + i.GetName(), force); @@ -449,7 +449,7 @@ void TFsPath::CopyTo(const TString& newPath, bool force) const { } } -void TFsPath::ForceRenameTo(const TString& newPath) const { +void TFsPath::ForceRenameTo(const TString& newPath) const { try { RenameTo(newPath); } catch (const TIoSystemError& /* error */) { diff --git a/util/folder/path.h b/util/folder/path.h index 2fb4d6b4ef..1c98714492 100644 --- a/util/folder/path.h +++ b/util/folder/path.h @@ -5,7 +5,7 @@ #include <util/generic/ptr.h> #include <util/generic/strbuf.h> -#include <util/generic/string.h> +#include <util/generic/string.h> #include <util/generic/vector.h> #include <util/string/cast.h> #include <util/system/fstat.h> @@ -25,7 +25,7 @@ private: public: TFsPath(); - TFsPath(const TString& path); + TFsPath(const TString& path); TFsPath(const TStringBuf path); TFsPath(const char* path); @@ -48,7 +48,7 @@ public: return Path_.c_str(); } - inline operator const TString&() const { + inline operator const TString&() const { return Path_; } @@ -71,19 +71,19 @@ public: TFsPath& Fix(); - inline const TString& GetPath() const { + inline const TString& GetPath() const { return Path_; } /// last component of path, or "/" if root - TString GetName() const; + TString GetName() const; /** * "a.b.tmp" -> "tmp" * "a.tmp" -> "tmp" * ".tmp" -> "" */ - TString GetExtension() const; + TString GetExtension() const; bool IsAbsolute() const; bool IsRelative() const; @@ -126,14 +126,14 @@ public: */ TFsPath Parent() const; - TString Basename() const { + TString Basename() const { return GetName(); } - TString Dirname() const { + TString Dirname() const { return Parent(); } - TFsPath Child(const TString& name) const; + TFsPath Child(const TString& name) const; /** * @brief create this directory @@ -152,8 +152,8 @@ public: void MkDirs(const int mode = MODE0777) const; // XXX: rewrite to return iterator - void List(TVector<TFsPath>& children) const; - void ListNames(TVector<TString>& children) const; + void List(TVector<TFsPath>& children) const; + void ListNames(TVector<TString>& children) const; // Check, if path contains at least one component with a specific name. bool Contains(const TString& component) const; @@ -181,12 +181,12 @@ public: /// throw TIoException if not exists void CheckExists() const; - void RenameTo(const TString& newPath) const; + void RenameTo(const TString& newPath) const; void RenameTo(const char* newPath) const; void RenameTo(const TFsPath& newFile) const; - void ForceRenameTo(const TString& newPath) const; + void ForceRenameTo(const TString& newPath) const; - void CopyTo(const TString& newPath, bool force) const; + void CopyTo(const TString& newPath, bool force) const; void Touch() const; @@ -197,7 +197,7 @@ public: /// always absolute static TFsPath Cwd(); - inline void Swap(TFsPath& p) noexcept { + inline void Swap(TFsPath& p) noexcept { DoSwap(Path_, p.Path_); Split_.Swap(p.Split_); } @@ -207,7 +207,7 @@ private: TSplit& GetSplit() const; private: - TString Path_; + TString Path_; /// cache mutable TSimpleIntrusivePtr<TSplit> Split_; }; @@ -224,7 +224,7 @@ namespace NPrivate { } template <class... Ts> -TString JoinFsPaths(Ts&&... args) { +TString JoinFsPaths(Ts&&... args) { TFsPath fsPath; ::NPrivate::AppendToFsPath(fsPath, std::forward<Ts>(args)...); return fsPath.GetPath(); diff --git a/util/folder/path_ut.cpp b/util/folder/path_ut.cpp index e6a3451016..595e727f2c 100644 --- a/util/folder/path_ut.cpp +++ b/util/folder/path_ut.cpp @@ -26,23 +26,23 @@ namespace { TFsPath Path_; public: - TTestDirectory(const TString& name); + TTestDirectory(const TString& name); ~TTestDirectory(); TFsPath GetFsPath() const { return Path_; } - TFsPath Child(const TString& name) const { + TFsPath Child(const TString& name) const { return Path_.Child(name); } }; - TTestDirectory::TTestDirectory(const TString& name) { + TTestDirectory::TTestDirectory(const TString& name) { Y_VERIFY(name.length() > 0, "have to specify name"); - Y_VERIFY(name.find('.') == TString::npos, "must be simple name"); - Y_VERIFY(name.find('/') == TString::npos, "must be simple name"); - Y_VERIFY(name.find('\\') == TString::npos, "must be simple name"); + Y_VERIFY(name.find('.') == TString::npos, "must be simple name"); + Y_VERIFY(name.find('/') == TString::npos, "must be simple name"); + Y_VERIFY(name.find('\\') == TString::npos, "must be simple name"); Path_ = TFsPath(name); Path_.ForceDelete(); @@ -119,13 +119,13 @@ Y_UNIT_TEST_SUITE(TFsPathTests) { Y_UNIT_TEST(GetName) { TTestDirectory d("GetName"); - UNIT_ASSERT_VALUES_EQUAL(TString("dfgh"), d.Child("dfgh").GetName()); + UNIT_ASSERT_VALUES_EQUAL(TString("dfgh"), d.Child("dfgh").GetName()); // check does not fail TFsPath(".").GetName(); #ifdef _unix_ - UNIT_ASSERT_VALUES_EQUAL(TString("/"), TFsPath("/").GetName()); + UNIT_ASSERT_VALUES_EQUAL(TString("/"), TFsPath("/").GetName()); #endif } @@ -235,11 +235,11 @@ Y_UNIT_TEST_SUITE(TFsPathTests) { dir.Child("c").MkDir(); dir.Child("d").Touch(); - TVector<TString> children; + TVector<TString> children; dir.ListNames(children); std::sort(children.begin(), children.end()); - TVector<TString> expected; + TVector<TString> expected; expected.push_back("a"); expected.push_back("b"); expected.push_back("c"); @@ -430,16 +430,16 @@ Y_UNIT_TEST_SUITE(TFsPathTests) { TTempDir tempDir; TFsPath tempDirPath(tempDir()); - const TString originDir = tempDirPath.Child("origin"); + const TString originDir = tempDirPath.Child("origin"); MakePathIfNotExist(originDir.c_str()); - const TString originFile = TFsPath(originDir).Child("data"); + const TString originFile = TFsPath(originDir).Child("data"); { - TFixedBufferFileOutput out(originFile); + TFixedBufferFileOutput out(originFile); out << "data111!!!"; } - const TString link = tempDirPath.Child("origin_symlink"); + const TString link = tempDirPath.Child("origin_symlink"); NFs::SymLink(originDir, link); TFsPath(link).ForceDelete(); @@ -453,16 +453,16 @@ Y_UNIT_TEST_SUITE(TFsPathTests) { TTempDir tempDir; TFsPath tempDirPath(tempDir()); - const TString originDir = tempDirPath.Child("origin"); + const TString originDir = tempDirPath.Child("origin"); MakePathIfNotExist(originDir.c_str()); - const TString originFile = TFsPath(originDir).Child("data"); + const TString originFile = TFsPath(originDir).Child("data"); { - TFixedBufferFileOutput out(originFile); + TFixedBufferFileOutput out(originFile); out << "data111!!!"; } - const TString link = tempDirPath.Child("origin_symlink"); + const TString link = tempDirPath.Child("origin_symlink"); NFs::SymLink(originFile, link); TFsPath(link).ForceDelete(); @@ -476,19 +476,19 @@ Y_UNIT_TEST_SUITE(TFsPathTests) { TTempDir tempDir; TFsPath tempDirPath(tempDir()); - const TString symlinkedDir = tempDirPath.Child("to_remove"); + const TString symlinkedDir = tempDirPath.Child("to_remove"); MakePathIfNotExist(symlinkedDir.c_str()); - const TString originDir = tempDirPath.Child("origin"); + const TString originDir = tempDirPath.Child("origin"); MakePathIfNotExist(originDir.c_str()); - const TString originFile = TFsPath(originDir).Child("data"); + const TString originFile = TFsPath(originDir).Child("data"); { - TFixedBufferFileOutput out(originFile); + TFixedBufferFileOutput out(originFile); out << "data111!!!"; } - const TString symlinkedFile = TFsPath(symlinkedDir).Child("origin_symlink"); + const TString symlinkedFile = TFsPath(symlinkedDir).Child("origin_symlink"); NFs::SymLink(originDir, symlinkedFile); TFsPath(symlinkedDir).ForceDelete(); @@ -503,19 +503,19 @@ Y_UNIT_TEST_SUITE(TFsPathTests) { TTempDir tempDir; TFsPath tempDirPath(tempDir()); - const TString symlinkedDir = tempDirPath.Child("to_remove"); + const TString symlinkedDir = tempDirPath.Child("to_remove"); MakePathIfNotExist(symlinkedDir.c_str()); - const TString originDir = tempDirPath.Child("origin"); + const TString originDir = tempDirPath.Child("origin"); MakePathIfNotExist(originDir.c_str()); - const TString originFile = TFsPath(originDir).Child("data"); + const TString originFile = TFsPath(originDir).Child("data"); { - TFixedBufferFileOutput out(originFile); + TFixedBufferFileOutput out(originFile); out << "data111!!!"; } - const TString symlinkedFile = TFsPath(symlinkedDir).Child("origin_symlink"); + const TString symlinkedFile = TFsPath(symlinkedDir).Child("origin_symlink"); NFs::SymLink(originFile, symlinkedFile); TFsPath(symlinkedDir).ForceDelete(); diff --git a/util/folder/pathsplit.cpp b/util/folder/pathsplit.cpp index 81d439a727..44a4810fef 100644 --- a/util/folder/pathsplit.cpp +++ b/util/folder/pathsplit.cpp @@ -85,8 +85,8 @@ void TPathSplitTraitsWindows::DoParsePart(const TStringBuf part0) { } } -TString TPathSplitStore::DoReconstruct(const TStringBuf slash) const { - TString r; +TString TPathSplitStore::DoReconstruct(const TStringBuf slash) const { + TString r; r.reserve(ToReserve(*this)); @@ -126,7 +126,7 @@ void Out<TPathSplit>(IOutputStream& o, const TPathSplit& ps) { o << ps.Reconstruct(); } -TString JoinPaths(const TPathSplit& p1, const TPathSplit& p2) { +TString JoinPaths(const TPathSplit& p1, const TPathSplit& p2) { if (p2.IsAbsolute) { ythrow yexception() << "can not join " << p1 << " and " << p2; } diff --git a/util/folder/pathsplit.h b/util/folder/pathsplit.h index d134338e35..af14c672d4 100644 --- a/util/folder/pathsplit.h +++ b/util/folder/pathsplit.h @@ -2,11 +2,11 @@ #include <util/generic/vector.h> #include <util/generic/strbuf.h> -#include <util/generic/string.h> +#include <util/generic/string.h> #include <util/string/ascii.h> //do not own any data -struct TPathSplitStore: public TVector<TStringBuf> { +struct TPathSplitStore: public TVector<TStringBuf> { TStringBuf Drive; bool IsAbsolute = false; @@ -14,7 +14,7 @@ struct TPathSplitStore: public TVector<TStringBuf> { TStringBuf Extension() const; protected: - TString DoReconstruct(const TStringBuf slash) const; + TString DoReconstruct(const TStringBuf slash) const; inline void DoAppendHint(size_t hint) { reserve(size() + hint); @@ -24,7 +24,7 @@ protected: struct TPathSplitTraitsUnix: public TPathSplitStore { static constexpr char MainPathSep = '/'; - inline TString Reconstruct() const { + inline TString Reconstruct() const { return DoReconstruct(TStringBuf("/")); } @@ -43,7 +43,7 @@ struct TPathSplitTraitsUnix: public TPathSplitStore { struct TPathSplitTraitsWindows: public TPathSplitStore { static constexpr char MainPathSep = '\\'; - inline TString Reconstruct() const { + inline TString Reconstruct() const { return DoReconstruct(TStringBuf("\\")); } @@ -108,6 +108,6 @@ using TPathSplit = TPathSplitBase<TPathSplitTraitsLocal>; using TPathSplitUnix = TPathSplitBase<TPathSplitTraitsUnix>; using TPathSplitWindows = TPathSplitBase<TPathSplitTraitsWindows>; -TString JoinPaths(const TPathSplit& p1, const TPathSplit& p2); +TString JoinPaths(const TPathSplit& p1, const TPathSplit& p2); TStringBuf CutExtension(const TStringBuf fileName); diff --git a/util/folder/tempdir.cpp b/util/folder/tempdir.cpp index 6fdf8f753c..6574a53009 100644 --- a/util/folder/tempdir.cpp +++ b/util/folder/tempdir.cpp @@ -21,7 +21,7 @@ TTempDir::TTempDir(const char* prefix, TCreationToken) TempDir = tempDir; } -TTempDir::TTempDir(const TString& tempDir) +TTempDir::TTempDir(const TString& tempDir) : TempDir(tempDir) , Remove(true) { diff --git a/util/folder/tempdir.h b/util/folder/tempdir.h index ff458f83b9..a6cac0cfc2 100644 --- a/util/folder/tempdir.h +++ b/util/folder/tempdir.h @@ -2,7 +2,7 @@ #include "fwd.h" #include "path.h" -#include <util/generic/string.h> +#include <util/generic/string.h> class TTempDir { public: @@ -10,18 +10,18 @@ public: TTempDir(); /// Create new directory with this fixed name. If it already exists, clear it. - TTempDir(const TString& tempDir); + TTempDir(const TString& tempDir); ~TTempDir(); /// Create new directory in given folder. static TTempDir NewTempDir(const TString& root); - const TString& operator()() const { + const TString& operator()() const { return Name(); } - const TString& Name() const { + const TString& Name() const { return TempDir.GetPath(); } |