From 3af0902f28a711003f58b32809c3bf2739425f77 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Fri, 22 Apr 2016 00:50:02 -0700 Subject: [PATCH] fs: Ignore file in recursive as well. --- client-fs.go | 5 +++++ client-fs_test.go | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/client-fs.go b/client-fs.go index b002ca1f..7a3efe5c 100644 --- a/client-fs.go +++ b/client-fs.go @@ -623,6 +623,11 @@ func (f *fsClient) listRecursiveInRoutine(contentCh chan *clientContent, incompl return nil } + // Ignore files from ignore list. + if isIgnoredFile(fi.Name()) { + return nil + } + /// In following situations we need to handle listing properly. // - When filepath is '/usr' and prefix is '/usr/bi' // - When filepath is '/usr/bin/subdir' and prefix is '/usr/bi' diff --git a/client-fs_test.go b/client-fs_test.go index b273dfb8..c4a27912 100644 --- a/client-fs_test.go +++ b/client-fs_test.go @@ -128,6 +128,51 @@ func (s *TestSuite) TestList(c *C) { } c.Assert(regularDirs, Equals, 0) c.Assert(regularFiles, Equals, 3) + + // Create an ignored file and list to verify if its ignored. + objectPath = filepath.Join(root, "test1/.DS_Store") + fsClient, err = fsNew(objectPath) + + reader = bytes.NewReader([]byte(data)) + n, err = fsClient.Put(reader, int64(len(data)), "application/octet-stream", nil) + c.Assert(err, IsNil) + c.Assert(n, Equals, int64(len(data))) + + fsClient, err = fsNew(root) + c.Assert(err, IsNil) + + contents = nil + // List recursively all files and verify. + for content := range fsClient.List(true, false) { + if content.Err != nil { + err = content.Err + break + } + contents = append(contents, content) + } + + c.Assert(err, IsNil) + switch runtime.GOOS { + case "darwin": + c.Assert(len(contents), Equals, 3) + default: + c.Assert(len(contents), Equals, 4) + } + + regularFiles = 0 + // Test number of expected files. + for _, content := range contents { + if content.Type.IsRegular() { + regularFiles++ + continue + } + } + switch runtime.GOOS { + case "darwin": + c.Assert(regularFiles, Equals, 3) + default: + c.Assert(regularFiles, Equals, 4) + } } // Test put bucket aka 'mkdir()' operation.