use crate::sys::{c, cvt};
use crate::sys_common::{AsInner, FromInner, IntoInner};
+use super::path::maybe_verbatim;
use super::to_u16s;
pub struct File {
impl File {
pub fn open(path: &Path, opts: &OpenOptions) -> io::Result<File> {
- let path = to_u16s(path)?;
+ let path = maybe_verbatim(path)?;
let handle = unsafe {
c::CreateFileW(
path.as_ptr(),
impl FromInner<Handle> for File {
fn from_inner(handle: Handle) -> File {
- File { handle: handle }
+ File { handle }
}
}
impl FileType {
fn new(attrs: c::DWORD, reparse_tag: c::DWORD) -> FileType {
- FileType { attributes: attrs, reparse_tag: reparse_tag }
+ FileType { attributes: attrs, reparse_tag }
}
pub fn is_dir(&self) -> bool {
!self.is_symlink() && self.is_directory()
}
pub fn mkdir(&self, p: &Path) -> io::Result<()> {
- let p = to_u16s(p)?;
+ let p = maybe_verbatim(p)?;
cvt(unsafe { c::CreateDirectoryW(p.as_ptr(), ptr::null_mut()) })?;
Ok(())
}
pub fn readdir(p: &Path) -> io::Result<ReadDir> {
let root = p.to_path_buf();
let star = p.join("*");
- let path = to_u16s(&star)?;
+ let path = maybe_verbatim(&star)?;
unsafe {
let mut wfd = mem::zeroed();
}
pub fn unlink(p: &Path) -> io::Result<()> {
- let p_u16s = to_u16s(p)?;
+ let p_u16s = maybe_verbatim(p)?;
cvt(unsafe { c::DeleteFileW(p_u16s.as_ptr()) })?;
Ok(())
}
pub fn rename(old: &Path, new: &Path) -> io::Result<()> {
- let old = to_u16s(old)?;
- let new = to_u16s(new)?;
+ let old = maybe_verbatim(old)?;
+ let new = maybe_verbatim(new)?;
cvt(unsafe { c::MoveFileExW(old.as_ptr(), new.as_ptr(), c::MOVEFILE_REPLACE_EXISTING) })?;
Ok(())
}
pub fn rmdir(p: &Path) -> io::Result<()> {
- let p = to_u16s(p)?;
+ let p = maybe_verbatim(p)?;
cvt(unsafe { c::RemoveDirectoryW(p.as_ptr()) })?;
Ok(())
}
pub fn symlink_inner(original: &Path, link: &Path, dir: bool) -> io::Result<()> {
let original = to_u16s(original)?;
- let link = to_u16s(link)?;
+ let link = maybe_verbatim(link)?;
let flags = if dir { c::SYMBOLIC_LINK_FLAG_DIRECTORY } else { 0 };
// Formerly, symlink creation required the SeCreateSymbolicLink privilege. For the Windows 10
// Creators Update, Microsoft loosened this to allow unprivileged symlink creation if the
#[cfg(not(target_vendor = "uwp"))]
pub fn link(original: &Path, link: &Path) -> io::Result<()> {
- let original = to_u16s(original)?;
- let link = to_u16s(link)?;
+ let original = maybe_verbatim(original)?;
+ let link = maybe_verbatim(link)?;
cvt(unsafe { c::CreateHardLinkW(link.as_ptr(), original.as_ptr(), ptr::null_mut()) })?;
Ok(())
}
}
pub fn set_perm(p: &Path, perm: FilePermissions) -> io::Result<()> {
- let p = to_u16s(p)?;
+ let p = maybe_verbatim(p)?;
unsafe {
cvt(c::SetFileAttributesW(p.as_ptr(), perm.attrs))?;
Ok(())
}
c::PROGRESS_CONTINUE
}
- let pfrom = to_u16s(from)?;
- let pto = to_u16s(to)?;
+ let pfrom = maybe_verbatim(from)?;
+ let pto = maybe_verbatim(to)?;
let mut size = 0i64;
cvt(unsafe {
c::CopyFileExW(