]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Fix sqlite piece completion error when dirs are missing
authorMatt Joiner <anacrolix@gmail.com>
Thu, 27 Jun 2024 04:31:31 +0000 (14:31 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Thu, 27 Jun 2024 04:34:55 +0000 (14:34 +1000)
storage/piece-completion.go

index bc646bd7aeb088f4e2a5b9b4d4df5eb678d36259..edc1e086437584d2d456de0e29cc0ceb5b224569 100644 (file)
@@ -2,6 +2,7 @@ package storage
 
 import (
        "github.com/anacrolix/log"
+       "os"
 
        "github.com/anacrolix/torrent/metainfo"
 )
@@ -18,9 +19,12 @@ type PieceCompletion interface {
 }
 
 func pieceCompletionForDir(dir string) (ret PieceCompletion) {
+       // This should be happening before sqlite attempts to open a database in the intended directory.
+       os.MkdirAll(dir, 0o700)
        ret, err := NewDefaultPieceCompletionForDir(dir)
        if err != nil {
-               log.Printf("couldn't open piece completion db in %q: %s", dir, err)
+               // This kinda sux using the global logger. This code is ancient.
+               log.Levelf(log.Warning, "couldn't open piece completion db in %q: %s", dir, err)
                ret = NewMapPieceCompletion()
        }
        return