diff options
author | Corinna Vinschen <corinna@vinschen.de> | 2005-01-13 22:56:20 +0000 |
---|---|---|
committer | Corinna Vinschen <corinna@vinschen.de> | 2005-01-13 22:56:20 +0000 |
commit | 36ca239fd4a64e2a17dfe265125b21c398a6ec59 (patch) | |
tree | 099ad3703e263ce58ceea61bcec705b9c3300149 /winsup/cygwin/fhandler_disk_file.cc | |
parent | 0dabe0e0c232687d9aa67ccd0474f4df8daf4f76 (diff) | |
download | cygnal-36ca239fd4a64e2a17dfe265125b21c398a6ec59.tar.gz cygnal-36ca239fd4a64e2a17dfe265125b21c398a6ec59.tar.bz2 cygnal-36ca239fd4a64e2a17dfe265125b21c398a6ec59.zip |
* fhandler.h (fhandler_disk_file::touch_ctime): Declare.
* fhandler_disk_file.cc (fhandler_disk_file::touch_ctime): New method
to set file's ctime.
(fhandler_disk_file::fchmod): Try opening file for writing first.
Set file's ctime on success.
(fhandler_disk_file::fchown): Ditto.
(fhandler_disk_file::facl): Ditto.
Diffstat (limited to 'winsup/cygwin/fhandler_disk_file.cc')
-rw-r--r-- | winsup/cygwin/fhandler_disk_file.cc | 65 |
1 files changed, 51 insertions, 14 deletions
diff --git a/winsup/cygwin/fhandler_disk_file.cc b/winsup/cygwin/fhandler_disk_file.cc index 84cafcd61..12de09ac1 100644 --- a/winsup/cygwin/fhandler_disk_file.cc +++ b/winsup/cygwin/fhandler_disk_file.cc @@ -376,6 +376,18 @@ fhandler_disk_file::fstat (struct __stat64 *buf) return fstat_fs (buf); } +void +fhandler_disk_file::touch_ctime (void) +{ + SYSTEMTIME st; + FILETIME ft; + + GetSystemTime (&st); + SystemTimeToFileTime (&st, &ft); + if (!SetFileTime (get_io_handle (), &ft, NULL, NULL)) + debug_printf ("SetFileTime (%s) failed, %E", get_win32_name ()); +} + int __stdcall fhandler_disk_file::fchmod (mode_t mode) { @@ -391,9 +403,13 @@ fhandler_disk_file::fchmod (mode_t mode) enable_restore_privilege (); if (!get_io_handle () && pc.has_acls ()) { - query_open (query_write_control); - if (!(oret = open_fs (O_BINARY, 0))) - return -1; + /* Open for writing required to be able to set ctime. */ + if (!(oret = open_fs (O_WRONLY | O_BINARY, 0))) + { + query_open (query_write_control); + if (!(oret = open_fs (O_BINARY, 0))) + return -1; + } } if (!allow_ntsec && allow_ntea) /* Not necessary when manipulating SD. */ @@ -404,9 +420,6 @@ fhandler_disk_file::fchmod (mode_t mode) ILLEGAL_UID, ILLEGAL_GID, mode) && allow_ntsec) res = 0; - - if (oret) - close_fs (); } /* if the mode we want has any write bits set, we can't be read only. */ @@ -421,6 +434,12 @@ fhandler_disk_file::fchmod (mode_t mode) /* Correct NTFS security attributes have higher priority */ res = 0; + if (!res && !query_open ()) + touch_ctime (); + + if (oret) + close_fs (); + return res; } @@ -439,9 +458,13 @@ fhandler_disk_file::fchown (__uid32_t uid, __gid32_t gid) enable_restore_privilege (); if (!get_io_handle ()) { - query_open (query_write_control); - if (!(oret = open_fs (O_BINARY, 0))) - return -1; + /* Open for writing required to be able to set ctime. */ + if (!(oret = open_fs (O_WRONLY | O_BINARY, 0))) + { + query_open (query_write_control); + if (!(oret = open_fs (O_BINARY, 0))) + return -1; + } } mode_t attrib = 0; @@ -449,8 +472,12 @@ fhandler_disk_file::fchown (__uid32_t uid, __gid32_t gid) attrib |= S_IFDIR; int res = get_file_attribute (pc.has_acls (), get_io_handle (), pc, &attrib); if (!res) - res = set_file_attribute (pc.has_acls (), get_io_handle (), pc, - uid, gid, attrib); + { + res = set_file_attribute (pc.has_acls (), get_io_handle (), pc, + uid, gid, attrib); + if (!res && !query_open ()) + touch_ctime (); + } if (oret) close_fs (); @@ -518,9 +545,16 @@ fhandler_disk_file::facl (int cmd, int nentries, __aclent32_t *aclbufp) enable_restore_privilege (); if (!get_io_handle ()) { - query_open (cmd == SETACL ? query_write_control : query_read_control); - if (!(oret = open_fs (O_BINARY, 0))) - return -1; + /* Open for writing required to be able to set ctime. */ + if (cmd == SETACL) + oret = open_fs (O_WRONLY | O_BINARY, 0); + if (!oret) + { + query_open (cmd == SETACL ? query_write_control + : query_read_control); + if (!(oret = open_fs (O_BINARY, 0))) + return -1; + } } switch (cmd) { @@ -542,6 +576,9 @@ fhandler_disk_file::facl (int cmd, int nentries, __aclent32_t *aclbufp) } } + if (!res && cmd == SETACL && !query_open ()) + touch_ctime (); + if (oret) close_fs (); |