X-Git-Url: https://git.r.bdr.sh/rbdr/mobius/blobdiff_plain/2d52424e94e617627e4438fd207ee94949409328..4fad3266d27d3d193c6e25298c6085dbf8a6b610:/hotline/files.go?ds=sidebyside diff --git a/hotline/files.go b/hotline/files.go index 7c2cd1a..4f55eba 100644 --- a/hotline/files.go +++ b/hotline/files.go @@ -10,6 +10,8 @@ import ( "strings" ) +const incompleteFileSuffix = ".incomplete" + func downcaseFileExtension(filename string) string { splitStr := strings.Split(filename, ".") ext := strings.ToLower( @@ -45,26 +47,54 @@ func getFileNameList(filePath string) (fields []Field, err error) { } for _, file := range files { - var fileType []byte var fnwi FileNameWithInfo + fileCreator := make([]byte, 4) - if !file.IsDir() { - fileType = []byte(fileTypeFromFilename(file.Name()).TypeCode) - fileCreator = []byte(fileTypeFromFilename(file.Name()).CreatorCode) - binary.BigEndian.PutUint32(fnwi.FileSize[:], uint32(file.Size())) - copy(fnwi.Type[:], fileType[:]) - copy(fnwi.Creator[:], fileCreator[:]) - } else { - fileType = []byte("fldr") + if file.Mode()&os.ModeSymlink != 0 { + resolvedPath, err := os.Readlink(filePath + "/" + file.Name()) + if err != nil { + return fields, err + } + rFile, err := os.Stat(filePath + "/" + resolvedPath) + if errors.Is(err, os.ErrNotExist) { + continue + } + if err != nil { + return fields, err + } + + if rFile.IsDir() { + dir, err := ioutil.ReadDir(filePath + "/" + file.Name()) + if err != nil { + return fields, err + } + binary.BigEndian.PutUint32(fnwi.FileSize[:], uint32(len(dir))) + 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)[:]) + } + + } else if file.IsDir() { dir, err := ioutil.ReadDir(filePath + "/" + file.Name()) if err != nil { return fields, err } binary.BigEndian.PutUint32(fnwi.FileSize[:], uint32(len(dir))) - copy(fnwi.Type[:], fileType[:]) + copy(fnwi.Type[:], []byte("fldr")[:]) copy(fnwi.Creator[:], fileCreator[:]) + } else { + // the Hotline protocol does not support file sizes > 4GiB due to the 4 byte field size, so skip them + if file.Size() > 4294967296 { + continue + } + binary.BigEndian.PutUint32(fnwi.FileSize[:], uint32(file.Size())) + copy(fnwi.Type[:], []byte(fileTypeFromFilename(file.Name()).TypeCode)[:]) + copy(fnwi.Creator[:], []byte(fileTypeFromFilename(file.Name()).CreatorCode)[:]) } strippedName := strings.Replace(file.Name(), ".incomplete", "", -1) @@ -149,8 +179,6 @@ func EncodeFilePath(filePath string) []byte { return bytes } -const incompleteFileSuffix = ".incomplete" - // effectiveFile wraps os.Open to check for the presence of a partial file transfer as a fallback func effectiveFile(filePath string) (*os.File, error) { file, err := os.Open(filePath)