Skip to content

Commit

Permalink
Remove dependency on 'users' crate #10
Browse files Browse the repository at this point in the history
  • Loading branch information
sagiegurari committed May 24, 2022
1 parent ed773fc commit df8b141
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 21 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## CHANGELOG

### v0.3.1

* Remove dependency on 'users' crate #10

### v0.3.0 (2021-09-13)

* Support windows UNC paths
Expand Down
5 changes: 1 addition & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ include = [
[dependencies]
rand = { version = "^0.8", optional = true }

[target.'cfg(not(windows))'.dependencies]
users = { version = "^0.11", optional = true }

[target.'cfg(windows)'.dependencies]
dunce = "^1"

Expand All @@ -37,7 +34,7 @@ doc-comment = "^0.3"

[features]
default = []
temp-path = ["rand", "users"]
temp-path = ["rand"]

[badges.codecov]
branch = "master"
Expand Down
30 changes: 13 additions & 17 deletions src/path/temp_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,33 @@ use rand::{thread_rng, Rng};
use std::env;
use std::iter;

#[cfg(not(windows))]
use users::get_current_username;

#[cfg(windows)]
fn get_additional_temp_path() -> Option<String> {
None
}

#[cfg(not(windows))]
fn get_additional_temp_path() -> Option<String> {
let username = get_current_username();

match username {
Some(os_value) => match os_value.into_string() {
Ok(value) => Some(value),
Err(_) => None,
},
None => None,
}
let random_string = get_random_string();
let mut additional_path = env!("CARGO_PKG_NAME").to_string();
additional_path.push('_');
additional_path.push_str(&random_string);
Some(additional_path.to_string())
}

pub(crate) fn get(extension: &str) -> String {
let name = env!("CARGO_PKG_NAME");

fn get_random_string() -> String {
let mut rng = thread_rng();
let file_name: String = iter::repeat(())
iter::repeat(())
.map(|()| rng.sample(Alphanumeric))
.map(char::from)
.take(10)
.collect();
.collect()
}

pub(crate) fn get(extension: &str) -> String {
let name = env!("CARGO_PKG_NAME");

let file_name = get_random_string();
let mut file_path = env::temp_dir();

match get_additional_temp_path() {
Expand Down

0 comments on commit df8b141

Please sign in to comment.