|
|
@ -17,6 +17,7 @@ |
|
|
|
package fs |
|
|
|
package fs |
|
|
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
import ( |
|
|
|
|
|
|
|
"errors" |
|
|
|
"os" |
|
|
|
"os" |
|
|
|
"runtime" |
|
|
|
"runtime" |
|
|
|
"strings" |
|
|
|
"strings" |
|
|
@ -93,13 +94,20 @@ func (fs API) DeleteBucket(bucket string) *probe.Error { |
|
|
|
if _, err := os.Stat(bucketDir); os.IsNotExist(err) { |
|
|
|
if _, err := os.Stat(bucketDir); os.IsNotExist(err) { |
|
|
|
return probe.NewError(BucketNotFound{Bucket: bucket}) |
|
|
|
return probe.NewError(BucketNotFound{Bucket: bucket}) |
|
|
|
} |
|
|
|
} |
|
|
|
files, err := ioutil.ReadDir(bucketDir) |
|
|
|
var errNotEmpty = errors.New("Directory Not empty") |
|
|
|
if err != nil { |
|
|
|
isDirNotEmpty := func(fp string, fl os.FileInfo, err error) error { |
|
|
|
return probe.NewError(err) |
|
|
|
if fl.Mode().IsRegular() || fl.Mode()&os.ModeSymlink == os.ModeSymlink { |
|
|
|
|
|
|
|
return errNotEmpty |
|
|
|
} |
|
|
|
} |
|
|
|
if len(files) > 0 { |
|
|
|
return ErrSkipDir |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
err := WalkUnsorted(bucketDir, isDirNotEmpty) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
if err == errNotEmpty { |
|
|
|
return probe.NewError(BucketNotEmpty{Bucket: bucket}) |
|
|
|
return probe.NewError(BucketNotEmpty{Bucket: bucket}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return probe.NewError(err) |
|
|
|
|
|
|
|
} |
|
|
|
if err := os.Remove(bucketDir); err != nil { |
|
|
|
if err := os.Remove(bucketDir); err != nil { |
|
|
|
return probe.NewError(err) |
|
|
|
return probe.NewError(err) |
|
|
|
} |
|
|
|
} |
|
|
@ -128,7 +136,6 @@ func (fs API) ListBuckets() ([]BucketMetadata, *probe.Error) { |
|
|
|
continue |
|
|
|
continue |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
metadata := BucketMetadata{ |
|
|
|
metadata := BucketMetadata{ |
|
|
|
Name: file.Name(), |
|
|
|
Name: file.Name(), |
|
|
|
Created: file.ModTime(), |
|
|
|
Created: file.ModTime(), |
|
|
@ -263,8 +270,44 @@ func (fs API) ListObjects(bucket string, resources BucketResourcesMetadata) ([]O |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// If delimiter is supplied make sure that paging doesn't go deep, treat it as simple directory listing.
|
|
|
|
// if delimiter is supplied and not prefix then we are the very top level, list everything and move on.
|
|
|
|
if resources.Delimiter != "" { |
|
|
|
if resources.Delimiter != "" && resources.Prefix == "" { |
|
|
|
|
|
|
|
files, err := ioutil.ReadDir(rootPrefix) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
if os.IsNotExist(err) { |
|
|
|
|
|
|
|
return nil, resources, probe.NewError(BucketNotFound{Bucket: bucket}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return nil, resources, probe.NewError(err) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
for _, fl := range files { |
|
|
|
|
|
|
|
p.files = append(p.files, contentInfo{ |
|
|
|
|
|
|
|
Prefix: fl.Name(), |
|
|
|
|
|
|
|
Size: fl.Size(), |
|
|
|
|
|
|
|
Mode: fl.Mode(), |
|
|
|
|
|
|
|
ModTime: fl.ModTime(), |
|
|
|
|
|
|
|
FileInfo: fl, |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// If delimiter and prefix is supplied make sure that paging doesn't go deep, treat it as simple directory listing.
|
|
|
|
|
|
|
|
if resources.Delimiter != "" && resources.Prefix != "" { |
|
|
|
|
|
|
|
if !strings.HasSuffix(resources.Prefix, resources.Delimiter) { |
|
|
|
|
|
|
|
fl, err := os.Stat(filepath.Join(rootPrefix, resources.Prefix)) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
if os.IsNotExist(err) { |
|
|
|
|
|
|
|
return nil, resources, probe.NewError(ObjectNotFound{Bucket: bucket, Object: resources.Prefix}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return nil, resources, probe.NewError(err) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
p.files = append(p.files, contentInfo{ |
|
|
|
|
|
|
|
Prefix: resources.Prefix, |
|
|
|
|
|
|
|
Size: fl.Size(), |
|
|
|
|
|
|
|
Mode: os.ModeDir, |
|
|
|
|
|
|
|
ModTime: fl.ModTime(), |
|
|
|
|
|
|
|
FileInfo: fl, |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} else { |
|
|
|
files, err := ioutil.ReadDir(filepath.Join(rootPrefix, resources.Prefix)) |
|
|
|
files, err := ioutil.ReadDir(filepath.Join(rootPrefix, resources.Prefix)) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
if os.IsNotExist(err) { |
|
|
|
if os.IsNotExist(err) { |
|
|
@ -285,7 +328,9 @@ func (fs API) ListObjects(bucket string, resources BucketResourcesMetadata) ([]O |
|
|
|
FileInfo: fl, |
|
|
|
FileInfo: fl, |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if resources.Delimiter == "" { |
|
|
|
var files []contentInfo |
|
|
|
var files []contentInfo |
|
|
|
getAllFiles := func(fp string, fl os.FileInfo, err error) error { |
|
|
|
getAllFiles := func(fp string, fl os.FileInfo, err error) error { |
|
|
|
// If any error return back quickly
|
|
|
|
// If any error return back quickly
|
|
|
|