mirror of
https://github.com/distribution/distribution.git
synced 2025-06-27 15:59:04 +00:00
avoid appending directory as file path in s3 driver Walk
when a directory is empty, the s3 api lists it with a trailing slash. this causes the path to be appended twice to the walkInfo slice, causing purge uploads path transformations to panic when the `_uploads` is emtpy. this adds a check for file paths ending on slash, and do not append those as regular files to the walkInfo slice. fixes #4358 Signed-off-by: Flavian Missi <fmissi@redhat.com>
This commit is contained in:
parent
e44d9317d0
commit
2e7482cb89
@ -1178,6 +1178,16 @@ func (d *driver) doWalk(parentCtx context.Context, objectCount *int64, from stri
|
|||||||
prevDir = dir
|
prevDir = dir
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// in some cases the _uploads dir might be empty. when this happens, it would
|
||||||
|
// be appended twice to the walkInfos slice, once as [...]/_uploads and
|
||||||
|
// once more erroneously as [...]/_uploads/. the easiest way to avoid this is
|
||||||
|
// to skip appending filePath to walkInfos if it ends in "/". the loop through
|
||||||
|
// dirs will already have handled it in that case, so it's safe to continue this
|
||||||
|
// loop.
|
||||||
|
if strings.HasSuffix(filePath, "/") {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
walkInfos = append(walkInfos, storagedriver.FileInfoInternal{
|
walkInfos = append(walkInfos, storagedriver.FileInfoInternal{
|
||||||
FileInfoFields: storagedriver.FileInfoFields{
|
FileInfoFields: storagedriver.FileInfoFields{
|
||||||
IsDir: false,
|
IsDir: false,
|
||||||
@ -1541,6 +1551,7 @@ func (w *writer) Write(p []byte) (int, error) {
|
|||||||
func (w *writer) Size() int64 {
|
func (w *writer) Size() int64 {
|
||||||
return w.size
|
return w.size
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *writer) Close() error {
|
func (w *writer) Close() error {
|
||||||
if w.closed {
|
if w.closed {
|
||||||
return fmt.Errorf("already closed")
|
return fmt.Errorf("already closed")
|
||||||
|
Loading…
Reference in New Issue
Block a user