Files
w3cjandClaude Opus 5.5 cb7177b32c feat(ui): waits for another devvm's lock show a status line; a project folder devvm can't read says so
Lock waits:
- platform.LockFile and LockFileShared take a platform.Waiting, called
  once they find the lock held, never when it's free, whose end they call
  once the wait ends; LockFileWaiting, LockFileSharedWaiting and their
  delays (ShareNote, OCINote, WaitNote, groupsNote, makingNote) go.
- msg.Waiting makes one from a Reporter's Status and a label;
  msg.WithStatus and msg.StatusOf carry the run's Status in its context
  for the two packages that take no Reporter, internal/state and
  internal/trust, which cli's execute sets; forbidigo keeps StatusOf to
  them, and AGENTS.md says so.
- Every lock that waits shows its own label: vm_state_waiting (a VM's
  state, its deletion), claims_waiting, layout_waiting, git_lock_waiting,
  ca_waiting, packages_waiting, rebuilds_waiting, ubuntu_pin_waiting,
  custom_secrets_waiting, forwarder_waiting, agent_store_waiting, and the
  waits that printed a line after a delay, which now show theirs as a
  status line: share_waiting, oci_waiting, image_build_waiting,
  group_waiting, making_waiting.
- An agent's login file's lock (agentlogin's lockLogin, a folder's flock
  that a VM's proxy holds while it refreshes the login) tries first
  without waiting and shows agentlogin.File's Waiting
  (agent_login_waiting) while it waits; secrets fills it from its
  Reporter, for SaveLogins, Claude Code's logins folder and every File.
- The structure test's status-lines rule counts a LockFile or
  LockFileShared whose waiting is nil as slow work; the build port's
  record, a file just made that never waits, is listed in statusSites.
- Without a terminal, or with -v, a status line draws nothing, so the
  waits that printed an info line after a delay no longer print it there;
  the CHANGELOG and the troubleshooting page say so. from.txtar's check
  that a free conversion lock printed no wait goes, as TestLockOCI checks
  it.

The layout's migration runs under a status line (layout_migrating),
only when there are migrations to run.

Backend calls outside a launch: TestCommandStatusLines runs devvm ls,
ports, size, network, tools, git-protect, history export, stop and rm on
a running and a stopped VM and fails on a backend call with no status
line showing, with a control that each makes one.

A project folder devvm can't open and read (vm_folder_unreadable) was
taken for another folder's VM (vm_other_folder, which offers rm and
adopt, and adopt went on); the finder now keeps why (target.unread), and
every command on the folder's VM, from the folder or a subfolder of it,
names the folder and why; devvm rm VM run elsewhere goes by the VM's
name as before.

platform.UniqueFolderID had no caller but its test: FolderStat.Unique,
from the open folder, replaced it; it goes, and its test checks
StatFolder's Unique instead.

Tests: TestLockFileWaiting (rewritten: called only when held, its end
once got or given up, shared too), TestVMLockWaits, TestCheckLayoutWaits,
TestCheckLayout (migrations under layout_migrating, nothing shown
otherwise), TestLockGroups, TestLockShare, TestMaking, TestLockOCI and
the build lock's test (status lines, not info lines), TestLockLogin,
TestInitCACancelled (ca_waiting), the status-lines rule's lock cases,
TestCommandStatusLines, TestUnreadableFolder (a subfolder of it too),
TestStatFolderUnique.

