Skip to content

Commit b062abb

Browse files
committed
feat(utils): generate random dir name
1 parent 4966629 commit b062abb

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

src/utils/mod.rs

+16-9
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,7 @@ pub fn replicate_android_project_to_temp(build_runtime: AndroidBuildRuntime) ->
6060
.join("android")
6161
.join(build_runtime.to_string());
6262

63-
let timestamp = std::time::SystemTime::now()
64-
.duration_since(UNIX_EPOCH)
65-
.expect("Error to get current timestamp")
66-
.as_millis()
67-
.to_string();
68-
69-
let random: u32 = rand::thread_rng().gen();
70-
71-
let dir_name = format!("{}_{}_{}", "test", timestamp, random.to_string());
63+
let dir_name = gen_random_dir_name("test");
7264

7365
let temp_dir = env::temp_dir().join(dir_name);
7466

@@ -84,6 +76,21 @@ pub fn replicate_android_project_to_temp(build_runtime: AndroidBuildRuntime) ->
8476
android_project_temp_dir
8577
}
8678

79+
pub fn gen_random_dir_name(prefix: &str) -> String {
80+
81+
let timestamp = std::time::SystemTime::now()
82+
.duration_since(UNIX_EPOCH)
83+
.expect("Error to get current timestamp")
84+
.as_millis()
85+
.to_string();
86+
87+
let random: u32 = rand::thread_rng().gen();
88+
89+
let dir_name = format!("{}_{}_{}", prefix, timestamp, random.to_string());
90+
91+
dir_name
92+
}
93+
8794
pub fn clean_temp(android_project_path: PathBuf) {
8895
fs::remove_dir_all(android_project_path.parent().unwrap())
8996
.expect("Error clean project dir from temp directory");

0 commit comments

Comments
 (0)