diff options
| author | Jeff Carr <[email protected]> | 2025-10-09 11:07:15 -0500 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-10-09 13:15:49 -0500 |
| commit | f47fbeed4d6b19f3859a3e4d417c4dc2592a5b38 (patch) | |
| tree | d39ce05325b810b90e5d8e041a041fa36b2948c0 /doIncoming.go | |
| parent | 31da3672f58df9a80e32a846bc9ff7bed3fdeffd (diff) | |
more on processing incoming/
Diffstat (limited to 'doIncoming.go')
| -rw-r--r-- | doIncoming.go | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/doIncoming.go b/doIncoming.go new file mode 100644 index 0000000..f077db7 --- /dev/null +++ b/doIncoming.go @@ -0,0 +1,76 @@ +package main + +import ( + "crypto/md5" + "os" + "path/filepath" + "strings" + + "go.wit.com/lib/config" + "go.wit.com/lib/gui/shell" + "go.wit.com/log" +) + +func doIncoming() (string, error) { + os.Chdir(me.mirrorsDir) + + for p := range me.pb.IterAll() { + log.Info(p.Package, p.Filename) + } + + err := filepath.Walk("pool", func(path string, info os.FileInfo, err error) error { + if err != nil { + return err + } + + if !info.IsDir() && strings.HasSuffix(info.Name(), ".deb") { + found := me.pb.FindByFilename(path) + if found == nil { + log.Printf("new file %s\n", path) + return nil + } + if strings.HasPrefix(path, "pool/main/incoming") { + letteredDir := log.Sprintf("%1.1s", found.Package) + _, filename := filepath.Split(path) + newfilename := filepath.Join("pool/main", letteredDir, found.Package, filename) + destDir := filepath.Dir(newfilename) + if err := os.MkdirAll(destDir, 0755); err != nil { + 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)) + } + 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") + return nil + } + log.Info("already processed", path) + + // Get control info + // cmd := exec.Command("dpkg-deb", "-I", path) + // var out bytes.Buffer + // cmd.Stdout = &out + // if err := cmd.Run(); err != nil { + // return fmt.Errorf("failed to run dpkg-deb on %s: %v", path, err) + // } + + } + return nil + }) + + return "scanned incoming", err +} |
