Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed bug where DataLakeFileClient.Rename(), DataLakePathClient.Renam… #15106

Merged
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
1 change: 1 addition & 0 deletions sdk/storage/Azure.Storage.Files.DataLake/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- Fixed bug where DataLakeFileClient.Upload() could not upload read-only files.
- Fixed bug where DataLakeBlobAccessPolicy.StartsOn and .ExpiresOn would cause the process to crash.
- Added Close and RetainUncommitedData to DataLakeFileUploadOptions.
- Fixed bug where DataLakeDirectoryClient.Rename(), DataLakeFileClient.Rename(), and DataLakeFileClient.Rename() couldn't handle source paths with special characters.

## 12.4.0 (2020-08-31)
- Fixed bug where DataLakeFileClient.Upload() would deadlock if the content stream's position was not 0.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using Metadata = System.Collections.Generic.IDictionary<string, string>;
using System.Text.Json;
using System.Collections.Generic;
using Azure.Storage.Shared;

namespace Azure.Storage.Files.DataLake
{
Expand Down Expand Up @@ -1574,7 +1575,7 @@ public virtual async Task<Response<DataLakeDirectoryClient>> CreateDirectoryAsyn

DataLakeDirectoryClient directoryClient = GetDirectoryClient(path);

Response<PathInfo> response = await GetDirectoryClient(path).CreateAsync(
Response<PathInfo> response = await directoryClient.CreateAsync(
httpHeaders,
metadata,
permissions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1604,7 +1604,7 @@ private async Task<Response<DataLakePathClient>> RenameInternal(
{
// Build renameSource
DataLakeUriBuilder sourceUriBuilder = new DataLakeUriBuilder(_dfsUri);
string renameSource = "/" + sourceUriBuilder.FileSystemName + "/" + sourceUriBuilder.DirectoryOrFilePath;
string renameSource = "/" + sourceUriBuilder.FileSystemName + "/" + sourceUriBuilder.DirectoryOrFilePath.EscapePath();

if (sourceUriBuilder.Sas != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,53 @@ await TestHelper.AssertExpectedExceptionAsync<RequestFailedException>(
}
}

[Test]
[TestCase("!'();[]@&%=+$,#äÄöÖüÜß;")]
[TestCase("%21%27%28%29%3B%5B%5D%40%26%25%3D%2B%24%2C%23äÄöÖüÜß%3B")]
[TestCase(" my cool directory ")]
[TestCase("directory")]
public async Task RenameAsync_DestinationSpecialCharacters(string destDirectoryName)
{
await using DisposingFileSystem test = await GetNewFileSystem();

// Arrange
DataLakeDirectoryClient sourceDirectory = await test.FileSystem.CreateDirectoryAsync(GetNewDirectoryName());
Uri expectedDestDirectoryUri = new Uri($"https://{test.FileSystem.AccountName}.dfs.core.windows.net/{test.FileSystem.Name}/{Uri.EscapeDataString(destDirectoryName)}");

// Act
DataLakeDirectoryClient destDirectory = await sourceDirectory.RenameAsync(destinationPath: destDirectoryName);

// Assert
Response<PathProperties> response = await destDirectory.GetPropertiesAsync();
Assert.AreEqual(destDirectoryName, destDirectory.Name);
Assert.AreEqual(destDirectoryName, destDirectory.Path);
Assert.AreEqual(expectedDestDirectoryUri, destDirectory.Uri);
}

[Test]
[TestCase("!'();[]@&%=+$,#äÄöÖüÜß;")]
[TestCase("%21%27%28%29%3B%5B%5D%40%26%25%3D%2B%24%2C%23äÄöÖüÜß%3B")]
[TestCase(" my cool directory ")]
[TestCase("directory")]
public async Task RenameAsync_SourceSpecialCharacters(string sourceDirectoryName)
{
await using DisposingFileSystem test = await GetNewFileSystem();

// Arrange
string destDirectoryName = GetNewDirectoryName();
DataLakeDirectoryClient sourceDirectory = await test.FileSystem.CreateDirectoryAsync(sourceDirectoryName);
Uri expectedDestDirectoryUri = new Uri($"https://{test.FileSystem.AccountName}.dfs.core.windows.net/{test.FileSystem.Name}/{destDirectoryName}");

// Act
DataLakeDirectoryClient destDirectory = await sourceDirectory.RenameAsync(destinationPath: destDirectoryName);

// Assert
Response<PathProperties> response = await destDirectory.GetPropertiesAsync();
Assert.AreEqual(destDirectoryName, destDirectory.Name);
Assert.AreEqual(destDirectoryName, destDirectory.Path);
Assert.AreEqual(expectedDestDirectoryUri, destDirectory.Uri);
}

[Test]
public async Task GetAccessControlAsync()
{
Expand Down
53 changes: 53 additions & 0 deletions sdk/storage/Azure.Storage.Files.DataLake/tests/FileClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,59 @@ await TestHelper.AssertExpectedExceptionAsync<RequestFailedException>(
}
}

[Test]
[TestCase("!'();[]@&%=+$,#äÄöÖüÜß;")]
[TestCase("%21%27%28%29%3B%5B%5D%40%26%25%3D%2B%24%2C%23äÄöÖüÜß%3B")]
[TestCase(" my cool file ")]
[TestCase("file")]
public async Task RenameAsync_DestinationSpecialCharacters(string destFileName)
{
// Arrange
await using DisposingFileSystem test = await GetNewFileSystem();
string directoryName = GetNewDirectoryName();
DataLakeDirectoryClient directory = InstrumentClient(test.FileSystem.GetDirectoryClient(directoryName));
await directory.CreateAsync();
DataLakeFileClient sourceFile = await test.FileSystem.CreateFileAsync(GetNewFileName());
Uri expectedDestFileUri = new Uri($"https://{test.FileSystem.AccountName}.dfs.core.windows.net/{test.FileSystem.Name}/{directoryName}/{Uri.EscapeDataString(destFileName)}");
string destFilePath = $"{directoryName}/{destFileName}";

// Act
DataLakeFileClient destFile = await sourceFile.RenameAsync(destinationPath: destFilePath);

// Assert
Response<PathProperties> response = await destFile.GetPropertiesAsync();
Assert.AreEqual(destFileName, destFile.Name);
Assert.AreEqual(destFilePath, destFile.Path);
Assert.AreEqual(expectedDestFileUri, destFile.Uri);
}

[Test]
[TestCase("!'();[]@&%=+$,#äÄöÖüÜß;")]
[TestCase("%21%27%28%29%3B%5B%5D%40%26%25%3D%2B%24%2C%23äÄöÖüÜß%3B")]
[TestCase(" my cool file ")]
[TestCase("file")]
public async Task RenameAsync_SourceSpecialCharacters(string sourceFileName)
{
// Arrange
await using DisposingFileSystem test = await GetNewFileSystem();
string directoryName = GetNewDirectoryName();
DataLakeDirectoryClient directory = InstrumentClient(test.FileSystem.GetDirectoryClient(directoryName));
await directory.CreateAsync();
DataLakeFileClient sourceFile = await test.FileSystem.CreateFileAsync(sourceFileName);
string destFileName = GetNewFileName();
Uri expectedDestFileUri = new Uri($"https://{test.FileSystem.AccountName}.dfs.core.windows.net/{test.FileSystem.Name}/{directoryName}/{destFileName}");
string destFilePath = $"{directoryName}/{destFileName}";

// Act
DataLakeFileClient destFile = await sourceFile.RenameAsync(destinationPath: destFilePath);

// Assert
Response<PathProperties> response = await destFile.GetPropertiesAsync();
Assert.AreEqual(destFileName, destFile.Name);
Assert.AreEqual(destFilePath, destFile.Path);
Assert.AreEqual(expectedDestFileUri, destFile.Uri);
}

[Test]
public async Task GetAccessControlAsync()
{
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading