Skip to content

Commit

Permalink
Make cache dir writable during tests
Browse files Browse the repository at this point in the history
Summary:
The temp cache is being left behind because it can't be deleted. This
fixes that.

Reviewed By: diliop

Differential Revision: D65338239

fbshipit-source-id: e49b7b952204259eecc8fcb5d87cbf0ffbaee0ca
  • Loading branch information
zertosh authored and facebook-github-bot committed Nov 1, 2024
1 parent 2a9943f commit a25a5ce
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
*/

use std::collections::HashMap;
use std::fs;
use std::io;
use std::path::Path;
use std::path::PathBuf;

Expand Down Expand Up @@ -262,3 +264,33 @@ impl DotslashTestEnv {
.with_assert(assert)
}
}

impl Drop for DotslashTestEnv {
fn drop(&mut self) {
// Make it possible to delete the temp cache.
let _ = make_tree_entries_writable(&self.tempdir_path);
}
}

fn make_tree_entries_writable(folder: &Path) -> io::Result<()> {
for entry in fs::read_dir(folder)? {
let path = entry?.path();
let metadata = fs::symlink_metadata(&path)?;

if metadata.is_symlink() {
continue;
}
if metadata.is_dir() {
make_tree_entries_writable(&path)?;
}

let mut perms = metadata.permissions();
if perms.readonly() {
#[expect(clippy::permissions_set_readonly_false)]
perms.set_readonly(false);
fs::set_permissions(path, perms)?;
}
}

Ok(())
}

0 comments on commit a25a5ce

Please sign in to comment.