From a3a717a27b5c0828b738deac465b72aed0cc1390 Mon Sep 17 00:00:00 2001 From: Florent Clairambault Date: Fri, 11 Dec 2020 01:49:42 +0100 Subject: [PATCH] fix: Listing without limit was broken (#19) --- gdrive.go | 2 +- gdrive_test.go | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/gdrive.go b/gdrive.go index 74b238e..d8f132a 100644 --- a/gdrive.go +++ b/gdrive.go @@ -139,7 +139,7 @@ func (d *GDriver) listDirectory(f *File, count int) ([]os.FileInfo, error) { for count < 0 || len(files) < count { pageSize := int64(count - len(files)) - if pageSize > filesListPageSizeMax { + if pageSize > filesListPageSizeMax || pageSize <= 0 { pageSize = filesListPageSizeMax } diff --git a/gdrive_test.go b/gdrive_test.go index 9670acd..59b5bd5 100644 --- a/gdrive_test.go +++ b/gdrive_test.go @@ -362,8 +362,7 @@ func TestListDirectory(t *testing.T) { mustWriteFile(t, driver, "Folder1/File1") mustWriteFile(t, driver, "Folder1/File2") - // var files []*FileInfo - { + t.Run("listing 1000", func(t *testing.T) { dir, err := driver.Open("Folder1") require.NoError(t, err) @@ -379,7 +378,17 @@ func TestListDirectory(t *testing.T) { require.Equal(t, "File1", files[0].Name()) require.Equal(t, "File2", files[1].Name()) - } + }) + + t.Run("listing no limit", func(t *testing.T) { + dir, err := driver.Open("Folder1") + require.NoError(t, err) + + files, err := dir.Readdir(-1) + require.NoError(t, err) + + require.Len(t, files, 2) + }) // Partial listing t.Run("partial", func(t *testing.T) {