@@ -15,6 +15,7 @@ import (
15
15
"code.gitea.io/gitea/modules/git"
16
16
giturl "code.gitea.io/gitea/modules/git/url"
17
17
"code.gitea.io/gitea/modules/gitrepo"
18
+ "code.gitea.io/gitea/modules/globallock"
18
19
"code.gitea.io/gitea/modules/lfs"
19
20
"code.gitea.io/gitea/modules/log"
20
21
"code.gitea.io/gitea/modules/process"
@@ -425,6 +426,10 @@ func runSync(ctx context.Context, m *repo_model.Mirror) ([]*mirrorSyncResult, bo
425
426
return parseRemoteUpdateOutput (output , m .GetRemoteName ()), true
426
427
}
427
428
429
+ func getRepoPullMirrorLockKey (repoID int64 ) string {
430
+ return fmt .Sprintf ("repo_pull_mirror_%d" , repoID )
431
+ }
432
+
428
433
// SyncPullMirror starts the sync of the pull mirror and schedules the next run.
429
434
func SyncPullMirror (ctx context.Context , repoID int64 ) bool {
430
435
log .Trace ("SyncMirrors [repo_id: %v]" , repoID )
@@ -437,6 +442,13 @@ func SyncPullMirror(ctx context.Context, repoID int64) bool {
437
442
log .Error ("PANIC whilst SyncMirrors[repo_id: %d] Panic: %v\n Stacktrace: %s" , repoID , err , log .Stack (2 ))
438
443
}()
439
444
445
+ releaser , err := globallock .Lock (ctx , getRepoPullMirrorLockKey (repoID ))
446
+ if err != nil {
447
+ log .Error ("globallock.Lock(): %v" , err )
448
+ return false
449
+ }
450
+ defer releaser ()
451
+
440
452
m , err := repo_model .GetMirrorByRepoID (ctx , repoID )
441
453
if err != nil {
442
454
log .Error ("SyncMirrors [repo_id: %v]: unable to GetMirrorByRepoID: %v" , repoID , err )
0 commit comments