feat(tvix/eval): Implement builtins.readFileType

builtins.readFileType was added to Nix back in version 2.14.

The tests were also moved out of notyetpassing in addition to the
readDir fixtures they depend on.

I caught a bug where we previously used std::fs::metadata (via the
.metadata() method on File) which follows symlinks so it would always
return false for is_symlink(). Instead we now use
std::fs::symlink_metadata directly which does not follow symlinks, so
tests now pass. This wasn't an issue for builtins.readDir as it uses
walkdir and walkdir doesn't follow symlinks either.

Change-Id: I58eb97bdb5ec95df4f6882f495f8c572fe7c6793
Reviewed-on: https://cl.tvl.fyi/c/depot/+/12130
Reviewed-by: flokli <flokli@flokli.de>
Autosubmit: Ilan Joselevich <personal@ilanjoselevich.com>
Tested-by: BuildkiteCI
This commit is contained in:
Ilan Joselevich 2024-08-04 01:00:25 +03:00
parent 9c4b57ac63
commit 3511e328ec
10 changed files with 47 additions and 3 deletions

View file

@ -81,6 +81,18 @@ mod impure_builtins {
}
}
}
#[builtin("readFileType")]
async fn builtin_read_file_type(co: GenCo, path: Value) -> Result<Value, ErrorKind> {
match coerce_value_to_path(&co, path).await? {
Err(cek) => Ok(Value::from(cek)),
Ok(path) => Ok(Value::from(
generators::request_read_file_type(&co, path)
.await
.to_string(),
)),
}
}
}
/// Return all impure builtins, that is all builtins which may perform I/O