]> Cypherpunks.ru repositories - nncp.git/commitdiff
Fixed nncp-rm work
authorSergey Matveev <stargrave@stargrave.org>
Sat, 2 Dec 2017 15:52:47 +0000 (18:52 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Sat, 2 Dec 2017 15:52:47 +0000 (18:52 +0300)
doc/cmds.texi
src/cypherpunks.ru/nncp/cmd/nncp-rm/main.go
src/cypherpunks.ru/nncp/humanizer.go

index 51ea04fdd3d78ce3a09f1a83aad5c51966094eb5..1de83a4e8dc361f1ac0fade948fa853a905dddda 100644 (file)
@@ -407,7 +407,9 @@ Checksums:
 @verbatim
 % nncp-rm [options] -tmp
 % nncp-rm [options] -lock
-% nncp-rm [options] -node NODE [-rx] [-tx] [-part] [-seen]
+% nncp-rm [options] -node NODE -part
+% nncp-rm [options] -node NODE -seen
+% nncp-rm [options] -node NODE [-rx] [-tx]
 % nncp-rm [options] -node NODE -pkt PKT
 @end verbatim
 
index d93a46a01bb903c990899a97c00ccac45e4923a3..b616ad8163cc578faae942a3c7cdde052dc99365 100644 (file)
@@ -35,7 +35,9 @@ func usage() {
        fmt.Fprintln(os.Stderr, "nncp-rm -- remove packet\n")
        fmt.Fprintf(os.Stderr, "Usage: %s [options] -tmp\n", os.Args[0])
        fmt.Fprintf(os.Stderr, "       %s [options] -lock\n", os.Args[0])
-       fmt.Fprintf(os.Stderr, "       %s [options] -node NODE [-rx] [-tx] [-part] [-seen]\n", os.Args[0])
+       fmt.Fprintf(os.Stderr, "       %s [options] -node NODE -part\n", os.Args[0])
+       fmt.Fprintf(os.Stderr, "       %s [options] -node NODE -seen\n", os.Args[0])
+       fmt.Fprintf(os.Stderr, "       %s [options] -node NODE {-rx|-tx}\n", os.Args[0])
        fmt.Fprintf(os.Stderr, "       %s [options] -node NODE -pkt PKT\n", os.Args[0])
        fmt.Fprintln(os.Stderr, "Options:")
        flag.PrintDefaults()
@@ -79,7 +81,11 @@ func main() {
                        if err != nil {
                                return err
                        }
-                       return os.Remove(info.Name())
+                       if info.IsDir() {
+                               return nil
+                       }
+                       ctx.LogI("nncp-rm", nncp.SDS{"file": path}, "")
+                       return os.Remove(path)
                })
                if err != nil {
                        log.Fatalln("Error during walking:", err)
@@ -91,8 +97,12 @@ func main() {
                        if err != nil {
                                return err
                        }
+                       if info.IsDir() {
+                               return nil
+                       }
                        if strings.HasSuffix(info.Name(), ".lock") {
-                               return os.Remove(info.Name())
+                               ctx.LogI("nncp-rm", nncp.SDS{"file": path}, "")
+                               return os.Remove(path)
                        }
                        return nil
                })
@@ -114,19 +124,32 @@ func main() {
                        if err != nil {
                                return err
                        }
+                       if info.IsDir() {
+                               return nil
+                       }
                        if *doSeen && strings.HasSuffix(info.Name(), nncp.SeenSuffix) {
-                               return os.Remove(info.Name())
+                               ctx.LogI("nncp-rm", nncp.SDS{"file": path}, "")
+                               return os.Remove(path)
                        }
                        if *doPart && strings.HasSuffix(info.Name(), nncp.PartSuffix) {
-                               return os.Remove(info.Name())
+                               ctx.LogI("nncp-rm", nncp.SDS{"file": path}, "")
+                               return os.Remove(path)
+                       }
+                       if *pktRaw != "" && filepath.Base(info.Name()) == *pktRaw {
+                               ctx.LogI("nncp-rm", nncp.SDS{"file": path}, "")
+                               return os.Remove(path)
                        }
-                       if *pktRaw == "" || filepath.Base(info.Name()) == *pktRaw {
-                               return os.Remove(info.Name())
+                       if !*doSeen &&
+                               !*doPart &&
+                               (*doRx || *doTx) &&
+                               ((*doRx && xx == nncp.TRx) || (*doTx && xx == nncp.TTx)) {
+                               ctx.LogI("nncp-rm", nncp.SDS{"file": path}, "")
+                               return os.Remove(path)
                        }
                        return nil
                })
        }
-       if *pktRaw != "" || *doRx {
+       if *pktRaw != "" || *doRx || *doSeen || *doPart {
                if err = remove(nncp.TRx); err != nil {
                        log.Fatalln("Can not remove:", err)
                }
index 7830a31e764cccda52eab660aa38d958a81a9bf2..4a79fcd9e6facae990d490bdd55ba8e761c1d3d5 100644 (file)
@@ -169,6 +169,8 @@ func (ctx *Ctx) Humanize(s string) string {
                if err, exists := sds["err"]; exists {
                        msg += ": " + err
                }
+       case "nncp-rm":
+               msg += "removing " + sds["file"]
        case "call-start":
                msg = fmt.Sprintf("Connected to %s", nodeS)
        case "call-finish":