Docs: Contributing's CLI page (Status lines) and structure page, the cli
and codebase-standards skills (the guards), AGENTS.md's Go conventions,
internals/images.md and design.md (the waits), using/troubleshooting.md,
using/vms.md (a folder devvm can't read); CHANGELOG.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-19 15:10:22 -07:00

117 lines
4.3 KiB
Go

// Package platform holds the code that differs between host systems,
// behind build tags: *_unix.go for macOS and Linux, *_darwin.go and
// *_linux.go for one of them, and *_other.go for the rest, which get an
// error until they're supported.
package platform
import (
"errors"
"os"
"strings"
)
// ErrNoSecret is KeychainGet's error for an item that isn't there.
var ErrNoSecret = errors.New("no such secret")
// folderDevice returns the device in a FolderID, "" when id has none. Only
// platform reads it: a boot can number an unchanged folder's device anew,
// so what compares one is SameFolder's and OnRecordedDisk's.
func folderDevice(id string) string {
dev, _, ok := strings.Cut(id, ":")
if !ok {
return ""
}
return dev
}
// SameFolder reports whether id, the FolderID of the folder at dir now,
// names the folder recorded as was when it was at wasDir: the same ID, or
// at the same path the same inode and birth time on another device. It's
// the one place two FolderIDs are compared. macOS numbers its disks'
// devices in the order they appear at boot, so after a restart an
// unchanged folder can have another device number. Only a folder whose ID
// is its alone (FolderStat.Unique), at a path with no link on it, matches on
// another device: what a VM can put in a folder's place, a link or a new
// folder, can't take an inode and a birth time, and a copy that keeps
// both, such as a snapshot or a cloned disk, is at another path, unless
// you mount it at the folder's own. A folder at another path (moved)
// matches only its ID as recorded. On another device, id must also be
// the ID of the folder opened at dir with no link followed (OpenNoLinks),
// read from that open folder, so a link put at the path, or above it,
// while the caller read id can't pass a copy's ID off as the folder's.
func SameFolder(wasDir, was, dir, id string) bool {
if was == "" || id == "" {
return false
}
if was == id {
return true
}
if !renumberedID(wasDir, was, dir, id) {
return false
}
s, err := StatFolder(dir)
return err == nil && s.Unique && s.ID == id
}
// SameOpenFolder is SameFolder for the folder s describes, as StatFolder
// read it at dir from the folder opened with no link on its path, so it
// opens nothing again: a caller that has s compares with it, once.
func SameOpenFolder(wasDir, was, dir string, s FolderStat) bool {
if was == "" || s.ID == "" {
return false
}
return was == s.ID || s.Unique && renumberedID(wasDir, was, dir, s.ID)
}
// RecordedAs reports whether s's ID is was, the ID recorded, byte for
// byte: the folder SameOpenFolder took for the recorded one, on the
// device it was recorded on, not one numbered anew since.
func RecordedAs(was string, s FolderStat) bool { return was != "" && was == s.ID }
// renumberedID reports whether id could be the folder recorded as was on
// another device, by the IDs alone: at the same path, with the same inode
// and birth time.
func renumberedID(wasDir, was, dir, id string) bool {
wasDev, wasRest, _ := strings.Cut(was, ":")
dev, rest, _ := strings.Cut(id, ":")
return wasDir == dir && digits(wasDev) && digits(dev) && wasRest == rest && strings.Count(id, ":") == 2
}
// Renumbered reports whether id names the folder recorded as was
// (SameFolder) on a device numbered anew since, so the record needs the
// folder's ID as it is now.
func Renumbered(wasDir, was, dir, id string) bool {
return was != id && SameFolder(wasDir, was, dir, id)
}
// VolPath returns the path of the folder a FolderID names by its device
// and inode, /.vol/<dev>/<ino>, which macOS's volfs opens whatever path
// the folder has now; "" when id has neither. Only macOS has /.vol.
func VolPath(id string) string {
dev, rest, ok := strings.Cut(id, ":")
ino, _, _ := strings.Cut(rest, ":")
if !ok || !digits(dev) || !digits(ino) {
return ""
}
return "/.vol/" + dev + "/" + ino
}
// digits reports whether s is a decimal number, without a sign.
func digits(s string) bool {
return s != "" && strings.Trim(s, "0123456789") == ""
}
// DeviceOf returns the device of what's at path, following a symlink, as
// FolderID writes it.
func DeviceOf(path string) (string, error) {
fi, err := os.Stat(path)
if err != nil {
return "", err
}
dev := folderDevice(DevIno(fi))
if dev == "" {
return "", errors.ErrUnsupported
}
return dev, nil
}