-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
extra::tempfile::TempDir
causes IoError during Drop
#10462
Comments
I initially thought this would work: pub struct TempDir {
priv path: Option<Path>
+ priv tmpdir: ~Path
}
...
pub fn new_in(tmpdir: &Path, suffix: &str) -> Option<TempDir> {
...
- Ok(()) => return Some(TempDir { path: Some(p) })
+ Ok(()) => return Some(TempDir { path: Some(p), tmpdir: tmpdir.clone() })
...
}
...
impl Drop for TempDir {
fn drop(&mut self) {
for path in self.path.iter() {
if path.exists() {
+ os::change_dir(tmpdir);
fs::rmdir_recursive(path);
}
}
} but I realized that |
It would seem to me that the most reasonable thing to do would to be just ignore the error in the destructor of |
I don't think unconditionally changing directories in the destructor is appropriate, but I'm not happy about silently leaving temporary directories lying around. The destructor could check whether the current working directory is a subdirectory of the one it's going to delete and only if so change directory to its parent directory, but then we're still transparently changing directories in a destructor, which I'm pretty sure is going to catch most people by surprise. I'd suggest we should just fail on all platforms in that case, but then we're failing in a destructor and callers pretty much need to do their own RAII for |
I started to think the real issue is that user does not easily recognize fn with_temp_dir<T>(base: &Path, suffix: &str, f: |temp_dir: &Path| -> T) -> T {
let prev_path = os::getcwd();
let temp_dir = TempDir::new_in(base, suffix);
os::change_dir(temp_dir.path());
let result = f(temp_dir.path());
os::change_dir(prev_path);
fs::rmdir_recursive(temp_dir);
result
} |
Rename {struct-update,fsu}-moves-and-copies, since win32 failed to run the test since UAC prevents any executable whose name contaning "update". (rust-lang#10452) Some tests related to rust-lang#9205 are expected to fail on gcc 4.8, so they are marked as `xfail-win32` instead of `xfail-fast`. Some tests using `extra::tempfile` fail on win32 due to rust-lang#10462. Mark them as `xfail-win32`.
cc #12628 |
Since opening the |
…s,xFrednet consider autoderef through user-defined `Deref` in `eager_or_lazy` Fixes rust-lang#10462 This PR handles autoderef in the `eager_or_lazy` util module and stops suggesting to change lazy to eager if autoderef in an expression goes through user defined `Deref` impls, e.g. ```rs struct S; impl Deref for S { type Target = (); fn deref(&self) -> &Self::Target { &() } } let _ = Some(()).as_ref().unwrap_or_else(|| &S); // autoderef `&S` -> `&()` ``` changelog: [`unnecessary_lazy_evaluations`]: don't suggest changing lazy evaluation to eager if autoderef goes through user-defined `Deref` r? `@xFrednet` (because of the earlier review in rust-lang#10864, might help for context here)
TempDir
hasDrop
implementation of callingrmdir
the dir, but it may fail (platform-dependent) if the taskchange_dir
ed.part of #10452:
run-pass/glob-std.rs
.The text was updated successfully, but these errors were encountered: