Created
March 21, 2016 14:28
-
-
Save krishnasrinivas/d50845f9345f81c75d08 to your computer and use it in GitHub Desktop.
treewalk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func treeWalk(fsPath, bucket, prefix, marker string, recursive bool, send func) bool { | |
markerEntry := "" | |
markerRemaining := "" | |
markerSplit := []string{} | |
if marker != "" { | |
markerSplit = strings.SplitN(marker, "/", 2) | |
markerEntry = markerSplit[0] | |
if len(markerSplit) == 2 { | |
markerRemaining = markerSplit[1] | |
} | |
} | |
entries := readdir(filepath.Join(fsPath, bucket, prefix)) | |
index := searchFileInfos(fis, markerEntry) | |
entries = entries[index:] | |
if len(entries) > 0 { | |
if markerEntry == entries[0].Name() && !entries[0].IsDir() { | |
entries = entries[1:] | |
} | |
} | |
for _, entry := range entries { | |
if entry.IsDir() { | |
markerArg := "" | |
if entry.Name() == markerEntry { | |
markerArg = markerRemaining | |
} | |
if !treeWalk(fsPath, bucket, path.Join(prefix, entry.Name()), markerArg, send) { | |
return false | |
} | |
} else { | |
if !send(path.Join(prefix, entry.Name())) { | |
return false | |
} | |
} | |
} | |
return true | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment