Skip to content

Commit 372b621

Browse files
committed
Auto merge of rust-lang#136754 - Urgau:rollup-qlkhjqr, r=Urgau
Rollup of 5 pull requests Successful merges: - rust-lang#134679 (Windows: remove readonly files) - rust-lang#136213 (Allow Rust to use a number of libc filesystem calls) - rust-lang#136530 (Implement `x perf` directly in bootstrap) - rust-lang#136601 (Detect (non-raw) borrows of null ZST pointers in CheckNull) - rust-lang#136659 (Pick the max DWARF version when LTO'ing modules with different versions ) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 594556d + 9e2eb8d commit 372b621

File tree

6 files changed

+53
-7
lines changed

6 files changed

+53
-7
lines changed

Diff for: core/src/panicking.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ fn panic_null_pointer_dereference() -> ! {
302302
}
303303

304304
panic_nounwind_fmt(
305-
format_args!("null pointer dereference occured"),
305+
format_args!("null pointer dereference occurred"),
306306
/* force_no_backtrace */ false,
307307
)
308308
}

Diff for: std/src/fs.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2307,8 +2307,8 @@ impl AsInner<fs_imp::DirEntry> for DirEntry {
23072307
///
23082308
/// # Platform-specific behavior
23092309
///
2310-
/// This function currently corresponds to the `unlink` function on Unix
2311-
/// and the `DeleteFile` function on Windows.
2310+
/// This function currently corresponds to the `unlink` function on Unix.
2311+
/// On Windows, `DeleteFile` is used or `CreateFileW` and `SetInformationByHandle` for readonly files.
23122312
/// Note that, this [may change in the future][changes].
23132313
///
23142314
/// [changes]: io#platform-specific-behavior

Diff for: std/src/fs/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1384,7 +1384,7 @@ fn file_try_clone() {
13841384
}
13851385

13861386
#[test]
1387-
#[cfg(not(windows))]
1387+
#[cfg(not(target_vendor = "win7"))]
13881388
fn unlink_readonly() {
13891389
let tmpdir = tmpdir();
13901390
let path = tmpdir.join("file");

Diff for: std/src/sys/pal/unix/fs.rs

+17-1
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@ use libc::c_char;
99
#[cfg(any(
1010
all(target_os = "linux", not(target_env = "musl")),
1111
target_os = "android",
12+
target_os = "fuchsia",
1213
target_os = "hurd"
1314
))]
1415
use libc::dirfd;
16+
#[cfg(target_os = "fuchsia")]
17+
use libc::fstatat as fstatat64;
1518
#[cfg(any(all(target_os = "linux", not(target_env = "musl")), target_os = "hurd"))]
1619
use libc::fstatat64;
1720
#[cfg(any(
@@ -848,7 +851,6 @@ impl Drop for Dir {
848851
target_os = "vita",
849852
target_os = "hurd",
850853
target_os = "espidf",
851-
target_os = "fuchsia",
852854
target_os = "horizon",
853855
target_os = "vxworks",
854856
target_os = "rtems",
@@ -880,6 +882,7 @@ impl DirEntry {
880882
any(
881883
all(target_os = "linux", not(target_env = "musl")),
882884
target_os = "android",
885+
target_os = "fuchsia",
883886
target_os = "hurd"
884887
),
885888
not(miri) // no dirfd on Miri
@@ -908,6 +911,7 @@ impl DirEntry {
908911
not(any(
909912
all(target_os = "linux", not(target_env = "musl")),
910913
target_os = "android",
914+
target_os = "fuchsia",
911915
target_os = "hurd",
912916
)),
913917
miri
@@ -1211,6 +1215,7 @@ impl File {
12111215
}
12121216
#[cfg(any(
12131217
target_os = "freebsd",
1218+
target_os = "fuchsia",
12141219
target_os = "linux",
12151220
target_os = "android",
12161221
target_os = "netbsd",
@@ -1223,6 +1228,7 @@ impl File {
12231228
}
12241229
#[cfg(not(any(
12251230
target_os = "android",
1231+
target_os = "fuchsia",
12261232
target_os = "freebsd",
12271233
target_os = "linux",
12281234
target_os = "netbsd",
@@ -1238,6 +1244,7 @@ impl File {
12381244

12391245
#[cfg(any(
12401246
target_os = "freebsd",
1247+
target_os = "fuchsia",
12411248
target_os = "linux",
12421249
target_os = "netbsd",
12431250
target_vendor = "apple",
@@ -1249,6 +1256,7 @@ impl File {
12491256

12501257
#[cfg(not(any(
12511258
target_os = "freebsd",
1259+
target_os = "fuchsia",
12521260
target_os = "linux",
12531261
target_os = "netbsd",
12541262
target_vendor = "apple",
@@ -1259,6 +1267,7 @@ impl File {
12591267

12601268
#[cfg(any(
12611269
target_os = "freebsd",
1270+
target_os = "fuchsia",
12621271
target_os = "linux",
12631272
target_os = "netbsd",
12641273
target_vendor = "apple",
@@ -1270,6 +1279,7 @@ impl File {
12701279

12711280
#[cfg(not(any(
12721281
target_os = "freebsd",
1282+
target_os = "fuchsia",
12731283
target_os = "linux",
12741284
target_os = "netbsd",
12751285
target_vendor = "apple",
@@ -1280,6 +1290,7 @@ impl File {
12801290

12811291
#[cfg(any(
12821292
target_os = "freebsd",
1293+
target_os = "fuchsia",
12831294
target_os = "linux",
12841295
target_os = "netbsd",
12851296
target_vendor = "apple",
@@ -1297,6 +1308,7 @@ impl File {
12971308

12981309
#[cfg(not(any(
12991310
target_os = "freebsd",
1311+
target_os = "fuchsia",
13001312
target_os = "linux",
13011313
target_os = "netbsd",
13021314
target_vendor = "apple",
@@ -1307,6 +1319,7 @@ impl File {
13071319

13081320
#[cfg(any(
13091321
target_os = "freebsd",
1322+
target_os = "fuchsia",
13101323
target_os = "linux",
13111324
target_os = "netbsd",
13121325
target_vendor = "apple",
@@ -1324,6 +1337,7 @@ impl File {
13241337

13251338
#[cfg(not(any(
13261339
target_os = "freebsd",
1340+
target_os = "fuchsia",
13271341
target_os = "linux",
13281342
target_os = "netbsd",
13291343
target_vendor = "apple",
@@ -1334,6 +1348,7 @@ impl File {
13341348

13351349
#[cfg(any(
13361350
target_os = "freebsd",
1351+
target_os = "fuchsia",
13371352
target_os = "linux",
13381353
target_os = "netbsd",
13391354
target_vendor = "apple",
@@ -1345,6 +1360,7 @@ impl File {
13451360

13461361
#[cfg(not(any(
13471362
target_os = "freebsd",
1363+
target_os = "fuchsia",
13481364
target_os = "linux",
13491365
target_os = "netbsd",
13501366
target_vendor = "apple",

Diff for: std/src/sys/pal/windows/fs.rs

+24-2
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,10 @@ impl OpenOptions {
296296
impl File {
297297
pub fn open(path: &Path, opts: &OpenOptions) -> io::Result<File> {
298298
let path = maybe_verbatim(path)?;
299+
Self::open_native(&path, opts)
300+
}
301+
302+
fn open_native(path: &[u16], opts: &OpenOptions) -> io::Result<File> {
299303
let creation = opts.get_creation_mode()?;
300304
let handle = unsafe {
301305
c::CreateFileW(
@@ -1226,8 +1230,26 @@ pub fn readdir(p: &Path) -> io::Result<ReadDir> {
12261230

12271231
pub fn unlink(p: &Path) -> io::Result<()> {
12281232
let p_u16s = maybe_verbatim(p)?;
1229-
cvt(unsafe { c::DeleteFileW(p_u16s.as_ptr()) })?;
1230-
Ok(())
1233+
if unsafe { c::DeleteFileW(p_u16s.as_ptr()) } == 0 {
1234+
let err = api::get_last_error();
1235+
// if `DeleteFileW` fails with ERROR_ACCESS_DENIED then try to remove
1236+
// the file while ignoring the readonly attribute.
1237+
// This is accomplished by calling the `posix_delete` function on an open file handle.
1238+
if err == WinError::ACCESS_DENIED {
1239+
let mut opts = OpenOptions::new();
1240+
opts.access_mode(c::DELETE);
1241+
opts.custom_flags(c::FILE_FLAG_OPEN_REPARSE_POINT);
1242+
if let Ok(f) = File::open_native(&p_u16s, &opts) {
1243+
if f.posix_delete().is_ok() {
1244+
return Ok(());
1245+
}
1246+
}
1247+
}
1248+
// return the original error if any of the above fails.
1249+
Err(io::Error::from_raw_os_error(err.code as i32))
1250+
} else {
1251+
Ok(())
1252+
}
12311253
}
12321254

12331255
pub fn rename(old: &Path, new: &Path) -> io::Result<()> {

Diff for: std/tests/win_delete_self.rs

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#![cfg(windows)]
2+
3+
/// Attempting to delete a running binary should return an error on Windows.
4+
#[test]
5+
fn win_delete_self() {
6+
let path = std::env::current_exe().unwrap();
7+
assert!(std::fs::remove_file(path).is_err());
8+
}

0 commit comments

Comments
 (0)