Skip to content

Commit ad28d10

Browse files
authored
Memorize filesystemUrl in directoryClient so that ListPaths knows the correct endpoint without guessing (Azure#4923)
1 parent 59af02e commit ad28d10

File tree

5 files changed

+58
-13
lines changed

5 files changed

+58
-13
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_129d7f8039"
5+
"Tag": "cpp/storage_a5249cec25"
66
}

sdk/storage/azure-storage-files-datalake/inc/azure/storage/files/datalake/datalake_options.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,12 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake {
104104
* @brief Holds the customer provided key used when making requests.
105105
*/
106106
Azure::Nullable<EncryptionKey> CustomerProvidedKey;
107+
108+
/**
109+
* The filesystem url. This is only non-null for directory clients that are created from a
110+
* filesystem client, so that this directory client knows where to send ListPaths requests.
111+
*/
112+
Azure::Nullable<Azure::Core::Url> FileSystemUrl;
107113
};
108114
} // namespace _detail
109115

sdk/storage/azure-storage-files-datalake/src/datalake_directory_client.cpp

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -220,21 +220,40 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake {
220220
protocolLayerOptions.Recursive = recursive;
221221
protocolLayerOptions.ContinuationToken = options.ContinuationToken;
222222

223-
const std::string currentPath = m_pathUrl.GetPath();
224-
auto firstSlashPos = std::find(currentPath.begin(), currentPath.end(), '/');
225-
const std::string fileSystemName(currentPath.begin(), firstSlashPos);
226-
if (firstSlashPos != currentPath.end())
223+
Azure::Core::Url fileSystemUrl;
224+
if (m_clientConfiguration.FileSystemUrl.HasValue())
227225
{
228-
++firstSlashPos;
226+
fileSystemUrl = m_clientConfiguration.FileSystemUrl.Value();
227+
const std::string fileSystemPath = fileSystemUrl.GetPath();
228+
const std::string currentPath = m_pathUrl.GetPath();
229+
std::string directoryPath = currentPath.substr(fileSystemPath.length());
230+
if (directoryPath.length() > 0 && directoryPath[0] == '/')
231+
{
232+
directoryPath = directoryPath.substr(1);
233+
}
234+
if (!directoryPath.empty())
235+
{
236+
protocolLayerOptions.Path = directoryPath;
237+
}
229238
}
230-
const std::string directoryPath(firstSlashPos, currentPath.end());
231-
if (!directoryPath.empty())
239+
else
232240
{
233-
protocolLayerOptions.Path = directoryPath;
234-
}
241+
const std::string currentPath = m_pathUrl.GetPath();
242+
auto firstSlashPos = std::find(currentPath.begin(), currentPath.end(), '/');
243+
const std::string fileSystemName(currentPath.begin(), firstSlashPos);
244+
if (firstSlashPos != currentPath.end())
245+
{
246+
++firstSlashPos;
247+
}
248+
const std::string directoryPath(firstSlashPos, currentPath.end());
249+
if (!directoryPath.empty())
250+
{
251+
protocolLayerOptions.Path = directoryPath;
252+
}
235253

236-
auto fileSystemUrl = m_pathUrl;
237-
fileSystemUrl.SetPath(fileSystemName);
254+
fileSystemUrl = m_pathUrl;
255+
fileSystemUrl.SetPath(fileSystemName);
256+
}
238257

239258
auto response = _detail::FileSystemClient::ListPaths(
240259
*m_pipeline, fileSystemUrl, protocolLayerOptions, _internal::WithReplicaStatus(context));

sdk/storage/azure-storage-files-datalake/src/datalake_file_system_client.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,13 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake {
152152
{
153153
auto builder = m_fileSystemUrl;
154154
builder.AppendPath(_internal::UrlEncodePath(directoryName));
155-
return DataLakeDirectoryClient(
155+
auto directoryClient = DataLakeDirectoryClient(
156156
std::move(builder),
157157
m_blobContainerClient.GetBlobClient(directoryName),
158158
m_pipeline,
159159
m_clientConfiguration);
160+
directoryClient.m_clientConfiguration.FileSystemUrl = m_fileSystemUrl;
161+
return directoryClient;
160162
}
161163

162164
Azure::Response<Models::CreateFileSystemResult> DataLakeFileSystemClient::Create(

sdk/storage/azure-storage-files-datalake/test/ut/datalake_directory_client_test.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -840,6 +840,24 @@ namespace Azure { namespace Storage { namespace Test {
840840

841841
EXPECT_EQ(results, paths);
842842
}
843+
{
844+
// List without FileSystemUrl in client configuration
845+
auto directoryClient = Files::DataLake::DataLakeDirectoryClient(
846+
Files::DataLake::_detail::GetDfsUrlFromUrl(m_directoryClient->GetUrl()),
847+
_internal::ParseConnectionString(AdlsGen2ConnectionString()).KeyCredential,
848+
InitStorageClientOptions<Files::DataLake::DataLakeClientOptions>());
849+
850+
std::set<std::string> results;
851+
for (auto page = directoryClient.ListPaths(false); page.HasPage(); page.MoveToNextPage())
852+
{
853+
for (auto& path : page.Paths)
854+
{
855+
results.insert(path.Name);
856+
}
857+
}
858+
859+
EXPECT_EQ(results, rootPaths);
860+
}
843861
{
844862
// non-recursive
845863
std::set<std::string> results;

0 commit comments

Comments
 (0)