public virtual Response StartCopy()

in sdk/storage/Azure.Storage.Files.Shares/src/ShareFileClient.cs [1343:1918]


        public virtual Response<ShareFileCopyInfo> StartCopy(
            Uri sourceUri,
            ShareFileCopyOptions options = default,
            CancellationToken cancellationToken = default) =>
            StartCopyInternal(
                sourceUri: sourceUri,
                metadata: options?.Metadata,
                smbProperties: options?.SmbProperties,
                filePermission: options?.FilePermission,
                filePermissionFormat: options?.PermissionFormat,
                filePermissionCopyMode: options?.FilePermissionCopyMode,
                ignoreReadOnly: options?.IgnoreReadOnly,
                setArchiveAttribute: options?.Archive,
                conditions: options?.Conditions,
                copyableFileSmbProperties: options?.SmbPropertiesToCopy,
                posixProperties: options?.PosixProperties,
                modeCopyMode: options?.ModeCopyMode,
                ownerCopyMode: options?.OwnerCopyMode,
                async: false,
                cancellationToken: cancellationToken)
                .EnsureCompleted();

        /// <summary>
        /// Copies a blob or file to a destination file within the storage account.
        ///
        /// For more information, see
        /// <see href="https://docs.microsoft.com/rest/api/storageservices/copy-file">
        /// Copy File</see>.
        /// </summary>
        /// <param name="sourceUri">
        /// Required. Specifies the URL of the source file or blob.
        /// </param>
        /// <param name="metadata">
        /// Optional custom metadata to set for the file.
        /// </param>
        /// <param name="smbProperties">
        /// Optional SMB paramters to set on the target file.
        /// </param>
        /// <param name="filePermission">
        /// Optional file permission to set for the file.
        /// </param>
        /// <param name="filePermissionCopyMode">
        /// Specifies the option to copy file security descriptor from source file or
        /// to set it using the value which is defined by the header value of FilePermission
        /// or FilePermissionKey.
        /// </param>
        /// <param name="ignoreReadOnly">
        /// Optional boolean specifying to overwrite the target file if it already
        /// exists and has read-only attribute set.
        /// </param>
        /// <param name="setArchiveAttribute">
        /// Optional boolean Specifying to set archive attribute on a target file. True
        /// means archive attribute will be set on a target file despite attribute
        /// overrides or a source file state.
        /// </param>
        /// <param name="conditions">
        /// Optional <see cref="ShareFileRequestConditions"/> to add conditions
        /// on creating the file.
        /// </param>
        /// <param name="cancellationToken">
        /// Optional <see cref="CancellationToken"/> to propagate
        /// notifications that the operation should be cancelled.
        /// </param>
        /// <returns>
        /// A <see cref="Response{StorageFileInfo}"/> describing the
        /// state of the file copy.
        /// </returns>
        /// <remarks>
        /// A <see cref="RequestFailedException"/> will be thrown if
        /// a failure occurs.
        /// If multiple failures occur, an <see cref="AggregateException"/> will be thrown,
        /// containing each failure instance.
        /// </remarks>
        [EditorBrowsable(EditorBrowsableState.Never)]
