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 ShareDirectoryClient.SetMetadataAsync() would not pro… #22309

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.Common/src/Shared/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ internal static class HeaderNames
public const string ContentRange = "Content-Range";
public const string VersionId = "x-ms-version-id";
public const string LeaseTime = "x-ms-lease-time";
public const string LastModified = "Last-Modified";
}

internal static class ErrorCodes
Expand Down
1 change: 1 addition & 0 deletions sdk/storage/Azure.Storage.Files.Shares/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- Added support for service version 2020-10-02.
- Added support for OAuth copy sources in ShareFileClient.UploadRangeFromUri()
- Added support for including additional information in ShareDirectoryClient.GetFilesAndDirectories().
- Fixed bug where ShareDirectoryClient.SetMetadataAsync() would not property parse Last-Modified response header.

## 12.7.0 (2021-06-08)
- Includes all features from 12.7.0-beta.4.
Expand Down
18 changes: 16 additions & 2 deletions sdk/storage/Azure.Storage.Files.Shares/src/ShareExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,12 @@ internal static ShareDirectoryInfo ToShareDirectoryInfo(this ResponseWithHeaders
return null;
}

// Set Directory metadata returns limited resposne headers - https://docs.microsoft.com/en-us/rest/api/storageservices/set-directory-metadata.
// Set Directory metadata returns limited response headers - https://docs.microsoft.com/en-us/rest/api/storageservices/set-directory-metadata.
return new ShareDirectoryInfo
{
ETag = response.GetRawResponse().Headers.ETag.GetValueOrDefault(),
SmbProperties = new FileSmbProperties()
SmbProperties = new FileSmbProperties(),
LastModified = response.GetRawResponse().Headers.ExtractLastModified()
};
}

Expand All @@ -200,6 +201,7 @@ internal static StorageClosedHandlesSegment ToStorageClosedHandlesSegment(this R
{
return null;
}

return new StorageClosedHandlesSegment
{
Marker = response.Headers.Marker,
Expand Down Expand Up @@ -894,5 +896,17 @@ internal static ShareFileItemProperties ToShareFileItemProperties(this FilePrope
lastModified: fileProperty.LastModified,
eTag: fileProperty.Etag == null ? null : new ETag(fileProperty.Etag));
}

internal static DateTimeOffset ExtractLastModified(this ResponseHeaders responseHeaders)
{
DateTimeOffset lastModified = DateTimeOffset.MinValue;

if (responseHeaders.TryGetValue(Constants.HeaderNames.LastModified, out string lastModifiedString))
{
lastModified = DateTimeOffset.Parse(lastModifiedString, CultureInfo.InvariantCulture);
}

return lastModified;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,8 @@ public async Task SetMetadataAsync()
IDictionary<string, string> metadata = BuildMetadata();

// Act
await directory.SetMetadataAsync(metadata);
Response<ShareDirectoryInfo> setMetadataResponse = await directory.SetMetadataAsync(metadata);
Assert.AreNotEqual(DateTimeOffset.MinValue, setMetadataResponse.Value.LastModified);

// Assert
Response<ShareDirectoryProperties> response = await directory.GetPropertiesAsync();
Expand Down