Skip to content

Commit

Permalink
Fixed doubling end slashes
Browse files Browse the repository at this point in the history
  • Loading branch information
rumanzo committed May 5, 2022
1 parent df880d4 commit 44c038b
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 6 deletions.
18 changes: 12 additions & 6 deletions internal/transfer/transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,10 @@ func (transfer *TransferStructure) HandleSavePaths() {
}
}
}
transfer.Fastresume.QbtSavePath = fileHelpers.CutLastPath(transfer.ResumeItem.Path, "/") + `/`
transfer.Fastresume.QbtSavePath = fileHelpers.CutLastPath(transfer.ResumeItem.Path, "/")
if string(transfer.Fastresume.QbtSavePath[len(transfer.Fastresume.QbtSavePath)-1]) != `/` {
transfer.Fastresume.QbtSavePath += `/`
}
} else {
transfer.Fastresume.QBtContentLayout = "NoSubfolder"
// NoSubfolder always has full mapped files
Expand Down Expand Up @@ -329,12 +332,13 @@ func (transfer *TransferStructure) HandleSavePaths() {
}
} else {
transfer.Fastresume.QBtContentLayout = "Original" // utorrent\bittorrent don't support create subfolders for torrents with single file
if lastPathName == torrentName {
transfer.Fastresume.QbtSavePath = fileHelpers.CutLastPath(transfer.ResumeItem.Path, `/`) + `/`
} else {
if lastPathName != torrentName {
//it means that we have renamed path and targets item, and should have mapped files
transfer.Fastresume.MappedFiles = []string{lastPathName}
transfer.Fastresume.QbtSavePath = fileHelpers.CutLastPath(transfer.ResumeItem.Path, `/`) + `/`
}
transfer.Fastresume.QbtSavePath = fileHelpers.CutLastPath(transfer.ResumeItem.Path, `/`)
if string(transfer.Fastresume.QbtSavePath[len(transfer.Fastresume.QbtSavePath)-1]) != `/` {
transfer.Fastresume.QbtSavePath += `/`
}
}
}
Expand All @@ -351,7 +355,9 @@ func (transfer *TransferStructure) HandleSavePaths() {

transfer.Fastresume.SavePath = fileHelpers.Normalize(transfer.Fastresume.QbtSavePath, transfer.Opts.PathSeparator)
if transfer.Fastresume.QBtContentLayout == "Original" && !transfer.Magnet {
transfer.Fastresume.SavePath += transfer.Opts.PathSeparator
if string(transfer.Fastresume.SavePath[len(transfer.Fastresume.SavePath)-1]) != transfer.Opts.PathSeparator {
transfer.Fastresume.SavePath += transfer.Opts.PathSeparator
}
}
}

Expand Down
51 changes: 51 additions & 0 deletions internal/transfer/transfer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,57 @@ func TestTransferStructure_HandleSavePaths(t *testing.T) {
},
},
},
{
name: "026 Test torrent with signle file torrent and savepath in rootdirectory",
newTransferStructure: &TransferStructure{
Fastresume: &qBittorrentStructures.QBittorrentFastresume{},
ResumeItem: &utorrentStructs.ResumeItem{
Path: `D:\test.txt`,
},
TorrentFile: &torrentStructures.Torrent{
Info: &torrentStructures.TorrentInfo{
Name: "test.txt",
},
},
Opts: &options.Opts{PathSeparator: `\`},
},
expected: &TransferStructure{
Fastresume: &qBittorrentStructures.QBittorrentFastresume{
QbtSavePath: `D:/`,
SavePath: `D:\`,
QBtContentLayout: "Original",
},
},
},
{
name: "027 Test torrent with signle file torrent and savepath in rootdirectory",
newTransferStructure: &TransferStructure{
Fastresume: &qBittorrentStructures.QBittorrentFastresume{},
ResumeItem: &utorrentStructs.ResumeItem{
Path: `D:\test_torrent`,
},
TorrentFile: &torrentStructures.Torrent{
Info: &torrentStructures.TorrentInfo{
Name: "test_torrent",
Files: []*torrentStructures.TorrentFile{
&torrentStructures.TorrentFile{Path: []string{"dir1", "file1.txt"}},
&torrentStructures.TorrentFile{Path: []string{"dir2", "file2.txt"}},
&torrentStructures.TorrentFile{Path: []string{"file0.txt"}},
&torrentStructures.TorrentFile{Path: []string{"file1.txt"}},
&torrentStructures.TorrentFile{Path: []string{"file2.txt"}},
},
},
},
Opts: &options.Opts{PathSeparator: `\`},
},
expected: &TransferStructure{
Fastresume: &qBittorrentStructures.QBittorrentFastresume{
QbtSavePath: `D:/`,
SavePath: `D:\`,
QBtContentLayout: "Original",
},
},
},
}
for _, testCase := range cases {
t.Run(testCase.name, func(t *testing.T) {
Expand Down

0 comments on commit 44c038b

Please sign in to comment.