diff options
| author | Igor Pavlov <87184205+ip7z@users.noreply.github.com> | 2022-06-20 00:00:00 +0000 |
|---|---|---|
| committer | Igor Pavlov <87184205+ip7z@users.noreply.github.com> | 2023-12-17 13:35:20 +0500 |
| commit | a3e1d227377188734b82f023f96f8e25dc40f3e6 (patch) | |
| tree | 23cad8d47eb23d26ea727b4f7f4a65124f724065 /CPP/Windows/FileDir.cpp | |
| parent | f19f813537c7aea1c20749c914e756b54a9c3cf5 (diff) | |
| download | 7zip-a3e1d227377188734b82f023f96f8e25dc40f3e6.tar.gz 7zip-a3e1d227377188734b82f023f96f8e25dc40f3e6.tar.bz2 7zip-a3e1d227377188734b82f023f96f8e25dc40f3e6.zip | |
22.0022.00
Diffstat (limited to 'CPP/Windows/FileDir.cpp')
| -rw-r--r-- | CPP/Windows/FileDir.cpp | 73 |
1 files changed, 39 insertions, 34 deletions
diff --git a/CPP/Windows/FileDir.cpp b/CPP/Windows/FileDir.cpp index 8a33fc8..cce2638 100644 --- a/CPP/Windows/FileDir.cpp +++ b/CPP/Windows/FileDir.cpp | |||
| @@ -17,7 +17,6 @@ | |||
| 17 | 17 | ||
| 18 | #include "../Common/StringConvert.h" | 18 | #include "../Common/StringConvert.h" |
| 19 | #include "../Common/C_FileIO.h" | 19 | #include "../Common/C_FileIO.h" |
| 20 | #include "TimeUtils.h" | ||
| 21 | #endif | 20 | #endif |
| 22 | 21 | ||
| 23 | #include "FileDir.h" | 22 | #include "FileDir.h" |
| @@ -32,6 +31,30 @@ using namespace NWindows; | |||
| 32 | using namespace NFile; | 31 | using namespace NFile; |
| 33 | using namespace NName; | 32 | using namespace NName; |
| 34 | 33 | ||
| 34 | #ifndef _WIN32 | ||
| 35 | |||
| 36 | static bool FiTime_To_timespec(const CFiTime *ft, timespec &ts) | ||
| 37 | { | ||
| 38 | if (ft) | ||
| 39 | { | ||
| 40 | ts = *ft; | ||
| 41 | return true; | ||
| 42 | } | ||
| 43 | // else | ||
| 44 | { | ||
| 45 | ts.tv_sec = 0; | ||
| 46 | ts.tv_nsec = | ||
| 47 | #ifdef UTIME_OMIT | ||
| 48 | UTIME_OMIT; // -2 keep old timesptamp | ||
| 49 | #else | ||
| 50 | // UTIME_NOW; -1 // set to the current time | ||
| 51 | 0; | ||
| 52 | #endif | ||
| 53 | return false; | ||
| 54 | } | ||
| 55 | } | ||
| 56 | #endif | ||
| 57 | |||
| 35 | namespace NWindows { | 58 | namespace NWindows { |
| 36 | namespace NFile { | 59 | namespace NFile { |
| 37 | namespace NDir { | 60 | namespace NDir { |
| @@ -86,7 +109,7 @@ bool GetSystemDir(FString &path) | |||
| 86 | #endif // UNDER_CE | 109 | #endif // UNDER_CE |
| 87 | 110 | ||
| 88 | 111 | ||
| 89 | bool SetDirTime(CFSTR path, const FILETIME *cTime, const FILETIME *aTime, const FILETIME *mTime) | 112 | bool SetDirTime(CFSTR path, const CFiTime *cTime, const CFiTime *aTime, const CFiTime *mTime) |
| 90 | { | 113 | { |
| 91 | #ifndef _UNICODE | 114 | #ifndef _UNICODE |
| 92 | if (!g_IsNT) | 115 | if (!g_IsNT) |
| @@ -920,39 +943,11 @@ bool GetCurrentDir(FString &path) | |||
| 920 | // #define UTIME_OMIT -2 | 943 | // #define UTIME_OMIT -2 |
| 921 | #endif | 944 | #endif |
| 922 | 945 | ||
| 923 | static bool FILETME_To_timespec(const FILETIME *ft, timespec &ts) | ||
| 924 | { | ||
| 925 | if (ft) | ||
| 926 | { | ||
| 927 | const Int64 sec = NTime::FileTimeToUnixTime64(*ft); | ||
| 928 | // time_t is long | ||
| 929 | const time_t sec2 = (time_t)sec; | ||
| 930 | if (sec2 == sec) | ||
| 931 | { | ||
| 932 | ts.tv_sec = sec2; | ||
| 933 | const UInt64 winTime = (((UInt64)ft->dwHighDateTime) << 32) + ft->dwLowDateTime; | ||
| 934 | ts.tv_nsec = (long)((winTime % 10000000) * 100); | ||
| 935 | return true; | ||
| 936 | } | ||
| 937 | } | ||
| 938 | // else | ||
| 939 | { | ||
| 940 | ts.tv_sec = 0; | ||
| 941 | ts.tv_nsec = | ||
| 942 | #ifdef UTIME_OMIT | ||
| 943 | UTIME_OMIT; // keep old timesptamp | ||
| 944 | #else | ||
| 945 | // UTIME_NOW; // set to the current time | ||
| 946 | 0; | ||
| 947 | #endif | ||
| 948 | return false; | ||
| 949 | } | ||
| 950 | } | ||
| 951 | 946 | ||
| 952 | 947 | ||
| 953 | 948 | ||
| 954 | 949 | ||
| 955 | bool SetDirTime(CFSTR path, const FILETIME *cTime, const FILETIME *aTime, const FILETIME *mTime) | 950 | bool SetDirTime(CFSTR path, const CFiTime *cTime, const CFiTime *aTime, const CFiTime *mTime) |
| 956 | { | 951 | { |
| 957 | // need testing | 952 | // need testing |
| 958 | /* | 953 | /* |
| @@ -998,12 +993,18 @@ bool SetDirTime(CFSTR path, const FILETIME *cTime, const FILETIME *aTime, const | |||
| 998 | UNUSED_VAR(cTime) | 993 | UNUSED_VAR(cTime) |
| 999 | 994 | ||
| 1000 | bool needChange; | 995 | bool needChange; |
| 1001 | needChange = FILETME_To_timespec(aTime, times[0]); | 996 | needChange = FiTime_To_timespec(aTime, times[0]); |
| 1002 | needChange |= FILETME_To_timespec(mTime, times[1]); | 997 | needChange |= FiTime_To_timespec(mTime, times[1]); |
| 998 | |||
| 999 | /* | ||
| 1000 | if (mTime) | ||
| 1001 | { | ||
| 1002 | printf("\n time = %ld.%9ld\n", mTime->tv_sec, mTime->tv_nsec); | ||
| 1003 | } | ||
| 1004 | */ | ||
| 1003 | 1005 | ||
| 1004 | if (!needChange) | 1006 | if (!needChange) |
| 1005 | return true; | 1007 | return true; |
| 1006 | |||
| 1007 | const int flags = 0; // follow link | 1008 | const int flags = 0; // follow link |
| 1008 | // = AT_SYMLINK_NOFOLLOW; // don't follow link | 1009 | // = AT_SYMLINK_NOFOLLOW; // don't follow link |
| 1009 | return utimensat(AT_FDCWD, path, times, flags) == 0; | 1010 | return utimensat(AT_FDCWD, path, times, flags) == 0; |
| @@ -1039,6 +1040,10 @@ static C_umask g_umask; | |||
| 1039 | #define TRACE_chmod(s, mode) \ | 1040 | #define TRACE_chmod(s, mode) \ |
| 1040 | PRF(printf("\n chmod(%s, %o)\n", (const char *)path, (unsigned)(mode))); | 1041 | PRF(printf("\n chmod(%s, %o)\n", (const char *)path, (unsigned)(mode))); |
| 1041 | 1042 | ||
| 1043 | int my_chown(CFSTR path, uid_t owner, gid_t group) | ||
| 1044 | { | ||
| 1045 | return chown(path, owner, group); | ||
| 1046 | } | ||
| 1042 | 1047 | ||
| 1043 | bool SetFileAttrib_PosixHighDetect(CFSTR path, DWORD attrib) | 1048 | bool SetFileAttrib_PosixHighDetect(CFSTR path, DWORD attrib) |
| 1044 | { | 1049 | { |
