]> Sergey Matveev's repositories - btrtrc.git/blobdiff - cmd/btrtrc/fifos.go
Save .torrent with human readable name
[btrtrc.git] / cmd / btrtrc / fifos.go
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)