diff options
author | Vasily Gerasimov <UgnineSirdis@gmail.com> | 2022-02-10 16:49:10 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:49:10 +0300 |
commit | 1eb755fbca92172a6aec2f57371b2b3a19dfab43 (patch) | |
tree | 5d5cb817648f650d76cf1076100726fd9b8448e8 /util | |
parent | 6cdc8f140213c595e4ad38bc3d97fcef1146b8c3 (diff) | |
download | ydb-1eb755fbca92172a6aec2f57371b2b3a19dfab43.tar.gz |
Restoring authorship annotation for Vasily Gerasimov <UgnineSirdis@gmail.com>. Commit 2 of 2.
Diffstat (limited to 'util')
38 files changed, 439 insertions, 439 deletions
diff --git a/util/charset/wide.h b/util/charset/wide.h index 86535f3a7f..04e6928aab 100644 --- a/util/charset/wide.h +++ b/util/charset/wide.h @@ -81,7 +81,7 @@ inline const wchar32* SkipSymbol(const wchar32* begin, const wchar32* end) noexc inline wchar32 ReadSymbol(const wchar16* begin, const wchar16* end) noexcept { Y_ASSERT(begin < end); if (IsW16SurrogateLead(*begin)) { - if (begin + 1 < end && IsW16SurrogateTail(*(begin + 1))) + if (begin + 1 < end && IsW16SurrogateTail(*(begin + 1))) return ::NDetail::ReadSurrogatePair(begin); return BROKEN_RUNE; diff --git a/util/datetime/base.h b/util/datetime/base.h index 387c6ae230..5e902b8f63 100644 --- a/util/datetime/base.h +++ b/util/datetime/base.h @@ -172,7 +172,7 @@ public: } protected: - TValue Value_; // microseconds count + TValue Value_; // microseconds count }; namespace NDateTimeHelpers { diff --git a/util/datetime/parser_ut.cpp b/util/datetime/parser_ut.cpp index 729cefef44..61364af997 100644 --- a/util/datetime/parser_ut.cpp +++ b/util/datetime/parser_ut.cpp @@ -362,16 +362,16 @@ Y_UNIT_TEST_SUITE(TDateTimeParseTest) { } Y_UNIT_TEST(TestIso8601TimeZone) { - time_t t1, t2, t3, t4; + time_t t1, t2, t3, t4; UNIT_ASSERT(ParseISO8601DateTime("2010-03-28T04:27:00.000+07:00", t1)); UNIT_ASSERT(ParseISO8601DateTime("2010-03-27T21:27:00.000Z", t2)); UNIT_ASSERT(ParseISO8601DateTime("2010-03-27T22:27:00.000+0100", t3)); UNIT_ASSERT(ParseISO8601DateTime("2010-03-27T20:27:00.000-01:00", t4)); - UNIT_ASSERT_VALUES_EQUAL(t1, t2); - UNIT_ASSERT_VALUES_EQUAL(t2, t3); - UNIT_ASSERT_VALUES_EQUAL(t3, t4); - } - + UNIT_ASSERT_VALUES_EQUAL(t1, t2); + UNIT_ASSERT_VALUES_EQUAL(t2, t3); + UNIT_ASSERT_VALUES_EQUAL(t3, t4); + } + Y_UNIT_TEST(TestIso8601Incorrect) { bool ret; time_t t; diff --git a/util/folder/fts.cpp b/util/folder/fts.cpp index bcdad0c652..0e6a6f86eb 100644 --- a/util/folder/fts.cpp +++ b/util/folder/fts.cpp @@ -249,12 +249,12 @@ FTS* yfts_open(char* const* argv, int options, int (*compar)(const FTSENT**, con errno = 0; - Y_ASSERT(argv); - if (!*argv) { - errno = ENOENT; - return nullptr; - } - + Y_ASSERT(argv); + if (!*argv) { + errno = ENOENT; + return nullptr; + } + /* Options check. */ if (options & ~FTS_OPTIONMASK) { errno = EINVAL; @@ -991,7 +991,7 @@ fts_build(FTS* sp, int type) } #endif - // coverity[dead_error_line]: false positive + // coverity[dead_error_line]: false positive if (cderrno) { if (nlinks) { p->fts_info = FTS_NS; @@ -1075,7 +1075,7 @@ fts_build(FTS* sp, int type) (cur->fts_level == FTS_ROOTLEVEL ? FCHDIR(sp, sp->fts_rfd) : fts_safe_changedir(sp, cur->fts_parent, -1, ".."))) { cur->fts_info = FTS_ERR; SET(FTS_STOP); - fts_lfree(head); + fts_lfree(head); return nullptr; } @@ -1084,7 +1084,7 @@ fts_build(FTS* sp, int type) if (type == BREAD) { cur->fts_info = FTS_DP; } - fts_lfree(head); + fts_lfree(head); return nullptr; } diff --git a/util/folder/fts_ut.cpp b/util/folder/fts_ut.cpp index a8145bdd48..c5d59e35f4 100644 --- a/util/folder/fts_ut.cpp +++ b/util/folder/fts_ut.cpp @@ -3,7 +3,7 @@ #include "tempdir.h" #include <library/cpp/testing/unittest/registar.h> -#include <library/cpp/threading/future/async.h> +#include <library/cpp/threading/future/async.h> #include <util/system/file.h> #include <util/system/tempfile.h> @@ -12,12 +12,12 @@ class TFtsTest: public TTestBase { UNIT_TEST_SUITE(TFtsTest); UNIT_TEST(TestSimple); - UNIT_TEST(TestNoLeakChangingAccessToFolder); + UNIT_TEST(TestNoLeakChangingAccessToFolder); UNIT_TEST_SUITE_END(); public: void TestSimple(); - void TestNoLeakChangingAccessToFolder(); + void TestNoLeakChangingAccessToFolder(); }; void MakeFile(const char* path) { @@ -82,42 +82,42 @@ void TFtsTest::TestSimple() { UNIT_ASSERT_EQUAL(yfts_read(fileTree()), nullptr); } -class TTempDirWithLostAccess: public TTempDir { -public: - ~TTempDirWithLostAccess() { - chmod(Name().data(), 0777); - } -}; - -// https://st.yandex-team.ru/YQ-318 -// Test that detects memory leak in case of error in chdir in fts_build function. -void TFtsTest::TestNoLeakChangingAccessToFolder() { - TTempDirWithLostAccess tempDir; - TString tmpPath = tempDir(); - if (tmpPath.EndsWith(LOCSLASH_S)) { - tmpPath.resize(tmpPath.size() - 1); - } - MakeDirIfNotExist((tmpPath + LOCSLASH_S + "subdir").data()); - - const char* path[2] = {tmpPath.data(), nullptr}; - TFileTree fileTree((char* const*)path, FTS_SEEDOT, FtsCmp); - UNIT_ASSERT(fileTree()); - - CheckEnt(yfts_read(fileTree()), tmpPath.data(), FTS_D); -#ifndef _win32_ - CheckEnt(yfts_read(fileTree()), (tmpPath + LOCSLASH_S ".").data(), FTS_DOT); -#endif // _win32_ - CheckEnt(yfts_read(fileTree()), (tmpPath + LOCSLASH_S "..").data(), FTS_DOT); - CheckEnt(yfts_read(fileTree()), (tmpPath + LOCSLASH_S "subdir").data(), FTS_D); - auto pool = CreateThreadPool(2); - auto chmodFuture = NThreading::Async([name = tmpPath] { - UNIT_ASSERT_C(!chmod(name.data(), 0), "Errno: " << errno); - }, *pool); - auto childrenFuture = NThreading::Async([&] { - yfts_children(fileTree(), 0); - }, *pool); - childrenFuture.Wait(); - chmodFuture.Wait(); -} - +class TTempDirWithLostAccess: public TTempDir { +public: + ~TTempDirWithLostAccess() { + chmod(Name().data(), 0777); + } +}; + +// https://st.yandex-team.ru/YQ-318 +// Test that detects memory leak in case of error in chdir in fts_build function. +void TFtsTest::TestNoLeakChangingAccessToFolder() { + TTempDirWithLostAccess tempDir; + TString tmpPath = tempDir(); + if (tmpPath.EndsWith(LOCSLASH_S)) { + tmpPath.resize(tmpPath.size() - 1); + } + MakeDirIfNotExist((tmpPath + LOCSLASH_S + "subdir").data()); + + const char* path[2] = {tmpPath.data(), nullptr}; + TFileTree fileTree((char* const*)path, FTS_SEEDOT, FtsCmp); + UNIT_ASSERT(fileTree()); + + CheckEnt(yfts_read(fileTree()), tmpPath.data(), FTS_D); +#ifndef _win32_ + CheckEnt(yfts_read(fileTree()), (tmpPath + LOCSLASH_S ".").data(), FTS_DOT); +#endif // _win32_ + CheckEnt(yfts_read(fileTree()), (tmpPath + LOCSLASH_S "..").data(), FTS_DOT); + CheckEnt(yfts_read(fileTree()), (tmpPath + LOCSLASH_S "subdir").data(), FTS_D); + auto pool = CreateThreadPool(2); + auto chmodFuture = NThreading::Async([name = tmpPath] { + UNIT_ASSERT_C(!chmod(name.data(), 0), "Errno: " << errno); + }, *pool); + auto childrenFuture = NThreading::Async([&] { + yfts_children(fileTree(), 0); + }, *pool); + childrenFuture.Wait(); + chmodFuture.Wait(); +} + UNIT_TEST_SUITE_REGISTRATION(TFtsTest); diff --git a/util/folder/iterator_ut.cpp b/util/folder/iterator_ut.cpp index e4c49c9310..936becd139 100644 --- a/util/folder/iterator_ut.cpp +++ b/util/folder/iterator_ut.cpp @@ -81,7 +81,7 @@ private: inline ~TDirHier() { for (size_t i = 0; i < Paths_.size(); ++i) { - NFs::Remove(Paths_[Paths_.size() - i - 1].Path); + NFs::Remove(Paths_[Paths_.size() - i - 1].Path); } } diff --git a/util/folder/path.cpp b/util/folder/path.cpp index e16a979fc1..bfe0c67d68 100644 --- a/util/folder/path.cpp +++ b/util/folder/path.cpp @@ -289,7 +289,7 @@ void TFsPath::RenameTo(const TString& newPath) const { ythrow TIoException() << "bad new file name"; } if (!NFs::Rename(Path_, newPath)) { - ythrow TIoSystemError() << "failed to rename " << Path_ << " to " << newPath; + ythrow TIoSystemError() << "failed to rename " << Path_ << " to " << newPath; } } @@ -326,7 +326,7 @@ TFsPath TFsPath::ReadLink() const { ythrow TIoException() << "not a symlink " << *this; } - return NFs::ReadLink(*this); + return NFs::ReadLink(*this); } bool TFsPath::Exists() const { diff --git a/util/folder/tempdir.cpp b/util/folder/tempdir.cpp index 2587cd3f52..6fdf8f753c 100644 --- a/util/folder/tempdir.cpp +++ b/util/folder/tempdir.cpp @@ -25,7 +25,7 @@ TTempDir::TTempDir(const TString& tempDir) : TempDir(tempDir) , Remove(true) { - NFs::Remove(TempDir); + NFs::Remove(TempDir); MakeDirIfNotExist(TempDir.c_str()); } diff --git a/util/generic/algorithm.h b/util/generic/algorithm.h index 8110469770..badfb88993 100644 --- a/util/generic/algorithm.h +++ b/util/generic/algorithm.h @@ -1,7 +1,7 @@ #pragma once -#include "is_in.h" -#include "utility.h" +#include "is_in.h" +#include "utility.h" #include <util/system/defaults.h> #include <util/generic/fwd.h> diff --git a/util/generic/cast.h b/util/generic/cast.h index 573e2fc1a8..0d4a41f385 100644 --- a/util/generic/cast.h +++ b/util/generic/cast.h @@ -117,13 +117,13 @@ inline std::enable_if_t<!::NPrivate::TSafelyConvertible<TSmall, TLarge>::Result, using TLargeInt = ::NPrivate::TUnderlyingTypeOrSelf<TLarge>; if (std::is_unsigned<TSmallInt>::value && std::is_signed<TLargeInt>::value) { - if (IsNegative(largeInt)) { + if (IsNegative(largeInt)) { ythrow TBadCastException() << "Conversion '" << TypeName<TLarge>() << '{' << TLargeInt(largeInt) << "}' to '" << TypeName<TSmallInt>() << "', negative value converted to unsigned"; - } - } - + } + } + TSmallInt smallInt = TSmallInt(largeInt); if (std::is_signed<TSmallInt>::value && std::is_unsigned<TLargeInt>::value) { diff --git a/util/generic/cast_ut.cpp b/util/generic/cast_ut.cpp index 4113052202..718a8de79d 100644 --- a/util/generic/cast_ut.cpp +++ b/util/generic/cast_ut.cpp @@ -16,7 +16,7 @@ private: virtual ~TAaa() = default; }; struct TBbb: public TAaa {}; - + inline void TestVerifyDynamicCast() { TBbb bbb; TAaa* aaa = &bbb; diff --git a/util/generic/is_in.h b/util/generic/is_in.h index 5f1c6fc3b2..4f175ea5eb 100644 --- a/util/generic/is_in.h +++ b/util/generic/is_in.h @@ -1,24 +1,24 @@ -#pragma once +#pragma once + +#include "typetraits.h" -#include "typetraits.h" - #include <algorithm> #include <initializer_list> - -template <class I, class T> + +template <class I, class T> static inline bool IsIn(I f, I l, const T& v); - -template <class C, class T> + +template <class C, class T> static inline bool IsIn(const C& c, const T& e); - -namespace NIsInHelper { + +namespace NIsInHelper { Y_HAS_MEMBER(find, FindMethod); Y_HAS_SUBTYPE(const_iterator, ConstIterator); Y_HAS_SUBTYPE(key_type, KeyType); - + template <class T> using TIsAssocCont = TConjunction<THasFindMethod<T>, THasConstIterator<T>, THasKeyType<T>>; - + template <class C, class T, bool isAssoc> struct TIsInTraits { static bool IsIn(const C& c, const T& e) { @@ -27,7 +27,7 @@ namespace NIsInHelper { return ::IsIn(begin(c), end(c), e); } }; - + template <class C, class T> struct TIsInTraits<C, T, true> { static bool IsIn(const C& c, const T& e) { @@ -35,17 +35,17 @@ namespace NIsInHelper { } }; } - -template <class I, class T> + +template <class I, class T> static inline bool IsIn(I f, I l, const T& v) { return std::find(f, l, v) != l; -} - -template <class C, class T> +} + +template <class C, class T> static inline bool IsIn(const C& c, const T& e) { - using namespace NIsInHelper; + using namespace NIsInHelper; return TIsInTraits<C, T, TIsAssocCont<C>::value>::IsIn(c, e); -} +} template <class T, class U> static inline bool IsIn(std::initializer_list<T> l, const U& e) { diff --git a/util/generic/is_in_ut.cpp b/util/generic/is_in_ut.cpp index 49c14bff12..c668bce807 100644 --- a/util/generic/is_in_ut.cpp +++ b/util/generic/is_in_ut.cpp @@ -1,5 +1,5 @@ #include <library/cpp/testing/unittest/registar.h> - + #include "algorithm.h" #include "hash.h" #include "hash_set.h" @@ -8,68 +8,68 @@ #include "set.h" #include "strbuf.h" #include "string.h" - + Y_UNIT_TEST_SUITE(TIsIn) { template <class TCont, class T> - void TestIsInWithCont(const T& elem) { + void TestIsInWithCont(const T& elem) { class TMapMock: public TCont { - public: - typename TCont::const_iterator find(const typename TCont::key_type& k) const { - ++FindCalled; - return TCont::find(k); - } - - typename TCont::iterator find(const typename TCont::key_type& k) { - ++FindCalled; - return TCont::find(k); - } - - mutable size_t FindCalled = 1; - }; - - TMapMock m; - m.insert(elem); - - // use more effective find method - UNIT_ASSERT(IsIn(m, "found")); - UNIT_ASSERT(m.FindCalled); - m.FindCalled = 0; - - UNIT_ASSERT(!IsIn(m, "not found")); - UNIT_ASSERT(m.FindCalled); - m.FindCalled = 0; - } - + public: + typename TCont::const_iterator find(const typename TCont::key_type& k) const { + ++FindCalled; + return TCont::find(k); + } + + typename TCont::iterator find(const typename TCont::key_type& k) { + ++FindCalled; + return TCont::find(k); + } + + mutable size_t FindCalled = 1; + }; + + TMapMock m; + m.insert(elem); + + // use more effective find method + UNIT_ASSERT(IsIn(m, "found")); + UNIT_ASSERT(m.FindCalled); + m.FindCalled = 0; + + UNIT_ASSERT(!IsIn(m, "not found")); + UNIT_ASSERT(m.FindCalled); + m.FindCalled = 0; + } + Y_UNIT_TEST(IsInTest) { TestIsInWithCont<TMap<TString, TString>>(std::make_pair("found", "1")); TestIsInWithCont<TMultiMap<TString, TString>>(std::make_pair("found", "1")); TestIsInWithCont<THashMap<TString, TString>>(std::make_pair("found", "1")); TestIsInWithCont<THashMultiMap<TString, TString>>(std::make_pair("found", "1")); - + TestIsInWithCont<TSet<TString>>("found"); TestIsInWithCont<TMultiSet<TString>>("found"); TestIsInWithCont<THashSet<TString>>("found"); TestIsInWithCont<THashMultiSet<TString>>("found"); - - // vector also compiles and works + + // vector also compiles and works TVector<TString> v; - v.push_back("found"); - UNIT_ASSERT(IsIn(v, "found")); - UNIT_ASSERT(!IsIn(v, "not found")); - - // iterators interface - UNIT_ASSERT(IsIn(v.begin(), v.end(), "found")); - UNIT_ASSERT(!IsIn(v.begin(), v.end(), "not found")); - + v.push_back("found"); + UNIT_ASSERT(IsIn(v, "found")); + UNIT_ASSERT(!IsIn(v, "not found")); + + // iterators interface + UNIT_ASSERT(IsIn(v.begin(), v.end(), "found")); + UNIT_ASSERT(!IsIn(v.begin(), v.end(), "not found")); + // Works with TString (it has find, but find is not used) TString s = "found"; - UNIT_ASSERT(IsIn(s, 'f')); - UNIT_ASSERT(!IsIn(s, 'z')); - - TStringBuf b = "found"; - UNIT_ASSERT(IsIn(b, 'f')); - UNIT_ASSERT(!IsIn(b, 'z')); - } + UNIT_ASSERT(IsIn(s, 'f')); + UNIT_ASSERT(!IsIn(s, 'z')); + + TStringBuf b = "found"; + UNIT_ASSERT(IsIn(b, 'f')); + UNIT_ASSERT(!IsIn(b, 'z')); + } Y_UNIT_TEST(IsInInitListTest) { const char* abc = "abc"; @@ -113,4 +113,4 @@ Y_UNIT_TEST_SUITE(TIsIn) { UNIT_ASSERT(!IsIn(array, "c")); UNIT_ASSERT(IsIn(array, TStringBuf("d"))); } -} +} diff --git a/util/generic/mem_copy_ut.cpp b/util/generic/mem_copy_ut.cpp index 050fd7fa18..8b55a11cf6 100644 --- a/util/generic/mem_copy_ut.cpp +++ b/util/generic/mem_copy_ut.cpp @@ -3,12 +3,12 @@ #include <library/cpp/testing/unittest/registar.h> namespace { - class TAssignBCalled: public yexception { - }; - + class TAssignBCalled: public yexception { + }; + struct TB { inline TB& operator=(const TB&) { - throw TAssignBCalled(); + throw TAssignBCalled(); return *this; } @@ -69,7 +69,7 @@ Y_UNIT_TEST_SUITE(TestMemCopy) { TC c1[5]; TC c2[5]; - UNIT_ASSERT_EXCEPTION(MemCopy(c2, c1, 5), TAssignBCalled); + UNIT_ASSERT_EXCEPTION(MemCopy(c2, c1, 5), TAssignBCalled); } template <class T> diff --git a/util/generic/ptr.h b/util/generic/ptr.h index 49a6fca6ae..19db0e3ec5 100644 --- a/util/generic/ptr.h +++ b/util/generic/ptr.h @@ -602,17 +602,17 @@ private: mutable T* T_; }; -template <class T, class Ops> +template <class T, class Ops> struct THash<TIntrusivePtr<T, Ops>>: THash<const T*> { - using THash<const T*>::operator(); - inline size_t operator()(const TIntrusivePtr<T, Ops>& ptr) const { - return THash<const T*>::operator()(ptr.Get()); - } -}; - + using THash<const T*>::operator(); + inline size_t operator()(const TIntrusivePtr<T, Ops>& ptr) const { + return THash<const T*>::operator()(ptr.Get()); + } +}; + // Behaves like TIntrusivePtr but returns const T* to prevent user from accidentally modifying the referenced object. template <class T, class Ops> -class TIntrusiveConstPtr: public TPointerBase<TIntrusiveConstPtr<T, Ops>, const T> { +class TIntrusiveConstPtr: public TPointerBase<TIntrusiveConstPtr<T, Ops>, const T> { public: inline TIntrusiveConstPtr(T* t = nullptr) noexcept // we need a non-const pointer to Ref(), UnRef() and eventually delete it. : T_(t) @@ -718,13 +718,13 @@ private: template <class T, class Ops> struct THash<TIntrusiveConstPtr<T, Ops>>: THash<const T*> { - using THash<const T*>::operator(); - inline size_t operator()(const TIntrusiveConstPtr<T, Ops>& ptr) const { - return THash<const T*>::operator()(ptr.Get()); - } -}; - -template <class T, class Ops> + using THash<const T*>::operator(); + inline size_t operator()(const TIntrusiveConstPtr<T, Ops>& ptr) const { + return THash<const T*>::operator()(ptr.Get()); + } +}; + +template <class T, class Ops> class TSimpleIntrusiveOps { using TFunc = void (*)(T*) #if __cplusplus >= 201703 @@ -932,14 +932,14 @@ private: C* C_; }; -template <class T, class C, class D> +template <class T, class C, class D> struct THash<TSharedPtr<T, C, D>>: THash<const T*> { - using THash<const T*>::operator(); - inline size_t operator()(const TSharedPtr<T, C, D>& ptr) const { - return THash<const T*>::operator()(ptr.Get()); - } -}; - + using THash<const T*>::operator(); + inline size_t operator()(const TSharedPtr<T, C, D>& ptr) const { + return THash<const T*>::operator()(ptr.Get()); + } +}; + template <class T, class D = TDelete> using TAtomicSharedPtr = TSharedPtr<T, TAtomicCounter, D>; diff --git a/util/generic/ptr_ut.cpp b/util/generic/ptr_ut.cpp index 210e562a36..c2dcff23f6 100644 --- a/util/generic/ptr_ut.cpp +++ b/util/generic/ptr_ut.cpp @@ -4,8 +4,8 @@ #include <library/cpp/testing/unittest/registar.h> -#include <util/generic/hash_set.h> -#include <util/generic/is_in.h> +#include <util/generic/hash_set.h> +#include <util/generic/is_in.h> #include <util/stream/output.h> #include <util/system/thread.h> @@ -31,9 +31,9 @@ class TPointerTest: public TTestBase { UNIT_TEST(TestCopyOnWritePtr2); UNIT_TEST(TestOperatorBool); UNIT_TEST(TestMakeShared); - UNIT_TEST(TestComparison); + UNIT_TEST(TestComparison); UNIT_TEST(TestSimpleIntrusivePtrCtorTsan); - UNIT_TEST(TestRefCountedPtrsInHashSet) + UNIT_TEST(TestRefCountedPtrsInHashSet) UNIT_TEST_SUITE_END(); private: @@ -83,10 +83,10 @@ private: void TestCopyOnWritePtr2(); void TestOperatorBool(); void TestMakeShared(); - void TestComparison(); - template <class T, class TRefCountedPtr> - void TestRefCountedPtrsInHashSetImpl(); - void TestRefCountedPtrsInHashSet(); + void TestComparison(); + template <class T, class TRefCountedPtr> + void TestRefCountedPtrsInHashSetImpl(); + void TestRefCountedPtrsInHashSet(); }; UNIT_TEST_SUITE_REGISTRATION(TPointerTest); @@ -709,73 +709,73 @@ void TPointerTest::TestMakeShared() { } } -template <class TPtr> -void TestPtrComparison(const TPtr& ptr) { - UNIT_ASSERT(ptr == ptr); - UNIT_ASSERT(!(ptr != ptr)); - UNIT_ASSERT(ptr == ptr.Get()); - UNIT_ASSERT(!(ptr != ptr.Get())); -} - -void TPointerTest::TestComparison() { +template <class TPtr> +void TestPtrComparison(const TPtr& ptr) { + UNIT_ASSERT(ptr == ptr); + UNIT_ASSERT(!(ptr != ptr)); + UNIT_ASSERT(ptr == ptr.Get()); + UNIT_ASSERT(!(ptr != ptr.Get())); +} + +void TPointerTest::TestComparison() { THolder<A> ptr1(new A); TAutoPtr<A> ptr2; TSimpleSharedPtr<int> ptr3(new int(6)); TIntrusivePtr<A> ptr4; - TIntrusiveConstPtr<A> ptr5 = ptr4; + TIntrusiveConstPtr<A> ptr5 = ptr4; UNIT_ASSERT(ptr1 != nullptr); UNIT_ASSERT(ptr2 == nullptr); UNIT_ASSERT(ptr3 != nullptr); UNIT_ASSERT(ptr4 == nullptr); - UNIT_ASSERT(ptr5 == nullptr); - - TestPtrComparison(ptr1); - TestPtrComparison(ptr2); - TestPtrComparison(ptr3); - TestPtrComparison(ptr4); - TestPtrComparison(ptr5); + UNIT_ASSERT(ptr5 == nullptr); + + TestPtrComparison(ptr1); + TestPtrComparison(ptr2); + TestPtrComparison(ptr3); + TestPtrComparison(ptr4); + TestPtrComparison(ptr5); } - -template <class T, class TRefCountedPtr> -void TPointerTest::TestRefCountedPtrsInHashSetImpl() { - THashSet<TRefCountedPtr> hashSet; - TRefCountedPtr p1(new T()); - UNIT_ASSERT(!IsIn(hashSet, p1)); - UNIT_ASSERT(hashSet.insert(p1).second); - UNIT_ASSERT(IsIn(hashSet, p1)); - UNIT_ASSERT_VALUES_EQUAL(hashSet.size(), 1); - UNIT_ASSERT(!hashSet.insert(p1).second); - - TRefCountedPtr p2(new T()); - UNIT_ASSERT(!IsIn(hashSet, p2)); - UNIT_ASSERT(hashSet.insert(p2).second); - UNIT_ASSERT(IsIn(hashSet, p2)); - UNIT_ASSERT_VALUES_EQUAL(hashSet.size(), 2); -} - + +template <class T, class TRefCountedPtr> +void TPointerTest::TestRefCountedPtrsInHashSetImpl() { + THashSet<TRefCountedPtr> hashSet; + TRefCountedPtr p1(new T()); + UNIT_ASSERT(!IsIn(hashSet, p1)); + UNIT_ASSERT(hashSet.insert(p1).second); + UNIT_ASSERT(IsIn(hashSet, p1)); + UNIT_ASSERT_VALUES_EQUAL(hashSet.size(), 1); + UNIT_ASSERT(!hashSet.insert(p1).second); + + TRefCountedPtr p2(new T()); + UNIT_ASSERT(!IsIn(hashSet, p2)); + UNIT_ASSERT(hashSet.insert(p2).second); + UNIT_ASSERT(IsIn(hashSet, p2)); + UNIT_ASSERT_VALUES_EQUAL(hashSet.size(), 2); +} + struct TCustomIntrusivePtrOps: TDefaultIntrusivePtrOps<A> { -}; - +}; + struct TCustomDeleter: TDelete { -}; - +}; + struct TCustomCounter: TSimpleCounter { - using TSimpleCounterTemplate::TSimpleCounterTemplate; -}; - -void TPointerTest::TestRefCountedPtrsInHashSet() { - // test common case - TestRefCountedPtrsInHashSetImpl<TString, TSimpleSharedPtr<TString>>(); - TestRefCountedPtrsInHashSetImpl<TString, TAtomicSharedPtr<TString>>(); - TestRefCountedPtrsInHashSetImpl<A, TIntrusivePtr<A>>(); - TestRefCountedPtrsInHashSetImpl<A, TIntrusiveConstPtr<A>>(); - - // test with custom ops - TestRefCountedPtrsInHashSetImpl<TString, TSharedPtr<TString, TCustomCounter, TCustomDeleter>>(); - TestRefCountedPtrsInHashSetImpl<A, TIntrusivePtr<A, TCustomIntrusivePtrOps>>(); - TestRefCountedPtrsInHashSetImpl<A, TIntrusiveConstPtr<A, TCustomIntrusivePtrOps>>(); -} + using TSimpleCounterTemplate::TSimpleCounterTemplate; +}; + +void TPointerTest::TestRefCountedPtrsInHashSet() { + // test common case + TestRefCountedPtrsInHashSetImpl<TString, TSimpleSharedPtr<TString>>(); + TestRefCountedPtrsInHashSetImpl<TString, TAtomicSharedPtr<TString>>(); + TestRefCountedPtrsInHashSetImpl<A, TIntrusivePtr<A>>(); + TestRefCountedPtrsInHashSetImpl<A, TIntrusiveConstPtr<A>>(); + + // test with custom ops + TestRefCountedPtrsInHashSetImpl<TString, TSharedPtr<TString, TCustomCounter, TCustomDeleter>>(); + TestRefCountedPtrsInHashSetImpl<A, TIntrusivePtr<A, TCustomIntrusivePtrOps>>(); + TestRefCountedPtrsInHashSetImpl<A, TIntrusiveConstPtr<A, TCustomIntrusivePtrOps>>(); +} class TRefCountedWithStatistics: public TNonCopyable { public: diff --git a/util/generic/strbuf.h b/util/generic/strbuf.h index 390f30e53d..70b9360d58 100644 --- a/util/generic/strbuf.h +++ b/util/generic/strbuf.h @@ -456,13 +456,13 @@ public: // string subsequences return *this; } - // coverity[exn_spec_violation] + // coverity[exn_spec_violation] inline TdSelf& Trunc(size_t targetSize) noexcept { - // Coverity false positive issue - // exn_spec_violation: An exception of type "std::out_of_range" is thrown but the exception specification "noexcept" doesn't allow it to be thrown. This will result in a call to terminate(). - // fun_call_w_exception: Called function TStringView::substr throws an exception of type "std::out_of_range". - // Suppress this issue because we pass argument pos=0 and string_view can't throw std::out_of_range. - *this = TStringView::substr(0, targetSize); //WARN: removing TStringView:: will lead to an infinite recursion + // Coverity false positive issue + // exn_spec_violation: An exception of type "std::out_of_range" is thrown but the exception specification "noexcept" doesn't allow it to be thrown. This will result in a call to terminate(). + // fun_call_w_exception: Called function TStringView::substr throws an exception of type "std::out_of_range". + // Suppress this issue because we pass argument pos=0 and string_view can't throw std::out_of_range. + *this = TStringView::substr(0, targetSize); //WARN: removing TStringView:: will lead to an infinite recursion return *this; } diff --git a/util/generic/strbuf_ut.cpp b/util/generic/strbuf_ut.cpp index 01d88d1b9f..69cde785af 100644 --- a/util/generic/strbuf_ut.cpp +++ b/util/generic/strbuf_ut.cpp @@ -332,20 +332,20 @@ Y_UNIT_TEST_SUITE(TStrBufTest) { char data[] = "Hello\0word"; PassByConstReference(data); } - - Y_UNIT_TEST(TestTruncate) { - TStringBuf s = "123"; - s.Trunc(5); - UNIT_ASSERT_STRINGS_EQUAL(s, "123"); - s.Trunc(3); - UNIT_ASSERT_STRINGS_EQUAL(s, "123"); - s.Trunc(1); - UNIT_ASSERT_STRINGS_EQUAL(s, "1"); - s.Trunc(0); - UNIT_ASSERT_STRINGS_EQUAL(s, ""); - s.Trunc(0); - UNIT_ASSERT_STRINGS_EQUAL(s, ""); - } + + Y_UNIT_TEST(TestTruncate) { + TStringBuf s = "123"; + s.Trunc(5); + UNIT_ASSERT_STRINGS_EQUAL(s, "123"); + s.Trunc(3); + UNIT_ASSERT_STRINGS_EQUAL(s, "123"); + s.Trunc(1); + UNIT_ASSERT_STRINGS_EQUAL(s, "1"); + s.Trunc(0); + UNIT_ASSERT_STRINGS_EQUAL(s, ""); + s.Trunc(0); + UNIT_ASSERT_STRINGS_EQUAL(s, ""); + } } Y_UNIT_TEST_SUITE(TWtrBufTest) { diff --git a/util/generic/typetraits.h b/util/generic/typetraits.h index 26ddb039d2..d165bd1a06 100644 --- a/util/generic/typetraits.h +++ b/util/generic/typetraits.h @@ -198,9 +198,9 @@ class TTypeTraits<void>: public TTypeTraitsBase<void> {}; struct THas##name: std::false_type {}; \ template <class T> \ struct THas##name<T, ::TVoidT<typename T::subtype>>: std::true_type {}; - + #define Y_HAS_SUBTYPE_IMPL_1(name) Y_HAS_SUBTYPE_IMPL_2(name, name) - + /* @def Y_HAS_SUBTYPE * * This macro should be used to define compile-time introspection helper classes for template diff --git a/util/generic/yexception_ut.cpp b/util/generic/yexception_ut.cpp index f8560cde23..cb3e29fed8 100644 --- a/util/generic/yexception_ut.cpp +++ b/util/generic/yexception_ut.cpp @@ -1,11 +1,11 @@ #include "yexception.h" static inline void Throw1DontMove() { - ythrow yexception() << "blabla"; // don't move this line + ythrow yexception() << "blabla"; // don't move this line } static inline void Throw2DontMove() { - ythrow yexception() << 1 << " qw " << 12.1; // don't move this line + ythrow yexception() << 1 << " qw " << 12.1; // don't move this line } #include <library/cpp/testing/unittest/registar.h> @@ -14,7 +14,7 @@ static inline void Throw2DontMove() { #include <util/memory/tempbuf.h> #include <util/random/mersenne.h> #include <util/stream/output.h> -#include <util/string/subst.h> +#include <util/string/subst.h> #include "yexception_ut.h" #include "bt_exception.h" @@ -218,18 +218,18 @@ private: } } - static inline void CheckCurrentExceptionContains(const char* message) { + static inline void CheckCurrentExceptionContains(const char* message) { TString err = CurrentExceptionMessage(); - SubstGlobal(err, '\\', '/'); // remove backslashes from path in message - UNIT_ASSERT(err.Contains(message)); - } - + SubstGlobal(err, '\\', '/'); // remove backslashes from path in message + UNIT_ASSERT(err.Contains(message)); + } + inline void TestRaise1() { try { Throw2DontMove(); UNIT_ASSERT(false); } catch (...) { - CheckCurrentExceptionContains("util/generic/yexception_ut.cpp:8: 1 qw 12.1"); + CheckCurrentExceptionContains("util/generic/yexception_ut.cpp:8: 1 qw 12.1"); } } @@ -240,9 +240,9 @@ private: inline void TestLineInfo() { try { Throw1DontMove(); - UNIT_ASSERT(false); + UNIT_ASSERT(false); } catch (...) { - CheckCurrentExceptionContains("util/generic/yexception_ut.cpp:4: blabla"); + CheckCurrentExceptionContains("util/generic/yexception_ut.cpp:4: blabla"); throw; } diff --git a/util/stream/zlib.cpp b/util/stream/zlib.cpp index 177fb20b05..60f4e9439f 100644 --- a/util/stream/zlib.cpp +++ b/util/stream/zlib.cpp @@ -1,7 +1,7 @@ #include "zlib.h" #include <util/memory/addstorage.h> -#include <util/generic/scope.h> +#include <util/generic/scope.h> #include <util/generic/utility.h> #include <contrib/libs/zlib/zlib.h> diff --git a/util/string/builder.h b/util/string/builder.h index 11eb840e23..7b54821151 100644 --- a/util/string/builder.h +++ b/util/string/builder.h @@ -4,14 +4,14 @@ #include <utility> #include <util/generic/string.h> -namespace NPrivateStringBuilder { +namespace NPrivateStringBuilder { class TStringBuilder: public TString { public: inline TStringBuilder() : Out(*this) { } - + TStringBuilder(TStringBuilder&& rhs) : TString(std::move(rhs)) , Out(*this) @@ -31,9 +31,9 @@ namespace NPrivateStringBuilder { template <class T> static inline TStringBuilder&& operator<<(TStringBuilder&& builder, const T& t) { builder.Out << t; - + return std::move(builder); } -} - -using TStringBuilder = NPrivateStringBuilder::TStringBuilder; +} + +using TStringBuilder = NPrivateStringBuilder::TStringBuilder; diff --git a/util/string/builder_ut.cpp b/util/string/builder_ut.cpp index 28777c87c1..22def683ec 100644 --- a/util/string/builder_ut.cpp +++ b/util/string/builder_ut.cpp @@ -37,27 +37,27 @@ Y_UNIT_TEST_SUITE(TStringBuilderTest) { out << sb; TestEquals("a", s); } - + Y_UNIT_TEST(TestStringBuilderRValue) { - struct TRValueAcceptTester { + struct TRValueAcceptTester { static bool IsRValue(const TString&) { - return false; - } - + return false; + } + static bool IsRValue(TString&&) { - return true; - } - }; - - UNIT_ASSERT(TRValueAcceptTester::IsRValue(TStringBuilder() << "a" << 1)); - - TStringBuilder b; - UNIT_ASSERT(!TRValueAcceptTester::IsRValue(b << "a" << 1)); - TStringBuilder b2; - UNIT_ASSERT(!TRValueAcceptTester::IsRValue(b2 << "a" << 1 << TStringBuilder() << "a")); - UNIT_ASSERT_VALUES_EQUAL("a1a", b2); - - UNIT_ASSERT(TRValueAcceptTester::IsRValue(TStringBuilder() << b2)); - UNIT_ASSERT_VALUES_EQUAL("a1a", TStringBuilder() << b2); - } + return true; + } + }; + + UNIT_ASSERT(TRValueAcceptTester::IsRValue(TStringBuilder() << "a" << 1)); + + TStringBuilder b; + UNIT_ASSERT(!TRValueAcceptTester::IsRValue(b << "a" << 1)); + TStringBuilder b2; + UNIT_ASSERT(!TRValueAcceptTester::IsRValue(b2 << "a" << 1 << TStringBuilder() << "a")); + UNIT_ASSERT_VALUES_EQUAL("a1a", b2); + + UNIT_ASSERT(TRValueAcceptTester::IsRValue(TStringBuilder() << b2)); + UNIT_ASSERT_VALUES_EQUAL("a1a", TStringBuilder() << b2); + } } diff --git a/util/string/cast_ut.cpp b/util/string/cast_ut.cpp index 4e53d6bf7a..033450c38c 100644 --- a/util/string/cast_ut.cpp +++ b/util/string/cast_ut.cpp @@ -5,8 +5,8 @@ #include <util/charset/wide.h> #include <util/system/defaults.h> -#include <limits> - +#include <limits> + // positive test (return true or no exception) #define test1(t, v) \ F<t>().CheckTryOK(v); \ @@ -279,14 +279,14 @@ Y_UNIT_TEST_SUITE(TCastTest) { UNIT_ASSERT_VALUES_EQUAL(FloatToString(1.2345678901234567), "1.2345678901234567"); // no truncation UNIT_ASSERT_VALUES_EQUAL(FloatToString(5e-324), "5e-324"); // denormalized UNIT_ASSERT_VALUES_EQUAL(FloatToString(-0.0), "-0"); // sign must be preserved - - UNIT_ASSERT_STRINGS_EQUAL(FloatToString(std::numeric_limits<double>::quiet_NaN()), "nan"); - UNIT_ASSERT_STRINGS_EQUAL(FloatToString(std::numeric_limits<double>::infinity()), "inf"); + + UNIT_ASSERT_STRINGS_EQUAL(FloatToString(std::numeric_limits<double>::quiet_NaN()), "nan"); + UNIT_ASSERT_STRINGS_EQUAL(FloatToString(std::numeric_limits<double>::infinity()), "inf"); UNIT_ASSERT_STRINGS_EQUAL(FloatToString(-std::numeric_limits<double>::infinity()), "-inf"); UNIT_ASSERT_STRINGS_EQUAL(FloatToString(std::numeric_limits<float>::quiet_NaN()), "nan"); UNIT_ASSERT_STRINGS_EQUAL(FloatToString(std::numeric_limits<float>::infinity()), "inf"); - UNIT_ASSERT_STRINGS_EQUAL(FloatToString(-std::numeric_limits<float>::infinity()), "-inf"); + UNIT_ASSERT_STRINGS_EQUAL(FloatToString(-std::numeric_limits<float>::infinity()), "-inf"); } Y_UNIT_TEST(TestReadFloats) { diff --git a/util/string/strip.h b/util/string/strip.h index c9172ef19a..d5ef6da96d 100644 --- a/util/string/strip.h +++ b/util/string/strip.h @@ -69,11 +69,11 @@ struct TStripImpl { const size_t oldLen = e - b; if (stripBeg) { - StripRangeBegin(b, e, criterion); + StripRangeBegin(b, e, criterion); } if (stripEnd) { - StripRangeEnd(b, e, criterion); + StripRangeEnd(b, e, criterion); } const size_t newLen = e - b; @@ -85,7 +85,7 @@ struct TStripImpl { auto b = from.begin(); auto e = from.end(); - if (StripRange(b, e, criterion)) { + if (StripRange(b, e, criterion)) { to = T(b, e - b); return true; @@ -99,7 +99,7 @@ struct TStripImpl { template <class T, class TStripCriterion> static inline T StripString(const T& from, TStripCriterion&& criterion) { T ret; - StripString(from, ret, criterion); + StripString(from, ret, criterion); return ret; } @@ -111,7 +111,7 @@ struct TStripImpl { template <class It, class TStripCriterion> inline bool StripRange(It& b, It& e, TStripCriterion&& criterion) noexcept { - return TStripImpl<true, true>::StripRange(b, e, criterion); + return TStripImpl<true, true>::StripRange(b, e, criterion); } template <class It> @@ -123,7 +123,7 @@ template <class It, class TStripCriterion> inline bool Strip(It& b, size_t& len, TStripCriterion&& criterion) noexcept { It e = b + len; - if (StripRange(b, e, criterion)) { + if (StripRange(b, e, criterion)) { len = e - b; return true; @@ -139,7 +139,7 @@ inline bool Strip(It& b, size_t& len) noexcept { template <class T, class TStripCriterion> static inline bool StripString(const T& from, T& to, TStripCriterion&& criterion) { - return TStripImpl<true, true>::StripString(from, to, criterion); + return TStripImpl<true, true>::StripString(from, to, criterion); } template <class T> @@ -149,7 +149,7 @@ static inline bool StripString(const T& from, T& to) { template <class T, class TStripCriterion> static inline T StripString(const T& from, TStripCriterion&& criterion) { - return TStripImpl<true, true>::StripString(from, criterion); + return TStripImpl<true, true>::StripString(from, criterion); } template <class T> @@ -169,12 +169,12 @@ static inline T StripStringRight(const T& from) { template <class T, class TStripCriterion> static inline T StripStringLeft(const T& from, TStripCriterion&& criterion) { - return TStripImpl<true, false>::StripString(from, criterion); + return TStripImpl<true, false>::StripString(from, criterion); } template <class T, class TStripCriterion> static inline T StripStringRight(const T& from, TStripCriterion&& criterion) { - return TStripImpl<false, true>::StripString(from, criterion); + return TStripImpl<false, true>::StripString(from, criterion); } /// Copies the given string removing leading and trailing spaces. diff --git a/util/string/subst_ut.cpp b/util/string/subst_ut.cpp index 60ea6aabba..21eccef779 100644 --- a/util/string/subst_ut.cpp +++ b/util/string/subst_ut.cpp @@ -130,8 +130,8 @@ Y_UNIT_TEST_SUITE(TStringSubst) { s = "aaa"; SubstGlobal(s, "a", ""); UNIT_ASSERT_EQUAL(s, TString("")); - s = "abcdefbcbcdfb"; - SubstGlobal(s, "bc", "bbc", 2); + s = "abcdefbcbcdfb"; + SubstGlobal(s, "bc", "bbc", 2); UNIT_ASSERT_EQUAL(s, TString("abcdefbbcbbcdfb")); s = "Москва ~ Париж"; SubstGlobal(s, " ~ ", " "); @@ -166,7 +166,7 @@ Y_UNIT_TEST_SUITE(TStringSubst) { UNIT_ASSERT_EQUAL(w, u"abcdaBcd"); TString s = "aaa"; - SubstGlobal(s, 'a', 'b', 1); + SubstGlobal(s, 'a', 'b', 1); UNIT_ASSERT_EQUAL(s, TString("abb")); } diff --git a/util/system/execpath.cpp b/util/system/execpath.cpp index 1c91cd1902..33198af58b 100644 --- a/util/system/execpath.cpp +++ b/util/system/execpath.cpp @@ -64,7 +64,7 @@ static inline TString FreeBSDGetExecPath() { * https://www.freebsd.org/cgi/man.cgi?query=procfs&sektion=5&format=html */ TString path("/proc/curproc/file"); - return NFs::ReadLink(path); + return NFs::ReadLink(path); } else { return TString(); } @@ -129,7 +129,7 @@ static TString GetExecPathImpl() { } #elif defined(_linux_) || defined(_cygwin_) TString path("/proc/self/exe"); - return NFs::ReadLink(path); + return NFs::ReadLink(path); // TODO(yoda): check if the filename ends with " (deleted)" #elif defined(_freebsd_) TString execPath = FreeBSDGetExecPath(); diff --git a/util/system/file.cpp b/util/system/file.cpp index 6bf3ae81fd..4a261d020c 100644 --- a/util/system/file.cpp +++ b/util/system/file.cpp @@ -134,7 +134,7 @@ TFileHandle::TFileHandle(const TString& fName, EOpenMode oMode) noexcept { attrMode |= /*FILE_FLAG_NO_BUFFERING |*/ FILE_FLAG_WRITE_THROUGH; } - Fd_ = NFsPrivate::CreateFileWithUtf8Name(fName, faMode, shMode, fcMode, attrMode, inheritHandle); + Fd_ = NFsPrivate::CreateFileWithUtf8Name(fName, faMode, shMode, fcMode, attrMode, inheritHandle); if ((oMode & ::ForAppend) && (Fd_ != INVALID_FHANDLE)) { ::SetFilePointer(Fd_, 0, 0, FILE_END); diff --git a/util/system/file_ut.cpp b/util/system/file_ut.cpp index 83e6eb9c0d..941e6a50f3 100644 --- a/util/system/file_ut.cpp +++ b/util/system/file_ut.cpp @@ -210,7 +210,7 @@ void TFileTest::TestLocale() { UNIT_ASSERT_VALUES_EQUAL(f.GetName(), "Имя.txt"); UNIT_ASSERT_VALUES_EQUAL(f.GetLength(), 0); f.Close(); - UNIT_ASSERT(NFs::Remove("Имя.txt")); + UNIT_ASSERT(NFs::Remove("Имя.txt")); #ifdef _unix_ setlocale(LC_CTYPE, loc); #endif diff --git a/util/system/fs.cpp b/util/system/fs.cpp index e62be57d81..d2611a8ccc 100644 --- a/util/system/fs.cpp +++ b/util/system/fs.cpp @@ -18,7 +18,7 @@ bool NFs::Remove(const TString& path) { #if defined(_win_) - return NFsPrivate::WinRemove(path); + return NFsPrivate::WinRemove(path); #else return ::remove(path.data()) == 0; #endif @@ -86,21 +86,21 @@ bool NFs::MakeDirectoryRecursive(const TString& path, EFilePermissions mode, boo bool NFs::Rename(const TString& oldPath, const TString& newPath) { #if defined(_win_) - return NFsPrivate::WinRename(oldPath, newPath); + return NFsPrivate::WinRename(oldPath, newPath); #else return ::rename(oldPath.data(), newPath.data()) == 0; #endif } void NFs::HardLinkOrCopy(const TString& existingPath, const TString& newPath) { - if (!NFs::HardLink(existingPath, newPath)) { - Copy(existingPath, 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); + return NFsPrivate::WinHardLink(existingPath, newPath); #elif defined(_unix_) return (0 == link(existingPath.data(), newPath.data())); #endif @@ -108,7 +108,7 @@ bool NFs::HardLink(const TString& existingPath, const TString& newPath) { bool NFs::SymLink(const TString& targetPath, const TString& linkPath) { #if defined(_win_) - return NFsPrivate::WinSymLink(targetPath, linkPath); + return NFsPrivate::WinSymLink(targetPath, linkPath); #elif defined(_unix_) return 0 == symlink(targetPath.data(), linkPath.data()); #endif @@ -116,7 +116,7 @@ bool NFs::SymLink(const TString& targetPath, const TString& linkPath) { TString NFs::ReadLink(const TString& path) { #if defined(_win_) - return NFsPrivate::WinReadLink(path); + return NFsPrivate::WinReadLink(path); #elif defined(_unix_) TTempBuf buf; while (true) { @@ -148,7 +148,7 @@ void NFs::Copy(const TString& existingPath, const TString& newPath) { bool NFs::Exists(const TString& path) { #if defined(_win_) - return NFsPrivate::WinExists(path); + return NFsPrivate::WinExists(path); #elif defined(_unix_) return access(path.data(), F_OK) == 0; #endif diff --git a/util/system/fs.h b/util/system/fs.h index 11161c3a79..237daf2d2d 100644 --- a/util/system/fs.h +++ b/util/system/fs.h @@ -4,7 +4,7 @@ #include <util/generic/string.h> #include <util/generic/yexception.h> -namespace NFs { +namespace NFs { enum EFilePermission { FP_ALL_EXEC = 01, FP_ALL_WRITE = 02, @@ -23,11 +23,11 @@ namespace NFs { Y_DECLARE_FLAGS(EFilePermissions, EFilePermission); - /// Remove a file or empty directory - /// - /// @param[in] path Path to file or directory - /// @returns true on success or false otherwise - /// LastSystemError() is set in case of failure + /// Remove a file or empty directory + /// + /// @param[in] path Path to file or directory + /// @returns true on success or false otherwise + /// LastSystemError() is set in case of failure bool Remove(const TString& path); /// Remove a file or directory with contents @@ -77,54 +77,54 @@ namespace NFs { return MakeDirectoryRecursive(path, FP_COMMON_FILE, false); } - /// Rename a file or directory. - /// Removes newPath if it exists - /// - /// @param[in] oldPath Path to file or directory to rename - /// @param[in] newPath New path of file or directory - /// @returns true on success or false otherwise - /// LastSystemError() is set in case of failure + /// Rename a file or directory. + /// Removes newPath if it exists + /// + /// @param[in] oldPath Path to file or directory to rename + /// @param[in] newPath New path of file or directory + /// @returns true on success or false otherwise + /// LastSystemError() is set in case of failure bool Rename(const TString& oldPath, const TString& newPath); - - /// Creates a new directory entry for a file - /// or creates a new one with the same content - /// - /// @param[in] existingPath Path to an existing file - /// @param[in] newPath New path of file + + /// Creates a new directory entry for a file + /// or creates a new one with the same content + /// + /// @param[in] existingPath Path to an existing file + /// @param[in] newPath New path of file void HardLinkOrCopy(const TString& existingPath, const TString& newPath); - - /// Creates a new directory entry for a file - /// - /// @param[in] existingPath Path to an existing file - /// @param[in] newPath New path of file - /// @returns true if new link was created or false otherwise - /// LastSystemError() is set in case of failure + + /// Creates a new directory entry for a file + /// + /// @param[in] existingPath Path to an existing file + /// @param[in] newPath New path of file + /// @returns true if new link was created or false otherwise + /// LastSystemError() is set in case of failure bool HardLink(const TString& existingPath, const TString& newPath); - - /// Creates a symlink to a file - /// - /// @param[in] targetPath Path to a target file - /// @param[in] linkPath Path of symlink - /// @returns true if new link was created or false otherwise - /// LastSystemError() is set in case of failure + + /// Creates a symlink to a file + /// + /// @param[in] targetPath Path to a target file + /// @param[in] linkPath Path of symlink + /// @returns true if new link was created or false otherwise + /// LastSystemError() is set in case of failure bool SymLink(const TString& targetPath, const TString& linkPath); - - /// Reads value of a symbolic link - /// - /// @param[in] path Path to a symlink - /// @returns File path that a symlink points to + + /// Reads value of a symbolic link + /// + /// @param[in] path Path to a symlink + /// @returns File path that a symlink points to TString ReadLink(const TString& path); - - /// Append contents of a file to a new file - /// - /// @param[in] dstPath Path to a destination file - /// @param[in] srcPath Path to a source file + + /// Append contents of a file to a new file + /// + /// @param[in] dstPath Path to a destination file + /// @param[in] srcPath Path to a source file void Cat(const TString& dstPath, const TString& srcPath); - - /// Copy contents of a file to a new file - /// - /// @param[in] existingPath Path to an existing file - /// @param[in] newPath New path of file + + /// Copy contents of a file to a new file + /// + /// @param[in] existingPath Path to an existing file + /// @param[in] newPath New path of file void Copy(const TString& existingPath, const TString& newPath); /// Returns path to the current working directory diff --git a/util/system/fs_ut.cpp b/util/system/fs_ut.cpp index 7739866acb..de071ebf55 100644 --- a/util/system/fs_ut.cpp +++ b/util/system/fs_ut.cpp @@ -6,7 +6,7 @@ #include "sysstat.h" #include "fstat.h" #include <util/folder/dirut.h> -#include <util/folder/path.h> +#include <util/folder/path.h> //WARNING: on windows the test must be run with administative rules @@ -114,7 +114,7 @@ void RunRenameTest(TFsPath src, TFsPath dst) { file.Write("123", 3); } - UNIT_ASSERT(NFs::Rename(src, dst)); + UNIT_ASSERT(NFs::Rename(src, dst)); UNIT_ASSERT(NFs::Exists(dst)); UNIT_ASSERT(!NFs::Exists(src)); @@ -128,7 +128,7 @@ void RunRenameTest(TFsPath src, TFsPath dst) { TFile file(dir1 / src, CreateNew | WrOnly); file.Write("123", 3); } - UNIT_ASSERT(NFs::Rename(dir1, dir2)); + UNIT_ASSERT(NFs::Rename(dir1, dir2)); UNIT_ASSERT(NFs::Exists(dir2 / src)); UNIT_ASSERT(!NFs::Exists(dir1)); @@ -137,11 +137,11 @@ void RunRenameTest(TFsPath src, TFsPath dst) { UNIT_ASSERT_VALUES_EQUAL(file.GetLength(), 3); } - UNIT_ASSERT(!NFs::Remove(src)); - UNIT_ASSERT(NFs::Remove(dst)); - UNIT_ASSERT(!NFs::Remove(dir1)); - UNIT_ASSERT(NFs::Remove(dir2 / src)); - UNIT_ASSERT(NFs::Remove(dir2)); + UNIT_ASSERT(!NFs::Remove(src)); + UNIT_ASSERT(NFs::Remove(dst)); + UNIT_ASSERT(!NFs::Remove(dir1)); + UNIT_ASSERT(NFs::Remove(dir2 / src)); + UNIT_ASSERT(NFs::Remove(dir2)); } void TFsTest::TestRename() { @@ -182,8 +182,8 @@ static void RunHardlinkTest(const TFsPath& src, const TFsPath& dst) { UNIT_ASSERT_VALUES_EQUAL(file.GetLength(), 5); } - UNIT_ASSERT(NFs::Remove(dst)); - UNIT_ASSERT(NFs::Remove(src)); + UNIT_ASSERT(NFs::Remove(dst)); + UNIT_ASSERT(NFs::Remove(src)); } void TFsTest::TestHardlink() { @@ -260,20 +260,20 @@ static void RunSymLinkTest(TString fileLocalName, TString symLinkName) { UNIT_ASSERT(fs.IsSymlink()); } - UNIT_ASSERT(NFs::Remove(symLinkName)); + UNIT_ASSERT(NFs::Remove(symLinkName)); UNIT_ASSERT(NFs::Exists(srcFile)); - UNIT_ASSERT(NFs::Remove(linkD1)); + UNIT_ASSERT(NFs::Remove(linkD1)); UNIT_ASSERT(NFs::Exists(srcFile)); - UNIT_ASSERT(!NFs::Remove(subDir)); + UNIT_ASSERT(!NFs::Remove(subDir)); - UNIT_ASSERT(NFs::Remove(srcFile)); - UNIT_ASSERT(NFs::Remove(linkD2)); - UNIT_ASSERT(NFs::Remove(dangling)); - UNIT_ASSERT(NFs::Remove(subsubDir1)); - UNIT_ASSERT(NFs::Remove(subsubDir2)); - UNIT_ASSERT(NFs::Remove(subDir)); + UNIT_ASSERT(NFs::Remove(srcFile)); + UNIT_ASSERT(NFs::Remove(linkD2)); + UNIT_ASSERT(NFs::Remove(dangling)); + UNIT_ASSERT(NFs::Remove(subsubDir1)); + UNIT_ASSERT(NFs::Remove(subsubDir2)); + UNIT_ASSERT(NFs::Remove(subDir)); } void TFsTest::TestSymlink() { diff --git a/util/system/fs_win.cpp b/util/system/fs_win.cpp index 020d3ca453..a410ccac06 100644 --- a/util/system/fs_win.cpp +++ b/util/system/fs_win.cpp @@ -8,7 +8,7 @@ #include <winioctl.h> -namespace NFsPrivate { +namespace NFsPrivate { static LPCWSTR UTF8ToWCHAR(const TStringBuf str, TUtf16String& wstr) { wstr.resize(str.size()); size_t written = 0; @@ -41,31 +41,31 @@ namespace NFsPrivate { bool WinRename(const TString& oldPath, const TString& newPath) { TUtf16String op, np; - LPCWSTR opPtr = UTF8ToWCHAR(oldPath, op); - LPCWSTR npPtr = UTF8ToWCHAR(newPath, np); + LPCWSTR opPtr = UTF8ToWCHAR(oldPath, op); + LPCWSTR npPtr = UTF8ToWCHAR(newPath, np); if (!opPtr || !npPtr) { ::SetLastError(ERROR_INVALID_NAME); - return false; + return false; } - return MoveFileExW(opPtr, npPtr, MOVEFILE_REPLACE_EXISTING) != 0; + return MoveFileExW(opPtr, npPtr, MOVEFILE_REPLACE_EXISTING) != 0; } bool WinRemove(const TString& path) { TUtf16String wstr; - LPCWSTR wname = UTF8ToWCHAR(path, wstr); + LPCWSTR wname = UTF8ToWCHAR(path, wstr); if (!wname) { ::SetLastError(ERROR_INVALID_NAME); - return false; + return false; } WIN32_FILE_ATTRIBUTE_DATA fad; if (::GetFileAttributesExW(wname, GetFileExInfoStandard, &fad)) { if (fad.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) - return ::RemoveDirectoryW(wname) != 0; - return ::DeleteFileW(wname) != 0; + return ::RemoveDirectoryW(wname) != 0; + return ::DeleteFileW(wname) != 0; } - return false; + return false; } bool WinSymLink(const TString& targetName, const TString& linkName) { @@ -78,7 +78,7 @@ namespace NFsPrivate { TUtf16String tstr; LPCWSTR wname = UTF8ToWCHAR(tName, tstr); TUtf16String lstr; - LPCWSTR lname = UTF8ToWCHAR(linkName, lstr); + LPCWSTR lname = UTF8ToWCHAR(linkName, lstr); // we can't create a dangling link to a dir in this way ui32 attr = ::GetFileAttributesW(wname); @@ -103,8 +103,8 @@ namespace NFsPrivate { bool WinHardLink(const TString& existingPath, const TString& newPath) { TUtf16String ep, np; - LPCWSTR epPtr = UTF8ToWCHAR(existingPath, ep); - LPCWSTR npPtr = UTF8ToWCHAR(newPath, np); + LPCWSTR epPtr = UTF8ToWCHAR(existingPath, ep); + LPCWSTR npPtr = UTF8ToWCHAR(newPath, np); if (!epPtr || !npPtr) { ::SetLastError(ERROR_INVALID_NAME); return false; @@ -115,7 +115,7 @@ namespace NFsPrivate { bool WinExists(const TString& path) { TUtf16String buf; - LPCWSTR ptr = UTF8ToWCHAR(path, buf); + LPCWSTR ptr = UTF8ToWCHAR(path, buf); return ::GetFileAttributesW(ptr) != INVALID_FILE_ATTRIBUTES; } @@ -181,7 +181,7 @@ namespace NFsPrivate { // the end of edited part of <Ntifs.h> TString WinReadLink(const TString& name) { - TFileHandle h = CreateFileWithUtf8Name(name, GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING, + TFileHandle h = CreateFileWithUtf8Name(name, GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING, FILE_FLAG_OPEN_REPARSE_POINT | FILE_FLAG_BACKUP_SEMANTICS, true); TTempBuf buf; while (true) { @@ -204,7 +204,7 @@ namespace NFsPrivate { if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) { buf = TTempBuf(buf.Size() * 2); } else { - ythrow yexception() << "can't read link " << name; + ythrow yexception() << "can't read link " << name; } } } diff --git a/util/system/fstat.cpp b/util/system/fstat.cpp index 5db39741ae..81e98cbc6b 100644 --- a/util/system/fstat.cpp +++ b/util/system/fstat.cpp @@ -84,7 +84,7 @@ static bool GetStatByHandle(TSystemFStat& fs, FHANDLE f) { static bool GetStatByName(TSystemFStat& fs, const char* fileName, bool nofollow) { #ifdef _win_ - TFileHandle h = NFsPrivate::CreateFileWithUtf8Name(fileName, FILE_READ_ATTRIBUTES | FILE_READ_EA, FILE_SHARE_READ | FILE_SHARE_WRITE, + TFileHandle h = NFsPrivate::CreateFileWithUtf8Name(fileName, FILE_READ_ATTRIBUTES | FILE_READ_EA, FILE_SHARE_READ | FILE_SHARE_WRITE, OPEN_EXISTING, (nofollow ? FILE_FLAG_OPEN_REPARSE_POINT : 0) | FILE_FLAG_BACKUP_SEMANTICS, true); if (!h.IsOpen()) { diff --git a/util/system/fstat_ut.cpp b/util/system/fstat_ut.cpp index 938e017839..160ecd936e 100644 --- a/util/system/fstat_ut.cpp +++ b/util/system/fstat_ut.cpp @@ -53,7 +53,7 @@ Y_UNIT_TEST_SUITE(TestFileStat) { UNIT_ASSERT(fs.IsDir()); UNIT_ASSERT(!fs.IsSymlink()); //UNIT_ASSERT(fs.Size == 0); // it fails under unix - UNIT_ASSERT(NFs::Remove("tmpd")); + UNIT_ASSERT(NFs::Remove("tmpd")); fs = TFileStat("tmpd"); UNIT_ASSERT(!fs.IsFile()); UNIT_ASSERT(!fs.IsDir()); diff --git a/util/system/shellcommand.cpp b/util/system/shellcommand.cpp index 47eefde0cd..b1989b5c8c 100644 --- a/util/system/shellcommand.cpp +++ b/util/system/shellcommand.cpp @@ -218,7 +218,7 @@ private: bool QuoteArguments = false; bool DetachSession = false; bool CloseStreams = false; - TAtomic ShouldCloseInput; + TAtomic ShouldCloseInput; TShellCommandOptions::EHandleMode InputMode = TShellCommandOptions::HANDLE_STREAM; TShellCommandOptions::EHandleMode OutputMode = TShellCommandOptions::HANDLE_STREAM; TShellCommandOptions::EHandleMode ErrorMode = TShellCommandOptions::HANDLE_STREAM; @@ -415,7 +415,7 @@ public: } inline void CloseInput() { - AtomicSet(ShouldCloseInput, true); + AtomicSet(ShouldCloseInput, true); } inline static bool TerminateIsRequired(void* processInfo) { @@ -1035,7 +1035,7 @@ void TShellCommand::TImpl::Communicate(TProcessInfo* pi) { if (!bytesToWrite) { bytesToWrite = input->Read(inputBuffer.Data(), inputBuffer.Capacity()); if (bytesToWrite == 0) { - if (AtomicGet(pi->Parent->ShouldCloseInput)) { + if (AtomicGet(pi->Parent->ShouldCloseInput)) { input = nullptr; } continue; diff --git a/util/system/shellcommand_ut.cpp b/util/system/shellcommand_ut.cpp index 283bbd9283..9d849279d2 100644 --- a/util/system/shellcommand_ut.cpp +++ b/util/system/shellcommand_ut.cpp @@ -1,16 +1,16 @@ #include "shellcommand.h" -#include "compat.h" +#include "compat.h" #include "defaults.h" -#include "fs.h" +#include "fs.h" #include "sigset.h" -#include "spinlock.h" - +#include "spinlock.h" + #include <library/cpp/testing/unittest/env.h> #include <library/cpp/testing/unittest/registar.h> - -#include <util/folder/dirut.h> -#include <util/random/random.h> + +#include <util/folder/dirut.h> +#include <util/random/random.h> #include <util/stream/file.h> #include <util/stream/str.h> #include <util/stream/mem.h> @@ -28,37 +28,37 @@ const size_t textSize = 20000; #endif class TGuardedStringStream: public IInputStream, public IOutputStream { -public: - TGuardedStringStream() { +public: + TGuardedStringStream() { Stream_.Reserve(100); - } - + } + TString Str() const { with_lock (Lock_) { return Stream_.Str(); - } + } return TString(); // line for compiler - } - -protected: - size_t DoRead(void* buf, size_t len) override { + } + +protected: + size_t DoRead(void* buf, size_t len) override { with_lock (Lock_) { return Stream_.Read(buf, len); - } - return 0; // line for compiler - } - - void DoWrite(const void* buf, size_t len) override { + } + return 0; // line for compiler + } + + void DoWrite(const void* buf, size_t len) override { with_lock (Lock_) { return Stream_.Write(buf, len); - } - } - -private: + } + } + +private: TAdaptiveLock Lock_; TStringStream Stream_; -}; - +}; + Y_UNIT_TEST_SUITE(TShellQuoteTest) { Y_UNIT_TEST(TestQuoteArg) { TString cmd; @@ -232,9 +232,9 @@ Y_UNIT_TEST_SUITE(TShellCommandTest) { options.SetClearSignalMask(true); options.SetCloseAllFdsOnExec(true); options.SetCloseInput(false); - TGuardedStringStream write; + TGuardedStringStream write; options.SetInputStream(&write); - TGuardedStringStream read; + TGuardedStringStream read; options.SetOutputStream(&read); options.SetUseShell(true); @@ -283,12 +283,12 @@ Y_UNIT_TEST_SUITE(TShellCommandTest) { Y_UNIT_TEST(TestInterruptSimple) { TShellCommandOptions options; options.SetAsync(true); - options.SetCloseInput(false); - TGuardedStringStream write; - options.SetInputStream(&write); // set input stream that will be waited by cat + options.SetCloseInput(false); + TGuardedStringStream write; + options.SetInputStream(&write); // set input stream that will be waited by cat TShellCommand cmd(catCommand, options); cmd.Run(); - sleep(1); + sleep(1); UNIT_ASSERT(TShellCommand::SHELL_RUNNING == cmd.GetStatus()); cmd.Terminate(); cmd.Wait(); diff --git a/util/system/tempfile.h b/util/system/tempfile.h index 6fd736ad7b..de249c129d 100644 --- a/util/system/tempfile.h +++ b/util/system/tempfile.h @@ -14,7 +14,7 @@ public: } inline ~TTempFile() { - NFs::Remove(Name()); + NFs::Remove(Name()); } inline const TString& Name() const noexcept { |