     java.time.Instant))
 
 
-;; ## FileSystem Utilities
-
-(def ^:private meta-properties-file
-  "Name of the properties file holding store-level metadata."
-  "meta.properties")
-
-
-(defn- initialize-meta
-  "Initialize the store by inspecting the metadata file for the current layout
-  version. If the version is not recognized, an error is thrown, otherwise this
-  returns the metadata properties as a map. If the metadata file does not
-  exist, it is created with the current version."
+(def layout-version
+  "The current supported storage layout version."
+  "1")
+
+
+
+;; ## Metadata
+
+(defn- meta-file
+  "Construct the store-level metadata properties file from the store root."
+  ^File
+  [root]
+  (io/file root "meta.properties"))
+
+
+(defn- read-meta-properties
+  "Read the store's metadata file if it exists."
   [^File root]
-  (let [meta-file (io/file root meta-properties-file)
-        supported "1"]
-    (if (.exists meta-file)
-      ; Check for correct format/version.
-      (let [props (doto (java.util.Properties.)
-                    (.load (io/reader meta-file)))
-            version (.getProperty props "version")]
-        (when (not= version supported)
-          (throw (ex-info
-                   (str "Unknown storage layout version " (pr-str version)
-                        " does not match supported version "
-                        (pr-str supported))
-                   {:supported supported
-                    :meta props})))
-        {:version version})
-      ; No file yet, probably a new store.
-      (let [version supported
-            props (doto (java.util.Properties.)
-                    (.setProperty "version" version))]
-        (with-open [out (io/writer meta-file)]
-          (.store props out " blocks.store.file"))
-        {:version version}))))
-
-
-(defn- seek-marker
-  "Given a marker string, determine whether the file should be skipped, recursed
-  into with a substring, or listed in full. Returs nil if the file should be
-  skipped, otherwise a vector of the file and a marker to recurse with."
-  [marker ^File file]
-  (if (empty? marker)
-    [file nil]
-    (let [fname (.getName file)
-          len (min (count marker) (count fname))
-          cmp (compare (subs fname  0 len)
-                       (subs marker 0 len))]
-      (when-not (neg? cmp)
-        (if (zero? cmp)
-          [file (subs marker len)]
-          [file nil])))))
-
-
-(defn- find-files
-  "Walks a directory tree depth first, returning a sequence of files found in
-  lexical order. Intelligently skips directories based on the given marker."
-  [^File file marker]
-  (if (.isDirectory file)
-    (->> (.listFiles file)
-         (keep (partial seek-marker marker))
-         (sort-by first)
-         (keep (partial apply find-files))
-         (flatten))
-    (when (.isFile file)
-      [file])))
+  (let [props-file (meta-file root)]
+    (when (.exists props-file)
+      (into {}
+            (map (juxt (comp keyword key) val))
+            (doto (java.util.Properties.)
+              (.load (io/reader props-file)))))))
+
+
+(defn- write-meta-properties
+  "Write a metadata properties file and returns the data map."
+  [^File root]
+  (let [props-file (meta-file root)
+        props (doto (java.util.Properties.)
+                (.setProperty "version" layout-version))]
+    (.mkdirs root)
+    (with-open [out (io/writer props-file)]
+      (.store props out " blocks.store.file"))
+    {:version layout-version}))
+
+
+
+;; ## Landing Area
+
+(defn- landing-dir
+  "Construct the landing directory from the store root."
+  ^File
+  [root]
+  (io/file root "landing"))
+
+
+(defn- landing-file
+  "Create an empty temporary file to land block data into. Marks the resulting
+  file for automatic cleanup if it is not moved."
+  ^File
+  [^File root]
+  (let [tmp-dir (landing-dir root)]
+    (.mkdirs tmp-dir)
+    (doto (File/createTempFile "block" ".tmp" tmp-dir)
+      (.deleteOnExit))))
 
 
 (defn- rm-r

    (let [out (s/stream)]
      (d/future
        (try
          (loop [files (find-files root (:after opts))]
            (when-let [file (first files)]
              (if-let [id (file->id root file)]
                ; Check that the id is still before the marker, if set.

      (let [id (:id block)
            file (id->file root id)]
        (when-not (.exists file)
          (let [tmp (landing-file root)]
            (with-open [content (data/content-stream block nil nil)]
              (io/copy content tmp))
            (io/make-parents file)
            (.setWritable tmp false false)
            (.renameTo tmp file)))
        (file->block id file))))
