Skip to content

Commit 81b733d

Browse files
committed
linting
1 parent 8eb18a4 commit 81b733d

File tree

5 files changed

+56
-152
lines changed

5 files changed

+56
-152
lines changed
Lines changed: 54 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package cmd
1+
package azcopy
22

33
import (
44
"context"
@@ -14,94 +14,94 @@ func TestValidateProtocolCompatibility(t *testing.T) {
1414

1515
// Test cases where validation should NOT be called (no File locations involved)
1616
testCases := []struct {
17-
name string
18-
fromTo common.FromTo
17+
name string
18+
fromTo common.FromTo
1919
shouldValidate bool
20-
description string
20+
description string
2121
}{
2222
{
23-
name: "S3ToBlob",
24-
fromTo: common.EFromTo.S3Blob(),
23+
name: "S3ToBlob",
24+
fromTo: common.EFromTo.S3Blob(),
2525
shouldValidate: false,
26-
description: "S3 to Blob should not validate (neither side is File)",
26+
description: "S3 to Blob should not validate (neither side is File)",
2727
},
2828
{
29-
name: "GCPToBlob",
30-
fromTo: common.EFromTo.GCPBlob(),
29+
name: "GCPToBlob",
30+
fromTo: common.EFromTo.GCPBlob(),
3131
shouldValidate: false,
32-
description: "GCP to Blob should not validate (neither side is File)",
32+
description: "GCP to Blob should not validate (neither side is File)",
3333
},
3434
{
35-
name: "LocalToBlob",
36-
fromTo: common.EFromTo.LocalBlob(),
35+
name: "LocalToBlob",
36+
fromTo: common.EFromTo.LocalBlob(),
3737
shouldValidate: false,
38-
description: "Local to Blob should not validate (neither side is File)",
38+
description: "Local to Blob should not validate (neither side is File)",
3939
},
4040
{
41-
name: "BlobToLocal",
42-
fromTo: common.EFromTo.BlobLocal(),
41+
name: "BlobToLocal",
42+
fromTo: common.EFromTo.BlobLocal(),
4343
shouldValidate: false,
44-
description: "Blob to Local should not validate (neither side is File)",
44+
description: "Blob to Local should not validate (neither side is File)",
4545
},
4646
{
47-
name: "BlobToBlob",
48-
fromTo: common.EFromTo.BlobBlob(),
47+
name: "BlobToBlob",
48+
fromTo: common.EFromTo.BlobBlob(),
4949
shouldValidate: false,
50-
description: "Blob to Blob should not validate (neither side is File)",
50+
description: "Blob to Blob should not validate (neither side is File)",
5151
},
5252
{
53-
name: "LocalToBlobFS",
54-
fromTo: common.EFromTo.LocalBlobFS(),
53+
name: "LocalToBlobFS",
54+
fromTo: common.EFromTo.LocalBlobFS(),
5555
shouldValidate: false,
56-
description: "Local to BlobFS should not validate (neither side is File)",
56+
description: "Local to BlobFS should not validate (neither side is File)",
5757
},
5858
{
59-
name: "LocalToFile",
60-
fromTo: common.EFromTo.LocalFile(),
59+
name: "LocalToFile",
60+
fromTo: common.EFromTo.LocalFile(),
6161
shouldValidate: true,
62-
description: "Local to File should validate (destination is File)",
62+
description: "Local to File should validate (destination is File)",
6363
},
6464
{
65-
name: "FileToLocal",
66-
fromTo: common.EFromTo.FileLocal(),
65+
name: "FileToLocal",
66+
fromTo: common.EFromTo.FileLocal(),
6767
shouldValidate: true,
68-
description: "File to Local should validate (source is File)",
68+
description: "File to Local should validate (source is File)",
6969
},
7070
{
71-
name: "LocalToFileNFS",
72-
fromTo: common.EFromTo.LocalFileNFS(),
71+
name: "LocalToFileNFS",
72+
fromTo: common.EFromTo.LocalFileNFS(),
7373
shouldValidate: true,
74-
description: "Local to FileNFS should validate (destination is FileNFS)",
74+
description: "Local to FileNFS should validate (destination is FileNFS)",
7575
},
7676
{
77-
name: "FileNFSToLocal",
78-
fromTo: common.EFromTo.FileNFSLocal(),
77+
name: "FileNFSToLocal",
78+
fromTo: common.EFromTo.FileNFSLocal(),
7979
shouldValidate: true,
80-
description: "FileNFS to Local should validate (source is FileNFS)",
80+
description: "FileNFS to Local should validate (source is FileNFS)",
8181
},
8282
{
83-
name: "FileToFile",
84-
fromTo: common.EFromTo.FileFile(),
83+
name: "FileToFile",
84+
fromTo: common.EFromTo.FileFile(),
8585
shouldValidate: true,
86-
description: "File to File should validate (both sides are File)",
86+
description: "File to File should validate (both sides are File)",
8787
},
8888
{
89-
name: "FileNFSToFileNFS",
90-
fromTo: common.EFromTo.FileNFSFileNFS(),
89+
name: "FileNFSToFileNFS",
90+
fromTo: common.EFromTo.FileNFSFileNFS(),
9191
shouldValidate: true,
92-
description: "FileNFS to FileNFS should validate (both sides are FileNFS)",
92+
description: "FileNFS to FileNFS should validate (both sides are FileNFS)",
9393
},
9494
{
95-
name: "FileToBlob",
96-
fromTo: common.EFromTo.FileBlob(),
95+
name: "FileToBlob",
96+
fromTo: common.EFromTo.FileBlob(),
9797
shouldValidate: true,
98-
description: "File to Blob should validate (source is File)",
98+
description: "File to Blob should validate (source is File)",
9999
},
100100
{
101-
name: "BlobToFile",
102-
fromTo: common.EFromTo.BlobFile(),
101+
name: "BlobToFile",
102+
fromTo: common.EFromTo.BlobFile(),
103103
shouldValidate: true,
104-
description: "Blob to File should validate (destination is File)",
104+
description: "Blob to File should validate (destination is File)",
105105
},
106106
}
107107

@@ -110,21 +110,21 @@ func TestValidateProtocolCompatibility(t *testing.T) {
110110
// Create dummy resource strings
111111
src := common.ResourceString{Value: "https://source.example.com/path"}
112112
dst := common.ResourceString{Value: "https://dest.example.com/path"}
113-
113+
114114
// For non-File transfers, we can pass nil service clients since validation should be skipped
115115
// For File transfers, we would need proper service clients, but we're testing the conditional logic
116116
var srcClient, dstClient *common.ServiceClient
117-
117+
118118
if !tc.shouldValidate {
119119
// Test that validation is skipped when no File locations are involved
120120
// This should not panic even with nil service clients
121-
err := validateProtocolCompatibility(ctx, tc.fromTo, src, dst, srcClient, dstClient)
121+
err := ValidateProtocolCompatibility(ctx, tc.fromTo, src, dst, srcClient, dstClient)
122122
a.NoError(err, "validateProtocolCompatibility should not fail for %s: %s", tc.name, tc.description)
123123
} else {
124124
// For File transfers, we expect the function to attempt validation
125125
// Since we're passing nil service clients, we expect it to fail gracefully
126126
// This tests that the conditional logic correctly identifies File transfers
127-
err := validateProtocolCompatibility(ctx, tc.fromTo, src, dst, srcClient, dstClient)
127+
err := ValidateProtocolCompatibility(ctx, tc.fromTo, src, dst, srcClient, dstClient)
128128
// We expect an error here because we're passing nil service clients for File transfers
129129
// The important thing is that it doesn't panic and attempts validation
130130
if tc.fromTo.From().IsFile() || tc.fromTo.To().IsFile() {
@@ -144,14 +144,14 @@ func TestValidateProtocolCompatibility_ConditionalLogic(t *testing.T) {
144144
dst := common.ResourceString{Value: "https://dest.example.com/path"}
145145

146146
// Test that S3->Blob doesn't call validation (should not panic with nil clients)
147-
err := validateProtocolCompatibility(ctx, common.EFromTo.S3Blob(), src, dst, nil, nil)
147+
err := ValidateProtocolCompatibility(ctx, common.EFromTo.S3Blob(), src, dst, nil, nil)
148148
a.NoError(err, "S3->Blob should skip validation and not panic with nil service clients")
149149

150-
// Test that GCP->Blob doesn't call validation (should not panic with nil clients)
151-
err = validateProtocolCompatibility(ctx, common.EFromTo.GCPBlob(), src, dst, nil, nil)
150+
// Test that GCP->Blob doesn't call validation (should not panic with nil clients)
151+
err = ValidateProtocolCompatibility(ctx, common.EFromTo.GCPBlob(), src, dst, nil, nil)
152152
a.NoError(err, "GCP->Blob should skip validation and not panic with nil service clients")
153153

154154
// Test that Local->Blob doesn't call validation (should not panic with nil clients)
155-
err = validateProtocolCompatibility(ctx, common.EFromTo.LocalBlob(), src, dst, nil, nil)
155+
err = ValidateProtocolCompatibility(ctx, common.EFromTo.LocalBlob(), src, dst, nil, nil)
156156
a.NoError(err, "Local->Blob should skip validation and not panic with nil service clients")
157157
}

cmd/flagsValidation.go

Lines changed: 0 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,8 @@
2020
package cmd
2121

2222
import (
23-
"context"
24-
"errors"
25-
"fmt"
2623
"runtime"
2724

28-
"github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/file"
29-
"github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/share"
3025
"github.com/Azure/azure-storage-azcopy/v10/azcopy"
3126
"github.com/Azure/azure-storage-azcopy/v10/common"
3227
"github.com/spf13/cobra"
@@ -105,96 +100,6 @@ import (
105100
// return nil
106101
// }
107102

108-
func validateShareProtocolCompatibility(
109-
ctx context.Context,
110-
resource common.ResourceString,
111-
serviceClient *common.ServiceClient,
112-
isSource bool,
113-
protocol common.Location,
114-
fromTo common.FromTo,
115-
) error {
116-
117-
// We can ignore the error if we fail to get the share properties.
118-
fileURLParts, err := file.ParseURL(resource.Value)
119-
if err != nil {
120-
return fmt.Errorf("failed to parse resource URL: %w", err)
121-
}
122-
shareName := fileURLParts.ShareName
123-
124-
if serviceClient == nil {
125-
return fmt.Errorf("service client is nil")
126-
}
127-
128-
fileServiceClient, err := serviceClient.FileServiceClient()
129-
if err != nil {
130-
return fmt.Errorf("failed to create file service client: %w", err)
131-
}
132-
shareClient := fileServiceClient.NewShareClient(shareName)
133-
shareProtocol, _ := getShareProtocolType(ctx, shareName, shareClient, protocol)
134-
135-
if shareProtocol == common.ELocation.File() {
136-
if isSource && fromTo.From() != common.ELocation.File() {
137-
return errors.New("the source share has SMB protocol enabled. " +
138-
"To copy from a SMB share, use the appropriate --from-to flag value")
139-
}
140-
if !isSource && fromTo.To() != common.ELocation.File() {
141-
return errors.New("the destination share has NFS protocol enabled. " +
142-
"To copy to a NFS share, use the appropriate --from-to flag value")
143-
}
144-
}
145-
146-
if shareProtocol == common.ELocation.FileNFS() {
147-
if isSource && fromTo.From() != common.ELocation.FileNFS() {
148-
return errors.New("the source share has NFS protocol enabled. " +
149-
"To copy from a NFS share, use the appropriate --from-to flag value")
150-
}
151-
if !isSource && fromTo.To() != common.ELocation.FileNFS() {
152-
return errors.New("the destination share has NFS protocol enabled. " +
153-
"To copy to a NFS share, use the appropriate --from-to flag value")
154-
}
155-
}
156-
return nil
157-
}
158-
159-
// getShareProtocolType returns "SMB", "NFS", or "UNKNOWN" based on the share's enabled protocols.
160-
// If retrieval fails, it logs a warning and returns the fallback givenValue ("SMB" or "NFS").
161-
func getShareProtocolType(
162-
ctx context.Context,
163-
shareName string,
164-
shareClient *share.Client,
165-
givenValue common.Location,
166-
) (common.Location, error) {
167-
properties, err := shareClient.GetProperties(ctx, nil)
168-
if err != nil {
169-
glcm.Info(fmt.Sprintf("Warning: Failed to fetch share properties for '%s'. Assuming the share uses '%s' protocol based on --from-to flag.", shareName, givenValue))
170-
return givenValue, err
171-
}
172-
173-
if properties.EnabledProtocols == nil || *properties.EnabledProtocols == "SMB" {
174-
return common.ELocation.File(), nil // Default assumption
175-
}
176-
177-
return common.ELocation.FileNFS(), nil
178-
}
179-
180-
// Protocol compatibility validation for SMB and NFS transfers
181-
func validateProtocolCompatibility(ctx context.Context, fromTo common.FromTo, src, dst common.ResourceString, srcClient, dstClient *common.ServiceClient) error {
182-
183-
if fromTo.From().IsFile() {
184-
if err := validateShareProtocolCompatibility(ctx, src, srcClient, true, fromTo.From(), fromTo); err != nil {
185-
return err
186-
}
187-
}
188-
189-
if fromTo.To().IsFile() {
190-
if err := validateShareProtocolCompatibility(ctx, dst, dstClient, false, fromTo.To(), fromTo); err != nil {
191-
return err
192-
}
193-
}
194-
195-
return nil
196-
}
197-
198103
// ComputePreserveFlags determines the final preserveInfo and preservePermissions flag values
199104
// based on user inputs, deprecated flags, and validation rules.
200105
func ComputePreserveFlags(cmd *cobra.Command, userFromTo common.FromTo, preserveInfo, preserveSMBInfo, preservePermissions, preserveSMBPermissions bool) (bool, bool) {

cmd/list.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ func (cooked cookedListCmdArgs) handleListContainerCommand() (err error) {
266266
fileClientOptions = &common.FileClientOptions{AllowTrailingDot: cooked.trailingDot.IsEnabled()}
267267
}
268268

269-
targetServiceClient, err := common.GetServiceClientForLocation(
269+
targetServiceClient, _ := common.GetServiceClientForLocation(
270270
cooked.location,
271271
source,
272272
credentialInfo.CredentialType,

cmd/syncEnumerator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,10 @@ func (cca *cookedSyncCmdArgs) initEnumerator(ctx context.Context) (enumerator *t
114114
return nil, err
115115
}
116116

117+
dstServiceClient, dstCredType, err := azcopy.GetDestinationServiceClient(ctx, cca.destination, cca.fromTo, srcCredType, cca.trailingDot, cca.cpkOptions, uotm)
117118
if err != nil {
118119
return nil, err
119120
}
120-
dstServiceClient, dstCredType, err := azcopy.GetDestinationServiceClient(ctx, cca.destination, cca.fromTo, srcCredType, cca.trailingDot, cca.cpkOptions, uotm)
121121

122122
// TODO: enable symlink support in a future release after evaluating the implications
123123
// GetProperties is enabled by default as sync supports both upload and download.

cmd/zc_processor.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ type copyTransferProcessor struct {
4545
preserveAccessTier bool
4646
folderPropertiesOption common.FolderPropertyOption
4747
symlinkHandlingType common.SymlinkHandlingType
48-
dryrunMode bool
4948
hardlinkHandlingType common.HardlinkHandlingType
5049
}
5150

0 commit comments

Comments
 (0)