Sample
fs_extra 1.3.0: fs_extra::dir
Verified sample for cargo fs_extra 1.3.0: fs_extra::dir. The contract ran on rust 1 · linux alpine/x64 · docker and passed: fs_extra::dir::create and…
sha256:94e7269a38ae2c300364a8551efd2c51257c7bd865d048e0ab03604d4f3e0a41
This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured.
How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people.
MIT-0
Execution evidence
The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.
- Evidence basis
- Signed contract pass
- Verification receipts
- 1
- Signing keys that built it
- 1
Declared environment
linux · alpine · musl x64 cargo
Verification-run environments
| Environment | Contract | Stages | Run |
|---|---|---|---|
| rust 1 · linux alpine/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · cargo@1rust:1-alpine@sha256:a10e64dd139b… |
2026-11-22 |
Case
HOW- Goal
- verify fs_extra::dir in pkg:cargo/fs_extra@1.3.0
- Packages
- Symbols
-
- fs_extra::dir
- Created
- 2026-11-22T16:43:08Z
Contract
- fs_extra::dir::create and fs_extra::dir::create_all create single and nested directories, and erase existing directory contents when erase=true
- fs_extra::dir::get_size sums file bytes only, while get_dir_content and get_dir_content2 (with DirOptions::depth) traverse entries and include directory metadata lengths in dir_size
- fs_extra::dir::ls populates DirEntryAttr attributes where Name is file_stem for files, FullName is full filename, Ext is extension, and DirEntryValue is inspected via pattern matching
- fs_extra::dir::copy with CopyOptions copies directory trees and supports content_only, skip_exist, and overwrite modes while returning an error on collisions by default
- fs_extra::dir::move_dir relocates a directory tree into a target directory and removes the source directory
- fs_extra::dir::remove recursively removes a directory tree
Files
- Cargo.lock
- Cargo.toml
- PROMPT.md
- csx.json
- spec.json
- src/lib.rs
- test/contract.rs
Source
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "fs_extra"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42703706b716c37f96a77aea830392ad231f44c9e9a67872fa5548707e11b11c"
[[package]]
name = "sample-fs-extra-dir"
version = "1.0.0"
dependencies = [
"fs_extra",
]
[package]
name = "sample-fs-extra-dir"
version = "1.0.0"
edition = "2021"
publish = false
[dependencies]
fs_extra = "=1.3.0"
[[bin]]
name = "contract"
path = "test/contract.rs"
Clean-room public code sample — generation instructions
Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.
A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.
Goal: verify fs_extra::dir in pkg:cargo/fs_extra@1.3.0
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:cargo/fs_extra@1.3.0
Demonstrate these symbols/APIs:
- fs_extra::dir
Rules:
- One focused purpose; the smallest project that proves the goal.
- Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
- Pin every dependency with a lockfile so resolution is reproducible.
- No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
- No personal names, emails, company names, or project identifiers of any kind.
- No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
- Keep it under 200 files and 256KB packed.
{"case":{"caseId":"case:sha256:1210f478e069c110c0599bac1cb8355bd50f40dfaddb87481d30062bfacd73ea","contract":["fs_extra::dir::create and fs_extra::dir::create_all create single and nested directories, and erase existing directory contents when erase=true","fs_extra::dir::get_size sums file bytes only, while get_dir_content and get_dir_content2 (with DirOptions::depth) traverse entries and include directory metadata lengths in dir_size","fs_extra::dir::ls populates DirEntryAttr attributes where Name is file_stem for files, FullName is full filename, Ext is extension, and DirEntryValue is inspected via pattern matching","fs_extra::dir::copy with CopyOptions copies directory trees and supports content_only, skip_exist, and overwrite modes while returning an error on collisions by default","fs_extra::dir::move_dir relocates a directory tree into a target directory and removes the source directory","fs_extra::dir::remove recursively removes a directory tree"],"goal":"verify fs_extra::dir in pkg:cargo/fs_extra@1.3.0","kind":"HOW","packages":["pkg:cargo/fs_extra@1.3.0"],"schemaVersion":1,"symbols":["fs_extra::dir"]},"contractCommand":["cargo","run","--offline"],"environment":{"arch":"x64","distro":"alpine","ecosystem":"cargo","libc":"musl","os":"linux","packageManager":"cargo","schemaVersion":1},"license":"MIT-0","packages":["pkg:cargo/fs_extra@1.3.0"],"schemaVersion":1,"subject":"pkg:cargo/fs_extra@1.3.0","symbols":["fs_extra::dir"],"verifierAdapter":"cargo@1"}
{
"schemaVersion": 1,
"goal": "verify fs_extra::dir in pkg:cargo/fs_extra@1.3.0",
"kind": "HOW",
"packages": [
"pkg:cargo/fs_extra@1.3.0"
],
"symbols": [
"fs_extra::dir"
]
}
//! Clean-room verification sample for `fs_extra::dir` in `fs_extra@1.3.0`.
pub use fs_extra::dir;
use std::collections::HashSet;
use std::env;
use std::fs;
use std::process;
use fs_extra::dir::{
self, CopyOptions, DirEntryAttr, DirEntryValue, DirOptions,
};
fn main() {
let base = env::temp_dir().join(format!("csx-fs-extra-dir-{}", process::id()));
// Clean start via create_all with erase = true
dir::create_all(&base, true).expect("create_all base directory");
assert!(base.is_dir());
// 1. dir::create and dir::create_all with erase semantics
let src_dir = base.join("src_tree");
let nested_dir = src_dir.join("nested").join("deep");
dir::create(&src_dir, false).expect("create src_tree");
dir::create_all(&nested_dir, false).expect("create_all nested/deep");
let file_a = src_dir.join("alpha.txt");
let file_b = nested_dir.join("beta.txt");
fs::write(&file_a, b"hello").expect("write alpha.txt");
fs::write(&file_b, b"world!").expect("write beta.txt");
// Re-creating a populated directory with erase = true wipes its previous contents
let erasable = base.join("erasable");
dir::create(&erasable, false).expect("create erasable");
fs::write(erasable.join("stale.txt"), b"old").expect("write stale.txt");
dir::create(&erasable, true).expect("recreate erasable with erase=true");
assert!(erasable.is_dir());
assert!(!erasable.join("stale.txt").exists());
// 2. dir::get_size counts file bytes only, whereas get_dir_content includes directory metadata sizes
let total_size = dir::get_size(&src_dir).expect("get_size src_tree");
assert_eq!(total_size, 11); // "hello" (5) + "world!" (6)
let content = dir::get_dir_content(&src_dir).expect("get_dir_content src_tree");
assert_eq!(content.files.len(), 2);
assert_eq!(content.directories.len(), 3); // src_tree, nested, deep
let dir_meta_sum: u64 = content
.directories
.iter()
.map(|d| fs::metadata(d).expect("dir metadata").len())
.sum();
assert_eq!(content.dir_size, dir_meta_sum + 11);
let mut limited_opts = DirOptions::new();
limited_opts.depth = 1;
let shallow = dir::get_dir_content2(&src_dir, &limited_opts).expect("get_dir_content2 depth=1");
assert_eq!(shallow.files.len(), 1);
assert_eq!(shallow.directories.len(), 2); // src_tree, nested (does not descend into deep)
let shallow_meta_sum: u64 = shallow
.directories
.iter()
.map(|d| fs::metadata(d).expect("shallow dir metadata").len())
.sum();
assert_eq!(shallow.dir_size, shallow_meta_sum + 5);
// 3. dir::ls with DirEntryAttr selection
// Note: DirEntryAttr::Name is file_stem for files (without extension), FullName includes extension,
// and DirEntryValue does not implement PartialEq/Debug so variants are matched explicitly.
let mut attrs = HashSet::new();
attrs.insert(DirEntryAttr::Name);
attrs.insert(DirEntryAttr::FullName);
attrs.insert(DirEntryAttr::Ext);
attrs.insert(DirEntryAttr::IsDir);
attrs.insert(DirEntryAttr::FileSize);
let listing = dir::ls(&src_dir, &attrs).expect("ls src_tree");
assert_eq!(listing.items.len(), 2); // alpha.txt and nested/
let mut found_alpha = false;
let mut found_nested = false;
for item in &listing.items {
match item.get(&DirEntryAttr::FullName) {
Some(DirEntryValue::String(full_name)) if full_name == "alpha.txt" => {
assert!(matches!(
item.get(&DirEntryAttr::Name),
Some(DirEntryValue::String(stem)) if stem == "alpha"
));
assert!(matches!(
item.get(&DirEntryAttr::Ext),
Some(DirEntryValue::String(ext)) if ext == "txt"
));
assert!(matches!(
item.get(&DirEntryAttr::IsDir),
Some(DirEntryValue::Boolean(false))
));
assert!(matches!(
item.get(&DirEntryAttr::FileSize),
Some(DirEntryValue::U64(5))
));
found_alpha = true;
}
Some(DirEntryValue::String(full_name)) if full_name == "nested" => {
assert!(matches!(
item.get(&DirEntryAttr::Name),
Some(DirEntryValue::String(name)) if name == "nested"
));
assert!(matches!(
item.get(&DirEntryAttr::IsDir),
Some(DirEntryValue::Boolean(true))
));
found_nested = true;
}
_ => {}
}
}
assert!(found_alpha && found_nested);
// 4. dir::copy with CopyOptions (default into target, content_only, overwrite, skip_exist)
let copy_dest = base.join("copy_dest");
dir::create(©_dest, true).expect("create copy_dest");
let opts = CopyOptions::new();
let copied_bytes = dir::copy(&src_dir, ©_dest, &opts).expect("copy src_tree into copy_dest");
assert_eq!(copied_bytes, 11);
assert_eq!(
fs::read(copy_dest.join("src_tree").join("alpha.txt")).expect("read copied alpha"),
b"hello"
);
assert_eq!(
fs::read(copy_dest.join("src_tree").join("nested").join("deep").join("beta.txt"))
.expect("read copied beta"),
b"world!"
);
// content_only copies children directly into destination without creating src_tree/
let content_dest = base.join("content_dest");
dir::create(&content_dest, true).expect("create content_dest");
let mut content_opts = CopyOptions::new();
content_opts.content_only = true;
dir::copy(&src_dir, &content_dest, &content_opts).expect("copy content_only");
assert_eq!(fs::read(content_dest.join("alpha.txt")).expect("read alpha"), b"hello");
// overwrite=false fails when destination exists, skip_exist=true skips without overwriting
fs::write(content_dest.join("alpha.txt"), b"modified").expect("modify alpha");
assert!(dir::copy(&src_dir, &content_dest, &content_opts).is_err());
let mut skip_opts = CopyOptions::new();
skip_opts.content_only = true;
skip_opts.skip_exist = true;
dir::copy(&src_dir, &content_dest, &skip_opts).expect("copy with skip_exist");
assert_eq!(fs::read(content_dest.join("alpha.txt")).expect("read skipped alpha"), b"modified");
let mut overwrite_opts = CopyOptions::new();
overwrite_opts.content_only = true;
overwrite_opts.overwrite = true;
dir::copy(&src_dir, &content_dest, &overwrite_opts).expect("copy with overwrite");
assert_eq!(fs::read(content_dest.join("alpha.txt")).expect("read overwritten alpha"), b"hello");
// 5. dir::move_dir relocates directory tree and removes source
let move_target = base.join("move_target");
dir::create(&move_target, true).expect("create move_target");
let move_opts = CopyOptions::new();
let moved_bytes = dir::move_dir(&content_dest, &move_target, &move_opts).expect("move_dir");
assert_eq!(moved_bytes, 11);
assert!(!content_dest.exists());
assert_eq!(
fs::read(move_target.join("content_dest").join("nested").join("deep").join("beta.txt"))
.expect("read moved beta"),
b"world!"
);
// 6. dir::remove deletes directory tree recursively
dir::remove(&base).expect("remove base temp directory");
assert!(!base.exists());
println!("All fs_extra::dir contract assertions passed.");
}
Origin Seeder
anonymous