Memorize filesystemUrl in directoryClient so that ListPaths knows the correct endpoint without guessing (#4923)
This commit is contained in:
parent
59af02e52a
commit
ad28d10ee0
@ -2,5 +2,5 @@
|
||||
"AssetsRepo": "Azure/azure-sdk-assets",
|
||||
"AssetsRepoPrefixPath": "cpp",
|
||||
"TagPrefix": "cpp/storage",
|
||||
"Tag": "cpp/storage_129d7f8039"
|
||||
"Tag": "cpp/storage_a5249cec25"
|
||||
}
|
||||
|
||||
@ -104,6 +104,12 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake {
|
||||
* @brief Holds the customer provided key used when making requests.
|
||||
*/
|
||||
Azure::Nullable<EncryptionKey> CustomerProvidedKey;
|
||||
|
||||
/**
|
||||
* The filesystem url. This is only non-null for directory clients that are created from a
|
||||
* filesystem client, so that this directory client knows where to send ListPaths requests.
|
||||
*/
|
||||
Azure::Nullable<Azure::Core::Url> FileSystemUrl;
|
||||
};
|
||||
} // namespace _detail
|
||||
|
||||
|
||||
@ -220,21 +220,40 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake {
|
||||
protocolLayerOptions.Recursive = recursive;
|
||||
protocolLayerOptions.ContinuationToken = options.ContinuationToken;
|
||||
|
||||
const std::string currentPath = m_pathUrl.GetPath();
|
||||
auto firstSlashPos = std::find(currentPath.begin(), currentPath.end(), '/');
|
||||
const std::string fileSystemName(currentPath.begin(), firstSlashPos);
|
||||
if (firstSlashPos != currentPath.end())
|
||||
Azure::Core::Url fileSystemUrl;
|
||||
if (m_clientConfiguration.FileSystemUrl.HasValue())
|
||||
{
|
||||
++firstSlashPos;
|
||||
fileSystemUrl = m_clientConfiguration.FileSystemUrl.Value();
|
||||
const std::string fileSystemPath = fileSystemUrl.GetPath();
|
||||
const std::string currentPath = m_pathUrl.GetPath();
|
||||
std::string directoryPath = currentPath.substr(fileSystemPath.length());
|
||||
if (directoryPath.length() > 0 && directoryPath[0] == '/')
|
||||
{
|
||||
directoryPath = directoryPath.substr(1);
|
||||
}
|
||||
if (!directoryPath.empty())
|
||||
{
|
||||
protocolLayerOptions.Path = directoryPath;
|
||||
}
|
||||
}
|
||||
const std::string directoryPath(firstSlashPos, currentPath.end());
|
||||
if (!directoryPath.empty())
|
||||
else
|
||||
{
|
||||
protocolLayerOptions.Path = directoryPath;
|
||||
}
|
||||
const std::string currentPath = m_pathUrl.GetPath();
|
||||
auto firstSlashPos = std::find(currentPath.begin(), currentPath.end(), '/');
|
||||
const std::string fileSystemName(currentPath.begin(), firstSlashPos);
|
||||
if (firstSlashPos != currentPath.end())
|
||||
{
|
||||
++firstSlashPos;
|
||||
}
|
||||
const std::string directoryPath(firstSlashPos, currentPath.end());
|
||||
if (!directoryPath.empty())
|
||||
{
|
||||
protocolLayerOptions.Path = directoryPath;
|
||||
}
|
||||
|
||||
auto fileSystemUrl = m_pathUrl;
|
||||
fileSystemUrl.SetPath(fileSystemName);
|
||||
fileSystemUrl = m_pathUrl;
|
||||
fileSystemUrl.SetPath(fileSystemName);
|
||||
}
|
||||
|
||||
auto response = _detail::FileSystemClient::ListPaths(
|
||||
*m_pipeline, fileSystemUrl, protocolLayerOptions, _internal::WithReplicaStatus(context));
|
||||
|
||||
@ -152,11 +152,13 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake {
|
||||
{
|
||||
auto builder = m_fileSystemUrl;
|
||||
builder.AppendPath(_internal::UrlEncodePath(directoryName));
|
||||
return DataLakeDirectoryClient(
|
||||
auto directoryClient = DataLakeDirectoryClient(
|
||||
std::move(builder),
|
||||
m_blobContainerClient.GetBlobClient(directoryName),
|
||||
m_pipeline,
|
||||
m_clientConfiguration);
|
||||
directoryClient.m_clientConfiguration.FileSystemUrl = m_fileSystemUrl;
|
||||
return directoryClient;
|
||||
}
|
||||
|
||||
Azure::Response<Models::CreateFileSystemResult> DataLakeFileSystemClient::Create(
|
||||
|
||||
@ -840,6 +840,24 @@ namespace Azure { namespace Storage { namespace Test {
|
||||
|
||||
EXPECT_EQ(results, paths);
|
||||
}
|
||||
{
|
||||
// List without FileSystemUrl in client configuration
|
||||
auto directoryClient = Files::DataLake::DataLakeDirectoryClient(
|
||||
Files::DataLake::_detail::GetDfsUrlFromUrl(m_directoryClient->GetUrl()),
|
||||
_internal::ParseConnectionString(AdlsGen2ConnectionString()).KeyCredential,
|
||||
InitStorageClientOptions<Files::DataLake::DataLakeClientOptions>());
|
||||
|
||||
std::set<std::string> results;
|
||||
for (auto page = directoryClient.ListPaths(false); page.HasPage(); page.MoveToNextPage())
|
||||
{
|
||||
for (auto& path : page.Paths)
|
||||
{
|
||||
results.insert(path.Name);
|
||||
}
|
||||
}
|
||||
|
||||
EXPECT_EQ(results, rootPaths);
|
||||
}
|
||||
{
|
||||
// non-recursive
|
||||
std::set<std::string> results;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user