Skip to content

Commit 6108e65

Browse files
authored
Storage STG98/NFS 2 (#6404)
* feature * add test record
1 parent e30a466 commit 6108e65

File tree

6 files changed

+235
-4
lines changed

6 files changed

+235
-4
lines changed

sdk/storage/assets.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"AssetsRepo": "Azure/azure-sdk-assets",
33
"AssetsRepoPrefixPath": "cpp",
44
"TagPrefix": "cpp/storage",
5-
"Tag": "cpp/storage_50acb6a662"
5+
"Tag": "cpp/storage_7bea1dff90"
66
}

sdk/storage/azure-storage-files-shares/inc/azure/storage/files/shares/share_file_client.hpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,30 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
379379
const UploadFileRangeFromUriOptions& options = UploadFileRangeFromUriOptions(),
380380
const Azure::Core::Context& context = Azure::Core::Context()) const;
381381

382+
/**
383+
* @brief NFS only. Creates a symbolic link to the file specified by path.
384+
* @param linkText The absolution or relative path to the file to be linked to.
385+
* @param options Optional parameters to create this file's symbolic link.
386+
* @param context Context for cancelling long running operations.
387+
* @return Azure::Response<Models::CreateFileSymbolicLinkResult> containing the returned
388+
* information.
389+
*/
390+
Azure::Response<Models::CreateFileSymbolicLinkResult> CreateSymbolicLink(
391+
const std::string& linkText,
392+
const CreateSymbolicLinkOptions& options = CreateSymbolicLinkOptions(),
393+
const Azure::Core::Context& context = Azure::Core::Context()) const;
394+
395+
/**
396+
* @brief NFS only. Reads the value of the symbolic link.
397+
* @param options Optional parameters to get this file's symbolic link.
398+
* @param context Context for cancelling long running operations.
399+
* @return Azure::Response<Models::GetFileSymbolicLinkResult> containing the returned
400+
* information.
401+
*/
402+
Azure::Response<Models::GetFileSymbolicLinkResult> GetSymbolicLink(
403+
const GetSymbolicLinkOptions& options = GetSymbolicLinkOptions(),
404+
const Azure::Core::Context& context = Azure::Core::Context()) const;
405+
382406
/**
383407
* @brief NFS only. Creates a hard link to the file specified by path.
384408
* @param targetFile Path of the file to create the hard link to, not including the share.

sdk/storage/azure-storage-files-shares/inc/azure/storage/files/shares/share_options.hpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1387,6 +1387,53 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
13871387
{
13881388
};
13891389

1390+
/**
1391+
* @brief Optional parameters for
1392+
* #Azure::Storage::Files::Shares::ShareFileClient::CreateSymbolicLink.
1393+
*/
1394+
struct CreateSymbolicLinkOptions final
1395+
{
1396+
/**
1397+
* A name-value pair to associate with a file storage object.
1398+
*/
1399+
Storage::Metadata Metadata;
1400+
1401+
/**
1402+
* Creation time for the file or directory.
1403+
*/
1404+
Nullable<DateTime> CreatedOn;
1405+
1406+
/**
1407+
* Last write time for the file or directory.
1408+
*/
1409+
Nullable<DateTime> LastWrittenOn;
1410+
1411+
/**
1412+
* Specify the access condition for the path.
1413+
*/
1414+
LeaseAccessConditions AccessConditions;
1415+
1416+
/**
1417+
* NFS only. The owner user identifier (UID) to be set on the symbolic link. The default value
1418+
* is 0 (root).
1419+
*/
1420+
Nullable<std::string> Owner;
1421+
1422+
/**
1423+
* NFS only. The owner group identifier (GID) to be set on the symbolic link. The default value
1424+
* is 0 (root group).
1425+
*/
1426+
Nullable<std::string> Group;
1427+
};
1428+
1429+
/**
1430+
* @brief Optional parameters for
1431+
* #Azure::Storage::Files::Shares::ShareFileClient::GetSymbolicLink.
1432+
*/
1433+
struct GetSymbolicLinkOptions final
1434+
{
1435+
};
1436+
13901437
/**
13911438
* @brief Optional parameters for
13921439
* #Azure::Storage::Files::Shares::ShareFileClient::CreateHardLink.

sdk/storage/azure-storage-files-shares/inc/azure/storage/files/shares/share_responses.hpp

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,57 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
591591
FilePosixProperties PosixProperties;
592592
};
593593

594+
/**
595+
* @brief Response type for #Azure::Storage::Files::Shares::ShareFileClient::CreateSymbolicLink.
596+
*/
597+
struct CreateFileSymbolicLinkResult final
598+
{
599+
/**
600+
* The ETag contains a value which represents the version of the file, in quotes.
601+
*/
602+
Azure::ETag ETag;
603+
604+
/**
605+
* Returns the date and time the share was last modified. Any operation that modifies the
606+
* directory or its properties updates the last modified time. Operations on files do not
607+
* affect the last modified time of the directory.
608+
*/
609+
DateTime LastModified;
610+
611+
/**
612+
* The SMB related properties for the file.
613+
*/
614+
FileSmbProperties SmbProperties;
615+
616+
/**
617+
* The NFS related properties for the file.
618+
*/
619+
FilePosixProperties PosixProperties;
620+
};
621+
622+
/**
623+
* @brief Response type for #Azure::Storage::Files::Shares::ShareFileClient::GetSymbolicLink.
624+
*/
625+
struct GetFileSymbolicLinkResult final
626+
{
627+
/**
628+
* The ETag contains a value which represents the version of the file, in quotes.
629+
*/
630+
Azure::ETag ETag;
631+
/**
632+
* Returns the date and time the share was last modified. Any operation that modifies the
633+
* directory or its properties updates the last modified time. Operations on files do not
634+
* affect the last modified time of the directory.
635+
*/
636+
DateTime LastModified;
637+
/**
638+
* The path to the original file, the symbolic link is pointing to. The path is of type
639+
* string which is not resolved and is stored as is. The path can be absolute path or the
640+
* relative path depending on the content stored in the symbolic link file.
641+
*/
642+
std::string LinkText;
643+
};
644+
594645
/**
595646
* @brief Response type for #Azure::Storage::Files::Shares::ShareFileClient::CreateHardLink.
596647
*/

sdk/storage/azure-storage-files-shares/src/share_file_client.cpp

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1434,6 +1434,65 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
14341434
*m_pipeline, m_shareFileUrl, protocolLayerOptions, context);
14351435
}
14361436

1437+
Azure::Response<Models::CreateFileSymbolicLinkResult> ShareFileClient::CreateSymbolicLink(
1438+
const std::string& linkText,
1439+
const CreateSymbolicLinkOptions& options,
1440+
const Azure::Core::Context& context) const
1441+
{
1442+
_detail::FileClient::CreateFileSymbolicLinkOptions protocolLayerOptions;
1443+
protocolLayerOptions.LinkText = linkText;
1444+
if (options.CreatedOn.HasValue())
1445+
{
1446+
protocolLayerOptions.FileCreationTime = options.CreatedOn.Value().ToString(
1447+
Azure::DateTime::DateFormat::Rfc3339, DateTime::TimeFractionFormat::AllDigits);
1448+
}
1449+
1450+
if (options.LastWrittenOn.HasValue())
1451+
{
1452+
protocolLayerOptions.FileLastWriteTime = options.LastWrittenOn.Value().ToString(
1453+
Azure::DateTime::DateFormat::Rfc3339, DateTime::TimeFractionFormat::AllDigits);
1454+
}
1455+
1456+
protocolLayerOptions.FileRequestIntent = m_shareTokenIntent;
1457+
protocolLayerOptions.Owner = options.Owner;
1458+
protocolLayerOptions.Group = options.Group;
1459+
protocolLayerOptions.Metadata
1460+
= std::map<std::string, std::string>(options.Metadata.begin(), options.Metadata.end());
1461+
protocolLayerOptions.LeaseId = options.AccessConditions.LeaseId;
1462+
1463+
auto response = _detail::FileClient::CreateSymbolicLink(
1464+
*m_pipeline, m_shareFileUrl, protocolLayerOptions, context);
1465+
1466+
Models::CreateFileSymbolicLinkResult ret;
1467+
ret.ETag = std::move(response.Value.ETag);
1468+
ret.SmbProperties = std::move(response.Value.SmbProperties);
1469+
ret.LastModified = std::move(response.Value.LastModified);
1470+
ret.PosixProperties.FileMode = Models::NfsFileMode::ParseOctalFileMode(response.Value.FileMode);
1471+
ret.PosixProperties.Owner = std::move(response.Value.Owner);
1472+
ret.PosixProperties.Group = std::move(response.Value.Group);
1473+
ret.PosixProperties.NfsFileType = std::move(response.Value.NfsFileType);
1474+
return Azure::Response<Models::CreateFileSymbolicLinkResult>(
1475+
std::move(ret), std::move(response.RawResponse));
1476+
}
1477+
1478+
Azure::Response<Models::GetFileSymbolicLinkResult> ShareFileClient::GetSymbolicLink(
1479+
const GetSymbolicLinkOptions& options,
1480+
const Azure::Core::Context& context) const
1481+
{
1482+
(void)options;
1483+
_detail::FileClient::GetFileSymbolicLinkOptions protocolLayerOptions;
1484+
protocolLayerOptions.FileRequestIntent = m_shareTokenIntent;
1485+
auto response = _detail::FileClient::GetSymbolicLink(
1486+
*m_pipeline, m_shareFileUrl, protocolLayerOptions, context);
1487+
1488+
Models::GetFileSymbolicLinkResult ret;
1489+
ret.ETag = std::move(response.Value.ETag);
1490+
ret.LastModified = std::move(response.Value.LastModified);
1491+
ret.LinkText = std::move(response.Value.LinkText);
1492+
return Azure::Response<Models::GetFileSymbolicLinkResult>(
1493+
std::move(ret), std::move(response.RawResponse));
1494+
}
1495+
14371496
Azure::Response<Models::CreateFileHardLinkResult> ShareFileClient::CreateHardLink(
14381497
const std::string& targetFile,
14391498
const CreateHardLinkOptions& options,

sdk/storage/azure-storage-files-shares/test/ut/share_file_client_test.cpp

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2212,7 +2212,7 @@ namespace Azure { namespace Storage { namespace Test {
22122212
}
22132213
}
22142214

2215-
TEST_F(FileShareFileClientTest, PremiumNfsProperties_PLAYBACKONLY_)
2215+
TEST_F(FileShareFileClientTest, PremiumPosixProperties_PLAYBACKONLY_)
22162216
{
22172217
auto shareServiceClient = *m_premiumShareServiceClient;
22182218

@@ -2333,6 +2333,56 @@ namespace Azure { namespace Storage { namespace Test {
23332333
setOptions.PosixProperties.Owner.Value());
23342334
EXPECT_TRUE(downloadToResult.Details.PosixProperties.LinkCount.HasValue());
23352335

2336+
// Create SymbolicLink
2337+
std::string sourceUrl = fileClient.GetUrl();
2338+
auto symbolicLinkClient
2339+
= shareClient.GetRootDirectoryClient().GetFileClient(LowercaseRandomString());
2340+
Files::Shares::CreateSymbolicLinkOptions createSymbolicLinkOptions;
2341+
createSymbolicLinkOptions.CreatedOn = otherProperties.SmbProperties.CreatedOn;
2342+
createSymbolicLinkOptions.LastWrittenOn = otherProperties.SmbProperties.LastWrittenOn;
2343+
2344+
createSymbolicLinkOptions.Metadata = RandomMetadata();
2345+
createSymbolicLinkOptions.Group = "123";
2346+
createSymbolicLinkOptions.Owner = "456";
2347+
Files::Shares::Models::CreateFileSymbolicLinkResult createSymbolicLinkResult;
2348+
EXPECT_NO_THROW(
2349+
createSymbolicLinkResult
2350+
= symbolicLinkClient.CreateSymbolicLink(sourceUrl, createSymbolicLinkOptions).Value);
2351+
EXPECT_TRUE(createSymbolicLinkResult.PosixProperties.FileMode.HasValue());
2352+
EXPECT_EQ(
2353+
createSymbolicLinkResult.PosixProperties.FileMode.Value().ToOctalFileMode(), octalMode);
2354+
EXPECT_TRUE(createSymbolicLinkResult.PosixProperties.Group.HasValue());
2355+
EXPECT_EQ(
2356+
createSymbolicLinkResult.PosixProperties.Group.Value(),
2357+
createSymbolicLinkOptions.Group.Value());
2358+
EXPECT_TRUE(createSymbolicLinkResult.PosixProperties.FileMode.HasValue());
2359+
EXPECT_EQ(
2360+
createSymbolicLinkResult.PosixProperties.Owner.Value(),
2361+
createSymbolicLinkOptions.Owner.Value());
2362+
EXPECT_TRUE(createSymbolicLinkResult.PosixProperties.NfsFileType.HasValue());
2363+
EXPECT_EQ(
2364+
createSymbolicLinkResult.PosixProperties.NfsFileType.Value(),
2365+
Files::Shares::Models::NfsFileType::SymLink);
2366+
EXPECT_EQ(
2367+
createSymbolicLinkResult.SmbProperties.CreatedOn.Value(),
2368+
createSymbolicLinkOptions.CreatedOn.Value());
2369+
EXPECT_EQ(
2370+
createSymbolicLinkResult.SmbProperties.LastWrittenOn.Value(),
2371+
createSymbolicLinkOptions.LastWrittenOn.Value());
2372+
EXPECT_TRUE(createSymbolicLinkResult.SmbProperties.ChangedOn.HasValue());
2373+
EXPECT_TRUE(!createSymbolicLinkResult.SmbProperties.FileId.empty());
2374+
EXPECT_TRUE(!createSymbolicLinkResult.SmbProperties.ParentFileId.empty());
2375+
EXPECT_TRUE(createSymbolicLinkResult.ETag.HasValue());
2376+
2377+
// Get SymbolicLink
2378+
Files::Shares::Models::GetFileSymbolicLinkResult getSymbolicLinkResult;
2379+
EXPECT_NO_THROW(getSymbolicLinkResult = symbolicLinkClient.GetSymbolicLink().Value);
2380+
EXPECT_TRUE(getSymbolicLinkResult.ETag.HasValue());
2381+
if (!m_testContext.IsPlaybackMode())
2382+
{
2383+
EXPECT_EQ(Azure::Core::Url::Decode(getSymbolicLinkResult.LinkText), sourceUrl);
2384+
}
2385+
23362386
// Create HardLink
23372387
auto hardLinkClient
23382388
= shareClient.GetRootDirectoryClient().GetFileClient(LowercaseRandomString());
@@ -2418,7 +2468,7 @@ namespace Azure { namespace Storage { namespace Test {
24182468
Files::Shares::Models::NfsFileType::Regular);
24192469
}
24202470

2421-
TEST_F(FileShareFileClientTest, PremiumNfsPropertiesForCopy_PLAYBACKONLY_)
2471+
TEST_F(FileShareFileClientTest, PremiumPosixPropertiesForCopy_PLAYBACKONLY_)
24222472
{
24232473
auto shareServiceClient = *m_premiumShareServiceClient;
24242474

@@ -2510,7 +2560,7 @@ namespace Azure { namespace Storage { namespace Test {
25102560
EXPECT_EQ(
25112561
properties.PosixProperties.Owner.Value(), createOptions.PosixProperties.Owner.Value());
25122562

2513-
// Copy without NfsProperties
2563+
// Copy without PosixProperties
25142564
copyOptions = Files::Shares::StartFileCopyOptions();
25152565
copyOptions.SmbPropertiesToCopy = Files::Shares::CopyableFileSmbPropertyFlags::None;
25162566
destFileClient = shareClient.GetRootDirectoryClient().GetFileClient(LowercaseRandomString());

0 commit comments

Comments
 (0)