Fixed doubling end slashes

This commit is contained in:
rumanzo 2022-05-05 22:00:19 +03:00
parent df880d4722
commit 44c038bd67
2 changed files with 63 additions and 6 deletions

View File

@ -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
@ -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 += `/`
}
}
}
@ -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
}
}
}

View File

@ -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) {