diff options
author | Ron Yorston <rmy@pobox.com> | 2014-03-13 16:03:13 +0000 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2014-03-13 16:03:13 +0000 |
commit | e15ec3837bfed8a05ff0e8c7edd658fbb41f5d7d (patch) | |
tree | e1b46e815470be1482ab23b20f5eb4f687450339 | |
parent | 02b877e3507f2aa063f157875d87456425642fe8 (diff) | |
download | busybox-w32-e15ec3837bfed8a05ff0e8c7edd658fbb41f5d7d.tar.gz busybox-w32-e15ec3837bfed8a05ff0e8c7edd658fbb41f5d7d.tar.bz2 busybox-w32-e15ec3837bfed8a05ff0e8c7edd658fbb41f5d7d.zip |
Allow utimes to change times on directories
-rw-r--r-- | win32/mingw.c | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/win32/mingw.c b/win32/mingw.c index 6bff1af1c..c52df4bb4 100644 --- a/win32/mingw.c +++ b/win32/mingw.c | |||
@@ -369,17 +369,30 @@ static inline void timeval_to_filetime(const struct timeval tv, FILETIME *ft) | |||
369 | int utimes(const char *file_name, const struct timeval times[2]) | 369 | int utimes(const char *file_name, const struct timeval times[2]) |
370 | { | 370 | { |
371 | FILETIME mft, aft; | 371 | FILETIME mft, aft; |
372 | int fh, rc; | 372 | HANDLE fh; |
373 | DWORD flags; | ||
374 | int rc; | ||
375 | |||
376 | flags = FILE_ATTRIBUTE_NORMAL; | ||
373 | 377 | ||
374 | /* must have write permission */ | 378 | /* must have write permission */ |
375 | DWORD attrs = GetFileAttributes(file_name); | 379 | DWORD attrs = GetFileAttributes(file_name); |
376 | if (attrs != INVALID_FILE_ATTRIBUTES && | 380 | if ( attrs != INVALID_FILE_ATTRIBUTES ) { |
377 | (attrs & FILE_ATTRIBUTE_READONLY)) { | 381 | if ( attrs & FILE_ATTRIBUTE_READONLY ) { |
378 | /* ignore errors here; open() will report them */ | 382 | /* ignore errors here; open() will report them */ |
379 | SetFileAttributes(file_name, attrs & ~FILE_ATTRIBUTE_READONLY); | 383 | SetFileAttributes(file_name, attrs & ~FILE_ATTRIBUTE_READONLY); |
384 | } | ||
385 | |||
386 | if ( attrs & FILE_ATTRIBUTE_DIRECTORY ) { | ||
387 | flags = FILE_FLAG_BACKUP_SEMANTICS; | ||
388 | } | ||
380 | } | 389 | } |
381 | 390 | ||
382 | if ((fh = open(file_name, O_RDWR | O_BINARY)) < 0) { | 391 | fh = CreateFile(file_name, GENERIC_READ|GENERIC_WRITE, |
392 | FILE_SHARE_READ|FILE_SHARE_WRITE, | ||
393 | NULL, OPEN_EXISTING, flags, NULL); | ||
394 | if ( fh == INVALID_HANDLE_VALUE ) { | ||
395 | errno = err_win_to_posix(GetLastError()); | ||
383 | rc = -1; | 396 | rc = -1; |
384 | goto revert_attrs; | 397 | goto revert_attrs; |
385 | } | 398 | } |
@@ -392,12 +405,12 @@ int utimes(const char *file_name, const struct timeval times[2]) | |||
392 | GetSystemTimeAsFileTime(&mft); | 405 | GetSystemTimeAsFileTime(&mft); |
393 | aft = mft; | 406 | aft = mft; |
394 | } | 407 | } |
395 | if (!SetFileTime((HANDLE)_get_osfhandle(fh), NULL, &aft, &mft)) { | 408 | if (!SetFileTime(fh, NULL, &aft, &mft)) { |
396 | errno = EINVAL; | 409 | errno = EINVAL; |
397 | rc = -1; | 410 | rc = -1; |
398 | } else | 411 | } else |
399 | rc = 0; | 412 | rc = 0; |
400 | close(fh); | 413 | CloseHandle(fh); |
401 | 414 | ||
402 | revert_attrs: | 415 | revert_attrs: |
403 | if (attrs != INVALID_FILE_ATTRIBUTES && | 416 | if (attrs != INVALID_FILE_ATTRIBUTES && |