diff options
author | ivanmorozov <ivanmorozov@yandex-team.ru> | 2022-02-10 16:47:34 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:47:34 +0300 |
commit | 464ba3814a83db4f2d5327393b0b6eaf0c86bfd7 (patch) | |
tree | c0748b5dcbade83af788c0abfa89c0383d6b779c /util | |
parent | cba5d9a444e2cfe105f55ccda66cd21d50440017 (diff) | |
download | ydb-464ba3814a83db4f2d5327393b0b6eaf0c86bfd7.tar.gz |
Restoring authorship annotation for <ivanmorozov@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'util')
-rw-r--r-- | util/charset/wide.h | 2 | ||||
-rw-r--r-- | util/folder/dirut.cpp | 20 | ||||
-rw-r--r-- | util/folder/dirut.h | 2 | ||||
-rw-r--r-- | util/folder/filelist.cpp | 6 | ||||
-rw-r--r-- | util/folder/path.cpp | 64 | ||||
-rw-r--r-- | util/folder/path.h | 6 | ||||
-rw-r--r-- | util/folder/path_ut.cpp | 90 | ||||
-rw-r--r-- | util/generic/maybe.h | 22 | ||||
-rw-r--r-- | util/generic/object_counter.h | 8 | ||||
-rw-r--r-- | util/generic/objects_counter_ut.cpp | 60 | ||||
-rw-r--r-- | util/generic/ut/ya.make | 2 | ||||
-rw-r--r-- | util/system/cpu_id.cpp | 4 | ||||
-rw-r--r-- | util/system/env.cpp | 4 | ||||
-rw-r--r-- | util/system/error.cpp | 20 | ||||
-rw-r--r-- | util/system/file.cpp | 2 | ||||
-rw-r--r-- | util/system/fs.cpp | 6 | ||||
-rw-r--r-- | util/system/fs_ut.cpp | 50 | ||||
-rw-r--r-- | util/system/rwlock.h | 18 |
18 files changed, 193 insertions, 193 deletions
diff --git a/util/charset/wide.h b/util/charset/wide.h index dd0754969b..04e6928aab 100644 --- a/util/charset/wide.h +++ b/util/charset/wide.h @@ -153,7 +153,7 @@ inline size_t WriteSymbol(wchar16 s, T& dest) noexcept { template <class T> inline size_t WriteSymbol(wchar32 s, T& dest) noexcept { if (s > 0xFFFF) { - if (s >= ::NUnicode::UnicodeInstancesLimit()) { + if (s >= ::NUnicode::UnicodeInstancesLimit()) { return WriteSymbol(static_cast<wchar16>(BROKEN_RUNE), dest); } 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); } diff --git a/util/generic/maybe.h b/util/generic/maybe.h index 37d9cf435e..34d21aebcd 100644 --- a/util/generic/maybe.h +++ b/util/generic/maybe.h @@ -9,16 +9,16 @@ #include <util/stream/output.h> #include <util/ysaveload.h> -namespace NMaybe { - struct TPolicyUndefinedExcept { +namespace NMaybe { + struct TPolicyUndefinedExcept { [[noreturn]] static void OnEmpty(const std::type_info& valueTypeInfo); - }; - - struct TPolicyUndefinedFail { + }; + + struct TPolicyUndefinedFail { [[noreturn]] static void OnEmpty(const std::type_info& valueTypeInfo); - }; -} - + }; +} + struct TNothing { explicit constexpr TNothing(int) noexcept { } @@ -448,9 +448,9 @@ private: } }; -template <class T> -using TMaybeFail = TMaybe<T, NMaybe::TPolicyUndefinedFail>; - +template <class T> +using TMaybeFail = TMaybe<T, NMaybe::TPolicyUndefinedFail>; + template <class T, class TPolicy = ::NMaybe::TPolicyUndefinedExcept> constexpr TMaybe<std::decay_t<T>, TPolicy> MakeMaybe(T&& value) { return TMaybe<std::decay_t<T>, TPolicy>(std::forward<T>(value)); diff --git a/util/generic/object_counter.h b/util/generic/object_counter.h index 56635bcc42..5257afa2e6 100644 --- a/util/generic/object_counter.h +++ b/util/generic/object_counter.h @@ -23,10 +23,10 @@ public: AtomicIncrement(Count_); } - inline TObjectCounter(const TObjectCounter& /*item*/) noexcept { - AtomicIncrement(Count_); - } - + inline TObjectCounter(const TObjectCounter& /*item*/) noexcept { + AtomicIncrement(Count_); + } + inline ~TObjectCounter() { AtomicDecrement(Count_); } diff --git a/util/generic/objects_counter_ut.cpp b/util/generic/objects_counter_ut.cpp index d12a1e78c6..4d5da37a56 100644 --- a/util/generic/objects_counter_ut.cpp +++ b/util/generic/objects_counter_ut.cpp @@ -1,36 +1,36 @@ -#include "object_counter.h" - +#include "object_counter.h" + #include <library/cpp/testing/unittest/registar.h> - + Y_UNIT_TEST_SUITE(ObjectsCounter) { - struct TObject: public TObjectCounter<TObject> { - }; - + struct TObject: public TObjectCounter<TObject> { + }; + Y_UNIT_TEST(Test1) { - TObject obj; + TObject obj; TVector<TObject> objects; - for (ui32 i = 0; i < 100; ++i) { - objects.push_back(obj); - } - UNIT_ASSERT_EQUAL(TObjectCounter<TObject>::ObjectCount(), 101); - } - + for (ui32 i = 0; i < 100; ++i) { + objects.push_back(obj); + } + UNIT_ASSERT_EQUAL(TObjectCounter<TObject>::ObjectCount(), 101); + } + Y_UNIT_TEST(TestEq) { - TObject obj; - { - TObject obj1 = obj; - UNIT_ASSERT_EQUAL(TObjectCounter<TObject>::ObjectCount(), 2); - } - UNIT_ASSERT_EQUAL(TObjectCounter<TObject>::ObjectCount(), 1); - } - + TObject obj; + { + TObject obj1 = obj; + UNIT_ASSERT_EQUAL(TObjectCounter<TObject>::ObjectCount(), 2); + } + UNIT_ASSERT_EQUAL(TObjectCounter<TObject>::ObjectCount(), 1); + } + Y_UNIT_TEST(TestMove) { - TObject obj; - UNIT_ASSERT_EQUAL(TObjectCounter<TObject>::ObjectCount(), 1); - { - TObject obj1 = std::move(obj); - UNIT_ASSERT_EQUAL(TObjectCounter<TObject>::ObjectCount(), 2); - } - UNIT_ASSERT_EQUAL(TObjectCounter<TObject>::ObjectCount(), 1); - } -} + TObject obj; + UNIT_ASSERT_EQUAL(TObjectCounter<TObject>::ObjectCount(), 1); + { + TObject obj1 = std::move(obj); + UNIT_ASSERT_EQUAL(TObjectCounter<TObject>::ObjectCount(), 2); + } + UNIT_ASSERT_EQUAL(TObjectCounter<TObject>::ObjectCount(), 1); + } +} diff --git a/util/generic/ut/ya.make b/util/generic/ut/ya.make index 89edb7f2b7..6eaf24cc5f 100644 --- a/util/generic/ut/ya.make +++ b/util/generic/ut/ya.make @@ -31,7 +31,7 @@ SRCS( generic/mapfindptr_ut.cpp generic/maybe_ut.cpp generic/mem_copy_ut.cpp - generic/objects_counter_ut.cpp + generic/objects_counter_ut.cpp generic/overloaded_ut.cpp generic/ptr_ut.cpp generic/queue_ut.cpp diff --git a/util/system/cpu_id.cpp b/util/system/cpu_id.cpp index b88b2c12c8..598c71f4d9 100644 --- a/util/system/cpu_id.cpp +++ b/util/system/cpu_id.cpp @@ -9,8 +9,8 @@ #include <immintrin.h> #elif defined(_x86_) #include <cpuid.h> -#endif - +#endif + #include <string.h> #if defined(_x86_) && !defined(_win_) diff --git a/util/system/env.cpp b/util/system/env.cpp index 33b9288e2d..ead9b566a5 100644 --- a/util/system/env.cpp +++ b/util/system/env.cpp @@ -3,13 +3,13 @@ #include <util/generic/string.h> #include <util/generic/yexception.h> -#ifdef _win_ +#ifdef _win_ #include <util/generic/vector.h> #include "winint.h" #else #include <cerrno> #include <cstdlib> -#endif +#endif /** * On Windows there may be many copies of enviroment variables, there at least two known, one is diff --git a/util/system/error.cpp b/util/system/error.cpp index f02b3e800f..f778ec42cb 100644 --- a/util/system/error.cpp +++ b/util/system/error.cpp @@ -26,19 +26,19 @@ void ClearLastSystemError() { int LastSystemError() { #if defined(_win_) - int ret = GetLastError(); + int ret = GetLastError(); - if (ret) + if (ret) return ret; - ret = WSAGetLastError(); - - if (ret) - return ret; - // when descriptors number are over maximum, errno set in this variable - ret = *(_errno()); - return ret; - + ret = WSAGetLastError(); + + if (ret) + return ret; + // when descriptors number are over maximum, errno set in this variable + ret = *(_errno()); + return ret; + #else return errno; #endif diff --git a/util/system/file.cpp b/util/system/file.cpp index 42adcb8b2f..4a261d020c 100644 --- a/util/system/file.cpp +++ b/util/system/file.cpp @@ -1272,7 +1272,7 @@ TFile Duplicate(int fd) { FHANDLE dupHandle; if (!::DuplicateHandle(GetCurrentProcess(), handle, GetCurrentProcess(), &dupHandle, 0, TRUE, DUPLICATE_SAME_ACCESS)) { - ythrow TFileError() << "can not duplicate file descriptor " << LastSystemError() << Endl; + ythrow TFileError() << "can not duplicate file descriptor " << LastSystemError() << Endl; } return TFile(dupHandle); diff --git a/util/system/fs.cpp b/util/system/fs.cpp index 33b23d09de..d2611a8ccc 100644 --- a/util/system/fs.cpp +++ b/util/system/fs.cpp @@ -95,9 +95,9 @@ bool NFs::Rename(const TString& oldPath, const TString& newPath) { void NFs::HardLinkOrCopy(const TString& existingPath, const TString& newPath) { if (!NFs::HardLink(existingPath, newPath)) { Copy(existingPath, newPath); - } -} - + } +} + bool NFs::HardLink(const TString& existingPath, const TString& newPath) { #if defined(_win_) return NFsPrivate::WinHardLink(existingPath, newPath); diff --git a/util/system/fs_ut.cpp b/util/system/fs_ut.cpp index b6e12857e4..de071ebf55 100644 --- a/util/system/fs_ut.cpp +++ b/util/system/fs_ut.cpp @@ -15,7 +15,7 @@ class TFsTest: public TTestBase { UNIT_TEST(TestCreateRemove); UNIT_TEST(TestRename); UNIT_TEST(TestSymlink); - UNIT_TEST(TestHardlink); + UNIT_TEST(TestHardlink); UNIT_TEST(TestCwdOpts); UNIT_TEST(TestEnsureExists); UNIT_TEST_SUITE_END(); @@ -24,7 +24,7 @@ public: void TestCreateRemove(); void TestRename(); void TestSymlink(); - void TestHardlink(); + void TestHardlink(); void TestCwdOpts(); void TestEnsureExists(); }; @@ -97,10 +97,10 @@ void TFsTest::TestCreateRemove() { } void RunRenameTest(TFsPath src, TFsPath dst) { - // if previous running was failed + // if previous running was failed TFsPath dir1 = "dir"; TFsPath dir2 = "dst_dir"; - + NFs::Remove(src); NFs::Remove(dst); @@ -109,22 +109,22 @@ void RunRenameTest(TFsPath src, TFsPath dst) { NFs::Remove(dir2 / src); NFs::Remove(dir2); - { + { TFile file(src, CreateNew | WrOnly); - file.Write("123", 3); - } - + file.Write("123", 3); + } + UNIT_ASSERT(NFs::Rename(src, dst)); UNIT_ASSERT(NFs::Exists(dst)); UNIT_ASSERT(!NFs::Exists(src)); - { + { TFile file(dst, OpenExisting); - UNIT_ASSERT_VALUES_EQUAL(file.GetLength(), 3); - } + UNIT_ASSERT_VALUES_EQUAL(file.GetLength(), 3); + } NFs::MakeDirectory(dir1); - { + { TFile file(dir1 / src, CreateNew | WrOnly); file.Write("123", 3); } @@ -166,26 +166,26 @@ static void RunHardlinkTest(const TFsPath& src, const TFsPath& dst) { } { TFile file(src, OpenExisting | WrOnly); - file.Write("1234", 4); - } - { + file.Write("1234", 4); + } + { TFile file(dst, OpenExisting | RdOnly); - UNIT_ASSERT_VALUES_EQUAL(file.GetLength(), 4); - } - { + UNIT_ASSERT_VALUES_EQUAL(file.GetLength(), 4); + } + { TFile file(dst, OpenExisting | WrOnly); - file.Write("12345", 5); - } + file.Write("12345", 5); + } - { + { TFile file(src, OpenExisting | RdOnly); - UNIT_ASSERT_VALUES_EQUAL(file.GetLength(), 5); - } + UNIT_ASSERT_VALUES_EQUAL(file.GetLength(), 5); + } UNIT_ASSERT(NFs::Remove(dst)); UNIT_ASSERT(NFs::Remove(src)); -} - +} + void TFsTest::TestHardlink() { RunHardlinkTest("tempfile", "hardlinkfile"); RunHardlinkTest("tempfile_абвг", "hardlinkfile_абвг"); //utf-8 names diff --git a/util/system/rwlock.h b/util/system/rwlock.h index e9d4062992..0bb9b3fe1c 100644 --- a/util/system/rwlock.h +++ b/util/system/rwlock.h @@ -55,24 +55,24 @@ struct TWriteGuardOps { }; template <class T> -struct TTryWriteGuardOps: public TWriteGuardOps<T> { +struct TTryWriteGuardOps: public TWriteGuardOps<T> { static inline bool TryAcquire(T* t) noexcept { - return t->TryAcquireWrite(); - } -}; - -template <class T> + return t->TryAcquireWrite(); + } +}; + +template <class T> using TReadGuardBase = TGuard<T, TReadGuardOps<T>>; template <class T> using TTryReadGuardBase = TTryGuard<T, TTryReadGuardOps<T>>; template <class T> using TWriteGuardBase = TGuard<T, TWriteGuardOps<T>>; -template <class T> -using TTryWriteGuardBase = TTryGuard<T, TTryWriteGuardOps<T>>; +template <class T> +using TTryWriteGuardBase = TTryGuard<T, TTryWriteGuardOps<T>>; using TReadGuard = TReadGuardBase<TRWMutex>; using TTryReadGuard = TTryReadGuardBase<TRWMutex>; using TWriteGuard = TWriteGuardBase<TRWMutex>; -using TTryWriteGuard = TTryWriteGuardBase<TRWMutex>; +using TTryWriteGuard = TTryWriteGuardBase<TRWMutex>; |