56bf59e7d4b8997901e4b7db87e94e7ed17998fd — Niklas Eklund 2 months ago 128a6af
Bug fix: Improve handlling of session directory

Create a detached--get-session-directory function to have the logic at
one place. A bug was present where the session directory creation was
not taking into account detached-local-session's value.
2 files changed, 21 insertions(+), 6 deletions(-)

M detached.el
M test/detached-test.el
M detached.el => detached.el +8 -6
@@ 572,8 572,7 @@ active session.  For sessions created with `detached-compile' or
                                    :time `(:start ,(time-to-seconds (current-time)) :end 0.0 :duration 0.0 :offset 0.0)
                                    :status '(unknown . 0)
                                    :size 0
                                    :directory (if detached-local-session detached-session-directory
                                                 (concat (file-remote-p default-directory) detached-session-directory))
                                    :directory (detached--get-session-directory)
                                    :env (detached--env command)
                                    :host (detached--host)
                                    :metadata (detached-metadata)

@@ 1056,10 1055,7 @@ Optionally make the path LOCAL to host."

(defun detached--create-session-directory ()
  "Create session directory if it doesn't exist."
  (let ((directory
          (file-remote-p default-directory)
  (let ((directory (detached--get-session-directory)))
    (unless (file-exists-p directory)
      (make-directory directory t))))

@@ 1071,6 1067,12 @@ Optionally make the path LOCAL to host."
                                 (expand-file-name default-directory))
    (abbreviate-file-name default-directory)))

(defun detached--get-session-directory ()
  "Return the session directory."
  (if detached-local-session
    (concat (file-remote-p default-directory) detached-session-directory)))

;;;;; Database

(defun detached--db-initialize ()

M test/detached-test.el => test/detached-test.el +13 -0
@@ 234,6 234,19 @@
    (should (not (detached-degraded-command-p "cd")))
    (should (detached-degraded-command-p "ls -la"))))

(ert-deftest detached-test-get-session-directory ()
  (let ((default-directory "/ssh:remotehost:/home/user/git")
        (detached-session-directory "/tmp/detached"))
    ;; Remote session directory
    (should (string= "/ssh:remotehost:/tmp/detached" (detached--get-session-directory)))
    (let ((detached-local-session t))
      ;; Enforced local session directory with `detached-local-session'
      (should (string= "/tmp/detached" (detached--get-session-directory)))))
  (let ((default-directory "/home/user/git")
        (detached-session-directory "/tmp/detached"))
    ;; Local session directory
    (should (string= "/tmp/detached" (detached--get-session-directory)))))

;;;;; String representations

(ert-deftest detached-test-duration-str ()