Skip to content

Use user-specific temp directories to prevent permission conflicts (fixes #217)#245

Open
glenneth1 wants to merge 1 commit into
edicl:masterfrom
glenneth1:fix/user-specific-temp-directories
Open

Use user-specific temp directories to prevent permission conflicts (fixes #217)#245
glenneth1 wants to merge 1 commit into
edicl:masterfrom
glenneth1:fix/user-specific-temp-directories

Conversation

@glenneth1

@glenneth1 glenneth1 commented Feb 7, 2026

Copy link
Copy Markdown
Contributor

Summary

Makes temporary directories user-specific to prevent permission conflicts when multiple users run Hunchentoot tests on the same machine.

Fixes #217

Problem

When user A runs tests, /tmp/hunchentoot/ is created and owned by user A. When user B subsequently runs tests, they get permission errors trying to write to the same directory.

Change

Temp directories now include the username in the path:

;; Before
/tmp/hunchentoot/

;; After
/tmp/hunchentoot-glenn/

Uses portable UIOP:GETENV to read USER/USERNAME environment variables, with an SBCL-specific sb-posix:getuid fallback.

  • specials.lisp: Added user-tmp-directory function, used for *tmp-directory*
  • test/test-handlers.lisp: Added user-tmp-test-directory function, used for *tmp-test-directory*

Testing

All existing tests pass on SBCL/Linux.

@stassats

stassats commented Feb 7, 2026

Copy link
Copy Markdown
Member

It would be better to have atomically created randomly named temporary directories.
cl-fad seems to only have CL-FAD:OPEN-TEMPORARY, maybe it should have something for directories too.

…conflicts (fixes edicl#217)

When multiple users run tests on the same machine, the shared
/tmp/hunchentoot/ directory causes permission errors because it is
owned by the first user who created it.

This change creates unique temporary directories with random names
using POSIX mkdtemp for atomic creation (e.g. /tmp/hunchentoot-sZYYDd/
instead of /tmp/hunchentoot/).

- specials.lisp: Add make-tmp-directory function using sb-posix:mkdtemp
  on SBCL, with portable fallback for other implementations
- test/test-handlers.lisp: Derive *tmp-test-directory* from *tmp-directory*
@glenneth1 glenneth1 force-pushed the fix/user-specific-temp-directories branch from 2bea217 to 79f13a8 Compare February 8, 2026 02:56
@glenneth1

Copy link
Copy Markdown
Contributor Author

Thanks @stassats, great suggestion. I've updated the PR to use atomically created, randomly named temporary directories.

What changed

Instead of a predictable user-specific path, *tmp-directory* is now set via a new make-tmp-directory function that creates a unique directory at load time:

SBCL (POSIX): Uses sb-posix:mkdtemp with the template /tmp/hunchentoot-XXXXXX, which atomically creates a directory with a random suffix — e.g. /tmp/hunchentoot-sZYYDd/.

CCL (POSIX): Calls mkdtemp via FFI.

Portable fallback (other implementations / Windows): Generates a random base-36 name, checks it doesn't exist, and creates it. Retries up to 100 times.

specials.lisp

(defun make-tmp-directory ()
  "Creates and returns a unique temporary directory for Hunchentoot.
On POSIX systems, uses mkdtemp for atomic creation.  On Windows,
generates a random name and creates the directory."
  #+(and :sbcl (not (or :win32 :mswindows)))
  (let ((template (format nil "/tmp/hunchentoot-XXXXXX")))
    (let ((path (sb-posix:mkdtemp template)))
      (format nil "~A/" path)))
  ...)

(defvar *tmp-directory* (make-tmp-directory)
  "Directory for temporary files created by MAKE-TMP-FILE-NAME.")

test/test-handlers.lisp

The test temp directory is now simply derived from *tmp-directory*, which is already unique per instance:

(defvar *tmp-test-directory*
    (pathname (format nil "~Atest/" *tmp-directory*)))

I agree that cl-fad having a make-temporary-directory would be the ideal long-term solution. This approach should work well in the meantime.

All existing tests pass on SBCL/Linux.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

running tests with different users causes failing tests

2 participants