aboutsummaryrefslogtreecommitdiff
path: root/crates/xa65/src/main.rs
diff options
context:
space:
mode:
authorMiquel Sabaté Solà <mssola@mssola.com>2025-12-15 21:58:16 +0100
committerMiquel Sabaté Solà <mssola@mssola.com>2025-12-15 21:58:16 +0100
commitb7645c842f6c3fd718debe8de3e32ae346b17567 (patch)
tree17dbf7ec019e9a46a62da1287e38550aa1023a76 /crates/xa65/src/main.rs
parent23bd15c063e40872f065d6b90c6d057e6f1756aa (diff)
downloadtools.nes-b7645c842f6c3fd718debe8de3e32ae346b17567.tar.gz
tools.nes-b7645c842f6c3fd718debe8de3e32ae346b17567.zip
xa65: use the current timestamp for the tmp directory
The easy "let's count how many directories there are in /tmp" trick was prone to errors. Hence, let's make things (hopefully) easier by just appending the current timestamp in milliseconds to the directory name. Fixes: 4961b715328d ("xa65: better ensure the name of the tmp directory") Signed-off-by: Miquel Sabaté Solà <mssola@mssola.com>
Diffstat (limited to 'crates/xa65/src/main.rs')
-rw-r--r--crates/xa65/src/main.rs10
1 files changed, 8 insertions, 2 deletions
diff --git a/crates/xa65/src/main.rs b/crates/xa65/src/main.rs
index 59bdc7d..fb1577c 100644
--- a/crates/xa65/src/main.rs
+++ b/crates/xa65/src/main.rs
@@ -2,6 +2,7 @@ use std::fs::File;
use std::io::prelude::*;
use std::path::{Path, PathBuf};
use std::process::Command;
+use std::time::{SystemTime, UNIX_EPOCH};
/// Version for this program.
const VERSION: &str = "0.1.0";
@@ -168,8 +169,13 @@ fn get_binaries(nasm_name: String) -> Result<(PathBuf, PathBuf), String> {
// Returns the path to the temporary directory that can be used for the run.
fn temporary_dir() -> PathBuf {
let tmp = &std::env::temp_dir();
- let paths = std::fs::read_dir(tmp).unwrap();
- let name = format!("xa65-{}", paths.count() + 1);
+
+ let start = SystemTime::now();
+ let epoch = start
+ .duration_since(UNIX_EPOCH)
+ .expect("xa65 (error): could not get current time.");
+
+ let name = format!("xa65-{}", epoch.as_millis());
tmp.join(name)
}