From cc679aa71441b17516f6dac7753d49d08af825e5 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Mon, 28 Jul 2014 18:04:52 +0100 Subject: [PATCH] google cloud storage: fix ListDir on subdirectory --- googlecloudstorage/googlecloudstorage.go | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/googlecloudstorage/googlecloudstorage.go b/googlecloudstorage/googlecloudstorage.go index d08fdc66d..f6cd40888 100644 --- a/googlecloudstorage/googlecloudstorage.go +++ b/googlecloudstorage/googlecloudstorage.go @@ -255,16 +255,23 @@ func (f *FsStorage) list(directories bool, fn func(string, *storage.Object)) { fs.Log(f, "Couldn't read bucket %q: %s", f.bucket, err) return } - for _, object := range objects.Items { - if directories && !strings.HasSuffix(object.Name, "/") { - continue + if !directories { + for _, object := range objects.Items { + if !strings.HasPrefix(object.Name, f.root) { + fs.Log(f, "Odd name received %q", object.Name) + continue + } + remote := object.Name[rootLength:] + fn(remote, object) } - if !strings.HasPrefix(object.Name, f.root) { - fs.Log(f, "Odd name received %q", object.Name) - continue + } else { + var object storage.Object + for _, prefix := range objects.Prefixes { + if !strings.HasSuffix(prefix, "/") { + continue + } + fn(prefix[:len(prefix)-1], &object) } - remote := object.Name[rootLength:] - fn(remote, object) } if objects.NextPageToken == "" { break