Numerous Bug Fixes
Some checks failed
Automated Container Build / build-and-push (push) Failing after 8s
Some checks failed
Automated Container Build / build-and-push (push) Failing after 8s
This commit is contained in:
parent
02eefdac0e
commit
267d429122
959 changed files with 145571 additions and 221 deletions
28
backend/handlers/utils.go
Normal file
28
backend/handlers/utils.go
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
package handlers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
// GetUniquePath checks if a file or folder exists at the given baseDir with the given name.
|
||||
// If it does, it systematically appends " (1)", " (2)", etc., until it finds an available name.
|
||||
// It returns the unique filename.
|
||||
func GetUniquePath(baseDir, name string) string {
|
||||
ext := filepath.Ext(name)
|
||||
base := name[:len(name)-len(ext)]
|
||||
|
||||
finalPath := filepath.Join(baseDir, name)
|
||||
if _, err := os.Stat(finalPath); os.IsNotExist(err) {
|
||||
return name
|
||||
}
|
||||
|
||||
for i := 1; ; i++ {
|
||||
newName := fmt.Sprintf("%s (%d)%s", base, i, ext)
|
||||
finalPath = filepath.Join(baseDir, newName)
|
||||
if _, err := os.Stat(finalPath); os.IsNotExist(err) {
|
||||
return newName
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in a new issue