use std::ffi::OsStr; use std::fs::{File, OpenOptions}; use std::os::windows::ffi::OsStrExt; use std::os::windows::fs::OpenOptionsExt; use std::os::windows::io::{AsRawHandle, FromRawHandle, RawHandle}; use std::path::Path; use std::{io, iter};
use windows_sys::Win32::Foundation::{HANDLE, INVALID_HANDLE_VALUE}; use windows_sys::Win32::Storage::FileSystem::{
MoveFileExW, ReOpenFile, SetFileAttributesW, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_TEMPORARY,
FILE_FLAG_DELETE_ON_CLOSE, FILE_GENERIC_READ, FILE_GENERIC_WRITE, FILE_SHARE_DELETE,
FILE_SHARE_READ, FILE_SHARE_WRITE, MOVEFILE_REPLACE_EXISTING,
};
pubfn persist(old_path: &Path, new_path: &Path, overwrite: bool) -> io::Result<()> { unsafe { let old_path_w = to_utf16(old_path); let new_path_w = to_utf16(new_path);
// Don't succeed if this fails. We don't want to claim to have successfully persisted a file // still marked as temporary because this file won't have the same consistency guarantees. if SetFileAttributesW(old_path_w.as_ptr(), FILE_ATTRIBUTE_NORMAL) == 0 { return Err(io::Error::last_os_error());
}
letmut flags = 0;
if overwrite {
flags |= MOVEFILE_REPLACE_EXISTING;
}
if MoveFileExW(old_path_w.as_ptr(), new_path_w.as_ptr(), flags) == 0 { let e = io::Error::last_os_error(); // If this fails, the temporary file is now un-hidden and no longer marked temporary // (slightly less efficient) but it will still work. let _ = SetFileAttributesW(old_path_w.as_ptr(), FILE_ATTRIBUTE_TEMPORARY);
Err(e)
} else {
Ok(())
}
}
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.14 Sekunden
(vorverarbeitet am 2026-06-23)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.