Skip to content

Commit 9e529cd

Browse files
authored
[Storage] [DataMovement] NFS over REST Cleanup (Azure#50304)
* initial commit * rerecorded tests * more documentation updates * tiny test enhancements * Added additional tests for DestinationOptionsOverride * tiny test change
1 parent 11554e3 commit 9e529cd

File tree

11 files changed

+586
-58
lines changed

11 files changed

+586
-58
lines changed

sdk/storage/Azure.Storage.DataMovement.Blobs.Files.Shares/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": "net",
44
"TagPrefix": "net/storage/Azure.Storage.DataMovement.Blobs.Files.Shares",
5-
"Tag": "net/storage/Azure.Storage.DataMovement.Blobs.Files.Shares_9cbe89e314"
5+
"Tag": "net/storage/Azure.Storage.DataMovement.Blobs.Files.Shares_3cdf992080"
66
}

sdk/storage/Azure.Storage.DataMovement.Files.Shares/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": "net",
44
"TagPrefix": "net/storage/Azure.Storage.DataMovement.Files.Shares",
5-
"Tag": "net/storage/Azure.Storage.DataMovement.Files.Shares_349100bbca"
5+
"Tag": "net/storage/Azure.Storage.DataMovement.Files.Shares_f6f89a43f9"
66
}

sdk/storage/Azure.Storage.DataMovement.Files.Shares/src/DataMovementSharesExtensions.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,15 @@ public static Metadata GetFileMetadata(
5454
? (Metadata)metadata
5555
: default;
5656

57+
public static Metadata GetDirectoryMetadata(
58+
this ShareFileStorageResourceOptions options,
59+
IDictionary<string, object> properties)
60+
=> (options?._isDirectoryMetadataSet ?? false)
61+
? options?.DirectoryMetadata
62+
: properties?.TryGetValue(DataMovementConstants.ResourceProperties.Metadata, out object metadata) == true
63+
? (Metadata)metadata
64+
: default;
65+
5766
public static string GetFilePermission(
5867
this ShareFileStorageResourceOptions options,
5968
StorageResourceItemProperties sourceProperties)

sdk/storage/Azure.Storage.DataMovement.Files.Shares/src/ShareDirectoryStorageResourceContainer.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,9 @@ ShareDirectoryStorageResourceContainer destinationStorageResourceContainer
6868
= destinationContainer as ShareDirectoryStorageResourceContainer;
6969
ShareFileStorageResourceOptions destinationOptions = destinationStorageResourceContainer.ResourceOptions;
7070
// both source and destination must be SMB
71-
if (((ResourceOptions?.ShareProtocol ?? ShareProtocol.Smb) == ShareProtocol.Smb)
72-
&& ((destinationOptions?.ShareProtocol ?? ShareProtocol.Smb) == ShareProtocol.Smb))
71+
ShareProtocol sourceShareProtocol = ResourceOptions?.ShareProtocol ?? ShareProtocol.Smb;
72+
ShareProtocol destinationShareProtocol = destinationOptions?.ShareProtocol ?? ShareProtocol.Smb;
73+
if (sourceShareProtocol == ShareProtocol.Smb && destinationShareProtocol == ShareProtocol.Smb)
7374
{
7475
traits = ShareFileTraits.Attributes;
7576
if (destinationOptions?.FilePermissions ?? false)
@@ -168,7 +169,7 @@ protected override async Task CreateIfNotExistsAsync(
168169
StorageResourceContainerProperties sourceProperties,
169170
CancellationToken cancellationToken = default)
170171
{
171-
IDictionary<string, string> metadata = ResourceOptions?.GetFileMetadata(sourceProperties?.RawProperties);
172+
IDictionary<string, string> metadata = ResourceOptions?.GetDirectoryMetadata(sourceProperties?.RawProperties);
172173
string filePermission = ResourceOptions?.GetFilePermission(sourceProperties);
173174
FileSmbProperties smbProperties = ResourceOptions?.GetFileSmbProperties(sourceProperties);
174175
FilePosixProperties filePosixProperties = ResourceOptions?.GetFilePosixProperties(sourceProperties);
@@ -196,9 +197,10 @@ protected override async Task ValidateTransferAsync(
196197
// ShareDirectory to ShareDirectory Copy transfer
197198
if (sourceResource is ShareDirectoryStorageResourceContainer sourceShareDirectoryResource)
198199
{
200+
ShareProtocol sourceProtocol = sourceShareDirectoryResource.ResourceOptions?.ShareProtocol ?? ShareProtocol.Smb;
201+
ShareProtocol destinationProtocol = ResourceOptions?.ShareProtocol ?? ShareProtocol.Smb;
199202
// Ensure the transfer is supported (NFS -> NFS and SMB -> SMB)
200-
if ((ResourceOptions?.ShareProtocol ?? ShareProtocol.Smb)
201-
!= (sourceShareDirectoryResource.ResourceOptions?.ShareProtocol ?? ShareProtocol.Smb))
203+
if (destinationProtocol != sourceProtocol)
202204
{
203205
throw Errors.ShareTransferNotSupported();
204206
}

sdk/storage/Azure.Storage.DataMovement.Files.Shares/src/ShareFileStorageResource.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,9 @@ protected override async Task SetPermissionsAsync(
283283
{
284284
ShareFileStorageResource sourceShareFile = (ShareFileStorageResource)sourceResource;
285285
// both source and destination must be SMB and destination FilePermission option must be set.
286-
if (((sourceShareFile._options?.ShareProtocol ?? ShareProtocol.Smb) == ShareProtocol.Smb)
287-
&& ((_options?.ShareProtocol ?? ShareProtocol.Smb) == ShareProtocol.Smb)
286+
ShareProtocol sourceShareProtocol = sourceShareFile._options?.ShareProtocol ?? ShareProtocol.Smb;
287+
ShareProtocol destinationShareProtocol = _options?.ShareProtocol ?? ShareProtocol.Smb;
288+
if (sourceShareProtocol == ShareProtocol.Smb && destinationShareProtocol == ShareProtocol.Smb
288289
&& (_options?.FilePermissions ?? false))
289290
{
290291
string permissionsValue = sourceProperties?.RawProperties?.GetPermission();
@@ -394,9 +395,10 @@ protected override async Task ValidateTransferAsync(
394395
// ShareFile to ShareFile Copy transfer
395396
if (sourceResource is ShareFileStorageResource sourceShareFileResource)
396397
{
398+
ShareProtocol sourceProtocol = sourceShareFileResource._options?.ShareProtocol ?? ShareProtocol.Smb;
399+
ShareProtocol destinationProtocol = _options?.ShareProtocol ?? ShareProtocol.Smb;
397400
// Ensure the transfer is supported (NFS -> NFS and SMB -> SMB)
398-
if ((_options?.ShareProtocol ?? ShareProtocol.Smb)
399-
!= (sourceShareFileResource._options?.ShareProtocol ?? ShareProtocol.Smb))
401+
if (destinationProtocol != sourceProtocol)
400402
{
401403
throw Errors.ShareTransferNotSupported();
402404
}

sdk/storage/Azure.Storage.DataMovement.Files.Shares/src/ShareFileStorageResourceOptions.cs

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public class ShareFileStorageResourceOptions
4848

4949
/// <summary>
5050
/// Optional. Specifies whether protocol validation for the resource should be skipped before starting the transfer.
51-
/// By default this value is set to false.
51+
/// By default this value is set to false. This is intended to be set on the source and destination Share.
5252
/// Applies to only Share-to-Share copy transfers.
5353
/// Note: Protocol validation requires share-level read access.
5454
/// </summary>
@@ -57,11 +57,12 @@ public class ShareFileStorageResourceOptions
5757
/// <summary>
5858
/// Optional. Specifies whether the Share uses NFS or SMB protocol.
5959
/// By default this value is set to SMB.
60-
/// Applies to copy, upload, and download transfers.
60+
/// This is intended to be set on the source and destination Share.
61+
/// Applies to copy, upload, and download transfers. Protocol validation only applies to Share-to-Share copy transfers.
6162
///
6263
/// Note: Only NFS -> NFS and SMB -> SMB transfers are currently supported.
63-
/// For NFS Share-to-Share Copy and Download transfers, Hardlinks will be copied as regular files and Symbolic links are skipped.
64-
/// For NFS Upload transfers, Hardlinks will be copied as regular files and Symbolic links are not supported.
64+
/// For NFS Share-to-Share Copy and Download transfers, Hard links will be copied as regular files and Symbolic links are skipped.
65+
/// For NFS Upload transfers, Hard links will be copied as regular files and Symbolic links are not supported.
6566
/// </summary>
6667
public ShareProtocol ShareProtocol { get; set; } = ShareProtocol.Smb;
6768

@@ -83,9 +84,9 @@ public class ShareFileStorageResourceOptions
8384

8485
/// <summary>
8586
/// Optional. Sets the Cache Control header which
86-
/// specifies directives for caching mechanisms.
87+
/// specifies directives for caching mechanisms. This is intended to be set on the destination Share.
8788
///
88-
/// By default preserves the Cache Control from the source. If explicitly set to null, the Cache Control will not be preserved and set to null.
89+
/// By default preserves the Cache Control from the source for copy transfers. If explicitly set, the Cache Control of the destination will be set to this value.
8990
///
9091
/// Applies to upload and copy transfers.
9192
/// </summary>
@@ -105,9 +106,9 @@ public string CacheControl
105106
/// payload, and also can be used to attach additional metadata. For
106107
/// example, if set to attachment, it indicates that the user-agent
107108
/// should not display the response, but instead show a Save As dialog
108-
/// with a filename other than the blob name specified.
109+
/// with a filename other than the blob name specified. This is intended to be set on the destination Share.
109110
///
110-
/// By default preserves the Content Disposition from the source. If explicitly set to null, the Content Disposition will not be preserved and set to null.
111+
/// By default preserves the Content Disposition from the source for copy transfers. If explicitly set, the Content Disposition of the destination will be set to this value.
111112
///
112113
/// Applies to upload and copy transfers.
113114
/// </summary>
@@ -126,9 +127,9 @@ public string ContentDisposition
126127
/// specifies which content encodings have been applied to the blob.
127128
/// This value is returned to the client when the Get Blob operation
128129
/// is performed on the blob resource. The client can use this value
129-
/// when returned to decode the blob content.
130+
/// when returned to decode the blob content. This is intended to be set on the destination Share.
130131
///
131-
/// By default preserves the Content Encoding from the source. If explicitly set to null, the Content Encoding will not be preserved and set to null.
132+
/// By default preserves the Content Encoding from the source for copy transfers. If explicitly set, the Content Encoding of the destination will be set to this value.
132133
///
133134
/// Applies to upload and copy transfers.
134135
/// </summary>
@@ -144,9 +145,9 @@ public string[] ContentEncoding
144145

145146
/// <summary>
146147
/// Optional. Sets the Content Language header which
147-
/// specifies the natural languages used by this resource.
148+
/// specifies the natural languages used by this resource. This is intended to be set on the destination Share.
148149
///
149-
/// By default preserves the Content Language from the source. If explicitly set to null, the Content Language will not be preserved and set to null.
150+
/// By default preserves the Content Language from the source for copy transfers. If explicitly set, the Content Language of the destination will be set to this value.
150151
///
151152
/// Applies to upload and copy transfers.
152153
/// </summary>
@@ -162,9 +163,9 @@ public string[] ContentLanguage
162163

163164
/// <summary>
164165
/// Optional. Sets the Content Type header which
165-
/// specifies the MIME content type of the blob.
166+
/// specifies the MIME content type of the file. This is intended to be set on the destination Share.
166167
///
167-
/// By default preserves the Content Type from the source. If explicitly set to null, the Content Type will not be preserved and set to null.
168+
/// By default preserves the Content Type from the source for copy transfers. If explicitly set, the Content Type of the destination will be set to this value.
168169
///
169170
/// Applies to upload and copy transfers.
170171
/// </summary>
@@ -179,9 +180,9 @@ public string ContentType
179180
}
180181

181182
/// <summary>
182-
/// The file system attributes for this file.
183+
/// The file system attributes for this file/directory. This is intended to be set on the destination Share.
183184
///
184-
/// By default preserves the File Attributes from the source. If explicitly set to null, the File Attributes will not be preserved and set to null.
185+
/// By default preserves the Attributes from the source for copy transfers. If explicitly set, the Attributes of the destination will be set to this value.
185186
/// </summary>
186187
public NtfsFileAttributes? FileAttributes
187188
{
@@ -194,20 +195,20 @@ public NtfsFileAttributes? FileAttributes
194195
}
195196

196197
/// <summary>
197-
/// To preserve the file permissions. This is intended to be set on the destination Share.
198+
/// To preserve the file/directory permissions. This is intended to be set on the destination Share.
198199
/// If set to true, the permissions will be preserved from the source Share to the destination Share.
199200
/// For SMB, this requires a <see href="https://learn.microsoft.com/en-us/rest/api/storageservices/create-permission">Create Share Permissions</see> operation,
200201
/// which is a operation called on the Destination Share, which requires Share level permissions.
201202
///
202-
/// By default the file permissions will not be preserved from the source Share to the destination Share. If explicitly set to null, the File Permissions will not be preserved.
203+
/// By default the permissions will not be preserved from the source Share to the destination Share. If explicitly set to null, the permissions will not be preserved.
203204
/// Applies only to copy transfers.
204205
/// </summary>
205206
public bool? FilePermissions { get; set; }
206207

207208
/// <summary>
208-
/// The creation time of the file.
209+
/// The creation time of the file/directory. This is intended to be set on the destination Share.
209210
///
210-
/// By default preserves the File Created On Time from the source. If explicitly set to null, the File Created On Time will not be preserved and set to `now`.
211+
/// By default preserves the Created On Time from the source for copy transfers. If explicitly set, the Created On Time of the destination will be set to this value.
211212
/// </summary>
212213
public DateTimeOffset? FileCreatedOn
213214
{
@@ -220,9 +221,10 @@ public DateTimeOffset? FileCreatedOn
220221
}
221222

222223
/// <summary>
223-
/// The last write time of the file.
224+
/// The last write time of the file/directory. This is intended to be set on the destination Share.
224225
///
225-
/// By default preserves the File Last Written On Time from the source. If explicitly set to null, the File Last Written On Time will not be preserved and set to `now`.
226+
/// By default preserves the Last Written On Time from the source for copy transfers. If explicitly set, the Last Written On Time of the destination will be set to this value.
227+
/// Note: For share directories, the Last Written On Time may not be preserved.
226228
/// </summary>
227229
public DateTimeOffset? FileLastWrittenOn
228230
{
@@ -235,9 +237,9 @@ public DateTimeOffset? FileLastWrittenOn
235237
}
236238

237239
/// <summary>
238-
/// The change time of the file.
240+
/// The change time of the file/directory. This is intended to be set on the destination Share.
239241
///
240-
/// By default preserves the File Changed On Time from the source. If explicitly set to null, the File Changed On Time will not be preserved and set to `now`.
242+
/// By default preserves the Changed On Time from the source for copy transfers. If explicitly set, the Changed On Time of the destination will be set to this value.
241243
/// </summary>
242244
public DateTimeOffset? FileChangedOn
243245
{
@@ -250,11 +252,11 @@ public DateTimeOffset? FileChangedOn
250252
}
251253

252254
/// <summary>
253-
/// Optional. Defines custom metadata to set on the destination resource.
255+
/// Optional. Defines custom metadata to set on the destination directory resource. This is intended to be set on the destination Share.
254256
///
255257
/// Applies to upload and copy transfers.
256258
///
257-
/// Preserves Metadata from the source by default. If explicitly set to null, the Metadata will not be preserved and set to null.
259+
/// By default preserves Metadata from the source for copy transfers. If explicitly set, the Metadata of the destination directory will be set to this value.
258260
/// </summary>
259261
#pragma warning disable CA2227 // Collection properties should be readonly
260262
public Metadata DirectoryMetadata
@@ -269,11 +271,11 @@ public Metadata DirectoryMetadata
269271
#pragma warning restore CA2227 // Collection properties should be readonly
270272

271273
/// <summary>
272-
/// Optional. Defines custom metadata to set on the destination resource.
274+
/// Optional. Defines custom metadata to set on the destination file resource. This is intended to be set on the destination Share.
273275
///
274276
/// Applies to upload and copy transfers.
275277
///
276-
/// Preserves Metadata from the source by default. If explicitly set to null, the Metadata will not be preserved and set to null.
278+
/// By default preserves Metadata from the source for copy transfers. If explicitly set, the Metadata of the destination file will be set to this value.
277279
/// </summary>
278280
#pragma warning disable CA2227 // Collection properties should be readonly
279281
public Metadata FileMetadata

0 commit comments

Comments
 (0)