Skip to content
Next Next commit
temp
  • Loading branch information
yifanz7 committed Sep 25, 2024
commit ea11507d2620b331938babf6964bb6f326ecd3cd
50 changes: 28 additions & 22 deletions src/Storage/Storage/File/Cmdlet/StartAzureStorageFileCopy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,18 +128,18 @@ public class StartAzureStorageFileCopyCommand : StorageFileDataManagementCmdletB
Mandatory = false, ValueFromPipelineByPropertyName = true, ParameterSetName = ContainerNameParameterSet)]
[Parameter(HelpMessage = "Source Azure Storage Context Object",
Mandatory = false, ValueFromPipelineByPropertyName = true, ParameterSetName = ShareNameParameterSet)]
[Parameter(HelpMessage = "Source Azure Storage Context Object",
Mandatory = false, ValueFromPipelineByPropertyName = true, ParameterSetName = ContainerParameterSet)]
[Parameter(HelpMessage = "Source Azure Storage Context Object",
Mandatory = false, ValueFromPipelineByPropertyName = true, ParameterSetName = BlobFilePathParameterSet)]
[Parameter(HelpMessage = "Source Azure Storage Context Object",
Mandatory = false, ValueFromPipelineByPropertyName = true, ParameterSetName = BlobFileParameterSet)]
[Parameter(HelpMessage = "Source Azure Storage Context Object",
Mandatory = false, ValueFromPipelineByPropertyName = true, ParameterSetName = ShareParameterSet)]
[Parameter(HelpMessage = "Source Azure Storage Context Object",
Mandatory = false, ValueFromPipelineByPropertyName = true, ParameterSetName = FileFileParameterSet)]
[Parameter(HelpMessage = "Source Azure Storage Context Object",
Mandatory = false, ValueFromPipelineByPropertyName = true, ParameterSetName = FileFilePathParameterSet)]
//[Parameter(HelpMessage = "Source Azure Storage Context Object",
//Mandatory = false, ValueFromPipelineByPropertyName = true, ParameterSetName = ContainerParameterSet)]
//[Parameter(HelpMessage = "Source Azure Storage Context Object",
// Mandatory = false, ValueFromPipelineByPropertyName = true, ParameterSetName = BlobFilePathParameterSet)]
//[Parameter(HelpMessage = "Source Azure Storage Context Object",
// Mandatory = false, ValueFromPipelineByPropertyName = true, ParameterSetName = BlobFileParameterSet)]
//[Parameter(HelpMessage = "Source Azure Storage Context Object",
//Mandatory = false, ValueFromPipelineByPropertyName = true, ParameterSetName = ShareParameterSet)]
//[Parameter(HelpMessage = "Source Azure Storage Context Object",
// Mandatory = false, ValueFromPipelineByPropertyName = true, ParameterSetName = FileFileParameterSet)]
//[Parameter(HelpMessage = "Source Azure Storage Context Object",
// Mandatory = false, ValueFromPipelineByPropertyName = true, ParameterSetName = FileFilePathParameterSet)]
public override IStorageContext Context { get; set; }

[Parameter(HelpMessage = "Destination Storage context object", ParameterSetName = ContainerNameParameterSet)]
Expand Down Expand Up @@ -198,13 +198,14 @@ private IStorageBlobManagement GetBlobChannel()
private AzureStorageContext GetSourceContext()
{
if (this.ParameterSetName == ContainerNameParameterSet ||
this.ParameterSetName == ShareNameParameterSet ||
this.ParameterSetName == ContainerParameterSet ||
this.ParameterSetName == BlobFilePathParameterSet ||
this.ParameterSetName == BlobFileParameterSet ||
this.ParameterSetName == ShareParameterSet ||
this.ParameterSetName == FileFilePathParameterSet ||
this.ParameterSetName == FileFileParameterSet)
this.ParameterSetName == ShareNameParameterSet
//this.ParameterSetName == ContainerParameterSet ||
//this.ParameterSetName == BlobFilePathParameterSet ||
//this.ParameterSetName == BlobFileParameterSet ||
//this.ParameterSetName == ShareParameterSet
//this.ParameterSetName == FileFilePathParameterSet ||
//this.ParameterSetName == FileFileParameterSet
)
{
return this.GetCmdletStorageContext();
}
Expand Down Expand Up @@ -391,10 +392,15 @@ private void StartCopyFromFile()

ShareFileClient destFile = this.GetDestFile();

if (((AzureStorageContext)this.Context).Track2OauthToken != null
&& string.Compare(sourceFile.Uri.Host, destFile.Uri.Host, ignoreCase: true) != 0)
//if (((AzureStorageContext)this.Context).Track2OauthToken != null
// && string.Compare(sourceFile.Uri.Host, destFile.Uri.Host, ignoreCase: true) != 0)
//{
// WriteWarning("The source File is on Azure AD credential, might cause cross account file copy fail. Please use source File based on SharedKey or SAS creadencial to avoid the failure.");
//}

if (!sourceFile.CanGenerateSasUri && string.Compare(sourceFile.Uri.Host, destFile.Uri.Host, ignoreCase: true) != 0)
{
WriteWarning("The source File is on Azure AD credential, might cause cross account file copy fail. Please use source File based on SharedKey or SAS creadencial to avoid the failure.");
WriteWarning("The source File cannot generate SAS Uri and might cause cross account file copy failures. Please use source File based on SharedKey or SAS creadencial to avoid the failure.");
}

Func<long, Task> taskGenerator = (taskId) => StartAsyncCopy(
Expand Down