#pragma warning disable AZC0002 // DO ensure all service methods, both asynchronous and synchronous, take an optional CancellationToken parameter called cancellationToken.
        public virtual Response<ShareFileCopyInfo> StartCopy(
#pragma warning restore AZC0002 // DO ensure all service methods, both asynchronous and synchronous, take an optional CancellationToken parameter called cancellationToken.
            Uri sourceUri,
            Metadata metadata,
            FileSmbProperties smbProperties,
            string filePermission,
            PermissionCopyMode? filePermissionCopyMode,
            bool? ignoreReadOnly,
            bool? setArchiveAttribute,
            ShareFileRequestConditions conditions,
            CancellationToken cancellationToken) =>
            StartCopyInternal(
                sourceUri,
                metadata,
                smbProperties,
                filePermission,
                filePermissionFormat: default,
                filePermissionCopyMode,
                ignoreReadOnly,
                setArchiveAttribute,
                conditions,
                copyableFileSmbProperties: default,
                posixProperties: default,
                modeCopyMode: default,
                ownerCopyMode: default,
                async: false,
                cancellationToken)
                .EnsureCompleted();

        /// <summary>
        /// Copies a blob or file to a destination file within the storage account.
        ///
        /// For more information, see
        /// <see href="https://docs.microsoft.com/rest/api/storageservices/copy-file">
        /// Copy File</see>.
        /// </summary>
        /// <param name="sourceUri">
        /// Required. Specifies the URL of the source file or blob.
        /// </param>
        /// <param name="metadata">
        /// Optional custom metadata to set for the file.
        /// </param>
        /// <param name="cancellationToken">
        /// Optional <see cref="CancellationToken"/> to propagate
        /// notifications that the operation should be cancelled.
        /// </param>
        /// <returns>
        /// A <see cref="Response{StorageFileInfo}"/> describing the
        /// state of the file copy.
        /// </returns>
        /// <remarks>
        /// A <see cref="RequestFailedException"/> will be thrown if
        /// a failure occurs.
        /// If multiple failures occur, an <see cref="AggregateException"/> will be thrown,
        /// containing each failure instance.
        /// </remarks>
#pragma warning disable AZC0002 // DO ensure all service methods, both asynchronous and synchronous, take an optional CancellationToken parameter called cancellationToken.
        [EditorBrowsable(EditorBrowsableState.Never)]
        public virtual Response<ShareFileCopyInfo> StartCopy(
#pragma warning restore AZC0002 // DO ensure all service methods, both asynchronous and synchronous, take an optional CancellationToken parameter called cancellationToken.
            Uri sourceUri,
            Metadata metadata,
            CancellationToken cancellationToken) =>
            StartCopyInternal(
                sourceUri,
                metadata,
                smbProperties: default,
                filePermission: default,
                filePermissionFormat: default,
                filePermissionCopyMode: default,
                ignoreReadOnly: default,
                setArchiveAttribute: default,
                conditions: default,
                copyableFileSmbProperties: default,
                posixProperties: default,
                modeCopyMode: default,
                ownerCopyMode: default,
                async: false,
                cancellationToken)
                .EnsureCompleted();

        /// <summary>
        /// Copies a blob or file to a destination file within the storage account.
        ///
        /// For more information, see
        /// <see href="https://docs.microsoft.com/rest/api/storageservices/copy-file">
        /// Copy File</see>.
        /// </summary>
        /// <param name="sourceUri">
        /// Required. Specifies the URL of the source file or blob.
        /// </param>
        /// <param name="options">
        /// Optional parameters.
        /// </param>
        /// <param name="cancellationToken">
        /// Optional <see cref="CancellationToken"/> to propagate
        /// notifications that the operation should be cancelled.
        /// </param>
        /// <returns>
        /// A <see cref="Response{StorageFileInfo}"/> describing the
        /// state of the file copy.
        /// </returns>
        /// <remarks>
        /// A <see cref="RequestFailedException"/> will be thrown if
        /// a failure occurs.
        /// If multiple failures occur, an <see cref="AggregateException"/> will be thrown,
        /// containing each failure instance.
        /// </remarks>
        public virtual async Task<Response<ShareFileCopyInfo>> StartCopyAsync(
            Uri sourceUri,
            ShareFileCopyOptions options = default,
            CancellationToken cancellationToken = default) =>
            await StartCopyInternal(
                sourceUri: sourceUri,
                metadata: options?.Metadata,
                smbProperties: options?.SmbProperties,
                filePermission: options?.FilePermission,
                filePermissionFormat: options?.PermissionFormat,
                filePermissionCopyMode: options?.FilePermissionCopyMode,
                ignoreReadOnly: options?.IgnoreReadOnly,
                setArchiveAttribute: options?.Archive,
                conditions: options?.Conditions,
                copyableFileSmbProperties: options?.SmbPropertiesToCopy,
                posixProperties: options?.PosixProperties,
                modeCopyMode: options?.ModeCopyMode,
                ownerCopyMode: options?.OwnerCopyMode,
                async: true,
                cancellationToken: cancellationToken).
                ConfigureAwait(false);

        /// <summary>
        /// Copies a blob or file to a destination file within the storage account.
        ///
        /// For more information, see
        /// <see href="https://docs.microsoft.com/rest/api/storageservices/copy-file">
        /// Copy File</see>.
        /// </summary>
        /// <param name="sourceUri">
        /// Required. Specifies the URL of the source file or blob.
        /// </param>
        /// <param name="metadata">
        /// Optional custom metadata to set for the file.
        /// </param>
        /// <param name="smbProperties">
        /// Optional SMB properties to set on the target file.
        /// </param>
        /// <param name="filePermission">
        /// Optional file permission to set for the file.
        /// </param>
        /// <param name="filePermissionCopyMode">
        /// Specifies the option to copy file security descriptor from source file or
        /// to set it using the value which is defined by the header value of FilePermission
        /// or FilePermissionKey.
        /// </param>
        /// <param name="ignoreReadOnly">
        /// Optional boolean specifying to overwrite the target file if it already
        /// exists and has read-only attribute set.
        /// </param>
        /// <param name="setArchiveAttribute">
        /// Optional boolean Specifying to set archive attribute on a target file. True
        /// means archive attribute will be set on a target file despite attribute
        /// overrides or a source file state.
        /// </param>
        /// <param name="conditions">
        /// Optional <see cref="ShareFileRequestConditions"/> to add conditions
        /// on creating the file.
        /// </param>
        /// <param name="cancellationToken">
        /// Optional <see cref="CancellationToken"/> to propagate
        /// notifications that the operation should be cancelled.
        /// </param>
        /// <returns>
        /// A <see cref="Response{StorageFileInfo}"/> describing the
        /// state of the file copy.
        /// </returns>
        /// <remarks>
        /// A <see cref="RequestFailedException"/> will be thrown if
        /// a failure occurs.
        /// If multiple failures occur, an <see cref="AggregateException"/> will be thrown,
        /// containing each failure instance.
        /// </remarks>
        [EditorBrowsable(EditorBrowsableState.Never)]
