Skip to content

Commit

Permalink
testing windows build
Browse files Browse the repository at this point in the history
  • Loading branch information
warrensbox committed Jul 13, 2021
1 parent 5f2d1b9 commit 916c9a7
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 5 deletions.
12 changes: 12 additions & 0 deletions lib/dir_perm.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// +build !windows

package lib

import "golang.org/x/sys/unix"

//Check if user has permission to directory :
//dir=path to file
//return bool
func CheckDirWritable(dir string) bool {
return unix.Access(dir, unix.W_OK) == nil
}
29 changes: 29 additions & 0 deletions lib/dir_perm_windows.go
Original file line number Diff line number Diff line change
@@ -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
}
8 changes: 3 additions & 5 deletions lib/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import (
"os"
"path/filepath"
"strings"

"golang.org/x/sys/unix"
)

// RenameFile : rename file name
Expand Down Expand Up @@ -228,9 +226,9 @@ func GetFileName(configfile string) string {
//Check if user has permission to directory :
//dir=path to file
//return bool
func CheckDirWritable(dir string) bool {
return unix.Access(dir, unix.W_OK) == nil
}
// func CheckDirWritable(dir string) bool {
// return unix.Access(dir, unix.W_OK) == nil
// }

// func WindowsCheckDirWritable(path string) bool {

Expand Down

0 comments on commit 916c9a7

Please sign in to comment.