diff options
author | Russ Allbery <rra@cpan.org> | 2022-01-17 11:58:26 -0800 |
---|---|---|
committer | Russ Allbery <rra@cpan.org> | 2022-01-17 11:58:26 -0800 |
commit | d09ba9dda5ecbd064997977ffcc3d344fb021e5f (patch) | |
tree | 3df48f03e5ba8c32ddf1d2ebed68eec1a042f809 | |
parent | e6296f537b3dc6527735d1067ff8e19cdc7b9130 (diff) |
Also copy modification timestamps of files
When copying distribution files with docknot release, also copy the
modification timestamps of those files.
Remove an unnecessary stat from latest_tarball, now that it's used
for more things, and move that stat to App::DocKnot::Release, which
has to do this to copy timestamps anyway.
-rw-r--r-- | Changes | 3 | ||||
-rw-r--r-- | lib/App/DocKnot/Release.pm | 12 | ||||
-rw-r--r-- | lib/App/DocKnot/Util.pm | 9 | ||||
-rwxr-xr-x | t/release/basic.t | 15 |
4 files changed, 25 insertions, 14 deletions
@@ -30,6 +30,9 @@ - Always recreate GnuPG signatures when generating distribution tarballs in docknot dist. + - When copying distribution files with docknot release, also copy the + modification timestamps of those files. + 6.01 - 2022-01-15 - Add new docknot release command and corresponding App::DocKnot::Release diff --git a/lib/App/DocKnot/Release.pm b/lib/App/DocKnot/Release.pm index b5d8d83..993c706 100644 --- a/lib/App/DocKnot/Release.pm +++ b/lib/App/DocKnot/Release.pm @@ -20,6 +20,7 @@ use App::DocKnot::Config; use App::DocKnot::Spin::Versions; use App::DocKnot::Util qw(latest_tarball); use Carp qw(croak); +use List::Util qw(min); use Path::Tiny qw(path); ############################################################################## @@ -122,9 +123,16 @@ sub release { } # Copy the new version into place and update the symlinks. + my @times; $current_path->mkpath(); for my $file ($tarball_ref->{files}->@*) { - $self->{distdir}->child($file)->copy($current_path->child($file)); + my $source = $self->{distdir}->child($file); + my $dest = $current_path->child($file); + $source->copy($dest); + my ($atime, $mtime) = $source->stat()->@[8, 9]; + push(@times, $mtime); + utime($atime, $mtime, $dest) + or die "cannot reset timestamps of $dest: $!\n"; my $generic_name = $file; $generic_name =~ s{ \A (\Q$self->{tarname}\E) - [\d.]+ [.] }{$1.}xms; my $generic_path = $current_path->child($generic_name); @@ -136,7 +144,7 @@ sub release { if ($self->{versions}) { my $name = $self->{version_name}; my $version = $tarball_ref->{version}; - my $date = $tarball_ref->{date}; + my $date = min(@times); $self->{versions}->update_version($name, $version, $date); } return; diff --git a/lib/App/DocKnot/Util.pm b/lib/App/DocKnot/Util.pm index ef0ef05..c5593df 100644 --- a/lib/App/DocKnot/Util.pm +++ b/lib/App/DocKnot/Util.pm @@ -49,7 +49,6 @@ sub is_newer { # # Returns: Anonymous hash with the following keys: # version - Latest version found -# date - Date (in seconds since epoch) of oldest file # files - Array of files for that version # or undef if no matching files were found # Throws: Text exception on any error @@ -69,14 +68,10 @@ sub latest_tarball { my $latest = $versions[0][0]; @files = map { $_->[1] } grep { $_->[0] eq $latest } @versions; - # Find the timestamps of those files. - my @times = sort(map { $path->child($_)->stat()->[9] } @files); - # Return the results. #<<< return { version => $latest, - date => $times[0], files => \@files, }; #<<< @@ -174,10 +169,6 @@ valid is a hash with the following keys: =over 4 -=item date - -The timestamp of the oldest file for that version, in seconds since epoch. - =item files The list of files found for that version. diff --git a/t/release/basic.t b/t/release/basic.t index 597cb95..ee67ccd 100755 --- a/t/release/basic.t +++ b/t/release/basic.t @@ -15,7 +15,7 @@ use lib 't/lib'; use Git::Repository (); use Path::Tiny qw(path); -use Test::More tests => 30; +use Test::More tests => 34; # Isolate from the environment. local $ENV{XDG_CONFIG_HOME} = '/nonexistent'; @@ -35,7 +35,10 @@ $dist_path->mkpath(); # Make a release when there are no existing files. my @extensions = qw(tar.gz tar.gz.asc tar.xz tar.xz.asc); for my $ext (@extensions) { - $dist_path->child('Empty-1.9.' . $ext)->touch(); + my $path = $dist_path->child('Empty-1.9.' . $ext); + $path->touch(); + utime(time() - 5, time() - 5, $path) + or die "Cannot reset timestamps for $path: $!\n"; } my $metadata = path('t', 'data', 'dist', 'package', 'docs', 'docknot.yaml'); my %options = ( @@ -49,7 +52,13 @@ $release->release(); # Check that the files were copied correctly and the symlinks were created. for my $ext (@extensions) { my $file = 'Empty-1.9.' . $ext; - ok($archive_path->child('devel', $file)->is_file(), "Copied $file"); + my $file_path = $archive_path->child('devel', $file); + ok($file_path->is_file(), "Copied $file"); + is( + $dist_path->child($file)->stat()->[9], + $file_path->stat()->[9], + "Timestamp set on $file", + ); my $link = 'Empty.' . $ext; is(readlink($archive_path->child('devel', $link)), $file, "Linked $link"); } |