From b8e1c9539907b177a7dac66c95304c0dbe91475f Mon Sep 17 00:00:00 2001 From: gitpubber <76197622+gitpubber@users.noreply.github.com> Date: Sun, 9 May 2021 15:04:41 +0530 Subject: [PATCH] Allows one to use Custom PieceCompletion (#486) * Change ClientImpl to ClientImplCloser We cannot close underlying Boltdb PieceCompletion if it is not closable * Update file.go --- storage/file.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/storage/file.go b/storage/file.go index a4c29015..1a273a34 100644 --- a/storage/file.go +++ b/storage/file.go @@ -36,7 +36,7 @@ func NewFile(baseDir string) ClientImplCloser { } func NewFileWithCompletion(baseDir string, completion PieceCompletion) *fileClientImpl { - return newFileWithCustomPathMakerAndCompletion(baseDir, nil, completion) + return NewFileWithCustomPathMakerAndCompletion(baseDir, nil, completion) } // File storage with data partitioned by infohash. @@ -48,10 +48,11 @@ func NewFileByInfoHash(baseDir string) ClientImplCloser { // responsible for sanitizing the info if it uses some part of it (for example sanitizing // info.Name). func NewFileWithCustomPathMaker(baseDir string, pathMaker func(baseDir string, info *metainfo.Info, infoHash metainfo.Hash) string) ClientImplCloser { - return newFileWithCustomPathMakerAndCompletion(baseDir, pathMaker, pieceCompletionForDir(baseDir)) + return NewFileWithCustomPathMakerAndCompletion(baseDir, pathMaker, pieceCompletionForDir(baseDir)) } -func newFileWithCustomPathMakerAndCompletion(baseDir string, pathMaker func(baseDir string, info *metainfo.Info, infoHash metainfo.Hash) string, completion PieceCompletion) *fileClientImpl { +// Allows passing custom PieceCompletion +func NewFileWithCustomPathMakerAndCompletion(baseDir string, pathMaker func(baseDir string, info *metainfo.Info, infoHash metainfo.Hash) string, completion PieceCompletion) *fileClientImpl { if pathMaker == nil { pathMaker = defaultPathMaker } -- 2.48.1