Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/).

### Fixed

- Build on Windows: read the file identity for spec transactions through a stable API, and keep the dependencies that every platform needs out of the Unix-only target table.
- Install a deck on Windows: write manifest keys, provenance paths, and snapshot entries with `/`, and read a manifest that an earlier tool wrote with `\`. `rune install` stopped with `source path has an ambiguous separator or control character`.
- Record the module name as the provenance source for a single-module source in `.rune`. The source was empty, and every install ended with `source snapshot remains unverified`.
- Step aside when Cursor runs a Claude hook entry: answer `{}` with exit 0, run no handler, and log `borrowed by cursor`. Every Cursor tool call was denied under `--on-failure deny`.
- Abandon the run workspace's initial working copy under jj 0.47, which names the caller's workspace on its creation. The run kept it and reported `outside_changes`.

Expand Down
8 changes: 5 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,6 @@ ureq = { version = "3", default-features = false, features = ["rustls", "platfor
webpki-root-certs = "1"
signal-hook = "=0.3.18"

[target.'cfg(unix)'.dependencies]
nix = { version = "0.30", features = ["fs", "process", "resource", "signal"] }

# git
gix = { version = "0.66", default-features = false, features = ["blocking-network-client", "blocking-http-transport-reqwest-rust-tls", "worktree-mutation"] }

Expand All @@ -105,6 +102,11 @@ ansi-to-tui = { version = "8.0.1", optional = true }
unicode-width = { version = "0.2", optional = true }
edtui = { version = "0.11", default-features = false, optional = true }

# A target table runs to the next table header, so it sits after every
# dependency that all platforms share.
[target.'cfg(unix)'.dependencies]
nix = { version = "0.30", features = ["fs", "process", "resource", "signal"] }

[build-dependencies]
sha2 = "0.10"

Expand Down
76 changes: 76 additions & 0 deletions docs/decisions/RUST-0015 Portable Path Text.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
---
title: "Portable Path Text"
description: "Every path that becomes text is written with forward slashes, so manifests, snapshots, and provenance read the same on Windows, macOS, and Linux"
type: adr
category: rust
tags:
- rust
- windows
- paths
- manifest
status: proposed
created: 2026-11-15
updated: 2026-11-15
author: "@LangrMartin"
project: rune-cli
related:
- "RUST-0003 Code Style and Tooling"
- "RUST-0010 Dependency and Lint Configuration"
responsible: ["@N4M3Z"]
accountable: ["@N4M3Z"]
consulted: []
informed: []
upstream: []
---

# Portable Path Text

## Context and Problem Statement

Rune stores and compares relative paths as text. Manifest keys, provenance paths, source snapshot entries, bundle entries, and the keys that `doctor` and `drift` compare are all strings, and the code splits and matches them on `/` (`strip_prefix("rules/")`, `split_once('/')`).

On Windows a `Path` turned into text carries `\`. Two things then go wrong:

- Matching fails. A rule at `rules\Name.md` is not recognized as a rule, so it deploys under `rules/rules/` and the manifest gets backslash keys.
- Validation refuses the path. `source_snapshot` and `bundle` reject any text that contains `\` as an ambiguous separator. On macOS and Linux that check catches a suspicious file name. On Windows it rejects every nested path and the deck root itself, so `rune install` stops with `source path has an ambiguous separator or control character`.

The same build had two blockers before any of this ran: `rune-docs` read the Windows file identity through the unstable `windows_by_handle` feature, and a `[target.'cfg(unix)'.dependencies]` header in `Cargo.toml` sat above dependencies that every platform needs.

## Considered Options

1. **Convert at each call site**: add `.replace('\\', "/")` wherever a failure shows up, as `assemble/sources.rs` and `graph/mod.rs` already do in one place each.
2. **One helper at the boundary**: every relative path that becomes text passes through `services::paths::slash_text` or `slash_separators`.
3. **Never compare paths as text**: carry `PathBuf` and components through the manifest, snapshot, and provenance code.
4. **Declare Windows unsupported**: keep the Unix-only assumption and say so.

## Decision Outcome

Option 2. The text form of a relative path is `/`-separated on every platform.

- Convert where a `Path` becomes a `String` that is stored, compared, or split. Use `rune::services::paths::slash_text` for a `Path` and `slash_separators` for text that came from `to_str()`. Do not call `to_string_lossy()` directly on such a path.
- On Windows the helper rewrites `\` to `/`. No Windows file name can contain `\`, so the rewrite loses nothing. On other platforms the helper returns the text unchanged.
- The ambiguous separator check runs after the conversion. It keeps rejecting a literal backslash in a name on macOS and Linux and no longer rejects ordinary Windows paths.
- Text read back from disk gets the same conversion. `manifest::read` converts keys and provenance paths, so a manifest written with `\` keys by an earlier deploy tool names the same files and its entries are not pruned as stale.
- Slash text may be joined back onto a `Path`. `Path::join` accepts `/` on Windows.
- An absolute path that is only shown to the user keeps the native form.

Option 1 leaves the next unconverted site to fail in the field. Option 3 is the larger and safer design, and it can follow later without changing the stored format this record fixes. Option 4 contradicts the Windows entry that the release workflow already carries.

### Consequences

A manifest written on Windows has the same keys as one written on macOS or Linux for the same content, so a deployment can be compared across machines.

File identity on Windows comes from the open handle through `winapi-util`, a safe wrapper, because stable `std` does not expose the volume serial number and file index. `unsafe_code = "forbid"` stays in force.

Directory syncing in the spec transaction is skipped on Windows, where `File::open` cannot open a directory.

Still open on Windows:

- Symlink assembly and deployment return an explicit error.
- Integration tests isolate the home directory through `HOME`. `dirs::home_dir` ignores `HOME` on Windows, so those tests would write to the real home directory and must not run there until rune has a home override.
- `target::Scope::Project` derives its key by replacing `/` only.
- Three library tests assert on the native text of an absolute path and fail on Windows.

## More Information

Verified on Windows 11 with the `stable-x86_64-pc-windows-gnu` toolchain: `rune install`, a repeated install, `rune doctor`, `rune drift`, and `rune provenance` against the runedeck deck in an isolated target; the `rune-docs` test suite; the library unit tests apart from the three named above.
8 changes: 7 additions & 1 deletion rune-docs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ default = []
# The whole spec module: lifecycle commands, the read-only scans, tree
# validation, and OpenSpec interop. links, adr, and the support helpers are
# always compiled.
lifecycle = ["dep:clap", "dep:sha2"]
lifecycle = ["dep:clap", "dep:sha2", "dep:winapi-util"]

[dependencies]
clap = { version = "4", features = ["derive"], optional = true }
Expand All @@ -27,6 +27,12 @@ serde_json = "1"
serde_yaml = "0.9"
sha2 = { version = "0.10", optional = true }

# Stable std keeps the Windows volume serial number and file index behind an
# unstable feature; this is the safe wrapper the spec transaction reads them
# through.
[target.'cfg(windows)'.dependencies]
winapi-util = { version = "0.1", optional = true }

[dev-dependencies]
tempfile = "3"

Expand Down
69 changes: 48 additions & 21 deletions rune-docs/src/spec/transaction/confine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,34 +18,61 @@ pub(super) struct FileIdentity {
#[cfg(windows)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub(super) struct FileIdentity {
volume: Option<u32>,
index: Option<u64>,
volume: u64,
index: u64,
}

#[cfg(not(any(unix, windows)))]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub(super) struct FileIdentity;

#[cfg(any(unix, windows))]
#[cfg(unix)]
pub(super) fn metadata_identity(metadata: &fs::Metadata) -> FileIdentity {
#[cfg(unix)]
{
use std::os::unix::fs::MetadataExt as _;
FileIdentity {
device: metadata.dev(),
inode: metadata.ino(),
}
}
#[cfg(windows)]
{
use std::os::windows::fs::MetadataExt as _;
FileIdentity {
volume: metadata.volume_serial_number(),
index: metadata.file_index(),
}
use std::os::unix::fs::MetadataExt as _;
FileIdentity {
device: metadata.dev(),
inode: metadata.ino(),
}
}

/// Stable std keeps the volume serial number and file index of
/// `fs::Metadata` behind an unstable feature on Windows, so the identity is
/// read from the open handle.
#[cfg(windows)]
pub(super) fn handle_identity(file: &fs::File) -> io::Result<FileIdentity> {
let information = winapi_util::file::information(file)?;
Ok(FileIdentity {
volume: information.volume_serial_number(),
index: information.file_index(),
})
}

/// Metadata and identity of `path` itself, taken from one inspection so the
/// two cannot describe different files. A symlink is never followed.
#[cfg(unix)]
fn inspect_without_following(path: &Path) -> io::Result<(fs::Metadata, FileIdentity)> {
let metadata = fs::symlink_metadata(path)?;
let identity = metadata_identity(&metadata);
Ok((metadata, identity))
}

#[cfg(windows)]
fn inspect_without_following(path: &Path) -> io::Result<(fs::Metadata, FileIdentity)> {
use std::os::windows::fs::OpenOptionsExt as _;
// The reparse-point flag opens a symlink itself rather than its target;
// backup semantics lets a directory open so the caller rejects it by kind
// instead of by an access error.
const FILE_FLAG_OPEN_REPARSE_POINT: u32 = 0x0020_0000;
const FILE_FLAG_BACKUP_SEMANTICS: u32 = 0x0200_0000;
let file = fs::OpenOptions::new()
.access_mode(0)
.custom_flags(FILE_FLAG_OPEN_REPARSE_POINT | FILE_FLAG_BACKUP_SEMANTICS)
.open(path)?;
let metadata = file.metadata()?;
let identity = handle_identity(&file)?;
Ok((metadata, identity))
}

pub(super) fn file_identity(path: &Path) -> Result<FileIdentity, Error> {
#[cfg(not(any(unix, windows)))]
{
Expand All @@ -57,15 +84,15 @@ pub(super) fn file_identity(path: &Path) -> Result<FileIdentity, Error> {
}
#[cfg(any(unix, windows))]
{
let metadata =
fs::symlink_metadata(path).map_err(|error| io_error("inspect", path, error))?;
let (metadata, identity) =
inspect_without_following(path).map_err(|error| io_error("inspect", path, error))?;
if metadata.file_type().is_symlink() || !metadata.is_file() {
return Err(Error::new(
ErrorKind::Io,
format!("transaction path is not a regular file: {}", path.display()),
));
}
Ok(metadata_identity(&metadata))
Ok(identity)
}
}

Expand Down
5 changes: 1 addition & 4 deletions rune-docs/src/spec/transaction/conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,10 +256,7 @@ impl<I: TransactionIo> Transaction<I> {
fs::hard_link(&install, &destination)
.map_err(|error| io_error("install create-only destination", &destination, error))?;
verify_file_hash(&destination, &write.intended_sha256)?;
let directory = File::open(parent).map_err(|error| io_error("open", parent, error))?;
directory
.sync_all()
.map_err(|error| io_error("sync", parent, error))
super::staging::sync_directory(parent)
}

fn create_conversion_destination_directories(
Expand Down
16 changes: 13 additions & 3 deletions rune-docs/src/spec/transaction/staging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,20 @@ pub(super) fn write_file_atomic(path: &Path, content: &[u8]) -> Result<(), Error
io_error("replace", path, error),
));
}
let directory = File::open(parent).map_err(|error| io_error("open", parent, error))?;
directory
sync_directory(parent)
}

/// Flush a directory after an entry in it changed. Windows cannot open a
/// directory through `File::open`, so the change is left to the filesystem
/// journal there.
pub(super) fn sync_directory(directory: &Path) -> Result<(), Error> {
if cfg!(windows) {
return Ok(());
}
let handle = File::open(directory).map_err(|error| io_error("open", directory, error))?;
handle
.sync_all()
.map_err(|error| io_error("sync", parent, error))
.map_err(|error| io_error("sync", directory, error))
}

pub(super) fn replace_file_from_backup(
Expand Down
9 changes: 8 additions & 1 deletion rune-docs/src/spec/transaction/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
//! a deterministic tree digest (sorted entries, kind- and length-prefixed)
//! that proves a copied archive matches its source byte for byte.

use super::confine::{FileIdentity, metadata_identity, reject_symlink};
#[cfg(windows)]
use super::confine::handle_identity;
#[cfg(unix)]
use super::confine::metadata_identity;
use super::confine::{FileIdentity, reject_symlink};
use super::io_error;
use crate::error::{Error, ErrorKind};
use sha2::{Digest, Sha256};
Expand Down Expand Up @@ -45,7 +49,10 @@ pub(super) fn hash_file_with_identity(path: &Path) -> Result<(String, FileIdenti
format!("transaction path is not a regular file: {}", path.display()),
));
}
#[cfg(unix)]
let identity = metadata_identity(&metadata);
#[cfg(windows)]
let identity = handle_identity(&file).map_err(|error| io_error("inspect", path, error))?;
Ok((hash_open_file(&mut file, path)?, identity))
}
}
Expand Down
30 changes: 9 additions & 21 deletions src/cli/assemble/sources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,12 +363,9 @@ fn collect_pending(dir: &Path, module_root: &Path, pending: &mut Vec<String>) {
effective_review_state(&path, module_root),
AdoptReviewState::Deployable
) {
pending.push(
path.strip_prefix(module_root)
.unwrap_or(&path)
.to_string_lossy()
.to_string(),
);
pending.push(rune::services::paths::slash_text(
path.strip_prefix(module_root).unwrap_or(&path),
));
}
}
}
Expand Down Expand Up @@ -440,11 +437,8 @@ fn walk_content_dir(

base_filenames.insert(filename);

let relative = path
.strip_prefix(module_root)
.unwrap_or(&path)
.to_string_lossy()
.to_string();
let relative =
rune::services::paths::slash_text(path.strip_prefix(module_root).unwrap_or(&path));

let Some(content) = read_source_text(&path)? else {
continue;
Expand Down Expand Up @@ -512,11 +506,8 @@ fn walk_hook_dir(
let Some(content) = read_source_text(&path)? else {
continue;
};
let relative_path = path
.strip_prefix(module_root)
.unwrap_or(&path)
.to_string_lossy()
.to_string();
let relative_path =
rune::services::paths::slash_text(path.strip_prefix(module_root).unwrap_or(&path));
sources.push(SourceFile {
relative_path,
full_path: path.to_string_lossy().to_string(),
Expand Down Expand Up @@ -655,11 +646,8 @@ fn walk_qualifier_dir(
if base_filenames.contains(&filename) {
continue;
}
let relative = path
.strip_prefix(module_root)
.unwrap_or(&path)
.to_string_lossy()
.to_string();
let relative =
rune::services::paths::slash_text(path.strip_prefix(module_root).unwrap_or(&path));
let Some(content) = read_source_text(&path)? else {
continue;
};
Expand Down
6 changes: 1 addition & 5 deletions src/cli/dashboard/routes/artifact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -543,11 +543,7 @@ fn resolve_effective_content(
use rune::assemble::variants;
match variant_path {
Some(path) => {
let label = path
.strip_prefix(repo)
.unwrap_or(path)
.to_string_lossy()
.to_string();
let label = rune::services::paths::slash_text(path.strip_prefix(repo).unwrap_or(path));
let variant_content = match std::fs::read_to_string(path) {
Ok(content) => content,
Err(error) => {
Expand Down
8 changes: 3 additions & 5 deletions src/cli/deploy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -492,11 +492,9 @@ fn deploy_provider_kind_files(
continue;
}

let relative = build_path
.strip_prefix(kind_dir)
.unwrap_or(&build_path)
.to_string_lossy()
.to_string();
let relative = rune::services::paths::slash_text(
build_path.strip_prefix(kind_dir).unwrap_or(&build_path),
);
let manifest_key = format!("{kind}/{relative}");
if only.is_some_and(|prefix| !only_matches(&manifest_key, prefix)) {
continue;
Expand Down
2 changes: 1 addition & 1 deletion src/cli/doctor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ fn collect_managed_files_recursive(
format!("cannot relativize {}: {error}", entry_path.display()),
)
})?;
files.push(relative.to_string_lossy().into_owned());
files.push(rune::services::paths::slash_text(relative));
}
}
Ok(())
Expand Down
Loading
Loading