forked from distribution/distribution
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request distribution#2702 from caervs/fix_path_enumeration
Ignore missing paths during enumeration
- Loading branch information
Showing
2 changed files
with
57 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package driver | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"testing" | ||
) | ||
|
||
type changingFileSystem struct { | ||
StorageDriver | ||
fileset []string | ||
keptFiles map[string]bool | ||
} | ||
|
||
func (cfs *changingFileSystem) List(ctx context.Context, path string) ([]string, error) { | ||
return cfs.fileset, nil | ||
} | ||
func (cfs *changingFileSystem) Stat(ctx context.Context, path string) (FileInfo, error) { | ||
kept, ok := cfs.keptFiles[path] | ||
if ok && kept { | ||
return &FileInfoInternal{ | ||
FileInfoFields: FileInfoFields{ | ||
Path: path, | ||
}, | ||
}, nil | ||
} | ||
return nil, PathNotFoundError{} | ||
} | ||
func TestWalkFileRemoved(t *testing.T) { | ||
d := &changingFileSystem{ | ||
fileset: []string{"zoidberg", "bender"}, | ||
keptFiles: map[string]bool{ | ||
"zoidberg": true, | ||
}, | ||
} | ||
infos := []FileInfo{} | ||
err := WalkFallback(context.Background(), d, "", func(fileInfo FileInfo) error { | ||
infos = append(infos, fileInfo) | ||
return nil | ||
}) | ||
if len(infos) != 1 || infos[0].Path() != "zoidberg" { | ||
t.Errorf(fmt.Sprintf("unexpected path set during walk: %s", infos)) | ||
} | ||
if err != nil { | ||
t.Fatalf(err.Error()) | ||
} | ||
} |