ssoma: lock against concurrent fetch/remote add
authorEric Wong <e@80x24.org>
Sat, 26 Apr 2014 03:16:06 +0000 (03:16 +0000)
committerEric Wong <e@80x24.org>
Sat, 26 Apr 2014 03:16:06 +0000 (03:16 +0000)
A user may manually run ssoma while cron is running,
so avoid any potential synchronization problems in this
case.

ssoma

diff --git a/ssoma b/ssoma
index ef99a008751a1cb7fbc0a1a401158a53c2471e77..9f71aa34461ba5d612a74befdfabb804ea489b56 100755 (executable)
--- a/ssoma
+++ b/ssoma
@@ -178,8 +178,10 @@ sub cmd_add {
                x(qw/git config/, "target.$target.$cfg", $path);
        }
 
-       $git->tmp_git_do(sub {
-               x(qw/git remote add --mirror=fetch origin/, $url);
+       $git->sync_do(sub {
+               $git->tmp_git_do(sub {
+                       x(qw/git remote add --mirror=fetch origin/, $url);
+               });
        });
 }
 
@@ -245,11 +247,13 @@ sub do_sync {
                @$targets = keys %t;
        }
 
-       $git->tmp_git_do(sub {
-               my @cmd = qw/git fetch/;
-               push @cmd, '-q' if $opts{quiet};
-               push @cmd, '-f' if $opts{force};
-               x(@cmd);
+       $git->sync_do(sub {
+               $git->tmp_git_do(sub {
+                       my @cmd = qw/git fetch/;
+                       push @cmd, '-q' if $opts{quiet};
+                       push @cmd, '-f' if $opts{force};
+                       x(@cmd);
+               });
        });
 
        foreach my $target (@$targets) {