Skip to content

Commit

Permalink
internal/backend/fs: check errors on filepath.Walk
Browse files Browse the repository at this point in the history
Also enable the filesystem backend in the bucket deletion tests.

Closes #1034.
  • Loading branch information
fsouza committed Jan 9, 2023
1 parent 34afa14 commit c6b5350
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
6 changes: 3 additions & 3 deletions fakestorage/bucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func TestServerClientBucketAttrsAfterCreateBucket(t *testing.T) {
func TestServerClientDeleteBucket(t *testing.T) {
t.Run("it deletes empty buckets", func(t *testing.T) {
const bucketName = "bucket-to-delete"
runServersTest(t, runServersOptions{}, func(t *testing.T, server *Server) {
runServersTest(t, runServersOptions{enableFSBackend: true}, func(t *testing.T, server *Server) {
server.CreateBucketWithOpts(CreateBucketOpts{Name: bucketName})
client := server.Client()
err := client.Bucket(bucketName).Delete(context.Background())
Expand All @@ -117,7 +117,7 @@ func TestServerClientDeleteBucket(t *testing.T) {
t.Run("it returns an error for non-empty buckets", func(t *testing.T) {
const bucketName = "non-empty-bucket"
objs := []Object{{ObjectAttrs: ObjectAttrs{BucketName: bucketName, Name: "static/js/app.js"}}}
runServersTest(t, runServersOptions{objs: objs}, func(t *testing.T, server *Server) {
runServersTest(t, runServersOptions{objs: objs, enableFSBackend: true}, func(t *testing.T, server *Server) {
client := server.Client()
err := client.Bucket(bucketName).Delete(context.Background())
if err == nil {
Expand All @@ -128,7 +128,7 @@ func TestServerClientDeleteBucket(t *testing.T) {

t.Run("it returns an error for unknown buckets", func(t *testing.T) {
const bucketName = "non-existent-bucket"
runServersTest(t, runServersOptions{}, func(t *testing.T, server *Server) {
runServersTest(t, runServersOptions{enableFSBackend: true}, func(t *testing.T, server *Server) {
client := server.Client()
err := client.Bucket(bucketName).Delete(context.Background())
if err == nil {
Expand Down
9 changes: 5 additions & 4 deletions internal/backend/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,12 +228,13 @@ func (s *storageFS) ListObjects(bucketName string, prefix string, versions bool)
defer s.mtx.RUnlock()

objects := []ObjectAttrs{}
// TODO: WalkDir more efficient?
bucketPath := filepath.Join(s.rootDir, url.PathEscape(bucketName))
if err := filepath.Walk(bucketPath, func(path string, info fs.FileInfo, _ error) error {
// Rel() should never return error since path always descend from bucketPath
if err := filepath.Walk(bucketPath, func(path string, info fs.FileInfo, err error) error {
if err != nil {
return err
}

objName, _ := filepath.Rel(bucketPath, path)
// TODO: should this check path?
if s.mh.isSpecialFile(info.Name()) {
return nil
}
Expand Down

0 comments on commit c6b5350

Please sign in to comment.