From e2e0dad1ad725c1b51eeb1c3985b6059a32ec3f5 Mon Sep 17 00:00:00 2001 From: Mikhail Klementev Date: Thu, 11 May 2023 02:42:34 +0000 Subject: [PATCH] Check that fs is case-sensitive --- main.go | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/main.go b/main.go index 7106c85..6dcde49 100644 --- a/main.go +++ b/main.go @@ -11,6 +11,7 @@ import ( "os" "os/exec" "os/user" + "path/filepath" "runtime/debug" "strconv" "time" @@ -92,6 +93,37 @@ func (lw *LevelWriter) WriteLevel(l zerolog.Level, p []byte) (n int, err error) return len(p), nil } +func isFsCaseInsensitive(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 +} + var tempDirBase string var consoleWriter, fileWriter LevelWriter @@ -163,6 +195,15 @@ func main() { log.Debug().Msgf("%v", buildInfo.Settings) } + path := filepath.Join(usr.HomeDir, ".out-of-tree") + yes, err := isFsCaseInsensitive(path) + if err != nil { + log.Fatal().Err(err).Msg(path) + } + if yes { + log.Warn().Msg("case-insensitive file system not supported") + } + _, err = exec.LookPath(cli.ContainerRuntime) if err != nil { if cli.ContainerRuntime == "podman" { // default value