diff --git a/src/pages/fileBrowser/fileBrowser.js b/src/pages/fileBrowser/fileBrowser.js index e977eb59d..dbde83462 100644 --- a/src/pages/fileBrowser/fileBrowser.js +++ b/src/pages/fileBrowser/fileBrowser.js @@ -1332,6 +1332,13 @@ function FileBrowserInclude(mode, info, doesOpenLast = true) { uuid: "terminal-public", }); } + + // Migrate any files left in the legacy alpine/home and + // alpine/root directories into public/MIGRATE so they are + // not hidden after the home/root/public merge. + if (typeof Terminal !== "undefined" && Terminal.migrateLegacyHome) { + Terminal.migrateLegacyHome(); + } } catch (err) { console.error("Error while adding public directory", err); } diff --git a/src/plugins/terminal/scripts/init-sandbox.sh b/src/plugins/terminal/scripts/init-sandbox.sh index b16096f12..5e100ef9e 100644 --- a/src/plugins/terminal/scripts/init-sandbox.sh +++ b/src/plugins/terminal/scripts/init-sandbox.sh @@ -4,26 +4,6 @@ mkdir -p "$PREFIX/tmp" mkdir -p "$PREFIX/alpine/tmp" mkdir -p "$PREFIX/public" -SRC1="$PREFIX/alpine/home" -SRC2="$PREFIX/alpine/root" -DEST="$PREFIX/public" - -mkdir -p "$DEST" - -move_all() { - SRC="$1" - - [ -d "$SRC" ] || return 0 - - # Only continue if directory is not empty - [ "$(find "$SRC" -mindepth 1 -maxdepth 1 | head -n 1)" ] || return 0 - - find "$SRC" -mindepth 1 -maxdepth 1 -exec mv -f {} "$DEST"/ \; -} - -move_all "$SRC1" -move_all "$SRC2" - export PROOT_TMP_DIR=$PREFIX/tmp if [ "$FDROID" = "true" ]; then diff --git a/src/plugins/terminal/www/Terminal.js b/src/plugins/terminal/www/Terminal.js index e6332b32f..21ffde375 100644 --- a/src/plugins/terminal/www/Terminal.js +++ b/src/plugins/terminal/www/Terminal.js @@ -21,6 +21,8 @@ const Terminal = { readAsset("init-sandbox.sh"), ]); + await this.migrateLegacyHome(); + const isFdroid = await Executor.execute("echo $FDROID"); if(isFdroid !== "true"){ @@ -567,6 +569,56 @@ const Terminal = { }); }, + /** + * Migrates the legacy terminal home directories into public/MIGRATE. + * Older builds stored user files under alpine/home and alpine/root. + * After /home, /root and /public were merged into a single public + * directory, any files still left in the old locations are copied + * into public/MIGRATE (keeping their source structure) so nothing is + * hidden or lost. This is a no-op once the migration has run. + * @returns {Promise} + */ + async migrateLegacyHome() { + if (this._legacyHomeMigrated) return; + try { + const cmd = ` + MIGRATE="$PREFIX/public/MIGRATE" + + # Already migrated + [ -e "$MIGRATE/.migrated" ] && exit 0 + + COPIED=false + + if [ -d "$PREFIX/alpine/home" ] && [ -n "$(find "$PREFIX/alpine/home" -mindepth 1 -maxdepth 1 2>/dev/null | head -n 1)" ]; then + mkdir -p "$MIGRATE/home" + if cp -a "$PREFIX/alpine/home/." "$MIGRATE/home/"; then + COPIED=true + else + exit 1 + fi + fi + + if [ -d "$PREFIX/alpine/root" ] && [ -n "$(find "$PREFIX/alpine/root" -mindepth 1 -maxdepth 1 2>/dev/null | head -n 1)" ]; then + mkdir -p "$MIGRATE/root" + if cp -a "$PREFIX/alpine/root/." "$MIGRATE/root/"; then + COPIED=true + else + exit 1 + fi + fi + + # Mark as migrated so this only runs once + if [ "$COPIED" = "true" ]; then + touch "$MIGRATE/.migrated" + fi + `; + await Executor.BackgroundExecutor.execute(cmd); + this._legacyHomeMigrated = true; + } catch (error) { + console.error("Failed to migrate legacy terminal home:", formatError(error)); + } + }, + formatError };