Skip to content

Commit 859faa8

Browse files
flokliclbot
authored andcommitted
fix(snix/glue): fix Store Path parsing
All outputs constructed by derivation_to_build_request use inputs_dir as a prefix (so we cannot use StorePath::from_bytes, which only takes the basename), and they are relative to their root, so we cannot use StorePath::from_absolute_path either. Construct the store paths by stripping inputs_dir early (right after the call to derivation_to_build_request), and use them later. Change-Id: I3874e11cf21159c05b02314d9baf26cc98ea7956 Reviewed-on: https://cl.snix.dev/c/snix/+/30569 Reviewed-by: Yureka <snix@yuka.dev> Tested-by: besadii Autosubmit: Florian Klink <flokli@flokli.de>
1 parent d741ca4 commit 859faa8

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

snix/glue/src/snix_store_io.rs

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,25 @@ impl SnixStoreIO {
197197
// synthesize the build request.
198198
let build_request = derivation_to_build_request(&drv, &resolved_inputs)?;
199199

200-
let build_request_outputs = build_request.outputs.clone();
200+
// collect all store paths from the request, sorted.
201+
let output_paths: Vec<StorePath<String>> = build_request
202+
.outputs
203+
.iter()
204+
.map(|output_path| {
205+
// in the case of building nix store paths,
206+
// all outputs are in `inputs_dir`.
207+
// When stripping it, we end up with the store path
208+
// basename.
209+
StorePath::from_bytes(
210+
output_path
211+
.strip_prefix(&build_request.inputs_dir)
212+
.expect("Snix bug: inputs_dir not prefix of request output")
213+
.as_os_str()
214+
.as_encoded_bytes(),
215+
)
216+
.expect("Snix bug: unable to parse output path as StorePath")
217+
})
218+
.collect();
201219

202220
// create a build
203221
let build_result = self
@@ -211,18 +229,8 @@ impl SnixStoreIO {
211229

212230
// For each output, insert a PathInfo.
213231
for (output, output_path) in
214-
build_result.outputs.into_iter().zip(build_request_outputs)
232+
build_result.outputs.into_iter().zip(output_paths)
215233
{
216-
// convert output_path to StorePath
217-
let output_store_path: StorePath<String> = {
218-
use std::os::unix::ffi::OsStrExt;
219-
220-
StorePath::from_bytes(output_path.as_path().as_os_str().as_bytes())
221-
.map_err(|e| {
222-
std::io::Error::new(std::io::ErrorKind::InvalidData, e)
223-
})?
224-
};
225-
226234
// calculate the nar representation
227235
let (nar_size, nar_sha256) = self
228236
.nar_calculation_service
@@ -231,7 +239,7 @@ impl SnixStoreIO {
231239

232240
// assemble the PathInfo to persist
233241
let path_info = PathInfo {
234-
store_path: output_store_path.clone(),
242+
store_path: output_path.clone(),
235243
node: output.node,
236244
references: {
237245
let all_possible_refs: Vec<_> = drv
@@ -283,7 +291,7 @@ impl SnixStoreIO {
283291
.await
284292
.map_err(|e| std::io::Error::new(io::ErrorKind::Other, e))?;
285293

286-
if store_path == &output_store_path {
294+
if store_path == &output_path {
287295
out_path_info = Some(path_info);
288296
}
289297
}

0 commit comments

Comments
 (0)