From 36ca239fd4a64e2a17dfe265125b21c398a6ec59 Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Thu, 13 Jan 2005 22:56:20 +0000 Subject: * 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. --- winsup/cygwin/ChangeLog | 10 ++++++ winsup/cygwin/fhandler.h | 2 ++ winsup/cygwin/fhandler_disk_file.cc | 65 +++++++++++++++++++++++++++++-------- 3 files changed, 63 insertions(+), 14 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 34e5b75..d970d6d 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,5 +1,15 @@ 2005-01-13 Corinna Vinschen + * 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. + +2005-01-13 Corinna Vinschen + * pinfo.cc (pinfo::exit): Don't access self after releasing it. * path.h (path_conv::path_conv): Fill path with native device name in case of device argument. diff --git a/winsup/cygwin/fhandler.h b/winsup/cygwin/fhandler.h index 47b216c..34b40b8 100644 --- a/winsup/cygwin/fhandler.h +++ b/winsup/cygwin/fhandler.h @@ -571,6 +571,8 @@ class fhandler_dev_tape: public fhandler_dev_raw class fhandler_disk_file: public fhandler_base { + void touch_ctime (void); + public: fhandler_disk_file (); diff --git a/winsup/cygwin/fhandler_disk_file.cc b/winsup/cygwin/fhandler_disk_file.cc index 84cafcd..12de09a 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 (); -- cgit v1.1