Repository: lucy-clownfish Updated Branches: refs/heads/master 19a0f7eb0 -> 61067b853
Handle read-only files when setting file time on Windows Strawberry Perl may unpack the files of a CPAN distribution as read-only. Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/61067b85 Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/61067b85 Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/61067b85 Branch: refs/heads/master Commit: 61067b8539bebef4172d16e84d06ad9a08a08632 Parents: 19a0f7e Author: Nick Wellnhofer <[email protected]> Authored: Fri Jun 12 15:05:57 2015 +0200 Committer: Nick Wellnhofer <[email protected]> Committed: Fri Jun 12 15:08:26 2015 +0200 ---------------------------------------------------------------------- compiler/perl/t/500-hierarchy.t | 5 +++++ compiler/src/CFCTest.c | 41 ++++++++++++++++++++++++------------ 2 files changed, 32 insertions(+), 14 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/61067b85/compiler/perl/t/500-hierarchy.t ---------------------------------------------------------------------- diff --git a/compiler/perl/t/500-hierarchy.t b/compiler/perl/t/500-hierarchy.t index 20ced34..62ac046 100644 --- a/compiler/perl/t/500-hierarchy.t +++ b/compiler/perl/t/500-hierarchy.t @@ -91,6 +91,11 @@ for my $file (@files) { } my $path_to_animal_cf = $animal->cfh_path( $base_dir ); +# Strawberry Perl may unpack the distribution's files as read-only. +if ( ! -w $path_to_animal_cf ) { + chmod( 0644, $path_to_animal_cf ) + or die "chmod for '$path_to_animal_cf' failed"; +} utime( undef, undef, $path_to_animal_cf ) or die "utime for '$path_to_animal_cf' failed"; # touch http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/61067b85/compiler/src/CFCTest.c ---------------------------------------------------------------------- diff --git a/compiler/src/CFCTest.c b/compiler/src/CFCTest.c index 21cff48..5ddff02 100644 --- a/compiler/src/CFCTest.c +++ b/compiler/src/CFCTest.c @@ -454,26 +454,25 @@ CFCTest_get_file_mtime(const char *path) { return buf.st_mtime; } -#if defined(CHY_HAS_UTIME_H) +#if defined(CHY_HAS_WINDOWS_H) -#include <utime.h> +#include <windows.h> void CFCTest_set_file_times(const char *path, time_t time) { - struct utimbuf buf; - buf.actime = time; - buf.modtime = time; - if (utime(path, &buf)) { - CFCUtil_die("Can't set file time of '%s': %s", path, strerror(errno)); + // Strawberry Perl may unpack the distribution's files as read-only. + DWORD attrs = GetFileAttributes(path); + if (attrs == INVALID_FILE_ATTRIBUTES) { + CFCUtil_die("Can't get file attrs of '%s': %u", path, GetLastError()); + } + if (attrs & FILE_ATTRIBUTE_READONLY) { + attrs &= ~FILE_ATTRIBUTE_READONLY; + if (!SetFileAttributes(path, attrs)) { + CFCUtil_die("Can't make '%s' writable: %u", path, + GetLastError()); + } } -} - -#elif defined(CHY_HAS_WINDOWS_H) - -#include <windows.h> -void -CFCTest_set_file_times(const char *path, time_t time) { HANDLE handle = CreateFile(path, GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); if (handle == INVALID_HANDLE_VALUE) { @@ -489,6 +488,20 @@ CFCTest_set_file_times(const char *path, time_t time) { CloseHandle(handle); } +#elif defined(CHY_HAS_UTIME_H) + +#include <utime.h> + +void +CFCTest_set_file_times(const char *path, time_t time) { + struct utimbuf buf; + buf.actime = time; + buf.modtime = time; + if (utime(path, &buf)) { + CFCUtil_die("Can't set file time of '%s': %s", path, strerror(errno)); + } +} + #else #error Need either utime.h or windows.h
