fix: defect in extension process during rename duplicate file (#1158)

This commit is contained in:
Little-King authored and GitHub committed 2025-11-14 18:49:21 +08:00
1 parent 07dc196c3c
commit 1b36ed1807
2 files changed
+23 -3

No files matched your search

+8 -3
View File
@@ -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)