diff options
author | spreis <spreis@yandex-team.com> | 2023-11-15 08:17:16 +0300 |
---|---|---|
committer | spreis <spreis@yandex-team.com> | 2023-11-15 08:42:52 +0300 |
commit | 1738956637b0691f2a1a9f9c25f8ad4657e89ebb (patch) | |
tree | 64c1a24b5ddd6a4c8b2ae1814227097e9f5bfcc2 | |
parent | ffd9cf091c04dec2930091cd731d6c47b0286cd9 (diff) | |
download | ydb-1738956637b0691f2a1a9f9c25f8ad4657e89ebb.tar.gz |
Add construction of TFileStat from struct stat
-rw-r--r-- | util/system/fstat.cpp | 22 | ||||
-rw-r--r-- | util/system/fstat.h | 2 |
2 files changed, 19 insertions, 5 deletions
diff --git a/util/system/fstat.cpp b/util/system/fstat.cpp index c759f68f11..121d34f23a 100644 --- a/util/system/fstat.cpp +++ b/util/system/fstat.cpp @@ -63,24 +63,32 @@ struct TSystemFStat: public BY_HANDLE_FILE_INFORMATION { ULONG ReparseTag = 0; }; -#else - +#elif defined(_unix_) using TSystemFStat = struct stat; - +#else + #error unsupported platform #endif -static void MakeStat(TFileStat& st, const TSystemFStat& fs) { -#ifdef _unix_ +static void MakeStatFromStructStat(TFileStat& st, const struct stat& fs) { st.Mode = fs.st_mode; st.NLinks = fs.st_nlink; st.Uid = fs.st_uid; st.Gid = fs.st_gid; st.Size = fs.st_size; +#ifdef _unix_ st.AllocationSize = fs.st_blocks * 512; +#else + st.AllocationSize = st.Size; // FIXME +#endif st.ATime = fs.st_atime; st.MTime = fs.st_mtime; st.CTime = fs.st_ctime; st.INode = fs.st_ino; +} + +static void MakeStat(TFileStat& st, const TSystemFStat& fs) { +#ifdef _unix_ + MakeStatFromStructStat(st, fs); #else timeval tv; FileTimeToTimeval(&fs.ftCreationTime, &tv); @@ -142,6 +150,10 @@ TFileStat::TFileStat(FHANDLE f) { } } +TFileStat::TFileStat(const struct stat& st) { + MakeStatFromStructStat(*this, st); +} + void TFileStat::MakeFromFileName(const char* fileName, bool nofollow) { TSystemFStat st; if (GetStatByName(st, fileName, nofollow)) { diff --git a/util/system/fstat.h b/util/system/fstat.h index 64e79e1b55..b487146e36 100644 --- a/util/system/fstat.h +++ b/util/system/fstat.h @@ -5,6 +5,7 @@ class TFile; class TFsPath; +struct stat; struct TFileStat { ui32 Mode = 0; /* protection */ @@ -29,6 +30,7 @@ public: bool IsDir() const noexcept; bool IsSymlink() const noexcept; + explicit TFileStat(const struct stat& fs); explicit TFileStat(const TFile& f); explicit TFileStat(FHANDLE f); TFileStat(const TFsPath& fileName, bool nofollow = false); |