@@ -5,11 +5,13 @@ import (
5
5
"flag"
6
6
"fmt"
7
7
"io"
8
+ "path"
8
9
"sort"
9
10
"time"
10
11
11
12
"github.com/ViBiOh/fibr/pkg/provider"
12
13
"github.com/ViBiOh/httputils/v4/pkg/flags"
14
+ "github.com/ViBiOh/httputils/v4/pkg/logger"
13
15
14
16
"github.com/minio/minio-go/v7"
15
17
"github.com/minio/minio-go/v7/pkg/credentials"
@@ -77,7 +79,8 @@ func (a App) WithIgnoreFn(ignoreFn func(provider.StorageItem) bool) provider.Sto
77
79
// Info provide metadata about given pathname
78
80
func (a App ) Info (pathname string ) (provider.StorageItem , error ) {
79
81
realPathname := getPath (pathname )
80
- if len (realPathname ) == 0 {
82
+
83
+ if realPathname == "/" {
81
84
return provider.StorageItem {
82
85
Name : "/" ,
83
86
Pathname : "/" ,
@@ -90,18 +93,28 @@ func (a App) Info(pathname string) (provider.StorageItem, error) {
90
93
return provider.StorageItem {}, convertError (err )
91
94
}
92
95
93
- return convertToItem (pathname , info ), nil
96
+ return convertToItem (realPathname , info ), nil
94
97
}
95
98
96
99
// List items in the storage
97
100
func (a App ) List (pathname string ) ([]provider.StorageItem , error ) {
101
+ realPathname := getPath (pathname )
102
+
103
+ if realPathname == "/" {
104
+ realPathname = ""
105
+ }
106
+
98
107
objectsCh := a .client .ListObjects (context .Background (), a .bucket , minio.ListObjectsOptions {
99
- Prefix : getPath ( pathname ) ,
108
+ Prefix : realPathname ,
100
109
})
101
110
102
111
var items []provider.StorageItem
103
112
for object := range objectsCh {
104
- item := convertToItem (pathname , object )
113
+ item := convertToItem (realPathname , object )
114
+ if item .IsDir && item .Name == path .Base (realPathname ) {
115
+ continue
116
+ }
117
+
105
118
if a .ignoreFn != nil && a .ignoreFn (item ) {
106
119
continue
107
120
}
@@ -118,13 +131,15 @@ func (a App) List(pathname string) ([]provider.StorageItem, error) {
118
131
func (a App ) WriterTo (pathname string ) (io.WriteCloser , error ) {
119
132
reader , writer := io .Pipe ()
120
133
121
- if _ , err := a .client .PutObject (context .Background (), a .bucket , getPath (pathname ), reader , - 1 , minio.PutObjectOptions {}); err != nil {
122
- if closeErr := writer .Close (); closeErr != nil {
123
- err = fmt .Errorf ("%s: %w" , err , closeErr )
124
- }
134
+ go func () {
135
+ if _ , err := a .client .PutObject (context .Background (), a .bucket , getPath (pathname ), reader , - 1 , minio.PutObjectOptions {}); err != nil {
136
+ if closeErr := writer .Close (); closeErr != nil {
137
+ err = fmt .Errorf ("%s: %w" , err , closeErr )
138
+ }
125
139
126
- return nil , convertError (err )
127
- }
140
+ logger .Error ("unable to put object: %s" , err )
141
+ }
142
+ }()
128
143
129
144
return writer , nil
130
145
}
@@ -183,7 +198,5 @@ func (a App) Rename(oldName, newName string) error {
183
198
184
199
// Remove file or directory from storage
185
200
func (a App ) Remove (pathname string ) error {
186
- // TODO
187
-
188
- return nil
201
+ return convertError (a .client .RemoveObject (context .Background (), a .bucket , getPath (pathname ), minio.RemoveObjectOptions {}))
189
202
}
0 commit comments