Skip to content

Commit

Permalink
Resolve comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
Strikerzee committed May 30, 2022
1 parent 23e8eb6 commit da38610
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 29 deletions.
4 changes: 2 additions & 2 deletions cmd/list.go
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"strconv"
"strings"

pipeline2 "github.com/Azure/azure-pipeline-go/pipeline"
"github.com/Azure/azure-pipeline-go/pipeline"

"github.com/spf13/cobra"

Expand Down Expand Up @@ -221,7 +221,7 @@ func (cooked cookedListCmdArgs) HandleListContainerCommand() (err error) {

traverser, err := InitResourceTraverser(source, cooked.location, &ctx, &credentialInfo, nil, nil,
true, false, false, common.EPermanentDeleteOption.None(), func(common.EntityType) {},
nil, false, pipeline2.LogNone, common.CpkOptions{}, nil /* errorChannel */)
nil, false, pipeline.LogNone, common.CpkOptions{}, nil /* errorChannel */)

if err != nil {
return fmt.Errorf("failed to initialize traverser: %s", err.Error())
Expand Down
48 changes: 21 additions & 27 deletions cmd/zc_traverser_local.go
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,12 @@ func (s symlinkTargetFileInfo) Name() string {
return s.name // override the name
}

func writeToErrorChannel(errorChannel chan ErrorFileInfo, err ErrorFileInfo) {
if errorChannel != nil {
errorChannel <- err
}
}

// WalkWithSymlinks is a symlinks-aware, parallelized, version of filePath.Walk.
// Separate this from the traverser for two purposes:
// 1) Cleaner code
Expand Down Expand Up @@ -195,10 +201,8 @@ func WalkWithSymlinks(appCtx context.Context, fullPath string, walkFunc filepath
// (for simplicity of coding, we don't parallelize across multiple queueItems)
parallel.Walk(appCtx, queueItem.fullPath, EnumerationParallelism, EnumerationParallelStatFiles, func(filePath string, fileInfo os.FileInfo, fileError error) error {
if fileError != nil {
WarnStdoutAndScanningLog(fmt.Sprintf("Accessing '%s' failed with error: %s", filePath, fileError))
if errorChannel != nil {
errorChannel <- ErrorFileInfo{FilePath: filePath, FileInfo: fileInfo, ErrorMsg: fileError}
}
WarnStdoutAndScanningLog(fmt.Sprintf("Accessing '%s' failed with error: %v", filePath, fileError))
writeToErrorChannel(errorChannel, ErrorFileInfo{FilePath: filePath, FileInfo: fileInfo, ErrorMsg: fileError})
return nil
}
computedRelativePath := strings.TrimPrefix(cleanLocalPath(filePath), cleanLocalPath(queueItem.fullPath))
Expand All @@ -216,41 +220,33 @@ func WalkWithSymlinks(appCtx context.Context, fullPath string, walkFunc filepath
result, err := UnfurlSymlinks(filePath)

if err != nil {
err = fmt.Errorf("Failed to resolve symlink %s: %s", filePath, err)
err = fmt.Errorf("Failed to resolve symlink %s: %v", filePath, err)
WarnStdoutAndScanningLog(err.Error())
if errorChannel != nil {
errorChannel <- ErrorFileInfo{FilePath: filePath, FileInfo: fileInfo, ErrorMsg: err}
}
writeToErrorChannel(errorChannel, ErrorFileInfo{FilePath: filePath, FileInfo: fileInfo, ErrorMsg: err})
return nil
}

result, err = filepath.Abs(result)
if err != nil {
err = fmt.Errorf("Failed to get absolute path of symlink result %s: %s", filePath, err)
err = fmt.Errorf("Failed to get absolute path of symlink result %s: %v", filePath, err)
WarnStdoutAndScanningLog(err.Error())
if errorChannel != nil {
errorChannel <- ErrorFileInfo{FilePath: filePath, FileInfo: fileInfo, ErrorMsg: err}
}
writeToErrorChannel(errorChannel, ErrorFileInfo{FilePath: filePath, FileInfo: fileInfo, ErrorMsg: err})
return nil
}

slPath, err := filepath.Abs(filePath)
if err != nil {
err = fmt.Errorf("Failed to get absolute path of %s: %s", filePath, err)
err = fmt.Errorf("Failed to get absolute path of %s: %v", filePath, err)
WarnStdoutAndScanningLog(err.Error())
if errorChannel != nil {
errorChannel <- ErrorFileInfo{FilePath: filePath, FileInfo: fileInfo, ErrorMsg: err}
}
writeToErrorChannel(errorChannel, ErrorFileInfo{FilePath: filePath, FileInfo: fileInfo, ErrorMsg: err})
return nil
}

rStat, err := os.Stat(result)
if err != nil {
err = fmt.Errorf("Failed to get properties of symlink target at %s: %s", result, err)
err = fmt.Errorf("Failed to get properties of symlink target at %s: %v", result, err)
WarnStdoutAndScanningLog(err.Error())
if errorChannel != nil {
errorChannel <- ErrorFileInfo{FilePath: filePath, FileInfo: fileInfo, ErrorMsg: err}
}
writeToErrorChannel(errorChannel, ErrorFileInfo{FilePath: filePath, FileInfo: fileInfo, ErrorMsg: err})
return nil
}

Expand Down Expand Up @@ -299,11 +295,9 @@ func WalkWithSymlinks(appCtx context.Context, fullPath string, walkFunc filepath
result, err := filepath.Abs(filePath)

if err != nil {
err = fmt.Errorf("Failed to get absolute path of %s: %s", filePath, err)
err = fmt.Errorf("Failed to get absolute path of %s: %v", filePath, err)
WarnStdoutAndScanningLog(err.Error())
if errorChannel != nil {
errorChannel <- ErrorFileInfo{FilePath: filePath, FileInfo: fileInfo, ErrorMsg: err}
}
writeToErrorChannel(errorChannel, ErrorFileInfo{FilePath: filePath, FileInfo: fileInfo, ErrorMsg: err})
return nil
}

Expand Down Expand Up @@ -338,7 +332,7 @@ func (t *localTraverser) Traverse(preprocessor objectMorpher, processor objectPr
singleFileInfo, isSingleFile, err := t.getInfoIfSingleFile()

if err != nil {
azcopyScanningLogger.Log(pipeline.LogError, fmt.Sprintf("Failed to scan path %s: %s", t.fullPath, err.Error()))
azcopyScanningLogger.Log(pipeline.LogError, fmt.Sprintf("Failed to scan path %s: %v", t.fullPath, err.Error()))
return fmt.Errorf("failed to scan path %s due to %s", t.fullPath, err.Error())
}

Expand Down Expand Up @@ -369,15 +363,15 @@ func (t *localTraverser) Traverse(preprocessor objectMorpher, processor objectPr
if t.recursive {
processFile := func(filePath string, fileInfo os.FileInfo, fileError error) error {
if fileError != nil {
WarnStdoutAndScanningLog(fmt.Sprintf("Accessing %s failed with error: %s", filePath, fileError))
WarnStdoutAndScanningLog(fmt.Sprintf("Accessing %s failed with error: %v", filePath, fileError))
return nil
}

var entityType common.EntityType
if fileInfo.IsDir() {
newFileInfo, err := WrapFolder(filePath, fileInfo)
if err != nil {
WarnStdoutAndScanningLog(fmt.Sprintf("Failed to get last change of target at %s: %s", filePath, err))
WarnStdoutAndScanningLog(fmt.Sprintf("Failed to get last change of target at %s: %v", filePath, err))
} else {
// fileInfo becomes nil in case we fail to wrap folder.
fileInfo = newFileInfo
Expand Down

0 comments on commit da38610

Please sign in to comment.