Skip to content

Commit c1a4e75

Browse files
committed
Auto clean up and use temp folder
1 parent 3f9a8f5 commit c1a4e75

File tree

6 files changed

+98
-36
lines changed

6 files changed

+98
-36
lines changed

.github/workflows/release.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: Release
22
on:
33
push:
44
tags:
5-
- 'v*'
5+
- 'v*.*.*'
66

77
jobs:
88
release:

src-tauri/Cargo.lock

+84-29
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src-tauri/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ reqwest = "0.11.20"
2323
zip-extract = "0.1.2"
2424
uuid = { version = "1.4.1", features = ["v4", "fast-rng"] }
2525
csv = "1.3.0"
26+
tempfile = "3.10.1"
2627

2728
[features]
2829
# this feature is used for production builds or when `devPath` points to the filesystem and the built-in dev server is disabled.

src-tauri/src/aggregator.rs

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::io::Cursor;
22
use std::path::PathBuf;
33
use csv::ReaderBuilder;
44
use tokio::fs;
5+
use tokio::fs::remove_file;
56

67
pub struct Calculation {
78
pub protein: String,
@@ -25,6 +26,8 @@ pub async fn aggregate(spreadsheets: &Vec<(PathBuf, u64)>) -> Result<Vec<Calcula
2526
for spreadsheet in spreadsheets {
2627
let mut spreadsheet_calculations = parse_calculations(spreadsheet).await?;
2728
calculations.append(&mut spreadsheet_calculations);
29+
30+
remove_file(&spreadsheet.0).await?;
2831
}
2932

3033
Ok(calculations)

src-tauri/src/analyzer.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::path::{Path, PathBuf};
2+
use tokio::fs::remove_file;
23
use tokio::process::Command;
34
use crate::serializer::Dataset;
45

@@ -27,6 +28,9 @@ async fn analyze_single(deps_dir: &Path, data_dir: &Path, dataset: &Dataset) ->
2728
.await
2829
.map_err(|err| format!("Command couldn't run: {err}"))?;
2930

31+
remove_file(&dataset.heavy_water).await.map_err(|err| format!("Couldn't delete heavy water file: {err}"))?;
32+
remove_file(&dataset.spreadsheet).await.map_err(|err| format!("Couldn't delete spreadsheet file: {err}"))?;
33+
3034
if output.status.success() {
3135
Ok((data_dir.join(format!("{input_file_name}.RateConst.csv")), dataset.samples_removed))
3236
} else {

src-tauri/src/commands.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::env::temp_dir;
12
use std::io::Cursor;
23
use std::path::Path;
34

@@ -48,11 +49,9 @@ pub async fn process_data(
4849
tolerance_multiplier: f64,
4950
input_file_path: String,
5051
) -> Result<(), String> {
51-
let data_dir = app_handle
52-
.path_resolver()
53-
.app_local_data_dir()
54-
.unwrap()
55-
.join("data");
52+
let temp_dir = tempfile::tempdir().map_err(|e| e.to_string())?;
53+
let data_dir = temp_dir.path().join("data");
54+
dbg!(temp_dir.path());
5655
let dependencies_dir = app_handle
5756
.path_resolver()
5857
.app_local_data_dir()
@@ -96,6 +95,6 @@ pub async fn process_data(
9695
serialize_calculations(&file_path, &calculations).map_err(|e| e.to_string())?;
9796
}
9897

99-
98+
temp_dir.close().map_err(|e| e.to_string())?;
10099
Ok(())
101100
}

0 commit comments

Comments
 (0)