Skip to content
Merged
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
34 changes: 34 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,37 @@ jobs:

- name: Test
run: cargo test --workspace

# release.yaml builds for Windows only on a signed tag, and the release
# rehearsal runs only when a release input changes. A pull request that
# changes Rust code alone reached a tag with a Windows build that did
# not compile. This job compiles every target of the workspace for
# Windows on every pull request, and a warning fails it. It then runs
# the release build command, which compiles code that only the release
# profile enables and links rune.exe, and the rune-docs tests.
windows:
runs-on: windows-latest
env:
RUSTFLAGS: -D warnings
steps:
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6
with:
persist-credentials: false

- uses: dtolnay/rust-toolchain@4be7066ada62dd38de10e7b70166bc74ed198c30 # stable
with:
toolchain: 1.100.0

- name: Check
run: cargo check --locked --workspace --all-features --all-targets

# The same command as the Windows row of the release matrix.
- name: Build the release binary
run: cargo build --release --locked --target x86_64-pc-windows-msvc

# Spec transactions open, link, rename, and flush files through
# Windows calls, and file identity comes from an open handle.
# Only a Windows runner can prove that a transaction completes
# there and that a hard link equals its target.
- name: Test rune-docs
run: cargo test --locked -p rune-docs --all-features
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/).

[0.7.1]: https://github.com/runedeck/rune/compare/v0.7.0...v0.7.1
[0.7.0]: https://github.com/runedeck/rune/compare/v0.6.0...v0.7.0
[0.6.0]: https://github.com/runedeck/rune/compare/v0.5.0...v0.6.0
[0.5.0]: https://github.com/runedeck/rune/compare/v0.4.0...v0.5.0
Expand All @@ -14,6 +15,15 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/).
[0.2.0]: https://github.com/runedeck/rune/compare/v0.1.0...v0.2.0
[0.1.0]: https://github.com/runedeck/rune/releases/tag/v0.1.0

## [0.7.1] - 2026-11-17

### Fixed

- Build for Windows again. The 0.7.0 release build for `x86_64-pc-windows-msvc` did not compile.
- Read a file's identity on Windows from an open handle, as the volume serial number and the file index, so the spec transaction can tell a replaced file from the one it hashed.
- Skip the directory flush on Windows, where a directory does not open as a file. Spec transactions no longer fail there when they sync a directory.
- Compile `gix`, `jsonschema`, and the dashboard and terminal UI dependencies on every platform. They sat in the Unix-only dependency table with `nix`.

## [0.7.0] - 2026-11-16

### Added
Expand Down
3 changes: 2 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rune-cli"
version = "0.7.0"
version = "0.7.1"
edition = "2024"
license = "EUPL-1.2"
repository = "https://github.com/runedeck/cli"
Expand Down Expand Up @@ -84,9 +84,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 @@ -109,6 +106,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 }

# Only nix is Unix-only. This table stays after every other dependency:
# a dependency written below a target table header belongs to that target.
[target.'cfg(unix)'.dependencies]
nix = { version = "0.30", features = ["fs", "process", "resource", "signal"] }

[build-dependencies]
sha2 = "0.10"

Expand Down
7 changes: 6 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,11 @@ serde_json = "1"
serde_yaml = "0.9"
sha2 = { version = "0.10", optional = true }

# File identity on Windows comes from an open handle: std has no stable
# accessor for the volume serial number or the file index.
[target.'cfg(windows)'.dependencies]
winapi-util = { version = "0.1.11", optional = true }

[dev-dependencies]
tempfile = "3"

Expand Down
166 changes: 141 additions & 25 deletions rune-docs/src/spec/transaction/confine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,62 +15,178 @@ pub(super) struct FileIdentity {
inode: u64,
}

/// The volume serial number and the file index, read from an open handle.
/// Stable Rust gives neither from `fs::Metadata` on Windows, and an
/// identity with no value in it would make every file equal every other.
///
/// The index is the 64-bit one. NTFS keeps it unique on a volume. `ReFS`
/// names a file with a 128-bit identifier and gives the 64-bit index only
/// where it can map the long identifier to it without loss. Everywhere
/// else it reports all bits set, and a file system with no index reports
/// zero. Neither value names a file, so `windows_identity` refuses both
/// instead of letting two files compare equal.
#[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;

/// `FILE_FLAG_BACKUP_SEMANTICS`: lets a directory open, so a directory is
/// reported as not a regular file instead of as an access error.
#[cfg(windows)]
const FILE_FLAG_BACKUP_SEMANTICS: u32 = 0x0200_0000;
/// `FILE_FLAG_OPEN_REPARSE_POINT`: opens a symlink itself, not its target.
#[cfg(windows)]
const FILE_FLAG_OPEN_REPARSE_POINT: u32 = 0x0020_0000;

