summaryrefslogtreecommitdiff
path: root/doIncoming.go
diff options
context:
space:
mode:
Diffstat (limited to 'doIncoming.go')
-rw-r--r--doIncoming.go76
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
+}