-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnefilim-defs.go
152 lines (131 loc) Β· 3.59 KB
/
nefilim-defs.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
package nef
import (
"io/fs"
"os"
)
// π¦ pkg: nef - contains local file system abstractions for navigation.
// Since there are no standard write-able file system interfaces,
// we need to define proprietary ones here in this package.
type (
// Rel represents generic info required to create a relative file system.
// Relative just means that a file system is created with a root path and
// the operations on the file system are invoked with paths that must be
// relative to the root.
Rel struct {
Root string
Overwrite bool
}
// FSUtility utilities associated with the FS
FSUtility interface {
// Calc is the path calculator used by the FS
Calc() PathCalc
// IsRelative determines if the methods invoked on the file
// system should use paths that are relative to a root specified
// when created.
IsRelative() bool
}
// ExistsInFS contains methods that check the existence of file system items.
ExistsInFS interface {
FSUtility
// FileExists does file exist at the path specified
FileExists(name string) bool
// DirectoryExists does directory exist at the path specified
DirectoryExists(name string) bool
}
// ReadFileFS file system non streaming reader
ReadFileFS interface {
fs.FS
// Read reads file at path, from file system specified
ReadFile(name string) ([]byte, error)
}
// ReaderFS
ReaderFS interface {
fs.StatFS
fs.ReadDirFS
ExistsInFS
ReadFileFS
}
// PathAs used with Ensure to define how to ensure that a path exists
// at the location specified
PathAs struct {
Name string
Default string
Perm os.FileMode
AsFile bool
}
// MakeDirFS is a file system with a MkDirAll method.
MakeDirFS interface {
ExistsInFS
MakeDir(name string, perm os.FileMode) error
MakeDirAll(name string, perm os.FileMode) error
// Ensure makes sure that a path exists (PathAs.Name). If the path exists
// as a file then no directories need to be created and this file name
// (PathAs.Name) is returned. If the path exists as a directory, then again
// no directories are created, but the default (PathAs.Default) is returned.
//
// If the path does not exist, then 1 of 2 things can happen. If PathAs.AsFile
// is set to true, then the parent of the path is created, and file portion
// of the path is returned. When PathAs.AsFile is not set, ie the path
// provided is to be interpreted as a directory, then this directory is
// created and the default is returned.
Ensure(as PathAs) (string, error)
}
// MoveFS
MoveFS interface {
Move(from, to string) error
}
// MoverFS
MoverFS interface {
MoveFS
ExistsInFS
fs.StatFS
}
ChangeFS interface {
Change(from, to string) error
}
ChangerFS interface {
ChangeFS
ExistsInFS
fs.StatFS
}
// CopyFS
CopyFS interface {
Copy(from, to string) error
// CopyFS copies the file system fsys into the directory dir,
// creating dir if necessary.
CopyFS(dir string, fsys fs.FS) error
}
// RemoveFS
RemoveFS interface {
Remove(name string) error
RemoveAll(path string) error
}
// RenameFS
RenameFS interface {
Rename(from, to string) error
}
// WriteFileFS file system non streaming writer
WriteFileFS interface {
FSUtility
// Create creates or truncates the named file.
Create(name string) (fs.File, error)
// Write writes file at path, to file system specified
WriteFile(name string, data []byte, perm os.FileMode) error
}
// WriterFS
WriterFS interface {
ChangeFS
CopyFS
ExistsInFS
MakeDirFS
MoveFS
RemoveFS
RenameFS
WriteFileFS
}
// UniversalFS the file system that can do it all
UniversalFS interface {
ReaderFS
WriterFS
}
)