Skip to content

Commit 3c12e5e

Browse files
authored
Added ModeCopyMode and OwnerCopyMode to Copy File (Azure#47440)
1 parent 76fcba8 commit 3c12e5e

File tree

9 files changed

+109
-22
lines changed

9 files changed

+109
-22
lines changed

sdk/storage/Azure.Storage.Files.Shares/api/Azure.Storage.Files.Shares.net6.0.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,11 @@ public static partial class FilesModelFactory
545545
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
546546
public static Azure.Storage.Files.Shares.Models.ShareFileProperties StorageFileProperties(System.DateTimeOffset lastModified, System.Collections.Generic.IDictionary<string, string> metadata, long contentLength, string contentType, Azure.ETag eTag, byte[] contentHash, System.Collections.Generic.IEnumerable<string> contentEncoding, string cacheControl, string contentDisposition, System.Collections.Generic.IEnumerable<string> contentLanguage, System.DateTimeOffset copyCompletedOn, string copyStatusDescription, string copyId, string copyProgress, string copySource, Azure.Storage.Files.Shares.Models.CopyStatus copyStatus, bool isServerEncrypted, string fileAttributes, System.DateTimeOffset fileCreationTime, System.DateTimeOffset fileLastWriteTime, System.DateTimeOffset fileChangeTime, string filePermissionKey, string fileId, string fileParentId) { throw null; }
547547
}
548+
public enum ModeCopyMode
549+
{
550+
Source = 0,
551+
Override = 1,
552+
}
548553
public partial class NfsFileMode
549554
{
550555
public NfsFileMode() { }
@@ -593,6 +598,11 @@ public enum NtfsFileAttributes
593598
NotContentIndexed = 256,
594599
NoScrubData = 512,
595600
}
601+
public enum OwnerCopyMode
602+
{
603+
Source = 0,
604+
Override = 1,
605+
}
596606
public enum PermissionCopyMode
597607
{
598608
Source = 0,
@@ -837,6 +847,8 @@ public ShareFileCopyOptions() { }
837847
public Azure.Storage.Files.Shares.Models.PermissionCopyMode? FilePermissionCopyMode { get { throw null; } set { } }
838848
public bool? IgnoreReadOnly { get { throw null; } set { } }
839849
public System.Collections.Generic.IDictionary<string, string> Metadata { get { throw null; } set { } }
850+
public Azure.Storage.Files.Shares.Models.ModeCopyMode? ModeCopyMode { get { throw null; } set { } }
851+
public Azure.Storage.Files.Shares.Models.OwnerCopyMode? OwnerCopyMode { get { throw null; } set { } }
840852
public Azure.Storage.Files.Shares.Models.FilePermissionFormat? PermissionFormat { get { throw null; } set { } }
841853
public Azure.Storage.Files.Shares.Models.FilePosixProperties PosixProperties { get { throw null; } set { } }
842854
public Azure.Storage.Files.Shares.Models.FileSmbProperties SmbProperties { get { throw null; } set { } }

sdk/storage/Azure.Storage.Files.Shares/api/Azure.Storage.Files.Shares.net8.0.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,11 @@ public static partial class FilesModelFactory
545545
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
546546
public static Azure.Storage.Files.Shares.Models.ShareFileProperties StorageFileProperties(System.DateTimeOffset lastModified, System.Collections.Generic.IDictionary<string, string> metadata, long contentLength, string contentType, Azure.ETag eTag, byte[] contentHash, System.Collections.Generic.IEnumerable<string> contentEncoding, string cacheControl, string contentDisposition, System.Collections.Generic.IEnumerable<string> contentLanguage, System.DateTimeOffset copyCompletedOn, string copyStatusDescription, string copyId, string copyProgress, string copySource, Azure.Storage.Files.Shares.Models.CopyStatus copyStatus, bool isServerEncrypted, string fileAttributes, System.DateTimeOffset fileCreationTime, System.DateTimeOffset fileLastWriteTime, System.DateTimeOffset fileChangeTime, string filePermissionKey, string fileId, string fileParentId) { throw null; }
547547
}
548+
public enum ModeCopyMode
549+
{
550+
Source = 0,
551+
Override = 1,
552+
}
548553
public partial class NfsFileMode
549554
{
550555
public NfsFileMode() { }
@@ -593,6 +598,11 @@ public enum NtfsFileAttributes
593598
NotContentIndexed = 256,
594599
NoScrubData = 512,
595600
}
601+
public enum OwnerCopyMode
602+
{
603+
Source = 0,
604+
Override = 1,
605+
}
596606
public enum PermissionCopyMode
597607
{
598608
Source = 0,
@@ -837,6 +847,8 @@ public ShareFileCopyOptions() { }
837847
public Azure.Storage.Files.Shares.Models.PermissionCopyMode? FilePermissionCopyMode { get { throw null; } set { } }
838848
public bool? IgnoreReadOnly { get { throw null; } set { } }
839849
public System.Collections.Generic.IDictionary<string, string> Metadata { get { throw null; } set { } }
850+
public Azure.Storage.Files.Shares.Models.ModeCopyMode? ModeCopyMode { get { throw null; } set { } }
851+
public Azure.Storage.Files.Shares.Models.OwnerCopyMode? OwnerCopyMode { get { throw null; } set { } }
840852
public Azure.Storage.Files.Shares.Models.FilePermissionFormat? PermissionFormat { get { throw null; } set { } }
841853
public Azure.Storage.Files.Shares.Models.FilePosixProperties PosixProperties { get { throw null; } set { } }
842854
public Azure.Storage.Files.Shares.Models.FileSmbProperties SmbProperties { get { throw null; } set { } }

sdk/storage/Azure.Storage.Files.Shares/api/Azure.Storage.Files.Shares.netstandard2.0.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,11 @@ public static partial class FilesModelFactory
545545
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
546546
public static Azure.Storage.Files.Shares.Models.ShareFileProperties StorageFileProperties(System.DateTimeOffset lastModified, System.Collections.Generic.IDictionary<string, string> metadata, long contentLength, string contentType, Azure.ETag eTag, byte[] contentHash, System.Collections.Generic.IEnumerable<string> contentEncoding, string cacheControl, string contentDisposition, System.Collections.Generic.IEnumerable<string> contentLanguage, System.DateTimeOffset copyCompletedOn, string copyStatusDescription, string copyId, string copyProgress, string copySource, Azure.Storage.Files.Shares.Models.CopyStatus copyStatus, bool isServerEncrypted, string fileAttributes, System.DateTimeOffset fileCreationTime, System.DateTimeOffset fileLastWriteTime, System.DateTimeOffset fileChangeTime, string filePermissionKey, string fileId, string fileParentId) { throw null; }
547547
}
548+
public enum ModeCopyMode
549+
{
550+
Source = 0,
551+
Override = 1,
552+
}
548553
public partial class NfsFileMode
549554
{
550555
public NfsFileMode() { }
@@ -593,6 +598,11 @@ public enum NtfsFileAttributes
593598
NotContentIndexed = 256,
594599
NoScrubData = 512,
595600
}
601+
public enum OwnerCopyMode
602+
{
603+
Source = 0,
604+
Override = 1,
605+
}
596606
public enum PermissionCopyMode
597607
{
598608
Source = 0,
@@ -837,6 +847,8 @@ public ShareFileCopyOptions() { }
837847
public Azure.Storage.Files.Shares.Models.PermissionCopyMode? FilePermissionCopyMode { get { throw null; } set { } }
838848
public bool? IgnoreReadOnly { get { throw null; } set { } }
839849
public System.Collections.Generic.IDictionary<string, string> Metadata { get { throw null; } set { } }
850+
public Azure.Storage.Files.Shares.Models.ModeCopyMode? ModeCopyMode { get { throw null; } set { } }
851+
public Azure.Storage.Files.Shares.Models.OwnerCopyMode? OwnerCopyMode { get { throw null; } set { } }
840852
public Azure.Storage.Files.Shares.Models.FilePermissionFormat? PermissionFormat { get { throw null; } set { } }
841853
public Azure.Storage.Files.Shares.Models.FilePosixProperties PosixProperties { get { throw null; } set { } }
842854
public Azure.Storage.Files.Shares.Models.FileSmbProperties SmbProperties { get { throw null; } set { } }

sdk/storage/Azure.Storage.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.Files.Shares",
5-
"Tag": "net/storage/Azure.Storage.Files.Shares_6cb8aed97e"
5+
"Tag": "net/storage/Azure.Storage.Files.Shares_93074c2c0f"
66
}

