* 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.
This commit is contained in:
Corinna Vinschen 2005-01-13 22:56:20 +00:00
parent 0dabe0e0c2
commit 36ca239fd4
3 changed files with 63 additions and 14 deletions

View File

@ -1,3 +1,13 @@
2005-01-13 Corinna Vinschen <corinna@vinschen.de>
* 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 <corinna@vinschen.de>
* pinfo.cc (pinfo::exit): Don't access self after releasing it.

View File

@ -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 ();

View File

@ -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)
{
@ -390,11 +402,15 @@ fhandler_disk_file::fchmod (mode_t mode)
{
enable_restore_privilege ();
if (!get_io_handle () && pc.has_acls ())
{
/* 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. */
SetFileAttributes (pc, (DWORD) pc & ~FILE_ATTRIBUTE_READONLY);
@ -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;
}
@ -438,19 +457,27 @@ fhandler_disk_file::fchown (__uid32_t uid, __gid32_t gid)
enable_restore_privilege ();
if (!get_io_handle ())
{
/* 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;
if (pc.isdir ())
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);
if (!res && !query_open ())
touch_ctime ();
}
if (oret)
close_fs ();
@ -518,10 +545,17 @@ 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);
/* 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)
{
case SETACL:
@ -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 ();