Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 28 additions & 8 deletions src/clj/metafacture_playground/process.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
(ns metafacture-playground.process
(:require
[clojure.string :as clj-str]
[clojure.java.io :as io]
[clojure.tools.logging :as log])
(:import
(java.io File)
Expand All @@ -26,11 +27,30 @@
transformationFile (content->tempfile-path transformation ".fix")
out-path (content->tempfile-path "" ".txt")
output (str "|write(\"" out-path "\");")
flux (-> (str "default inputFile = \"" inputfile "\";\n"
"default transformationFile = \"" transformationFile "\";\n"
flux)
(clj-str/replace #"\|(\s*|\n*)write\(\".*\"\)(\s*|\n*);" output)
(clj-str/replace #"\|(\s*|\n*)print(\s*|\n*);" output))]
(Flux/main (into-array [(content->tempfile-path flux ".flux")]))
(log/info "Executed flux file with Flux/main. Result in" out-path)
(slurp out-path)))
flux-str (-> (str "default inputFile = \"" inputfile "\";\n"
"default transformationFile = \"" transformationFile "\";\n"
flux)
;; Ersetze vorhandene |write(...) oder |print durch unsere Ausgabeanweisung
(clj-str/replace #"\|(\s*|\n*)write\(\".*\"\)(\s*|\n*);" output)
(clj-str/replace #"\|(\s*|\n*)print(\s*|\n*);" output))
fluxfile (content->tempfile-path flux-str ".flux")
max-size-bytes (* 1024 1024 1024)] ;; 1 GB

(try
;; Führe das Flux-Programm aus
(Flux/main (into-array [fluxfile]))
(let [outfile (io/file out-path)]
(if (> (.length outfile) max-size-bytes)
(throw (ex-info "Output file exceeds maximum allowed size (1 GB)" {:file out-path}))
(do
(log/info "Executed flux file with Flux/main. Result in" out-path)
(slurp outfile))))
(finally
;; Aufräumen der temporären Dateien
(doseq [f [inputfile transformationFile fluxfile out-path]]
(try
(let [file (io/file f)]
(when (.exists file)
(io/delete-file file true)))
(catch Exception e
(log/warn "Could not delete temp file:" f e))))))))
Loading