summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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