diff options
author | nalpp <nalpp@yandex-team.ru> | 2022-02-10 16:46:46 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:46:46 +0300 |
commit | 30d1ef3941e0dc835be7609de5ebee66958f215a (patch) | |
tree | 49e222ea1c5804306084bb3ae065bb702625360f /util | |
parent | 87f3eb38999df2d3c1cb77f8ffb9c52ec9c516fb (diff) | |
download | ydb-30d1ef3941e0dc835be7609de5ebee66958f215a.tar.gz |
Restoring authorship annotation for <nalpp@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'util')
-rw-r--r-- | util/folder/path_ut.cpp | 140 | ||||
-rw-r--r-- | util/system/file.cpp | 12 | ||||
-rw-r--r-- | util/system/fs.cpp | 16 | ||||
-rw-r--r-- | util/system/fs.h | 2 | ||||
-rw-r--r-- | util/system/fs_ut.cpp | 14 | ||||
-rw-r--r-- | util/system/fs_win.cpp | 2 | ||||
-rw-r--r-- | util/system/shellcommand.cpp | 26 | ||||
-rw-r--r-- | util/system/shellcommand.h | 16 | ||||
-rw-r--r-- | util/system/shellcommand_ut.cpp | 24 |
9 files changed, 126 insertions, 126 deletions
diff --git a/util/folder/path_ut.cpp b/util/folder/path_ut.cpp index df67fc854f..e6a3451016 100644 --- a/util/folder/path_ut.cpp +++ b/util/folder/path_ut.cpp @@ -1,7 +1,7 @@ #include "path.h" #include "pathsplit.h" -#include "dirut.h" -#include "tempdir.h" +#include "dirut.h" +#include "tempdir.h" #include <library/cpp/testing/unittest/registar.h> @@ -9,8 +9,8 @@ #include <util/system/platform.h> #include <util/system/yassert.h> #include <util/stream/output.h> -#include <util/stream/file.h> -#include <util/system/fs.h> +#include <util/stream/file.h> +#include <util/system/fs.h> #include <algorithm> @@ -424,108 +424,108 @@ Y_UNIT_TEST_SUITE(TFsPathTests) { TFsPath pathThree{"/a/b"}; UNIT_ASSERT_VALUES_EQUAL(ToString(pathThree), "/a/b"); } - -#ifdef _unix_ + +#ifdef _unix_ Y_UNIT_TEST(TestRemoveSymlinkToDir) { - TTempDir tempDir; - TFsPath tempDirPath(tempDir()); - + TTempDir tempDir; + TFsPath tempDirPath(tempDir()); + const TString originDir = tempDirPath.Child("origin"); - MakePathIfNotExist(originDir.c_str()); - + MakePathIfNotExist(originDir.c_str()); + const TString originFile = TFsPath(originDir).Child("data"); - { + { TFixedBufferFileOutput out(originFile); - out << "data111!!!"; - } - + out << "data111!!!"; + } + const TString link = tempDirPath.Child("origin_symlink"); - NFs::SymLink(originDir, link); - - TFsPath(link).ForceDelete(); - + NFs::SymLink(originDir, link); + + TFsPath(link).ForceDelete(); + UNIT_ASSERT(!NFs::Exists(link)); UNIT_ASSERT(NFs::Exists(originFile)); UNIT_ASSERT(NFs::Exists(originDir)); - } - + } + Y_UNIT_TEST(TestRemoveSymlinkToFile) { - TTempDir tempDir; - TFsPath tempDirPath(tempDir()); - + TTempDir tempDir; + TFsPath tempDirPath(tempDir()); + const TString originDir = tempDirPath.Child("origin"); - MakePathIfNotExist(originDir.c_str()); - + MakePathIfNotExist(originDir.c_str()); + const TString originFile = TFsPath(originDir).Child("data"); - { + { TFixedBufferFileOutput out(originFile); - out << "data111!!!"; - } - + out << "data111!!!"; + } + const TString link = tempDirPath.Child("origin_symlink"); - NFs::SymLink(originFile, link); - - TFsPath(link).ForceDelete(); - + NFs::SymLink(originFile, link); + + TFsPath(link).ForceDelete(); + UNIT_ASSERT(!NFs::Exists(link)); UNIT_ASSERT(NFs::Exists(originFile)); UNIT_ASSERT(NFs::Exists(originDir)); - } - + } + Y_UNIT_TEST(TestRemoveDirWithSymlinkToDir) { - TTempDir tempDir; - TFsPath tempDirPath(tempDir()); - + TTempDir tempDir; + TFsPath tempDirPath(tempDir()); + const TString symlinkedDir = tempDirPath.Child("to_remove"); - MakePathIfNotExist(symlinkedDir.c_str()); - + MakePathIfNotExist(symlinkedDir.c_str()); + const TString originDir = tempDirPath.Child("origin"); - MakePathIfNotExist(originDir.c_str()); - + MakePathIfNotExist(originDir.c_str()); + const TString originFile = TFsPath(originDir).Child("data"); - { + { TFixedBufferFileOutput out(originFile); - out << "data111!!!"; - } - + out << "data111!!!"; + } + const TString symlinkedFile = TFsPath(symlinkedDir).Child("origin_symlink"); - NFs::SymLink(originDir, symlinkedFile); - - TFsPath(symlinkedDir).ForceDelete(); - + NFs::SymLink(originDir, symlinkedFile); + + TFsPath(symlinkedDir).ForceDelete(); + UNIT_ASSERT(!NFs::Exists(symlinkedFile)); UNIT_ASSERT(!NFs::Exists(symlinkedDir)); UNIT_ASSERT(NFs::Exists(originFile)); UNIT_ASSERT(NFs::Exists(originDir)); - } - + } + Y_UNIT_TEST(TestRemoveDirWithSymlinkToFile) { - TTempDir tempDir; - TFsPath tempDirPath(tempDir()); - + TTempDir tempDir; + TFsPath tempDirPath(tempDir()); + const TString symlinkedDir = tempDirPath.Child("to_remove"); - MakePathIfNotExist(symlinkedDir.c_str()); - + MakePathIfNotExist(symlinkedDir.c_str()); + const TString originDir = tempDirPath.Child("origin"); - MakePathIfNotExist(originDir.c_str()); - + MakePathIfNotExist(originDir.c_str()); + const TString originFile = TFsPath(originDir).Child("data"); - { + { TFixedBufferFileOutput out(originFile); - out << "data111!!!"; - } - + out << "data111!!!"; + } + const TString symlinkedFile = TFsPath(symlinkedDir).Child("origin_symlink"); - NFs::SymLink(originFile, symlinkedFile); - - TFsPath(symlinkedDir).ForceDelete(); - + NFs::SymLink(originFile, symlinkedFile); + + TFsPath(symlinkedDir).ForceDelete(); + UNIT_ASSERT(!NFs::Exists(symlinkedFile)); UNIT_ASSERT(!NFs::Exists(symlinkedDir)); UNIT_ASSERT(NFs::Exists(originFile)); UNIT_ASSERT(NFs::Exists(originDir)); - } -#endif + } +#endif Y_UNIT_TEST(TestForceDeleteNonexisting) { TTempDir tempDir; diff --git a/util/system/file.cpp b/util/system/file.cpp index 941a652d63..4a261d020c 100644 --- a/util/system/file.cpp +++ b/util/system/file.cpp @@ -111,8 +111,8 @@ TFileHandle::TFileHandle(const TString& fName, EOpenMode oMode) noexcept { faMode &= ~FILE_WRITE_DATA; } - bool inheritHandle = !(oMode & CloseOnExec); - + bool inheritHandle = !(oMode & CloseOnExec); + ui32 shMode = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE; ui32 attrMode = FILE_ATTRIBUTE_NORMAL; @@ -175,10 +175,10 @@ TFileHandle::TFileHandle(const TString& fName, EOpenMode oMode) noexcept { fcMode |= O_APPEND; } - if (oMode & CloseOnExec) { - fcMode |= O_CLOEXEC; - } - + if (oMode & CloseOnExec) { + fcMode |= O_CLOEXEC; + } + /* I don't now about this for unix... if (oMode & Temp) { } diff --git a/util/system/fs.cpp b/util/system/fs.cpp index 01ad2bb9b5..d2611a8ccc 100644 --- a/util/system/fs.cpp +++ b/util/system/fs.cpp @@ -71,16 +71,16 @@ bool NFs::MakeDirectoryRecursive(const TString& path, EFilePermissions mode, boo return true; } else { //NOTE: recursion is finite due to existence of "." and "/" - if (!NFs::MakeDirectoryRecursive(TFsPath(path).Parent(), mode, false)) { - return false; - } - - bool isDirMade = NFs::MakeDirectory(path, mode); - if (!isDirMade && alwaysCreate) { + if (!NFs::MakeDirectoryRecursive(TFsPath(path).Parent(), mode, false)) { + return false; + } + + bool isDirMade = NFs::MakeDirectory(path, mode); + if (!isDirMade && alwaysCreate) { ythrow TIoException() << "failed to create " << path << " with cwd (" << NFs::CurrentWorkingDirectory() << ")"; } - - return TFileStat(path).IsDir(); + + return TFileStat(path).IsDir(); } } diff --git a/util/system/fs.h b/util/system/fs.h index 129d5ccd89..237daf2d2d 100644 --- a/util/system/fs.h +++ b/util/system/fs.h @@ -64,7 +64,7 @@ namespace NFs { /// /// @param[in] path Path to be created /// @param[in] mode Access permissions field; NOTE: ignored on win - /// @returns true if target path created or exists (and directory) + /// @returns true if target path created or exists (and directory) inline bool MakeDirectoryRecursive(const TString& path, EFilePermissions mode) { return MakeDirectoryRecursive(path, mode, false); } diff --git a/util/system/fs_ut.cpp b/util/system/fs_ut.cpp index b96461a8a9..de071ebf55 100644 --- a/util/system/fs_ut.cpp +++ b/util/system/fs_ut.cpp @@ -63,13 +63,13 @@ void TFsTest::TestCreateRemove() { Touch(file3); //UNIT_ASSERT(NFs::SymLink(file3.RealPath(), link)); - UNIT_ASSERT(NFs::MakeDirectoryRecursive(dir1 / "subdir1" / "subdir2" / "subdir3" / "subdir4", NFs::FP_COMMON_FILE, false)); - UNIT_ASSERT(NFs::MakeDirectoryRecursive(dir1 / "subdir1" / "subdir2", NFs::FP_COMMON_FILE, false)); - - // the target path is a file or "subdirectory" of a file - UNIT_ASSERT(!NFs::MakeDirectoryRecursive(file1 / "subdir1" / "subdir2", NFs::FP_COMMON_FILE, false)); - UNIT_ASSERT(!NFs::MakeDirectoryRecursive(file1, NFs::FP_COMMON_FILE, false)); - + UNIT_ASSERT(NFs::MakeDirectoryRecursive(dir1 / "subdir1" / "subdir2" / "subdir3" / "subdir4", NFs::FP_COMMON_FILE, false)); + UNIT_ASSERT(NFs::MakeDirectoryRecursive(dir1 / "subdir1" / "subdir2", NFs::FP_COMMON_FILE, false)); + + // the target path is a file or "subdirectory" of a file + UNIT_ASSERT(!NFs::MakeDirectoryRecursive(file1 / "subdir1" / "subdir2", NFs::FP_COMMON_FILE, false)); + UNIT_ASSERT(!NFs::MakeDirectoryRecursive(file1, NFs::FP_COMMON_FILE, false)); + TString longUtf8Name = ""; while (longUtf8Name.size() < 255) { longUtf8Name = longUtf8Name + "fф"; diff --git a/util/system/fs_win.cpp b/util/system/fs_win.cpp index c76b25280e..a410ccac06 100644 --- a/util/system/fs_win.cpp +++ b/util/system/fs_win.cpp @@ -215,7 +215,7 @@ namespace NFsPrivate { /* bool GetObjectId(const char* path, GUID* id) { TFileHandle h = CreateFileWithUtf8Name(path, 0, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, - OPEN_EXISTING, FILE_FLAG_OPEN_REPARSE_POINT|FILE_FLAG_BACKUP_SEMANTICS, true); + OPEN_EXISTING, FILE_FLAG_OPEN_REPARSE_POINT|FILE_FLAG_BACKUP_SEMANTICS, true); if (h.IsOpen()) { FILE_OBJECTID_BUFFER fob; DWORD resSize = 0; diff --git a/util/system/shellcommand.cpp b/util/system/shellcommand.cpp index b712321c10..b1989b5c8c 100644 --- a/util/system/shellcommand.cpp +++ b/util/system/shellcommand.cpp @@ -195,7 +195,7 @@ private: TList<TString> Arguments; TString WorkDir; TAtomic ExecutionStatus; // TShellCommand::ECommandStatus - TMaybe<int> ExitCode; + TMaybe<int> ExitCode; IInputStream* InputStream; IOutputStream* OutputStream; IOutputStream* ErrorStream; @@ -362,10 +362,10 @@ public: return static_cast<ECommandStatus>(AtomicGet(ExecutionStatus)); } - inline TMaybe<int> GetExitCode() const { - return ExitCode; - } - + inline TMaybe<int> GetExitCode() const { + return ExitCode; + } + inline TProcessId GetPid() const { #if defined(_win_) return GetProcessId(Pid); @@ -1062,9 +1062,9 @@ void TShellCommand::TImpl::Communicate(TProcessInfo* pi) { // Otherwise there is no way for input stream provider to discover // that process has exited and stream shouldn't wait for new data. bool cleanExit = false; - TMaybe<int> processExitCode; + TMaybe<int> processExitCode; #if defined(_unix_) - processExitCode = WEXITSTATUS(status); + processExitCode = WEXITSTATUS(status); if (WIFEXITED(status) && processExitCode == 0) { cleanExit = true; } else if (WIFSIGNALED(status)) { @@ -1078,11 +1078,11 @@ void TShellCommand::TImpl::Communicate(TProcessInfo* pi) { } if (exitCode == 0) cleanExit = true; - processExitCode = static_cast<int>(exitCode); + processExitCode = static_cast<int>(exitCode); DBG(Cerr << "exit code: " << exitCode << Endl); } #endif - pi->Parent->ExitCode = processExitCode; + pi->Parent->ExitCode = processExitCode; if (cleanExit) { AtomicSet(pi->Parent->ExecutionStatus, SHELL_FINISHED); } else { @@ -1155,10 +1155,10 @@ TShellCommand::ECommandStatus TShellCommand::GetStatus() const { return Impl->GetStatus(); } -TMaybe<int> TShellCommand::GetExitCode() const { - return Impl->GetExitCode(); -} - +TMaybe<int> TShellCommand::GetExitCode() const { + return Impl->GetExitCode(); +} + TProcessId TShellCommand::GetPid() const { return Impl->GetPid(); } diff --git a/util/system/shellcommand.h b/util/system/shellcommand.h index ba30735c41..8730627fe5 100644 --- a/util/system/shellcommand.h +++ b/util/system/shellcommand.h @@ -5,7 +5,7 @@ #include <util/generic/list.h> #include <util/generic/hash.h> #include <util/generic/strbuf.h> -#include <util/generic/maybe.h> +#include <util/generic/maybe.h> #include <util/stream/input.h> #include <util/stream/output.h> #include "file.h" @@ -399,13 +399,13 @@ public: ECommandStatus GetStatus() const; /** - * @brief return exit code of finished process - * The value is unspecified in case of internal errors or if the process is running - * - * @return exit code - */ - TMaybe<int> GetExitCode() const; - + * @brief return exit code of finished process + * The value is unspecified in case of internal errors or if the process is running + * + * @return exit code + */ + TMaybe<int> GetExitCode() const; + /** * @brief get id of underlying process * @note depends on os: pid_t on UNIX, HANDLE on win diff --git a/util/system/shellcommand_ut.cpp b/util/system/shellcommand_ut.cpp index db5545ea88..9d849279d2 100644 --- a/util/system/shellcommand_ut.cpp +++ b/util/system/shellcommand_ut.cpp @@ -79,7 +79,7 @@ Y_UNIT_TEST_SUITE(TShellCommandTest) { UNIT_ASSERT_VALUES_EQUAL(cmd.GetError(), ""); UNIT_ASSERT_VALUES_EQUAL(cmd.GetOutput(), "hello" NL); UNIT_ASSERT(TShellCommand::SHELL_FINISHED == cmd.GetStatus()); - UNIT_ASSERT(cmd.GetExitCode().Defined() && 0 == cmd.GetExitCode()); + UNIT_ASSERT(cmd.GetExitCode().Defined() && 0 == cmd.GetExitCode()); UNIT_ASSERT_VALUES_EQUAL(cmd.GetQuotedCommand(), "echo hello"); } @@ -108,7 +108,7 @@ Y_UNIT_TEST_SUITE(TShellCommandTest) { UNIT_ASSERT_VALUES_EQUAL(cmd.GetOutput(), "hello\n"); #endif UNIT_ASSERT(TShellCommand::SHELL_FINISHED == cmd.GetStatus()); - UNIT_ASSERT(cmd.GetExitCode().Defined() && 0 == cmd.GetExitCode()); + UNIT_ASSERT(cmd.GetExitCode().Defined() && 0 == cmd.GetExitCode()); } // running with no shell is not implemented for win // there should be no problem with it as long as SearchPath is on @@ -130,7 +130,7 @@ Y_UNIT_TEST_SUITE(TShellCommandTest) { cmd.Run(); UNIT_ASSERT(TShellCommand::SHELL_ERROR == cmd.GetStatus()); - UNIT_ASSERT(cmd.GetExitCode().Defined() && 0 != cmd.GetExitCode()); + UNIT_ASSERT(cmd.GetExitCode().Defined() && 0 != cmd.GetExitCode()); } { options.SetUseShell(true); @@ -140,7 +140,7 @@ Y_UNIT_TEST_SUITE(TShellCommandTest) { cmd.Run(); UNIT_ASSERT(TShellCommand::SHELL_FINISHED == cmd.GetStatus()); UNIT_ASSERT_VALUES_EQUAL(cmd.GetError().size(), 0u); - UNIT_ASSERT(cmd.GetExitCode().Defined() && 0 == cmd.GetExitCode()); + UNIT_ASSERT(cmd.GetExitCode().Defined() && 0 == cmd.GetExitCode()); } } Y_UNIT_TEST(TestAsyncRun) { @@ -165,7 +165,7 @@ Y_UNIT_TEST_SUITE(TShellCommandTest) { #if !defined(_win_) UNIT_ASSERT(TShellCommand::SHELL_FINISHED == cmd.GetStatus()); UNIT_ASSERT_VALUES_EQUAL(cmd.GetOutput().size(), 0u); - UNIT_ASSERT(cmd.GetExitCode().Defined() && 0 == cmd.GetExitCode()); + UNIT_ASSERT(cmd.GetExitCode().Defined() && 0 == cmd.GetExitCode()); #endif } Y_UNIT_TEST(TestQuotes) { @@ -190,15 +190,15 @@ Y_UNIT_TEST_SUITE(TShellCommandTest) { cmd.Run().Wait(); UNIT_ASSERT(TShellCommand::SHELL_ERROR == cmd.GetStatus()); UNIT_ASSERT_VALUES_UNEQUAL(cmd.GetError().size(), 0u); - UNIT_ASSERT(cmd.GetExitCode().Defined() && 0 != cmd.GetExitCode()); + UNIT_ASSERT(cmd.GetExitCode().Defined() && 0 != cmd.GetExitCode()); } Y_UNIT_TEST(TestExitCode) { - TShellCommand cmd("grep qwerty qwerty"); // some nonexistent file name - cmd.Run().Wait(); - UNIT_ASSERT(TShellCommand::SHELL_ERROR == cmd.GetStatus()); + TShellCommand cmd("grep qwerty qwerty"); // some nonexistent file name + cmd.Run().Wait(); + UNIT_ASSERT(TShellCommand::SHELL_ERROR == cmd.GetStatus()); UNIT_ASSERT_VALUES_UNEQUAL(cmd.GetError().size(), 0u); - UNIT_ASSERT(cmd.GetExitCode().Defined() && 2 == cmd.GetExitCode()); - } + UNIT_ASSERT(cmd.GetExitCode().Defined() && 2 == cmd.GetExitCode()); + } // 'type con' and 'copy con con' want real console, not stdin, use sort Y_UNIT_TEST(TestInput) { TShellCommandOptions options; @@ -258,7 +258,7 @@ Y_UNIT_TEST_SUITE(TShellCommandTest) { UNIT_ASSERT_VALUES_EQUAL(cmd.GetError(), ""); UNIT_ASSERT(TShellCommand::SHELL_FINISHED == cmd.GetStatus()); UNIT_ASSERT_VALUES_EQUAL(read.Str(), "alpha" NL "omega" NL "zeta" NL); - UNIT_ASSERT(cmd.GetExitCode().Defined() && 0 == cmd.GetExitCode()); + UNIT_ASSERT(cmd.GetExitCode().Defined() && 0 == cmd.GetExitCode()); } Y_UNIT_TEST(TestStreamClose) { struct TStream: public IOutputStream { |