Skip to content
Snippets Groups Projects
Unverified Commit 631a618e authored by Cam Saul's avatar Cam Saul
Browse files

Copy newer versions of modules when launching

parent 4480b24b
No related branches found
No related tags found
No related merge requests found
......@@ -54,7 +54,7 @@
(when (io/resource "modules")
(let [plugins-path (plugins-dir)]
(files/with-open-path-to-resource [modules-path "modules"]
(files/copy-files-if-not-exists! modules-path plugins-path)))))
(files/copy-files! modules-path plugins-path)))))
;;; +----------------------------------------------------------------------------------------------------------------+
......
......@@ -7,14 +7,15 @@
*file-manipulation* functions for the sorts of operations the plugin system needs to perform."
(:require [clojure.java.io :as io]
[clojure.string :as str]
[clojure.tools.logging :as log]
[metabase.util :as u]
[metabase.util
[date :as du]
[i18n :refer [trs]]])
(:import java.io.FileNotFoundException
java.net.URL
[java.nio.file CopyOption Files FileSystem FileSystems LinkOption OpenOption Path]
java.nio.file.attribute.FileAttribute
[java.nio.file CopyOption Files FileSystem FileSystems LinkOption OpenOption Path StandardCopyOption]
[java.nio.file.attribute FileAttribute FileTime]
java.util.Collections))
;;; --------------------------------------------------- Path Utils ---------------------------------------------------
......@@ -69,20 +70,25 @@
;;; ------------------------------------------------- Copying Stuff --------------------------------------------------
(defn- copy! [^Path source, ^Path dest]
(du/profile (trs "Extract file {0} -> {1}" source dest)
(Files/copy source dest (u/varargs CopyOption))))
(defn- last-modified-time ^FileTime [^Path path]
(Files/getLastModifiedTime path (u/varargs LinkOption)))
(defn- copy-if-not-exists! [^Path source, ^Path dest]
(when-not (exists? dest)
(copy! source dest)))
(defn- copy-file! [^Path source, ^Path dest]
(when (or (not (exists? dest))
(pos? (.compareTo (last-modified-time source) (last-modified-time dest))))
(du/profile (trs "Extract file {0} -> {1}" source dest)
(Files/copy source dest (u/varargs CopyOption [StandardCopyOption/REPLACE_EXISTING])))))
(defn copy-files-if-not-exists!
"Copy all files in `source-dir` to `dest-dir`; skip files if a file of the same name already exists in `dest-dir`."
(defn copy-files!
"Copy all files in `source-dir` to `dest-dir`. Overwrites existing files if last modified date is older than that of
the source file."
[^Path source-dir, ^Path dest-dir]
(doseq [^Path source (files-seq source-dir)
:let [target (append-to-path dest-dir (str (.getFileName source)))]]
(copy-if-not-exists! source target)))
(try
(copy-file! source target)
(catch Throwable e
(log/error e (trs "Failed to copy file"))))))
;;; ------------------------------------------ Opening filesystems for URLs ------------------------------------------
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment