                    :basic-auth [archive-web-user archive-web-password]})]
     (if (client/success? response)
       (let [dam-number (prod/dam-number production)
-            tar-file (io/file (fs/tmpdir) (str dam-number ".tar"))
-            tar-dir (io/file (fs/tmpdir) dam-number)]
+            ;; create the tmp dir in the structured-path as there is
+            ;; not enough space on the normal tmp dir path
+            tmp-dir (nio/resolve-sibling (path/structured-path production)
+                                         (str (:id production) "_repair"))
+            tar-file (io/file tmp-dir (str dam-number ".tar"))
+            tar-dir (io/file tmp-dir dam-number)]
         (transaction
          ;; create all dirs for this production
          (prod/create-dirs production)
          ;; copy tar to tmpdir
+         (nio/create-directory! tmp-dir)
          (with-open [input (:body response)
                      output (io/output-stream tar-file)]
            (io/copy input output))

(ns mdr2.repair
  "Functions to handle repairing of a production

  This mostly entails functionality to fetch a production from the archive."
  (:require [clojure.java.io :as io]
            [clojure.tools.logging :as log]
            [immutant.transactions :refer [transaction]]
            [immutant.transactions.jdbc :refer [factory]]
            [yesql.core :refer [defqueries]]
            [me.raynes.fs :as fs]
            [me.raynes.fs.compression :as compress]
            [org.tobereplaced.nio.file :as nio]
            [environ.core :refer [env]]
            [clj-http.client :as client]
            [mdr2.obi :as obi]
            [mdr2.production :as prod]
            [mdr2.production.path :as path]))

(def ^:private db {:factory factory :name "java:jboss/datasources/archive"})
(def ^:private archive-web-root (env :archive-web-root))

         (let [src-path (io/file tar-dir dam-number "produkt" dam-number)
               dest-path (path/structured-path production)]
           (doseq [f (filter #(.isFile %) (file-seq src-path))]
             (nio/move! f (io/file dest-path (nio/file-name f)))))
         ;; clear the temporary files
         (util/delete-directory! tmp-dir)
         ;; create the obi config file
         (obi/config-file production)
         ;; set the state
