Fixed a bug where unspecified SMB properties got overwritten rather than preserved by SetProperties() (#2632)

* fix bug: Set{File/Directory}Properties overwrites unspecified values

* CL
This commit is contained in:
JinmingHu 2021-07-16 10:08:50 +08:00 committed by GitHub
parent 0140a4add6
commit 59c46e2ab1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 61 additions and 7 deletions

View File

@ -8,6 +8,8 @@
### Bugs Fixed
- Fixed a bug where unspecified SMB properties got overwritten rather than preserved by `SetProperties()`.
### Other Changes
## 12.0.1 (2021-07-07)

View File

@ -241,6 +241,10 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
{
auto protocolLayerOptions = _detail::ShareRestClient::Directory::SetPropertiesOptions();
protocolLayerOptions.FileAttributes = smbProperties.Attributes.ToString();
if (protocolLayerOptions.FileAttributes.empty())
{
protocolLayerOptions.FileAttributes = FilePreserveSmbProperties;
}
if (smbProperties.CreatedOn.HasValue())
{
protocolLayerOptions.FileCreationTime = smbProperties.CreatedOn.Value().ToString(
@ -248,7 +252,7 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
}
else
{
protocolLayerOptions.FileCreationTime = std::string(FileDefaultTimeValue);
protocolLayerOptions.FileCreationTime = FilePreserveSmbProperties;
}
if (smbProperties.LastWrittenOn.HasValue())
{
@ -257,7 +261,7 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
}
else
{
protocolLayerOptions.FileLastWriteTime = std::string(FileDefaultTimeValue);
protocolLayerOptions.FileLastWriteTime = FilePreserveSmbProperties;
}
if (options.FilePermission.HasValue())
{
@ -269,7 +273,7 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
}
else
{
protocolLayerOptions.FilePermission = std::string(FileInheritPermission);
protocolLayerOptions.FilePermission = FilePreserveSmbProperties;
}
return _detail::ShareRestClient::Directory::SetProperties(
m_shareDirectoryUrl, *m_pipeline, context, protocolLayerOptions);

View File

@ -402,7 +402,7 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
protocolLayerOptions.FileAttributes = smbProperties.Attributes.ToString();
if (protocolLayerOptions.FileAttributes.empty())
{
protocolLayerOptions.FileAttributes = Models::FileAttributes::None.ToString();
protocolLayerOptions.FileAttributes = FilePreserveSmbProperties;
}
if (smbProperties.CreatedOn.HasValue())
{
@ -411,7 +411,7 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
}
else
{
protocolLayerOptions.FileCreationTime = std::string(FileDefaultTimeValue);
protocolLayerOptions.FileCreationTime = FilePreserveSmbProperties;
}
if (smbProperties.LastWrittenOn.HasValue())
{
@ -420,7 +420,7 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
}
else
{
protocolLayerOptions.FileLastWriteTime = std::string(FileDefaultTimeValue);
protocolLayerOptions.FileLastWriteTime = FilePreserveSmbProperties;
}
protocolLayerOptions.XMsContentLength = options.Size;
protocolLayerOptions.LeaseIdOptional = options.AccessConditions.LeaseId;
@ -434,7 +434,7 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
}
else
{
protocolLayerOptions.FilePermission = std::string(FileInheritPermission);
protocolLayerOptions.FilePermission = FilePreserveSmbProperties;
}
if (!httpHeaders.ContentType.empty())

View File

@ -316,6 +316,30 @@ namespace Azure { namespace Storage { namespace Test {
}
}
TEST_F(FileShareDirectoryClientTest, SmbPropertiesDefaultValue)
{
auto directoryClient
= m_shareClient->GetRootDirectoryClient().GetSubdirectoryClient(RandomString());
directoryClient.Create();
auto smbProperties = directoryClient.GetProperties().Value.SmbProperties;
EXPECT_EQ(smbProperties.Attributes, Files::Shares::Models::FileAttributes::Directory);
ASSERT_TRUE(smbProperties.CreatedOn.HasValue());
EXPECT_TRUE(IsValidTime(smbProperties.CreatedOn.Value()));
ASSERT_TRUE(smbProperties.LastWrittenOn.HasValue());
EXPECT_TRUE(IsValidTime(smbProperties.LastWrittenOn.Value()));
ASSERT_TRUE(smbProperties.ChangedOn.HasValue());
EXPECT_TRUE(IsValidTime(smbProperties.ChangedOn.Value()));
directoryClient.SetProperties(Files::Shares::Models::FileSmbProperties());
auto smbProperties2 = directoryClient.GetProperties().Value.SmbProperties;
EXPECT_EQ(smbProperties2.PermissionKey.Value(), smbProperties.PermissionKey.Value());
EXPECT_EQ(smbProperties2.Attributes, smbProperties.Attributes);
EXPECT_EQ(smbProperties2.CreatedOn.Value(), smbProperties.CreatedOn.Value());
EXPECT_EQ(smbProperties2.LastWrittenOn.Value(), smbProperties.LastWrittenOn.Value());
EXPECT_NE(smbProperties2.ChangedOn.Value(), smbProperties.ChangedOn.Value());
}
TEST_F(FileShareDirectoryClientTest, ListFilesAndDirectoriesSinglePageTest)
{
// Setup

View File

@ -258,6 +258,30 @@ namespace Azure { namespace Storage { namespace Test {
}
}
TEST_F(FileShareFileClientTest, SmbPropertiesDefaultValue)
{
auto fileClient = m_shareClient->GetRootDirectoryClient().GetFileClient(RandomString());
fileClient.Create(1024);
auto smbProperties = fileClient.GetProperties().Value.SmbProperties;
EXPECT_EQ(smbProperties.Attributes, Files::Shares::Models::FileAttributes::Archive);
ASSERT_TRUE(smbProperties.CreatedOn.HasValue());
EXPECT_TRUE(IsValidTime(smbProperties.CreatedOn.Value()));
ASSERT_TRUE(smbProperties.LastWrittenOn.HasValue());
EXPECT_TRUE(IsValidTime(smbProperties.LastWrittenOn.Value()));
ASSERT_TRUE(smbProperties.ChangedOn.HasValue());
EXPECT_TRUE(IsValidTime(smbProperties.ChangedOn.Value()));
fileClient.SetProperties(
Files::Shares::Models::FileHttpHeaders(), Files::Shares::Models::FileSmbProperties());
auto smbProperties2 = fileClient.GetProperties().Value.SmbProperties;
EXPECT_EQ(smbProperties2.PermissionKey.Value(), smbProperties.PermissionKey.Value());
EXPECT_EQ(smbProperties2.Attributes, smbProperties.Attributes);
EXPECT_EQ(smbProperties2.CreatedOn.Value(), smbProperties.CreatedOn.Value());
EXPECT_EQ(smbProperties2.LastWrittenOn.Value(), smbProperties.LastWrittenOn.Value());
EXPECT_NE(smbProperties2.ChangedOn.Value(), smbProperties.ChangedOn.Value());
}
TEST_F(FileShareFileClientTest, HandlesFunctionalityWorks)
{
auto result = m_fileClient->ListHandles();