Skip to content

Commit 00c1924

Browse files
Ericson2314amaanq
andcommitted
harmonia-file: async file-tree libraries backed by cap-std
Add harmonia-file-io-pure and harmonia-file-fd implementing a generic async file-tree abstraction mirroring nix's SourceAccessor and FileSystemObjectSink, slim harmonia-file-core to the shared data types, and route NAR dump/restore plus harmonia-cache/narlist through the new FileSystemSource/FileSystemSink traits. The filesystem source wraps the released cap-std in spawn_blocking rather than depending on the unreleased cap-tokio PR, which is only that same sync crate behind spawn_blocking anyway. read_link uses read_link_contents so absolute symlink targets come back verbatim, and the dump strips the case-hack suffix on case-insensitive filesystems to match nix. Co-authored-by: Amaan Qureshi <git@amaanq.com>
1 parent b9374ca commit 00c1924

35 files changed

Lines changed: 2397 additions & 1201 deletions

Cargo.lock

Lines changed: 124 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ members = [
1717
"harmonia-store-remote",
1818
"harmonia-store-aterm",
1919
"harmonia-file-core",
20+
"harmonia-file-fd",
21+
"harmonia-file-io-pure",
2022
"harmonia-file-nar",
2123
"harmonia-protocol",
2224
"harmonia-protocol-derive",
@@ -45,6 +47,7 @@ async-stream = "0.3"
4547
blake3 = "1.8"
4648
bstr = "1.11"
4749
bytes = "1.11"
50+
cap-std = "3"
4851
data-encoding = "2.11"
4952
derive_more = { version = "2.1", features = [ "display" ] }
5053
ed25519-dalek = "2"
@@ -98,6 +101,8 @@ tokio-test = "0.4"
98101

99102
# Internal crates
100103
harmonia-file-core = { path = "harmonia-file-core" }
104+
harmonia-file-fd = { path = "harmonia-file-fd" }
105+
harmonia-file-io-pure = { path = "harmonia-file-io-pure" }
101106
harmonia-file-nar = { path = "harmonia-file-nar" }
102107
harmonia-protocol = { path = "harmonia-protocol" }
103108
harmonia-protocol-derive = { path = "harmonia-protocol-derive" }

docs/architecture/harmonia-store-structure.md

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ composed.
2222
┌────────────────────────────┬─────────────────────────┐
2323
│ Format / File │ Database │
2424
│ harmonia-file-nar │ harmonia-store-db │
25-
│ harmonia-file-core │ │
26-
│ NAR pack/unpack, types │ SQLite store metadata │
25+
│ harmonia-file-core/io/fd │ │
26+
│ NAR pack/unpack, file I/O │ SQLite store metadata │
2727
└────────────────────────────┴─────────────────────────┘
2828
2929
┌──────────────────────────────────────────────────────┐
@@ -51,7 +51,9 @@ composed.
5151
| [harmonia-store-aterm](../../harmonia-store-aterm/) | ATerm derivation parser |
5252
| [harmonia-store-path-info](../../harmonia-store-path-info/) | ValidPathInfo types (pure) |
5353
| [harmonia-store-db](../../harmonia-store-db/README.md) | SQLite store metadata |
54-
| [harmonia-file-core](../../harmonia-file-core/) | File tree types and serde (pure) |
54+
| [harmonia-file-core](../../harmonia-file-core/) | File tree data types and serde |
55+
| [harmonia-file-io-pure](../../harmonia-file-io-pure/) | Async IO traits, in-memory impls, listing |
56+
| [harmonia-file-fd](../../harmonia-file-fd/) | Filesystem source/sink via cap-std |
5557
| [harmonia-file-nar](../../harmonia-file-nar/README.md) | NAR archive format |
5658
| [harmonia-protocol](../../harmonia-protocol/README.md) | Daemon wire protocol |
5759
| [harmonia-protocol-derive](../../harmonia-protocol-derive/README.md) | Derive macros for protocol types |
@@ -100,16 +102,20 @@ graph BT
100102
end
101103
subgraph "File"
102104
file-core
105+
file-fd
106+
file-io-pure
103107
file-nar
104108
end
105109
bench
106110
client
107111
ssh-store
108-
file-nar --> file-core
109-
file-nar --> utils-io
112+
file-io-pure --> file-core
110113
utils-hash --> utils-base-encoding
111114
utils-signature --> utils-base-encoding
115+
file-fd --> file-io-pure
112116
store-path --> utils-hash
117+
file-nar --> file-fd
118+
file-nar --> utils-io
113119
store-content-address --> store-path
114120
store-ref-scan --> store-path
115121
store-derivation --> store-content-address
@@ -155,9 +161,11 @@ intra-workspace dependencies.
155161
- `harmonia-store-derivation`: derivations, derived paths, placeholders, realisations — depends on `harmonia-store-content-address`.
156162
- `harmonia-store-aterm`, `harmonia-store-path-info`, `harmonia-store-build-result`, `harmonia-store-nar-info`: format/metadata crates kept separate to avoid coupling.
157163

158-
**File** (`harmonia-file-core`, `harmonia-file-nar`)
159-
- `harmonia-file-core`: pure file tree types and serde matching nix's JSON format.
160-
- `harmonia-file-nar`: NAR pack/unpack against generic `AsyncRead`/`AsyncWrite`. Streaming; never requires the full input in memory. Knows nothing about derivations or signatures.
164+
**File** (`harmonia-file-core`, `harmonia-file-io-pure`, `harmonia-file-fd`, `harmonia-file-nar`)
165+
- `harmonia-file-core`: pure file tree data types (`FileTree`, `FileSystemObject`), serde matching nix's JSON format.
166+
- `harmonia-file-io-pure`: async IO traits (`FileSystemSource`/`FileSystemSink`), in-memory implementations, listing functions.
167+
- `harmonia-file-fd`: real filesystem source/sink via `cap-std` (openat, no symlink following).
168+
- `harmonia-file-nar`: NAR pack/unpack against generic `FileSystemSource`/`FileSystemSink` traits. Streaming; never requires the full input in memory. Knows nothing about derivations or signatures.
161169

162170
**Database** (`harmonia-store-db`)
163171
- Schema matches Nix's `db.sqlite` exactly.

harmonia-cache/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ edition.workspace = true
66
license.workspace = true
77
homepage.workspace = true
88
repository.workspace = true
9+
readme = "README.md"
910

1011
[[bin]]
1112
name = "harmonia-cache"
@@ -42,6 +43,8 @@ bytes = { workspace = true }
4243
futures-core = { workspace = true }
4344
futures-util = { workspace = true }
4445
harmonia-file-core = { workspace = true }
46+
harmonia-file-fd = { workspace = true }
47+
harmonia-file-io-pure = { workspace = true }
4548
harmonia-file-nar = { workspace = true }
4649
harmonia-store-db = { workspace = true }
4750
harmonia-store-derivation = { workspace = true }

harmonia-cache/src/error.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ pub enum ServeError {
7171
},
7272

7373
#[error("Access denied: {path}")]
74+
#[allow(dead_code)]
7475
AccessDenied { path: String },
7576
}
7677

0 commit comments

Comments
 (0)