This commit is contained in:
jola5
2017-01-29 12:25:38 +01:00
parent 970b1a424a
commit 4456f8da57
4 changed files with 27 additions and 22 deletions

View File

@@ -1,2 +1,23 @@
// Package utils collects various services: simple operations, compression, etc.
package utils
import (
"fmt"
"os"
"golang.org/x/sys/unix"
)
// check if directory exists and is accessible
func DirIsAccessible(filename string) error {
_, err := os.Stat(filename);
if err != nil {
if ! os.IsNotExist(err) {
return fmt.Errorf("Something went wrong, %v", err)
}
} else {
if unix.Access(filename, unix.W_OK) != nil {
return fmt.Errorf("'%s' is inaccessible, check access rights", filename)
}
}
return nil
}