Merge pull request #17 from rumanzo/mappedfilesreplace

Replace MappedFiles separators if defined
This commit is contained in:
Alexey Kostin 2020-07-05 22:51:35 +03:00 committed by GitHub
commit 885c0ff94c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 5 deletions

View File

@ -278,7 +278,6 @@ func main() {
flags.QBitDir = usr.HomeDir + sep + "Library" + sep + "Application Support" + sep + "QBittorrent" + sep + "BT_backup" + sep
}
_, err := goflags.Parse(&flags)
if _, err := goflags.Parse(&flags); err != nil { // https://godoc.org/github.com/jessevdk/go-flags#ErrorType
if flagsErr, ok := err.(*goflags.Error); ok && flagsErr.Type == goflags.ErrHelp {
os.Exit(0)

View File

@ -273,15 +273,22 @@ func (newstructure *NewTorrentStructure) FillSavePaths() {
for _, pattern := range newstructure.Replace {
newstructure.QbtSavePath = strings.ReplaceAll(newstructure.QbtSavePath, pattern.From, pattern.To)
}
var oldsep string
switch newstructure.Separator {
case "\\":
newstructure.QbtSavePath = strings.ReplaceAll(newstructure.QbtSavePath, "/", newstructure.Separator)
oldsep = "/"
case "/":
newstructure.QbtSavePath = strings.ReplaceAll(newstructure.QbtSavePath, "\\", newstructure.Separator)
oldsep = "\\"
}
newstructure.QbtSavePath = strings.ReplaceAll(newstructure.QbtSavePath, oldsep, newstructure.Separator)
newstructure.SavePath = strings.ReplaceAll(newstructure.QbtSavePath, "\\", "/")
for num, entry := range newstructure.MappedFiles {
newentry := strings.ReplaceAll(entry, oldsep, newstructure.Separator)
if entry != newentry {
newstructure.MappedFiles[num] = newentry
}
}
}
func fmtime(path string) (mtime int64) {