Documentation
¶
Overview ¶
Package mounts is what a project's VM is given of this machine: the project, and the entries of ~/.agent-vm/volumes, each checked first.
Index ¶
- Constants
- Variables
- func CacheOn() bool
- func CredentialLocation(dir string, refs []Ref) (string, bool)
- func GitDirShare(dir string) (string, bool)
- func Matches(filter, dir, home string, warn io.Writer) bool
- func ProjectMountpoint(dir, rel, src string, warn io.Writer) (string, bool)
- func RWDirs(entries []Entry) []string
- func Stage(src, dst string, warn io.Writer) bool
- func UnderName(rel string, names []string) bool
- func Unmountable(dir string) (string, bool)
- func UnsafeLocation(dir string, refs []Ref) (string, bool)
- func UnsafeProject(dir string, refs []Ref) (string, bool)
- func Unwritable(s string) (string, bool)
- type Entry
- type FileMount
- type Ref
- type Shares
Constants ¶
const SelfRef = "agent-vm itself"
SelfRef is the What of the Ref to agent-vm's own folder.
Variables ¶
var BaseNames = []string{".git", ".hg", ".sl", ".jj"}
BaseNames are always read-only in every share. .hg: Mercurial runs the hooks of .hg/hgrc in a repository the user owns, which files written through a share are. .sl (Sapling) and .jj (Jujutsu) keep a repository's config, which names commands to run, in the same way. .lfsconfig is not one: git-lfs reads only a few URL and filter keys from it, no command.
Functions ¶
func CacheOn ¶
func CacheOn() bool
CacheOn is sshfs's cache mode asked from the shell: on with AGENT_VM_SSHFS_CACHE=1, never from the project. With it, a file the host adds, deletes or extends shows as it was for up to 20 seconds, and an agent writing back what it read would undo the host's change; it is off on the writable shares otherwise.
func CredentialLocation ¶
CredentialLocation says why dir must not be shared with a VM: it is, contains or is inside a folder of credentials or applications' data under the home folder (see credentialRel), found in refs. Those folders resolved through their links count too, as dir does.
func GitDirShare ¶
GitDirShare says why dir must not be a writable share: it is, or is inside, a repository's own folder: a .git or .hg (by name, as the SFTP server matches them), or a bare repository (HEAD, objects/ and refs/, as git finds one). The read-only names apply below a share's root, so such a share would be writable whole, hooks and config included.
func Matches ¶
Matches reports whether the project dir matches filter, the 4th field of a volumes entry: a path, ~ expanded, where * matches anything, / included (and ? and [...] as the shell has them). A filter that is not absolute matches nothing, with a warning; ~user is not expanded.
func ProjectMountpoint ¶
ProjectMountpoint makes, on the host, the mount point of a relative destination rel, inside the project dir: a folder, or an empty file for a file source src. virtiofs and 9p make mount points before the project is mounted, and --readonly refuses the guest's write. No component may be ".." or a symlink: the agent can write the project. Made without following links (env.MkdirIn), since the VM could swap one in after the check.
func RWDirs ¶
RWDirs are the folders of entries the VM can write besides the project: shares that are rw and directories.
func Stage ¶
Stage puts src at dst by a hardlink, which keeps it in step with the host (same inode) without sharing its folder; by a copy when they are on two file systems, with a warning: then changes reach the VM on its next start.
func UnderName ¶
UnderName reports whether the relative path rel goes through one of names (BaseNames when nil), matched as the SFTP server does: per component, whatever the case.
func Unmountable ¶
Unmountable says why Lima cannot be given dir as a share: with whitespace the mount fails silently, leaving a bare, root-owned mount point; a quote, a backslash or a control character are refused as 0.2 refused them; and what Lima would read as another path (Unwritable).
func UnsafeLocation ¶
UnsafeLocation says why dir must not be shared with a VM, writable or not, when it is or contains the home folder, or is, contains or is inside one of the other refs. A project inside the home folder is what is expected. Compared as physical paths, whatever the case where the file system ignores it.
func UnsafeProject ¶
UnsafeProject says why the project dir must not be shared: see UnsafeLocation, CredentialLocation and GitDirShare.
func Unwritable ¶
Unwritable says why s cannot go into Lima's config as written: Lima expands Go templates in share paths ({{.Home}} is the home folder), and a byte that is not UTF-8 becomes U+FFFD on the way.
Types ¶
type Entry ¶
type Entry struct {
Src string // ~ expanded, existing
Dst string // absolute and normalized, relative as written, or "" for Src's own path
Mode string // "ro" or "rw"
Line string // source:destination:mode, for messages
}
Entry is a usable line of ~/.agent-vm/volumes.
type FileMount ¶
type FileMount struct {
Src, Staging, BindSrc, BindDst string
}
FileMount is a single file of ~/.agent-vm/volumes: hardlinked into a staging folder of its own, which is shared, then bound in place in the VM (BindSrc onto BindDst), so the VM never sees the file's folder.
type Ref ¶
Ref is a location no share may reach.
func Refs ¶
Refs are the locations no share may reach: the home folder (dotfiles, SSH keys, every other project), agent-vm itself (the host runs its files), agent-vm's state (every VM's env) and Lima's homes, agent-vm's and the user's own (the VMs' SSH key and disks, its _config adding mounts to every VM).