safer moves, verify, dry run, heic/raw and video dates
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>
This commit is contained in:
+30
-9
@@ -1,24 +1,25 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
"crypto/sha256"
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"mcquay.me/arrange"
|
||||
)
|
||||
|
||||
const usage = "am <arr|clean|meta> [flags]"
|
||||
const arrUsage = "am arr [-h|-cores=N] <in> <out>"
|
||||
const cleanUsage = "am clean [-h|-cores=N] <directory>"
|
||||
const usage = "am <arr|clean|verify|meta> [flags]"
|
||||
const arrUsage = "am arr [-h|-n|-hash=sha256|md5|-cores=N] <in> <out>"
|
||||
const cleanUsage = "am clean [-h|-n|-cores=N] <directory>"
|
||||
const verifyUsage = "am verify [-h|-cores=N] <directory>"
|
||||
const metaUsage = "am meta [-h|-cores=N] <file0> <file1> ... <fileN>"
|
||||
|
||||
type stats struct {
|
||||
total int
|
||||
dupes int
|
||||
moved int
|
||||
}
|
||||
|
||||
var cores = flag.Int("cores", 0, "how many threads to use")
|
||||
var dryRun = flag.Bool("n", false, "dry run: print the plan as tab-separated lines, change nothing")
|
||||
var hashName = flag.String("hash", "sha256", "content-address hash: sha256, or md5 to add to a store built by older versions")
|
||||
|
||||
func main() {
|
||||
if len(os.Args) < 2 {
|
||||
@@ -31,6 +32,16 @@ func main() {
|
||||
flag.Parse()
|
||||
log.SetFlags(log.Lshortfile)
|
||||
|
||||
switch *hashName {
|
||||
case "sha256":
|
||||
arrange.NewHash = sha256.New
|
||||
case "md5":
|
||||
arrange.NewHash = md5.New
|
||||
default:
|
||||
fmt.Fprintf(os.Stderr, "unsupported hash %q (supported: sha256, md5)\n", *hashName)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
switch sub {
|
||||
case "ar", "arr", "arrange":
|
||||
args := flag.Args()
|
||||
@@ -54,6 +65,16 @@ func main() {
|
||||
fmt.Fprintf(os.Stderr, "problem cleaning: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
case "v", "verify":
|
||||
args := flag.Args()
|
||||
if len(args) != 1 {
|
||||
fmt.Fprintf(os.Stderr, "%s\n", verifyUsage)
|
||||
os.Exit(1)
|
||||
}
|
||||
if err := verify(args[0]); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "problem verifying: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
case "m", "meta":
|
||||
args := flag.Args()
|
||||
if len(args) < 1 {
|
||||
|
||||
Reference in New Issue
Block a user