commit f0c4175f5d32c41433ae61d076b0d6a4ec61dd84
parent 0482d0499cfaa5e0f1d47cb6431a07aa3679e15b
Author: lumidify <nobody@lumidify.org>
Date:   Wed,  8 Jun 2022 00:03:35 +0200
Sort file list; add TODO
Diffstat:
3 files changed, 13 insertions(+), 7 deletions(-)
diff --git a/CHANGELOG b/CHANGELOG
@@ -1,4 +1,4 @@
 1.0 -> 1.1
-* Made it work with cksum implementation that don't have '-q'
+* Made it work with cksum implementations that don't have '-q'
 * Added Makefile
 * Improved documentation
diff --git a/TODO b/TODO
@@ -0,0 +1,3 @@
+* Add option to disable sorting?
+  -> Also maybe change sorting to be case-insensitve.
+* Progress indicator.
diff --git a/lumia b/lumia
@@ -58,7 +58,7 @@ sub make_file_iter {
 			if (-d $file) {
 				my $new_files = $dir_func->($file);
 				next if !defined $new_files;
-				push @queue, @$new_files;
+				push @queue, sort {$b cmp $a} @$new_files;
 			}
 			return $file if $file_func->($file);
 		}
@@ -222,7 +222,7 @@ sub check_cksums {
 	my $cksums = read_cksum_file("$dir/$cksum_file", {});
 	return 0 if !defined $cksums;
 	my $failed = 1;
-	foreach my $file (keys %$cksums) {
+	foreach my $file (sort keys %$cksums) {
 		my $path = "$dir/$file";
 		my $output = get_cksum $path;
 		next if !defined $output;
@@ -240,7 +240,7 @@ sub check_cksums {
 sub check_files {
 	my $args = shift;
 	my @dirs;
-	foreach my $file (@_) {
+	foreach my $file (sort @_) {
 		if (-d $file) {
 			push @dirs, $file;
 			next;
@@ -265,7 +265,7 @@ sub check_files {
 			print "FAILED $file\n";
 		}
 	}
-	my $iter = make_lumia_iter 0, @dirs;
+	my $iter = make_lumia_iter 0, reverse @dirs;
 	while (my $file = $iter->()) {
 		check_cksums $file, $DOUBLE_CKSUM_FILE, $args->{"q"};
 		check_cksums $file, $CKSUM_FILE, $args->{"q"};
@@ -282,7 +282,7 @@ sub write_special_cksums {
 		$cksums = read_cksum_file $cksum_file, {};
 	}
 	return if !defined $cksums;
-	foreach my $file (@files) {
+	foreach my $file (sort @files) {
 		my $cksum_output = get_cksum("$dir/$file");
 		next if (!defined $cksum_output);
 		$cksums->{$file} = $cksum_output;
@@ -317,9 +317,11 @@ sub check_new_files {
 		my $lumia_files = $read_file_noerror->("$dir/$CKSUM_FILE", \&read_cksum_file);
 		my @dirs;
 		my $found = 0;
-		while (my $file = readdir $dh) {
+		my @sortedfiles = sort readdir $dh;
+		foreach my $file (@sortedfiles) {
 			next if $file eq "." || $file eq "..";
 			next if exists $ignore->{$file} || exists $SPECIAL_FILES{$file};
+			# FIXME: move file from dirs to files and vice versa if necessary
 			if (!exists $lumia_dirs->{$file} && !exists $lumia_files->{$file}) {
 				if (!$found && defined $before_dir_func) {
 					last if !$before_dir_func->($dir);
@@ -334,6 +336,7 @@ sub check_new_files {
 			push @dirs, "$dir/$file" if -d "$dir/$file";
 		}
 		closedir $dh;
+		# FIXME: should this check for presence of other .lumidify* files as well?
 		# also call $before_dir_func if the directory has not been initialized yet
 		if (!$found && !-f "$dir/$DOUBLE_CKSUM_FILE" && defined $before_dir_func) {
 			$before_dir_func->($dir);