Skip to content

Commit

Permalink
Revert use of $TMPDIR
Browse files Browse the repository at this point in the history
Pertaining to #68.
  • Loading branch information
kotauskas committed Jul 21, 2024
1 parent 050ae2e commit 9f743d5
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "interprocess"
version = "2.2.0"
version = "2.2.1"
authors = ["Kotauskas <[email protected]>"]
edition = "2021"
rust-version = "1.75"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ platform to be demoted, although promotions quite obviously can happen as minor
- Interprocess is guaranteed to compile and succeed in running all tests – it would be a critical
bug for it not to
- CI, currently provided by GitHub Actions, runs on all of those platforms and displays an ugly red
badge if anything is wrong on any of those systems
badge if anything is wrong on any of those systems
- Certain `#[cfg]`-gated platform-specific features are supported with stable public APIs

##### Explicit support without CI
Expand Down
18 changes: 11 additions & 7 deletions src/os/unix/uds_local_socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,16 @@ fn get_run_user() -> io::Result<Option<OsString>> {
}
}

/// Gets the `TMPDIR` environment variable, or returns `/tmp` if it doesn't exist.
fn get_tmpdir() -> Cow<'static, OsStr> {
std::env::var_os("TMPDIR")
.map(Cow::Owned)
.unwrap_or(Cow::Borrowed(OsStr::new("/tmp")))
}
static TMPDIR: &str = {
#[cfg(target_os = "android")]
{
"/data/local/tmp"
}
#[cfg(not(target_os = "android"))]
{
"/tmp"
}
};

#[allow(clippy::indexing_slicing, clippy::arithmetic_side_effects)]
fn construct_and_prepare_pseudo_ns(
Expand All @@ -95,7 +99,7 @@ fn construct_and_prepare_pseudo_ns(
return Err(io::Error::new(io::ErrorKind::InvalidInput, TOOLONG));
}
let run_user = get_run_user()?;
let pfx = run_user.map(Cow::Owned).unwrap_or_else(get_tmpdir);
let pfx = run_user.map(Cow::Owned).unwrap_or(Cow::Borrowed(OsStr::new(TMPDIR)));
let pl = pfx.len();
let mut path = [0; SUN_LEN];
path[..pl].copy_from_slice(pfx.as_bytes());
Expand Down

0 comments on commit 9f743d5

Please sign in to comment.