 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;;; Low-level API
 
+(defun straight--norm (string-or-symbol)
+  (if (symbolp string-or-symbol)
+      (symbol-name string-or-symbol)
+    string-or-symbol))
+
 (defun straight--dir (&rest segments)
   (apply 'concat user-emacs-directory
          (mapcar (lambda (segment)
-                   (concat segment "/"))
+                   (concat (straight--norm segment) "/"))
                  (cons "straight" segments))))
 
 (defun straight--file (&rest segments)

                    nil 'silent))))

(defun straight--validate-build-recipe (build-recipe)
  (unless (plist-get :name build-recipe)
    (error "build recipe is missing `:name': %S" build-recipe))
  (unless (plist-get :repo build-recipe)
    (error "build recipe is missing `:repo': %S" build-recipe)))

;;;###autoload
(defun straight-package-might-be-modified-p (build-recipe)
  (straight--validate-build-recipe build-recipe)
  (let* ((name (plist-get :name build-recipe))
         (mtime (gethash name straight--cache)))
    (or (not mtime)
        (with-temp-buffer

            (> (buffer-size) 0))))))

(defun straight--delete-package (build-recipe)
  (ignore-errors
    (delete-directory
     (straight--dir "build" (plist-get build-recipe :name))
     'recursive)))

(defun straight--symlink-package (build-recipe)
  ()
  (let ((name (plist-get build-recipe :name))
        (repo (plist-get build-recipe :repo))
        (files (or (plist-get build-recipe :files)
                   package-build-default-files-spec)))
    (make-directory (straight--dir "build" name) 'parents)
    (dolist (spec (package-build-expand-file-specs
                   (straight--dir "repos" repo)
                   files))
      (let ((repo-file (straight--file "repos" repo (car spec)))
            (build-file (straight--file "build" name (cdr spec))))
        (unless (file-exists-p repo-file)
          (error "file %S does not exist" repo-file))
        (make-symbolic-link repo-file build-file)))))

(defun straight--autoload-file (package-name)
  (format "%S-autoloads.el" package-name))

(defun straight--generate-package-autoloads (build-recipe)
  (let* ((name (plist-get build-recipe :name))
         (generated-autoload-file
          (straight--autoload-file name)))
    (update-directory-autoloads
     (straight--dir "build" name))))

(defun straight--byte-compile-package (build-recipe)
  (let ((name (plist-get build-recipe :name)))
    (byte-recompile-directory
     (straight--dir "build" name 0))))

(defun straight--update-build-mtime (build-recipe)
  (let ((name (plist-get build-recipe :name))
        (mtime (format-time-string "%FT%T%z")))
    (puthash name mtime straight--cache)))

