## Summary
Remove verbose syntax pattern by adopting `trim_{prefix,suffix}`, which
sometimes saves clones or other work.
`value.strip_suffix(pattern).unwrap(value)` ->
`value.trim_suffix(pattern)`
`value.strip_prefix(pattern).unwrap(value)` ->
`value.trim_prefix(pattern)`
I also found a common pattern of `.starts_with` before `strip_prefix`,
which the latter already checks for implicitly.
## Testing
Tests pass, no behavior changes.
## Self-review
- [x] I've reviewed my diff for quality, security, reliability, and
performance.
- [x] UI changes follow the
[checklist](https://zed.dev/docs/development/ui-checklist).
- [x] Tests cover the new or changed behavior.
Release Notes:
- N/A
- [GPUI] N/A
Many tools call `mkdir -p`, which calls the `mkdir` syscall. Previously,
we would require write access to `mkdir` even in the case where a
directory already existed. This meant that `mkdir -p` would ask for
permission even when it wouldn't modify the FS state.
While this technically does leak information about whether directories
exist, this was already an intentional design decision (i.e. we do not
trap `stat` for performance reasons).
Release Notes:
- N/A
Note: this PR does not change any behaviour of zed itself. The old
sandbox implementation is still in use. The code in this PR is not
considered secure. I'll need more time to torture it before I'm
confident :)
The old sandbox used `bwrap` to set up mounts to restrict FS access, and
an in-sandbox network proxy to forward HTTP requests. It has significant
limitations however:
- it cannot restrict FS access to paths that don't exist at sandbox
creation time. This means that files that become available while a
command is running are unprotected
- it cannot restrict FS access based on a glob - each individual mount
must be specified explicitly
- it cannot restrict network access that is not HTTP (i.e. SSH traffic).
- it cannot change permissions while a sandboxed command is running -
the grants given at the start of the execution are fixed. Agents can
request to re-run the app with broader permissions, which is fine, but
not great UX
- it cannot detect whether a command failed because it hit the sandbox
boundary or not. Again, agents can guess, but we'd like something more
robust
- it cannot dynamically prompt the user to escalate privileges
The new sandbox has a different different design which solves these
problems:
- all restrictions go through seccomp user notifications
- this allows us to register a supervisor process with the kernel to
validate the syscalls of another program. This supervisor can run
arbitrary userspace code to inspect syscalls before
allowing/denying/modifying them
- we create and upload a policy object to this supervisor which checks
syscalls against this policy
- if the policy says that the operation requires "ask"-ing, the
supervisor will ask zed to show a prompt to the user and report a
decision
This design is a lot more unified, and since it is much more flexible,
is also potentially suitable for sandboxing more parts of zed (user
terminals, LSP servers, etc.).
Release Notes:
- N/A