mirror of
https://github.com/GopeedLab/gopeed.git
synced 2026-11-16 21:33:41 +00:00
fix(bt): always preserve the torrent root directory
This commit is contained in:
1 parent
7c33d978c4
commit
69b3e223ad
2 files changed
+24
-5
No files matched your search
@@ -411,11 +411,18 @@ func (f *Fetcher) Wait() (err error) {
|
||||
}
|
||||
}
|
||||
|
||||
// Path already includes the torrent's root directory. Never prune the download
|
||||
// directory itself, and only remove parent directories that are empty.
|
||||
// Path already includes the torrent's root directory. Preserve that directory
|
||||
// even when empty, and only prune empty directories below it.
|
||||
func removeUnselectedFile(downloadDir, torrentPath string) error {
|
||||
if !filepath.IsLocal(torrentPath) {
|
||||
return fmt.Errorf("invalid torrent file path %q", torrentPath)
|
||||
}
|
||||
root := filepath.Clean(downloadDir)
|
||||
torrentPath = filepath.Clean(torrentPath)
|
||||
name := filepath.Join(root, torrentPath)
|
||||
if torrentDir, _, hasDir := strings.Cut(torrentPath, string(filepath.Separator)); hasDir {
|
||||
root = filepath.Join(root, torrentDir)
|
||||
}
|
||||
for _, candidate := range []string{name, name + ".part"} {
|
||||
if err := util.SafeRemove(candidate); err != nil {
|
||||
return fmt.Errorf("remove unselected torrent file %q: %w", candidate, err)
|
||||
|
||||
Reference in new issue
Block a user