Fix repair bug
This commit is contained in:
@@ -88,6 +88,8 @@ func collectFiles(media arr.Content) map[string][]arr.ContentFile {
|
|||||||
func (r *Repair) checkTorrentFiles(torrentPath string, files []arr.ContentFile, clients map[string]types.Client, caches map[string]*store.Cache) []arr.ContentFile {
|
func (r *Repair) checkTorrentFiles(torrentPath string, files []arr.ContentFile, clients map[string]types.Client, caches map[string]*store.Cache) []arr.ContentFile {
|
||||||
brokenFiles := make([]arr.ContentFile, 0)
|
brokenFiles := make([]arr.ContentFile, 0)
|
||||||
|
|
||||||
|
emptyFiles := make([]arr.ContentFile, 0)
|
||||||
|
|
||||||
r.logger.Debug().Msgf("Checking %s", torrentPath)
|
r.logger.Debug().Msgf("Checking %s", torrentPath)
|
||||||
|
|
||||||
// Get the debrid client
|
// Get the debrid client
|
||||||
@@ -95,17 +97,18 @@ func (r *Repair) checkTorrentFiles(torrentPath string, files []arr.ContentFile,
|
|||||||
debridName := r.findDebridForPath(dir, clients)
|
debridName := r.findDebridForPath(dir, clients)
|
||||||
if debridName == "" {
|
if debridName == "" {
|
||||||
r.logger.Debug().Msgf("No debrid found for %s. Skipping", torrentPath)
|
r.logger.Debug().Msgf("No debrid found for %s. Skipping", torrentPath)
|
||||||
return files // Return all files as broken if no debrid found
|
return emptyFiles
|
||||||
}
|
}
|
||||||
|
|
||||||
cache, ok := caches[debridName]
|
cache, ok := caches[debridName]
|
||||||
if !ok {
|
if !ok {
|
||||||
r.logger.Debug().Msgf("No cache found for %s. Skipping", debridName)
|
r.logger.Debug().Msgf("No cache found for %s. Skipping", debridName)
|
||||||
return files // Return all files as broken if no cache found
|
return emptyFiles
|
||||||
}
|
}
|
||||||
tor, ok := r.torrentsMap.Load(debridName)
|
tor, ok := r.torrentsMap.Load(debridName)
|
||||||
if !ok {
|
if !ok {
|
||||||
r.logger.Debug().Msgf("Could not find torrents for %s. Skipping", debridName)
|
r.logger.Debug().Msgf("Could not find torrents for %s. Skipping", debridName)
|
||||||
|
return emptyFiles
|
||||||
}
|
}
|
||||||
|
|
||||||
torrentsMap := tor.(map[string]store.CachedTorrent)
|
torrentsMap := tor.(map[string]store.CachedTorrent)
|
||||||
@@ -114,8 +117,9 @@ func (r *Repair) checkTorrentFiles(torrentPath string, files []arr.ContentFile,
|
|||||||
torrentName := filepath.Clean(filepath.Base(torrentPath))
|
torrentName := filepath.Clean(filepath.Base(torrentPath))
|
||||||
torrent, ok := torrentsMap[torrentName]
|
torrent, ok := torrentsMap[torrentName]
|
||||||
if !ok {
|
if !ok {
|
||||||
r.logger.Debug().Msgf("No torrent found for %s. Skipping", torrentName)
|
r.logger.Debug().Msgf("Can't find torrent %s in %s. Marking as broken", torrentName, debridName)
|
||||||
return files // Return all files as broken if torrent not found
|
// Return all files as broken
|
||||||
|
return files
|
||||||
}
|
}
|
||||||
|
|
||||||
// Batch check files
|
// Batch check files
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ type entry struct {
|
|||||||
|
|
||||||
func filesToXML(urlPath string, fi os.FileInfo, children []os.FileInfo) stringbuf.StringBuf {
|
func filesToXML(urlPath string, fi os.FileInfo, children []os.FileInfo) stringbuf.StringBuf {
|
||||||
|
|
||||||
now := time.Now().UTC().Format("2006-01-02T15:04:05.000-07:00")
|
now := time.Now().UTC().Format(time.RFC3339)
|
||||||
entries := make([]entry, 0, len(children)+1)
|
entries := make([]entry, 0, len(children)+1)
|
||||||
|
|
||||||
// Add the current file itself
|
// Add the current file itself
|
||||||
@@ -65,7 +65,7 @@ func filesToXML(urlPath string, fi os.FileInfo, children []os.FileInfo) stringbu
|
|||||||
escName: xmlEscape(fi.Name()),
|
escName: xmlEscape(fi.Name()),
|
||||||
isDir: fi.IsDir(),
|
isDir: fi.IsDir(),
|
||||||
size: fi.Size(),
|
size: fi.Size(),
|
||||||
modTime: fi.ModTime().Format("2006-01-02T15:04:05.000-07:00"),
|
modTime: fi.ModTime().Format(time.RFC3339),
|
||||||
})
|
})
|
||||||
for _, info := range children {
|
for _, info := range children {
|
||||||
|
|
||||||
@@ -81,7 +81,7 @@ func filesToXML(urlPath string, fi os.FileInfo, children []os.FileInfo) stringbu
|
|||||||
escName: xmlEscape(nm),
|
escName: xmlEscape(nm),
|
||||||
isDir: info.IsDir(),
|
isDir: info.IsDir(),
|
||||||
size: info.Size(),
|
size: info.Size(),
|
||||||
modTime: info.ModTime().Format("2006-01-02T15:04:05.000-07:00"),
|
modTime: info.ModTime().Format(time.RFC3339),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
"path"
|
"path"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type contextKey string
|
type contextKey string
|
||||||
@@ -61,7 +62,7 @@ func (h *Handler) handlePropfind(w http.ResponseWriter, r *http.Request) {
|
|||||||
escName: xmlEscape(fi.Name()),
|
escName: xmlEscape(fi.Name()),
|
||||||
isDir: fi.IsDir(),
|
isDir: fi.IsDir(),
|
||||||
size: fi.Size(),
|
size: fi.Size(),
|
||||||
modTime: fi.ModTime().Format("2006-01-02T15:04:05.000-07:00"),
|
modTime: fi.ModTime().Format(time.RFC3339),
|
||||||
})
|
})
|
||||||
for _, info := range rawEntries {
|
for _, info := range rawEntries {
|
||||||
|
|
||||||
@@ -77,7 +78,7 @@ func (h *Handler) handlePropfind(w http.ResponseWriter, r *http.Request) {
|
|||||||
escName: xmlEscape(nm),
|
escName: xmlEscape(nm),
|
||||||
isDir: info.IsDir(),
|
isDir: info.IsDir(),
|
||||||
size: info.Size(),
|
size: info.Size(),
|
||||||
modTime: info.ModTime().Format("2006-01-02T15:04:05.000-07:00"),
|
modTime: info.ModTime().Format(time.RFC3339),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user