H6: isolated data directory for dev and live-check instances
`--data-dir DIR` / `LUTRA_DATA_DIR` move settings, the recovery journal, the rendezvous file and the WebView2 user data folder into one directory. `--control PORT` without either uses `<temp>/lutra-control/<port>/`. The SHA-256-checked Phpactor cache stays shared from the user's data dir (`Engine::share_tools_from`). An isolated instance never forwards to or registers as the user's main instance; `rendezvous::dir()` honours `LUTRA_DATA_DIR` after `LUTRA_RENDEZVOUS_DIR`, so the CLI finds it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
e5891ddeb4
commit
ba70b0f43a
10 changed files with 418 additions and 29 deletions
|
|
@ -101,6 +101,10 @@ pub struct Toolchain {
|
|||
config: Option<Config>,
|
||||
/// The project root the last job saw.
|
||||
root: Option<PathBuf>,
|
||||
/// Where the managed tools live (`tools/phpactor/<version>/`) when that
|
||||
/// is not the engine's data directory; see
|
||||
/// [`crate::Engine::share_tools_from`].
|
||||
tools_dir: Option<PathBuf>,
|
||||
}
|
||||
|
||||
impl Toolchain {
|
||||
|
|
@ -114,6 +118,12 @@ impl Toolchain {
|
|||
pub fn allow_downloads(&mut self, source: Source) {
|
||||
self.source = Some(source);
|
||||
}
|
||||
|
||||
/// Keeps the managed tools in `dir` instead of the engine's data
|
||||
/// directory.
|
||||
pub fn set_tools_dir(&mut self, dir: PathBuf) {
|
||||
self.tools_dir = Some(dir);
|
||||
}
|
||||
}
|
||||
|
||||
/// The settings and directories a job runs with.
|
||||
|
|
@ -125,7 +135,8 @@ struct Config {
|
|||
phpactor_path: String,
|
||||
/// `phpactor.autoDownload`.
|
||||
auto_download: bool,
|
||||
/// The engine's data directory.
|
||||
/// The directory holding the managed tools: the toolchain's tools
|
||||
/// directory if set, else the engine's data directory.
|
||||
data_dir: Option<PathBuf>,
|
||||
}
|
||||
|
||||
|
|
@ -236,7 +247,11 @@ fn config(state: &State) -> Config {
|
|||
.get("phpactor.autoDownload")
|
||||
.and_then(|v| v.as_bool())
|
||||
.unwrap_or(true),
|
||||
data_dir: state.config.as_ref().map(|c| c.data_dir.clone()),
|
||||
data_dir: state
|
||||
.toolchain
|
||||
.tools_dir
|
||||
.clone()
|
||||
.or_else(|| state.config.as_ref().map(|c| c.data_dir.clone())),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -883,4 +898,32 @@ mod tests {
|
|||
Mode::Auto(PathBuf::from("p"))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_shared_tools_dir_is_used_instead_of_the_data_dir() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let shared = dir.path().join("user-data");
|
||||
let body = b"shared phar".to_vec();
|
||||
let path = phpactor::managed_path(&shared, "1.0.0");
|
||||
std::fs::create_dir_all(path.parent().unwrap()).unwrap();
|
||||
std::fs::write(&path, &body).unwrap();
|
||||
let mut engine = engine(dir.path());
|
||||
engine.share_tools_from(shared.clone());
|
||||
engine.allow_downloads_from(Source {
|
||||
url: "http://127.0.0.1:9/never".into(),
|
||||
version: "1.0.0".into(),
|
||||
sha256: Hash::of_bytes(&body),
|
||||
https_only: false,
|
||||
});
|
||||
engine.execute("toolchain.status", Value::Null).unwrap();
|
||||
let events = pump_until(&mut engine, |ev| {
|
||||
last_status(ev).is_some_and(|s| s.phpactor.state == PhpactorState::Ready)
|
||||
});
|
||||
let status = last_status(&events).unwrap();
|
||||
assert_eq!(
|
||||
status.phpactor.path.as_deref(),
|
||||
Some(path.display().to_string().as_str())
|
||||
);
|
||||
assert!(!dir.path().join("data").join("tools").exists());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue