Skip to content

Commit b75f088

Browse files
authored
Fixed bug where ShareDirectoryClient.SetMetadataAsync() would not property parse Last-Modified response header. (Azure#22309)
1 parent 6e7a370 commit b75f088

File tree

4 files changed

+20
-3
lines changed

4 files changed

+20
-3
lines changed

sdk/storage/Azure.Storage.Common/src/Shared/Constants.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ internal static class HeaderNames
172172
public const string ContentRange = "Content-Range";
173173
public const string VersionId = "x-ms-version-id";
174174
public const string LeaseTime = "x-ms-lease-time";
175+
public const string LastModified = "Last-Modified";
175176
}
176177

177178
internal static class ErrorCodes

sdk/storage/Azure.Storage.Files.Shares/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
- Added support for service version 2020-10-02.
55
- Added support for OAuth copy sources in ShareFileClient.UploadRangeFromUri()
66
- Added support for including additional information in ShareDirectoryClient.GetFilesAndDirectories().
7+
- Fixed bug where ShareDirectoryClient.SetMetadataAsync() would not property parse Last-Modified response header.
78

89
## 12.7.0 (2021-06-08)
910
- Includes all features from 12.7.0-beta.4.

sdk/storage/Azure.Storage.Files.Shares/src/ShareExtensions.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,11 +172,12 @@ internal static ShareDirectoryInfo ToShareDirectoryInfo(this ResponseWithHeaders
172172
return null;
173173
}
174174

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

@@ -200,6 +201,7 @@ internal static StorageClosedHandlesSegment ToStorageClosedHandlesSegment(this R
200201
{
201202
return null;
202203
}
204+
203205
return new StorageClosedHandlesSegment
204206
{
205207
Marker = response.Headers.Marker,
@@ -894,5 +896,17 @@ internal static ShareFileItemProperties ToShareFileItemProperties(this FilePrope
894896
lastModified: fileProperty.LastModified,
895897
eTag: fileProperty.Etag == null ? null : new ETag(fileProperty.Etag));
896898
}
899+
900+
internal static DateTimeOffset ExtractLastModified(this ResponseHeaders responseHeaders)
901+
{
902+
DateTimeOffset lastModified = DateTimeOffset.MinValue;
903+
904+
if (responseHeaders.TryGetValue(Constants.HeaderNames.LastModified, out string lastModifiedString))
905+
{
906+
lastModified = DateTimeOffset.Parse(lastModifiedString, CultureInfo.InvariantCulture);
907+
}
908+
909+
return lastModified;
910+
}
897911
}
898912
}

sdk/storage/Azure.Storage.Files.Shares/tests/DirectoryClientTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,8 @@ public async Task SetMetadataAsync()
703703
IDictionary<string, string> metadata = BuildMetadata();
704704

705705
// Act
706-
await directory.SetMetadataAsync(metadata);
706+
Response<ShareDirectoryInfo> setMetadataResponse = await directory.SetMetadataAsync(metadata);
707+
Assert.AreNotEqual(DateTimeOffset.MinValue, setMetadataResponse.Value.LastModified);
707708

708709
// Assert
709710
Response<ShareDirectoryProperties> response = await directory.GetPropertiesAsync();

0 commit comments

Comments
 (0)