#[cfg(any(unix, windows))]
pub(super) fn metadata_identity(metadata: &fs::Metadata) -> FileIdentity {
fn not_a_regular_file(path: &Path) -> Error {
Error::new(
ErrorKind::Io,
format!("transaction path is not a regular file: {}", path.display()),
)
}

/// The identity of an open regular file. The caller keeps the handle, so
/// the identity names the file the caller reads, not whatever the path
/// names a moment later.
#[cfg(any(unix, windows))]
pub(super) fn open_file_identity(file: &fs::File, path: &Path) -> Result<FileIdentity, Error> {
let metadata = file
.metadata()
.map_err(|error| io_error("inspect", path, error))?;
if !metadata.is_file() {
return Err(not_a_regular_file(path));
}
#[cfg(unix)]
{
use std::os::unix::fs::MetadataExt as _;
FileIdentity {
device: metadata.dev(),
inode: metadata.ino(),
}
Ok(unix_identity(&metadata))
}
#[cfg(windows)]
{
use std::os::windows::fs::MetadataExt as _;
FileIdentity {
volume: metadata.volume_serial_number(),
index: metadata.file_index(),
}
windows_identity(file, path)
}
}

pub(super) fn file_identity(path: &Path) -> Result<FileIdentity, Error> {
#[cfg(not(any(unix, windows)))]
{
let _ = path;
#[cfg(unix)]
fn unix_identity(metadata: &fs::Metadata) -> FileIdentity {
use std::os::unix::fs::MetadataExt as _;
FileIdentity {
device: metadata.dev(),
inode: metadata.ino(),
}
}

/// Whether a 64-bit file index names one file. Zero means the file system
/// keeps no index. All bits set means it could not give this file a
/// unique one, which `ReFS` does for a file whose 128-bit identifier does
/// not fit.
#[cfg(windows)]
pub(super) const fn index_names_one_file(index: u64) -> bool {
index != 0 && index != u64::MAX
}

/// The identity behind an open handle to a regular file. Every Windows
/// identity comes through here, so a path and an open file are held to
/// the same rules: the handle is not a console, a pipe, or another
/// device, and its index names one file.
#[cfg(windows)]
fn windows_identity(file: &fs::File, path: &Path) -> Result<FileIdentity, Error> {
let kind = winapi_util::file::typ(file).map_err(|error| io_error("inspect", path, error))?;
if kind.is_char() || kind.is_pipe() || kind.is_unknown() {
return Err(not_a_regular_file(path));
}
let information =
winapi_util::file::information(file).map_err(|error| io_error("inspect", path, error))?;
let index = information.file_index();
if !index_names_one_file(index) {
return Err(Error::new(
ErrorKind::Io,
"cannot verify file identity on this platform",
format!(
"cannot prove file identity because the file system gives no unique file index: {}",
path.display()
),
));
}
#[cfg(any(unix, windows))]
Ok(FileIdentity {
volume: information.volume_serial_number(),
index,
})
}

/// Opens `path` without following a symlink and without any access right:
/// reading the file information needs none. This is the handle form of
/// `fs::symlink_metadata`.
#[cfg(windows)]
fn open_without_following(path: &Path) -> Result<fs::File, Error> {
use std::os::windows::fs::OpenOptionsExt as _;
fs::OpenOptions::new()
.access_mode(0)
.custom_flags(FILE_FLAG_OPEN_REPARSE_POINT | FILE_FLAG_BACKUP_SEMANTICS)
.open(path)
.map_err(|error| io_error("inspect", path, error))
}

/// The identity behind a handle from `open_without_following`. The
/// metadata of that handle classifies the path as `fs::symlink_metadata`
/// does: a symlink or a junction is refused, and so is a directory. A
/// deduplicated file or a cloud file also carries a reparse point, but it
/// is a regular file with its own index, and a followed open of the same
/// path reads that same index.
#[cfg(windows)]
fn unfollowed_identity(file: &fs::File, path: &Path) -> Result<FileIdentity, Error> {
let metadata = file
.metadata()
.map_err(|error| io_error("inspect", path, error))?;
if metadata.file_type().is_symlink() || !metadata.is_file() {
return Err(not_a_regular_file(path));
}
windows_identity(file, path)
}

pub(super) fn file_identity(path: &Path) -> Result<FileIdentity, Error> {
#[cfg(unix)]
{
let metadata =
fs::symlink_metadata(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()),
));
return Err(not_a_regular_file(path));
}
Ok(metadata_identity(&metadata))
Ok(unix_identity(&metadata))
}
#[cfg(windows)]
{
unfollowed_identity(&open_without_following(path)?, path)
}
#[cfg(not(any(unix, windows)))]
{
let _ = path;
Err(Error::new(
ErrorKind::Io,
"cannot verify file identity on this platform",
))
}
}

pub(super) fn is_same_file(left: &Path, right: &Path) -> Result<bool, Error> {
Ok(file_identity(left)? == file_identity(right)?)
#[cfg(windows)]
{
// Both handles stay open until the comparison. A file index is
// unique only while the file exists, and an open handle keeps it
// from being given to another file.
let left_file = open_without_following(left)?;
let right_file = open_without_following(right)?;
Ok(unfollowed_identity(&left_file, left)? == unfollowed_identity(&right_file, right)?)
}
#[cfg(not(windows))]
{
Ok(file_identity(left)? == file_identity(right)?)
}
}

pub(super) fn path_exists_without_following(path: &Path) -> Result<bool, Error> {
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))
sync_directory(parent)
}

fn create_conversion_destination_directories(
Expand Down
Loading
Loading