Skip to content

Commit 9b94e51

Browse files
authored
fix: dynamically update spec paths when home directory changes (#40)
In cases where you install the app over itself, the home directory can change. This updates specs to always refer to valid home directories; otherwise, you can get into a download error loop.
1 parent 7cc539b commit 9b94e51

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/index.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,19 @@ export default class DownloadQueue {
639639
}
640640

641641
private start(spec: Spec) {
642+
const path = this.pathFromId(spec.id, this.extensionFromUri(spec.url));
643+
644+
// This can happen in cases where you install a new build over an old one.
645+
// The old home directory is gone, and yet you have a bunch of specs that
646+
// refer to the old directory. So we update those dynamically here.
647+
if (spec.path !== path) {
648+
spec.path = path;
649+
// We're playing a little fast and loose here, not awaiting the write, to
650+
// simplify expectations of callers who classically expected a synchronous
651+
// function. In theory, failing this silently async is harmless.
652+
void this.kvfs.write(this.keyFromId(spec.id), spec);
653+
}
654+
642655
const task = download({
643656
id: spec.id,
644657
url: spec.url,

0 commit comments

Comments
 (0)