@@ -849,6 +849,24 @@ static int maintenance_run(struct repository *r)
{
int i;
int result = 0;
+ struct lock_file lk;
+ char *lock_path = xstrfmt("%s/maintenance", r->objects->odb->path);
+
+ if (hold_lock_file_for_update(&lk, lock_path, LOCK_NO_DEREF) < 0) {
+ /*
+ * Another maintenance command is running.
+ *
+ * If --auto was provided, then it is likely due to a
+ * recursive process stack. Do not report an error in
+ * that case.
+ */
+ if (!opts.auto_flag && !opts.quiet)
+ error(_("lock file '%s' exists, skipping maintenance"),
+ lock_path);
+ free(lock_path);
+ return 0;
+ }
+ free(lock_path);
if (opts.tasks_selected)
QSORT(tasks, num_tasks, compare_tasks_by_selection);
@@ -863,6 +881,7 @@ static int maintenance_run(struct repository *r)
result = tasks[i]->fn(r);
}
+ rollback_lock_file(&lk);
return result;
}