From 3b503fc868ff8874dcae3690f9e30d215874a5b2 Mon Sep 17 00:00:00 2001 From: Ben Sarmiento Date: Sat, 21 Oct 2023 12:09:38 +0200 Subject: [PATCH] Only add DMM fragment when there is the same filename in the directory --- internal/dav/response.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/internal/dav/response.go b/internal/dav/response.go index 67aad87..d593263 100644 --- a/internal/dav/response.go +++ b/internal/dav/response.go @@ -43,7 +43,8 @@ func createSingleTorrentResponse(basePath string, torrents []torrent.Torrent, t currentPath := filepath.Join(basePath, torrents[0].Name) responses = append(responses, dav.Directory(currentPath)) - seen := make(map[string]bool) + nameAndLink := make(map[string]bool) + finalName := make(map[string]bool) var torrentResponses []dav.Response for _, torrent := range torrents { @@ -57,12 +58,15 @@ func createSingleTorrentResponse(basePath string, torrents []torrent.Torrent, t continue } filename := filepath.Base(file.Path) - fragment := davextra.GetLinkFragment(file.Link) - filename = davextra.InsertLinkFragment(filename, fragment) - if _, exists := seen[filename]; exists { + if _, exists := nameAndLink[filename+file.Link]; exists { continue } - seen[filename] = true + nameAndLink[filename+file.Link] = true + if _, exists := finalName[filename]; exists { + fragment := davextra.GetLinkFragment(file.Link) + filename = davextra.InsertLinkFragment(filename, fragment) + } + finalName[filename] = true filePath := filepath.Join(currentPath, filename) torrentResponses = append(torrentResponses, dav.File( filePath,