mirror of
https://github.com/marcoallegretti/WEFT_OS.git
synced 2026-11-22 08:13:59 +00:00
App data lived in ~/.local/share/weft/apps/<id>/data, inside the user package store under the installed package directory. Uninstalling a package deleted its data, and launching a package installed elsewhere created that directory, after which installing the package for the user failed because its directory already existed. App data now lives in $XDG_DATA_HOME/weft/app-data/<id>, one shared rule in weft_ipc_types::package, and is made private (0700) on every launch. Data in the earlier location is moved there in one rename on the first launch with an app-data capability, and by weft-pack before it uninstalls a package or installs over a directory holding only data. If both locations hold data, nothing is moved: the launch is refused with 409 and weft-pack stops, so neither copy is lost or merged. tests/frame/check_app_data.py launches the Notes demo on the nested desktop with notes in the earlier location and checks that they arrive byte for byte (including a literal backslash sequence and non-ASCII text), that the old directory is gone, that the new one is 0700 and that a second copy makes the next launch fail with 409 without changing either. The weft-pack tests that change the environment now share a lock.
107 lines
4.7 KiB
Python
107 lines
4.7 KiB
Python
"""Check that existing Notes data survives the move to the app data store.
|
|
|
|
Earlier versions kept app data inside the user package store, at
|
|
`~/.local/share/weft/apps/<id>/data`. The harness places a notes file there
|
|
(with a backslash sequence, a newline and non-ASCII text, which must come
|
|
through byte for byte), runs weft-appd on a nested desktop and launches
|
|
`org.weft.demo.notes` with the real runtime and app shell. The session must
|
|
reach APP_READY, the file must then be at
|
|
`$XDG_DATA_HOME/weft/app-data/org.weft.demo.notes/notes.txt` with identical
|
|
bytes, the old directory must be gone and the new one private (0700).
|
|
|
|
A second launch after placing a different file at the old location must be
|
|
refused with error 409, leaving both copies untouched.
|
|
|
|
Requires Xvfb, xwd, ImageMagick's convert and xdotool.
|
|
"""
|
|
|
|
import argparse
|
|
import shutil
|
|
import sys
|
|
import tempfile
|
|
from pathlib import Path
|
|
|
|
sys.dont_write_bytecode = True
|
|
from check_counter import AppdClient, free_port, read_endpoint # noqa: E402
|
|
from session import ROOT, Desktop, SessionError, missing_tools # noqa: E402
|
|
|
|
APP_ID = "org.weft.demo.notes"
|
|
NOTES = "first line\nliteral \\n stays\ncafé ☃\n".encode()
|
|
|
|
|
|
def run(args, desktop, home):
|
|
legacy = home / ".local/share/weft/apps" / APP_ID / "data"
|
|
legacy.mkdir(parents=True)
|
|
(legacy / "notes.txt").write_bytes(NOTES)
|
|
data_home = home / "data-home"
|
|
target = data_home / "weft/app-data" / APP_ID
|
|
|
|
t = Path(args.target)
|
|
desktop.launch_client("appd", [t / "weft-appd"], {
|
|
"WEFT_RUNTIME_BIN": str(t / "weft-runtime"),
|
|
"WEFT_APP_SHELL_BIN": str(t / "weft-app-shell"),
|
|
"WEFT_APP_STORE": str(args.store),
|
|
"WEFT_DISABLE_CGROUP": "1",
|
|
"WEFT_APPD_WS_PORT": str(free_port()),
|
|
"HOME": str(home),
|
|
"XDG_DATA_HOME": str(data_home),
|
|
})
|
|
port, token = read_endpoint(desktop.runtime, 30)
|
|
appd = AppdClient(port, token)
|
|
appd.send({"type": "LAUNCH_APP", "app_id": APP_ID, "surface_id": 0})
|
|
reply = appd.wait_for(lambda m: m.get("type") in ("APP_READY", "ERROR"), 120)
|
|
if reply.get("type") != "APP_READY":
|
|
raise AssertionError(f"Notes did not start: {reply}")
|
|
if (target / "notes.txt").read_bytes() != NOTES:
|
|
raise AssertionError("notes changed while moving")
|
|
if legacy.exists():
|
|
raise AssertionError(f"{legacy} still exists")
|
|
if target.stat().st_mode & 0o777 != 0o700:
|
|
raise AssertionError(f"{target} is not private: {oct(target.stat().st_mode)}")
|
|
|
|
appd.send({"type": "TERMINATE_APP", "session_id": reply["session_id"]})
|
|
legacy.mkdir(parents=True)
|
|
(legacy / "notes.txt").write_bytes(b"other copy")
|
|
appd.send({"type": "LAUNCH_APP", "app_id": APP_ID, "surface_id": 0})
|
|
reply = appd.wait_for(lambda m: m.get("type") in ("APP_READY", "ERROR"), 60)
|
|
if reply.get("type") != "ERROR" or reply.get("code") != 409:
|
|
raise AssertionError(f"conflicting data was not refused: {reply}")
|
|
if (legacy / "notes.txt").read_bytes() != b"other copy" or \
|
|
(target / "notes.txt").read_bytes() != NOTES:
|
|
raise AssertionError("a refused launch changed app data")
|
|
|
|
|
|
def main(argv=None):
|
|
parser = argparse.ArgumentParser(description=__doc__,
|
|
formatter_class=argparse.RawDescriptionHelpFormatter)
|
|
parser.add_argument("--compositor", type=Path, default=ROOT / "target/debug/weft-compositor")
|
|
parser.add_argument("--target", type=Path, default=ROOT / "target/debug",
|
|
help="directory with weft-appd, weft-runtime and weft-app-shell")
|
|
parser.add_argument("--store", type=Path, default=ROOT / "examples",
|
|
help="app store containing org.weft.demo.notes")
|
|
parser.add_argument("--output", type=Path, default=ROOT / "target/app-data-check")
|
|
args = parser.parse_args(argv)
|
|
|
|
missing = missing_tools() + [str(p) for p in (args.compositor, args.target / "weft-appd",
|
|
args.target / "weft-runtime",
|
|
args.target / "weft-app-shell")
|
|
if not p.is_file()]
|
|
if missing:
|
|
print("missing: " + ", ".join(missing), file=sys.stderr)
|
|
return 2
|
|
home = Path(tempfile.mkdtemp(prefix="weft-home-"))
|
|
try:
|
|
with Desktop(args.compositor, args.output, outputs=["appd.log"]) as desktop:
|
|
run(args, desktop, home)
|
|
except (AssertionError, SessionError, TimeoutError) as failure:
|
|
print(f"app data check failed: {failure}", file=sys.stderr)
|
|
print(f"logs in {args.output}", file=sys.stderr)
|
|
return 1
|
|
finally:
|
|
shutil.rmtree(home, ignore_errors=True)
|
|
print("app data check passed")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|