v0.9.2: add manifest repair
This commit is contained in:
@@ -92,6 +92,8 @@ func run(args []string, stdout, stderr io.Writer, bridge photos.Bridge) int {
|
||||
return cmdDiff(args[1:], stdout, stderr, bridge)
|
||||
case "verify":
|
||||
return cmdVerify(args[1:], stdout, stderr)
|
||||
case "manifest":
|
||||
return cmdManifest(args[1:], stdout, stderr)
|
||||
case "retry-failed":
|
||||
return cmdRetryFailed(args[1:], stdout, stderr, bridge)
|
||||
case "failures":
|
||||
@@ -137,6 +139,7 @@ USAGE
|
||||
photoscli report --out <dir> [--manifest jsonl|sqlite]
|
||||
photoscli diff --album-id <id-or-title> --out <dir> [--manifest jsonl|sqlite]
|
||||
photoscli verify --out <dir> [--manifest jsonl|sqlite]
|
||||
photoscli manifest repair --out <dir> [--manifest jsonl|sqlite] [--checksum sha256] [--dry-run]
|
||||
photoscli retry-failed --out <dir>
|
||||
photoscli retry-failed --out <dir> --clear-on-success
|
||||
photoscli failures list --out <dir>
|
||||
@@ -182,6 +185,9 @@ COMMANDS
|
||||
--sidecar to require photoscli schema/generator and exported filename metadata.
|
||||
Add --deep to verify manifest SHA-256 checksums when present.
|
||||
|
||||
manifest repair --out <dir> [--manifest jsonl|sqlite] [--checksum sha256] [--dry-run]
|
||||
Fill missing manifest size/checksum metadata from files that exist on disk.
|
||||
|
||||
retry-failed --out <dir>
|
||||
Retry assets previously written to failures.jsonl.
|
||||
|
||||
@@ -2383,6 +2389,91 @@ func verifySidecar(stdout io.Writer, outDir, id, checkPath string, strict bool)
|
||||
return 0
|
||||
}
|
||||
|
||||
func cmdManifest(args []string, stdout, stderr io.Writer) int {
|
||||
if len(args) < 1 || args[0] != "repair" {
|
||||
fmt.Fprintln(stderr, "error: expected manifest repair")
|
||||
return exitErr
|
||||
}
|
||||
outDir := flagVal(args, "--out")
|
||||
if outDir == "" {
|
||||
fmt.Fprintln(stderr, "error: --out is required")
|
||||
return exitErr
|
||||
}
|
||||
checksumMode := flagValWithDefault(args, "--checksum", "none")
|
||||
if checksumMode != "none" && checksumMode != "sha256" {
|
||||
fmt.Fprintf(stderr, "error: --checksum must be none or sha256, got %q\n", checksumMode)
|
||||
return exitErr
|
||||
}
|
||||
mf, err := manifest.ParseFormat(flagValWithDefault(args, "--manifest", "jsonl"))
|
||||
if err != nil {
|
||||
fmt.Fprintf(stderr, "error: %v\n", err)
|
||||
return exitErr
|
||||
}
|
||||
m, err := manifest.Open(outDir, mf)
|
||||
if err != nil {
|
||||
fmt.Fprintf(stderr, "error: %v\n", err)
|
||||
return exitErr
|
||||
}
|
||||
defer m.Close()
|
||||
reader := m.(manifest.EntryReader)
|
||||
if !hasFlag(args, "--dry-run") {
|
||||
if err := m.OpenAppend(); err != nil {
|
||||
fmt.Fprintf(stderr, "error: %v\n", err)
|
||||
return exitErr
|
||||
}
|
||||
}
|
||||
repaired := 0
|
||||
skipped := 0
|
||||
for id, entry := range reader.Entries() {
|
||||
checkPath := entry.Path
|
||||
if checkPath == "" {
|
||||
checkPath = entry.Filename
|
||||
}
|
||||
if checkPath == "" {
|
||||
skipped++
|
||||
continue
|
||||
}
|
||||
fullPath := filepath.Join(outDir, checkPath)
|
||||
info, err := statFunc(fullPath)
|
||||
if err != nil || info.IsDir() || info.Size() == 0 {
|
||||
skipped++
|
||||
continue
|
||||
}
|
||||
updated := entry
|
||||
updated.ID = id
|
||||
changed := false
|
||||
if updated.Size != info.Size() {
|
||||
updated.Size = info.Size()
|
||||
changed = true
|
||||
}
|
||||
if checksumMode == "sha256" && updated.Checksum == "" {
|
||||
checksum, err := fileSHA256(fullPath)
|
||||
if err != nil {
|
||||
skipped++
|
||||
continue
|
||||
}
|
||||
updated.Checksum = checksum
|
||||
changed = true
|
||||
}
|
||||
if !changed {
|
||||
continue
|
||||
}
|
||||
repaired++
|
||||
fmt.Fprintf(stdout, "%s\t%s\trepaired\n", id, checkPath)
|
||||
if !hasFlag(args, "--dry-run") {
|
||||
m.AddEntry(updated)
|
||||
}
|
||||
}
|
||||
if !hasFlag(args, "--dry-run") {
|
||||
if err := m.Save(); err != nil {
|
||||
fmt.Fprintf(stderr, "error: %v\n", err)
|
||||
return exitErr
|
||||
}
|
||||
}
|
||||
fmt.Fprintf(stdout, "repaired\t%d\nskipped\t%d\n", repaired, skipped)
|
||||
return exitOK
|
||||
}
|
||||
|
||||
func cmdSidecar(args []string, stdout, stderr io.Writer) int {
|
||||
if len(args) < 1 || args[0] != "inspect" {
|
||||
fmt.Fprintln(stderr, "error: expected sidecar inspect <file.xmp>")
|
||||
|
||||
Reference in New Issue
Block a user