From dde93a1fe6a50dd2b0610cd45f2856995adb48d2 Mon Sep 17 00:00:00 2001 From: Alex Grintsvayg Date: Thu, 27 Feb 2020 14:52:48 -0500 Subject: [PATCH] make cache dir a cli flag --- cmd/reflector.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/cmd/reflector.go b/cmd/reflector.go index e922c51..8177d1e 100644 --- a/cmd/reflector.go +++ b/cmd/reflector.go @@ -18,12 +18,15 @@ import ( "github.com/spf13/cobra" ) +var reflectorCmdCacheDir string + func init() { var cmd = &cobra.Command{ Use: "reflector", Short: "Run reflector server", Run: reflectorCmd, } + cmd.Flags().StringVar(&reflectorCmdCacheDir, "cache", "", "Enable disk cache for blobs. Store them in this directory") rootCmd.AddCommand(cmd) } @@ -35,7 +38,6 @@ func reflectorCmd(cmd *cobra.Command, args []string) { useDB := true s3 := store.NewS3BlobStore(globalConfig.AwsID, globalConfig.AwsSecret, globalConfig.BucketRegion, globalConfig.BucketName) - diskStore := store.NewDiskBlobStore("/home/lbry/lbry_downloaded_blobs", 2) var err error @@ -60,9 +62,16 @@ func reflectorCmd(cmd *cobra.Command, args []string) { log.Fatal(err) } } - cacheStore := store.NewCachingBlobStore(blobStore, diskStore) - peerServer := peer.NewServer(cacheStore) + if reflectorCmdCacheDir != "" { + err = os.MkdirAll(reflectorCmdCacheDir, os.ModePerm) + if err != nil { + log.Fatal(err) + } + blobStore = store.NewCachingBlobStore(blobStore, store.NewDiskBlobStore(reflectorCmdCacheDir, 2)) + } + + peerServer := peer.NewServer(blobStore) err = peerServer.Start(":5567") if err != nil { log.Fatal(err)