diff options
author | Quentin <quentin@deuxfleurs.fr> | 2021-08-23 20:40:03 +0200 |
---|---|---|
committer | Quentin <quentin@deuxfleurs.fr> | 2021-08-23 20:40:03 +0200 |
commit | 15e4d10fd4b35a2e70cc4fa6ad4117cd5c402cbc (patch) | |
tree | 0fe31ac79d5dbe480b1b386845b3dd8fcaa55bd4 /s3_fs.go | |
parent | 5d64be33e64eb75160b6fe37b01997de7e96237a (diff) | |
download | bagage-15e4d10fd4b35a2e70cc4fa6ad4117cd5c402cbc.tar.gz bagage-15e4d10fd4b35a2e70cc4fa6ad4117cd5c402cbc.zip |
Refactor the codebase
Diffstat (limited to 's3_fs.go')
-rw-r--r-- | s3_fs.go | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/s3_fs.go b/s3_fs.go new file mode 100644 index 0000000..ecade9f --- /dev/null +++ b/s3_fs.go @@ -0,0 +1,66 @@ +package main + +import ( + "context" + "errors" + "os" + "time" + + "github.com/minio/minio-go/v7" + "golang.org/x/net/webdav" +) + +/* + * S3FS lifetime is limited to a single request + * Conversely, Golang's abstraction has been thought to be shared between users + * Sharing an instance between users would be very dangerous (as we would need many checks between shared values) + */ +type S3FS struct { + cache map[string]*S3Stat + mc *minio.Client + ctx context.Context +} + +func NewS3FS(mc *minio.Client) S3FS { + return S3FS{ + cache: make(map[string]*S3Stat), + mc: mc, + } +} + +func (s S3FS) Mkdir(ctx context.Context, name string, perm os.FileMode) error { + s.ctx = ctx + return errors.New("Not implemented Mkdir") +} + +func (s S3FS) OpenFile(ctx context.Context, name string, flag int, perm os.FileMode) (webdav.File, error) { + s.ctx = ctx + + // If the file does not exist when opening it, we create a stub + if _, ok := s.cache[name]; !ok { + st := new(S3Stat) + st.fs = &s + st.path = NewS3Path(name) + st.path.class = OBJECT + st.obj.Key = st.path.key + st.obj.LastModified = time.Now() + s.cache[name] = st + } + + return NewS3File(&s, name) +} + +func (s S3FS) RemoveAll(ctx context.Context, name string) error { + s.ctx = ctx + return errors.New("Not implemented RemoveAll") +} + +func (s S3FS) Rename(ctx context.Context, oldName, newName string) error { + s.ctx = ctx + return errors.New("Not implemented Rename") +} + +func (s S3FS) Stat(ctx context.Context, name string) (os.FileInfo, error) { + s.ctx = ctx + return NewS3Stat(&s, name) +} |