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 properly error message for system to system container copy #2883

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
11 changes: 11 additions & 0 deletions cmd/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -1634,6 +1634,17 @@ func (cca *CookedCopyCmdArgs) processCopyJobPartOrders() (err error) {
return fmt.Errorf("S2S copy from Azure File authenticated with Azure AD to Blob/BlobFS is not supported")
}

// Check if destination is system container
if cca.FromTo.IsS2S() {
dstContainerName, err := GetContainerName(cca.Destination.Value, cca.FromTo.To())
if err != nil {
return fmt.Errorf("failed to get container name from destination (is it formatted correctly?)")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we add the err with %w to the print statement?

}
if common.IsSystemContainer(dstContainerName) {
return fmt.Errorf("cannot copy to system container '%s'", dstContainerName)
}
}

switch {
case cca.FromTo.IsUpload(), cca.FromTo.IsDownload(), cca.FromTo.IsS2S():
// Execute a standard copy command
Expand Down
11 changes: 11 additions & 0 deletions cmd/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,17 @@ func (cca *cookedSyncCmdArgs) process() (err error) {
return fmt.Errorf("S2S sync from Azure File authenticated with Azure AD to Blob/BlobFS is not supported")
}

// Check if destination is system container
if cca.fromTo.IsS2S() {
dstContainerName, err := GetContainerName(cca.destination.Value, cca.fromTo.To())
if err != nil {
return fmt.Errorf("failed to get container name from destination (is it formatted correctly?)")
}
if common.IsSystemContainer(dstContainerName) {
return fmt.Errorf("cannot copy to system container '%s'", dstContainerName)
}
}

enumerator, err := cca.initEnumerator(ctx)
if err != nil {
return err
Expand Down
12 changes: 12 additions & 0 deletions common/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,3 +382,15 @@ func DoWithOverrideReadOnlyOnAzureFiles(ctx context.Context, action func() (inte
_, err = action()
return err
}

// @brief Thia API check if the container name provided is a system container or not
func IsSystemContainer(containerName string) bool {
// define the system variables for the system containers
systemContainers := []string{"$blobchangefeed", "$logs"}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These containers as destination of copy shall be errored out but as source it shall still work. Add test cases around such combinations in E2E

for _, sys := range systemContainers {
if containerName == sys {
return true
}
}
return false
}
Loading