|
| 1 | +// Issue #66530: We would ICE if someone compiled with `-o /dev/null`, |
| 2 | +// because we would try to generate auxiliary files in `/dev/` (which |
| 3 | +// at least the OS X file system rejects). |
| 4 | +// |
| 5 | +// An attempt to `-Ztemps-dir` into a directory we cannot write into should |
| 6 | +// indeed be an error; but not an ICE. |
| 7 | +// |
| 8 | +// However, some folks run tests as root, which can write `/dev/` and end |
| 9 | +// up clobbering `/dev/null`. Instead we'll use an inaccessible path, which |
| 10 | +// also used to ICE, but even root can't magically write there. |
| 11 | +// |
| 12 | +// Note that `-Ztemps-dir` uses `create_dir_all` so it is not sufficient to |
| 13 | +// use a directory with non-existing parent like `/does-not-exist/output`. |
| 14 | +// See https://github.com/rust-lang/rust/issues/66530 |
| 15 | + |
| 16 | +//@ only-linux |
| 17 | +// Reason: set_mode is only available on Unix |
| 18 | + |
| 19 | +//@ ignore-arm |
| 20 | +// Reason: linker error on `armhf-gnu` |
| 21 | + |
| 22 | +use run_make_support::{fs_wrapper, rustc}; |
| 23 | + |
| 24 | +fn main() { |
| 25 | + // Create an inaccessible directory. |
| 26 | + fs_wrapper::create_dir("inaccessible"); |
| 27 | + let meta = fs_wrapper::metadata("inaccessible"); |
| 28 | + let mut perms = meta.permissions(); |
| 29 | + perms.set_mode(0o000); // Lock down the directory. |
| 30 | + fs_wrapper::set_permissions("inaccessible", perms); |
| 31 | + |
| 32 | + // Run rustc with `-Z temps-dir` set to a directory *inside* the inaccessible one, |
| 33 | + // so that it can't create `tmp`. |
| 34 | + rustc() |
| 35 | + .input("program.rs") |
| 36 | + .arg("-Ztemps-dir=inaccessible/tmp") |
| 37 | + .run_fail() |
| 38 | + .assert_stderr_contains( |
| 39 | + "failed to find or create the directory specified by `--temps-dir`", |
| 40 | + ); |
| 41 | + |
| 42 | + perms.set_mode(0o666); // Unlock the directory, so that compiletest can delete it. |
| 43 | + fs_wrapper::set_permissions("inaccessible", perms); |
| 44 | +} |
0 commit comments