package protocol // Directory browsing for the chat folder picker. A client sends // Message{Type: ListDirectory, ID: , ListDirectory: &DirectoryListRequest{Path: ...}} // and the server echoes the ID on a DirectoryListing reply. Listing is // restricted to the server user's home directory subtree, returns names, kinds, // and file metadata (never file contents), and is bounded by // DirectoryListingMaxEntries. const ( ListDirectory = "list_directory" DirectoryListing = "directory_listing" ) // DirectoryListingMaxEntries caps the entries one directory_listing returns; // a larger directory sets Truncated. const DirectoryListingMaxEntries = 2000 // DirectoryListRequest is the list_directory body. Path is absolute or starts // with "~" ("~" or "~/sub"); an omitted or empty path lists the home directory. type DirectoryListRequest struct { Path string `json:"path,omitempty"` } // DirectoryListingResult is the directory_listing reply. Path is the absolute, // cleaned directory listed (expressed under Home), Parent is null at the home // root, and Entries are directories first, then files, each group sorted // case-insensitively. Entries include file size and modification time when // available; file contents are never returned, and files are not selectable. type DirectoryListingResult struct { Path string `json:"path"` Home string `json:"home"` Parent *string `json:"parent"` Entries []DirectoryEntry `json:"entries"` Truncated bool `json:"truncated,omitempty"` } // DirectoryEntry is one listed name. IsDir is true only for a directory (or a // symlink to one) that stays inside the home subtree; IsGitRepo marks a // directory containing .git; Hidden marks a dot-name. Size and Modified are // populated for files; directories have no file metadata. type DirectoryEntry struct { Name string `json:"name"` Path string `json:"path"` IsDir bool `json:"is_dir"` IsGitRepo bool `json:"is_git_repo"` Hidden bool `json:"hidden"` 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"` }