Improved error handling
This commit is contained in:
parent
8de28852cd
commit
b72e3943a4
3 changed files with 10 additions and 15 deletions
|
@ -9,11 +9,11 @@ const blockSize = 4096
|
|||
|
||||
// Walk calls your callback function for every file name inside the directory.
|
||||
// It doesn't distinguish between files and directories.
|
||||
func Walk(directory string, callBack func(string)) {
|
||||
func Walk(directory string, callBack func(string)) error {
|
||||
fd, err := syscall.Open(directory, 0, 0)
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
return err
|
||||
}
|
||||
|
||||
defer syscall.Close(fd)
|
||||
|
@ -23,7 +23,7 @@ func Walk(directory string, callBack func(string)) {
|
|||
n, err := syscall.ReadDirent(fd, buffer)
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
return err
|
||||
}
|
||||
|
||||
if n <= 0 {
|
||||
|
@ -58,4 +58,6 @@ func Walk(directory string, callBack func(string)) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue