Skip to content

fix: terminal backup#1985

Open
RohitKushvaha01 wants to merge 7 commits intoAcode-Foundation:mainfrom
RohitKushvaha01:main
Open

fix: terminal backup#1985
RohitKushvaha01 wants to merge 7 commits intoAcode-Foundation:mainfrom
RohitKushvaha01:main

Conversation

@RohitKushvaha01
Copy link
Copy Markdown
Member

@RohitKushvaha01 RohitKushvaha01 commented Mar 27, 2026

Closes #1965

@RohitKushvaha01 RohitKushvaha01 marked this pull request as draft March 27, 2026 08:47
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Mar 27, 2026

Greptile Summary

This PR fixes terminal backup/restore reliability by expanding the tar exclusion list to cover additional Android bind-mounts (apex, odm, proc, sys, dev, run, tmp, etc.), adding the .configured marker file to both backup and restore file lists, replacing the arbitrary sleep 2 in restore with set -e for proper error propagation, renaming the backup artifact from .bin to .tar, and simplifying cleanup to a shell glob (rm -rf $PREFIX/aterm_backup.*).

Key changes:

  • backup(): seven new --exclude entries prevent Android system directories from bloating or breaking the archive
  • restore(): set -e replaces sleep 2; glob aterm_backup.* handles both .tar and potential .tar.tar copy artefacts
  • terminalSettings.js: pre-cleans leftover temp files before opening the picker; post-cleanup uses the same shell glob, dropping the old fsOperation-based delete
  • Minor: a comment about the copied filename contains a typo (atem_backup) and is potentially misleading about the double extension; the restore() JSDoc @throws description is now stale because the explicit "Backup File does not exist" shell check was not carried forward alongside set -e

Confidence Score: 5/5

Safe to merge — all remaining findings are minor style/documentation issues that do not affect runtime correctness under normal usage.

The functional changes (extra excludes, .configured inclusion, set -e, glob-based cleanup) are clear improvements. The only issues found are: an unquoted glob whose edge cases are guarded by the pre-cleanup step, a stale JSDoc @throws description, and a misleading comment — all P2 with no runtime impact in the expected flow.

src/plugins/terminal/www/Terminal.js — the unquoted glob on line 385 and the stale JSDoc on the restore() function.

Important Files Changed

Filename Overview
src/plugins/terminal/www/Terminal.js backup() now excludes more Android bind-mounts (apex, odm, proc, sys, etc.) and includes .configured; restore() drops sleep 2 in favour of set -e, adds .configured, and switches from a hard-coded .bin path to an unquoted glob (aterm_backup.*) — works in practice but has edge-case risks when no file or multiple files match.
src/settings/terminalSettings.js terminalRestore() now pre-cleans leftover temp files before opening the file picker, renames the copied archive to aterm_backup.tar, and cleans up via shell glob; simpler and more robust than the old fsOperation-based deletion, though the inline comment about the resulting filename is misleading.

Sequence Diagram

sequenceDiagram
    participant U as User
    participant TS as terminalSettings.js
    participant EX as Executor
    participant SD as sdcard API
    participant SYS as system.copyToUri
    participant T as Terminal.js

    Note over U,T: Backup Flow
    U->>TS: terminalBackup()
    TS->>SD: FileBrowser folder picker
    SD-->>TS: folder URL
    TS->>T: Terminal.backup()
    T->>EX: tar -cf aterm_backup.tar with excludes
    EX-->>T: ok
    T-->>TS: dataDirectory/aterm_backup.tar
    TS->>SYS: copyToUri to selected folder
    SYS-->>TS: done
    TS->>U: alert success

    Note over U,T: Restore Flow
    U->>TS: terminalRestore()
    TS->>EX: rm old aterm_backup files
    EX-->>TS: done
    TS->>SD: openDocumentFile application/x-tar
    SD-->>TS: data.uri from user
    TS->>SYS: copyToUri to aterm_backup.tar
    SYS-->>TS: done
    TS->>T: Terminal.restore()
    T->>EX: set -e, rm existing, tar -xf aterm_backup glob
    EX-->>T: ok
    T-->>TS: ok
    TS->>EX: rm aterm_backup temp files
    EX-->>TS: done
    TS->>U: alert success
Loading

Reviews (2): Last reviewed commit: "removed logging" | Re-trigger Greptile

},
toast,
"application/x-tar",
"application/octet-stream",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 MIME type change widens file picker filter

Changing from "application/x-tar" to "application/octet-stream" makes the file picker show all files instead of only .tar archives. While this is a pragmatic choice given Android's inconsistent MIME type associations for .tar files, it means a user can accidentally select any binary file and attempt a restore with it. Terminal.restore() will only fail after copying the wrong file to $PREFIX and running tar -xf on it.

If application/x-tar did not work reliably on device (which is a valid reason), consider also trying "application/x-tar,application/octet-stream" as a comma-separated fallback list (if the sdcard.openDocumentFile API supports it), or at least add a filename validation step before the restore to check that the selected file ends with .tar.

@RohitKushvaha01 RohitKushvaha01 marked this pull request as ready for review March 29, 2026 10:44
@RohitKushvaha01 RohitKushvaha01 self-assigned this Mar 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Can't backup Terminal.

2 participants