diff --git a/src/rustup-utils/src/remove_dir_all.rs b/src/rustup-utils/src/remove_dir_all.rs index 8333b6c23ef..352ae955e7f 100644 --- a/src/rustup-utils/src/remove_dir_all.rs +++ b/src/rustup-utils/src/remove_dir_all.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![allow(non_snake_case)] + use winapi::{ FileBasicInfo, FILE_BASIC_INFO, @@ -52,6 +54,8 @@ use winapi::{ SECURITY_SQOS_PRESENT, FSCTL_GET_REPARSE_POINT, BY_HANDLE_FILE_INFORMATION, + IO_REPARSE_TAG_SYMLINK, + IO_REPARSE_TAG_MOUNT_POINT, }; use kernel32::{ @@ -154,7 +158,7 @@ pub fn remove_dir_all(path: &Path) -> io::Result<()> { } -pub fn readdir(p: &Path) -> io::Result { +fn readdir(p: &Path) -> io::Result { let root = p.to_path_buf(); let star = p.join("*"); let path = try!(to_u16s(&star)); @@ -228,13 +232,13 @@ fn remove_item(path: &Path, ctx: &mut RmdirContext) -> io::Result<()> { macro_rules! compat_fn { ($module:ident: $( - pub fn $symbol:ident($($argname:ident: $argtype:ty),*) + fn $symbol:ident($($argname:ident: $argtype:ty),*) -> $rettype:ty { $($body:expr);* } )*) => ($( #[allow(unused_variables)] - pub unsafe fn $symbol($($argname: $argtype),*) -> $rettype { + unsafe fn $symbol($($argname: $argtype),*) -> $rettype { use std::sync::atomic::{AtomicUsize, Ordering}; use std::mem; use std::ffi::CString; @@ -242,7 +246,7 @@ macro_rules! compat_fn { lazy_static! { static ref PTR: AtomicUsize = AtomicUsize::new(0);} - pub fn lookup(module: &str, symbol: &str) -> Option { + fn lookup(module: &str, symbol: &str) -> Option { let mut module: Vec = module.encode_utf16().collect(); module.push(0); let symbol = CString::new(symbol).unwrap(); @@ -255,7 +259,7 @@ macro_rules! compat_fn { } } - pub fn store_func(ptr: &AtomicUsize, module: &str, symbol: &str, + fn store_func(ptr: &AtomicUsize, module: &str, symbol: &str, fallback: usize) -> usize { let value = lookup(module, symbol).unwrap_or(fallback); ptr.store(value, Ordering::SeqCst); @@ -281,16 +285,16 @@ macro_rules! compat_fn { compat_fn! { kernel32: - pub fn GetFinalPathNameByHandleW(_hFile: HANDLE, - _lpszFilePath: LPCWSTR, - _cchFilePath: DWORD, - _dwFlags: DWORD) -> DWORD { + fn GetFinalPathNameByHandleW(_hFile: HANDLE, + _lpszFilePath: LPCWSTR, + _cchFilePath: DWORD, + _dwFlags: DWORD) -> DWORD { SetLastError(ERROR_CALL_NOT_IMPLEMENTED as DWORD); 0 } - pub fn SetFileInformationByHandle(_hFile: HANDLE, - _FileInformationClass: FILE_INFO_BY_HANDLE_CLASS, - _lpFileInformation: LPVOID, - _dwBufferSize: DWORD) -> BOOL { + fn SetFileInformationByHandle(_hFile: HANDLE, + _FileInformationClass: FILE_INFO_BY_HANDLE_CLASS, + _lpFileInformation: LPVOID, + _dwBufferSize: DWORD) -> BOOL { SetLastError(ERROR_CALL_NOT_IMPLEMENTED as DWORD); 0 } } @@ -303,7 +307,7 @@ fn cvt(i: i32) -> io::Result { } } -pub fn to_u16s>(s: S) -> io::Result> { +fn to_u16s>(s: S) -> io::Result> { fn inner(s: &OsStr) -> io::Result> { let mut maybe_result: Vec = s.encode_wide().collect(); if maybe_result.iter().any(|&u| u == 0) { @@ -316,7 +320,7 @@ pub fn to_u16s>(s: S) -> io::Result> { inner(s.as_ref()) } -pub fn truncate_utf16_at_nul<'a>(v: &'a [u16]) -> &'a [u16] { +fn truncate_utf16_at_nul<'a>(v: &'a [u16]) -> &'a [u16] { match v.iter().position(|c| *c == 0) { // don't include the 0 Some(i) => &v[..i], @@ -371,16 +375,16 @@ fn fill_utf16_buf(mut f1: F1, f2: F2) -> io::Result } #[derive(Clone, PartialEq, Eq, Debug, Default)] -pub struct FilePermissions { readonly: bool } +struct FilePermissions { readonly: bool } impl FilePermissions { - pub fn new() -> FilePermissions { Default::default() } - pub fn readonly(&self) -> bool { self.readonly } - pub fn set_readonly(&mut self, readonly: bool) { self.readonly = readonly } + fn new() -> FilePermissions { Default::default() } + fn readonly(&self) -> bool { self.readonly } + fn set_readonly(&mut self, readonly: bool) { self.readonly = readonly } } #[derive(Clone)] -pub struct OpenOptions { +struct OpenOptions { // generic read: bool, write: bool, @@ -398,7 +402,7 @@ pub struct OpenOptions { } impl OpenOptions { - pub fn new() -> OpenOptions { + fn new() -> OpenOptions { OpenOptions { // generic read: false, @@ -416,8 +420,8 @@ impl OpenOptions { security_attributes: 0, } } - pub fn custom_flags(&mut self, flags: u32) { self.custom_flags = flags; } - pub fn access_mode(&mut self, access_mode: u32) { self.access_mode = Some(access_mode); } + fn custom_flags(&mut self, flags: u32) { self.custom_flags = flags; } + fn access_mode(&mut self, access_mode: u32) { self.access_mode = Some(access_mode); } fn get_access_mode(&self) -> io::Result { const ERROR_INVALID_PARAMETER: i32 = 87; @@ -467,10 +471,10 @@ impl OpenOptions { } } -pub struct File { handle: Handle } +struct File { handle: Handle } impl File { - pub fn open(path: &Path, opts: &OpenOptions) -> io::Result { + fn open(path: &Path, opts: &OpenOptions) -> io::Result { let path = try!(to_u16s(path)); let handle = unsafe { CreateFileW(path.as_ptr(), @@ -488,7 +492,7 @@ impl File { } } - pub fn file_attr(&self) -> io::Result { + fn file_attr(&self) -> io::Result { unsafe { let mut info: BY_HANDLE_FILE_INFORMATION = mem::zeroed(); try!(cvt(GetFileInformationByHandle(self.handle.raw(), @@ -511,7 +515,7 @@ impl File { } } - pub fn set_attributes(&self, attr: DWORD) -> io::Result<()> { + fn set_attributes(&self, attr: DWORD) -> io::Result<()> { let mut info = FILE_BASIC_INFO { CreationTime: 0, // do not change LastAccessTime: 0, // do not change @@ -529,7 +533,7 @@ impl File { Ok(()) } - pub fn rename(&self, new: &Path, replace: bool) -> io::Result<()> { + fn rename(&self, new: &Path, replace: bool) -> io::Result<()> { // &self must be opened with DELETE permission use std::iter; #[cfg(target_arch = "x86")] @@ -560,7 +564,7 @@ impl File { Ok(()) } } - pub fn set_perm(&self, perm: FilePermissions) -> io::Result<()> { + fn set_perm(&self, perm: FilePermissions) -> io::Result<()> { let attr = try!(self.file_attr()).attributes; if perm.readonly == (attr & FILE_ATTRIBUTE_READONLY != 0) { Ok(()) @@ -571,7 +575,7 @@ impl File { } } - pub fn handle(&self) -> &Handle { &self.handle } + fn handle(&self) -> &Handle { &self.handle } fn reparse_point<'a>(&self, space: &'a mut [u8; MAXIMUM_REPARSE_DATA_BUFFER_SIZE]) @@ -595,7 +599,7 @@ impl File { #[derive(Copy, Clone, PartialEq, Eq, Hash)] -pub enum FileType { +enum FileType { Dir, File, SymlinkFile, SymlinkDir, ReparsePoint, MountPoint, } @@ -616,8 +620,8 @@ impl FileType { } } - pub fn is_dir(&self) -> bool { *self == FileType::Dir } - pub fn is_symlink_dir(&self) -> bool { + fn is_dir(&self) -> bool { *self == FileType::Dir } + fn is_symlink_dir(&self) -> bool { *self == FileType::SymlinkDir || *self == FileType::MountPoint } } @@ -635,21 +639,21 @@ impl DirEntry { } } - pub fn path(&self) -> PathBuf { + fn path(&self) -> PathBuf { self.root.join(&self.file_name()) } - pub fn file_name(&self) -> OsString { + fn file_name(&self) -> OsString { let filename = truncate_utf16_at_nul(&self.data.cFileName); OsString::from_wide(filename) } - pub fn file_type(&self) -> io::Result { + fn file_type(&self) -> io::Result { Ok(FileType::new(self.data.dwFileAttributes, /* reparse_tag = */ self.data.dwReserved0)) } - pub fn metadata(&self) -> io::Result { + fn metadata(&self) -> io::Result { Ok(FileAttr { attributes: self.data.dwFileAttributes, creation_time: self.data.ftCreationTime, @@ -668,12 +672,12 @@ impl DirEntry { -pub struct DirEntry { +struct DirEntry { root: Arc, data: WIN32_FIND_DATAW, } -pub struct ReadDir { +struct ReadDir { handle: FindNextFileHandle, root: Arc, first: Option, @@ -707,7 +711,7 @@ impl Iterator for ReadDir { #[derive(Clone)] -pub struct FileAttr { +struct FileAttr { attributes: DWORD, creation_time: FILETIME, last_access_time: FILETIME, @@ -717,13 +721,13 @@ pub struct FileAttr { } impl FileAttr { - pub fn perm(&self) -> FilePermissions { + fn perm(&self) -> FilePermissions { FilePermissions { readonly: self.attributes & FILE_ATTRIBUTE_READONLY != 0 } } - pub fn file_type(&self) -> FileType { + fn file_type(&self) -> FileType { FileType::new(self.attributes, self.reparse_tag) } @@ -733,20 +737,20 @@ impl FileAttr { } #[repr(C)] -pub struct REPARSE_DATA_BUFFER { - pub ReparseTag: c_uint, - pub ReparseDataLength: c_ushort, - pub Reserved: c_ushort, - pub rest: (), +struct REPARSE_DATA_BUFFER { + ReparseTag: c_uint, + ReparseDataLength: c_ushort, + Reserved: c_ushort, + rest: (), } -pub const MAXIMUM_REPARSE_DATA_BUFFER_SIZE: usize = 16 * 1024; +const MAXIMUM_REPARSE_DATA_BUFFER_SIZE: usize = 16 * 1024; /// An owned container for `HANDLE` object, closing them on Drop. /// /// All methods are inherited through a `Deref` impl to `RawHandle` -pub struct Handle(RawHandle); +struct Handle(RawHandle); use std::ops::Deref; @@ -756,13 +760,13 @@ use std::ops::Deref; /// This does **not** drop the handle when it goes out of scope, use `Handle` /// instead for that. #[derive(Copy, Clone)] -pub struct RawHandle(HANDLE); +struct RawHandle(HANDLE); unsafe impl Send for RawHandle {} unsafe impl Sync for RawHandle {} impl Handle { - pub fn new(handle: HANDLE) -> Handle { + fn new(handle: HANDLE) -> Handle { Handle(RawHandle::new(handle)) } } @@ -779,11 +783,11 @@ impl Drop for Handle { } impl RawHandle { - pub fn new(handle: HANDLE) -> RawHandle { + fn new(handle: HANDLE) -> RawHandle { RawHandle(handle) } - pub fn raw(&self) -> HANDLE { self.0 } + fn raw(&self) -> HANDLE { self.0 } } struct FindNextFileHandle(HANDLE); @@ -810,7 +814,7 @@ fn move_item(file: &File, ctx: &mut RmdirContext) -> io::Result<()> { Ok(()) } -pub fn set_perm(path: &Path, perm: FilePermissions) -> io::Result<()> { +fn set_perm(path: &Path, perm: FilePermissions) -> io::Result<()> { let mut opts = OpenOptions::new(); opts.access_mode(FILE_READ_ATTRIBUTES | FILE_WRITE_ATTRIBUTES); opts.custom_flags(FILE_FLAG_BACKUP_SEMANTICS); @@ -818,4 +822,4 @@ pub fn set_perm(path: &Path, perm: FilePermissions) -> io::Result<()> { file.set_perm(perm) } -pub const VOLUME_NAME_DOS: DWORD = 0x0; +const VOLUME_NAME_DOS: DWORD = 0x0;