Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ModeCopyMode and OwnerCopyMode to Copy File #47440

Merged
merged 2 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,11 @@ public static partial class FilesModelFactory
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
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; }
}
public enum ModeCopyMode
{
Source = 0,
Override = 1,
}
public partial class NfsFileMode
{
public NfsFileMode() { }
Expand Down Expand Up @@ -593,6 +598,11 @@ public enum NtfsFileAttributes
NotContentIndexed = 256,
NoScrubData = 512,
}
public enum OwnerCopyMode
{
Source = 0,
Override = 1,
}
public enum PermissionCopyMode
{
Source = 0,
Expand Down Expand Up @@ -837,6 +847,8 @@ public ShareFileCopyOptions() { }
public Azure.Storage.Files.Shares.Models.PermissionCopyMode? FilePermissionCopyMode { get { throw null; } set { } }
public bool? IgnoreReadOnly { get { throw null; } set { } }
public System.Collections.Generic.IDictionary<string, string> Metadata { get { throw null; } set { } }
public Azure.Storage.Files.Shares.Models.ModeCopyMode? ModeCopyMode { get { throw null; } set { } }
public Azure.Storage.Files.Shares.Models.OwnerCopyMode? OwnerCopyMode { get { throw null; } set { } }
public Azure.Storage.Files.Shares.Models.FilePermissionFormat? PermissionFormat { get { throw null; } set { } }
public Azure.Storage.Files.Shares.Models.FilePosixProperties PosixProperties { get { throw null; } set { } }
public Azure.Storage.Files.Shares.Models.FileSmbProperties SmbProperties { get { throw null; } set { } }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,11 @@ public static partial class FilesModelFactory
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
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; }
}
public enum ModeCopyMode
{
Source = 0,
Override = 1,
}
public partial class NfsFileMode
{
public NfsFileMode() { }
Expand Down Expand Up @@ -593,6 +598,11 @@ public enum NtfsFileAttributes
NotContentIndexed = 256,
NoScrubData = 512,
}
public enum OwnerCopyMode
{
Source = 0,
Override = 1,
}
public enum PermissionCopyMode
{
Source = 0,
Expand Down Expand Up @@ -837,6 +847,8 @@ public ShareFileCopyOptions() { }
public Azure.Storage.Files.Shares.Models.PermissionCopyMode? FilePermissionCopyMode { get { throw null; } set { } }
public bool? IgnoreReadOnly { get { throw null; } set { } }
public System.Collections.Generic.IDictionary<string, string> Metadata { get { throw null; } set { } }
public Azure.Storage.Files.Shares.Models.ModeCopyMode? ModeCopyMode { get { throw null; } set { } }
public Azure.Storage.Files.Shares.Models.OwnerCopyMode? OwnerCopyMode { get { throw null; } set { } }
public Azure.Storage.Files.Shares.Models.FilePermissionFormat? PermissionFormat { get { throw null; } set { } }
public Azure.Storage.Files.Shares.Models.FilePosixProperties PosixProperties { get { throw null; } set { } }
public Azure.Storage.Files.Shares.Models.FileSmbProperties SmbProperties { get { throw null; } set { } }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,11 @@ public static partial class FilesModelFactory
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
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; }
}
public enum ModeCopyMode
{
Source = 0,
Override = 1,
}
public partial class NfsFileMode
{
public NfsFileMode() { }
Expand Down Expand Up @@ -593,6 +598,11 @@ public enum NtfsFileAttributes
NotContentIndexed = 256,
NoScrubData = 512,
}
public enum OwnerCopyMode
{
Source = 0,
Override = 1,
}
public enum PermissionCopyMode
{
Source = 0,
Expand Down Expand Up @@ -837,6 +847,8 @@ public ShareFileCopyOptions() { }
public Azure.Storage.Files.Shares.Models.PermissionCopyMode? FilePermissionCopyMode { get { throw null; } set { } }
public bool? IgnoreReadOnly { get { throw null; } set { } }
public System.Collections.Generic.IDictionary<string, string> Metadata { get { throw null; } set { } }
public Azure.Storage.Files.Shares.Models.ModeCopyMode? ModeCopyMode { get { throw null; } set { } }
public Azure.Storage.Files.Shares.Models.OwnerCopyMode? OwnerCopyMode { get { throw null; } set { } }
public Azure.Storage.Files.Shares.Models.FilePermissionFormat? PermissionFormat { get { throw null; } set { } }
public Azure.Storage.Files.Shares.Models.FilePosixProperties PosixProperties { get { throw null; } set { } }
public Azure.Storage.Files.Shares.Models.FileSmbProperties SmbProperties { get { throw null; } set { } }
Expand Down
2 changes: 1 addition & 1 deletion sdk/storage/Azure.Storage.Files.Shares/assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "net",
"TagPrefix": "net/storage/Azure.Storage.Files.Shares",
"Tag": "net/storage/Azure.Storage.Files.Shares_6cb8aed97e"
"Tag": "net/storage/Azure.Storage.Files.Shares_93074c2c0f"
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,17 @@ public class ShareFileCopyOptions
/// Only applicable to NFS Files. NFS properties to set on the destination file.
/// </summary>
public FilePosixProperties PosixProperties { get; set; }

/// <summary>
/// Optional, only applicable to NFS Files.
/// If not populated, the desination file will have the default File Mode.
/// </summary>
public ModeCopyMode? ModeCopyMode { get; set; }

/// <summary>
/// Optional, only applicable to NFS Files.
/// If not populated, the desination file will have the default Owner and Group.
/// </summary>
public OwnerCopyMode? OwnerCopyMode { get; set; }
}
}
34 changes: 22 additions & 12 deletions sdk/storage/Azure.Storage.Files.Shares/src/ShareFileClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1323,6 +1323,8 @@ public virtual Response<ShareFileCopyInfo> StartCopy(
conditions: options?.Conditions,
copyableFileSmbProperties: options?.SmbPropertiesToCopy,
posixProperties: options?.PosixProperties,
modeCopyMode: options?.ModeCopyMode,
ownerCopyMode: options?.OwnerCopyMode,
async: false,
cancellationToken: cancellationToken)
.EnsureCompleted();
Expand Down Expand Up @@ -1401,6 +1403,8 @@ public virtual Response<ShareFileCopyInfo> StartCopy(
conditions,
copyableFileSmbProperties: default,
posixProperties: default,
modeCopyMode: default,
ownerCopyMode: default,
async: false,
cancellationToken)
.EnsureCompleted();
Expand Down Expand Up @@ -1449,6 +1453,8 @@ public virtual Response<ShareFileCopyInfo> StartCopy(
conditions: default,
copyableFileSmbProperties: default,
posixProperties: default,
modeCopyMode: default,
ownerCopyMode: default,
async: false,
cancellationToken)
.EnsureCompleted();
Expand Down Expand Up @@ -1494,6 +1500,8 @@ await StartCopyInternal(
conditions: options?.Conditions,
copyableFileSmbProperties: options?.SmbPropertiesToCopy,
posixProperties: options?.PosixProperties,
modeCopyMode: options?.ModeCopyMode,
ownerCopyMode: options?.OwnerCopyMode,
async: true,
cancellationToken: cancellationToken).
ConfigureAwait(false);
Expand Down Expand Up @@ -1572,6 +1580,8 @@ await StartCopyInternal(
conditions,
copyableFileSmbProperties: default,
posixProperties: default,
modeCopyMode: default,
ownerCopyMode: default,
async: true,
cancellationToken).
ConfigureAwait(false);
Expand Down Expand Up @@ -1620,6 +1630,8 @@ await StartCopyInternal(
conditions: default,
copyableFileSmbProperties: default,
posixProperties: default,
modeCopyMode: default,
ownerCopyMode: default,
async: true,
cancellationToken).
ConfigureAwait(false);
Expand Down Expand Up @@ -1670,6 +1682,14 @@ await StartCopyInternal(
/// <param name="posixProperties">
/// NFS files only. NFS properties to set on the destination file.
/// </param>
/// <param name="modeCopyMode">
/// Optional, only applicable to NFS Files.
/// If not populated, the desination file will have the default File Mode.
/// </param>
/// <param name="ownerCopyMode">
/// Optional, only applicable to NFS Files.
/// If not populated, the desination file will have the default Owner and Group.
/// </param>
/// <param name="async">
/// Whether to invoke the operation asynchronously.
/// </param>
Expand Down Expand Up @@ -1697,6 +1717,8 @@ private async Task<Response<ShareFileCopyInfo>> StartCopyInternal(
ShareFileRequestConditions conditions,
CopyableFileSmbProperties? copyableFileSmbProperties,
FilePosixProperties posixProperties,
ModeCopyMode? modeCopyMode,
OwnerCopyMode? ownerCopyMode,
bool async,
CancellationToken cancellationToken)
{
Expand Down Expand Up @@ -1796,18 +1818,6 @@ private async Task<Response<ShareFileCopyInfo>> StartCopyInternal(

ShareUriBuilder uriBuilder = new ShareUriBuilder(sourceUri);

ModeCopyMode? modeCopyMode = null;
if (posixProperties?.FileMode != null)
{
modeCopyMode = ModeCopyMode.Override;
}

OwnerCopyMode? ownerCopyMode = null;
if (posixProperties?.Owner != null || posixProperties?.Group != null)
{
ownerCopyMode = OwnerCopyMode.Override;
}

if (async)
{
response = await FileRestClient.StartCopyAsync(
Expand Down
31 changes: 26 additions & 5 deletions sdk/storage/Azure.Storage.Files.Shares/tests/FileClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2542,10 +2542,11 @@ await TestHelper.AssertExpectedExceptionAsync<RequestFailedException>(
}

[RecordedTest]
[TestCase(false)]
[TestCase(true)]
[TestCase(null)]
[TestCase(ModeCopyMode.Source)]
[TestCase(ModeCopyMode.Override)]
[ServiceVersion(Min = ShareClientOptions.ServiceVersion.V2025_05_05)]
public async Task StartCopy_NFS(bool overwriteOwnerAndMode)
public async Task StartCopy_NFS(ModeCopyMode? modeAndOwnerCopyMode)
{
// Arrange
await using DisposingFile source = await SharesClientBuilder.GetTestFileAsync(nfs: true);
Expand All @@ -2557,6 +2558,16 @@ await source.File.UploadRangeAsync(
range: new HttpRange(0, Constants.KB),
content: stream);

await source.File.SetHttpHeadersAsync(new ShareFileSetHttpHeadersOptions
{
PosixProperties = new FilePosixProperties
{
Owner = "999",
Group = "888",
FileMode = NfsFileMode.ParseOctalFileMode("0111")
}
});

Response<ShareFileProperties> sourceProperties = await source.File.GetPropertiesAsync();

string owner;
Expand All @@ -2568,21 +2579,31 @@ await source.File.UploadRangeAsync(
PosixProperties = new FilePosixProperties()
};

if (overwriteOwnerAndMode)
if (modeAndOwnerCopyMode == ModeCopyMode.Override)
{
owner = "54321";
group = "12345";
fileMode = NfsFileMode.ParseOctalFileMode("7777");
options.ModeCopyMode = ModeCopyMode.Override;
options.OwnerCopyMode = OwnerCopyMode.Override;
options.PosixProperties.Owner = owner;
options.PosixProperties.Group = group;
options.PosixProperties.FileMode = fileMode;
}
else
else if (modeAndOwnerCopyMode == ModeCopyMode.Source)
{
options.ModeCopyMode = ModeCopyMode.Source;
options.OwnerCopyMode = OwnerCopyMode.Source;
owner = sourceProperties.Value.PosixProperties.Owner;
fileMode = sourceProperties.Value.PosixProperties.FileMode;
group = sourceProperties.Value.PosixProperties.Group;
}
else
{
owner = "0";
group = "0";
fileMode = NfsFileMode.ParseOctalFileMode("0664");
}

// Act
await destination.File.StartCopyAsync(source.File.Uri, options);
Expand Down
Loading