rust-lang/rust · error · Exception

Temp directory is not clean (in {tmp_dir})

Error message

Temp directory is not clean (in {tmp_dir})

What it means

Raised by TestEnvironment.start() immediately after creating the temp directory, if the directory is not empty (len(os.listdir()) != 0). The runner assumes a clean slate because it lays down a fixed structure (output/, packages/, repo, ffx isolate, etc.) and leftover files from a previous run would collide or confuse ffx.

Source

Thrown at src/ci/docker/scripts/fuchsia-test-runner.py:463

    def start(self):
        """Sets up the testing environment and prepares to run tests.

        Args:
            args: The command-line arguments to this command.

        During setup, this function will:
        - Locate necessary shared libraries
        - Create a new temp directory (this is where all temporary files are stored)
        - Start an emulator
        - Start an update server
        - Create a new package repo and register it with the emulator
        - Write test environment settings to a temporary file
        """

        # Initialize temp directory
        os.makedirs(self.tmp_dir(), exist_ok=True)
        if len(os.listdir(self.tmp_dir())) != 0:
            raise Exception(f"Temp directory is not clean (in {self.tmp_dir()})")
        self.setup_logging(log_to_file=True)
        os.mkdir(self.output_dir)

        ffx_path = self.tool_path("ffx")
        ffx_env = self.ffx_cmd_env()

        # Start ffx isolation
        self.env_logger.info("Starting ffx isolation...")
        self.start_ffx_isolation()

        # Stop any running emulators (there shouldn't be any)
        check_call_with_logging(
            [
                ffx_path,
                "emu",
                "stop",
                "--all",
            ],

View on GitHub (pinned to 7088e4b63a)

Solutions

  1. Run `fuchsia-test-runner.py stop` then `fuchsia-test-runner.py cleanup` to tear down the existing environment and remove temp files.
  2. Manually delete the contents of the reported tmp_dir (rm -rf the path in the error).
  3. Set TEST_TOOLCHAIN_TMP_DIR to a fresh, dedicated empty directory for this run.
  4. Ensure no other instance of the runner is using the same tmp_dir concurrently.

Example fix

// before
$ fuchsia-test-runner.py start ...
# Exception: Temp directory is not clean (in /path/to/tmp~)

// after
$ fuchsia-test-runner.py cleanup   # or: rm -rf /path/to/tmp~
$ fuchsia-test-runner.py start ...
Defensive patterns

Strategy: validation

Validate before calling

import os
from pathlib import Path

tmp_dir = Path(os.environ.get("TEST_TOOLCHAIN_TMP_DIR") or (Path(__file__).parent / "tmp~"))
tmp_dir.mkdir(parents=True, exist_ok=True)
if os.listdir(tmp_dir):
    raise SystemExit(
        f"tmp_dir {tmp_dir} is not empty; run `cleanup` or rm -rf it first."
    )
# safe to call start()
env.start()

Type guard

null

Try / catch

try:
    test_env.start()
except Exception as e:
    if "Temp directory is not clean" in str(e):
        logging.error("Run `fuchsia-test-runner.py cleanup` then retry.")
    raise

Prevention

When it happens

Trigger: Invoking the 'start' subcommand when the resolved tmp_dir (TEST_TOOLCHAIN_TMP_DIR env var, or {script_dir}/tmp~ by default at line 133) already contains files. Reached at line 462 right after os.makedirs(exist_ok=True).

Common situations: A previous 'start' crashed before 'stop'/'cleanup' ran; TEST_TOOLCHAIN_TMP_DIR points at a shared/non-dedicated directory; a stale tmp~ directory sits next to the script; concurrent invocations sharing the same tmp dir.

Related errors


AI-assisted analysis of rust-lang/rust@7088e4b63a (2026-08-10). Data as JSON: /api/errors/ccb45e7e75b46951. Report an issue: GitHub.