Skip to content

Commit 81fc973

Browse files
init commit
1 parent 13df0f9 commit 81fc973

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

traverser/zc_traverser_blob.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,10 @@ func (t *BlobTraverser) Traverse(preprocessor objectMorpher, processor ObjectPro
229229
return fmt.Errorf("cannot list files due to reason %s", respErr)
230230
} else if respErr.StatusCode == 403 { // Some nature of auth error-- Whatever the user is pointing at, they don't have access to, regardless of whether it's a file or a dir stub.
231231
return fmt.Errorf("cannot list files due to reason %s", respErr)
232-
}
232+
// TODO wonw
233+
//} else if respErr.StatusCode == 404 {
234+
// return fmt.Errorf("cannot list files due to reason %s", respErr)
235+
//}
233236
}
234237

235238
// schedule the blob in two cases:

traverser/zc_traverser_list.go

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ package traverser
2323
import (
2424
"context"
2525
"fmt"
26+
"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/bloberror"
2627
"net/url"
28+
"strings"
2729

2830
"github.com/Azure/azure-storage-azcopy/v10/common"
2931
)
@@ -46,6 +48,9 @@ func (l *listTraverser) IsDirectory(bool) (bool, error) {
4648
// To kill the traverser, close() the channel under it.
4749
// Behavior demonstrated: https://play.golang.org/p/OYdvLmNWgwO
4850
func (l *listTraverser) Traverse(preprocessor objectMorpher, processor ObjectProcessor, filters []ObjectFilter) (err error) {
51+
itemsProcessed := 0
52+
itemsSkipped := 0
53+
var lastError error
4954
// read a channel until it closes to get a list of objects
5055

5156
childPath, ok := <-l.listReader
@@ -57,12 +62,25 @@ func (l *listTraverser) Traverse(preprocessor objectMorpher, processor ObjectPro
5762
childTraverser, err := l.childTraverserGenerator(childPath)
5863
if err != nil {
5964
common.GetLifecycleMgr().Info(fmt.Sprintf("Skipping %s due to error %s", childPath, err))
65+
itemsSkipped++
66+
lastError = err
6067
continue
6168
}
6269
// listTraverser will only ever execute on the source
6370

64-
//TODO wonw why isnt the error handled from the file not found?
65-
isDir, _ := childTraverser.IsDirectory(true)
71+
// Handle error when necessary
72+
isDir, isDirErr := childTraverser.IsDirectory(true)
73+
74+
if isDirErr != nil {
75+
if bloberror.HasCode(isDirErr, bloberror.BlobNotFound) ||
76+
strings.Contains(isDirErr.Error(), common.FILE_NOT_FOUND) {
77+
common.GetLifecycleMgr().Info(fmt.Sprintf("Skipping %s: file/directory not found", childPath))
78+
itemsSkipped++
79+
lastError = isDirErr
80+
continue
81+
}
82+
}
83+
6684
if !l.recursive && isDir {
6785
continue // skip over directories
6886
}
@@ -84,6 +102,16 @@ func (l *listTraverser) Traverse(preprocessor objectMorpher, processor ObjectPro
84102
err = childTraverser.Traverse(preProcessorForThisChild, processor, filters)
85103
if err != nil {
86104
common.GetLifecycleMgr().Info(fmt.Sprintf("Skipping %s as it cannot be scanned due to error: %s", childPath, err))
105+
itemsSkipped++
106+
lastError = err
107+
} else {
108+
itemsProcessed++
109+
}
110+
}
111+
// Return err if nothing is processed
112+
if itemsProcessed == 0 && itemsSkipped > 0 {
113+
if lastError != nil {
114+
return fmt.Errorf("failed to process files with --list-of-files. Error: %w", lastError)
87115
}
88116
}
89117

0 commit comments

Comments
 (0)