From 46b7b8bc417a84c8e941efb12685dd5fab7e6a04 Mon Sep 17 00:00:00 2001 From: "warren.veerasingam@gmail.com" Date: Mon, 15 Nov 2021 00:29:37 -0600 Subject: [PATCH] windows check writable dir --- lib/dir_perm_windows.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 lib/dir_perm_windows.go diff --git a/lib/dir_perm_windows.go b/lib/dir_perm_windows.go new file mode 100644 index 0000000..56a6be2 --- /dev/null +++ b/lib/dir_perm_windows.go @@ -0,0 +1,29 @@ +package lib + +import ( + "fmt" + "os" +) + +func CheckDirWritable(path string) bool { + + info, err := os.Stat(path) + if err != nil { + fmt.Println("Path doesn't exist") + return false + } + + err = nil + if !info.IsDir() { + fmt.Println("Path isn't a directory") + return false + } + + // Check if the user bit is enabled in file permission + if info.Mode().Perm()&(1<<(uint(7))) == 0 { + fmt.Println("Write permission bit is not set on this file for user") + return false + } + + return true +}