Skip to content

Commit e6687dc

Browse files
committed
Make open_temporary_file() fallible again
I was under the apparently mistaken impression that `FLOG!(error, ...)` triggered an abort when I committed 58a6eb6.
1 parent bb6b310 commit e6687dc

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/env_universal_common.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,11 @@ impl EnvUniversal {
492492
res_fd
493493
}
494494

495-
fn open_temporary_file(&mut self, directory: &wstr, out_path: &mut WString) -> OwnedFd {
495+
fn open_temporary_file(
496+
&mut self,
497+
directory: &wstr,
498+
out_path: &mut WString,
499+
) -> Result<OwnedFd, Errno> {
496500
// Create and open a temporary file for writing within the given directory. Try to create a
497501
// temporary file, up to 10 times. We don't use mkstemps because we want to open it CLO_EXEC.
498502
// This should almost always succeed on the first try.
@@ -518,13 +522,14 @@ impl EnvUniversal {
518522
e.to_string()
519523
)
520524
);
525+
return Err(e);
521526
}
522527
_ => continue,
523528
}
524529
};
525530

526531
*out_path = str2wcstring(result.1.as_bytes());
527-
result.0
532+
Ok(result.0)
528533
}
529534

530535
/// Writes our state to the fd. path is provided only for error reporting.
@@ -753,7 +758,9 @@ impl EnvUniversal {
753758

754759
// Open adjacent temporary file.
755760
let mut private_file_path = WString::new();
756-
let private_fd = self.open_temporary_file(directory, &mut private_file_path);
761+
let Ok(private_fd) = self.open_temporary_file(directory, &mut private_file_path) else {
762+
return false;
763+
};
757764
// unlink pfp upon failure. In case of success, it (already) won't exist.
758765
let delete_pfp = ScopeGuard::new(private_file_path, |path| {
759766
wunlink(path);

0 commit comments

Comments
 (0)