Skip to content

Commit

Permalink
Fixes #220
Browse files Browse the repository at this point in the history
  • Loading branch information
drn05r committed Apr 28, 2022
1 parent c67d9e7 commit d940ee2
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/cfg.d/template_core.pl
Expand Up @@ -39,11 +39,11 @@
$head->appendChild( $repo->xml->create_element( "link",
rel => "stylesheet",
type => "text/css",
href => $repo->current_url( path => "static", "style/auto-".EPrints->human_version.".css" ),
href => $repo->current_url( path => "static", "style/auto-".EPrints->human_version.".css" ) . "?".$repo->auto_last_modified( 'style' ),
) );
$head->appendChild( $repo->xml->create_text_node( "\n " ) );
$head->appendChild( $repo->make_javascript( undef,
src => $repo->current_url( path => "static", "javascript/auto-".EPrints->human_version.".js" ),
src => $repo->current_url( path => "static", "javascript/auto-".EPrints->human_version.".js" ) . "?".$repo->auto_last_modified( 'javascript' ),
) );
$head->appendChild( $repo->xml->create_text_node( "\n " ) );

Expand Down
44 changes: 43 additions & 1 deletion perl_lib/EPrints/Repository.pm
Expand Up @@ -6002,9 +6002,51 @@ sub in_export_fieldlist
}


1;
######################################################################
=pod
=begin InternalDoc
=item $Boolean = $repository->aut_last_modified( $type )
Return an integer (seconds since start of last epoch) for the last
modified file that contributes to one of EPrints auto files for either
style or javascript.
=end InternalDoc
=cut
######################################################################

sub auto_last_modified
{

my ( $self, $type ) = @_;

my $style_path = "/static/$type/auto/";

my $last_modified_time = EPrints::Utils::last_modified_time_in_dir( $self->config( "lib_path" ).$style_path );

my $flavour = $self->config( "flavour" );
my $lib_order = $self->config('flavours')->{$flavour};
foreach ( @$lib_order )
{
my $dir = $self->config( "base_path" )."/$_".$style_path;
if( ! -e $dir )
{
next;
}
my $new_last_modified_time = EPrints::Utils::last_modified_time_in_dir( $dir );
$last_modified_time = ( $new_last_modified_time > $last_modified_time ) ? $new_last_modified_time : $last_modified_time;
}

my $new_last_modified_time = EPrints::Utils::last_modified_time_in_dir( $self->config( "config_path" ).$style_path );
$last_modified_time = ( $new_last_modified_time > $last_modified_time ) ? $new_last_modified_time : $last_modified_time;

return $last_modified_time;
}

1;

=head1 COPYRIGHT
Expand Down
20 changes: 20 additions & 0 deletions perl_lib/EPrints/Utils.pm
Expand Up @@ -1540,6 +1540,26 @@ sub validate_email
return defined $email && $email =~ m/^[a-zA-Z0-9.!#$%&’*+i\/=\?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/;
}

# EPrints::Utils::last_modified_time_in_dir ( $dir );
# Get seconds since start of last epoch for last modified file in a particular directory (non-recursive).
sub last_modified_time_in_dir
{
my ( $dir ) = @_;

opendir my $dh, $dir or return 0;
my $last_modified_time = 0;
while ( defined( my $file = readdir($dh) ) ) {
my $path = File::Spec->catfile( $dir, $file );
next if -d $path; # skip directories
my $modified_time = (stat($path))[9];
if ( $modified_time > $last_modified_time )
{
$last_modified_time = $modified_time;
}
}
return $last_modified_time;
}

1;

=head1 COPYRIGHT
Expand Down

0 comments on commit d940ee2

Please sign in to comment.