Improved error handling

This commit is contained in:
Eduard Urbach 2023-11-03 10:42:10 +01:00
parent 8de28852cd
commit b72e3943a4
Signed by: eduard
GPG key ID: 49226B848C78F6C8
3 changed files with 10 additions and 15 deletions

View file

@ -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
}