From 988b9a3a191590e00e296779d214312545410664 Mon Sep 17 00:00:00 2001 From: Uri Simchoni Date: Mon, 24 Jun 2019 22:05:19 +0300 Subject: [PATCH] local: only walk the subdirectory designated by prefix When listing items using the local-file-system driver, only traverse the subdirectory with longest prefix that contains the given listing prefix. Three cases are of interest: a. The listing prefix is foo/bar/ - we walk subdirectory foo/bar under the container's path. b. The listing prefix is foo/ba - we walk subdirectory foo under the container's path, and filter stuff that doesn't begin with foo/ba. c. The prefix is an empty string - walk the container's path like today. --- local/container.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/local/container.go b/local/container.go index 6b11feef..47214829 100644 --- a/local/container.go +++ b/local/container.go @@ -79,7 +79,11 @@ func (c *container) Put(name string, r io.Reader, size int64, metadata map[strin func (c *container) Items(prefix, cursor string, count int) ([]stow.Item, string, error) { prefix = filepath.FromSlash(prefix) - files, err := flatdirs(c.path) + walkBase := c.path + if prefix != "" { + walkBase = filepath.Dir(filepath.Join(c.path, prefix)) + } + files, err := flatdirs(walkBase) if err != nil { return nil, "", err }