i messed up

master
Bel LaPointe 2024-11-17 23:13:27 -07:00
parent eb12586a40
commit 9de277a879
1 changed files with 54 additions and 0 deletions

54
cmd/rmdir/main.go Normal file
View File

@ -0,0 +1,54 @@
package main
import (
"context"
"fmt"
"log"
"os"
"os/signal"
"syscall"
"ffmpeg.d/pkg/fs"
)
func main() {
ctx, can := signal.NotifyContext(context.Background(), syscall.SIGINT)
defer can()
if err := Run(ctx, os.Args[1:]); err != nil {
panic(err)
}
}
func Run(ctx context.Context, args []string) error {
cams, err := lsd(args[0])
if err != nil {
return fmt.Errorf("failed to lsd %s: %w", args[0], err)
}
for _, cam := range cams {
files, err := lsf(cam)
if err != nil {
return fmt.Errorf("failed to lsf %s: %w", cam, err)
} else if len(files) < 1 {
continue
}
for _, file := range files {
log.Println("rm", file)
if os.Getenv("DRY_RUN") == "false" {
os.Remove(file)
}
}
}
return nil
}
func lsd(d string) ([]string, error) {
return fs.LsD(d)
}
func lsf(d string) ([]string, error) {
return fs.LsF(d)
}