From d3448bae5d61e4d1361d570ac83bfb5572fae119 Mon Sep 17 00:00:00 2001 From: Sergey Matveev Date: Mon, 28 Nov 2022 11:47:20 +0300 Subject: [PATCH] Save .torrent with human readable name --- cmd/btrtrc/USAGE | 2 +- cmd/btrtrc/fifos.go | 11 +++++++++++ cmd/btrtrc/main.go | 14 -------------- 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/cmd/btrtrc/USAGE b/cmd/btrtrc/USAGE index eec41551..40d58782 100644 --- a/cmd/btrtrc/USAGE +++ b/cmd/btrtrc/USAGE @@ -47,7 +47,7 @@ fifos subdirectory will be created with following FIFO files: * remote address with port * client's name -For each torrent, corresponding HASH.torrent file will be created. +For each torrent, corresponding .torrent file will be created. Additional symbolic link with torrent's name will lead to HASH.torrent. HASH.bf file is piece completion database. HASH.tx contains overall outgoing payload traffic amount and it is updated each 10sec. diff --git a/cmd/btrtrc/fifos.go b/cmd/btrtrc/fifos.go index 09f4f56b..cb6139c8 100644 --- a/cmd/btrtrc/fifos.go +++ b/cmd/btrtrc/fifos.go @@ -2,6 +2,7 @@ package main import ( "bufio" + "bytes" "encoding/hex" "fmt" "log" @@ -253,6 +254,16 @@ func readLinesFromFIFO(pth string) []string { return lines } +func saveTorrent(t *torrent.Torrent) error { + pth := t.Name() + TorrentExt + if _, err := os.Stat(pth); err == nil { + return nil + } + var b bytes.Buffer + t.Metainfo().Write(&b) + return os.WriteFile(pth, b.Bytes(), 0666) +} + func fifoAdd(c *torrent.Client) { pth := path.Join(FIFOsDir, "add") recreateFIFO(pth) diff --git a/cmd/btrtrc/main.go b/cmd/btrtrc/main.go index 26dafe23..1f78e9e8 100644 --- a/cmd/btrtrc/main.go +++ b/cmd/btrtrc/main.go @@ -1,7 +1,6 @@ package main import ( - "bytes" "flag" "log" "net" @@ -19,19 +18,6 @@ import ( const TorrentExt = ".torrent" -func saveTorrent(t *torrent.Torrent) error { - pth := t.InfoHash().HexString() + TorrentExt - if _, err := os.Stat(pth); err == nil { - return nil - } - var b bytes.Buffer - t.Metainfo().Write(&b) - if err := os.WriteFile(pth, b.Bytes(), 0666); err != nil { - return err - } - return os.Symlink(pth, t.Name()+TorrentExt) -} - func main() { log.SetFlags(log.Ldate | log.Ltime) dhtBoot := flag.String("dht", "dht.cypherpunks.ru:8991", "Comma-separated list of DHT bootstrap nodes") -- 2.48.1