File: fileutil.go

package info (click to toggle)
golang-github-kisom-goutils 0.0~git20161101.0.858c9cb-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 384 kB
  • ctags: 331
  • sloc: makefile: 6
file content (47 lines) | stat: -rw-r--r-- 1,022 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Package fileutil contains common file functions.
package fileutil

import (
	"os"

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

// FileDoesExist returns true if the file exists.
func FileDoesExist(path string) bool {
	_, err := os.Stat(path)
	return !os.IsNotExist(err)
}

// DirectoryDoesExist returns true if the file exists.
func DirectoryDoesExist(path string) bool {
	fi, err := os.Stat(path)
	if err != nil {
		return false
	}

	return fi.Mode().IsDir()
}

const (
	// AccessExists checks whether the file exists.
	AccessExists = unix.F_OK

	// AccessRead checks whether the user has read permissions on
	// the file.
	AccessRead = unix.R_OK

	// AccessWrite checks whether the user has write permissions
	// on the file.
	AccessWrite = unix.W_OK

	// AccessExec checks whether the user has executable
	// permissions on the file.
	AccessExec = unix.X_OK
)

// Access returns a boolean indicating whether the mode being checked
// for is valid.
func Access(path string, mode int) error {
	return unix.Access(path, uint32(mode))
}