* times.cc (utimes): Open files with FILE_WRITE_ATTRIBUTES first,

if that fails, try opeing with GENERIC_WRITE.  Fix comments.
This commit is contained in:
Corinna Vinschen 2005-02-17 12:08:16 +00:00
parent f1d439fc64
commit b066a19513
2 changed files with 18 additions and 14 deletions

View File

@ -1,3 +1,8 @@
2005-02-17 Corinna Vinschen <corinna@vinschen.de>
* times.cc (utimes): Open files with FILE_WRITE_ATTRIBUTES first,
if that fails, try opeing with GENERIC_WRITE. Fix comments.
2005-02-15 Christopher Faylor <cgf@timesys.com> 2005-02-15 Christopher Faylor <cgf@timesys.com>
* path.h (path_conv::issocket): Return true if device == FH_UNIX rather * path.h (path_conv::issocket): Return true if device == FH_UNIX rather

View File

@ -461,20 +461,22 @@ utimes (const char *path, const struct timeval *tvp)
/* MSDN suggests using FILE_FLAG_BACKUP_SEMANTICS for accessing /* MSDN suggests using FILE_FLAG_BACKUP_SEMANTICS for accessing
the times of directories. */ the times of directories. */
/* Note: It's not documented in MSDN that FILE_WRITE_ATTRIBUTES is /* Note: It's documented in MSDN that FILE_WRITE_ATTRIBUTES is
sufficient to change the timestamps, but it is for NTFS and FAT, sufficient to change the timestamps. Unfortunately it's not
local or remote, NT and 9x. Unfortunately it's not sufficient sufficient for a remote HPFS which requires GENERIC_WRITE.
for a remote HPFS. Looking for a way to decide whether we Since we don't trust the weird FS name "??SS", we just try to
should use FILE_WRITE_ATTRIBUTES or GENERIC_WRITE, we're now open with GENERIC_WRITE if opening with FILE_WRITE_ATTRIBUTES
using the has_acls () attribute. The assumption is, that file failed. That should do it, though this fails for R/O files
systems not supporting ACLs don't have a way to distinguish of course. */
between GENERIC_WRITE and FILE_WRITE_ATTRIBUTES anyway. */ HANDLE h = CreateFile (win32, FILE_WRITE_ATTRIBUTES,
HANDLE h = CreateFile (win32, win32.has_acls () ? FILE_WRITE_ATTRIBUTES
: GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,
&sec_none_nih, OPEN_EXISTING, &sec_none_nih, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_BACKUP_SEMANTICS, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_BACKUP_SEMANTICS,
0); 0);
if (h == INVALID_HANDLE_VALUE)
h = CreateFile (win32, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,
&sec_none_nih, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_BACKUP_SEMANTICS, 0);
if (h == INVALID_HANDLE_VALUE) if (h == INVALID_HANDLE_VALUE)
{ {
@ -504,16 +506,13 @@ utimes (const char *path, const struct timeval *tvp)
timeval_to_filetime (tvp + 0, &lastaccess); timeval_to_filetime (tvp + 0, &lastaccess);
timeval_to_filetime (tvp + 1, &lastwrite); timeval_to_filetime (tvp + 1, &lastwrite);
/* Mark st_ctime for update */ /* Update st_ctime */
timeval_to_filetime (tmp + 0, &lastchange); timeval_to_filetime (tmp + 0, &lastchange);
debug_printf ("incoming lastaccess %08x %08x", debug_printf ("incoming lastaccess %08x %08x",
tvp->tv_sec, tvp->tv_sec,
tvp->tv_usec); tvp->tv_usec);
// dump_filetime (lastaccess);
// dump_filetime (lastwrite);
/* FIXME: SetFileTime needs a handle with a write lock /* FIXME: SetFileTime needs a handle with a write lock
on the file whose time is being modified. So calls to utime() on the file whose time is being modified. So calls to utime()
fail for read only files. */ fail for read only files. */