Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
cb38a07
Catalog: an upgrade keeps the files it replaces
nledford Oct 23, 2026
1ec43ee
Catalog: a later upgrade tells where it kept the files it replaced
nledford Oct 26, 2026
26cf95d
Catalog: a snapshot already in this format is the upgrade done, and t…
nledford Oct 26, 2026
d50ad6f
Catalog: a write that fails leaves no staging file, so a copy that ca…
nledford Oct 26, 2026
c8be9db
Catalog: the docs and comments say what a failed later snapshot leave…
nledford Oct 29, 2026
af6b1c5
Catalog: the damaged-log bullet and the module docs say what is left …
nledford Oct 29, 2026
f9e8358
Upgrade notice names a damaged log kept by the upgrade; the way back …
nledford Oct 29, 2026
c6f52eb
Catalog: the store can write files that a later write names, list its…
nledford Oct 23, 2026
c08a818
Catalog: a library states what its missing develop settings read as
nledford Oct 23, 2026
3cdf821
Catalog: say what the next open reads after a rewrite for other defau…
nledford Oct 25, 2026
9fc9453
Catalog: the test for the defaults reading ending with the open leave…
nledford Oct 30, 2026
4decee3
Catalog: the formats are one table, and every format from 6 on has a …
nledford Oct 25, 2026
a340c33
Catalog: develop settings can be stored as their difference from the …
nledford Oct 25, 2026
254e30e
catalog: read, append and truncate refuse a segments folder that isn'…
nledford Oct 25, 2026
2a51d02
Catalog: compact records are format 10
nledford Oct 25, 2026
b9fa882
Merge catalog-store-hooks (#2871, 254e30e4cf) into the catalog compac…
nledford Oct 30, 2026
50b6190
Catalog: the segments of a snapshot: their names, rules, writer and r…
nledford Oct 23, 2026
852b8fa
Catalog: the journal saves the snapshot in segments and opens one (fo…
nledford Oct 25, 2026
9e9e84c
Catalog: map the v10 catalog fixtures in ci_quick::EMBEDDED
nledford Oct 26, 2026
d88a313
Catalog: the put-off upgrade's tests, from #2958, run on format 11's …
nledford Oct 26, 2026
038f346
Catalog: segment files nothing lists are removed when the library is …
nledford Oct 25, 2026
870cdea
Catalog: a compaction writes only the segments whose photos changed
nledford Oct 25, 2026
f381d2e
Catalog: back up the library to a dated folder that shares unchanged …
nledford Oct 10, 2026
c2bde11
Catalog: the library's own files are one list, and backups take all o…
nledford Oct 11, 2026
fdb46e3
Catalog: a backup ignores what the OS writes into its folder, and a m…
nledford Oct 18, 2026
5e38caf
Catalog: sweep takes only a missing segments folder for quiet, and th…
nledford Oct 18, 2026
b98cb85
Catalog: the sweep test that sets folder times is for Unix
nledford Oct 18, 2026
3dd8fc4
Locales: fi, id, sv and vi for the backup labels; Parity: summary ref…
nledford Oct 22, 2026
8332b4d
Catalog: restore a library from a backup, and keep what it replaces
nledford Oct 10, 2026
1832d7a
Catalog: say what a restore does with the files an upgrade kept
nledford Oct 11, 2026
8917bee
Catalog: review fixes for restore: a backup named by its files is ref…
nledford Oct 18, 2026
04f2cd4
Catalog: the backup tests remove the folders they restore into
nledford Oct 18, 2026
e2e4159
Locales: fi, id, sv and vi for the restore labels; Parity: summary re…
nledford Oct 22, 2026
5f864f6
Catalog: restore from the File menu, with the backup copied in the ba…
nledford Oct 11, 2026
315eca7
Catalog: review fixes for the restore in the background: a given-up w…
nledford Oct 18, 2026
122fcb6
Catalog: review fixes for the restore in the background: a late worke…
nledford Oct 18, 2026
a2691bd
Catalog: a restore's status stays running while its worker still clea…
nledford Oct 18, 2026
59452ba
Locales: fi, id, sv and vi for the background restore; Parity: summar…
nledford Oct 22, 2026
9820b0f
Catalog: the menus list one Restore Library from Backup… per host, th…
nledford Oct 30, 2026
68a3c56
Catalog: the backup folder is shown and chosen in Settings
nledford Oct 11, 2026
58e80fe
Catalog: Settings reads the backup folder without running a command, …
nledford Oct 11, 2026
ca3523c
Catalog: the rule for where backups go can't be walked round
nledford Oct 11, 2026
14b324b
Catalog: What's New says Back Up Library goes to the library's backup…
nledford Oct 18, 2026
7fdc8c0
Catalog: a backup folder that could not be saved is not chosen, and W…
nledford Oct 18, 2026
3fb84f4
Catalog: the usual Backups folder is told by its real path
nledford Oct 18, 2026
656f855
Locales: fi, id, sv and vi for the backup folder; de in du; Parity: s…
nledford Oct 22, 2026
1a5f2f9
Settings: Backups ▸ Folder is one line cut from the front like the ot…
nledford Oct 30, 2026
36ac223
Catalog: a library is backed up by itself while it is open, and when …
nledford Oct 11, 2026
ba753e6
Catalog: quitting with a backup ahead can always be finished, and wai…
nledford Oct 11, 2026
e3d59c9
Catalog: only the open library's own backup is waited for at quitting…
nledford Oct 11, 2026
997c2bb
Catalog: review fixes for backup by itself: a changed folder, and a s…
nledford Oct 18, 2026
2b568f8
Catalog: review fixes for backup by itself: the tests that hold a bac…
nledford Oct 18, 2026
29b941c
Catalog: review fixes for backup by itself: a key bound to Back Up Li…
nledford Oct 18, 2026
d457390
Catalog: review fixes for backup by itself: the key test has no unuse…
nledford Oct 18, 2026
faeb847
Catalog: the schedule tests' scratch folder is removed by a guard, al…
nledford Oct 18, 2026
eabb210
Locales: fi, id, sv and vi for the backup schedule; Parity: summary r…
nledford Oct 22, 2026
85d46b3
Catalog: a library can keep its backups for a time, and old ones go a…
nledford Oct 11, 2026
a0b2ba9
Catalog: a backup that a file manager wrote into is removed like any …
nledford Oct 18, 2026
d65944a
Catalog: the backup preferences compile where they were merged (befor…
nledford Oct 18, 2026
ad04589
Catalog: a restore into another folder forgets the library id while i…
nledford Oct 18, 2026
3d6521d
Catalog: forgetting the library id rewrites prefs.json durably
nledford Oct 18, 2026
6e5f147
Locales: fi, id, sv and vi for backup pruning; Parity: summary refreshed
nledford Oct 22, 2026
9b9e3b7
Catalog: what restores replaced goes with the old backups of a librar…
nledford Oct 11, 2026
c4d02ae
Catalog: review fixes for what restores replaced: a half-removed fold…
nledford Oct 18, 2026
af2e894
Catalog: review fixes for what restores replaced: uk genitive plural,…
nledford Oct 18, 2026
f08a641
Catalog: What's New says a restore's "(not opened)" folder goes by ag…
nledford Oct 18, 2026
415eefa
Catalog: a folder of Replaced that a file manager wrote into is still…
nledford Oct 18, 2026
b08492b
Catalog: pruning takes a numbered "(not opened)" folder of Replaced b…
nledford Oct 18, 2026
1221587
Locales: fi, id, sv and vi for what restores replaced; the restore li…
nledford Oct 22, 2026
38e9bd6
Catalog: a backup restored into another folder is checked to open there
nledford Oct 11, 2026
1e54b8b
App: the folder dialog asked on the UI thread has a title that fits w…
nledford Oct 11, 2026
3785141
App: why a backup or restore is refused is said in the person's language
nledford Oct 11, 2026
c4158a1
CLI: run sees a restore or backup it started in the background throug…
nledford Oct 11, 2026
5f36b18
CLI: review fixes for run seeing a background job through: an earlier…
nledford Oct 18, 2026
5d9e893
CLI: review fixes for run seeing a background job through: the help a…
nledford Oct 18, 2026
2b4ef8f
CLI: review fixes for run seeing a background job through: an earlier…
nledford Oct 18, 2026
0444632
CLI: review fixes for run seeing a background job through: each earli…
nledford Oct 18, 2026
082031a
CLI: the help and docs of run say it waits for every earlier job, say…
nledford Oct 18, 2026
849cd58
CLI: a background backup that was over when the call returned is said…
nledford Oct 18, 2026
ed4a200
CLI: only a result that is a job is waited for (a restore with to run…
nledford Oct 18, 2026
6ad80d7
CLI: run waits for either kind of background job before starting a ba…
nledford Oct 18, 2026
337e565
CLI: run is split into small functions (clippy's complexity bound), a…
nledford Oct 18, 2026
5ea5152
Locales: fi, id, sv and vi for the small-items backup reasons; de in …
nledford Oct 22, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

213 changes: 164 additions & 49 deletions apps/lightcraft-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ USAGE:
engine.commands / ui.inspect / ui.screenshot) and print one JSON line per command:
{\"command\", \"ok\", \"result\" | \"error\", \"ms\"}. A word without `=` starts the next
command; values are JSON when they parse (1, true, [1,2], {…}), else strings. Exit status
is non-zero when a command fails. Example:
is non-zero when a command fails. Headless, a restore or backup started with
`background=true` is waited for before the call ends (also before another of its kind
starts), and how each ended is one more line (`library.restoreStatus` /
`library.backupStatus`); a failed one fails the call, even when a later one worked; not
after a command failed, unless --keep-going. Example:
lightcraft-cli run --import ~/Photos/a.jpg develop.set control=light.exposure value=0.7 \\
develop.auto app.export path=/tmp/a.jpg longEdge=1600
Options:
Expand Down Expand Up @@ -550,80 +554,191 @@ fn run(args: &[String]) -> Result<(), String> {
}
let mut steps = parse_steps(&args[i..])?;
if let Some(path) = &script {
let text = if path == "-" {
let mut s = String::new();
std::io::Read::read_to_string(&mut std::io::stdin(), &mut s).map_err(|e| e.to_string())?;
s
} else {
std::fs::read_to_string(path).map_err(|e| format!("{path}: {e}"))?
};
for (n, line) in text.lines().enumerate().filter(|(_, l)| !l.trim().is_empty() && !l.trim_start().starts_with('#')) {
let v: Value = serde_json::from_str(line).map_err(|e| format!("{path}:{}: {e}", n + 1))?;
// `{"command": id, "params": …}` or a control request `{"method": m, "params": …}`
let id = v
.get("command")
.or(v.get("method"))
.and_then(Value::as_str)
.ok_or_else(|| format!("{path}:{}: needs `command` or `method`", n + 1))?;
let params = v.get("params").cloned().filter(|p| p.is_object()).unwrap_or_else(|| json!({}));
steps.push(Step { id: id.to_string(), params });
}
steps.extend(read_script(path)?);
}
if steps.is_empty() {
return Err("run: no command given (see `lightcraft-cli commands`)".into());
}
let mut backend: Box<dyn Backend> =
// (this process holds the library: what it starts in the background ends with it)
let headless = connect.is_none();
let mut backend =
match connect {
Some(addr) => {
if demo || library.is_some() || !imports.is_empty() {
return Err("--demo, --library and --import apply to headless mode only".into());
}
Box::new(Remote::connect(&addr).map_err(|e| {
format!("LightCraft is not reachable at {addr} ({e}); start it with `lightcraft --control {}`", connect_port(&addr))
})?)
}
None => {
let mut h = match &library {
Some(dir) => {
let mut h = Headless::default();
h.session.open_library(dir, demo).map_err(|e| library_error(dir, e))?;
library_warnings(&mut h.session, "lightcraft-cli");
h
}
None if demo => Headless::demo(),
None => Headless::default(),
};
if !imports.is_empty() {
let paths = expand_paths(&imports);
let r = h.session.execute("library.import", &json!({"paths": paths})).map_err(|e| e.to_string())?;
// what follows acts on the imported photos (already-known files are reported as duplicates)
let mut ids: Vec<Value> = r["imported"].as_array().cloned().unwrap_or_default();
ids.extend(r["duplicates"].as_array().into_iter().flatten().filter_map(|d| d.get("existing").filter(|v| v.is_u64()).cloned()));
if let Some(first) = ids.first().cloned() {
h.session.execute("library.select", &json!({"ids": ids, "active": first})).map_err(|e| e.to_string())?;
}
}
Box::new(h)
})?) as Box<dyn Backend>
}
None => Box::new(open_headless(library.as_deref(), demo, &imports)?),
};
let mut out = std::io::stdout().lock();
let mut failed = 0;
let mut state = JobState::default();
for s in &steps {
// A background job that ended is the last one the library knows: a later one of the same
// kind replaces it, and with it how it ended. So how an earlier one ended is said, and
// counted, before another is started.
let starts_job = headless && matches!(s.id.as_str(), "library.backup" | "library.restore");
if starts_job && say_earlier_jobs(backend.as_mut(), &mut out, &mut state, keep_going)? {
break;
}
let t = std::time::Instant::now();
let line = match run_step(backend.as_mut(), s) {
Ok(r) => json!({"command": s.id, "ok": true, "result": r, "ms": (t.elapsed().as_secs_f64() * 1e4).round() / 10.0}),
Ok(r) => {
// (started in the background: it is seen through below)
// (also one that was over before the call returned: how it ended is still to be said)
let goes_on = r["running"] == json!(true) || (s.params["background"] == json!(true) && r.get("running").is_some());
state.restoring |= goes_on && s.id == "library.restore";
state.backing_up |= goes_on && s.id == "library.backup";
json!({"command": s.id, "ok": true, "result": r, "ms": (t.elapsed().as_secs_f64() * 1e4).round() / 10.0})
}
Err(e) => {
failed += 1;
state.failed += 1;
json!({"command": s.id, "ok": false, "error": e})
}
};
writeln!(out, "{line}").map_err(|e| e.to_string())?;
if failed > 0 && !keep_going {
if state.failed > 0 && !keep_going {
break;
}
}
// A restore or a backup that a command started in the background is seen through before
// this session ends: its work is this process's, and would end with it (a restore given up
// with nothing changed, a backup cut short). How it ended is one more line, whether or not
// it was over already when it was first asked about.
if headless && (state.failed == 0 || keep_going) {
for (started, status) in [(state.restoring, "library.restoreStatus"), (state.backing_up, "library.backupStatus")] {
if started {
let (line, ok) = see_job_through(backend.as_mut(), status);
state.failed += usize::from(!ok);
writeln!(out, "{line}").map_err(|e| e.to_string())?;
}
}
}
drop(backend); // a library session is flushed here
if failed > 0 { Err(format!("{failed} command(s) failed")) } else { Ok(()) }
if state.failed > 0 { Err(format!("{} command(s) failed", state.failed)) } else { Ok(()) }
}

/// What `run` has seen of background jobs and failures so far.
#[derive(Default)]
struct JobState {
failed: usize,
restoring: bool,
backing_up: bool,
}

/// The result line of a job's status (`ended`, taking `ms` milliseconds to arrive) and whether it
/// says the job went well.
fn status_line(status: &str, ended: Result<Value, String>, ms: f64) -> (Value, bool) {
match ended {
Ok(r) => {
let ok = r["error"].is_null();
(json!({"command": status, "ok": ok, "result": r, "ms": ms}), ok)
}
Err(e) => (json!({"command": status, "ok": false, "error": e}), false),
}
}

/// Ask for `status` until its job is over, saying once (when `warn_after` is set) that it is taking
/// a while. Returns the answer and the wait in milliseconds, to one decimal.
fn wait_for_status(backend: &mut dyn Backend, status: &str, warn_after: Option<std::time::Duration>) -> (Result<Value, String>, f64) {
let step = Step { id: status.to_string(), params: json!({}) };
let t = std::time::Instant::now();
let mut said = false;
let ended = loop {
match run_step(backend, &step) {
Ok(r) if r["running"] == json!(true) => {
// (a restore is moved into place once nothing else is at work in the
// library: one that waits is said, not waited for in silence)
if let Some(after) = warn_after
&& !said
&& t.elapsed() > after
{
said = true;
eprintln!("lightcraft-cli run: still waiting for {status} to say it is over (stop with Ctrl-C: nothing is left half done)");
}
std::thread::sleep(std::time::Duration::from_millis(20));
}
other => break other,
}
};
(ended, (t.elapsed().as_secs_f64() * 1e4).round() / 10.0)
}

/// The line for how a background job a command started ended, once seen through.
fn see_job_through(backend: &mut dyn Backend, status: &str) -> (Value, bool) {
let (ended, ms) = wait_for_status(backend, status, Some(std::time::Duration::from_secs(10)));
status_line(status, ended, ms)
}

/// Before a job is started in a headless session: say, and count, how an earlier backup or restore
/// ended (either kind: the engine refuses a backup while a restore runs, and the other way round).
/// `true` when the run is to stop (a failure, without `keep_going`).
fn say_earlier_jobs(backend: &mut dyn Backend, out: &mut impl Write, state: &mut JobState, keep_going: bool) -> Result<bool, String> {
let mut stop = false;
for (is_backup, status) in [(true, "library.backupStatus"), (false, "library.restoreStatus")] {
let earlier = if is_backup { &mut state.backing_up } else { &mut state.restoring };
if !*earlier {
continue;
}
// (said here: it is not asked about again at the end, unless another is started)
*earlier = false;
// (it is seen through first, as at the end)
let (ended, ms) = wait_for_status(backend, status, None);
let (line, ok) = status_line(status, ended, ms);
// (a line for each job, as for the last one at the end; only a failure fails the call)
state.failed += usize::from(!ok);
writeln!(out, "{line}").map_err(|e| e.to_string())?;
stop |= !ok && !keep_going;
}
Ok(stop)
}

/// The steps of a `--script` file (`-`: standard input), one JSON object per line.
fn read_script(path: &str) -> Result<Vec<Step>, String> {
let text = if path == "-" {
let mut s = String::new();
std::io::Read::read_to_string(&mut std::io::stdin(), &mut s).map_err(|e| e.to_string())?;
s
} else {
std::fs::read_to_string(path).map_err(|e| format!("{path}: {e}"))?
};
let mut steps = Vec::new();
for (n, line) in text.lines().enumerate().filter(|(_, l)| !l.trim().is_empty() && !l.trim_start().starts_with('#')) {
let v: Value = serde_json::from_str(line).map_err(|e| format!("{path}:{}: {e}", n + 1))?;
// `{"command": id, "params": …}` or a control request `{"method": m, "params": …}`
let id =
v.get("command").or(v.get("method")).and_then(Value::as_str).ok_or_else(|| format!("{path}:{}: needs `command` or `method`", n + 1))?;
let params = v.get("params").cloned().filter(|p| p.is_object()).unwrap_or_else(|| json!({}));
steps.push(Step { id: id.to_string(), params });
}
Ok(steps)
}

/// A headless session, on `library` or a demo one, with `imports` already imported and selected
/// (what follows acts on them; already-known files are reported as duplicates).
fn open_headless(library: Option<&str>, demo: bool, imports: &[String]) -> Result<Headless, String> {
let mut h = match library {
Some(dir) => {
let mut h = Headless::default();
h.session.open_library(dir, demo).map_err(|e| library_error(dir, e))?;
library_warnings(&mut h.session, "lightcraft-cli");
h
}
None if demo => Headless::demo(),
None => Headless::default(),
};
if !imports.is_empty() {
let paths = expand_paths(imports);
let r = h.session.execute("library.import", &json!({"paths": paths})).map_err(|e| e.to_string())?;
let mut ids: Vec<Value> = r["imported"].as_array().cloned().unwrap_or_default();
ids.extend(r["duplicates"].as_array().into_iter().flatten().filter_map(|d| d.get("existing").filter(|v| v.is_u64()).cloned()));
if let Some(first) = ids.first().cloned() {
h.session.execute("library.select", &json!({"ids": ids, "active": first})).map_err(|e| e.to_string())?;
}
}
Ok(h)
}

fn take_value<'a>(args: &'a [String], i: &mut usize, flag: &str) -> Result<&'a str, String> {
Expand Down
Loading
Loading