Skip to content

Commit

Permalink
Fixed bug where ShareDirectoryClient.SetMetadataAsync() would not pro…
Browse files Browse the repository at this point in the history
…perty parse Last-Modified response header. (#22309)
  • Loading branch information
seanmcc-msft authored Jun 30, 2021
1 parent 6e7a370 commit b75f088
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
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

0 comments on commit b75f088

Please sign in to comment.