Delete related changes. (#1506)

* Delete related changes.

* DeleteEmpty instead of DeleteIfEmpty

* Remove using and refine doc

* doc
This commit is contained in:
Kan Tang 2021-01-28 19:11:12 -08:00 committed by GitHub
parent a858a77ac0
commit 648a98b38e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 68 additions and 53 deletions

View File

@ -45,6 +45,8 @@
- Type for ETag was changed to `Azure::Core::ETag`.
- Type for `IfMatch` and `IfNoneMatch` was changed to `Azure::Core::ETag`.
- Renamed `ListDataLakeFileSystemsIncludeItem` to `ListDataLakeFileSystemsIncludeFlags`.
- Removed `DataLakeDirectoryClient::Delete` and `DataLakeDirectoryClient::DeleteIfExists`. Added `DataLakeDirectoryClient::DeleteEmpty`, `DataLakeDirectoryClient::DeleteEmptyIfExists`, `DataLakeDirectoryClient::DeleteRecursive` and `DataLakeDirectoryClient::DeleteRecursiveIfExists` instead.
- Removed `ContinuationToken` in `DeleteDataLakePathResult` and `DeleteDataLakeDirectoryResult`, as they will never be returned for HNS enabled accounts.
### Other Changes and Improvements

View File

@ -146,30 +146,57 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake {
= RenameDataLakeSubdirectoryOptions()) const;
/**
* @brief Deletes the directory.
* @param recursive If "true", all paths beneath the directory will be deleted. If "false" and
* the directory is non-empty, an error occurs.
* @brief Deletes the empty directory. Throws exception if directory is not empty.
* @param options Optional parameters to delete the directory the path points to.
* @return Azure::Core::Response<Models::DeleteShareDirectoryResult> containing the information
* returned when deleting the directory.
* @remark This request is sent to dfs endpoint.
*/
Azure::Core::Response<Models::DeleteDataLakeDirectoryResult> Delete(
bool recursive,
const DeleteDataLakeDirectoryOptions& options = DeleteDataLakeDirectoryOptions()) const;
Azure::Core::Response<Models::DeleteDataLakeDirectoryResult> DeleteEmpty(
const DeleteDataLakeDirectoryOptions& options = DeleteDataLakeDirectoryOptions()) const
{
return this->Delete(false, options);
}
/**
* @brief Deletes the directory if it already exists.
* @param recursive If "true", all paths beneath the directory will be deleted. If "false" and
* the directory is non-empty, an error occurs.
* @brief Deletes the empty directory if it already exists. Throws exception if directory is not
* empty.
* @param options Optional parameters to delete the directory the path points to.
* @return Azure::Core::Response<Models::DeleteShareDirectoryResult> containing the information
* returned when deleting the directory.
* @remark This request is sent to dfs endpoint.
*/
Azure::Core::Response<Models::DeleteDataLakeDirectoryResult> DeleteIfExists(
bool recursive,
const DeleteDataLakeDirectoryOptions& options = DeleteDataLakeDirectoryOptions()) const;
Azure::Core::Response<Models::DeleteDataLakeDirectoryResult> DeleteEmptyIfExists(
const DeleteDataLakeDirectoryOptions& options = DeleteDataLakeDirectoryOptions()) const
{
return this->DeleteIfExists(false, options);
}
/**
* @brief Deletes the directory and all its subdirectories and files.
* @param options Optional parameters to delete the directory the path points to.
* @return Azure::Core::Response<Models::DeleteShareDirectoryResult> containing the information
* returned when deleting the directory.
* @remark This request is sent to dfs endpoint.
*/
Azure::Core::Response<Models::DeleteDataLakeDirectoryResult> DeleteRecursive(
const DeleteDataLakeDirectoryOptions& options = DeleteDataLakeDirectoryOptions()) const
{
return this->Delete(true, options);
}
/**
* @brief Deletes the directory and all its subdirectories and files if the directory exists.
* @param options Optional parameters to delete the directory the path points to.
* @return Azure::Core::Response<Models::DeleteShareDirectoryResult> containing the information
* returned when deleting the directory.
* @remark This request is sent to dfs endpoint.
*/
Azure::Core::Response<Models::DeleteDataLakeDirectoryResult> DeleteRecursiveIfExists(
const DeleteDataLakeDirectoryOptions& options = DeleteDataLakeDirectoryOptions()) const
{
return this->DeleteIfExists(true, options);
}
/**
* @brief List the paths in this file system.
@ -193,6 +220,14 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake {
{
}
Azure::Core::Response<Models::DeleteDataLakeDirectoryResult> Delete(
bool recursive,
const DeleteDataLakeDirectoryOptions& options = DeleteDataLakeDirectoryOptions()) const;
Azure::Core::Response<Models::DeleteDataLakeDirectoryResult> DeleteIfExists(
bool recursive,
const DeleteDataLakeDirectoryOptions& options = DeleteDataLakeDirectoryOptions()) const;
friend class DataLakeFileSystemClient;
};
}}}} // namespace Azure::Storage::Files::DataLake

View File

@ -252,6 +252,7 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake {
m_blockBlobClient(std::move(blockBlobClient))
{
}
friend class DataLakeFileSystemClient;
friend class DataLakeDirectoryClient;
};

View File

@ -514,15 +514,6 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake {
*/
Azure::Core::Context Context;
/**
* @brief When deleting a directory, the number of paths that are deleted with each invocation
* is limited. If the number of paths to be deleted exceeds this limit, a continuation
* token is returned in this response header. When a continuation token is returned in
* the response, it must be specified in a subsequent invocation of the delete operation
* to continue deleting the directory.
*/
Azure::Core::Nullable<std::string> ContinuationToken;
/**
* @brief Required and valid only when the resource is a directory. If "true", all paths beneath
* the directory will be deleted. If "false" and the directory is non-empty, an error
@ -660,15 +651,6 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake {
*/
Azure::Core::Context Context;
/**
* @brief When deleting a directory, the number of paths that are deleted with each invocation
* is limited. If the number of paths to be deleted exceeds this limit, a continuation
* token is returned in this response header. When a continuation token is returned in
* the response, it must be specified in a subsequent invocation of the delete operation
* to continue deleting the directory.
*/
Azure::Core::Nullable<std::string> ContinuationToken;
/**
* @brief Specify the access condition for the path.
*/

View File

@ -93,7 +93,6 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake { nam
struct DeleteDataLakePathResult
{
bool Deleted = true;
Azure::Core::Nullable<std::string> ContinuationToken;
std::string RequestId;
};

View File

@ -244,7 +244,6 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake {
DeleteDataLakePathOptions deleteOptions;
deleteOptions.AccessConditions = options.AccessConditions;
deleteOptions.Context = options.Context;
deleteOptions.ContinuationToken = options.ContinuationToken;
deleteOptions.Recursive = recursive;
return DataLakePathClient::Delete(deleteOptions);
}
@ -255,7 +254,6 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake {
DeleteDataLakePathOptions deleteOptions;
deleteOptions.AccessConditions = options.AccessConditions;
deleteOptions.Context = options.Context;
deleteOptions.ContinuationToken = options.ContinuationToken;
deleteOptions.Recursive = recursive;
return DataLakePathClient::DeleteIfExists(deleteOptions);
}

View File

@ -308,7 +308,6 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake {
const DeleteDataLakePathOptions& options) const
{
Details::DataLakeRestClient::Path::DeleteOptions protocolLayerOptions;
protocolLayerOptions.ContinuationToken = options.ContinuationToken;
protocolLayerOptions.LeaseIdOptional = options.AccessConditions.LeaseId;
protocolLayerOptions.IfMatch = options.AccessConditions.IfMatch;
protocolLayerOptions.IfNoneMatch = options.AccessConditions.IfNoneMatch;
@ -318,7 +317,6 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake {
auto result = Details::DataLakeRestClient::Path::Delete(
m_dfsUrl, *m_pipeline, options.Context, protocolLayerOptions);
Models::DeleteDataLakePathResult ret;
ret.ContinuationToken = std::move(result->ContinuationToken);
ret.Deleted = true;
ret.RequestId = std::move(result->RequestId);
return Azure::Core::Response<Models::DeleteDataLakePathResult>(

View File

@ -43,7 +43,7 @@ namespace Azure { namespace Storage { namespace Test {
}
for (const auto& client : directoryClient)
{
EXPECT_NO_THROW(client.Delete(false));
EXPECT_NO_THROW(client.DeleteEmpty());
}
}
{
@ -61,10 +61,10 @@ namespace Azure { namespace Storage { namespace Test {
Files::DataLake::DeleteDataLakeDirectoryOptions options1;
options1.AccessConditions.IfModifiedSince = response->LastModified;
EXPECT_TRUE(IsValidTime(response->LastModified));
EXPECT_THROW(client.Delete(false, options1), StorageException);
EXPECT_THROW(client.DeleteEmpty(options1), StorageException);
Files::DataLake::DeleteDataLakeDirectoryOptions options2;
options2.AccessConditions.IfUnmodifiedSince = response->LastModified;
EXPECT_NO_THROW(client.Delete(false, options2));
EXPECT_NO_THROW(client.DeleteEmpty(options2));
}
}
{
@ -81,10 +81,10 @@ namespace Azure { namespace Storage { namespace Test {
auto response = client.GetProperties();
Files::DataLake::DeleteDataLakeDirectoryOptions options1;
options1.AccessConditions.IfNoneMatch = response->ETag;
EXPECT_THROW(client.Delete(false, options1), StorageException);
EXPECT_THROW(client.DeleteEmpty(options1), StorageException);
Files::DataLake::DeleteDataLakeDirectoryOptions options2;
options2.AccessConditions.IfMatch = response->ETag;
EXPECT_NO_THROW(client.Delete(false, options2));
EXPECT_NO_THROW(client.DeleteEmpty(options2));
}
}
@ -100,8 +100,8 @@ namespace Azure { namespace Storage { namespace Test {
EXPECT_NO_THROW(client.Create());
directoryClient.emplace_back(std::move(client));
}
EXPECT_THROW(rootDirClient.Delete(false), StorageException);
EXPECT_NO_THROW(rootDirClient.Delete(true));
EXPECT_THROW(rootDirClient.DeleteEmpty(), StorageException);
EXPECT_NO_THROW(rootDirClient.DeleteRecursive());
}
}
@ -115,16 +115,16 @@ namespace Azure { namespace Storage { namespace Test {
EXPECT_TRUE(created);
EXPECT_NO_THROW(created = client.CreateIfNotExists()->Created);
EXPECT_FALSE(created);
EXPECT_NO_THROW(deleted = client.Delete(false)->Deleted);
EXPECT_NO_THROW(deleted = client.DeleteEmpty()->Deleted);
EXPECT_TRUE(deleted);
EXPECT_NO_THROW(deleted = client.DeleteIfExists(false)->Deleted);
EXPECT_NO_THROW(deleted = client.DeleteEmptyIfExists()->Deleted);
EXPECT_FALSE(deleted);
}
{
auto client = Files::DataLake::DataLakeDirectoryClient::CreateFromConnectionString(
AdlsGen2ConnectionString(), LowercaseRandomString(), RandomString());
bool deleted = false;
EXPECT_NO_THROW(deleted = client.DeleteIfExists(false)->Deleted);
EXPECT_NO_THROW(deleted = client.DeleteEmptyIfExists()->Deleted);
EXPECT_FALSE(deleted);
}
}
@ -149,11 +149,11 @@ namespace Azure { namespace Storage { namespace Test {
}
for (const auto& client : directoryClients)
{
EXPECT_THROW(client.Delete(false), StorageException);
EXPECT_THROW(client.DeleteEmpty(), StorageException);
}
for (const auto& client : newDirectoryClients)
{
EXPECT_NO_THROW(client.Delete(false));
EXPECT_NO_THROW(client.DeleteEmpty());
}
}
{
@ -176,7 +176,7 @@ namespace Azure { namespace Storage { namespace Test {
options2.SourceAccessConditions.IfUnmodifiedSince = response->LastModified;
auto newPath = RandomString();
EXPECT_NO_THROW(
client.RenameSubdirectory("", newPath, options2).ExtractValue().Delete(false));
client.RenameSubdirectory("", newPath, options2).ExtractValue().DeleteEmpty());
}
}
{
@ -198,7 +198,7 @@ namespace Azure { namespace Storage { namespace Test {
options2.SourceAccessConditions.IfMatch = response->ETag;
auto newPath = RandomString();
EXPECT_NO_THROW(
client.RenameSubdirectory("", newPath, options2).ExtractValue().Delete(false));
client.RenameSubdirectory("", newPath, options2).ExtractValue().DeleteEmpty());
}
}
{
@ -233,7 +233,7 @@ namespace Azure { namespace Storage { namespace Test {
{
auto newPath = RandomString();
EXPECT_NO_THROW(
client.RenameSubdirectory("", newPath, options).ExtractValue().Delete(false));
client.RenameSubdirectory("", newPath, options).ExtractValue().DeleteEmpty());
}
}
}
@ -321,7 +321,7 @@ namespace Azure { namespace Storage { namespace Test {
EXPECT_EQ(httpHeader.ContentDisposition, result->HttpHeaders.ContentDisposition);
EXPECT_EQ(httpHeader.ContentLanguage, result->HttpHeaders.ContentLanguage);
EXPECT_EQ(httpHeader.ContentType, result->HttpHeaders.ContentType);
EXPECT_NO_THROW(client.Delete(false));
EXPECT_NO_THROW(client.DeleteEmpty());
}
}
}
@ -604,7 +604,7 @@ namespace Azure { namespace Storage { namespace Test {
= Azure::Storage::Files::DataLake::DataLakeDirectoryClient::CreateFromConnectionString(
AdlsGen2ConnectionString(), m_fileSystemName, directoryName);
EXPECT_NO_THROW(connectionStringClient.Create());
EXPECT_NO_THROW(connectionStringClient.Delete(true));
EXPECT_NO_THROW(connectionStringClient.DeleteRecursive());
}
{
@ -619,7 +619,7 @@ namespace Azure { namespace Storage { namespace Test {
credential);
EXPECT_NO_THROW(clientSecretClient.Create());
EXPECT_NO_THROW(clientSecretClient.Delete(true));
EXPECT_NO_THROW(clientSecretClient.DeleteRecursive());
}
{