// handler should have returned an error to the client indicating there was an existing file present.
_, err := os.Stat(fullPath)
if err == nil {
- return fmt.Errorf("existing file found: %s", fullPath)
+ // return fmt.Errorf("existing file found: %s", fullPath)
}
- if errors.Is(err, fs.ErrNotExist) {
+ // if errors.Is(err, fs.ErrNotExist) {
// If not found, open or create a new .incomplete file
file, err = os.OpenFile(fullPath+IncompleteFileSuffix, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0644)
if err != nil {
return err
}
- }
+ // }
defer file.Close()
updateTransactionPath(t, resolvedPath)
return HandleUploadFolder(cc, t)
}
+
+func HandleDeleteFileWithUserFolders(cc *hotline.ClientConn, t *hotline.Transaction) (res []hotline.Transaction) {
+ requestedPath, err := hotline.ReadPath(cc.FileRoot(), t.GetField(hotline.FieldFilePath).Data, nil)
+ if err != nil {
+ return res
+ }
+
+ resolvedPath, err := ResolveUserPath(cc, requestedPath[len(cc.FileRoot())+1:])
+ if err != nil {
+ return cc.NewErrReply(t, "Cannot upload to non-existent user folder.")
+ }
+
+ updateTransactionPath(t, resolvedPath)
+ return HandleUploadFolder(cc, t)
+}
srv.HandleFunc(hotline.TranChatSend, HandleChatSend)
srv.HandleFunc(hotline.TranDelNewsArt, HandleDelNewsArt)
srv.HandleFunc(hotline.TranDelNewsItem, HandleDelNewsItem)
- srv.HandleFunc(hotline.TranDeleteFile, HandleDeleteFile)
+ srv.HandleFunc(hotline.TranDeleteFile, HandleDeleteFileWithUserFolders)
srv.HandleFunc(hotline.TranDeleteUser, HandleDeleteUser)
srv.HandleFunc(hotline.TranDisconnectUser, HandleDisconnectUser)
srv.HandleFunc(hotline.TranDownloadFile, HandleDownloadFile)
fileName := t.GetField(hotline.FieldFileName).Data
filePath := t.GetField(hotline.FieldFilePath).Data
+ var fp hotline.FilePath
+ if filePath != nil {
+ if _, err := fp.Write(filePath); err != nil {
+ return res
+ }
+ }
+
fullFilePath, err := hotline.ReadPath(cc.FileRoot(), filePath, fileName)
if err != nil {
return res
switch mode := fi.Mode(); {
case mode.IsDir():
- if !cc.Authorize(hotline.AccessDeleteFolder) {
+ if !cc.Authorize(hotline.AccessDeleteFolder) && !fp.IsUserDir() {
return cc.NewErrReply(t, "You are not allowed to delete folders.")
}
case mode.IsRegular():
- if !cc.Authorize(hotline.AccessDeleteFile) {
+ if !cc.Authorize(hotline.AccessDeleteFile) && !fp.IsUserDir() {
return cc.NewErrReply(t, "You are not allowed to delete files.")
}
}
}
if _, err := cc.Server.FS.Stat(fullFilePath); err == nil {
- return cc.NewErrReply(t, fmt.Sprintf("Cannot accept upload because there is already a file named \"%v\". Try choosing a different Name.", string(fileName)))
+ if !fp.IsUserDir() {
+ 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, cc.FileRoot(), fileName, filePath, transferSize)