-
Notifications
You must be signed in to change notification settings - Fork 4
/
hide.go
63 lines (53 loc) · 1.28 KB
/
hide.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
55
56
57
58
59
60
61
62
63
package higgs
// FileHidener implements the FileHide methods
type FileHidener interface {
IsHidden() (bool, error)
Hide() error
Unhide() error
}
// FileHide object that holds higgs configs
type FileHide struct {
Path string
UnixOverwrite bool
}
// FileHideOption type that holds a FileHide option
type FileHideOption func(*FileHide)
// NewFileHide makes new FileHide instance
func NewFileHide(path string, options ...FileHideOption) *FileHide {
fh := &FileHide{
Path: path,
UnixOverwrite: false,
}
for _, option := range options {
option(fh)
}
return fh
}
// UnixOverwriteOption allows the renaming process to overwrite existing file (unix option)
func UnixOverwriteOption(value bool) FileHideOption {
return func(fh *FileHide) {
fh.UnixOverwrite = value
}
}
// IsHidden checks whether "path" is hidden or not
func IsHidden(path string) (bool, error) {
return NewFileHide(path).IsHidden()
}
// Hide makes file or directory hidden
func Hide(path string) (string, error) {
fh := NewFileHide(path)
err := fh.Hide()
if err != nil {
return "", err
}
return fh.Path, nil
}
// Unhide makes file or directory unhidden
func Unhide(path string) (string, error) {
fh := NewFileHide(path)
err := fh.Unhide()
if err != nil {
return "", err
}
return fh.Path, nil
}