]> git.r.bdr.sh - rbdr/mobius/commitdiff
Allow to delete home files / replace files
authorRuben Beltran del Rio <redacted>
Tue, 4 Feb 2025 09:59:32 +0000 (10:59 +0100)
committerRuben Beltran del Rio <redacted>
Tue, 4 Feb 2025 09:59:32 +0000 (10:59 +0100)
hotline/file_transfer.go
internal/mobius/friendship_quest_file_extensions.go
internal/mobius/transaction_handlers.go

index 626cfff48823030be76618e1cdcfdc22a556f919..4e71bd66a0c511181003b5ce76d00f6c1b555653 100644 (file)
@@ -316,15 +316,15 @@ func UploadHandler(rwc io.ReadWriter, fullPath string, fileTransfer *FileTransfe
        // 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()
 
index fb23b79a3f1e6889ca89f2c4105bf50d66f88a31..1ef8ad6a4d26a55bf42f802a6a5e40ba192c060f 100644 (file)
@@ -156,3 +156,18 @@ func HandleUploadFolderWithUserFolders(cc *hotline.ClientConn, t *hotline.Transa
        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)
+}
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)