aboutsummaryrefslogtreecommitdiff
path: root/hotline
diff options
context:
space:
mode:
authorJeff Halter <868228+jhalter@users.noreply.github.com>2022-06-05 16:44:18 -0700
committerJeff Halter <868228+jhalter@users.noreply.github.com>2022-06-05 16:44:18 -0700
commitd7548c16cdbff6f9baa2f545eb808030a6b3ec2e (patch)
tree05f202c116c0eb0794480837fd93a68cae9093c4 /hotline
parent2d52424e94e617627e4438fd207ee94949409328 (diff)
Follow symlinks in Files dir
Diffstat (limited to 'hotline')
-rw-r--r--hotline/files.go41
1 files changed, 31 insertions, 10 deletions
diff --git a/hotline/files.go b/hotline/files.go
index 7c2cd1a..04334e9 100644
--- a/hotline/files.go
+++ b/hotline/files.go
@@ -45,26 +45,47 @@ 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 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 {
+ 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)