Use name for directory/file initializing and removed unwanted funcion… (#1401)

…ality.

Fixes https://github.com/Azure/azure-sdk-for-cpp/issues/1163

# Pull Request Checklist

Please leverage this checklist as a reminder to address commonly occurring feedback when submitting a pull request to make sure your PR can be reviewed quickly:

See the detailed list in the [contributing guide](https://github.com/Azure/azure-sdk-for-cpp/blob/master/CONTRIBUTING.md#pull-requests).

- [x] [C++ Guidelines](https://azure.github.io/azure-sdk/cpp_introduction.html)
- [x] Doxygen docs
- [x] Unit tests
- [x] No unwanted commits/changes
- [x] Descriptive title/description
  - [x] PR is single purpose
  - [x] Related issue listed
- [x] Comments in source
- [x] No typos
- [x] Update changelog
- [x] Not work-in-progress
- [x] External references or docs updated
- [x] Self review of PR done
- [x] Any breaking changes?
This commit is contained in:
Kan Tang 2021-01-19 16:42:25 +08:00 committed by GitHub
parent c2d26ddb35
commit a726e81fa4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 74 additions and 76 deletions

View File

@ -2,6 +2,9 @@
## 12.0.0-beta.7 (Unreleased)
### Breaking Changes
- Removed `GetDirectoryClient` and `GetFileClient` from `ShareClient`. `ShareDirectoryClient` and `ShareFileClient` now initializes with the name of the resource, not path, to indicate that no path parsing is done for the API
## 12.0.0-beta.6 (2020-01-14)

View File

@ -80,22 +80,6 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
*/
ShareDirectoryClient GetRootDirectoryClient() const;
/**
* @brief Create a ShareDirectoryClient from current ShareClient
* @param directoryPath The path of the directory.
* @return ShareDirectoryClient A directory client that can be used to manage a share directory
* resource.
*/
ShareDirectoryClient GetDirectoryClient(const std::string& directoryPath) const;
/**
* @brief Create a ShareFileClient from current ShareClient
* @param filePath The path of the file.
* @return ShareFileClient A file client that can be used to manage a share file
* resource.
*/
ShareFileClient GetFileClient(const std::string& filePath) const;
/**
* @brief Creates the file share.
* @param options Optional parameters to create this file share.

View File

@ -33,7 +33,7 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
static ShareDirectoryClient CreateFromConnectionString(
const std::string& connectionString,
const std::string& shareName,
const std::string& directoryPath,
const std::string& directoryName,
const ShareClientOptions& options = ShareClientOptions());
/**
@ -67,11 +67,11 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
/**
* @brief Create a ShareDirectoryClient that's a sub directory of the current
* ShareDirectoryClient
* @param subDirectoryName The name of the subdirectory.
* @param subdirectoryName The name of the subdirectory.
* @return ShareDirectoryClient A directory client that can be used to manage a share directory
* resource.
*/
ShareDirectoryClient GetSubdirectoryClient(const std::string& subDirectoryName) const;
ShareDirectoryClient GetSubdirectoryClient(const std::string& subdirectoryName) const;
/**
* @brief Create a ShareFileClient from current ShareDirectoryClient
@ -79,7 +79,7 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
* @return ShareFileClient A file client that can be used to manage a share file
* resource.
*/
ShareFileClient GetFileClient(const std::string& filePath) const;
ShareFileClient GetFileClient(const std::string& fileName) const;
/**
* @brief Initializes a new instance of the ShareDirectoryClient class with an identical uri

View File

@ -32,7 +32,7 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
static ShareFileClient CreateFromConnectionString(
const std::string& connectionString,
const std::string& shareName,
const std::string& filePath,
const std::string& fileName,
const ShareClientOptions& options = ShareClientOptions());
/**

View File

@ -27,7 +27,7 @@ void FileShareGettingStarted()
std::cout << e.what() << std::endl;
}
ShareFileClient fileClient = shareClient.GetFileClient(fileName);
ShareFileClient fileClient = shareClient.GetRootDirectoryClient().GetFileClient(fileName);
fileClient.UploadFrom(reinterpret_cast<const uint8_t*>(fileContent.data()), fileContent.size());

View File

@ -90,21 +90,7 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
ShareDirectoryClient ShareClient::GetRootDirectoryClient() const
{
return GetDirectoryClient("");
}
ShareDirectoryClient ShareClient::GetDirectoryClient(const std::string& directoryPath) const
{
auto builder = m_shareUri;
builder.AppendPath(Storage::Details::UrlEncodePath(directoryPath));
return ShareDirectoryClient(builder, m_pipeline);
}
ShareFileClient ShareClient::GetFileClient(const std::string& filePath) const
{
auto builder = m_shareUri;
builder.AppendPath(Storage::Details::UrlEncodePath(filePath));
return ShareFileClient(builder, m_pipeline);
return ShareDirectoryClient(m_shareUri, m_pipeline);
}
ShareClient ShareClient::WithSnapshot(const std::string& snapshot) const

View File

@ -20,13 +20,13 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
ShareDirectoryClient ShareDirectoryClient::CreateFromConnectionString(
const std::string& connectionString,
const std::string& shareName,
const std::string& directoryPath,
const std::string& directoryName,
const ShareClientOptions& options)
{
auto parsedConnectionString = Azure::Storage::Details::ParseConnectionString(connectionString);
auto directoryUri = std::move(parsedConnectionString.FileServiceUrl);
directoryUri.AppendPath(Storage::Details::UrlEncodePath(shareName));
directoryUri.AppendPath(Storage::Details::UrlEncodePath(directoryPath));
directoryUri.AppendPath(Storage::Details::UrlEncodePath(directoryName));
if (parsedConnectionString.KeyCredential)
{
@ -92,17 +92,17 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
}
ShareDirectoryClient ShareDirectoryClient::GetSubdirectoryClient(
const std::string& subDirectoryName) const
const std::string& subdirectoryName) const
{
auto builder = m_shareDirectoryUri;
builder.AppendPath(Storage::Details::UrlEncodePath(subDirectoryName));
builder.AppendPath(Storage::Details::UrlEncodePath(subdirectoryName));
return ShareDirectoryClient(builder, m_pipeline);
}
ShareFileClient ShareDirectoryClient::GetFileClient(const std::string& filePath) const
ShareFileClient ShareDirectoryClient::GetFileClient(const std::string& fileName) const
{
auto builder = m_shareDirectoryUri;
builder.AppendPath(Storage::Details::UrlEncodePath(filePath));
builder.AppendPath(Storage::Details::UrlEncodePath(fileName));
return ShareFileClient(builder, m_pipeline);
}

View File

@ -23,13 +23,13 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
ShareFileClient ShareFileClient::CreateFromConnectionString(
const std::string& connectionString,
const std::string& shareName,
const std::string& filePath,
const std::string& fileName,
const ShareClientOptions& options)
{
auto parsedConnectionString = Azure::Storage::Details::ParseConnectionString(connectionString);
auto fileUri = std::move(parsedConnectionString.FileServiceUrl);
fileUri.AppendPath(Storage::Details::UrlEncodePath(shareName));
fileUri.AppendPath(Storage::Details::UrlEncodePath(filePath));
fileUri.AppendPath(Storage::Details::UrlEncodePath(fileName));
if (parsedConnectionString.KeyCredential)
{

View File

@ -345,7 +345,8 @@ namespace Azure { namespace Storage { namespace Test {
{
std::string directoryName = baseName + RandomString();
auto directoryClient = m_shareClient->GetDirectoryClient(directoryName);
auto directoryClient
= m_shareClient->GetRootDirectoryClient().GetSubdirectoryClient(directoryName);
EXPECT_NO_THROW(directoryClient.Create());
auto directoryUrl = directoryClient.GetUri();
EXPECT_EQ(
@ -354,7 +355,7 @@ namespace Azure { namespace Storage { namespace Test {
}
{
std::string fileName = baseName + RandomString();
auto fileClient = m_shareClient->GetFileClient(fileName);
auto fileClient = m_shareClient->GetRootDirectoryClient().GetFileClient(fileName);
EXPECT_NO_THROW(fileClient.Create(1024));
auto fileUrl = fileClient.GetUri();
EXPECT_EQ(fileUrl, m_shareClient->GetUri() + "/" + Storage::Details::UrlEncodePath(fileName));

View File

@ -21,7 +21,7 @@ namespace Azure { namespace Storage { namespace Test {
StandardStorageConnectionString(), m_shareName));
m_shareClient->Create();
m_fileShareDirectoryClient = std::make_shared<Files::Shares::ShareDirectoryClient>(
m_shareClient->GetDirectoryClient(m_directoryName));
m_shareClient->GetRootDirectoryClient().GetSubdirectoryClient(m_directoryName));
m_fileShareDirectoryClient->Create();
}
@ -57,7 +57,8 @@ namespace Azure { namespace Storage { namespace Test {
{
options.Prefix = prefix;
}
auto directoryClient = m_shareClient->GetDirectoryClient(directoryPath);
auto directoryClient
= m_shareClient->GetRootDirectoryClient().GetSubdirectoryClient(directoryPath);
do
{
auto response = directoryClient.ListFilesAndDirectoriesSinglePage(options);
@ -81,7 +82,8 @@ namespace Azure { namespace Storage { namespace Test {
for (int32_t i = 0; i < 5; ++i)
{
auto name = RandomString(10);
Files::Shares::ShareDirectoryClient client = m_shareClient->GetDirectoryClient(name);
Files::Shares::ShareDirectoryClient client
= m_shareClient->GetRootDirectoryClient().GetSubdirectoryClient(name);
EXPECT_NO_THROW(client.Create());
directoryClients.emplace_back(std::move(client));
}
@ -96,7 +98,8 @@ namespace Azure { namespace Storage { namespace Test {
for (int32_t i = 0; i < 5; ++i)
{
auto name = RandomString(10);
Files::Shares::ShareDirectoryClient client = m_shareClient->GetDirectoryClient(name);
Files::Shares::ShareDirectoryClient client
= m_shareClient->GetRootDirectoryClient().GetSubdirectoryClient(name);
EXPECT_NO_THROW(client.Create());
EXPECT_THROW(client.Create(), StorageException);
}
@ -170,8 +173,10 @@ namespace Azure { namespace Storage { namespace Test {
{
// Create directory with metadata works
auto client1 = m_shareClient->GetDirectoryClient(LowercaseRandomString());
auto client2 = m_shareClient->GetDirectoryClient(LowercaseRandomString());
auto client1
= m_shareClient->GetRootDirectoryClient().GetSubdirectoryClient(LowercaseRandomString());
auto client2
= m_shareClient->GetRootDirectoryClient().GetSubdirectoryClient(LowercaseRandomString());
Files::Shares::CreateShareDirectoryOptions options1;
Files::Shares::CreateShareDirectoryOptions options2;
options1.Metadata = metadata1;
@ -194,8 +199,10 @@ namespace Azure { namespace Storage { namespace Test {
{
// Create directory with permission/permission key works
auto client1 = m_shareClient->GetDirectoryClient(LowercaseRandomString());
auto client2 = m_shareClient->GetDirectoryClient(LowercaseRandomString());
auto client1
= m_shareClient->GetRootDirectoryClient().GetSubdirectoryClient(LowercaseRandomString());
auto client2
= m_shareClient->GetRootDirectoryClient().GetSubdirectoryClient(LowercaseRandomString());
Files::Shares::CreateShareDirectoryOptions options1;
Files::Shares::CreateShareDirectoryOptions options2;
options1.DirectoryPermission = permission;
@ -207,7 +214,8 @@ namespace Azure { namespace Storage { namespace Test {
auto result2 = client2.GetProperties()->FilePermissionKey;
EXPECT_EQ(result1, result2);
auto client3 = m_shareClient->GetDirectoryClient(LowercaseRandomString());
auto client3
= m_shareClient->GetRootDirectoryClient().GetSubdirectoryClient(LowercaseRandomString());
Files::Shares::CreateShareDirectoryOptions options3;
options3.SmbProperties.PermissionKey = result1;
EXPECT_NO_THROW(client3.Create(options3));
@ -223,8 +231,10 @@ namespace Azure { namespace Storage { namespace Test {
properties.CreatedOn = std::chrono::system_clock::now();
properties.LastWrittenOn = std::chrono::system_clock::now();
properties.PermissionKey = "";
auto client1 = m_shareClient->GetDirectoryClient(LowercaseRandomString());
auto client2 = m_shareClient->GetDirectoryClient(LowercaseRandomString());
auto client1
= m_shareClient->GetRootDirectoryClient().GetSubdirectoryClient(LowercaseRandomString());
auto client2
= m_shareClient->GetRootDirectoryClient().GetSubdirectoryClient(LowercaseRandomString());
EXPECT_NO_THROW(client1.Create());
EXPECT_NO_THROW(client2.Create());
@ -238,7 +248,8 @@ namespace Azure { namespace Storage { namespace Test {
auto result2 = client2.GetProperties()->FilePermissionKey;
EXPECT_EQ(result1, result2);
auto client3 = m_shareClient->GetDirectoryClient(LowercaseRandomString());
auto client3
= m_shareClient->GetRootDirectoryClient().GetSubdirectoryClient(LowercaseRandomString());
Files::Shares::CreateShareDirectoryOptions options3;
options3.SmbProperties.PermissionKey = result1;
std::string permissionKey;
@ -258,8 +269,10 @@ namespace Azure { namespace Storage { namespace Test {
properties.PermissionKey = m_fileShareDirectoryClient->GetProperties()->FilePermissionKey;
{
// Create directory with SmbProperties works
auto client1 = m_shareClient->GetDirectoryClient(LowercaseRandomString());
auto client2 = m_shareClient->GetDirectoryClient(LowercaseRandomString());
auto client1
= m_shareClient->GetRootDirectoryClient().GetSubdirectoryClient(LowercaseRandomString());
auto client2
= m_shareClient->GetRootDirectoryClient().GetSubdirectoryClient(LowercaseRandomString());
Files::Shares::CreateShareDirectoryOptions options1;
Files::Shares::CreateShareDirectoryOptions options2;
options1.SmbProperties = properties;
@ -276,8 +289,10 @@ namespace Azure { namespace Storage { namespace Test {
{
// SetProperties works
auto client1 = m_shareClient->GetDirectoryClient(LowercaseRandomString());
auto client2 = m_shareClient->GetDirectoryClient(LowercaseRandomString());
auto client1
= m_shareClient->GetRootDirectoryClient().GetSubdirectoryClient(LowercaseRandomString());
auto client2
= m_shareClient->GetRootDirectoryClient().GetSubdirectoryClient(LowercaseRandomString());
EXPECT_NO_THROW(client1.Create());
EXPECT_NO_THROW(client2.Create());
@ -300,9 +315,9 @@ namespace Azure { namespace Storage { namespace Test {
std::vector<std::string> directoryNameSetB;
std::vector<std::string> fileNameSetA;
std::vector<std::string> fileNameSetB;
auto clientA = m_shareClient->GetDirectoryClient(directoryNameA);
auto clientA = m_shareClient->GetRootDirectoryClient().GetSubdirectoryClient(directoryNameA);
clientA.Create();
auto clientB = m_shareClient->GetDirectoryClient(directoryNameB);
auto clientB = m_shareClient->GetRootDirectoryClient().GetSubdirectoryClient(directoryNameB);
clientB.Create();
for (size_t i = 0; i < 5; ++i)
{
@ -399,7 +414,8 @@ namespace Azure { namespace Storage { namespace Test {
// List max result
Files::Shares::ListFilesAndDirectoriesSinglePageOptions options;
options.PageSizeHint = 2;
auto directoryNameAClient = m_shareClient->GetDirectoryClient(directoryNameA);
auto directoryNameAClient
= m_shareClient->GetRootDirectoryClient().GetSubdirectoryClient(directoryNameA);
auto response = directoryNameAClient.ListFilesAndDirectoriesSinglePage(options);
EXPECT_LE(2U, response->DirectoryItems.size() + response->FileItems.size());
}

View File

@ -27,7 +27,7 @@ namespace Azure { namespace Storage { namespace Test {
StandardStorageConnectionString(), m_shareName));
m_shareClient->Create();
m_fileShareDirectoryClient = std::make_shared<Files::Shares::ShareDirectoryClient>(
m_shareClient->GetDirectoryClient(m_directoryName));
m_shareClient->GetRootDirectoryClient().GetSubdirectoryClient(m_directoryName));
m_fileShareDirectoryClient->Create();
m_fileClient = std::make_shared<Files::Shares::ShareFileClient>(
m_fileShareDirectoryClient->GetFileClient(m_fileName));
@ -580,7 +580,8 @@ namespace Azure { namespace Storage { namespace Test {
auto memBodyStream = Core::Http::MemoryBodyStream(rangeContent);
{
// Simple upload/download.
auto fileClient = m_shareClient->GetFileClient(LowercaseRandomString(10));
auto fileClient
= m_shareClient->GetRootDirectoryClient().GetFileClient(LowercaseRandomString(10));
fileClient.Create(static_cast<int64_t>(numOfChunks) * rangeSize);
for (int32_t i = 0; i < numOfChunks; ++i)
{
@ -608,7 +609,8 @@ namespace Azure { namespace Storage { namespace Test {
memBodyStream.Rewind();
auto md5 = Md5::Hash(rangeContent.data(), rangeContent.size());
auto invalidMd5 = Md5::Hash(std::string("This is garbage."));
auto fileClient = m_shareClient->GetFileClient(LowercaseRandomString(10));
auto fileClient
= m_shareClient->GetRootDirectoryClient().GetFileClient(LowercaseRandomString(10));
Files::Shares::UploadShareFileRangeOptions uploadOptions;
fileClient.Create(static_cast<int64_t>(numOfChunks) * rangeSize);
ContentHash hash;
@ -630,10 +632,12 @@ namespace Azure { namespace Storage { namespace Test {
auto memBodyStream = Core::Http::MemoryBodyStream(fileContent);
{
// Simple copy works.
auto fileClient = m_shareClient->GetFileClient(LowercaseRandomString(10));
auto fileClient
= m_shareClient->GetRootDirectoryClient().GetFileClient(LowercaseRandomString(10));
fileClient.Create(fileSize);
auto destFileClient = m_shareClient->GetFileClient(LowercaseRandomString(10));
auto destFileClient
= m_shareClient->GetRootDirectoryClient().GetFileClient(LowercaseRandomString(10));
Files::Shares::Models::StartCopyShareFileResult result;
EXPECT_NO_THROW(result = destFileClient.StartCopy(fileClient.GetUri()).ExtractValue());
EXPECT_EQ(Files::Shares::Models::CopyStatusType::Success, result.CopyStatus);
@ -642,10 +646,12 @@ namespace Azure { namespace Storage { namespace Test {
{
// Copy mode with override and empty permission throws error..
auto fileClient = m_shareClient->GetFileClient(LowercaseRandomString(10));
auto fileClient
= m_shareClient->GetRootDirectoryClient().GetFileClient(LowercaseRandomString(10));
fileClient.Create(fileSize);
auto destFileClient = m_shareClient->GetFileClient(LowercaseRandomString(10));
auto destFileClient
= m_shareClient->GetRootDirectoryClient().GetFileClient(LowercaseRandomString(10));
Files::Shares::StartCopyShareFileOptions copyOptions;
copyOptions.PermissionCopyMode = Files::Shares::Models::PermissionCopyModeType::Override;
EXPECT_THROW(destFileClient.StartCopy(fileClient.GetUri(), copyOptions), std::runtime_error);
@ -660,7 +666,8 @@ namespace Azure { namespace Storage { namespace Test {
auto halfContent
= std::vector<uint8_t>(fileContent.begin(), fileContent.begin() + fileSize / 2);
halfContent.resize(fileSize);
auto fileClient = m_shareClient->GetFileClient(LowercaseRandomString(10));
auto fileClient
= m_shareClient->GetRootDirectoryClient().GetFileClient(LowercaseRandomString(10));
fileClient.Create(fileSize);
EXPECT_NO_THROW(fileClient.UploadRange(0, &memBodyStream));
EXPECT_NO_THROW(fileClient.ClearRange(fileSize / 2, fileSize / 2));
@ -689,7 +696,8 @@ namespace Azure { namespace Storage { namespace Test {
auto halfContent
= std::vector<uint8_t>(fileContent.begin(), fileContent.begin() + fileSize / 2);
halfContent.resize(fileSize);
auto fileClient = m_shareClient->GetFileClient(LowercaseRandomString(10));
auto fileClient
= m_shareClient->GetRootDirectoryClient().GetFileClient(LowercaseRandomString(10));
fileClient.Create(fileSize);
EXPECT_NO_THROW(fileClient.UploadRange(0, &memBodyStream));
EXPECT_NO_THROW(fileClient.ClearRange(fileSize / 2, fileSize / 2));

View File

@ -34,7 +34,7 @@ namespace Azure { namespace Storage { namespace Test {
auto fileServiceClient0 = Files::Shares::ShareServiceClient::CreateFromConnectionString(
StandardStorageConnectionString());
auto shareClient0 = fileServiceClient0.GetShareClient(m_shareName);
auto fileClient0 = shareClient0.GetFileClient(fileName);
auto fileClient0 = shareClient0.GetRootDirectoryClient().GetFileClient(fileName);
std::string shareUri = shareClient0.GetUri();
std::string fileUri = fileClient0.GetUri();