Skip to content

Commit 50d4714

Browse files
committed
libstd/os: set tmp dir to /data/tmp on Android
Android has no /tmp partition, return /data/tmp instead. Cf. #8511.
1 parent 6178501 commit 50d4714

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/libstd/os.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,8 @@ pub fn homedir() -> Option<Path> {
584584
*
585585
* On Unix, returns the value of the 'TMPDIR' environment variable if it is
586586
* set and non-empty and '/tmp' otherwise.
587+
* On Android, there is no global temporary folder (it is usually allocated
588+
* per-app), hence returns '/data/tmp' which is commonly used.
587589
*
588590
* On Windows, returns the value of, in order, the 'TMP', 'TEMP',
589591
* 'USERPROFILE' environment variable if any are set and not the empty
@@ -606,7 +608,11 @@ pub fn tmpdir() -> Path {
606608

607609
#[cfg(unix)]
608610
fn lookup() -> Path {
609-
getenv_nonempty("TMPDIR").unwrap_or_default(Path("/tmp"))
611+
if cfg!(target_os = "android") {
612+
Path("/data/tmp")
613+
} else {
614+
getenv_nonempty("TMPDIR").unwrap_or_default(Path("/tmp"))
615+
}
610616
}
611617

612618
#[cfg(windows)]

0 commit comments

Comments
 (0)