Skip to content

Commit 14f6bc7

Browse files
committed
sort values returned by readdir to improve reproducibility
1 parent 8e48fec commit 14f6bc7

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

lib/LaTeXML/Util/Pack.pm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use warnings;
1515

1616
use LaTeXML::Util::Pathname;
1717
use File::Spec::Functions qw(catfile);
18-
use File::Path qw(rmtree);
18+
use File::Path qw(rmtree);
1919
use IO::String;
2020
use Archive::Zip qw(:CONSTANTS :ERROR_CODES);
2121

@@ -250,7 +250,7 @@ sub get_archive {
250250
# or Fatal('expected', 'directory', undef,
251251
# "Expected a directory to archive '$directory':", $@);
252252
or (print STDERR 'Fatal:expected:directory Failed to compress directory \'$directory\': $@');
253-
my @entries = grep { /^[^.]/ } readdir($dirhandle);
253+
my @entries = sort (grep { /^[^.]/ } readdir($dirhandle));
254254
closedir $dirhandle;
255255
my @files = grep { !/$archive_file_exclusion_regex/ && -f pathname_concat($directory, $_) } @entries;
256256
my @subdirs = grep { -d File::Spec->catdir($directory, $_) } @entries;

lib/LaTeXML/Util/Pathname.pm

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,7 @@ sub candidate_pathnames {
399399
opendir(DIR, $dir) or next;
400400
my @dir_files = readdir(DIR);
401401
closedir(DIR);
402+
my @dir_paths;
402403
for my $local_file (@dir_files) {
403404
for my $regex_pair (@regexes) {
404405
my ($i_regex, $regex) = @$regex_pair;
@@ -408,7 +409,8 @@ sub candidate_pathnames {
408409
if ($local_file =~ m/$regex/) {
409410
# if we are only interested in the first match, return it:
410411
return ($full_file) if $options{findfirst};
411-
push(@paths, $full_file); } } } } }
412+
push(@dir_paths, $full_file); } } } }
413+
push(@paths, sort @dir_paths); }
412414
# Fallback: if no strict matches were found, return any existing case-insensitive matches
413415
# Defer the -f check until we are sure we need it, to keep the usual cases fast.
414416
return @paths ? @paths : @nocase_paths; }

0 commit comments

Comments
 (0)