fix(anatomy): R5.3 authored values read as JSON.parse does (key order, big integers), non-list children refused, document value bound, --check and seed guard by identity
This commit is contained in:
1 parent
6c0fe88725
commit
07d63076d3
10 files changed
+222
-23
No files matched your search
@@ -181,6 +181,12 @@ fn listed(dir: &Path, prefix: &str, out: &mut Vec<String>) -> Result<(), String>
|
||||
/// draft are reported, not counted.
|
||||
fn check(folder: &Folder) -> Result<Vec<String>, String> {
|
||||
let target = Path::new(SEED).join(folder.name);
|
||||
// The generated folder itself must lie in the seed: a link there is never listed through.
|
||||
let seed = fs::canonicalize(SEED).map_err(|error| format!("{SEED}: {error}"))?;
|
||||
let canonical = fs::canonicalize(&target).map_err(|e| format!("{}: {e}", target.display()))?;
|
||||
if canonical != seed.join(folder.name) {
|
||||
return Ok(vec![format!("{}: not a folder of the seed", folder.name)]);
|
||||
}
|
||||
let mut problems = Vec::new();
|
||||
for (name, bytes) in &folder.files {
|
||||
match read(&target.join(name)) {
|
||||
@@ -227,7 +233,7 @@ fn claim_destination(typed: &Path, seed: &Path) -> Result<PathBuf, String> {
|
||||
}
|
||||
None => return Err(refuse("not a destination folder")),
|
||||
};
|
||||
if inside(&parent, seed) {
|
||||
if inside(&parent, seed) || inside_by_identity(&parent, seed) {
|
||||
return Err(refuse("inside the seed folder"));
|
||||
}
|
||||
let name = out
|
||||
@@ -254,6 +260,18 @@ fn inside(folder: &Path, seed: &Path) -> bool {
|
||||
folder.starts_with(seed)
|
||||
}
|
||||
|
||||
/// Whether the seed folder is `folder` or one of its ancestors, by file identity (device and
|
||||
/// inode): a second path to the seed (a bind mount, a share mounted twice) is caught too.
|
||||
fn inside_by_identity(folder: &Path, seed: &Path) -> bool {
|
||||
use std::os::unix::fs::MetadataExt;
|
||||
let Ok(seed) = fs::metadata(seed) else {
|
||||
return true;
|
||||
};
|
||||
folder.ancestors().any(|ancestor| {
|
||||
fs::metadata(ancestor).is_ok_and(|m| m.dev() == seed.dev() && m.ino() == seed.ino())
|
||||
})
|
||||
}
|
||||
|
||||
/// Where a relative destination is typed from: `INIT_CWD` when pnpm set it to an absolute
|
||||
/// path, else the current folder (the repository root when the script is run directly: it
|
||||
/// moves there first).
|
||||
@@ -377,10 +395,11 @@ fn main() {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
/// Fixed fixtures under the system's temporary folder: created once, never deleted, never
|
||||
/// written by the refusals below.
|
||||
/// Fixed fixtures under the workspace's target folder (private to the checkout): created
|
||||
/// once, never deleted, never written by the refusals below.
|
||||
fn fixture_seed() -> PathBuf {
|
||||
let base = env::temp_dir().join("faunosteo-import-equine-claim");
|
||||
let base = Path::new(concat!(env!("CARGO_MANIFEST_DIR"), "/../../target/tmp"))
|
||||
.join("import-equine-claim");
|
||||
fs::create_dir_all(base.join("seed/draft")).unwrap_or_else(|e| panic!("{e}"));
|
||||
fs::canonicalize(base.join("seed")).unwrap_or_else(|e| panic!("{e}"))
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user