Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,38 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
const CreateDirectoryOptions& options = CreateDirectoryOptions(),
const Azure::Core::Context& context = Azure::Core::Context()) const;

/**
* @brief Renames a file. This API does not support renaming a file
* from one share to another, or between storage accounts.
* @param fileName The file that gets renamed.
* @param destinationFilePath The path of the file the source file is renaming to.
* @param options Optional parameters to rename a file.
* @param context Context for cancelling long running operations.
* @return Azure::Response<ShareFileClient> The client targets the renamed file.
*/
Azure::Response<ShareFileClient> RenameFile(
const std::string& fileName,
const std::string& destinationFilePath,
const RenameFileOptions& options = RenameFileOptions(),
const Azure::Core::Context& context = Azure::Core::Context()) const;

/**
* @brief Renames a directory. This API does not support renaming a directory
* from one share to another, or between storage accounts.
* @param subdirectoryName The subdirectory that gets renamed.
* @param destinationDirectoryPath The destinationPath the source subdirectory is renaming to.
* @param options Optional parameters to rename a directory.
* @param context Context for cancelling long running operations.
* @return Azure::Response<ShareDirectoryClient> The client targets the renamed
* directory.
* @remark This request is sent to dfs endpoint.
Comment thread
microzchang marked this conversation as resolved.
Outdated
*/
Azure::Response<ShareDirectoryClient> RenameSubdirectory(
const std::string& directoryName,
const std::string& destinationDirectoryPath,
const RenameDirectoryOptions& options = RenameDirectoryOptions(),
const Azure::Core::Context& context = Azure::Core::Context()) const;

/**
* @brief Deletes the directory.
* @param options Optional parameters to delete this directory.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,115 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
Models::FileSmbProperties SmbProperties;
};

/**
* @brief Optional parameters for
* #Azure::Storage::Files::Shares::ShareDirectoryClient::RenameFile.
*/
struct RenameFileOptions final
{
/**
* A boolean value for if the destination file already exists, whether this request will
* overwrite the file or not. If true, the rename will succeed and will overwrite the
* destination file. If not provided or if false and the destination file does exist, the
* request will not overwrite the destination file. If provided and the destination file doesn�t
* exist, the rename will succeed.
*/
Azure::Nullable<bool> ReplaceIfExists;

/**
* A boolean value that specifies whether the ReadOnly attribute on a preexisting destination
* file should be respected. If true, the rename will succeed, otherwise, a previous file at the
* destination with the ReadOnly attribute set will cause the rename to fail. ReplaceIfExists
* must also be true.
*/
Azure::Nullable<bool> IgnoreReadOnly;

/**
* Specify the access condition for the path.
*/
LeaseAccessConditions AccessConditions;

/**
* The access condition for source path.
*/
LeaseAccessConditions SourceAccessConditions;

/**
* SMB properties to set for the directory.
*/
Models::FileSmbProperties SmbProperties;

/**
* If specified the permission (security descriptor) shall be set for the directory.
* This option can be used if Permission size is <= 8KB, else SmbProperties.PermissionKey
* shall be used.A value of preserve may be passed to keep an existing value unchanged.
*/
Azure::Nullable<std::string> FilePermission;

/**
* A name-value pair to associate with a file storage object.
*/
Storage::Metadata Metadata;

/**
* Sets the file's content type.If this property is not specified on the request, then the
* property will be preserved for the file
*/
Nullable<std::string> FileContentType;
Comment thread
Jinming-Hu marked this conversation as resolved.
Outdated

};

/**
* @brief Optional parameters for
* #Azure::Storage::Files::Shares::ShareDirectoryClient::RenameSubdirectory.
*/
struct RenameDirectoryOptions final
{
/**
* A boolean value for if the destination directory already exists, whether this request will
* overwrite the file or not. If true, the rename will succeed and will overwrite the
* destination directory. If not provided or if false and the destination directory does exist,
* the request will not overwrite the destination directory. If provided and the destination
* file doesn�t exist, the rename will succeed.
*/
Azure::Nullable<bool> ReplaceIfExists;

/**
* A boolean value that specifies whether the ReadOnly attribute on a preexisting destination
* directory should be respected. If true, the rename will succeed, otherwise, a previous file
* at the destination with the ReadOnly attribute set will cause the rename to fail.
* ReplaceIfExists must also be true.
*/
Azure::Nullable<bool> IgnoreReadOnly;

/**
* Specify the access condition for the path.
*/
LeaseAccessConditions AccessConditions;

/**
* The access condition for source path.
*/
LeaseAccessConditions SourceAccessConditions;

/**
* SMB properties to set for the directory.
*/
Models::FileSmbProperties SmbProperties;

/**
* If specified the permission (security descriptor) shall be set for the directory.
* This option can be used if Permission size is <= 8KB, else SmbProperties.PermissionKey
* shall be used.A value of preserve may be passed to keep an existing value unchanged.
*/
Azure::Nullable<std::string> FilePermission;

/**
* A name-value pair to associate with a file storage object.
*/
Storage::Metadata Metadata;
};

