2023-05-13 09:17:57 +00:00
|
|
|
package fs
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
2023-05-13 11:29:25 +00:00
|
|
|
|
|
|
|
"code.dumpstack.io/tools/out-of-tree/config"
|
2023-05-13 09:17:57 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// CaseInsensitive check
|
|
|
|
func CaseInsensitive(dir string) (yes bool, err error) {
|
|
|
|
pathLowercase := filepath.Join(dir, "file")
|
|
|
|
fLowercase, err := os.Create(pathLowercase)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
defer fLowercase.Close()
|
|
|
|
defer os.Remove(pathLowercase)
|
|
|
|
|
|
|
|
pathUppercase := filepath.Join(dir, "FILE")
|
|
|
|
fUppercase, err := os.Create(pathUppercase)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
defer fUppercase.Close()
|
|
|
|
defer os.Remove(pathUppercase)
|
|
|
|
|
|
|
|
statLowercase, err := fLowercase.Stat()
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
statUppercase, err := fUppercase.Stat()
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
yes = os.SameFile(statLowercase, statUppercase)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// PathExists check
|
|
|
|
func PathExists(path string) bool {
|
|
|
|
if _, err := os.Stat(path); err != nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
2023-05-13 11:29:25 +00:00
|
|
|
|
|
|
|
// TempDir that exist relative to config directory
|
|
|
|
func TempDir() (string, error) {
|
|
|
|
return os.MkdirTemp(config.Dir("tmp"), "")
|
|
|
|
}
|