X-Git-Url: https://git.r.bdr.sh/rbdr/mobius/blobdiff_plain/2b7fabb5a1ff6092dd3ea62bd882dd0c02951b81..153e2eac3b51a6a426556752fa2c532cfe53f026:/hotline/files.go diff --git a/hotline/files.go b/hotline/files.go index dcabf9d..6753cce 100644 --- a/hotline/files.go +++ b/hotline/files.go @@ -3,6 +3,8 @@ package hotline import ( "encoding/binary" "errors" + "fmt" + "io" "io/fs" "os" "path/filepath" @@ -35,7 +37,7 @@ const maxFileSize = 4294967296 func getFileNameList(path string, ignoreList []string) (fields []Field, err error) { files, err := os.ReadDir(path) if err != nil { - return fields, nil + return fields, fmt.Errorf("error reading path: %s: %w", path, err) } for _, file := range files { @@ -49,14 +51,14 @@ func getFileNameList(path string, ignoreList []string) (fields []Field, err erro fileInfo, err := file.Info() if err != nil { - return fields, err + return fields, fmt.Errorf("error getting file info: %s: %w", file.Name(), err) } // Check if path is a symlink. If so, follow it. if fileInfo.Mode()&os.ModeSymlink != 0 { resolvedPath, err := os.Readlink(filepath.Join(path, file.Name())) if err != nil { - return fields, err + return fields, fmt.Errorf("error following symlink: %s: %w", resolvedPath, err) } rFile, err := os.Stat(resolvedPath) @@ -91,7 +93,7 @@ func getFileNameList(path string, ignoreList []string) (fields []Field, err erro } else if file.IsDir() { dir, err := os.ReadDir(filepath.Join(path, file.Name())) if err != nil { - return fields, err + return fields, fmt.Errorf("readDir: %w", err) } var c uint32 @@ -112,7 +114,7 @@ func getFileNameList(path string, ignoreList []string) (fields []Field, err erro hlFile, err := newFileWrapper(&OSFileStore{}, path+"/"+file.Name(), 0) if err != nil { - return nil, err + return nil, fmt.Errorf("newFileWrapper: %w", err) } copy(fnwi.FileSize[:], hlFile.totalSize()) @@ -130,11 +132,11 @@ func getFileNameList(path string, ignoreList []string) (fields []Field, err erro binary.BigEndian.PutUint16(nameSize, uint16(len(strippedName))) copy(fnwi.NameSize[:], nameSize) - fnwi.name = []byte(strippedName) + fnwi.Name = []byte(strippedName) - b, err := fnwi.MarshalBinary() + b, err := io.ReadAll(&fnwi) if err != nil { - return nil, err + return nil, fmt.Errorf("error io.ReadAll: %w", err) } fields = append(fields, NewField(FieldFileNameWithInfo, b)) }