sdk/storage/Azure.Storage.Files.Shares/src/Models/Internal/ModeCopyMode.cs renamed to sdk/storage/Azure.Storage.Files.Shares/src/Generated/Models/ModeCopyMode.cs

Lines changed: 6 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/storage/Azure.Storage.Files.Shares/src/Models/Internal/OwnerCopyMode.cs renamed to sdk/storage/Azure.Storage.Files.Shares/src/Generated/Models/OwnerCopyMode.cs

Lines changed: 6 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/storage/Azure.Storage.Files.Shares/src/Models/ShareFileCopyOptions.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,5 +69,17 @@ public class ShareFileCopyOptions
6969
/// Only applicable to NFS Files. NFS properties to set on the destination file.
7070
/// </summary>
7171
public FilePosixProperties PosixProperties { get; set; }
72+
73+
/// <summary>
74+
/// Optional, only applicable to NFS Files.
75+
/// If not populated, the desination file will have the default File Mode.
76+
/// </summary>
77+
public ModeCopyMode? ModeCopyMode { get; set; }
78+
79+
/// <summary>
80+
/// Optional, only applicable to NFS Files.
81+
/// If not populated, the desination file will have the default Owner and Group.
82+
/// </summary>
83+
public OwnerCopyMode? OwnerCopyMode { get; set; }
7284
}
7385
}

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

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1323,6 +1323,8 @@ public virtual Response<ShareFileCopyInfo> StartCopy(
13231323
conditions: options?.Conditions,
13241324
copyableFileSmbProperties: options?.SmbPropertiesToCopy,
13251325
posixProperties: options?.PosixProperties,
1326+
modeCopyMode: options?.ModeCopyMode,
1327+
ownerCopyMode: options?.OwnerCopyMode,
13261328
async: false,
13271329
cancellationToken: cancellationToken)
13281330
.EnsureCompleted();
@@ -1401,6 +1403,8 @@ public virtual Response<ShareFileCopyInfo> StartCopy(
14011403
conditions,
14021404
copyableFileSmbProperties: default,
14031405
posixProperties: default,
1406+
modeCopyMode: default,
1407+
ownerCopyMode: default,
14041408
async: false,
14051409
cancellationToken)
14061410
.EnsureCompleted();
@@ -1449,6 +1453,8 @@ public virtual Response<ShareFileCopyInfo> StartCopy(
14491453
conditions: default,
14501454
copyableFileSmbProperties: default,
14511455
posixProperties: default,
1456+
modeCopyMode: default,
1457+
ownerCopyMode: default,
14521458
async: false,
14531459
cancellationToken)
14541460
.EnsureCompleted();
@@ -1494,6 +1500,8 @@ await StartCopyInternal(
14941500
conditions: options?.Conditions,
14951501
copyableFileSmbProperties: options?.SmbPropertiesToCopy,
14961502
posixProperties: options?.PosixProperties,
1503+
modeCopyMode: options?.ModeCopyMode,
1504+
ownerCopyMode: options?.OwnerCopyMode,
14971505
async: true,
14981506
cancellationToken: cancellationToken).
14991507
ConfigureAwait(false);
@@ -1572,6 +1580,8 @@ await StartCopyInternal(
15721580
conditions,
15731581
copyableFileSmbProperties: default,
15741582
posixProperties: default,
1583+
modeCopyMode: default,
1584+
ownerCopyMode: default,
15751585
async: true,
15761586
cancellationToken).
15771587
ConfigureAwait(false);
@@ -1620,6 +1630,8 @@ await StartCopyInternal(
16201630
conditions: default,
16211631
copyableFileSmbProperties: default,
16221632
posixProperties: default,
1633+
modeCopyMode: default,
1634+
ownerCopyMode: default,
16231635
async: true,
16241636
cancellationToken).
16251637
ConfigureAwait(false);
@@ -1670,6 +1682,14 @@ await StartCopyInternal(
16701682
/// <param name="posixProperties">
16711683
/// NFS files only. NFS properties to set on the destination file.
16721684
/// </param>
1685+
/// <param name="modeCopyMode">
1686+
/// Optional, only applicable to NFS Files.
1687+
/// If not populated, the desination file will have the default File Mode.
1688+
/// </param>
1689+
/// <param name="ownerCopyMode">
1690+
/// Optional, only applicable to NFS Files.
1691+
/// If not populated, the desination file will have the default Owner and Group.
1692+
/// </param>
16731693
/// <param name="async">
16741694
/// Whether to invoke the operation asynchronously.
16751695
/// </param>
@@ -1697,6 +1717,8 @@ private async Task<Response<ShareFileCopyInfo>> StartCopyInternal(
16971717
ShareFileRequestConditions conditions,
16981718
CopyableFileSmbProperties? copyableFileSmbProperties,
16991719
FilePosixProperties posixProperties,
1720+
ModeCopyMode? modeCopyMode,
1721+
OwnerCopyMode? ownerCopyMode,
17001722
bool async,
17011723
CancellationToken cancellationToken)
17021724
{
@@ -1796,18 +1818,6 @@ private async Task<Response<ShareFileCopyInfo>> StartCopyInternal(
17961818

17971819
ShareUriBuilder uriBuilder = new ShareUriBuilder(sourceUri);
17981820

1799-
ModeCopyMode? modeCopyMode = null;
1800-
if (posixProperties?.FileMode != null)
1801-
{
1802-
modeCopyMode = ModeCopyMode.Override;
1803-
}
1804-
1805-
OwnerCopyMode? ownerCopyMode = null;
1806-
if (posixProperties?.Owner != null || posixProperties?.Group != null)
1807-
{
1808-
ownerCopyMode = OwnerCopyMode.Override;
1809-
}
1810-
18111821
if (async)
18121822
{
18131823
response = await FileRestClient.StartCopyAsync(

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

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2542,10 +2542,11 @@ await TestHelper.AssertExpectedExceptionAsync<RequestFailedException>(
25422542
}
25432543

25442544
[RecordedTest]
2545-
[TestCase(false)]
2546-
[TestCase(true)]
2545+
[TestCase(null)]
2546+
[TestCase(ModeCopyMode.Source)]
2547+
[TestCase(ModeCopyMode.Override)]
25472548
[ServiceVersion(Min = ShareClientOptions.ServiceVersion.V2025_05_05)]
2548-
public async Task StartCopy_NFS(bool overwriteOwnerAndMode)
2549+
public async Task StartCopy_NFS(ModeCopyMode? modeAndOwnerCopyMode)
25492550
{
25502551
// Arrange
25512552
await using DisposingFile source = await SharesClientBuilder.GetTestFileAsync(nfs: true);
@@ -2557,6 +2558,16 @@ await source.File.UploadRangeAsync(
25572558
range: new HttpRange(0, Constants.KB),
25582559
content: stream);
25592560

2561+
await source.File.SetHttpHeadersAsync(new ShareFileSetHttpHeadersOptions
2562+
{
2563+
PosixProperties = new FilePosixProperties
2564+
{
2565+
Owner = "999",
2566+
Group = "888",
2567+
FileMode = NfsFileMode.ParseOctalFileMode("0111")
2568+
}
2569+
});
2570+
25602571
Response<ShareFileProperties> sourceProperties = await source.File.GetPropertiesAsync();
25612572

25622573
string owner;
@@ -2568,21 +2579,31 @@ await source.File.UploadRangeAsync(
25682579
PosixProperties = new FilePosixProperties()
25692580
};
25702581

2571-
if (overwriteOwnerAndMode)
2582+
if (modeAndOwnerCopyMode == ModeCopyMode.Override)
25722583
{
25732584
owner = "54321";
25742585
group = "12345";
25752586
fileMode = NfsFileMode.ParseOctalFileMode("7777");
2587+
options.ModeCopyMode = ModeCopyMode.Override;
2588+
options.OwnerCopyMode = OwnerCopyMode.Override;
25762589
options.PosixProperties.Owner = owner;
25772590
options.PosixProperties.Group = group;
25782591
options.PosixProperties.FileMode = fileMode;
25792592
}
2580-
else
2593+
else if (modeAndOwnerCopyMode == ModeCopyMode.Source)
25812594
{
2595+
options.ModeCopyMode = ModeCopyMode.Source;
2596+
options.OwnerCopyMode = OwnerCopyMode.Source;
25822597
owner = sourceProperties.Value.PosixProperties.Owner;
25832598
fileMode = sourceProperties.Value.PosixProperties.FileMode;
25842599
group = sourceProperties.Value.PosixProperties.Group;
25852600
}
2601+
else
2602+
{
2603+
owner = "0";
2604+
group = "0";
2605+
fileMode = NfsFileMode.ParseOctalFileMode("0664");
2606+
}
25862607

25872608
// Act
25882609
await destination.File.StartCopyAsync(source.File.Uri, options);

0 commit comments

Comments
 (0)