diff options
Diffstat (limited to 'library/std/src')
| -rw-r--r-- | library/std/src/env.rs | 4 | ||||
| -rw-r--r-- | library/std/src/fs/tests.rs | 4 | ||||
| -rw-r--r-- | library/std/src/sys/pal/windows/fs.rs | 36 |
3 files changed, 18 insertions, 26 deletions
diff --git a/library/std/src/env.rs b/library/std/src/env.rs index adbd6889624..4a071b4e1fa 100644 --- a/library/std/src/env.rs +++ b/library/std/src/env.rs @@ -668,7 +668,9 @@ pub fn home_dir() -> Option<PathBuf> { /// On Unix, returns the value of the `TMPDIR` environment variable if it is /// set, otherwise the value is OS-specific: /// - On Android, there is no global temporary folder (it is usually allocated -/// per-app), it returns `/data/local/tmp`. +/// per-app), it will return the application's cache dir if the program runs +/// in application's namespace and system version is Android 13 (or above), or +/// `/data/local/tmp` otherwise. /// - On Darwin-based OSes (macOS, iOS, etc) it returns the directory provided /// by `confstr(_CS_DARWIN_USER_TEMP_DIR, ...)`, as recommended by [Apple's /// security guidelines][appledoc]. diff --git a/library/std/src/fs/tests.rs b/library/std/src/fs/tests.rs index c7833c7dc71..38dcd816d26 100644 --- a/library/std/src/fs/tests.rs +++ b/library/std/src/fs/tests.rs @@ -1962,6 +1962,10 @@ fn test_rename_directory_to_non_empty_directory() { #[test] fn test_rename_symlink() { let tmpdir = tmpdir(); + if !got_symlink_permission(&tmpdir) { + return; + }; + let original = tmpdir.join("original"); let dest = tmpdir.join("dest"); let not_exist = Path::new("does not exist"); diff --git a/library/std/src/sys/pal/windows/fs.rs b/library/std/src/sys/pal/windows/fs.rs index 0ddce30cf8e..dce5a429cb0 100644 --- a/library/std/src/sys/pal/windows/fs.rs +++ b/library/std/src/sys/pal/windows/fs.rs @@ -1,4 +1,4 @@ -use super::api::{self, WinError}; +use super::api::{self, WinError, set_file_information_by_handle}; use super::{IoResult, to_u16s}; use crate::alloc::{alloc, handle_alloc_error}; use crate::borrow::Cow; @@ -319,31 +319,17 @@ impl File { && creation == c::OPEN_ALWAYS && api::get_last_error() == WinError::ALREADY_EXISTS { - unsafe { - // This first tries `FileAllocationInfo` but falls back to - // `FileEndOfFileInfo` in order to support WINE. - // If WINE gains support for FileAllocationInfo, we should - // remove the fallback. - let alloc = c::FILE_ALLOCATION_INFO { AllocationSize: 0 }; - let result = c::SetFileInformationByHandle( - handle.as_raw_handle(), - c::FileAllocationInfo, - (&raw const alloc).cast::<c_void>(), - mem::size_of::<c::FILE_ALLOCATION_INFO>() as u32, - ); - if result == 0 { + // This first tries `FileAllocationInfo` but falls back to + // `FileEndOfFileInfo` in order to support WINE. + // If WINE gains support for FileAllocationInfo, we should + // remove the fallback. + let alloc = c::FILE_ALLOCATION_INFO { AllocationSize: 0 }; + set_file_information_by_handle(handle.as_raw_handle(), &alloc) + .or_else(|_| { let eof = c::FILE_END_OF_FILE_INFO { EndOfFile: 0 }; - let result = c::SetFileInformationByHandle( - handle.as_raw_handle(), - c::FileEndOfFileInfo, - (&raw const eof).cast::<c_void>(), - mem::size_of::<c::FILE_END_OF_FILE_INFO>() as u32, - ); - if result == 0 { - return Err(io::Error::last_os_error()); - } - } - } + set_file_information_by_handle(handle.as_raw_handle(), &eof) + }) + .io_result()?; } Ok(File { handle: Handle::from_inner(handle) }) } else { |
