Documentation
¶
Overview ¶
Package drop turns a file dropped on the terminal into a path the session can paste.
The window hands over the dropped files' own paths, and an unconfined session takes them as they are. A confined session's home is an empty private one (internal/sandbox), so a file outside its checkout is a path only lich can open: for those the window uploads the bytes (Upload), lich keeps a copy under the config dir, and the copy's path is pasted. Reading it works; editing it edits the copy, which is why the copy's path never lands at a prompt without the line that says so (copyNotice). The sandbox binds the copies directory and nothing else of the home.
The copies are kept one directory per session, named by its files key (store.SessionFilesKey) so a resume, which gives the row a fresh id, finds the copies it already pasted, and that is the unit they are deleted in: a confined session sees its own directory mounted and not the one beside it, and every copy a session was dropped goes when its row does (Purge): a copy lives exactly as long as the session it was dropped into, and the clock only ever collects the orphans (Prune).
The footer's attach button lands here too (Attach): a file chosen from the native picker already has its path, but a confined session cannot open one outside its checkout either, and the same copy is the answer.
Index ¶
- func Dir(configDir string) string
- type Attachment
- type Service
- func (s *Service) Attach(_ context.Context, opts api.AttachDropOptions) (Attachment, error)
- func (s *Service) Prune()
- func (s *Service) PruneStale()
- func (s *Service) Purge(filesKey string)
- func (s *Service) Save(sessionID, name string, body io.Reader) (string, error)
- func (s *Service) SetFilesKey(key func(sessionID string) string)
- func (s *Service) SetPicker(pick func(title string) (string, error))
- func (s *Service) SetPromptLanguage(lang func() prompt.Lang)
- func (s *Service) Upload(w http.ResponseWriter, r *http.Request)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Attachment ¶
type Attachment = api.DropAttachment
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
func New ¶
New keeps uploaded copies under Dir(configDir), and creates that directory now rather than on the first drop. A confined session binds its own copies directory when its PTY spawns (internal/terminal/sandbox.go), and a bind whose source is not there yet is skipped: the first file dropped into a session that opened before the directory existed would land where that session cannot read it.
live answers whether a row, open or parked, still holds a files key (store.FilesKeyInUse): it is what keeps the age rule off the copies of a session that is still around. A nil one makes every copy an orphan, which is what the tests want and never what a running lich does.
func (*Service) Attach ¶
func (s *Service) Attach(_ context.Context, opts api.AttachDropOptions) (Attachment, error)
Attach opens the file chooser and answers with a path the session can actually open: the file's own where the session reaches it, a copy's inside the session's dropped-files directory otherwise. It is the footer's attach button, and the counterpart of a drop — the same problem arrives through a dialog instead of a drag.
The picker runs here rather than in the caller, and that is the security property of this method: every session carries LICH_TOKEN (see internal/terminal), so a confined agent can call any RPC on the loopback listener. A method that copied a *path it was handed* would let that agent name ~/.ssh/id_rsa and read the copy from inside the sandbox — the sandbox undone by its own harness. Here the path can only come from a dialog a human answers on screen.
opts.Root is the session's checkout, the one tree a confined session sees; a file under it keeps its own path. Anything else is copied, including files under directories the sandbox happens to bind (a toolchain, ~/.config): copying one of those costs a few bytes, and deciding it does not need copying means reproducing the mount list here, where it would go stale in silence.
func (*Service) Prune ¶
func (s *Service) Prune()
Prune deletes the copies of sessions that are gone and older than keepDropped. Called after each new copy, the only thing that grows the directory, so a lich left running for weeks still clears what earlier drops left behind.
Age is the backstop, not the rule: a session that ends takes its copies with it (Purge), and what this catches is the session lich never saw end — a crash, a kill, a machine that went down.
A failure here is never the caller's problem — the copy it just wrote is good, and the stale ones get another chance on the next drop.
func (*Service) PruneStale ¶
func (s *Service) PruneStale()
PruneStale is Prune plus the session directories left with nothing in them. Startup only, and that is the whole reason it is a second method: a confined session binds its own copies directory when it spawns, and removing that directory under a live mount leaves every later copy of that session invisible inside it — the mount would still point at the deleted one. At startup no session has spawned yet, so there is no mount to strand.
func (*Service) Purge ¶
Purge deletes every copy dropped into one session, by its files key. It is what makes a copy die with the session it was dropped into rather than with the clock: the paths pasted from it only ever meant anything inside that conversation, and the session's own row is gone by the time this runs (store.SetSessionGone).
Best effort, like Prune: a failure leaves copies that the age rule still clears.
func (*Service) Save ¶
Save writes one dropped file under the session's own copies directory, without ever overwriting an earlier drop — its path may still be sitting in a prompt. sessionID must already be one path element (element).
func (*Service) SetFilesKey ¶ added in v0.88.0
SetFilesKey wires how a session's id becomes the key its copies directory is named by (store.SessionFilesKey); without it the id is the key. Startup wiring, called before anything serves.
func (*Service) SetPicker ¶
SetPicker wires the host's file picker (internal/project), which is what the footer's attach button reaches through Attach. Startup wiring, called before anything serves.
func (*Service) SetPromptLanguage ¶
SetPromptLanguage wires where the copy notice reads its language. It is read again for every notice, so a change in Settings reaches the next drop; without it the notice is English, the default. Startup wiring, called before anything serves.