Skip to content

Commit

Permalink
fix(Git): Make sure foreign locks are freed when forceLock is set
Browse files Browse the repository at this point in the history
Signed-off-by: Marcel Klehr <[email protected]>
  • Loading branch information
marcelklehr committed Feb 9, 2025
1 parent 9261b2b commit ad159fc
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/lib/adapters/Git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
}
}
Expand Down Expand Up @@ -275,6 +276,14 @@ export default class GitAdapter extends CachingAdapter {
}
}

async clearAllLocks(): Promise<void> {
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 {
Expand Down Expand Up @@ -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()
}
}

Expand Down

0 comments on commit ad159fc

Please sign in to comment.