diff options
| author | Jeff Carr <[email protected]> | 2025-10-26 14:56:52 -0500 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-10-26 14:58:01 -0500 |
| commit | 342c88ebbaac034c98dce4d19ebc1e7049323d5b (patch) | |
| tree | 42920c416c8ca7a1259b606f24ff313c30cd9dc2 | |
| parent | 337add61d45b558fe11765342b7498a86d5834df (diff) | |
fix incoming
| -rw-r--r-- | config.text | 24 | ||||
| -rw-r--r-- | doIncoming.go | 87 | ||||
| -rw-r--r-- | doIncomingOld.go | 68 |
3 files changed, 112 insertions, 67 deletions
diff --git a/config.text b/config.text index 2bdd782..0941913 100644 --- a/config.text +++ b/config.text @@ -1,3 +1,7 @@ +# +# This is our WIT mirrors config file +# ~/.config/mirrors/config.text +# uuid: "3135d0f9-82a9-40b6-8aa1-b683ebe7bedd" version: "v0.0.2 go.wit.com/lib/config" configs: { @@ -5,7 +9,21 @@ configs: { value: "protobufs are neat" } configs: { - key: "Verbose" - value: "true" + key: "mirrors.pb" + value: "/home/mirrors/wit/mirrors.wit.com.pb" } -filename: "/home/jcarr/.config/mirrors/config.text" +configs: { + key: "BaseDir" + value: "/home/mirrors/wit" +} +configs: { + key: "distPath" + value: "/home/mirrors/wit/dists/sid" +} +# YOUR GPG KEY +# Find it with: gpg --list-secret-keys --keyid-format=long +configs: { + key: "gpgKeyID" + value: "5D7C9BE47836D2FA48F83C2B4A854AEAF7E0E16D" +} +filename: "/root/.config/mirrors/config.text" diff --git a/doIncoming.go b/doIncoming.go index af8ac21..a6a6cbd 100644 --- a/doIncoming.go +++ b/doIncoming.go @@ -1,27 +1,17 @@ package main import ( - "crypto/md5" "errors" "os" "path/filepath" "strings" "go.wit.com/lib/config" - "go.wit.com/lib/gui/shell" - "go.wit.com/lib/protobuf/argvpb" "go.wit.com/lib/protobuf/zoopb" "go.wit.com/log" ) func moveOutOfIncoming(fullname string) error { - if strings.HasPrefix(fullname, "pool/main/incoming") { - log.Info("file is in incoming", fullname) - } else { - log.Info("file isn't in incoming", fullname) - return nil - } - _, filename := filepath.Split(fullname) parts := strings.Split(filename, "_") if len(parts) != 3 { @@ -31,73 +21,42 @@ func moveOutOfIncoming(fullname string) error { packageName := parts[0] letteredDir := log.Sprintf("%1.1s", filename) newfilename := filepath.Join("pool/main", letteredDir, packageName, filename) - if newfilename == fullname { - // the filename is correct - return errors.New(log.Sprintf("should be impossible %s", filename)) - } + destDir := filepath.Dir(newfilename) if err := os.MkdirAll(destDir, 0755); err != nil { log.Printf("%s move incoming oldname %s newname: %s\n", packageName, fullname, newfilename) log.Fatal("Failed to create destination directory: %v", err) } + log.Printf("%s move incoming oldname %s newname: %s\n", packageName, fullname, newfilename) if config.Exists(newfilename) { - olddata, _ := os.ReadFile(fullname) - newdata, _ := os.ReadFile(newfilename) - oldmd5 := md5.Sum(olddata) - newmd5 := md5.Sum(newdata) - if oldmd5 == newmd5 { - log.Info("OLD FILE", fullname) - log.Info("NEW FILE", newfilename) - log.Printf("files are the same %x %x\n", md5.Sum(olddata), md5.Sum(newdata)) - } else { - shell.RunVerbose([]string{"dpkg", "-I", fullname}) - shell.RunVerbose([]string{"dpkg", "-I", newfilename}) - log.Printf("different checksums: %s %s\n", fullname, newfilename) - log.Printf("md5sum old %x vs new %x\n", md5.Sum(olddata), md5.Sum(newdata)) - } - if argv.Force { - moveFileToBroken(newfilename) - // os.Rename(path, newfilename) - // log.Printf("%s moved incoming oldname %s newname: %s\n", packageName, path, newfilename) - } - // return "file already exists. use --force to replace", errors.New("duplicate .deb in incoming/") - argvpb.GoodExit("file already exists. TODO: fix this to use --force to replace") + log.Info("DEBIAN POLICY: YOU CAN NEVER REBUILD THE SAME FILE. APT WILL NOT REINSTALL IT.") + log.Info("AUTO REMOVING", fullname) + return os.Remove(fullname) + } + if argv.Force { + // file can be moved + os.Rename(fullname, newfilename) } - // file can be moved - os.Rename(fullname, newfilename) log.Printf("%s moved incoming oldname %s newname: %s\n", packageName, fullname, newfilename) return nil } func doIncoming(pb *zoopb.Packages) (string, error) { - os.Chdir(me.pb.BaseDir) + if err := os.Chdir(me.pb.BaseDir); err != nil { + return "no dir " + me.pb.BaseDir, err + } + + globPattern := "/home/mirrors/wit/incoming/*.deb" + files, err := filepath.Glob(globPattern) + if err != nil { + return "glob error", err + } - var counter int - var incount int - var newcount int - err := filepath.Walk("pool", func(path string, info os.FileInfo, err error) error { - if err != nil { - return err - } - counter += 1 - if !info.IsDir() && strings.HasSuffix(info.Name(), ".deb") { - if found := me.pb.FindByFilename(path); found != nil { - // log.Printf("not new file %s\n", path) - if strings.HasPrefix(path, "pool/main/incoming") { - incount += 1 - log.Info("file is in incomging", path) - err := moveOutOfIncoming(path) - if err != nil { - log.Info("moveOut err:", err) - } - } - } - return nil - } - newcount += 1 - return nil - }) + for _, filename := range files { + log.Info("need to move", filename) + moveOutOfIncoming(filename) + } - s := log.Sprintf("scanned %d files. (%d) in incoming. (%d) new files pb.Len(%d)", counter, incount, newcount, pb.Len()) + s := log.Sprintf("scanned (%d) in incoming", len(files)) return s, err } diff --git a/doIncomingOld.go b/doIncomingOld.go new file mode 100644 index 0000000..35873f0 --- /dev/null +++ b/doIncomingOld.go @@ -0,0 +1,68 @@ +package main + +import ( + "crypto/md5" + "errors" + "os" + "path/filepath" + "strings" + + "go.wit.com/lib/config" + "go.wit.com/lib/gui/shell" + "go.wit.com/log" +) + +func moveOutOfIncomingOld(fullname string) error { + if strings.HasPrefix(fullname, "pool/main/incoming") { + log.Info("file is in incoming", fullname) + } else { + log.Info("file isn't in incoming", fullname) + return nil + } + + _, filename := filepath.Split(fullname) + parts := strings.Split(filename, "_") + if len(parts) != 3 { + // todo: add more filename checking here (check for ".deb") + return errors.New(log.Sprintf("bad filenae %s", filename)) + } + packageName := parts[0] + letteredDir := log.Sprintf("%1.1s", filename) + newfilename := filepath.Join("pool/main", letteredDir, packageName, filename) + if newfilename == fullname { + // the filename is correct + return errors.New(log.Sprintf("should be impossible %s", filename)) + } + destDir := filepath.Dir(newfilename) + if err := os.MkdirAll(destDir, 0755); err != nil { + log.Printf("%s move incoming oldname %s newname: %s\n", packageName, fullname, newfilename) + log.Fatal("Failed to create destination directory: %v", err) + } + if config.Exists(newfilename) { + olddata, _ := os.ReadFile(fullname) + newdata, _ := os.ReadFile(newfilename) + oldmd5 := md5.Sum(olddata) + newmd5 := md5.Sum(newdata) + if oldmd5 == newmd5 { + log.Info("OLD FILE", fullname) + log.Info("NEW FILE", newfilename) + log.Printf("files are the same %x %x\n", md5.Sum(olddata), md5.Sum(newdata)) + } else { + shell.RunVerbose([]string{"dpkg", "-I", fullname}) + shell.RunVerbose([]string{"dpkg", "-I", newfilename}) + log.Printf("different checksums: %s %s\n", fullname, newfilename) + log.Printf("md5sum old %x vs new %x\n", md5.Sum(olddata), md5.Sum(newdata)) + } + if argv.Force { + moveFileToBroken(newfilename) + // os.Rename(path, newfilename) + // log.Printf("%s moved incoming oldname %s newname: %s\n", packageName, path, newfilename) + } + // return "file already exists. use --force to replace", errors.New("duplicate .deb in incoming/") + me.argv.GoodExit("file already exists. TODO: fix this to use --force to replace") + } + // file can be moved + os.Rename(fullname, newfilename) + log.Printf("%s moved incoming oldname %s newname: %s\n", packageName, fullname, newfilename) + return nil +} |
