linstrom/shared/isWritable_windows.go
2025-04-14 16:59:59 +02:00

26 lines
605 B
Go

package shared
import "os"
// Copied from https://stackoverflow.com/a/20026945 and https://stackoverflow.com/a/49148866
// Not testable as host environment could be just about anything
// and this function is for testing the host environment.
// Also, Windows is not supported. It may work, it may not, doesn't matter
func IsWritable(path string) bool {
info, err := os.Stat(path)
if err != nil {
return false
}
err = nil
if !info.IsDir() {
return false
}
// Check if the user bit is enabled in file permission
if info.Mode().Perm()&(1<<(uint(7))) == 0 {
return false
}
return true
}