         (finally
           (.close dos))))))
 
-
 (defn- write-edn-key
   "help function for -update-in"
   [serializer write-handlers read-handlers folder fn {:keys [key] :as key-meta} config]

    (let [fn     (str (uuid key))
          f      (io/file (str folder "/data/" fn))
          res-ch (chan)]
      (binary-read f res-ch folder fn key locked-cb)
      res-ch))

  (-bassoc [this key input]
    (let [file-name    (uuid key)


(defn new-fs-store
  "Filestore contains a Key and a Data Folder"
  [path  & {:keys [serializer read-handlers write-handlers config]
            :or   {serializer     (ser/fressian-serializer)
                   read-handlers  (atom {})
                   write-handlers (atom {})
                   config         {:fsync true}}}]
  (let [_               (check-and-create-folder path)
        key-path        (str path "/meta")
        data-path       (str path "/data")
        _               (check-and-create-folder key-path)
        _               (check-and-create-folder data-path)
        stale-binaries? (->> (io/file path)
                             .list
                             seq
                             (filter #(re-matches
                                       #"B\\_[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}"
                                       %))
                             empty?)
        stale-edn?      (->> (io/file path)
                             .list
                             seq
                             (filter #(re-matches
                                       #"[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}"
                                       %))
                             empty?)
        store           (map->FileSystemStore {:folder          path
                                               :serializer      serializer
                                               :read-handlers   read-handlers
                                               :write-handlers  write-handlers
                                               :stale-binaries? stale-binaries?
                                               :locks           (atom {})
                                               :config          config})]
    (if-not stale-edn?
      (do
        (go
          (<! (filestore-schema-update store))
          store))
      (go store))))




(comment
 
  (read-string "{:update-store {:version-12-to-14 true}}")

  (time (def store (<!! (new-fs-store "/tmp/konserve-fs-migration-test"))))

  store




  store
  (->> (io/file "/tmp/konserve-fs-migration-test")
       .list
       seq
       (filter #(re-matches
                 #"B\\_[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}"
                 %))
       empty?)


  (spit "/tmp/old-CCCP/config" "update-store :version [8.11 8.12]")

  (keyword (slurp "/tmp/old-CCCP/config"))

  (slurp "/tmp/old-CCCP/config")

  (<!! (-assoc-in store [":123"] 43))

