aboutsummaryrefslogtreecommitdiff
path: root/hotline
diff options
context:
space:
mode:
authorJeff Halter <868228+jhalter@users.noreply.github.com>2025-11-19 16:36:06 -0800
committerJeff Halter <868228+jhalter@users.noreply.github.com>2025-11-19 16:36:06 -0800
commit1b2df8a630bfc83304ef90610bdf7ebe91d4e555 (patch)
tree9a9df319d5cc16ab9cdebf481515c11f648a4ba1 /hotline
parentb395859da4937fa4c3064f4e022e46690df8f2d4 (diff)
Fix error when downloading incomplete files
Diffstat (limited to 'hotline')
-rw-r--r--hotline/file_transfer.go16
-rw-r--r--hotline/file_wrapper.go8
-rw-r--r--hotline/files.go4
3 files changed, 16 insertions, 12 deletions
diff --git a/hotline/file_transfer.go b/hotline/file_transfer.go
index 521b963..e8acbb3 100644
--- a/hotline/file_transfer.go
+++ b/hotline/file_transfer.go
@@ -257,7 +257,7 @@ func DownloadHandler(w io.Writer, fullPath string, fileTransfer *FileTransfer, f
dataOffset = int64(binary.BigEndian.Uint32(fileTransfer.FileResumeData.ForkInfoList[0].DataSize[:]))
}
- fw, err := NewFileWrapper(fs, fullPath, 0)
+ hlFile, err := NewFile(fs, fullPath, 0)
if err != nil {
return fmt.Errorf("reading file header: %v", err)
}
@@ -267,12 +267,12 @@ func DownloadHandler(w io.Writer, fullPath string, fileTransfer *FileTransfer, f
// If file transfer options are included, that means this is a "quick preview" request. In this case skip sending
// the flat file info and proceed directly to sending the file data.
if fileTransfer.Options == nil {
- if _, err = io.Copy(w, fw.Ffo); err != nil {
+ if _, err = io.Copy(w, hlFile.Ffo); err != nil {
return fmt.Errorf("send flat file object: %v", err)
}
}
- file, err := fw.dataForkReader()
+ file, err := hlFile.dataForkReader()
if err != nil {
return fmt.Errorf("open data fork reader: %v", err)
}
@@ -288,13 +288,13 @@ func DownloadHandler(w io.Writer, fullPath string, fileTransfer *FileTransfer, f
// If the client requested to resume transfer, do not send the resource fork header.
if fileTransfer.FileResumeData == nil {
- err = binary.Write(w, binary.BigEndian, fw.rsrcForkHeader())
+ err = binary.Write(w, binary.BigEndian, hlFile.rsrcForkHeader())
if err != nil {
return fmt.Errorf("send resource fork header: %v", err)
}
}
- rFile, _ := fw.rsrcForkFile()
+ rFile, _ := hlFile.rsrcForkFile()
//if err != nil {
// // return fmt.Errorf("open resource fork file: %v", err)
//}
@@ -332,7 +332,7 @@ func UploadHandler(rwc io.ReadWriter, fullPath string, fileTransfer *FileTransfe
return fmt.Errorf("open temp file for uploade: %w", err)
}
- f, err := NewFileWrapper(fileStore, fullPath, 0)
+ f, err := NewFile(fileStore, fullPath, 0)
if err != nil {
return err
}
@@ -424,7 +424,7 @@ func DownloadFolderHandler(rwc io.ReadWriter, fullPath string, fileTransfer *Fil
return nil
}
- hlFile, err := NewFileWrapper(fileStore, path, 0)
+ hlFile, err := NewFile(fileStore, path, 0)
if err != nil {
return err
}
@@ -645,7 +645,7 @@ func UploadFolderHandler(rwc io.ReadWriter, fullPath string, fileTransfer *FileT
filePath := path.Join(fullPath, fu.FormattedPath())
- hlFile, err := NewFileWrapper(fileStore, filePath, 0)
+ hlFile, err := NewFile(fileStore, filePath, 0)
if err != nil {
return err
}
diff --git a/hotline/file_wrapper.go b/hotline/file_wrapper.go
index 41b3338..b80bc4b 100644
--- a/hotline/file_wrapper.go
+++ b/hotline/file_wrapper.go
@@ -30,7 +30,7 @@ type File struct {
Ffo *flattenedFileObject
}
-func NewFileWrapper(fs FileStore, path string, dataOffset int64) (*File, error) {
+func NewFile(fs FileStore, path string, dataOffset int64) (*File, error) {
dir := filepath.Dir(path)
fName := filepath.Base(path)
f := File{
@@ -130,7 +130,11 @@ func (f *File) incFileWriter() (io.WriteCloser, error) {
}
func (f *File) dataForkReader() (io.Reader, error) {
- return f.fs.Open(f.dataPath)
+ if _, err := f.fs.Stat(f.dataPath); err == nil {
+ return f.fs.Open(f.dataPath)
+ }
+
+ return f.fs.Open(f.incompletePath)
}
func (f *File) rsrcForkFile() (*os.File, error) {
diff --git a/hotline/files.go b/hotline/files.go
index e9f7b4f..581b11c 100644
--- a/hotline/files.go
+++ b/hotline/files.go
@@ -112,9 +112,9 @@ func GetFileNameList(path string, ignoreList []string) (fields []Field, err erro
continue
}
- hlFile, err := NewFileWrapper(&OSFileStore{}, path+"/"+file.Name(), 0)
+ hlFile, err := NewFile(&OSFileStore{}, path+"/"+file.Name(), 0)
if err != nil {
- return nil, fmt.Errorf("NewFileWrapper: %w", err)
+ return nil, fmt.Errorf("NewFile: %w", err)
}
copy(fnwi.FileSize[:], hlFile.TotalSize())