Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Find a file
tims f64bfe8c1d
Some checks are pending
CI / check_docs_only (push) Waiting to run
CI / Check Postgres and Protobuf migrations, mergability (push) Waiting to run
CI / Check formatting and spelling (push) Waiting to run
CI / (macOS) Run Clippy and tests (push) Blocked by required conditions
CI / (Linux) Run Clippy and tests (push) Blocked by required conditions
CI / (Linux) Build Remote Server (push) Blocked by required conditions
CI / (Windows) Run Clippy and tests (push) Blocked by required conditions
CI / Create a macOS bundle (push) Blocked by required conditions
CI / Create a Linux bundle (push) Blocked by required conditions
CI / Create arm64 Linux bundle (push) Blocked by required conditions
CI / Auto release preview (push) Blocked by required conditions
Deploy Docs / Deploy Docs (push) Waiting to run
Docs / Check formatting (push) Waiting to run
Script / ShellCheck Scripts (push) Waiting to run
linux: Fix saving file with root ownership (#22045)
Closes #13585

Currently, saving files with `root` ownership or `root` as the group
throws a `Permission denied (os error 13). Please try again.` error.
This PR fixes the issue on Linux by prompting the user for a password
and saving the file with elevated privileges.

It uses `pkexec` (Polkit), which is by default available on GNOME, KDE,
and most Linux systems. I haven't implemented this for macOS as I don't
have a device to test it on.

This implementation is similar to how Vscode handles it. Except, they
don't show custom message.

**Working**:

When file saving fails due to a `PermissionDenied` error, we create a
temporary file in the same directory as the target file and writes the
data to this temporary file. After, the contents of this file are copied
to the original file using the `tee` command instead of `cp` or `mv`.
This ensures that the ownership and permissions of the original file are
preserved. This command is executed using `pkexec` which will prompt
user for their password.

**Custom Message**:

The message displayed to the user in the prompt is automatically
retrieved from the `org.zed.app.policy` file, which is located at
`/usr/share/polkit-1/actions/`. This file should be installed during the
setup process. While the policy file is optional, omitting it will cause
the user to see the underlying command being executed rather than a
user-friendly message. Currently, VSCode does not display the
user-friendly message.

The policy file must specify a unique binary, ensuring that only that
binary can use the policy file. It cannot be as generic as a
`/bin/bash`, as any software using bash to prompt will end up showing
Zed’s custom message. To address this, we will create a custom bash
script, as simple as the following, placed in `/usr/bin/zed/elevate.sh`.
The script should have root ownership and should not reside in the home
directory, since the policy file cannot resolve `$HOME`.

```sh
#!/bin/bash
eval "$@"
```

*IMPORTANT NOTE*

Since copying the policy file and our script requires sudo privileges,
the installation script will now prompt for the password at very end.
Only on Linux, if `pexec` is installed.

Screenshots:

KDE with policy file:
![Screenshot from 2024-12-15
22-13-06](https://github.com/user-attachments/assets/b8bb7565-85df-4c95-bb10-82e50acf9b56)

Gnome with policy file:
![Screenshot from 2024-12-15
22-21-48](https://github.com/user-attachments/assets/83d15056-a2bd-41d9-a01d-9b8954260381)

Gnome without policy file:

![image](https://github.com/user-attachments/assets/66c39d02-eed4-4f09-886f-621b6d37ff43)

VSCode:

![image](https://github.com/user-attachments/assets/949dc470-c3df-4e2f-8cc6-31babaee1d18)

User declines the permission request:

![image](https://github.com/user-attachments/assets/c5cbf056-f6f9-43a8-8d88-f2b0597e14d6)

Release Notes:

- Fixed file saving with root ownership on Linux.
2024-12-19 22:16:01 +00:00
.cargo Use LiveKit's Rust SDK on Linux while continue using Swift SDK on Mac (#21550) 2024-12-05 15:06:17 -08:00
.cloudflare docs: Document context servers (#21170) 2024-11-25 11:05:14 -05:00
.config
.github ci: Put docs-only conditionals on each step (#22261) 2024-12-19 19:46:10 +00:00
.zed
assets Hide chat panel button when not in a call (#22200) 2024-12-19 19:32:45 +00:00
crates linux: Fix saving file with root ownership (#22045) 2024-12-19 22:16:01 +00:00
docs linux: Fix saving file with root ownership (#22045) 2024-12-19 22:16:01 +00:00
extensions astro: Bump to v0.1.2 (#22220) 2024-12-18 23:22:24 +00:00
legal Stop sending data to Clickhouse (#21763) 2024-12-10 08:47:29 -07:00
nix nix: Return to building with crane (#21292) 2024-11-29 10:09:33 +01:00
script Remove main push from bump-zed-minor-versions script (#22170) 2024-12-18 11:32:58 -05:00
tooling/xtask
.git-blame-ignore-revs
.gitattributes
.gitignore nix: Return to building with crane (#21292) 2024-11-29 10:09:33 +01:00
.mailmap Update .mailmap (#20729) 2024-11-15 11:05:41 -05:00
Cargo.lock linux: Fix saving file with root ownership (#22045) 2024-12-19 22:16:01 +00:00
Cargo.toml Switch to a single GPU context in Blade (#20853) 2024-12-18 14:47:09 -07:00
clippy.toml
CODE_OF_CONDUCT.md Remove community content from docs and point to zed.dev (#19895) 2024-10-29 09:44:58 -04:00
compose.yml
CONTRIBUTING.md Remove community content from docs and point to zed.dev (#19895) 2024-10-29 09:44:58 -04:00
Cross.toml
debug.plist
default.nix
docker-compose.sql
Dockerfile-collab
Dockerfile-collab.dockerignore
Dockerfile-cross
Dockerfile-cross.dockerignore
Dockerfile-distros
Dockerfile-distros.dockerignore
flake.lock nix: Return to building with crane (#21292) 2024-11-29 10:09:33 +01:00
flake.nix nix: Return to building with crane (#21292) 2024-11-29 10:09:33 +01:00
LICENSE-AGPL
LICENSE-APACHE
LICENSE-GPL
livekit.yaml
Procfile
Procfile.postgrest
README.md
renovate.json Migrate Renovate config (#20741) 2024-11-15 14:37:39 -05:00
rust-toolchain.toml
shell.nix
typos.toml Stop sending data to Clickhouse (#21763) 2024-12-10 08:47:29 -07:00

Zed

CI

Welcome to Zed, a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.


Installation

Packaging status

On macOS and Linux you can download Zed directly or install Zed via your local package manager.

Other platforms are not yet available:

Developing Zed

Contributing

See CONTRIBUTING.md for ways you can contribute to Zed.

Also... we're hiring! Check out our jobs page for open roles.

Licensing

License information for third party dependencies must be correctly provided for CI to pass.

We use cargo-about to automatically comply with open source licenses. If CI is failing, check the following:

  • Is it showing a no license specified error for a crate you've created? If so, add publish = false under [package] in your crate's Cargo.toml.
  • Is the error failed to satisfy license requirements for a dependency? If so, first determine what license the project has and whether this system is sufficient to comply with this license's requirements. If you're unsure, ask a lawyer. Once you've verified that this system is acceptable add the license's SPDX identifier to the accepted array in script/licenses/zed-licenses.toml.
  • Is cargo-about unable to find the license for a dependency? If so, add a clarification field at the end of script/licenses/zed-licenses.toml, as specified in the cargo-about book.