From 0d9f584b2c2a816670a22948615d7e0a5b93fc10 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Fri, 5 Oct 2012 11:17:17 +0200 Subject: [PATCH] Support setting file times of directories on MS-Windows. src/w32.c (utime): Open the file with FILE_FLAG_BACKUP_SEMANTICS, so that time stamps of directories could also be changed. Don't request the too broad GENERIC_WRITE, only the more restrictive FILE_WRITE_ATTRIBUTES access rights. src/fileio.c (Fset_file_times): Special-case ignoring errors for directories only on MSDOS, not on MS-Windows. --- src/ChangeLog | 10 ++++++++++ src/fileio.c | 2 +- src/w32.c | 5 +++-- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 396240bb7b..b250201061 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,13 @@ +2012-10-05 Eli Zaretskii + + * w32.c (utime): Open the file with FILE_FLAG_BACKUP_SEMANTICS, so + that time stamps of directories could also be changed. Don't + request the too broad GENERIC_WRITE, only the more restrictive + FILE_WRITE_ATTRIBUTES access rights. + + * fileio.c (Fset_file_times): Special-case ignoring errors for + directories only on MSDOS, not on MS-Windows. + 2012-10-05 Ikumi Keita (tiny change) * minibuf.c (Fcompleting_read): Doc fix. (Bug#12555) diff --git a/src/fileio.c b/src/fileio.c index 9ce9e7b839..b4eda01afc 100644 --- a/src/fileio.c +++ b/src/fileio.c @@ -3034,7 +3034,7 @@ Use the current time if TIMESTAMP is nil. TIMESTAMP is in the format of { if (set_file_times (-1, SSDATA (encoded_absname), t, t)) { -#ifdef DOS_NT +#ifdef MSDOS struct stat st; /* Setting times on a directory always fails. */ diff --git a/src/w32.c b/src/w32.c index 6b52fb8398..5809e3ff91 100644 --- a/src/w32.c +++ b/src/w32.c @@ -3952,8 +3952,9 @@ utime (const char *name, struct utimbuf *times) } /* Need write access to set times. */ - fh = CreateFile (name, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, - 0, OPEN_EXISTING, 0, NULL); + fh = CreateFile (name, FILE_WRITE_ATTRIBUTES, + FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, + 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL); if (fh != INVALID_HANDLE_VALUE) { convert_from_time_t (times->actime, &atime); -- 2.20.1