#pragma warning disable AZC0002 // DO ensure all service methods, both asynchronous and synchronous, take an optional CancellationToken parameter called cancellationToken.
        public virtual async Task<Response<ShareFileCopyInfo>> StartCopyAsync(
#pragma warning restore AZC0002 // DO ensure all service methods, both asynchronous and synchronous, take an optional CancellationToken parameter called cancellationToken.
            Uri sourceUri,
            Metadata metadata,
            FileSmbProperties smbProperties,
            string filePermission,
            PermissionCopyMode? filePermissionCopyMode,
            bool? ignoreReadOnly,
            bool? setArchiveAttribute,
            ShareFileRequestConditions conditions,
            CancellationToken cancellationToken) =>
            await StartCopyInternal(
                sourceUri,
                metadata,
                smbProperties,
                filePermission,
                filePermissionFormat: default,
                filePermissionCopyMode,
                ignoreReadOnly,
                setArchiveAttribute,
                conditions,
                copyableFileSmbProperties: default,
                posixProperties: default,
                modeCopyMode: default,
                ownerCopyMode: default,
                async: true,
                cancellationToken).
                ConfigureAwait(false);

        /// <summary>
        /// Copies a blob or file to a destination file within the storage account.
        ///
        /// For more information, see
        /// <see href="https://docs.microsoft.com/rest/api/storageservices/copy-file">
        /// Copy File</see>.
        /// </summary>
        /// <param name="sourceUri">
        /// Required. Specifies the URL of the source file or blob.
        /// </param>
        /// <param name="metadata">
        /// Optional custom metadata to set for the file.
        /// </param>
        /// <param name="cancellationToken">
        /// Optional <see cref="CancellationToken"/> to propagate
        /// notifications that the operation should be cancelled.
        /// </param>
        /// <returns>
        /// A <see cref="Response{StorageFileInfo}"/> describing the
        /// state of the file copy.
        /// </returns>
        /// <remarks>
        /// A <see cref="RequestFailedException"/> will be thrown if
        /// a failure occurs.
        /// If multiple failures occur, an <see cref="AggregateException"/> will be thrown,
        /// containing each failure instance.
        /// </remarks>
