summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-10-16 10:58:18 -0500
committerJeff Carr <[email protected]>2025-10-16 10:59:25 -0500
commitc5d1d34ef4e9f3ffb09ff1705c42c0ecc986abda (patch)
tree519221dbc7e1176263b20af45fbde79899b40f31
parenta1d3c86addef10faf24d829e52f342629466d993 (diff)
damnit. somehow removed the incoming/ Rename()v0.0.27
-rw-r--r--doIncoming.go125
1 files changed, 65 insertions, 60 deletions
diff --git a/doIncoming.go b/doIncoming.go
index 7dc0b45..85b81aa 100644
--- a/doIncoming.go
+++ b/doIncoming.go
@@ -2,6 +2,7 @@ package main
import (
"crypto/md5"
+ "errors"
"os"
"path/filepath"
"strings"
@@ -12,6 +13,61 @@ import (
"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 {
+ // 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.sh.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
+}
+
func doIncoming(pb *zoopb.Packages) (string, error) {
os.Chdir(me.pb.BaseDir)
@@ -22,73 +78,22 @@ func doIncoming(pb *zoopb.Packages) (string, 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)
- counter += 1
- }
- newcount += 1
- if !strings.HasPrefix(path, "pool/main") {
- if config.Verbose() {
- log.Info("already processed", 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)
+ }
}
- log.Info("TODO: fix this: ignoring files not in pool/main", path)
}
- _, filename := filepath.Split(path)
- parts := strings.Split(filename, "_")
- if len(parts) != 3 {
- // todo: add more filename checking here (check for ".deb")
- log.Println("bad filenae", filename)
- return nil
- }
- packageName := parts[0]
- letteredDir := log.Sprintf("%1.1s", filename)
- newfilename := filepath.Join("pool/main", letteredDir, packageName, filename)
- if newfilename == path {
- // the filename is correct
- return nil
- }
- destDir := filepath.Dir(newfilename)
- if err := os.MkdirAll(destDir, 0755); err != nil {
- log.Printf("%s move incoming oldname %s newname: %s\n", packageName, 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("OLD FILE", path)
- 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", 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 {
- 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.sh.GoodExit("file already exists. TODO: fix this to use --force to replace")
- }
- incount += 1
return nil
-
- // 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)
- // }
-
}
+ newcount += 1
return nil
})