X-Git-Url: https://git.r.bdr.sh/rbdr/mobius/blobdiff_plain/67d1f7231b807771b57c8f0e63dd796a03130eaf..9ff8293362adff9e7c39d9f620b593f6be661f1e:/hotline/files.go diff --git a/hotline/files.go b/hotline/files.go index c4ba718..8d35a94 100644 --- a/hotline/files.go +++ b/hotline/files.go @@ -4,7 +4,6 @@ import ( "encoding/binary" "errors" "io/fs" - "io/ioutil" "os" "path/filepath" "regexp" @@ -51,13 +50,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 } @@ -66,7 +66,7 @@ func getFileNameList(path string, ignoreList []string) (fields []Field, err erro } if rFile.IsDir() { - dir, err := ioutil.ReadDir(filepath.Join(path, file.Name())) + dir, err := os.ReadDir(filepath.Join(path, file.Name())) if err != nil { return fields, err } @@ -79,16 +79,15 @@ func getFileNameList(path string, ignoreList []string) (fields []Field, err erro } binary.BigEndian.PutUint32(fnwi.FileSize[:], c) - copy(fnwi.Type[:], []byte("fldr")[:]) - copy(fnwi.Creator[:], fileCreator[:]) + copy(fnwi.Type[:], []byte("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[:], []byte(fileTypeFromFilename(rFile.Name()).TypeCode)) + copy(fnwi.Creator[:], []byte(fileTypeFromFilename(rFile.Name()).CreatorCode)) } - } else if file.IsDir() { - dir, err := ioutil.ReadDir(filepath.Join(path, file.Name())) + dir, err := os.ReadDir(filepath.Join(path, file.Name())) if err != nil { return fields, err } @@ -101,8 +100,8 @@ func getFileNameList(path string, ignoreList []string) (fields []Field, err erro } binary.BigEndian.PutUint32(fnwi.FileSize[:], c) - copy(fnwi.Type[:], []byte("fldr")[:]) - copy(fnwi.Creator[:], fileCreator[:]) + copy(fnwi.Type[:], []byte("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 { @@ -114,16 +113,20 @@ func getFileNameList(path string, ignoreList []string) (fields []Field, err erro return nil, err } - copy(fnwi.FileSize[:], hlFile.totalSize()[:]) - copy(fnwi.Type[:], hlFile.ffo.FlatFileInformationFork.TypeSignature[:]) - copy(fnwi.Creator[:], hlFile.ffo.FlatFileInformationFork.CreatorSignature[:]) + copy(fnwi.FileSize[:], hlFile.totalSize()) + copy(fnwi.Type[:], hlFile.ffo.FlatFileInformationFork.TypeSignature) + copy(fnwi.Creator[:], hlFile.ffo.FlatFileInformationFork.CreatorSignature) } - strippedName := strings.Replace(file.Name(), ".incomplete", "", -1) + strippedName := strings.ReplaceAll(file.Name(), ".incomplete", "") + strippedName, err = txtEncoder.String(strippedName) + if err != nil { + return nil, err + } nameSize := make([]byte, 2) binary.BigEndian.PutUint16(nameSize, uint16(len(strippedName))) - copy(fnwi.NameSize[:], nameSize[:]) + copy(fnwi.NameSize[:], nameSize) fnwi.name = []byte(strippedName)