Skip to content

Commit

Permalink
Azcopy sync option for file share is not supported (#2676)
Browse files Browse the repository at this point in the history
* Azcopy sync option for file share is not supported

* Added e2e test

* corrected the failed test case due to code changes

* updated e2e test

* restored the original changes for unchanged files

---------

Co-authored-by: Gauri Lamunion <[email protected]>
  • Loading branch information
dphulkar-msft and gapra-msft committed May 27, 2024
1 parent a2521ad commit bc87edc
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 3 deletions.
17 changes: 17 additions & 0 deletions cmd/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ import (
"github.com/spf13/cobra"
)

var LocalToFileShareWarnMsg = "AzCopy sync is supported but not fully recommended for Azure Files. AzCopy sync doesn't support differential copies at scale, and some file fidelity might be lost."

type rawSyncCmdArgs struct {
src string
dst string
Expand Down Expand Up @@ -152,6 +154,21 @@ func (raw *rawSyncCmdArgs) cook() (cookedSyncCmdArgs, error) {
return cooked, err
}

// display a warning message to console and job log file if there is a sync operation being performed from local to file share.
// Reference : https://learn.microsoft.com/en-us/azure/storage/common/storage-use-azcopy-files#synchronize-files
if cooked.fromTo == common.EFromTo.LocalFile() {

glcm.Warn(LocalToFileShareWarnMsg)
if jobsAdmin.JobsAdmin != nil {
jobsAdmin.JobsAdmin.LogToJobLog(LocalToFileShareWarnMsg, common.LogWarning)
}
if raw.dryrun {
glcm.Dryrun(func(_ common.OutputFormat) string {
return fmt.Sprintf("DRYRUN: warn %s", LocalToFileShareWarnMsg)
})
}
}

switch cooked.fromTo {
case common.EFromTo.Unknown():
return cooked, fmt.Errorf("Unable to infer the source '%s' / destination '%s'. ", raw.src, raw.dst)
Expand Down
10 changes: 7 additions & 3 deletions cmd/zt_sync_comparator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@ package cmd

import (
"context"
"github.com/Azure/azure-storage-azcopy/v10/common"
"github.com/stretchr/testify/assert"
"os"
"sort"
"strings"
"testing"
"time"

"github.com/Azure/azure-storage-azcopy/v10/common"
"github.com/stretchr/testify/assert"
)

// regular file->file sync
Expand Down Expand Up @@ -619,10 +620,13 @@ func TestDryrunSyncLocaltoFile(t *testing.T) {
for i := 0; i < len(msg); i++ {
if strings.Contains(msg[i], "DRYRUN: remove") {
a.True(strings.Contains(msg[i], dstShareClient.URL()))
} else {
} else if strings.Contains(msg[i], "DRYRUN: copy") {
a.True(strings.Contains(msg[i], "DRYRUN: copy"))
a.True(strings.Contains(msg[i], srcDirName))
a.True(strings.Contains(msg[i], dstShareClient.URL()))
} else {
a.True(strings.Contains(msg[i], "DRYRUN: warn"))
a.True(strings.Contains(msg[i], LocalToFileShareWarnMsg))
}
}

Expand Down
36 changes: 36 additions & 0 deletions e2etest/zt_sync_local_file_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package e2etest

import (
"github.com/Azure/azure-storage-azcopy/v10/cmd"
"github.com/Azure/azure-storage-azcopy/v10/common"
)

// @brief This scenario performs sync operation from local to file share.
// @validation This test verifies if the warning message is displayed on console if the
// user tries to perform sync operation from local to file share.
func (s *FileOAuthTestSuite) Scenario_SyncFromLocalToFSWarningMsg(svm *ScenarioVariationManager) {
azCopyVerb := ResolveVariation(svm, []AzCopyVerb{AzCopyVerbSync}) // Calculate verb early to create the destination object early

srcContainer := CreateResource[ContainerResourceManager](svm, GetRootResource(svm, common.ELocation.Local()), ResourceDefinitionContainer{})
dstContainer := CreateResource[ContainerResourceManager](svm, GetRootResource(svm, common.ELocation.File()), ResourceDefinitionContainer{})

dstAuth := ResolveVariation(svm, []ExplicitCredentialTypes{EExplicitCredentialType.SASToken(), EExplicitCredentialType.OAuth()})

stdout, _ := RunAzCopy(
svm,
AzCopyCommand{
Verb: azCopyVerb,
Targets: []ResourceManager{
TryApplySpecificAuthType(srcContainer, EExplicitCredentialType.OAuth(), svm, CreateAzCopyTargetOptions{}),
TryApplySpecificAuthType(dstContainer, dstAuth, svm, CreateAzCopyTargetOptions{}),
},
Flags: CopyFlags{
CopySyncCommonFlags: CopySyncCommonFlags{
Recursive: pointerTo(true),
},
},
ShouldFail: false,
})

ValidateErrorOutput(svm, stdout, cmd.LocalToFileShareWarnMsg)
}

0 comments on commit bc87edc

Please sign in to comment.