Skip to content

Commit c8693fe

Browse files
authored
fix list files and dirs bug (Azure#4826)
* fix list files and dirs bug * test case * recording
1 parent 6ad42e1 commit c8693fe

File tree

4 files changed

+42
-2
lines changed

4 files changed

+42
-2
lines changed

sdk/storage/assets.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"AssetsRepo": "Azure/azure-sdk-assets",
33
"AssetsRepoPrefixPath": "cpp",
44
"TagPrefix": "cpp/storage",
5-
"Tag": "cpp/storage_b920de0000"
5+
"Tag": "cpp/storage_02a857d53e"
66
}

sdk/storage/azure-storage-files-shares/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
### Bugs Fixed
1010

11+
- Fixed a bug where `ShareDirectoryClient::ListFilesAndDirectories` only returns the first page without ContinuationToken, even if there are more pages.
12+
1113
### Other Changes
1214

1315
## 12.6.0 (2023-07-11)

sdk/storage/azure-storage-files-shares/src/share_directory_client.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
550550
pagedResponse.m_shareDirectoryClient = std::make_shared<ShareDirectoryClient>(*this);
551551
pagedResponse.m_operationOptions = options;
552552
pagedResponse.CurrentPageToken = options.ContinuationToken.ValueOr(std::string());
553-
pagedResponse.NextPageToken = response.Value.Marker;
553+
pagedResponse.NextPageToken = response.Value.NextMarker;
554554
pagedResponse.RawResponse = std::move(response.RawResponse);
555555

556556
return pagedResponse;

sdk/storage/azure-storage-files-shares/test/ut/share_directory_client_test.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,44 @@ namespace Azure { namespace Storage { namespace Test {
577577
EXPECT_NE(smbProperties2.ChangedOn.Value(), smbProperties.ChangedOn.Value());
578578
}
579579

580+
TEST_F(FileShareDirectoryClientTest, ListFilesAndDirectoriesMultiPageTest)
581+
{
582+
auto dirClient = m_shareClient->GetRootDirectoryClient().GetSubdirectoryClient(RandomString());
583+
dirClient.Create();
584+
std::set<std::string> nameSet;
585+
for (size_t i = 0; i < 5; ++i)
586+
{
587+
auto dirname = RandomString();
588+
auto subdirClient = dirClient.GetSubdirectoryClient(dirname);
589+
subdirClient.Create();
590+
auto filename = RandomString();
591+
auto fileClient = dirClient.GetFileClient(filename);
592+
fileClient.Create(1024);
593+
nameSet.insert(dirname);
594+
nameSet.insert(filename);
595+
}
596+
597+
Files::Shares::ListFilesAndDirectoriesOptions listOptions;
598+
listOptions.PageSizeHint = 3;
599+
std::set<std::string> listedNameSet;
600+
int numPages = 0;
601+
for (auto page = dirClient.ListFilesAndDirectories(listOptions); page.HasPage();
602+
page.MoveToNextPage())
603+
{
604+
++numPages;
605+
for (const auto& i : page.Directories)
606+
{
607+
listedNameSet.insert(i.Name);
608+
}
609+
for (const auto& i : page.Files)
610+
{
611+
listedNameSet.insert(i.Name);
612+
}
613+
}
614+
EXPECT_EQ(nameSet, listedNameSet);
615+
EXPECT_GT(numPages, 1);
616+
}
617+
580618
TEST_F(FileShareDirectoryClientTest, ListFilesAndDirectoriesSinglePageTest)
581619
{
582620
// Setup

0 commit comments

Comments
 (0)