]> git.r.bdr.sh - rbdr/mobius/blobdiff - internal/mobius/transaction_handlers.go
Allow to delete home files / replace files
[rbdr/mobius] / internal / mobius / transaction_handlers.go
index e74056f8dc4da49eda764c33b1ff9356692b005e..32535b296349d9dab4eac155a56e9200cb6058b0 100644 (file)
@@ -28,7 +28,7 @@ func RegisterHandlers(srv *hotline.Server) {
        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)
@@ -346,6 +346,13 @@ func HandleDeleteFile(cc *hotline.ClientConn, t *hotline.Transaction) (res []hot
        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
@@ -363,11 +370,11 @@ func HandleDeleteFile(cc *hotline.ClientConn, t *hotline.Transaction) (res []hot
 
        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.")
                }
        }
@@ -1438,7 +1445,9 @@ func HandleUploadFile(cc *hotline.ClientConn, t *hotline.Transaction) (res []hot
        }
 
        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)