summaryrefslogtreecommitdiff
path: root/fs.go
diff options
context:
space:
mode:
authorMarin Ivanov <[email protected]>2022-08-14 23:29:21 +0300
committerMarin Ivanov <[email protected]>2022-08-14 23:29:21 +0300
commit7a71f66504bdfd20cb82e4af064bf618c0b8961b (patch)
treeea4f854716d764f95e3120e73a9d4b708e7ba003 /fs.go
parent97848bf3f97005a43bf53ae96617e3d38a15b8f7 (diff)
Add Remove(), RemoveAll(), Rename() operations
Diffstat (limited to 'fs.go')
-rw-r--r--fs.go40
1 files changed, 37 insertions, 3 deletions
diff --git a/fs.go b/fs.go
index 9f5af23..a4a1831 100644
--- a/fs.go
+++ b/fs.go
@@ -6,6 +6,7 @@ import (
"fmt"
neturl "net/url"
"os"
+ "strings"
"time"
"github.com/minio/minio-go/v7"
@@ -102,18 +103,51 @@ func (fs *Fs) OpenFile(name string, flag int, perm os.FileMode) (File, error) {
// Remove removes a file identified by name, returning an error, if any
// happens.
func (fs *Fs) Remove(name string) error {
- panic("not implemented")
+ ctx, cancel := fs.contextWithTimeout()
+ defer cancel()
+ err := fs.client.RemoveObject(ctx, fs.bucket, name, minio.RemoveObjectOptions{})
+ if err != nil {
+ return transformError(err)
+ }
+ return nil
}
// RemoveAll removes a directory path and any children it contains. It
// does not fail if the path does not exist (return nil).
func (fs *Fs) RemoveAll(path string) error {
- panic("not implemented")
+ ctx, cancel := fs.contextWithTimeout()
+ defer cancel()
+
+ if !strings.HasSuffix(path, "/") {
+ path += "/"
+ }
+ objectsCh := fs.client.ListObjects(ctx, fs.bucket, minio.ListObjectsOptions{Prefix: path})
+ errc := fs.client.RemoveObjects(ctx, fs.bucket, objectsCh, minio.RemoveObjectsOptions{})
+ for err := range errc {
+ if err.Err != nil {
+ return transformError(err.Err)
+ }
+ }
+ return nil
}
// Rename renames a file.
func (fs *Fs) Rename(oldname, newname string) error {
- panic("not implemented")
+ ctx, cancel := fs.contextWithTimeout()
+ defer cancel()
+
+ _, err := fs.client.CopyObject(ctx,
+ minio.CopyDestOptions{Bucket: fs.bucket, Object: newname},
+ minio.CopySrcOptions{Bucket: fs.bucket, Object: oldname})
+ if err != nil {
+ return transformError(err)
+ }
+ err = fs.client.RemoveObject(ctx, fs.bucket, oldname, minio.RemoveObjectOptions{})
+ if err != nil {
+ return transformError(err)
+ }
+
+ return nil
}
// Stat returns a FileInfo describing the named file, or an error, if any