]> git.r.bdr.sh - rbdr/mobius/blobdiff - hotline/files.go
Remove CircleCI config
[rbdr/mobius] / hotline / files.go
index 0746b1f6ef51d1f5f26bdf8fad34cd386ce11ea6..d4bea538258dc2ebc362b455bb48e27bd02952fa 100644 (file)
@@ -3,6 +3,7 @@ package hotline
 import (
        "encoding/binary"
        "errors"
+       "io"
        "io/fs"
        "os"
        "path/filepath"
@@ -30,6 +31,8 @@ func fileTypeFromInfo(info fs.FileInfo) (ft fileType, err error) {
        return ft, nil
 }
 
+const maxFileSize = 4294967296
+
 func getFileNameList(path string, ignoreList []string) (fields []Field, err error) {
        files, err := os.ReadDir(path)
        if err != nil {
@@ -50,13 +53,14 @@ func getFileNameList(path string, ignoreList []string) (fields []Field, err erro
                        return fields, 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
                        }
 
-                       rFile, err := os.Stat(filepath.Join(path, resolvedPath))
+                       rFile, err := os.Stat(resolvedPath)
                        if errors.Is(err, os.ErrNotExist) {
                                continue
                        }
@@ -78,12 +82,12 @@ func getFileNameList(path string, ignoreList []string) (fields []Field, err erro
                                }
 
                                binary.BigEndian.PutUint32(fnwi.FileSize[:], c)
-                               copy(fnwi.Type[:], []byte("fldr"))
+                               copy(fnwi.Type[:], "fldr")
                                copy(fnwi.Creator[:], fileCreator)
                        } else {
                                binary.BigEndian.PutUint32(fnwi.FileSize[:], uint32(rFile.Size()))
-                               copy(fnwi.Type[:], []byte(fileTypeFromFilename(rFile.Name()).TypeCode))
-                               copy(fnwi.Creator[:], []byte(fileTypeFromFilename(rFile.Name()).CreatorCode))
+                               copy(fnwi.Type[:], fileTypeFromFilename(rFile.Name()).TypeCode)
+                               copy(fnwi.Creator[:], fileTypeFromFilename(rFile.Name()).CreatorCode)
                        }
                } else if file.IsDir() {
                        dir, err := os.ReadDir(filepath.Join(path, file.Name()))
@@ -99,11 +103,11 @@ func getFileNameList(path string, ignoreList []string) (fields []Field, err erro
                        }
 
                        binary.BigEndian.PutUint32(fnwi.FileSize[:], c)
-                       copy(fnwi.Type[:], []byte("fldr"))
+                       copy(fnwi.Type[:], "fldr")
                        copy(fnwi.Creator[:], fileCreator)
                } else {
-                       // the Hotline protocol does not support fileWrapper sizes > 4GiB due to the 4 byte field size, so skip them
-                       if fileInfo.Size() > 4294967296 {
+                       // the Hotline protocol does not support file sizes > 4GiB due to the 4 byte field size, so skip them
+                       if fileInfo.Size() > maxFileSize {
                                continue
                        }
 
@@ -120,7 +124,7 @@ func getFileNameList(path string, ignoreList []string) (fields []Field, err erro
                strippedName := strings.ReplaceAll(file.Name(), ".incomplete", "")
                strippedName, err = txtEncoder.String(strippedName)
                if err != nil {
-                       return nil, err
+                       continue
                }
 
                nameSize := make([]byte, 2)
@@ -129,7 +133,7 @@ func getFileNameList(path string, ignoreList []string) (fields []Field, err erro
 
                fnwi.name = []byte(strippedName)
 
-               b, err := fnwi.MarshalBinary()
+               b, err := io.ReadAll(&fnwi)
                if err != nil {
                        return nil, err
                }