-
Notifications
You must be signed in to change notification settings - Fork 0
/
subfilesystem.go
216 lines (168 loc) · 5.7 KB
/
subfilesystem.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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
package fs
import (
"context"
iofs "io/fs"
"path/filepath"
"strings"
"github.com/ungerik/go-fs/fsimpl"
)
// todoSubFileSystemPrefix is the URI prefix used to identify SubFileSystem files
const todoSubFileSystemPrefix = "sub://"
type todoSubFileSystem struct {
prefix string
Parent FileSystem
BasePath string
}
func todoNewSubFileSystem(parent FileSystem, basePath string) *todoSubFileSystem {
subfs := &todoSubFileSystem{
prefix: todoSubFileSystemPrefix + fsimpl.RandomString(),
Parent: parent,
BasePath: basePath,
}
Register(subfs)
return subfs
}
func (subfs *todoSubFileSystem) ReadableWritable() (readable, writable bool) {
return subfs.Parent.ReadableWritable()
}
func (subfs *todoSubFileSystem) RootDir() File {
return File(subfs.Parent.Separator())
}
func (subfs *todoSubFileSystem) ID() (string, error) {
parentID, err := subfs.Parent.ID()
if err != nil {
return "", err
}
return parentID + "/" + subfs.BasePath, nil
}
func (subfs *todoSubFileSystem) Prefix() string {
return subfs.prefix
}
func (subfs *todoSubFileSystem) Name() string {
return "Sub file system of " + subfs.Parent.Name()
}
// String implements the fmt.Stringer interface.
func (subfs *todoSubFileSystem) String() string {
return subfs.Name() + " with prefix " + subfs.Prefix()
}
///////////////////////////////////////////////////
// TODO Replace implementation with real SubFileSystem from here on:
///////////////////////////////////////////////////
func (subfs *todoSubFileSystem) JoinCleanFile(uri ...string) File {
if len(uri) == 0 {
panic("SubFileSystem uri must not be empty")
}
return File(filepath.Clean(filepath.Join(uri...)))
}
func (subfs *todoSubFileSystem) URN(filePath string) string {
return filepath.ToSlash(filePath)
}
func (subfs *todoSubFileSystem) URL(filePath string) string {
return subfs.prefix + subfs.URN(filePath)
}
func (subfs *todoSubFileSystem) CleanPathFromURI(uri string) string {
return strings.TrimPrefix(uri, subfs.prefix)
}
func (subfs *todoSubFileSystem) JoinCleanPath(uri ...string) string {
return subfs.prefix + subfs.Parent.JoinCleanPath(uri...)
}
func (subfs *todoSubFileSystem) SplitPath(filePath string) []string {
return subfs.Parent.SplitPath(filePath)
}
func (subfs *todoSubFileSystem) Separator() string {
return subfs.Parent.Separator()
}
// MatchAnyPattern returns true if name matches any of patterns,
// or if len(patterns) == 0.
// The match per pattern works like path.Match or filepath.Match
func (subfs *todoSubFileSystem) MatchAnyPattern(name string, patterns []string) (bool, error) {
return subfs.Parent.MatchAnyPattern(name, patterns)
}
func (subfs *todoSubFileSystem) SplitDirAndName(filePath string) (dir, name string) {
panic("TODO")
}
func (subfs *todoSubFileSystem) VolumeName(filePath string) string {
if fs, ok := subfs.Parent.(VolumeNameFileSystem); ok {
return fs.VolumeName(filePath)
}
return ""
}
func (subfs *todoSubFileSystem) IsAbsPath(filePath string) bool {
return subfs.Parent.IsAbsPath(filePath)
}
func (subfs *todoSubFileSystem) AbsPath(filePath string) string {
return subfs.Parent.AbsPath(filePath)
}
func (subfs *todoSubFileSystem) Stat(filePath string) (iofs.FileInfo, error) {
return subfs.Parent.Stat(filePath)
}
func (subfs *todoSubFileSystem) Exists(filePath string) bool {
if fs, ok := subfs.Parent.(ExistsFileSystem); ok {
return fs.Exists(filePath)
}
_, err := subfs.Parent.Stat(filePath)
return err != nil
}
func (subfs *todoSubFileSystem) IsHidden(filePath string) bool {
return subfs.Parent.IsHidden(filePath)
}
func (subfs *todoSubFileSystem) IsSymbolicLink(filePath string) bool {
return subfs.Parent.IsSymbolicLink(filePath)
}
func (subfs *todoSubFileSystem) ListDirInfo(ctx context.Context, dirPath string, callback func(*FileInfo) error, patterns []string) error {
panic("TODO")
}
func (subfs *todoSubFileSystem) ListDirInfoRecursive(ctx context.Context, dirPath string, callback func(*FileInfo) error, patterns []string) error {
panic("TODO")
}
func (subfs *todoSubFileSystem) ListDirMax(ctx context.Context, dirPath string, max int, patterns []string) (files []File, err error) {
panic("TODO")
}
func (subfs *todoSubFileSystem) SetPermissions(filePath string, perm Permissions) error {
panic("TODO")
}
func (subfs *todoSubFileSystem) User(filePath string) (string, error) {
panic("TODO")
}
func (subfs *todoSubFileSystem) SetUser(filePath string, user string) error {
panic("TODO")
}
func (subfs *todoSubFileSystem) Group(filePath string) (string, error) {
panic("TODO")
}
func (subfs *todoSubFileSystem) SetGroup(filePath string, group string) error {
panic("TODO")
}
func (subfs *todoSubFileSystem) Touch(filePath string, perm []Permissions) error {
panic("TODO")
}
func (subfs *todoSubFileSystem) MakeDir(filePath string, perm []Permissions) error {
panic("TODO")
}
func (subfs *todoSubFileSystem) ReadAll(ctx context.Context, filePath string) ([]byte, error) {
panic("TODO")
}
func (subfs *todoSubFileSystem) WriteAll(ctx context.Context, filePath string, data []byte, perm []Permissions) error {
panic("TODO")
}
func (subfs *todoSubFileSystem) OpenReader(filePath string) (ReadCloser, error) {
panic("TODO")
}
func (subfs *todoSubFileSystem) OpenWriter(filePath string, perm []Permissions) (WriteCloser, error) {
panic("TODO")
}
func (subfs *todoSubFileSystem) OpenAppendWriter(filePath string, perm []Permissions) (WriteCloser, error) {
panic("TODO")
}
func (subfs *todoSubFileSystem) OpenReadWriter(filePath string, perm []Permissions) (ReadWriteSeekCloser, error) {
panic("TODO")
}
func (subfs *todoSubFileSystem) Truncate(filePath string, size int64) error {
panic("TODO")
}
func (subfs *todoSubFileSystem) Remove(filePath string) error {
panic("TODO")
}
func (subfs *todoSubFileSystem) Close() error {
panic("TODO")
}