From ad159fc53696b2e0ea7f32f287631c4d111ddca8 Mon Sep 17 00:00:00 2001 From: Marcel Klehr Date: Sun, 9 Feb 2025 11:56:15 +0100 Subject: [PATCH] fix(Git): Make sure foreign locks are freed when forceLock is set Signed-off-by: Marcel Klehr --- src/lib/adapters/Git.ts | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/lib/adapters/Git.ts b/src/lib/adapters/Git.ts index e3dae1a446..6a0957d166 100644 --- a/src/lib/adapters/Git.ts +++ b/src/lib/adapters/Git.ts @@ -155,6 +155,7 @@ export default class GitAdapter extends CachingAdapter { clearInterval(this.lockingInterval) } if (forceLock) { + await this.clearAllLocks() await this.setLock() } else if (needLock) { await this.obtainLock() @@ -212,7 +213,7 @@ export default class GitAdapter extends CachingAdapter { }) } catch (e) { if (e.code && e.code === git.Errors.PushRejectedError.code) { - this.freeLock() + await this.freeLock() // Only clears the locks set in the current adapter instance throw new ResourceLockedError } } @@ -275,6 +276,14 @@ export default class GitAdapter extends CachingAdapter { } } + async clearAllLocks(): Promise { + const tags = await git.listTags({ fs: this.fs, dir: this.dir }) + const lockTags = tags.filter(tag => tag.startsWith('floccus-lock-')) + for (const tag of lockTags) { + await git.push({ fs: this.fs, http, dir: this.dir, ref: tag, delete: true, onAuth: () => this.onAuth() }) + } + } + async pullFromServer() { let fileContents try { @@ -369,11 +378,7 @@ export default class GitAdapter extends CachingAdapter { depth: 10, onAuth: () => this.onAuth() }) - const tags = await git.listTags({ fs, dir: this.dir }) - const lockTags = tags.filter(tag => tag.startsWith('floccus-lock-')) - for (const tag of lockTags) { - await git.push({ fs, http, dir: this.dir, ref: tag, delete: true, onAuth: () => this.onAuth() }) - } + await this.clearAllLocks() } }