mirror of
https://github.com/GopeedLab/gopeed.git
synced 2026-11-08 17:40:28 +00:00
fix: defect in extension process during rename duplicate file (#1158)
This commit is contained in:
1 parent
07dc196c3c
commit
1b36ed1807
2 files changed
+23
-3
No files matched your search
+8
-3
@@ -50,12 +50,17 @@ func CheckDuplicateAndRename(path string) (string, error) {
|
||||
return "", err
|
||||
}
|
||||
|
||||
index := strings.LastIndex(name, ".")
|
||||
ext := syspath.Ext(name)
|
||||
var nameTpl string
|
||||
if index == -1 {
|
||||
// Special case: if the extension is the entire filename (like .gitignore),
|
||||
// or if index of last dot is 0 (starts with dot), treat it as no extension
|
||||
if ext == "" || ext == name || (len(ext) > 0 && strings.LastIndex(name, ".") == 0) {
|
||||
// No extension or hidden file without extension
|
||||
nameTpl = name + " (%d)"
|
||||
} else {
|
||||
nameTpl = name[:index] + " (%d)" + name[index:]
|
||||
// Has extension
|
||||
nameWithoutExt := name[:len(name)-len(ext)]
|
||||
nameTpl = nameWithoutExt + " (%d)" + ext
|
||||
}
|
||||
for i := 1; ; i++ {
|
||||
newName := fmt.Sprintf(nameTpl, i)
|
||||
|
||||
Reference in new issue
Block a user