]> Cypherpunks.ru repositories - nncp.git/blobdiff - src/cmd/nncp-rm/main.go
MTH
[nncp.git] / src / cmd / nncp-rm / main.go
index b036d7080a0f835e7540e7c0f2a0be652a8364df..f8f4289639c0f685cd3a777471eec40cada25b7b 100644 (file)
@@ -29,7 +29,7 @@ import (
        "strings"
        "time"
 
-       "go.cypherpunks.ru/nncp/v5"
+       "go.cypherpunks.ru/nncp/v7"
 )
 
 func usage() {
@@ -69,6 +69,7 @@ func main() {
                version   = flag.Bool("version", false, "Print version information")
                warranty  = flag.Bool("warranty", false, "Print warranty information")
        )
+       log.SetFlags(log.Lshortfile)
        flag.Usage = usage
        flag.Parse()
        if *warranty {
@@ -122,10 +123,14 @@ func main() {
                                        return nil
                                }
                                if now.Sub(info.ModTime()) < oldBoundary {
-                                       ctx.LogD("nncp-rm", nncp.LEs{{K: "File", V: path}}, "too fresh, skipping")
+                                       ctx.LogD("rm-skip", nncp.LEs{{K: "File", V: path}}, func(les nncp.LEs) string {
+                                               return fmt.Sprintf("File %s: too fresh, skipping", path)
+                                       })
                                        return nil
                                }
-                               ctx.LogI("nncp-rm", nncp.LEs{{K: "File", V: path}}, "")
+                               ctx.LogI("rm", nncp.LEs{{K: "File", V: path}}, func(les nncp.LEs) string {
+                                       return fmt.Sprintf("File %s: removed", path)
+                               })
                                if *dryRun {
                                        return nil
                                }
@@ -145,7 +150,9 @@ func main() {
                                return nil
                        }
                        if strings.HasSuffix(info.Name(), ".lock") {
-                               ctx.LogI("nncp-rm", nncp.LEs{{K: "File", V: path}}, "")
+                               ctx.LogI("rm", nncp.LEs{{K: "File", V: path}}, func(les nncp.LEs) string {
+                                       return fmt.Sprintf("File %s: removed", path)
+                               })
                                if *dryRun {
                                        return nil
                                }
@@ -176,22 +183,27 @@ func main() {
                                if info.IsDir() {
                                        return nil
                                }
+                               logMsg := func(les nncp.LEs) string {
+                                       return fmt.Sprintf("File %s: removed", path)
+                               }
                                if now.Sub(info.ModTime()) < oldBoundary {
-                                       ctx.LogD("nncp-rm", nncp.LEs{{K: "File", V: path}}, "too fresh, skipping")
+                                       ctx.LogD("rm-skip", nncp.LEs{{K: "File", V: path}}, func(les nncp.LEs) string {
+                                               return fmt.Sprintf("File %s: too fresh, skipping", path)
+                                       })
                                        return nil
                                }
                                if (*doSeen && strings.HasSuffix(info.Name(), nncp.SeenSuffix)) ||
                                        (*doNoCK && strings.HasSuffix(info.Name(), nncp.NoCKSuffix)) ||
                                        (*doHdr && strings.HasSuffix(info.Name(), nncp.HdrSuffix)) ||
                                        (*doPart && strings.HasSuffix(info.Name(), nncp.PartSuffix)) {
-                                       ctx.LogI("nncp-rm", nncp.LEs{{K: "File", V: path}}, "")
+                                       ctx.LogI("rm", nncp.LEs{{K: "File", V: path}}, logMsg)
                                        if *dryRun {
                                                return nil
                                        }
                                        return os.Remove(path)
                                }
                                if *pktRaw != "" && filepath.Base(info.Name()) == *pktRaw {
-                                       ctx.LogI("nncp-rm", nncp.LEs{{K: "File", V: path}}, "")
+                                       ctx.LogI("rm", nncp.LEs{{K: "File", V: path}}, logMsg)
                                        if *dryRun {
                                                return nil
                                        }
@@ -200,7 +212,7 @@ func main() {
                                if !*doSeen && !*doNoCK && !*doHdr && !*doPart &&
                                        (*doRx || *doTx) &&
                                        ((*doRx && xx == nncp.TRx) || (*doTx && xx == nncp.TTx)) {
-                                       ctx.LogI("nncp-rm", nncp.LEs{{K: "File", V: path}}, "")
+                                       ctx.LogI("rm", nncp.LEs{{K: "File", V: path}}, logMsg)
                                        if *dryRun {
                                                return nil
                                        }