Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -123,7 +123,8 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake {
* @brief Renames a file. By default, the destination is overwritten and
* if the destination already exists and has a lease the lease is broken.
* @param fileName The file that gets renamed.
* @param destinationFilePath The path of the file the source file is renaming to.
* @param destinationFilePath The path of the file the source file is renaming to. The
* destination is an absolute path under the root of the file system, without leading slash.
* @param options Optional parameters to rename a file.
* @param context Context for cancelling long running operations.
* @return Azure::Response<DataLakeFileClient> The client targets the renamed file.
Expand All @@ -140,6 +141,7 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake {
* if the destination already exists and has a lease the lease is broken.
* @param subdirectoryName The subdirectory that gets renamed.
* @param destinationDirectoryPath The destinationPath the source subdirectory is renaming to.
* The destination is an absolute path under the root of the file system, without leading slash.
* @param options Optional parameters to rename a directory.
* @param context Context for cancelling long running operations.
* @return Azure::Response<DataLakeDirectoryClient> The client targets the renamed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,39 @@ 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. The
* destination is an absolute path under the root of the share, without leading slash.
* @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.
* The destination is an absolute path under the root of the share, without leading slash.
* @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.
*/
Azure::Response<ShareDirectoryClient> RenameSubdirectory(
const std::string& subdirectoryName,
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,108 @@ 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;
};

/**
* @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
111 changes: 111 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,117 @@ 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));

const std::string& currentPath = m_shareDirectoryUrl.GetPath();
std::string destinationFileShare = currentPath.substr(0, currentPath.find('/'));
auto destinationFileUrl = m_shareDirectoryUrl;
destinationFileUrl.SetPath(_internal::UrlEncodePath(destinationFileShare));
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.FileAttributes = options.SmbProperties.Attributes.ToString();
protocolLayerOptions.Metadata
= std::map<std::string, std::string>(options.Metadata.begin(), options.Metadata.end());
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::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& subdirectoryName,
const std::string& destinationDirectoryPath,
const RenameDirectoryOptions& options,
const Azure::Core::Context& context) const
{
auto sourceDirectoryUrl = m_shareDirectoryUrl;
sourceDirectoryUrl.AppendPath(_internal::UrlEncodePath(subdirectoryName));

const std::string& currentPath = m_shareDirectoryUrl.GetPath();
std::string destinationFileShare = currentPath.substr(0, currentPath.find('/'));
auto destinationDirectoryUrl = m_shareDirectoryUrl;
destinationDirectoryUrl.SetPath(_internal::UrlEncodePath(destinationFileShare));
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.FileAttributes = options.SmbProperties.Attributes.ToString();
protocolLayerOptions.Metadata
= std::map<std::string, std::string>(options.Metadata.begin(), options.Metadata.end());
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