Skip to content

Commit be756d6

Browse files
committed
refactor: own temporary directories through kernal-api
1 parent 027ddf5 commit be756d6

27 files changed

Lines changed: 176 additions & 140 deletions

‎Cargo.lock‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Cargo.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ strip = "none"
3636

3737
# Temporary migration override; replace with the verified published release.
3838
[patch.crates-io]
39-
kernal-api = { path = "../fastled-wasm-extern/kernal-api-entropy" }
39+
kernal-api = { path = "../fastled-wasm-extern/kernal-api-temporary" }
4040

4141
[profile.dev.package.kernal-api]
4242
codegen-units = 1

‎crates/fastled-cli/Cargo.toml‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ crossterm = { workspace = true }
3232
tokio = { workspace = true }
3333
toml = { workspace = true }
3434
tauri = { workspace = true, optional = true }
35-
tempfile = "3"
3635
shell-words = { workspace = true }
3736
tree-sitter = { workspace = true }
3837
tree-sitter-cpp = { workspace = true }

‎crates/fastled-cli/src/archive.rs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,10 +269,10 @@ fn _promote_single_child(dir: &Path) -> Result<()> {
269269
#[cfg(test)]
270270
mod tests {
271271
use super::*;
272-
use tempfile::TempDir;
272+
use kernal_api::platform::fs::TemporaryDirectory;
273273

274-
fn temp_dir() -> TempDir {
275-
tempfile::tempdir().expect("tempdir")
274+
fn temp_dir() -> TemporaryDirectory {
275+
kernal_api::platform::fs::TemporaryDirectory::new().expect("tempdir")
276276
}
277277

278278
#[test]
@@ -422,7 +422,7 @@ mod tests {
422422

423423
#[test]
424424
fn test_write_emscripten_config_does_not_touch_unchanged_file() {
425-
let dir = tempfile::tempdir().unwrap();
425+
let dir = kernal_api::platform::fs::TemporaryDirectory::new().unwrap();
426426
let install_dir = dir.path().join("emscripten").join("4.0.19");
427427
fs::create_dir_all(&install_dir).unwrap();
428428
let node = install_dir.join("managed-node");

‎crates/fastled-cli/src/cache_upgrade.rs‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ mod tests {
183183

184184
#[test]
185185
fn first_version_clears_only_shared_cache_and_records_breadcrumb() {
186-
let temp = tempfile::tempdir().unwrap();
186+
let temp = kernal_api::platform::fs::TemporaryDirectory::new().unwrap();
187187
let root = temp.path();
188188
write(&root.join("cache/legacy.txt"), "stale");
189189
write(&root.join("toolchains/keep.txt"), "toolchain");
@@ -210,7 +210,7 @@ mod tests {
210210

211211
#[test]
212212
fn same_version_preserves_new_cache_and_emits_no_warning() {
213-
let temp = tempfile::tempdir().unwrap();
213+
let temp = kernal_api::platform::fs::TemporaryDirectory::new().unwrap();
214214
let root = temp.path();
215215
write(&root.join("cache/legacy.txt"), "stale");
216216
ensure_cache_version(root, "2.0.16").unwrap();
@@ -228,7 +228,7 @@ mod tests {
228228

229229
#[test]
230230
fn changed_version_clears_cache_once_again() {
231-
let temp = tempfile::tempdir().unwrap();
231+
let temp = kernal_api::platform::fs::TemporaryDirectory::new().unwrap();
232232
let root = temp.path();
233233
ensure_cache_version(root, "2.0.16").unwrap();
234234
write(&root.join("cache/from-old-version.txt"), "stale");
@@ -246,7 +246,7 @@ mod tests {
246246

247247
#[test]
248248
fn missing_cache_records_version_silently() {
249-
let temp = tempfile::tempdir().unwrap();
249+
let temp = kernal_api::platform::fs::TemporaryDirectory::new().unwrap();
250250

251251
let outcome = ensure_cache_version(temp.path(), "2.0.16").unwrap();
252252

@@ -260,7 +260,7 @@ mod tests {
260260

261261
#[test]
262262
fn deletion_failure_does_not_publish_breadcrumb() {
263-
let temp = tempfile::tempdir().unwrap();
263+
let temp = kernal_api::platform::fs::TemporaryDirectory::new().unwrap();
264264
let root = temp.path();
265265
write(&root.join("cache/legacy.txt"), "stale");
266266

@@ -275,7 +275,7 @@ mod tests {
275275

276276
#[test]
277277
fn breadcrumb_failure_does_not_publish_success() {
278-
let temp = tempfile::tempdir().unwrap();
278+
let temp = kernal_api::platform::fs::TemporaryDirectory::new().unwrap();
279279
let root = temp.path();
280280
write(&root.join("cache/legacy.txt"), "stale");
281281
fs::create_dir_all(breadcrumb_temp_path(root, "2.0.16")).unwrap();
@@ -288,7 +288,7 @@ mod tests {
288288

289289
#[test]
290290
fn concurrent_first_runs_clear_once_after_rechecking_under_lock() {
291-
let temp = tempfile::tempdir().unwrap();
291+
let temp = kernal_api::platform::fs::TemporaryDirectory::new().unwrap();
292292
let root = temp.path().to_path_buf();
293293
write(&root.join("cache/legacy.txt"), "stale");
294294
let barrier = Arc::new(Barrier::new(3));

‎crates/fastled-cli/src/clangd_config.rs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ mod tests {
545545

546546
#[test]
547547
fn writes_all_three_files_with_expected_contents() {
548-
let tmp = tempfile::tempdir().unwrap();
548+
let tmp = kernal_api::platform::fs::TemporaryDirectory::new().unwrap();
549549
let inputs = stub_inputs(tmp.path());
550550

551551
write_clangd_config(&inputs).unwrap();
@@ -664,7 +664,7 @@ mod tests {
664664

665665
#[test]
666666
fn merges_existing_vscode_settings() {
667-
let tmp = tempfile::tempdir().unwrap();
667+
let tmp = kernal_api::platform::fs::TemporaryDirectory::new().unwrap();
668668
let inputs = stub_inputs(tmp.path());
669669
let settings_path = inputs.sketch_dir.join(".vscode").join("settings.json");
670670
fs::create_dir_all(settings_path.parent().unwrap()).unwrap();
@@ -686,7 +686,7 @@ mod tests {
686686

687687
#[test]
688688
fn regenerating_is_idempotent() {
689-
let tmp = tempfile::tempdir().unwrap();
689+
let tmp = kernal_api::platform::fs::TemporaryDirectory::new().unwrap();
690690
let inputs = stub_inputs(tmp.path());
691691
write_clangd_config(&inputs).unwrap();
692692
let first = fs::read_to_string(inputs.sketch_dir.join("compile_commands.json")).unwrap();
@@ -697,7 +697,7 @@ mod tests {
697697

698698
#[test]
699699
fn emits_a_forced_prelude_entry_for_every_ino_tab() {
700-
let tmp = tempfile::tempdir().unwrap();
700+
let tmp = kernal_api::platform::fs::TemporaryDirectory::new().unwrap();
701701
let mut inputs = stub_inputs(tmp.path());
702702
let utility = inputs.sketch_dir.join("Utility.ino");
703703
fs::write(&utility, "void utility() {}\n").unwrap();

‎crates/fastled-cli/src/compile_stream.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ mod tests {
373373

374374
#[test]
375375
fn report_build_outcome_success_requires_index_html() {
376-
let dir = tempfile::tempdir().unwrap();
376+
let dir = kernal_api::platform::fs::TemporaryDirectory::new().unwrap();
377377
let (tx, mut rx) = kernal_api::async_engine::broadcast_channel::<String>(8).unwrap();
378378

379379
assert!(!report_build_outcome(dir.path(), &tx, true, true));
@@ -390,7 +390,7 @@ mod tests {
390390

391391
#[test]
392392
fn report_build_outcome_failure_is_error_even_with_stale_index() {
393-
let dir = tempfile::tempdir().unwrap();
393+
let dir = kernal_api::platform::fs::TemporaryDirectory::new().unwrap();
394394
std::fs::write(dir.path().join("index.html"), "<html></html>").unwrap();
395395
let (tx, mut rx) = kernal_api::async_engine::broadcast_channel::<String>(8).unwrap();
396396

@@ -402,7 +402,7 @@ mod tests {
402402

403403
#[test]
404404
fn report_build_outcome_allows_success_without_app() {
405-
let dir = tempfile::tempdir().unwrap();
405+
let dir = kernal_api::platform::fs::TemporaryDirectory::new().unwrap();
406406
let (tx, mut rx) = kernal_api::async_engine::broadcast_channel::<String>(8).unwrap();
407407

408408
assert!(report_build_outcome(dir.path(), &tx, true, false));

‎crates/fastled-cli/src/debug_symbols.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -368,11 +368,11 @@ pub fn guess_emsdk_path() -> Option<PathBuf> {
368368
#[cfg(test)]
369369
mod tests {
370370
use super::*;
371+
use kernal_api::platform::fs::TemporaryDirectory;
371372
use std::fs;
372-
use tempfile::TempDir;
373373

374-
fn setup_dirs() -> (TempDir, PathBuf, PathBuf, PathBuf) {
375-
let tmp = TempDir::new().unwrap();
374+
fn setup_dirs() -> (TemporaryDirectory, PathBuf, PathBuf, PathBuf) {
375+
let tmp = TemporaryDirectory::new().unwrap();
376376
let sketch_dir = tmp.path().join("sketch");
377377
let fastled_dir = tmp.path().join("FastLED");
378378
let emsdk_dir = tmp.path().join("emsdk");

‎crates/fastled-cli/src/dwarf_smoke.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ pub(crate) fn run_dwarf_source_smoke(output_dir: &Path) -> anyhow::Result<usize>
6161
#[cfg(test)]
6262
#[test]
6363
fn source_smoke_uses_manifest_paths_and_reports_missing_source() {
64-
let dir = tempfile::tempdir().unwrap();
64+
let dir = kernal_api::platform::fs::TemporaryDirectory::new().unwrap();
6565
let sketch = dir.path().join("sketch");
6666
std::fs::create_dir(&sketch).unwrap();
6767
let source = sketch.join("demo.ino");

‎crates/fastled-cli/src/dynamic_cache.rs‎

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -335,8 +335,11 @@ pub(crate) fn write_metadata(staging: &Path, fingerprint: &str, artifacts: &[&st
335335
/// Publish a fully validated staging directory by one same-filesystem rename.
336336
/// A key is never observable as successful until every artifact and its
337337
/// metadata are complete.
338-
pub(crate) fn publish_staging(staging: tempfile::TempDir, target: &Path) -> Result<()> {
339-
let staging_path = staging.keep();
338+
pub(crate) fn publish_staging(
339+
staging: kernal_api::platform::fs::TemporaryDirectory,
340+
target: &Path,
341+
) -> Result<()> {
342+
let staging_path = staging.persist();
340343
if target.exists() {
341344
fs::remove_dir_all(target)
342345
.with_context(|| format!("remove invalid cache entry {}", target.display()))?;
@@ -354,12 +357,13 @@ pub(crate) fn publish_staging(staging: tempfile::TempDir, target: &Path) -> Resu
354357
Ok(())
355358
}
356359

357-
pub(crate) fn staging_dir(cache_root: &Path, prefix: &str) -> Result<tempfile::TempDir> {
360+
pub(crate) fn staging_dir(
361+
cache_root: &Path,
362+
prefix: &str,
363+
) -> Result<kernal_api::platform::fs::TemporaryDirectory> {
358364
fs::create_dir_all(cache_root)
359365
.with_context(|| format!("create cache root {}", cache_root.display()))?;
360-
tempfile::Builder::new()
361-
.prefix(prefix)
362-
.tempdir_in(cache_root)
366+
kernal_api::platform::fs::TemporaryDirectory::in_directory(cache_root, prefix)
363367
.with_context(|| format!("create staging directory in {}", cache_root.display()))
364368
}
365369

@@ -473,7 +477,7 @@ mod tests {
473477
// the persistent fingerprint before the next lookup.
474478
#[test]
475479
fn explicit_invalidation_detects_immediate_same_size_edit_with_restored_mtime() {
476-
let temp = tempfile::tempdir().unwrap();
480+
let temp = kernal_api::platform::fs::TemporaryDirectory::new().unwrap();
477481
let source = temp.path().join("sketch.ino");
478482
fs::write(&source, "aaaa").unwrap();
479483
let mut fingerprint = fingerprint_tree_persistent(temp.path(), &["**/*.ino"], &[]).unwrap();
@@ -499,8 +503,8 @@ mod tests {
499503

500504
#[test]
501505
fn path_invalidation_dirties_only_matching_spec() {
502-
let first = tempfile::tempdir().unwrap();
503-
let second = tempfile::tempdir().unwrap();
506+
let first = kernal_api::platform::fs::TemporaryDirectory::new().unwrap();
507+
let second = kernal_api::platform::fs::TemporaryDirectory::new().unwrap();
504508
fs::write(first.path().join("one.cpp"), "one").unwrap();
505509
fs::write(second.path().join("two.cpp"), "two").unwrap();
506510
fingerprint_tree_persistent(first.path(), &["**/*.cpp"], &[]).unwrap();
@@ -516,7 +520,7 @@ mod tests {
516520

517521
#[test]
518522
fn lost_fingerprint_watch_discards_cached_value_and_registers_again() {
519-
let temp = tempfile::tempdir().unwrap();
523+
let temp = kernal_api::platform::fs::TemporaryDirectory::new().unwrap();
520524
fs::write(temp.path().join("sketch.ino"), "aaaa").unwrap();
521525
let expected = fingerprint_tree_persistent(temp.path(), &["**/*.ino"], &[]).unwrap();
522526
let spec = FingerprintSpec {
@@ -542,8 +546,8 @@ mod tests {
542546

543547
#[test]
544548
fn invalidate_all_dirties_every_spec() {
545-
let first = tempfile::tempdir().unwrap();
546-
let second = tempfile::tempdir().unwrap();
549+
let first = kernal_api::platform::fs::TemporaryDirectory::new().unwrap();
550+
let second = kernal_api::platform::fs::TemporaryDirectory::new().unwrap();
547551
fs::write(first.path().join("one.cpp"), "one").unwrap();
548552
fs::write(second.path().join("two.cpp"), "two").unwrap();
549553
fingerprint_tree_persistent(first.path(), &["**/*.cpp"], &[]).unwrap();
@@ -554,7 +558,7 @@ mod tests {
554558

555559
#[test]
556560
fn excluded_output_path_does_not_dirty_spec() {
557-
let temp = tempfile::tempdir().unwrap();
561+
let temp = kernal_api::platform::fs::TemporaryDirectory::new().unwrap();
558562
fs::create_dir_all(temp.path().join("fastled_js")).unwrap();
559563
fs::write(temp.path().join("source.cpp"), "source").unwrap();
560564
fingerprint_tree_persistent(temp.path(), &["**/*.cpp"], &["fastled_js/**"]).unwrap();
@@ -588,7 +592,7 @@ mod tests {
588592

589593
#[test]
590594
fn validation_rejects_missing_empty_truncated_and_corrupt_entries() {
591-
let temp = tempfile::tempdir().unwrap();
595+
let temp = kernal_api::platform::fs::TemporaryDirectory::new().unwrap();
592596
let entry = temp.path().join("entry");
593597
fs::create_dir(&entry).unwrap();
594598
fs::write(entry.join("fastled.js"), "js").unwrap();
@@ -612,7 +616,7 @@ mod tests {
612616

613617
#[test]
614618
fn cache_lock_serializes_same_key() {
615-
let temp = tempfile::tempdir().unwrap();
619+
let temp = kernal_api::platform::fs::TemporaryDirectory::new().unwrap();
616620
let root = temp.path().to_path_buf();
617621
let barrier = Arc::new(Barrier::new(2));
618622
let other_barrier = Arc::clone(&barrier);
@@ -630,7 +634,7 @@ mod tests {
630634

631635
#[test]
632636
fn atomic_publish_replaces_invalid_entry() {
633-
let temp = tempfile::tempdir().unwrap();
637+
let temp = kernal_api::platform::fs::TemporaryDirectory::new().unwrap();
634638
let root = temp.path().join("cache");
635639
fs::create_dir(&root).unwrap();
636640
let target = root.join("key");
@@ -648,7 +652,7 @@ mod tests {
648652

649653
#[test]
650654
fn attempt_state_records_pending_failure_and_clears_after_success() {
651-
let temp = tempfile::tempdir().unwrap();
655+
let temp = kernal_api::platform::fs::TemporaryDirectory::new().unwrap();
652656
mark_pending(temp.path(), "key", "main-link").unwrap();
653657
assert_eq!(
654658
previous_attempt(temp.path(), "key").as_deref(),

0 commit comments

Comments
 (0)