"Name", string(fileTransfer.ClientConn.UserName),
)
- fullPath, err := ReadPath(s.Config.FileRoot, fileTransfer.FilePath, fileTransfer.FileName)
+ fullPath, err := ReadPath(fileTransfer.FileRoot, fileTransfer.FilePath, fileTransfer.FileName)
if err != nil {
return err
}
switch fileTransfer.Type {
case BannerDownload:
if _, err := io.Copy(rwc, bytes.NewBuffer(s.Banner)); err != nil {
- return fmt.Errorf("error sending Banner: %w", err)
+ return fmt.Errorf("banner download: %w", err)
}
case FileDownload:
s.Stats.Increment(StatDownloadCounter, StatDownloadsInProgress)
err = UploadHandler(rwc, fullPath, fileTransfer, s.FS, rLogger, s.Config.PreserveResourceForks)
if err != nil {
- return fmt.Errorf("file upload error: %w", err)
+ return fmt.Errorf("file upload: %w", err)
}
case FolderDownload:
err = DownloadFolderHandler(rwc, fullPath, fileTransfer, s.FS, rLogger, s.Config.PreserveResourceForks)
if err != nil {
- return fmt.Errorf("file upload error: %w", err)
+ return fmt.Errorf("folder download: %w", err)
}
case FolderUpload:
err = UploadFolderHandler(rwc, fullPath, fileTransfer, s.FS, rLogger, s.Config.PreserveResourceForks)
if err != nil {
- return fmt.Errorf("file upload error: %w", err)
+ return fmt.Errorf("folder upload: %w", err)
}
}
return nil
fileName := t.GetField(hotline.FieldFileName).Data
filePath := t.GetField(hotline.FieldFilePath).Data
- fullFilePath, err := hotline.ReadPath(cc.Server.Config.FileRoot, filePath, fileName)
+ fullFilePath, err := hotline.ReadPath(cc.FileRoot(), filePath, fileName)
if err != nil {
return res
}
fileName := t.GetField(hotline.FieldFileName).Data
filePath := t.GetField(hotline.FieldFilePath).Data
- fullFilePath, err := hotline.ReadPath(cc.Server.Config.FileRoot, filePath, fileName)
+ fullFilePath, err := hotline.ReadPath(cc.FileRoot(), filePath, fileName)
if err != nil {
return res
}
}
}
- fullNewFilePath, err := hotline.ReadPath(cc.Server.Config.FileRoot, filePath, t.GetField(hotline.FieldFileNewName).Data)
+ fullNewFilePath, err := hotline.ReadPath(cc.FileRoot(), filePath, t.GetField(hotline.FieldFileNewName).Data)
if err != nil {
return nil
}
if !cc.Authorize(hotline.AccessRenameFile) {
return cc.NewErrReply(t, "You are not allowed to rename files.")
}
- fileDir, err := hotline.ReadPath(cc.Server.Config.FileRoot, filePath, []byte{})
+ fileDir, err := hotline.ReadPath(cc.FileRoot(), filePath, []byte{})
if err != nil {
return nil
}
fileName := t.GetField(hotline.FieldFileName).Data
filePath := t.GetField(hotline.FieldFilePath).Data
- fullFilePath, err := hotline.ReadPath(cc.Server.Config.FileRoot, filePath, fileName)
+ fullFilePath, err := hotline.ReadPath(cc.FileRoot(), filePath, fileName)
if err != nil {
return res
}
func HandleMoveFile(cc *hotline.ClientConn, t *hotline.Transaction) (res []hotline.Transaction) {
fileName := string(t.GetField(hotline.FieldFileName).Data)
- filePath, err := hotline.ReadPath(cc.Server.Config.FileRoot, t.GetField(hotline.FieldFilePath).Data, t.GetField(hotline.FieldFileName).Data)
+ filePath, err := hotline.ReadPath(cc.FileRoot(), t.GetField(hotline.FieldFilePath).Data, t.GetField(hotline.FieldFileName).Data)
if err != nil {
return res
}
- fileNewPath, err := hotline.ReadPath(cc.Server.Config.FileRoot, t.GetField(hotline.FieldFileNewPath).Data, nil)
+ fileNewPath, err := hotline.ReadPath(cc.FileRoot(), t.GetField(hotline.FieldFileNewPath).Data, nil)
if err != nil {
return res
}
subPath = filepath.Join("/", subPath, string(pathItem.Name))
}
}
- newFolderPath := path.Join(cc.Server.Config.FileRoot, subPath, folderName)
+ newFolderPath := path.Join(cc.FileRoot(), subPath, folderName)
newFolderPath, err := txtDecoder.String(newFolderPath)
if err != nil {
return res
dataOffset = int64(binary.BigEndian.Uint32(frd.ForkInfoList[0].DataSize[:]))
}
- fullFilePath, err := hotline.ReadPath(cc.Server.Config.FileRoot, filePath, fileName)
+ fullFilePath, err := hotline.ReadPath(cc.FileRoot(), filePath, fileName)
if err != nil {
return res
}
xferSize := hlFile.Ffo.TransferSize(0)
- ft := cc.NewFileTransfer(hotline.FileDownload, fileName, filePath, xferSize)
+ ft := cc.NewFileTransfer(
+ hotline.FileDownload,
+ cc.FileRoot(),
+ fileName,
+ filePath,
+ xferSize,
+ )
- // TODO: refactor to remove this
if resumeData != nil {
var frd hotline.FileResumeData
if err := frd.UnmarshalBinary(t.GetField(hotline.FieldFileResumeData).Data); err != nil {
return cc.NewErrReply(t, "You are not allowed to download folders.")
}
- fullFilePath, err := hotline.ReadPath(cc.Server.Config.FileRoot, t.GetField(hotline.FieldFilePath).Data, t.GetField(hotline.FieldFileName).Data)
+ fullFilePath, err := hotline.ReadPath(cc.FileRoot(), t.GetField(hotline.FieldFilePath).Data, t.GetField(hotline.FieldFileName).Data)
if err != nil {
- return res
+ return nil
}
transferSize, err := hotline.CalcTotalSize(fullFilePath)
if err != nil {
- return res
+ return nil
}
itemCount, err := hotline.CalcItemCount(fullFilePath)
if err != nil {
- return res
+ return nil
}
- fileTransfer := cc.NewFileTransfer(hotline.FolderDownload, t.GetField(hotline.FieldFileName).Data, t.GetField(hotline.FieldFilePath).Data, transferSize)
+ fileTransfer := cc.NewFileTransfer(hotline.FolderDownload, cc.FileRoot(), t.GetField(hotline.FieldFileName).Data, t.GetField(hotline.FieldFilePath).Data, transferSize)
var fp hotline.FilePath
_, err = fp.Write(t.GetField(hotline.FieldFilePath).Data)
if err != nil {
- return res
+ return nil
}
res = append(res, cc.NewReply(t,
}
fileTransfer := cc.NewFileTransfer(hotline.FolderUpload,
+ cc.FileRoot(),
t.GetField(hotline.FieldFileName).Data,
t.GetField(hotline.FieldFilePath).Data,
t.GetField(hotline.FieldTransferSize).Data,
return cc.NewErrReply(t, fmt.Sprintf("Cannot accept upload of the file \"%v\" because you are only allowed to upload to the \"Uploads\" folder.", string(fileName)))
}
}
- fullFilePath, err := hotline.ReadPath(cc.Server.Config.FileRoot, filePath, fileName)
+ fullFilePath, err := hotline.ReadPath(cc.FileRoot(), filePath, fileName)
if err != nil {
return res
}
return cc.NewErrReply(t, fmt.Sprintf("Cannot accept upload because there is already a file named \"%v\". Try choosing a different Name.", string(fileName)))
}
- ft := cc.NewFileTransfer(hotline.FileUpload, fileName, filePath, transferSize)
+ ft := cc.NewFileTransfer(hotline.FileUpload, cc.FileRoot(), fileName, filePath, transferSize)
replyT := cc.NewReply(t, hotline.NewField(hotline.FieldRefNum, ft.RefNum[:]))
func HandleGetFileNameList(cc *hotline.ClientConn, t *hotline.Transaction) (res []hotline.Transaction) {
fullPath, err := hotline.ReadPath(
- cc.Server.Config.FileRoot,
+ cc.FileRoot(),
t.GetField(hotline.FieldFilePath).Data,
nil,
)
filePath := t.GetField(hotline.FieldFilePath).Data
fileNewPath := t.GetField(hotline.FieldFileNewPath).Data
- fullFilePath, err := hotline.ReadPath(cc.Server.Config.FileRoot, filePath, fileName)
+ fullFilePath, err := hotline.ReadPath(cc.FileRoot(), filePath, fileName)
if err != nil {
return res
}
- fullNewFilePath, err := hotline.ReadPath(cc.Server.Config.FileRoot, fileNewPath, fileName)
+ fullNewFilePath, err := hotline.ReadPath(cc.FileRoot(), fileNewPath, fileName)
if err != nil {
return res
}
// 107 FieldRefNum Used later for transfer
// 108 FieldTransferSize Size of data to be downloaded
func HandleDownloadBanner(cc *hotline.ClientConn, t *hotline.Transaction) (res []hotline.Transaction) {
- ft := cc.NewFileTransfer(hotline.BannerDownload, []byte{}, []byte{}, make([]byte, 4))
+ ft := cc.NewFileTransfer(hotline.BannerDownload, "", []byte{}, []byte{}, make([]byte, 4))
binary.BigEndian.PutUint32(ft.TransferSize, uint32(len(cc.Server.Banner)))
return append(res, cc.NewReply(t,