Skip to content

Commit 3592c9d

Browse files
author
root
committed
Merge remote-tracking branch 'origin/remove-tmp-files' into main
2 parents da01329 + 479e4d7 commit 3592c9d

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ jobs:
2828
# Setup Leiningen. Also supports setting up other commonly used tools.
2929
- name: Install clojure tools
3030
uses: DeLaGuardo/[email protected]
31-
with: lein: 2.9.1
31+
with:
32+
lein: 2.9.1
3233
# Enable cache so our actions run faster.
3334
- name: Cache clojure dependencies
3435
uses: actions/cache@v3

src/clj/metafacture_playground/process.clj

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
(ns metafacture-playground.process
22
(:require
33
[clojure.string :as clj-str]
4+
[clojure.java.io :as io]
45
[clojure.tools.logging :as log])
56
(:import
67
(java.io File)
@@ -20,17 +21,29 @@
2021
(log/trace "Content" content)
2122
file-path))))
2223

24+
(defn- remove-temp-files [temp-files]
25+
(doseq [temp-file temp-files]
26+
(try
27+
(let [file (io/file temp-file)]
28+
(when (.exists file)
29+
(io/delete-file file false)))
30+
(catch Exception e
31+
(log/warn "Could not delete temp file:" temp-file e)))))
2332

2433
(defn process [flux data transformation]
25-
(let [inputfile (content->tempfile-path data ".data")
26-
transformationFile (content->tempfile-path transformation ".fix")
34+
(let [input-file (content->tempfile-path data ".data")
35+
transformation-file (content->tempfile-path transformation ".fix")
2736
out-path (content->tempfile-path "" ".txt")
2837
output (str "|write(\"" out-path "\");")
29-
flux (-> (str "default inputFile = \"" inputfile "\";\n"
30-
"default transformationFile = \"" transformationFile "\";\n"
38+
flux (-> (str "default inputFile = \"" input-file "\";\n"
39+
"default transformationFile = \"" transformation-file "\";\n"
3140
flux)
3241
(clj-str/replace #"\|(\s*|\n*)write\(\".*\"\)(\s*|\n*);" output)
33-
(clj-str/replace #"\|(\s*|\n*)print(\s*|\n*);" output))]
34-
(Flux/main (into-array [(content->tempfile-path flux ".flux")]))
35-
(log/info "Executed flux file with Flux/main. Result in" out-path)
36-
(slurp out-path)))
42+
(clj-str/replace #"\|(\s*|\n*)print(\s*|\n*);" output))
43+
flux-file (content->tempfile-path flux ".flux")]
44+
(try
45+
(Flux/main (into-array [flux-file]))
46+
(log/info "Executed flux file with Flux/main. Result in" out-path)
47+
(slurp out-path)
48+
(finally
49+
(remove-temp-files [input-file transformation-file flux-file out-path])))))

0 commit comments

Comments
 (0)