Skip to content

Commit 05f98cf

Browse files
Improve error if we cannot determine if source is a directory (#1412)
* Improve error if we cannot determine if source is a directory * Replace ste logger with scanning logger * Undo white space changes * Fix CI
1 parent 134d2b6 commit 05f98cf

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

cmd/zc_traverser_blob.go

+24-2
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func (t *blobTraverser) IsDirectory(isSource bool) bool {
7272
return isDirDirect
7373
}
7474

75-
_, isSingleBlob, _, err := t.getPropertiesIfSingleBlob()
75+
_, _, isDirStub, err := t.getPropertiesIfSingleBlob()
7676

7777
if stgErr, ok := err.(azblob.StorageError); ok {
7878
// We know for sure this is a single blob still, let it walk on through to the traverser.
@@ -81,7 +81,29 @@ func (t *blobTraverser) IsDirectory(isSource bool) bool {
8181
}
8282
}
8383

84-
return !isSingleBlob
84+
if err == nil {
85+
return isDirStub
86+
}
87+
88+
blobURLParts := azblob.NewBlobURLParts(*t.rawURL)
89+
containerRawURL := copyHandlerUtil{}.getContainerUrl(blobURLParts)
90+
containerURL := azblob.NewContainerURL(containerRawURL, t.p)
91+
searchPrefix := strings.TrimSuffix(blobURLParts.BlobName, common.AZCOPY_PATH_SEPARATOR_STRING) + common.AZCOPY_PATH_SEPARATOR_STRING
92+
resp, err := containerURL.ListBlobsFlatSegment(t.ctx, azblob.Marker{}, azblob.ListBlobsSegmentOptions{Prefix: searchPrefix, MaxResults: 1})
93+
if err != nil {
94+
if azcopyScanningLogger != nil {
95+
msg := fmt.Sprintf("Failed to check if the destination is a folder or a file (Azure Files). Assuming the destination is a file: %s", err)
96+
azcopyScanningLogger.Log(pipeline.LogError, msg)
97+
}
98+
return false
99+
}
100+
101+
if len(resp.Segment.BlobItems) == 0 {
102+
//Not a directory
103+
return false
104+
}
105+
106+
return true
85107
}
86108

87109
func (t *blobTraverser) getPropertiesIfSingleBlob() (props *azblob.BlobGetPropertiesResponse, isBlob bool, isDirStub bool, err error) {

cmd/zt_sync_blob_blob_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ func (s *cmdIntegrationSuite) TestSyncS2SContainerAndEmptyVirtualDir(c *chk.C) {
482482

483483
// construct the raw input to simulate user input
484484
srcContainerURLWithSAS := scenarioHelper{}.getRawContainerURLWithSAS(c, srcContainerName)
485-
dstVirtualDirURLWithSAS := scenarioHelper{}.getRawBlobURLWithSAS(c, dstContainerName, "emptydir")
485+
dstVirtualDirURLWithSAS := scenarioHelper{}.getRawBlobURLWithSAS(c, dstContainerName, "emptydir/")
486486
raw := getDefaultSyncRawInput(srcContainerURLWithSAS.String(), dstVirtualDirURLWithSAS.String())
487487

488488
// verify that targeting a virtual directory works fine

testSuite/scripts/test_blob_sync.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def test_sync_entire_directory_with_local(self):
7171

7272
# sync to local
7373
src = vdir_sas
74-
dst = dir_path
74+
dst = dir_path + "/"
7575
result = util.Command("sync").add_arguments(src).add_arguments(dst).add_flags("log-level", "info")\
7676
.execute_azcopy_copy_command()
7777
self.assertTrue(result)
@@ -116,7 +116,7 @@ def test_sync_entire_vdir_to_vdir(self):
116116
content_dir_name = "dir_sync_test"
117117
content_dir_path = util.create_test_n_files(1024, 10, content_dir_name)
118118
src_vdir_path = util.get_resource_sas("srcdir")
119-
dst_vdir_path = util.get_resource_sas("dstdir")
119+
dst_vdir_path = util.get_resource_sas("dstdir/")
120120

121121
# create sub-directory inside directory
122122
sub_dir_name = os.path.join(content_dir_name, "sub_dir_sync_test")

0 commit comments

Comments
 (0)