From 1716524422a23aaa3740391b73a36cbbffcf5c16 Mon Sep 17 00:00:00 2001
From: Maximilian Moser <maximilian.moser@tuwien.ac.at>
Date: Tue, 5 Mar 2024 10:11:46 +0100
Subject: [PATCH] Simplify setting the temp directory in formatscaper

* siegfried sometimes creates temporary files which can exhaust the
  disk space of the default temp directory
---
 formatscaper/formatscaper.py | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/formatscaper/formatscaper.py b/formatscaper/formatscaper.py
index 63aada1..7840737 100755
--- a/formatscaper/formatscaper.py
+++ b/formatscaper/formatscaper.py
@@ -90,6 +90,12 @@ parser.add_argument(
     action="store_true",
     help="disable the progress bar",
 )
+parser.add_argument(
+    "--tempdir",
+    "-t",
+    default=None,
+    help="set directory for storing temporary files",
+)
 args = parser.parse_args()
 
 
@@ -165,6 +171,17 @@ if (num_threads := args.parallel) <= 0:
 if os.environ.get("TERM") == "foot":
     os.environ["TERM"] = "xterm"
 
+# set the directory for storing temporary files
+if args.tempdir:
+    if os.path.exists(args.tempdir):
+        os.environ["TMPDIR"] = os.environ["TMP"] = args.tempdir
+    else:
+        print(
+            "WARN: ignoring tempdir as it does not exist:",
+            args.tempdir,
+            file=sys.stderr,
+        )
+
 
 # set up variables required in the collection of results
 all_results = []
-- 
GitLab