]> git.r.bdr.sh - rbdr/mobius/blobdiff - hotline/file_transfer.go
Convert hardcoded path separators to filepath.Join
[rbdr/mobius] / hotline / file_transfer.go
index 9e86bb8724558164f948bc5a916f6c781cc4fb9c..90dbbe669a2c9391afbb481f81f5c27bcded0eaa 100644 (file)
@@ -3,7 +3,7 @@ package hotline
 import (
        "encoding/binary"
        "fmt"
 import (
        "encoding/binary"
        "fmt"
-       "strings"
+       "path/filepath"
 )
 
 // File transfer types
 )
 
 // File transfer types
@@ -38,38 +38,6 @@ func (ft *FileTransfer) ItemCount() int {
        return int(binary.BigEndian.Uint16(ft.FolderItemCount))
 }
 
        return int(binary.BigEndian.Uint16(ft.FolderItemCount))
 }
 
-// 00 28 // DataSize
-// 00 00 // IsFolder
-// 00 02 // PathItemCount
-//
-// 00 00
-// 09
-// 73 75 62 66 6f 6c 64 65 72 // "subfolder"
-//
-// 00 00
-// 15
-// 73 75 62 66 6f 6c 64 65 72 2d 74 65 73 74 66 69 6c 65 2d 35 6b // "subfolder-testfile-5k"
-func readFolderUpload(buf []byte) folderUpload {
-       dataLen := binary.BigEndian.Uint16(buf[0:2])
-
-       fu := folderUpload{
-               DataSize:      [2]byte{buf[0], buf[1]}, // Size of this structure (not including data size element itself)
-               IsFolder:      [2]byte{buf[2], buf[3]},
-               PathItemCount: [2]byte{buf[4], buf[5]},
-               FileNamePath:  buf[6 : dataLen+2],
-       }
-
-       return fu
-}
-
-func (fu *folderUpload) UnmarshalBinary(b []byte) error {
-       fu.DataSize = [2]byte{b[0], b[1]}
-       fu.IsFolder = [2]byte{b[2], b[3]}
-       fu.PathItemCount = [2]byte{b[4], b[5]}
-
-       return nil
-}
-
 type folderUpload struct {
        DataSize      [2]byte
        IsFolder      [2]byte
 type folderUpload struct {
        DataSize      [2]byte
        IsFolder      [2]byte
@@ -83,11 +51,12 @@ func (fu *folderUpload) FormattedPath() string {
        var pathSegments []string
        pathData := fu.FileNamePath
 
        var pathSegments []string
        pathData := fu.FileNamePath
 
+       // TODO: implement scanner interface instead?
        for i := uint16(0); i < pathItemLen; i++ {
                segLen := pathData[2]
                pathSegments = append(pathSegments, string(pathData[3:3+segLen]))
                pathData = pathData[3+segLen:]
        }
 
        for i := uint16(0); i < pathItemLen; i++ {
                segLen := pathData[2]
                pathSegments = append(pathSegments, string(pathData[3:3+segLen]))
                pathData = pathData[3+segLen:]
        }
 
-       return strings.Join(pathSegments, pathSeparator)
+       return filepath.Join(pathSegments...)
 }
 }