]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Save .torrent with human readable name
authorSergey Matveev <stargrave@stargrave.org>
Mon, 28 Nov 2022 08:47:20 +0000 (11:47 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Fri, 13 Jan 2023 08:32:42 +0000 (11:32 +0300)
cmd/btrtrc/USAGE
cmd/btrtrc/fifos.go
cmd/btrtrc/main.go

index eec41551c5d4c76f6b1a6e042af6f688638305ab..40d58782a38d62031bd4ddd9c4bd5dfaa41177f8 100644 (file)
@@ -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.
index 09f4f56b8599e41592c97348934def833f3d7e0c..cb6139c8a7bd7023be0df3189fd01e3ea7fa4bc3 100644 (file)
@@ -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)
index 26dafe23379a1aaa63ec8c86f058c2780d0a2e3d..1f78e9e82509071c9cb21bfce16050d81076147e 100644 (file)
@@ -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")