diff options
| -rw-r--r-- | argv.go | 20 | ||||
| -rw-r--r-- | doIncoming.go | 35 |
2 files changed, 33 insertions, 22 deletions
@@ -17,14 +17,14 @@ import ( var argv args type args struct { - List *EmptyCmd `arg:"subcommand:list" help:"show the packages"` - Walk *WalkCmd `arg:"subcommand:walk" help:"walk the filesystem for new .deb files"` - Update *EmptyCmd `arg:"subcommand:oldway" help:"the old code to update the apt repo"` - Incoming *EmptyCmd `arg:"subcommand:incoming" help:"handle the incoming directory"` - MakeDists *EmptyCmd `arg:"subcommand:makedists" help:"make debian mirrors/dists files for 'apt update'"` - DryRun bool `arg:"--dry-run" help:"only show what would be packaged"` - Verbose bool `arg:"--verbose" help:"be loud about it"` - Force bool `arg:"--force" help:"rebuild everything"` + List *EmptyCmd `arg:"subcommand:list" help:"show the packages"` + Walk *WalkCmd `arg:"subcommand:walk" help:"walk the filesystem for new .deb files"` + Update *EmptyCmd `arg:"subcommand:oldway" help:"the old code to update the apt repo"` + Incoming *IncomingCmd `arg:"subcommand:incoming" help:"handle the incoming directory"` + MakeDists *EmptyCmd `arg:"subcommand:makedists" help:"make debian mirrors/dists files for 'apt update'"` + DryRun bool `arg:"--dry-run" help:"only show what would be packaged"` + Verbose bool `arg:"--verbose" help:"be loud about it"` + Force bool `arg:"--force" help:"rebuild everything"` } type EmptyCmd struct { @@ -34,6 +34,10 @@ type WalkCmd struct { Verbose bool `arg:"--verbose" help:"be loud about it"` } +type IncomingCmd struct { + Force bool `arg:"--force" help:"rebuild everything"` +} + func (args) Buildtime() (string, string) { return BUILDTIME, VERSION } diff --git a/doIncoming.go b/doIncoming.go index f077db7..9f2202d 100644 --- a/doIncoming.go +++ b/doIncoming.go @@ -18,6 +18,7 @@ func doIncoming() (string, error) { log.Info(p.Package, p.Filename) } + var counter int err := filepath.Walk("pool", func(path string, info os.FileInfo, err error) error { if err != nil { return err @@ -38,24 +39,30 @@ func doIncoming() (string, error) { log.Printf("%s move incoming oldname %s newname: %s\n", found.Package, path, newfilename) log.Fatal("Failed to create destination directory: %v", err) } - if config.Exists(newfilename) { - olddata, _ := os.ReadFile(path) - newdata, _ := os.ReadFile(newfilename) - oldmd5 := md5.Sum(olddata) - newmd5 := md5.Sum(newdata) - if oldmd5 == newmd5 { - log.Info("files are the same", md5.Sum(olddata), md5.Sum(newdata)) - } else { - shell.RunVerbose([]string{"dpkg", "-I", path}) - shell.RunVerbose([]string{"dpkg", "-I", newfilename}) - log.Printf("different checksums: %s %s\n", path, newfilename) - log.Printf("md5sum old %x vs new %x\n", md5.Sum(olddata), md5.Sum(newdata)) + if !argv.Force { + if config.Exists(newfilename) { + olddata, _ := os.ReadFile(path) + newdata, _ := os.ReadFile(newfilename) + oldmd5 := md5.Sum(olddata) + newmd5 := md5.Sum(newdata) + if oldmd5 == newmd5 { + log.Info("files are the same", md5.Sum(olddata), md5.Sum(newdata)) + } else { + shell.RunVerbose([]string{"dpkg", "-I", path}) + shell.RunVerbose([]string{"dpkg", "-I", newfilename}) + log.Printf("different checksums: %s %s\n", path, newfilename) + log.Printf("md5sum old %x vs new %x\n", md5.Sum(olddata), md5.Sum(newdata)) + } + // return "file already exists. use --force to replace", errors.New("duplicate .deb in incoming/") + me.sh.GoodExit("file already exists. use --force to replace") } - me.sh.BadExit("file already exists", nil) } os.Rename(path, newfilename) log.Printf("%s moved incoming oldname %s newname: %s\n", found.Package, path, newfilename) - me.sh.GoodExit("file moved") + counter += 1 + if counter > 100 { + me.sh.GoodExit("file moved") + } return nil } log.Info("already processed", path) |
