-
Notifications
You must be signed in to change notification settings - Fork 1
/
io.go
54 lines (45 loc) · 751 Bytes
/
io.go
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
48
49
50
51
52
53
54
package fsdd
import (
"os"
)
//
// DISPLAY IO
//
func out(message string) {
os.Stdout.Write([]byte(message + "\n"))
}
//
// ERROR DISPLAY IO
//
func errOut(m string) {
out("[error] " + m)
}
func errExit(m string) {
errOut(m)
os.Exit(1)
}
//
// FILE IO
//
func pathSanitizer(path string) string {
var err error
if path == "." {
path, err = os.Getwd()
if err != nil {
errExit("[pathSanitizer] [invalid current dir]")
}
}
return path
}
func verifyPath(path string) string {
var err error
_, err = os.ReadDir(path)
if err != nil {
errExit("[read root dir] [" + path + "] [" + err.Error() + "]")
}
_, err = os.Stat(path)
if err != nil {
errExit("[stat root dir] [" + path + "] [" + err.Error() + "]")
}
return path
}