diff options
author | sath <sath@yandex-team.com> | 2024-09-23 11:34:23 +0300 |
---|---|---|
committer | sath <sath@yandex-team.com> | 2024-09-23 11:47:38 +0300 |
commit | 3d1f648a83b3d3482fa5df8f1cfe2b0a89261784 (patch) | |
tree | f8ee85688f2b44980d7493498c0c91ae78d79680 /util | |
parent | 41602592e595da1a255b6bb8326b1b7550dd99fe (diff) | |
download | ydb-3d1f648a83b3d3482fa5df8f1cfe2b0a89261784.tar.gz |
Use unified remove function in TFsPath.
Текущая реализация не удаляет readonly файлы под Windows
Для остальных систем
```
::unlink
::rmdir
```
равноценно вызову
```
remove
```
commit_hash:99a45d03ae667ec82e57ca8fa7500bae9f827086
Diffstat (limited to 'util')
-rw-r--r-- | util/folder/path.cpp | 11 | ||||
-rw-r--r-- | util/folder/path_ut.cpp | 9 |
2 files changed, 9 insertions, 11 deletions
diff --git a/util/folder/path.cpp b/util/folder/path.cpp index 940f6dffe0..321776cb0c 100644 --- a/util/folder/path.cpp +++ b/util/folder/path.cpp @@ -406,8 +406,7 @@ void TFsPath::DeleteIfExists() const { return; } - ::unlink(this->c_str()); - ::rmdir(this->c_str()); + NFs::Remove(GetPath()); if (Exists()) { ythrow TIoException() << "failed to delete " << Path_; } @@ -441,7 +440,7 @@ void TFsPath::ForceDelete() const { return; } - TFileStat stat(GetPath().c_str(), true); + TFileStat stat(GetPath(), true); if (stat.IsNull()) { const int err = LastSystemError(); #ifdef _win_ @@ -455,19 +454,15 @@ void TFsPath::ForceDelete() const { } } - bool succ; if (stat.IsDir()) { TVector<TFsPath> children; List(children); for (auto& i : children) { i.ForceDelete(); } - succ = ::rmdir(this->c_str()) == 0; - } else { - succ = ::unlink(this->c_str()) == 0; } - if (!succ && LastSystemError()) { + if (!NFs::Remove(GetPath())) { ythrow TIoException() << "failed to delete " << Path_; } } diff --git a/util/folder/path_ut.cpp b/util/folder/path_ut.cpp index 0fbcac8263..f73bd7f57a 100644 --- a/util/folder/path_ut.cpp +++ b/util/folder/path_ut.cpp @@ -663,7 +663,7 @@ Y_UNIT_TEST_SUITE(TFsPathTests) { }; #endif - Y_UNIT_TEST(TestForceDeleteErrorUnlink) { + Y_UNIT_TEST(TestForceDeleteErrorRemove) { TTempDir tempDir; const TFsPath testDir = TFsPath(tempDir()).Child("dir"); @@ -680,14 +680,17 @@ Y_UNIT_TEST_SUITE(TFsPathTests) { Y_DEFER { Chmod(testFile.c_str(), MODE0777); }; + // Checks that dir/file with readonly attribute will be deleted + // on Windows + UNIT_ASSERT_NO_EXCEPTION(testFile.ForceDelete()); #else Chmod(testDir.c_str(), S_IRUSR | S_IXUSR); Y_DEFER { Chmod(testDir.c_str(), MODE0777); }; + UNIT_ASSERT_EXCEPTION_CONTAINS(testFile.ForceDelete(), TIoException, + "failed to delete"); #endif - - UNIT_ASSERT_EXCEPTION_CONTAINS(testFile.ForceDelete(), TIoException, "failed to delete"); } Y_UNIT_TEST(TestForceDeleteErrorRmdir) { |