Skip to content

Commit 78f5d44

Browse files
fix: migration (Acode-Foundation#2741)
* fix: migration * Update src/plugins/terminal/www/Terminal.js Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> --------- Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
1 parent 50b3703 commit 78f5d44

3 files changed

Lines changed: 59 additions & 20 deletions

File tree

src/pages/fileBrowser/fileBrowser.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1332,6 +1332,13 @@ function FileBrowserInclude(mode, info, doesOpenLast = true) {
13321332
uuid: "terminal-public",
13331333
});
13341334
}
1335+
1336+
// Migrate any files left in the legacy alpine/home and
1337+
// alpine/root directories into public/MIGRATE so they are
1338+
// not hidden after the home/root/public merge.
1339+
if (typeof Terminal !== "undefined" && Terminal.migrateLegacyHome) {
1340+
Terminal.migrateLegacyHome();
1341+
}
13351342
} catch (err) {
13361343
console.error("Error while adding public directory", err);
13371344
}

src/plugins/terminal/scripts/init-sandbox.sh

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,6 @@ mkdir -p "$PREFIX/tmp"
44
mkdir -p "$PREFIX/alpine/tmp"
55
mkdir -p "$PREFIX/public"
66

7-
SRC1="$PREFIX/alpine/home"
8-
SRC2="$PREFIX/alpine/root"
9-
DEST="$PREFIX/public"
10-
11-
mkdir -p "$DEST"
12-
13-
move_all() {
14-
SRC="$1"
15-
16-
[ -d "$SRC" ] || return 0
17-
18-
# Only continue if directory is not empty
19-
[ "$(find "$SRC" -mindepth 1 -maxdepth 1 | head -n 1)" ] || return 0
20-
21-
find "$SRC" -mindepth 1 -maxdepth 1 -exec mv -f {} "$DEST"/ \;
22-
}
23-
24-
move_all "$SRC1"
25-
move_all "$SRC2"
26-
277
export PROOT_TMP_DIR=$PREFIX/tmp
288

299
if [ "$FDROID" = "true" ]; then

src/plugins/terminal/www/Terminal.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ const Terminal = {
2121
readAsset("init-sandbox.sh"),
2222
]);
2323

24+
await this.migrateLegacyHome();
25+
2426
const isFdroid = await Executor.execute("echo $FDROID");
2527

2628
if(isFdroid !== "true"){
@@ -567,6 +569,56 @@ const Terminal = {
567569
});
568570
},
569571

572+
/**
573+
* Migrates the legacy terminal home directories into public/MIGRATE.
574+
* Older builds stored user files under alpine/home and alpine/root.
575+
* After /home, /root and /public were merged into a single public
576+
* directory, any files still left in the old locations are copied
577+
* into public/MIGRATE (keeping their source structure) so nothing is
578+
* hidden or lost. This is a no-op once the migration has run.
579+
* @returns {Promise<void>}
580+
*/
581+
async migrateLegacyHome() {
582+
if (this._legacyHomeMigrated) return;
583+
try {
584+
const cmd = `
585+
MIGRATE="$PREFIX/public/MIGRATE"
586+
587+
# Already migrated
588+
[ -e "$MIGRATE/.migrated" ] && exit 0
589+
590+
COPIED=false
591+
592+
if [ -d "$PREFIX/alpine/home" ] && [ -n "$(find "$PREFIX/alpine/home" -mindepth 1 -maxdepth 1 2>/dev/null | head -n 1)" ]; then
593+
mkdir -p "$MIGRATE/home"
594+
if cp -a "$PREFIX/alpine/home/." "$MIGRATE/home/"; then
595+
COPIED=true
596+
else
597+
exit 1
598+
fi
599+
fi
600+
601+
if [ -d "$PREFIX/alpine/root" ] && [ -n "$(find "$PREFIX/alpine/root" -mindepth 1 -maxdepth 1 2>/dev/null | head -n 1)" ]; then
602+
mkdir -p "$MIGRATE/root"
603+
if cp -a "$PREFIX/alpine/root/." "$MIGRATE/root/"; then
604+
COPIED=true
605+
else
606+
exit 1
607+
fi
608+
fi
609+
610+
# Mark as migrated so this only runs once
611+
if [ "$COPIED" = "true" ]; then
612+
touch "$MIGRATE/.migrated"
613+
fi
614+
`;
615+
await Executor.BackgroundExecutor.execute(cmd);
616+
this._legacyHomeMigrated = true;
617+
} catch (error) {
618+
console.error("Failed to migrate legacy terminal home:", formatError(error));
619+
}
620+
},
621+
570622
formatError
571623
};
572624

0 commit comments

Comments
 (0)