]> git.r.bdr.sh - rbdr/mobius/blobdiff - hotline/file_transfer.go
Fix comments
[rbdr/mobius] / hotline / file_transfer.go
index e37295abd3d581d3140fe090b0a6015841551ab4..626cfff48823030be76618e1cdcfdc22a556f919 100644 (file)
@@ -87,6 +87,7 @@ func (ftm *MemFileTransferMgr) Delete(id FileTransferID) {
 }
 
 type FileTransfer struct {
+       FileRoot         string
        FileName         []byte
        FilePath         []byte
        RefNum           [4]byte
@@ -116,9 +117,10 @@ func (wc *WriteCounter) Write(p []byte) (int, error) {
        return n, nil
 }
 
-func (cc *ClientConn) NewFileTransfer(transferType FileTransferType, fileName, filePath, size []byte) *FileTransfer {
+func (cc *ClientConn) NewFileTransfer(transferType FileTransferType, fileroot string, fileName, filePath, size []byte) *FileTransfer {
        ft := &FileTransfer{
                FileName:         fileName,
+               FileRoot:         fileroot,
                FilePath:         filePath,
                Type:             transferType,
                TransferSize:     size,
@@ -289,14 +291,15 @@ func DownloadHandler(w io.Writer, fullPath string, fileTransfer *FileTransfer, f
                }
        }
 
-       rFile, err := fw.rsrcForkFile()
-       if err != nil {
-               // return fmt.Errorf("open resource fork file: %v", err)
-       }
+       rFile, _ := fw.rsrcForkFile()
+       //if err != nil {
+       //      // return fmt.Errorf("open resource fork file: %v", err)
+       //}
 
-       if _, err = io.Copy(w, io.TeeReader(rFile, fileTransfer.bytesSentCounter)); err != nil {
-               // return fmt.Errorf("send resource fork data: %v", err)
-       }
+       _, _ = io.Copy(w, io.TeeReader(rFile, fileTransfer.bytesSentCounter))
+       //if err != nil {
+       //      // return fmt.Errorf("send resource fork data: %v", err)
+       //}
 
        return nil
 }
@@ -323,12 +326,14 @@ func UploadHandler(rwc io.ReadWriter, fullPath string, fileTransfer *FileTransfe
                }
        }
 
+       defer file.Close()
+
        f, err := NewFileWrapper(fileStore, fullPath, 0)
        if err != nil {
                return err
        }
 
-       rLogger.Info("File upload started", "dstFile", fullPath)
+       rLogger.Debug("File upload started", "dstFile", fullPath)
 
        rForkWriter := io.Discard
        iForkWriter := io.Discard
@@ -345,15 +350,11 @@ func UploadHandler(rwc io.ReadWriter, fullPath string, fileTransfer *FileTransfe
        }
 
        if err := receiveFile(rwc, file, rForkWriter, iForkWriter, fileTransfer.bytesSentCounter); err != nil {
-               rLogger.Error(err.Error())
-       }
-
-       if err := file.Close(); err != nil {
-               return err
+               return fmt.Errorf("receive file: %v", err)
        }
 
        if err := fileStore.Rename(fullPath+".incomplete", fullPath); err != nil {
-               return err
+               return fmt.Errorf("rename incomplete file: %v", err)
        }
 
        rLogger.Info("File upload complete", "dstFile", fullPath)
@@ -365,26 +366,26 @@ func DownloadFolderHandler(rwc io.ReadWriter, fullPath string, fileTransfer *Fil
        // Folder Download flow:
        // 1. Get filePath from the transfer
        // 2. Iterate over files
-       // 3. For each fileWrapper:
-       //       Send fileWrapper header to client
+       // 3. For each file:
+       //       Send file header to client
        // The client can reply in 3 ways:
        //
-       // 1. If type is an odd number (unknown type?), or fileWrapper download for the current fileWrapper is completed:
-       //              client sends []byte{0x00, 0x03} to tell the server to continue to the next fileWrapper
+       // 1. If type is an odd number (unknown type?), or file download for the current file is completed:
+       //              client sends []byte{0x00, 0x03} to tell the server to continue to the next file
        //
-       // 2. If download of a fileWrapper is to be resumed:
+       // 2. If download of a file is to be resumed:
        //              client sends:
        //                      []byte{0x00, 0x02} // download folder action
        //                      [2]byte // Resume data size
-       //                      []byte fileWrapper resume data (see myField_FileResumeData)
+       //                      []byte file resume data (see myField_FileResumeData)
        //
-       // 3. Otherwise, download of the fileWrapper is requested and client sends []byte{0x00, 0x01}
+       // 3. Otherwise, download of the file is requested and client sends []byte{0x00, 0x01}
        //
        // When download is requested (case 2 or 3), server replies with:
-       //                      [4]byte - fileWrapper size
+       //                      [4]byte - file size
        //                      []byte  - Flattened File Object
        //
-       // After every fileWrapper download, client could request next fileWrapper with:
+       // After every file download, client could request next file with:
        //                      []byte{0x00, 0x03}
        //
        // This notifies the server to send the next item header
@@ -418,7 +419,6 @@ func DownloadFolderHandler(rwc io.ReadWriter, fullPath string, fileTransfer *Fil
                }
 
                subPath := path[basePathLen+1:]
-               rLogger.Debug("Sending fileheader", "i", i, "path", path, "fullFilePath", fullPath, "subPath", subPath, "IsDir", info.IsDir())
 
                if i == 1 {
                        return nil
@@ -434,8 +434,6 @@ func DownloadFolderHandler(rwc io.ReadWriter, fullPath string, fileTransfer *Fil
                        return err
                }
 
-               rLogger.Debug("Client folder download action", "action", fmt.Sprintf("%X", nextAction[0:2]))
-
                var dataOffset int64
 
                switch nextAction[1] {
@@ -672,7 +670,7 @@ func UploadFolderHandler(rwc io.ReadWriter, fullPath string, fileTransfer *FileT
                                }
                        }
 
-                       // Tell client to send next fileWrapper
+                       // Tell client to send next file
                        if _, err := rwc.Write([]byte{0, DlFldrActionNextFile}); err != nil {
                                return err
                        }