Back

join (clj)

(source)

function

(join coll) (join separator coll)
Joins strings together with given separator.

Examples

penpot/penpot
(ns app.storage.fs
  (:require
   [app.common.data.macros :as dm]
   [app.common.exceptions :as ex]
   [app.common.spec :as us]
   [app.common.uri :as u]
   [app.storage :as-alias sto]
   [app.storage.impl :as impl]
   [clojure.spec.alpha :as s]
   [cuerdas.core :as str]
   [datoteka.fs :as fs]
   [datoteka.io :as io]
   [integrant.core :as ig])
  (:import
   java.nio.file.Files
   java.nio.file.Path))

(defmethod impl/put-object :fs
  [backend {:keys [id] :as object} content]
  (us/assert! ::backend backend)
  (let [base (fs/path (::directory backend))
        path (fs/path (impl/id->path id))
        full (fs/normalize (fs/join base path))]

(defmethod impl/get-object-data :fs
  [backend {:keys [id] :as object}]
  (us/assert! ::backend backend)
  (let [^Path base (fs/path (::directory backend))
        ^Path path (fs/path (impl/id->path id))
        ^Path full (fs/normalize (fs/join base path))]
    (when-not (fs/exists? full)
      (ex/raise :type :internal
                :code :filesystem-object-does-not-exists
                :path (str full)))
    (io/input-stream full)))

(defmethod impl/del-object :fs
  [backend {:keys [id] :as object}]
  (us/assert! ::backend backend)
  (let [base (fs/path (::directory backend))
        path (fs/path (impl/id->path id))
        path (fs/join base path)]
    (Files/deleteIfExists ^Path path)))

(defmethod impl/del-objects-in-bulk :fs
  [backend ids]
  (us/assert! ::backend backend)
  (let [base (fs/path (::directory backend))]
    (doseq [id ids]
      (let [path (fs/path (impl/id->path id))
            path (fs/join base path)]
        (Files/deleteIfExists ^Path path)))))