From 37c5400e2d38f3608ac3e801dd087fd72f2e4db5 Mon Sep 17 00:00:00 2001 From: Shizeeg Unadequatov Date: Tue, 3 Aug 2021 20:40:50 -0700 Subject: [PATCH] Add an option to configure download directory defaulted to os.TmpDir() just as before. --- client.go | 3 ++- main.go | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/client.go b/client.go index 8fdd894..3621d41 100644 --- a/client.go +++ b/client.go @@ -46,6 +46,7 @@ type Client struct { // ClientConfig specifies the behaviour of a client. type ClientConfig struct { TorrentPath string + DataDir string Port int TorrentPort int Seed bool @@ -74,7 +75,7 @@ func NewClient(cfg ClientConfig) (client Client, err error) { blocklist := getBlocklist() torrentConfig := torrent.NewDefaultClientConfig() - torrentConfig.DataDir = os.TempDir() + torrentConfig.DataDir = cfg.DataDir torrentConfig.NoUpload = !cfg.Seed torrentConfig.DisableTCP = !cfg.TCP torrentConfig.ListenPort = cfg.TorrentPort diff --git a/main.go b/main.go index 3056e4c..244850f 100644 --- a/main.go +++ b/main.go @@ -27,6 +27,7 @@ func main() { flag.BoolVar(&cfg.Seed, "seed", cfg.Seed, "Seed after finished downloading") flag.IntVar(&cfg.MaxConnections, "conn", cfg.MaxConnections, "Maximum number of connections") flag.BoolVar(&cfg.TCP, "tcp", cfg.TCP, "Allow connections via TCP") + flag.StringVar(&cfg.DataDir, "datadir", os.TempDir(), "Where to download torrent data") flag.Parse() if len(flag.Args()) == 0 { flag.Usage()