/*
NNCP -- Node to Node copy, utilities for store-and-forward data exchange
-Copyright (C) 2016-2017 Sergey Matveev <stargrave@stargrave.org>
+Copyright (C) 2016-2019 Sergey Matveev <stargrave@stargrave.org>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
+the Free Software Foundation, version 3 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-// Remove packet from the queue
+// Remove packet from the queue.
package main
import (
func usage() {
fmt.Fprintf(os.Stderr, nncp.UsageHeader())
- fmt.Fprintln(os.Stderr, "nncp-rm -- remove packet\n")
+ fmt.Fprintf(os.Stderr, "nncp-rm -- remove packet\n\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()
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)
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
})
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)
}