#pragma warning disable AZC0002 // DO ensure all service methods, both asynchronous and synchronous, take an optional CancellationToken parameter called cancellationToken.
        [EditorBrowsable(EditorBrowsableState.Never)]
        public virtual async Task<Response<ShareFileCopyInfo>> StartCopyAsync(
#pragma warning restore AZC0002 // DO ensure all service methods, both asynchronous and synchronous, take an optional CancellationToken parameter called cancellationToken.
            Uri sourceUri,
            Metadata metadata,
            CancellationToken cancellationToken) =>
            await StartCopyInternal(
                sourceUri,
                metadata,
                smbProperties: default,
                filePermission: default,
                filePermissionFormat: default,
                filePermissionCopyMode: default,
                ignoreReadOnly: default,
                setArchiveAttribute: default,
                conditions: default,
                copyableFileSmbProperties: default,
                posixProperties: default,
                modeCopyMode: default,
                ownerCopyMode: default,
                async: true,
                cancellationToken).
                ConfigureAwait(false);

        /// <summary>
        /// Copies a blob or file to a destination file within the storage account.
        ///
        /// For more information, see
        /// <see href="https://docs.microsoft.com/rest/api/storageservices/copy-file">
        /// Copy File</see>.
        /// </summary>
        /// <param name="sourceUri">
        /// Required. Specifies the URL of the source file or blob.
        /// </param>
        /// <param name="metadata">
        /// Optional custom metadata to set for the file.
        /// </param>
        /// <param name="smbProperties">
        /// Optional SMB properties to set on the target file.
        /// </param>
        /// <param name="filePermission">
        /// Optional file permission to set for the file.
        /// </param>
        /// <param name="filePermissionFormat">
        /// Optional file permission format.
        /// </param>
        /// <param name="filePermissionCopyMode">
        /// Specifies the option to copy file security descriptor from source file or
        /// to set it using the value which is defined by the header value of FilePermission
        /// or FilePermissionKey.
        /// </param>
        /// <param name="ignoreReadOnly">
        /// Optional boolean specifying to overwrite the target file if it already
        /// exists and has read-only attribute set.
        /// </param>
        /// <param name="setArchiveAttribute">
        /// Optional boolean Specifying to set archive attribute on a target file. True
        /// means archive attribute will be set on a target file despite attribute
        /// overrides or a source file state.
        /// </param>
        /// <param name="conditions">
        /// Optional <see cref="ShareFileRequestConditions"/> to add conditions
        /// on creating the file.
        /// </param>
        /// <param name="copyableFileSmbProperties">
        /// SMB properties to copy from the source file.
        /// </param>
        /// <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>
        /// <param name="cancellationToken">
        /// Optional <see cref="CancellationToken"/> to propagate
        /// notifications that the operation should be cancelled.
        /// </param>
        /// <returns>
        /// A <see cref="Response{StorageFileInfo}"/> describing the
        /// state of the file copy.
        /// </returns>
        /// <remarks>
        /// A <see cref="RequestFailedException"/> will be thrown if
        /// a failure occurs.
        /// If multiple failures occur, an <see cref="AggregateException"/> will be thrown,
        /// containing each failure instance.
        /// </remarks>
        private async Task<Response<ShareFileCopyInfo>> StartCopyInternal(
            Uri sourceUri,
            Metadata metadata,
            FileSmbProperties smbProperties,
            string filePermission,
            FilePermissionFormat? filePermissionFormat,
            PermissionCopyMode? filePermissionCopyMode,
            bool? ignoreReadOnly,
            bool? setArchiveAttribute,
            ShareFileRequestConditions conditions,
            CopyableFileSmbProperties? copyableFileSmbProperties,
            FilePosixProperties posixProperties,
            ModeCopyMode? modeCopyMode,
            OwnerCopyMode? ownerCopyMode,
            bool async,
            CancellationToken cancellationToken)
        {
            using (ClientConfiguration.Pipeline.BeginLoggingScope(nameof(ShareFileClient)))
            {
                ClientConfiguration.Pipeline.LogMethodEnter(
                    nameof(ShareFileClient),
                    message:
                    $"{nameof(Uri)}: {Uri}\n" +
                    $"{nameof(sourceUri)}: {sourceUri}");

                DiagnosticScope scope = ClientConfiguration.ClientDiagnostics.CreateScope($"{nameof(ShareFileClient)}.{nameof(StartCopy)}");

                try
                {
                    scope.Start();
                    ResponseWithHeaders<FileStartCopyHeaders> response;

                    if ((copyableFileSmbProperties.GetValueOrDefault() & CopyableFileSmbProperties.FileAttributes) == CopyableFileSmbProperties.FileAttributes
                        && smbProperties?.FileAttributes != null)
                    {
                        throw new ArgumentException($"{nameof(ShareFileCopyOptions)}.{nameof(ShareFileCopyOptions.SmbProperties)}.{nameof(ShareFileCopyOptions.SmbProperties.FileAttributes)} and {nameof(ShareFileCopyOptions)}.{nameof(CopyableFileSmbProperties)}.{nameof(CopyableFileSmbProperties.FileAttributes)} cannot both be set.");
                    }

                    if ((copyableFileSmbProperties.GetValueOrDefault() & CopyableFileSmbProperties.CreatedOn) == CopyableFileSmbProperties.CreatedOn
                        && smbProperties?.FileCreatedOn != null)
                    {
                        throw new ArgumentException($"{nameof(ShareFileCopyOptions)}.{nameof(ShareFileCopyOptions.SmbProperties)}.{nameof(ShareFileCopyOptions.SmbProperties.FileCreatedOn)} and {nameof(ShareFileCopyOptions)}.{nameof(CopyableFileSmbProperties)}.{nameof(CopyableFileSmbProperties.CreatedOn)} cannot both be set.");
                    }

                    if ((copyableFileSmbProperties.GetValueOrDefault() & CopyableFileSmbProperties.LastWrittenOn) == CopyableFileSmbProperties.LastWrittenOn
                        && smbProperties?.FileLastWrittenOn != null)
                    {
                        throw new ArgumentException($"{nameof(ShareFileCopyOptions)}.{nameof(ShareFileCopyOptions.SmbProperties)}.{nameof(ShareFileCopyOptions.SmbProperties.FileLastWrittenOn)} and {nameof(ShareFileCopyOptions)}.{nameof(CopyableFileSmbProperties)}.{nameof(CopyableFileSmbProperties.LastWrittenOn)} cannot both be set.");
                    }

                    if ((copyableFileSmbProperties.GetValueOrDefault() & CopyableFileSmbProperties.ChangedOn) == CopyableFileSmbProperties.ChangedOn
                        && smbProperties?.FileChangedOn != null)
                    {
                        throw new ArgumentException($"{nameof(ShareFileCopyOptions)}.{nameof(ShareFileCopyOptions.SmbProperties)}.{nameof(ShareFileCopyOptions.SmbProperties.FileChangedOn)} and {nameof(ShareFileCopyOptions)}.{nameof(CopyableFileSmbProperties)}.{nameof(CopyableFileSmbProperties.ChangedOn)} cannot both be set.");
                    }

                    string fileAttributes = null;
                    if ((copyableFileSmbProperties.GetValueOrDefault() & CopyableFileSmbProperties.FileAttributes)
                        == CopyableFileSmbProperties.FileAttributes)
                    {
                        fileAttributes = Constants.File.Source;
                    }
                    else
                    {
                        fileAttributes = smbProperties?.FileAttributes.ToAttributesString();
                    }

                    string fileCreatedOn = null;
                    if ((copyableFileSmbProperties.GetValueOrDefault() & CopyableFileSmbProperties.CreatedOn)
                        == CopyableFileSmbProperties.CreatedOn)
                    {
                        fileCreatedOn = Constants.File.Source;
                    }
                    else
                    {
                        fileCreatedOn = smbProperties?.FileCreatedOn.ToFileDateTimeString();
                    }

                    string fileLastWrittenOn = null;
                    if ((copyableFileSmbProperties.GetValueOrDefault() & CopyableFileSmbProperties.LastWrittenOn)
                        == CopyableFileSmbProperties.LastWrittenOn)
                    {
                        fileLastWrittenOn = Constants.File.Source;
                    }
                    else
                    {
                        fileLastWrittenOn = smbProperties?.FileLastWrittenOn.ToFileDateTimeString();
                    }

                    string fileChangedOn = null;
                    if ((copyableFileSmbProperties.GetValueOrDefault() & CopyableFileSmbProperties.ChangedOn)
                        == CopyableFileSmbProperties.ChangedOn)
                    {
                        fileChangedOn = Constants.File.Source;
                    }
                    else
                    {
                        fileChangedOn = smbProperties?.FileChangedOn.ToFileDateTimeString();
                    }

                    CopyFileSmbInfo copyFileSmbInfo = new CopyFileSmbInfo
                    {
                        FilePermissionCopyMode = filePermissionCopyMode,
                        IgnoreReadOnly = ignoreReadOnly,
                        FileAttributes = fileAttributes,
                        FileCreationTime = fileCreatedOn,
                        FileLastWriteTime = fileLastWrittenOn,
                        FileChangeTime = fileChangedOn,
                        SetArchiveAttribute = setArchiveAttribute
                    };

                    ShareUriBuilder uriBuilder = new ShareUriBuilder(sourceUri);

                    if (async)
                    {
                        response = await FileRestClient.StartCopyAsync(
                            copySource: uriBuilder.ToString(),
                            metadata: metadata,
                            filePermission: filePermission,
                            filePermissionFormat: filePermissionFormat,
                            filePermissionKey: smbProperties?.FilePermissionKey,
                            owner: posixProperties?.Owner,
                            group: posixProperties?.Group,
                            fileMode: posixProperties?.FileMode?.ToOctalFileMode(),
                            fileModeCopyMode: modeCopyMode,
                            fileOwnerCopyMode: ownerCopyMode,
                            copyFileSmbInfo: copyFileSmbInfo,
                            shareFileRequestConditions: conditions,
                            cancellationToken: cancellationToken)
                            .ConfigureAwait(false);
                    }
                    else
                    {
                        response = FileRestClient.StartCopy(
                            copySource: uriBuilder.ToString(),
                            metadata: metadata,
                            filePermission: filePermission,
                            filePermissionFormat: filePermissionFormat,
                            filePermissionKey: smbProperties?.FilePermissionKey,
                            owner: posixProperties?.Owner,
                            group: posixProperties?.Group,
                            fileMode: posixProperties?.FileMode?.ToOctalFileMode(),
                            fileModeCopyMode: modeCopyMode,
                            fileOwnerCopyMode: ownerCopyMode,
                            copyFileSmbInfo: copyFileSmbInfo,
                            shareFileRequestConditions: conditions,
                            cancellationToken: cancellationToken);
                    }

                    return Response.FromValue(
                        response.ToShareFileCopyInfo(),
                        response.GetRawResponse());
                }
                catch (Exception ex)
                {
                    ClientConfiguration.Pipeline.LogException(ex);
                    scope.Failed(ex);
                    throw;
                }
                finally
                {
                    ClientConfiguration.Pipeline.LogMethodExit(nameof(ShareFileClient));
                    scope.Dispose();
                }
            }
        }