Add rename_path, move_path and delete_path for home files

The chat Files panel needs to rename, move and delete entries. Three
websocket requests, dispatched beside list_directory, operate on one
entry inside the operator's home and reply with path_mutated {path} or
an error frame (does not exist, already exists, is not empty, outside
the home directory, cannot be moved into itself).

The entry's parent folder and the move destination are resolved through
symlinks and must stay inside home; the entry's own symlink is never
followed, so a link is renamed, moved or removed as a link. The home
directory itself, anything outside it and pseudo filesystems are
refused. A folder is deleted only when empty unless recursive is set;
os.RemoveAll unlinks symlinks rather than descending into them.
This commit is contained in:
2026-11-09 01:32:31 +00:00
parent a02b271509
commit c61490aeb0
6 changed files with 555 additions and 0 deletions
+45
View File
@@ -47,3 +47,48 @@ type DirectoryEntry struct {
Size int64 `json:"size,omitempty"`
Modified string `json:"modified,omitempty"`
}
// Home file mutations for the chat Files panel. Each request names one entry
// inside the server user's home by absolute or "~/" path and is answered with a
// PathMutated reply carrying the resulting path, or an Error reply whose text
// says why (does not exist, already exists, is not empty, outside the home
// directory). The home directory itself and anything outside it are never
// touched; symlinks are renamed, moved or removed as links, never followed.
const (
RenamePath = "rename_path"
MovePath = "move_path"
DeletePath = "delete_path"
PathMutated = "path_mutated"
)
// FolderNotEmpty is the phrase a delete_path refusal carries when the folder
// has contents and Recursive was false; a client then offers a recursive delete.
const FolderNotEmpty = "is not empty"
// RenamePathRequest is the rename_path body: the entry's path and its new
// plain name within the same folder (no separators, not "." or "..").
type RenamePathRequest struct {
Path string `json:"path"`
Name string `json:"name"`
}
// MovePathRequest is the move_path body: the entry's path and the folder it
// moves into, keeping its name. An existing name in Into is refused, as is
// moving a folder into itself or one of its descendants.
type MovePathRequest struct {
Path string `json:"path"`
Into string `json:"into"`
}
// DeletePathRequest is the delete_path body. A file or symlink is always
// removed; a folder only when empty unless Recursive is true.
type DeletePathRequest struct {
Path string `json:"path"`
Recursive bool `json:"recursive,omitempty"`
}
// PathMutatedResult is the path_mutated reply: the renamed, moved or deleted
// entry's resulting path, expressed under the home directory.
type PathMutatedResult struct {
Path string `json:"path"`
}
+6
View File
@@ -266,6 +266,12 @@ type Message struct {
// the home-restricted folder picker listing (see directories.go).
ListDirectory *DirectoryListRequest `json:"list_directory,omitempty"`
DirectoryListing *DirectoryListingResult `json:"directory_listing,omitempty"`
// RenamePath, MovePath and DeletePath are the Files panel's home file
// mutations and PathMutated their shared reply (see directories.go).
RenamePath *RenamePathRequest `json:"rename_path,omitempty"`
MovePath *MovePathRequest `json:"move_path,omitempty"`
DeletePath *DeletePathRequest `json:"delete_path,omitempty"`
PathMutated *PathMutatedResult `json:"path_mutated,omitempty"`
// ChatAttachmentImageRequest is the chat_attachment_image body and
// ChatAttachmentImage its reply.
ChatAttachmentImageRequest *ChatAttachmentImageRequest `json:"chat_attachment_image_request,omitempty"`