]> mj.ucw.cz Git - gallery.git/commitdiff
gal-scan preserves order of pre-existing images
authorMartin Mares <mj@ucw.cz>
Sun, 9 Jun 2013 11:06:21 +0000 (13:06 +0200)
committerMartin Mares <mj@ucw.cz>
Sun, 8 Feb 2015 20:14:17 +0000 (21:14 +0100)
gal/bin/gal-scan

index 0cdff942663b41429db9e53e970a9b64f1071823..41e2d3a607bd5183ae1f032230544a786b1c1ab5 100755 (executable)
@@ -116,23 +116,26 @@ if (!$update) {
        my $old = $gal->read_list('gallery.list');
        if ($old) {
                print "Updating gallery.list\n";
-               my %old_by_id = map { $_->{id} => $_ } @$old;
-               for my $i (@images) {
-                       my $id = $i->{id};
-                       my $o = $old_by_id{$id};
-                       if ($o) {
-                               print "\t$id: updated\n";
-                               $i->{orientation} = $o->{orientation};
-                               $i->{xfrm} = $o->{xfrm};
-                               $i->{title} = $o->{title};
-                       } else {
-                               print "\t$id: new\n";
+               my %new_by_id = map { $_->{id} => $_ } @images;
+               my @result = ();
+               for my $o (@$old) {
+                       my $id = $o->{id};
+                       my $i = $new_by_id{$id};
+                       if (!$i) {
+                               print "\t$id: removed\n";
+                               next;
                        }
-                       delete $old_by_id{$id};
+                       print "\t$id: updated\n";
+                       push @result, $o;
+                       delete $new_by_id{$id};
                }
-               for my $id (keys %old_by_id) {
-                       print "\t$id: removed\n";
+               for my $i (@images) {
+                       my $id = $i->{id};
+                       $new_by_id{$id} or next;
+                       print "\t$id: new\n";
+                       push @result, $i;
                }
+               @images = @result;
        }
 }