Safety: - clean no longer deletes a dated file whose content is missing from the store. os.SameFile(nil, ...) returned false, so clean removed the file and then failed to relink it. MissingLink now reports and skips those files, and Relink swaps the link in with link+rename, so the path exists the whole time. - Move writes the content file under a temporary name, checks it against the hash, fsyncs it, and links it into place. An interrupted run can no longer leave a truncated file that later runs treat as a dup. - The crawl logs and skips unreadable paths instead of stopping, and it ignores AppleDouble ._ files and QNAP .@__thumb directories. Features: - sha256 content addresses by default; -hash=md5 adds to older stores. - am verify rehashes the store and reports corrupt, orphaned, and stale temp files. It only reads. - -n dry run for arr and clean prints the plan as TSV and changes nothing. - arr ends with a summary of counts and sizes by extension and year, with no file names. - heic/heif/avif, tiff, dng, cr2/cr3, nef, and arw are dated by exif via imagemeta, with goexif kept as the jpeg fallback. Exif times without an offset are read as local time, as before. - mov/mp4/m4v/3gp are dated from the moov/mvhd creation time. mkv, mts, webm, and friends are now included and dated by mtime. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
70 lines
1.3 KiB
Go
70 lines
1.3 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"os"
|
|
"path/filepath"
|
|
"runtime"
|
|
|
|
"mcquay.me/arrange"
|
|
)
|
|
|
|
func arr(indir, outdir string) error {
|
|
if !*dryRun {
|
|
if err := arrange.PrepOutput(outdir); err != nil {
|
|
return fmt.Errorf("problem creating directory structure: %v", err)
|
|
}
|
|
}
|
|
|
|
work := arrange.Source(indir)
|
|
streams := []<-chan arrange.Media{}
|
|
|
|
workers := runtime.NumCPU()
|
|
if *cores != 0 {
|
|
workers = *cores
|
|
}
|
|
|
|
for w := 0; w < workers; w++ {
|
|
streams = append(streams, arrange.Parse(work))
|
|
}
|
|
|
|
st := newStats()
|
|
// in a dry run nothing lands in the store, so remember what would have
|
|
seen := map[string]bool{}
|
|
for m := range arrange.Merge(streams) {
|
|
if *dryRun {
|
|
content := m.Content(outdir)
|
|
_, err := os.Stat(content)
|
|
dup := seen[m.Hash] || err == nil
|
|
seen[m.Hash] = true
|
|
action := "new"
|
|
if dup {
|
|
action = "dup"
|
|
}
|
|
date := filepath.Join(outdir, "date", fmt.Sprintf("%04d", m.Time.Year()), fmt.Sprintf("%02d", m.Time.Month()))
|
|
fmt.Printf("%s\t%s\t%s\t%s\n", action, m.Path, content, date)
|
|
st.add(m, dup)
|
|
continue
|
|
}
|
|
|
|
err := m.Move(outdir)
|
|
switch err.(type) {
|
|
case nil:
|
|
st.add(m, false)
|
|
case arrange.Dup:
|
|
st.add(m, true)
|
|
default:
|
|
st.errors++
|
|
log.Printf("%+v", err)
|
|
}
|
|
}
|
|
|
|
verb := "moved"
|
|
if *dryRun {
|
|
verb = "would move"
|
|
}
|
|
st.write(os.Stderr, verb)
|
|
return nil
|
|
}
|