/**
* @brief Optional parameters for #Azure::Storage::Files::Shares::ShareDirectoryClient::Delete.
*/
Expand Down
112 changes: 112 additions & 0 deletions sdk/storage/azure-storage-files-shares/src/share_directory_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,118 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
throw;
}
}
Azure::Response<ShareFileClient> ShareDirectoryClient::RenameFile(
const std::string& fileName,
const std::string& destinationFilePath,
const RenameFileOptions& options,
const Azure::Core::Context& context) const
{
auto sourceFileUrl = m_shareDirectoryUrl;
sourceFileUrl.AppendPath(_internal::UrlEncodePath(fileName));

auto destinationFileUrl = m_shareDirectoryUrl;
Comment thread
microzchang marked this conversation as resolved.
destinationFileUrl.AppendPath(_internal::UrlEncodePath(destinationFilePath));

auto protocolLayerOptions = _detail::FileClient::RenameFileOptions();
protocolLayerOptions.RenameSource = sourceFileUrl.GetAbsoluteUrl();
protocolLayerOptions.ReplaceIfExists = options.ReplaceIfExists;
protocolLayerOptions.IgnoreReadOnly = options.IgnoreReadOnly;
protocolLayerOptions.DestinationLeaseId = options.AccessConditions.LeaseId;
protocolLayerOptions.SourceLeaseId = options.SourceAccessConditions.LeaseId;
protocolLayerOptions.FileContentType = options.FileContentType;
protocolLayerOptions.Metadata
= std::map<std::string, std::string>(options.Metadata.begin(), options.Metadata.end());
if (!options.SmbProperties.Attributes.GetValues().empty())
{
protocolLayerOptions.FileAttributes = options.SmbProperties.Attributes.ToString();
}
Comment thread
microzchang marked this conversation as resolved.
Outdated
if (options.SmbProperties.CreatedOn.HasValue())
{
protocolLayerOptions.FileCreationTime = options.SmbProperties.CreatedOn.Value().ToString(
Azure::DateTime::DateFormat::Rfc3339, DateTime::TimeFractionFormat::AllDigits);
}
if (options.SmbProperties.LastWrittenOn.HasValue())
{
protocolLayerOptions.FileLastWriteTime = options.SmbProperties.LastWrittenOn.Value().ToString(
Azure::DateTime::DateFormat::Rfc3339, DateTime::TimeFractionFormat::AllDigits);
}
if (options.SmbProperties.ChangedOn.HasValue())
{
protocolLayerOptions.FileChangeTime = options.SmbProperties.ChangedOn.Value().ToString(
Azure::DateTime::DateFormat::Rfc3339, DateTime::TimeFractionFormat::AllDigits);
}
if (options.FilePermission.HasValue())
{
protocolLayerOptions.FilePermission = options.FilePermission.Value();
}
else if (options.SmbProperties.PermissionKey.HasValue())
{
protocolLayerOptions.FilePermissionKey = options.SmbProperties.PermissionKey;
}
Comment thread
microzchang marked this conversation as resolved.

auto response = _detail::FileClient::Rename(
*m_pipeline, destinationFileUrl, protocolLayerOptions, context);

auto renamedFileClient = ShareFileClient(destinationFileUrl, m_pipeline);
return Azure::Response<ShareFileClient>(
std::move(renamedFileClient), std::move(response.RawResponse));
}

Azure::Response<ShareDirectoryClient> ShareDirectoryClient::RenameSubdirectory(
const std::string& directoryName,
const std::string& destinationDirectoryPath,
const RenameDirectoryOptions& options,
const Azure::Core::Context& context) const
{
auto sourceDirectoryUrl = m_shareDirectoryUrl;
sourceDirectoryUrl.AppendPath(_internal::UrlEncodePath(directoryName));

auto destinationDirectoryUrl = m_shareDirectoryUrl;
destinationDirectoryUrl.AppendPath(_internal::UrlEncodePath(destinationDirectoryPath));

auto protocolLayerOptions = _detail::DirectoryClient::RenameDirectoryOptions();
protocolLayerOptions.RenameSource = sourceDirectoryUrl.GetAbsoluteUrl();
protocolLayerOptions.ReplaceIfExists = options.ReplaceIfExists;
protocolLayerOptions.IgnoreReadOnly = options.IgnoreReadOnly;
protocolLayerOptions.DestinationLeaseId = options.AccessConditions.LeaseId;
protocolLayerOptions.SourceLeaseId = options.SourceAccessConditions.LeaseId;
protocolLayerOptions.Metadata
= std::map<std::string, std::string>(options.Metadata.begin(), options.Metadata.end());
if (!options.SmbProperties.Attributes.GetValues().empty())
{
protocolLayerOptions.FileAttributes = options.SmbProperties.Attributes.ToString();
}
if (options.SmbProperties.CreatedOn.HasValue())
{
protocolLayerOptions.FileCreationTime = options.SmbProperties.CreatedOn.Value().ToString(
Azure::DateTime::DateFormat::Rfc3339, DateTime::TimeFractionFormat::AllDigits);
}
if (options.SmbProperties.LastWrittenOn.HasValue())
{
protocolLayerOptions.FileLastWriteTime = options.SmbProperties.LastWrittenOn.Value().ToString(
Azure::DateTime::DateFormat::Rfc3339, DateTime::TimeFractionFormat::AllDigits);
}
if (options.SmbProperties.ChangedOn.HasValue())
{
protocolLayerOptions.FileChangeTime = options.SmbProperties.ChangedOn.Value().ToString(
Azure::DateTime::DateFormat::Rfc3339, DateTime::TimeFractionFormat::AllDigits);
}
if (options.FilePermission.HasValue())
{
protocolLayerOptions.FilePermission = options.FilePermission.Value();
}
else if (options.SmbProperties.PermissionKey.HasValue())
{
protocolLayerOptions.FilePermissionKey = options.SmbProperties.PermissionKey;
}

auto response = _detail::DirectoryClient::Rename(
*m_pipeline, destinationDirectoryUrl, protocolLayerOptions, context);

auto renamedFileClient = ShareDirectoryClient(destinationDirectoryUrl, m_pipeline);
return Azure::Response<ShareDirectoryClient>(
std::move(renamedFileClient), std::move(response.RawResponse));
}

Azure::Response<Models::DeleteDirectoryResult> ShareDirectoryClient::Delete(
const DeleteDirectoryOptions& options,
Expand Down
Loading