mirror of
https://github.com/packwiz/packwiz.git
synced 2025-04-19 21:16:30 +02:00
Attempt to redownload cached files when errors are found
This commit is contained in:
parent
dd5520e471
commit
0df199852f
@ -72,19 +72,21 @@ func (d *downloadSessionInternal) StartDownloads() chan CompletedDownload {
|
||||
downloads <- found
|
||||
}
|
||||
for _, task := range d.downloadTasks {
|
||||
warnings := make([]error, 0)
|
||||
|
||||
// Get handle for mod
|
||||
cacheHandle := d.cacheIndex.GetHandleFromHash(task.hashFormat, task.hash)
|
||||
if cacheHandle != nil {
|
||||
download, err := reuseExistingFile(cacheHandle, d.hashesToObtain, task.mod)
|
||||
if err != nil {
|
||||
downloads <- CompletedDownload{
|
||||
Error: err,
|
||||
Mod: task.mod,
|
||||
}
|
||||
// Remove handle and try again
|
||||
cacheHandle.Remove()
|
||||
cacheHandle = nil
|
||||
warnings = append(warnings, fmt.Errorf("redownloading cached file: %w", err))
|
||||
} else {
|
||||
downloads <- download
|
||||
continue
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
download, err := downloadNewFile(&task, d.cacheFolder, d.hashesToObtain, &d.cacheIndex)
|
||||
@ -94,6 +96,7 @@ func (d *downloadSessionInternal) StartDownloads() chan CompletedDownload {
|
||||
Mod: task.mod,
|
||||
}
|
||||
} else {
|
||||
download.Warnings = warnings
|
||||
downloads <- download
|
||||
}
|
||||
}
|
||||
@ -538,6 +541,16 @@ func (h *CacheIndexHandle) UpdateIndex() (warnings []error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (h *CacheIndexHandle) Remove() {
|
||||
for hashFormat := range h.Hashes {
|
||||
hashList := h.index.Hashes[hashFormat]
|
||||
if h.hashIdx < len(hashList) {
|
||||
h.index.Hashes[hashFormat] = slices.Delete(hashList, h.hashIdx, h.hashIdx+1)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func CreateDownloadSession(mods []*Mod, hashesToObtain []string) (DownloadSession, error) {
|
||||
// Load cache index
|
||||
cacheIndex := CacheIndex{Version: 1, Hashes: make(map[string][]string)}
|
||||
|
Loading…
x
Reference in New Issue
Block a user