aboutsummaryrefslogtreecommitdiffstats
path: root/util/folder
diff options
context:
space:
mode:
authorivanmorozov <ivanmorozov@yandex-team.ru>2022-02-10 16:47:34 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:47:34 +0300
commit464ba3814a83db4f2d5327393b0b6eaf0c86bfd7 (patch)
treec0748b5dcbade83af788c0abfa89c0383d6b779c /util/folder
parentcba5d9a444e2cfe105f55ccda66cd21d50440017 (diff)
downloadydb-464ba3814a83db4f2d5327393b0b6eaf0c86bfd7.tar.gz
Restoring authorship annotation for <ivanmorozov@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'util/folder')
-rw-r--r--util/folder/dirut.cpp20
-rw-r--r--util/folder/dirut.h2
-rw-r--r--util/folder/filelist.cpp6
-rw-r--r--util/folder/path.cpp64
-rw-r--r--util/folder/path.h6
-rw-r--r--util/folder/path_ut.cpp90
6 files changed, 94 insertions, 94 deletions
diff --git a/util/folder/dirut.cpp b/util/folder/dirut.cpp
index 52606b3846..ffc9b09f96 100644
--- a/util/folder/dirut.cpp
+++ b/util/folder/dirut.cpp
@@ -17,7 +17,7 @@ void SlashFolderLocal(TString& folder) {
#ifdef _win32_
size_t pos;
while ((pos = folder.find('/')) != TString::npos)
- folder.replace(pos, 1, LOCSLASH_S);
+ folder.replace(pos, 1, LOCSLASH_S);
#endif
if (folder[folder.size() - 1] != LOCSLASH_C)
folder.append(LOCSLASH_S);
@@ -506,7 +506,7 @@ const char* GetFileNameComponent(const char* f) {
}
TString GetSystemTempDir() {
-#ifdef _win_
+#ifdef _win_
char buffer[1024];
DWORD size = GetTempPath(1024, buffer);
if (!size) {
@@ -527,14 +527,14 @@ TString ResolveDir(const char* path) {
}
bool SafeResolveDir(const char* path, TString& result) {
- try {
- result = ResolvePath(path, true);
- return true;
- } catch (...) {
- return false;
- }
-}
-
+ try {
+ result = ResolvePath(path, true);
+ return true;
+ } catch (...) {
+ return false;
+ }
+}
+
TString GetDirName(const TString& path) {
return TFsPath(path).Dirname();
}
diff --git a/util/folder/dirut.h b/util/folder/dirut.h
index d095e0a900..2537027b12 100644
--- a/util/folder/dirut.h
+++ b/util/folder/dirut.h
@@ -82,7 +82,7 @@ TString ResolvePath(const char* path, bool isDir = false);
TString ResolveDir(const char* path);
bool SafeResolveDir(const char* path, TString& result);
-
+
TString GetDirName(const TString& path);
TString GetBaseName(const TString& path);
diff --git a/util/folder/filelist.cpp b/util/folder/filelist.cpp
index 0f86fef549..b21fcdbf20 100644
--- a/util/folder/filelist.cpp
+++ b/util/folder/filelist.cpp
@@ -13,15 +13,15 @@ void TFileEntitiesList::Fill(const TString& dirname, TStringBuf prefix, TStringB
TDirIterator dir(dirname, opts);
Clear();
-
+
size_t dirNameLength = dirname.length();
while (dirNameLength && (dirname[dirNameLength - 1] == '\\' || dirname[dirNameLength - 1] == '/')) {
--dirNameLength;
}
-
+
for (auto file = dir.begin(); file != dir.end(); ++file) {
if (file->fts_pathlen == file->fts_namelen || file->fts_pathlen <= dirNameLength) {
- continue;
+ continue;
}
TStringBuf filename = file->fts_path + dirNameLength + 1;
diff --git a/util/folder/path.cpp b/util/folder/path.cpp
index 821ca18ba2..bfe0c67d68 100644
--- a/util/folder/path.cpp
+++ b/util/folder/path.cpp
@@ -365,7 +365,7 @@ void TFsPath::DeleteIfExists() const {
void TFsPath::MkDir(const int mode) const {
CheckDefined();
- if (!Exists()) {
+ if (!Exists()) {
int r = Mkdir(this->c_str(), mode);
if (r != 0) {
// TODO (stanly) will still fail on Windows because
@@ -375,11 +375,11 @@ void TFsPath::MkDir(const int mode) const {
ythrow TIoSystemError() << "could not create directory " << Path_;
}
}
- }
+ }
}
void TFsPath::MkDirs(const int mode) const {
- CheckDefined();
+ CheckDefined();
if (!Exists()) {
Parent().MkDirs(mode);
MkDir(mode);
@@ -423,41 +423,41 @@ void TFsPath::ForceDelete() const {
}
void TFsPath::CopyTo(const TString& newPath, bool force) const {
- if (IsDirectory()) {
- if (force) {
- TFsPath(newPath).MkDirs();
- } else if (!TFsPath(newPath).IsDirectory()) {
+ if (IsDirectory()) {
+ if (force) {
+ TFsPath(newPath).MkDirs();
+ } else if (!TFsPath(newPath).IsDirectory()) {
ythrow TIoException() << "Target path is not a directory " << newPath;
- }
+ }
TVector<TFsPath> children;
- List(children);
- for (auto&& i : children) {
- i.CopyTo(newPath + "/" + i.GetName(), force);
- }
- } else {
- if (force) {
- TFsPath(newPath).Parent().MkDirs();
- } else {
- if (!TFsPath(newPath).Parent().IsDirectory()) {
+ List(children);
+ for (auto&& i : children) {
+ i.CopyTo(newPath + "/" + i.GetName(), force);
+ }
+ } else {
+ if (force) {
+ TFsPath(newPath).Parent().MkDirs();
+ } else {
+ if (!TFsPath(newPath).Parent().IsDirectory()) {
ythrow TIoException() << "Parent (" << TFsPath(newPath).Parent() << ") of a target path is not a directory " << newPath;
- }
- if (TFsPath(newPath).Exists()) {
+ }
+ if (TFsPath(newPath).Exists()) {
ythrow TIoException() << "Path already exists " << newPath;
- }
- }
- NFs::Copy(Path_, newPath);
- }
-}
-
+ }
+ }
+ NFs::Copy(Path_, newPath);
+ }
+}
+
void TFsPath::ForceRenameTo(const TString& newPath) const {
- try {
- RenameTo(newPath);
+ try {
+ RenameTo(newPath);
} catch (const TIoSystemError& /* error */) {
- CopyTo(newPath, true);
- ForceDelete();
- }
-}
-
+ CopyTo(newPath, true);
+ ForceDelete();
+ }
+}
+
TFsPath TFsPath::Cwd() {
return TFsPath(::NFs::CurrentWorkingDirectory());
}
diff --git a/util/folder/path.h b/util/folder/path.h
index 904f6199d6..2fb4d6b4ef 100644
--- a/util/folder/path.h
+++ b/util/folder/path.h
@@ -139,8 +139,8 @@ public:
* @brief create this directory
*
* @param mode specifies permissions to use as described in mkdir(2), makes sense only on Unix-like systems.
- *
- * Nothing to do if dir exists.
+ *
+ * Nothing to do if dir exists.
*/
void MkDir(const int mode = MODE0777) const;
@@ -187,7 +187,7 @@ public:
void ForceRenameTo(const TString& newPath) const;
void CopyTo(const TString& newPath, bool force) const;
-
+
void Touch() const;
TFsPath RealPath() const;
diff --git a/util/folder/path_ut.cpp b/util/folder/path_ut.cpp
index e6a42f2e09..e6a3451016 100644
--- a/util/folder/path_ut.cpp
+++ b/util/folder/path_ut.cpp
@@ -56,36 +56,36 @@ namespace {
Y_UNIT_TEST_SUITE(TFsPathTests) {
Y_UNIT_TEST(TestMkDirs) {
- const TFsPath path = "a/b/c/d/e/f";
- path.ForceDelete();
- TFsPath current = path;
- ui32 checksCounter = 0;
- while (current != ".") {
- UNIT_ASSERT(!path.Exists());
- ++checksCounter;
- current = current.Parent();
- }
+ const TFsPath path = "a/b/c/d/e/f";
+ path.ForceDelete();
+ TFsPath current = path;
+ ui32 checksCounter = 0;
+ while (current != ".") {
+ UNIT_ASSERT(!path.Exists());
+ ++checksCounter;
+ current = current.Parent();
+ }
UNIT_ASSERT_VALUES_EQUAL(checksCounter, 6);
-
- path.MkDirs();
- UNIT_ASSERT(path.Exists());
-
- current = path;
- while (current != ".") {
- UNIT_ASSERT(path.Exists());
- current = current.Parent();
- }
- }
-
+
+ path.MkDirs();
+ UNIT_ASSERT(path.Exists());
+
+ current = path;
+ while (current != ".") {
+ UNIT_ASSERT(path.Exists());
+ current = current.Parent();
+ }
+ }
+
Y_UNIT_TEST(MkDirFreak) {
- TFsPath path;
+ TFsPath path;
UNIT_ASSERT_EXCEPTION(path.MkDir(), TIoException);
UNIT_ASSERT_EXCEPTION(path.MkDirs(), TIoException);
- path = ".";
- path.MkDir();
- path.MkDirs();
- }
-
+ path = ".";
+ path.MkDir();
+ path.MkDirs();
+ }
+
Y_UNIT_TEST(Parent) {
#ifdef _win_
UNIT_ASSERT_VALUES_EQUAL(TFsPath("\\etc/passwd").Parent(), TFsPath("\\etc"));
@@ -149,25 +149,25 @@ Y_UNIT_TEST_SUITE(TFsPathTests) {
}
Y_UNIT_TEST(TestForceRename) {
- TTestDirectory xx("TestForceRename");
- TFsPath fMain = xx.Child("main");
-
- TFsPath f1 = fMain.Child("f1");
- f1.MkDirs();
- TFsPath f1Child = f1.Child("f1child");
- f1Child.Touch();
-
- TFsPath f2 = fMain.Child("f2");
- f2.MkDirs();
-
- fMain.ForceRenameTo("TestForceRename/main1");
-
- UNIT_ASSERT(!xx.Child("main").Exists());
- UNIT_ASSERT(xx.Child("main1").Child("f1").Exists());
- UNIT_ASSERT(xx.Child("main1").Child("f2").Exists());
- UNIT_ASSERT(xx.Child("main1").Child("f1").Child("f1child").Exists());
- }
-
+ TTestDirectory xx("TestForceRename");
+ TFsPath fMain = xx.Child("main");
+
+ TFsPath f1 = fMain.Child("f1");
+ f1.MkDirs();
+ TFsPath f1Child = f1.Child("f1child");
+ f1Child.Touch();
+
+ TFsPath f2 = fMain.Child("f2");
+ f2.MkDirs();
+
+ fMain.ForceRenameTo("TestForceRename/main1");
+
+ UNIT_ASSERT(!xx.Child("main").Exists());
+ UNIT_ASSERT(xx.Child("main1").Child("f1").Exists());
+ UNIT_ASSERT(xx.Child("main1").Child("f2").Exists());
+ UNIT_ASSERT(xx.Child("main1").Child("f1").Child("f1child").Exists());
+ }
+
Y_UNIT_TEST(TestRenameFail) {
UNIT_ASSERT_EXCEPTION(TFsPath("sfsfsfsdfsfsdfdf").RenameTo("sdfsdf"), TIoException);
}