|
1 | 1 | use std::{
|
2 | 2 | cell::{Cell, RefCell},
|
3 | 3 | env, fs,
|
4 |
| - sync::{Once, OnceLock}, |
| 4 | + sync::Once, |
5 | 5 | time::Duration,
|
6 | 6 | };
|
7 | 7 |
|
@@ -141,34 +141,15 @@ impl Project<'_> {
|
141 | 141 | /// file in the config dir after server is run, something where our naive approach comes short.
|
142 | 142 | /// Using a `prelock` allows us to force a lock when we know we need it.
|
143 | 143 | pub(crate) fn server_with_lock(self, config_lock: bool) -> Server {
|
144 |
| - static CONFIG_DIR_LOCK: OnceLock<(Utf8PathBuf, Mutex<()>)> = OnceLock::new(); |
| 144 | + static CONFIG_DIR_LOCK: Mutex<()> = Mutex::new(()); |
145 | 145 |
|
146 | 146 | let config_dir_guard = if config_lock {
|
147 | 147 | Some({
|
148 |
| - let (path, mutex) = CONFIG_DIR_LOCK.get_or_init(|| { |
149 |
| - let value = TestDir::new().keep().path().to_owned(); |
150 |
| - env::set_var("__TEST_RA_USER_CONFIG_DIR", &value); |
151 |
| - (value, Mutex::new(())) |
152 |
| - }); |
153 |
| - #[allow(dyn_drop)] |
154 |
| - (mutex.lock(), { |
155 |
| - Box::new({ |
156 |
| - struct Dropper(Utf8PathBuf); |
157 |
| - impl Drop for Dropper { |
158 |
| - fn drop(&mut self) { |
159 |
| - for entry in fs::read_dir(&self.0).unwrap() { |
160 |
| - let path = entry.unwrap().path(); |
161 |
| - if path.is_file() { |
162 |
| - fs::remove_file(path).unwrap(); |
163 |
| - } else if path.is_dir() { |
164 |
| - fs::remove_dir_all(path).unwrap(); |
165 |
| - } |
166 |
| - } |
167 |
| - } |
168 |
| - } |
169 |
| - Dropper(path.clone()) |
170 |
| - }) as Box<dyn Drop> |
171 |
| - }) |
| 148 | + let guard = CONFIG_DIR_LOCK.lock(); |
| 149 | + let test_dir = TestDir::new(); |
| 150 | + let value = test_dir.path().to_owned(); |
| 151 | + env::set_var("__TEST_RA_USER_CONFIG_DIR", &value); |
| 152 | + (guard, test_dir) |
172 | 153 | })
|
173 | 154 | } else {
|
174 | 155 | None
|
@@ -311,14 +292,12 @@ pub(crate) struct Server {
|
311 | 292 | client: Connection,
|
312 | 293 | /// XXX: remove the tempdir last
|
313 | 294 | dir: TestDir,
|
314 |
| - #[allow(dyn_drop)] |
315 |
| - _config_dir_guard: Option<(MutexGuard<'static, ()>, Box<dyn Drop>)>, |
| 295 | + _config_dir_guard: Option<(MutexGuard<'static, ()>, TestDir)>, |
316 | 296 | }
|
317 | 297 |
|
318 | 298 | impl Server {
|
319 |
| - #[allow(dyn_drop)] |
320 | 299 | fn new(
|
321 |
| - config_dir_guard: Option<(MutexGuard<'static, ()>, Box<dyn Drop>)>, |
| 300 | + config_dir_guard: Option<(MutexGuard<'static, ()>, TestDir)>, |
322 | 301 | dir: TestDir,
|
323 | 302 | config: Config,
|
324 | 303 | ) -> Server {
|
|
0 commit comments