diff options
author | myltsev <myltsev@yandex-team.ru> | 2022-02-10 16:46:03 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:46:03 +0300 |
commit | fc361854fd6ee8d747229b090f0b8018e260d1fb (patch) | |
tree | 1a2c5ffcf89eb53ecd79dbc9bc0a195c27404d0c /util/system | |
parent | 9166d66c30c23c9e85a7c88185a068987148d23f (diff) | |
download | ydb-fc361854fd6ee8d747229b090f0b8018e260d1fb.tar.gz |
Restoring authorship annotation for <myltsev@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'util/system')
-rw-r--r-- | util/system/file.cpp | 66 | ||||
-rw-r--r-- | util/system/file.h | 28 | ||||
-rw-r--r-- | util/system/filemap.cpp | 12 | ||||
-rw-r--r-- | util/system/fstat.cpp | 22 | ||||
-rw-r--r-- | util/system/tempfile.cpp | 20 | ||||
-rw-r--r-- | util/system/tempfile.h | 8 | ||||
-rw-r--r-- | util/system/tempfile_ut.cpp | 28 |
7 files changed, 92 insertions, 92 deletions
diff --git a/util/system/file.cpp b/util/system/file.cpp index b468d2cfb4..4a261d020c 100644 --- a/util/system/file.cpp +++ b/util/system/file.cpp @@ -16,7 +16,7 @@ #include <util/random/random.h> -#include <util/generic/size_literals.h> +#include <util/generic/size_literals.h> #include <util/generic/string.h> #include <util/generic/ylimits.h> #include <util/generic/yexception.h> @@ -932,31 +932,31 @@ public: return res; } - // Maximum amount of bytes to be read via single system call. - // Some libraries fail when it is greater than max int. - // Syscalls can cause contention if they operate on very large data blocks. - static constexpr size_t MaxReadPortion = 1_GB; - + // Maximum amount of bytes to be read via single system call. + // Some libraries fail when it is greater than max int. + // Syscalls can cause contention if they operate on very large data blocks. + static constexpr size_t MaxReadPortion = 1_GB; + i32 RawRead(void* bufferIn, size_t numBytes) { - const size_t toRead = Min(MaxReadPortion, numBytes); - return Handle_.Read(bufferIn, toRead); - } - - size_t ReadOrFail(void* buf, size_t numBytes) { - const i32 reallyRead = RawRead(buf, numBytes); - - if (reallyRead < 0) { - ythrow TFileError() << "can not read data from " << FileName_.Quote(); - } - - return reallyRead; - } - + const size_t toRead = Min(MaxReadPortion, numBytes); + return Handle_.Read(bufferIn, toRead); + } + + size_t ReadOrFail(void* buf, size_t numBytes) { + const i32 reallyRead = RawRead(buf, numBytes); + + if (reallyRead < 0) { + ythrow TFileError() << "can not read data from " << FileName_.Quote(); + } + + return reallyRead; + } + size_t Read(void* bufferIn, size_t numBytes) { ui8* buf = (ui8*)bufferIn; while (numBytes) { - const size_t reallyRead = ReadOrFail(buf, numBytes); + const size_t reallyRead = ReadOrFail(buf, numBytes); if (reallyRead == 0) { // file exhausted @@ -976,16 +976,16 @@ public: } } - // Maximum amount of bytes to be written via single system call. - // Some libraries fail when it is greater than max int. - // Syscalls can cause contention if they operate on very large data blocks. - static constexpr size_t MaxWritePortion = 1_GB; - + // Maximum amount of bytes to be written via single system call. + // Some libraries fail when it is greater than max int. + // Syscalls can cause contention if they operate on very large data blocks. + static constexpr size_t MaxWritePortion = 1_GB; + void Write(const void* buffer, size_t numBytes) { const ui8* buf = (const ui8*)buffer; while (numBytes) { - const i32 toWrite = (i32)Min(MaxWritePortion, numBytes); + const i32 toWrite = (i32)Min(MaxWritePortion, numBytes); const i32 reallyWritten = Handle_.Write(buf, toWrite); if (reallyWritten < 0) { @@ -1001,7 +1001,7 @@ public: ui8* buf = (ui8*)bufferIn; while (numBytes) { - const i32 toRead = (i32)Min(MaxReadPortion, numBytes); + const i32 toRead = (i32)Min(MaxReadPortion, numBytes); const i32 reallyRead = RawPread(buf, toRead, offset); if (reallyRead < 0) { @@ -1035,7 +1035,7 @@ public: const ui8* buf = (const ui8*)buffer; while (numBytes) { - const i32 toWrite = (i32)Min(MaxWritePortion, numBytes); + const i32 toWrite = (i32)Min(MaxWritePortion, numBytes); const i32 reallyWritten = Handle_.Pwrite(buf, toWrite, offset); if (reallyWritten < 0) { @@ -1175,10 +1175,10 @@ i32 TFile::RawRead(void* buf, size_t len) { return Impl_->RawRead(buf, len); } -size_t TFile::ReadOrFail(void* buf, size_t len) { - return Impl_->ReadOrFail(buf, len); -} - +size_t TFile::ReadOrFail(void* buf, size_t len) { + return Impl_->ReadOrFail(buf, len); +} + void TFile::Load(void* buf, size_t len) { Impl_->Load(buf, len); } diff --git a/util/system/file.h b/util/system/file.h index 62622501c9..9502e159b6 100644 --- a/util/system/file.h +++ b/util/system/file.h @@ -172,28 +172,28 @@ public: void LinkTo(const TFile& f) const; TFile Duplicate() const; - // Reads up to 1 GB without retrying, returns -1 on error - i32 RawRead(void* buf, size_t len); - // Reads up to 1 GB without retrying, throws on error - size_t ReadOrFail(void* buf, size_t len); - // Retries incomplete reads until EOF, throws on error + // Reads up to 1 GB without retrying, returns -1 on error + i32 RawRead(void* buf, size_t len); + // Reads up to 1 GB without retrying, throws on error + size_t ReadOrFail(void* buf, size_t len); + // Retries incomplete reads until EOF, throws on error size_t Read(void* buf, size_t len); - // Reads exactly len bytes, throws on premature EOF or error + // Reads exactly len bytes, throws on premature EOF or error void Load(void* buf, size_t len); - - // Retries incomplete writes, will either write len bytes or throw + + // Retries incomplete writes, will either write len bytes or throw void Write(const void* buf, size_t len); - - // Retries incomplete reads until EOF, throws on error + + // Retries incomplete reads until EOF, throws on error size_t Pread(void* buf, size_t len, i64 offset) const; // Single pread call i32 RawPread(void* buf, ui32 len, i64 offset) const; - // Reads exactly len bytes, throws on premature EOF or error + // Reads exactly len bytes, throws on premature EOF or error void Pload(void* buf, size_t len, i64 offset) const; - - // Retries incomplete writes, will either write len bytes or throw + + // Retries incomplete writes, will either write len bytes or throw void Pwrite(const void* buf, size_t len, i64 offset) const; - + void Flock(int op); //do not use, their meaning very platform-dependant diff --git a/util/system/filemap.cpp b/util/system/filemap.cpp index 7cd3a9b42f..7454a4cb94 100644 --- a/util/system/filemap.cpp +++ b/util/system/filemap.cpp @@ -153,14 +153,14 @@ public: } void CheckFile() const { - if (!File_.IsOpen()) { + if (!File_.IsOpen()) { ythrow yexception() << "TMemoryMap: FILE '" << DbgName_ << "' is not open, " << LastSystemErrorText(); - } - if (Length_ < 0) { + } + if (Length_ < 0) { ythrow yexception() << "'" << DbgName_ << "' is not a regular file"; - } - } - + } + } + inline TImpl(FILE* f, EOpenMode om, TString dbgName) : File_(Duplicate(f)) , DbgName_(std::move(dbgName)) diff --git a/util/system/fstat.cpp b/util/system/fstat.cpp index cadd0f4540..81e98cbc6b 100644 --- a/util/system/fstat.cpp +++ b/util/system/fstat.cpp @@ -6,7 +6,7 @@ #include <util/folder/path.h> #include <cerrno> - + #if defined(_win_) #include "fs_win.h" @@ -174,11 +174,11 @@ i64 GetFileLength(FHANDLE fd) { if (::fstat(fd, &statbuf) != 0) { return -1L; } - if (!(statbuf.st_mode & (S_IFREG | S_IFBLK | S_IFCHR))) { - // st_size only makes sense for regular files or devices - errno = EINVAL; - return -1L; - } + if (!(statbuf.st_mode & (S_IFREG | S_IFBLK | S_IFCHR))) { + // st_size only makes sense for regular files or devices + errno = EINVAL; + return -1L; + } return statbuf.st_size; #else #error unsupported platform @@ -199,11 +199,11 @@ i64 GetFileLength(const char* name) { if (r == -1) { return -1; } - if (!(buf.st_mode & (S_IFREG | S_IFBLK | S_IFCHR))) { - // st_size only makes sense for regular files or devices - errno = EINVAL; - return -1; - } + if (!(buf.st_mode & (S_IFREG | S_IFBLK | S_IFCHR))) { + // st_size only makes sense for regular files or devices + errno = EINVAL; + return -1; + } return (i64)buf.st_size; #else #error unsupported platform diff --git a/util/system/tempfile.cpp b/util/system/tempfile.cpp index 74a64f854d..a2e9f49eb1 100644 --- a/util/system/tempfile.cpp +++ b/util/system/tempfile.cpp @@ -1,20 +1,20 @@ -#include "tempfile.h" - +#include "tempfile.h" + TTempFileHandle::TTempFileHandle() : TTempFile(MakeTempName()) , TFile(CreateFile()) { -} - +} + TTempFileHandle::TTempFileHandle(const TString& fname) - : TTempFile(fname) - , TFile(CreateFile()) -{ -} - + : TTempFile(fname) + , TFile(CreateFile()) +{ +} + TTempFileHandle TTempFileHandle::InCurrentDir(const TString& filePrefix, const TString& extension) { return TTempFileHandle(MakeTempName(".", filePrefix.c_str(), extension.c_str())); -} +} TTempFileHandle TTempFileHandle::InDir(const TFsPath& dirPath, const TString& filePrefix, const TString& extension) { return TTempFileHandle(MakeTempName(dirPath.c_str(), filePrefix.c_str(), extension.c_str())); diff --git a/util/system/tempfile.h b/util/system/tempfile.h index 9bde1c669f..de249c129d 100644 --- a/util/system/tempfile.h +++ b/util/system/tempfile.h @@ -27,14 +27,14 @@ private: class TTempFileHandle: public TTempFile, public TFile { public: - TTempFileHandle(); + TTempFileHandle(); TTempFileHandle(const TString& fname); - + static TTempFileHandle InCurrentDir(const TString& filePrefix = "yandex", const TString& extension = "tmp"); static TTempFileHandle InDir(const TFsPath& dirPath, const TString& filePrefix = "yandex", const TString& extension = "tmp"); -private: - TFile CreateFile() const; +private: + TFile CreateFile() const; }; /* diff --git a/util/system/tempfile_ut.cpp b/util/system/tempfile_ut.cpp index 6f749d4e0e..e4a0923d0b 100644 --- a/util/system/tempfile_ut.cpp +++ b/util/system/tempfile_ut.cpp @@ -1,25 +1,25 @@ -#include "tempfile.h" - +#include "tempfile.h" + #include <library/cpp/testing/unittest/registar.h> - -#include <util/folder/dirut.h> + +#include <util/folder/dirut.h> #include <util/generic/yexception.h> -#include <util/stream/file.h> - +#include <util/stream/file.h> + #include <algorithm> Y_UNIT_TEST_SUITE(TTempFileHandle) { Y_UNIT_TEST(Create) { TString path; - { - TTempFileHandle tmp; - path = tmp.Name(); - tmp.Write("hello world\n", 12); - tmp.FlushData(); + { + TTempFileHandle tmp; + path = tmp.Name(); + tmp.Write("hello world\n", 12); + tmp.FlushData(); UNIT_ASSERT_STRINGS_EQUAL(TUnbufferedFileInput(tmp.Name()).ReadAll(), "hello world\n"); - } + } UNIT_ASSERT(!NFs::Exists(path)); - } + } Y_UNIT_TEST(InCurrentDir) { #ifndef _win32_ @@ -115,7 +115,7 @@ Y_UNIT_TEST_SUITE(TTempFileHandle) { Y_UNIT_TEST(NonExistingDirectory) { UNIT_ASSERT_EXCEPTION(TTempFileHandle::InDir("nonexsistingdirname"), TSystemError); } -} +} Y_UNIT_TEST_SUITE(MakeTempName) { Y_UNIT_TEST(Default) { |