{"record":{"id":"ccb45e7e75b46951","repo":"rust-lang/rust","slug":"temp-directory-is-not-clean-in-tmp-dir","errorCode":null,"errorMessage":"Temp directory is not clean (in {tmp_dir})","messagePattern":"Temp directory is not clean \\(in (.+?)\\)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/ci/docker/scripts/fuchsia-test-runner.py","lineNumber":463,"sourceCode":"    def start(self):\n        \"\"\"Sets up the testing environment and prepares to run tests.\n\n        Args:\n            args: The command-line arguments to this command.\n\n        During setup, this function will:\n        - Locate necessary shared libraries\n        - Create a new temp directory (this is where all temporary files are stored)\n        - Start an emulator\n        - Start an update server\n        - Create a new package repo and register it with the emulator\n        - Write test environment settings to a temporary file\n        \"\"\"\n\n        # Initialize temp directory\n        os.makedirs(self.tmp_dir(), exist_ok=True)\n        if len(os.listdir(self.tmp_dir())) != 0:\n            raise Exception(f\"Temp directory is not clean (in {self.tmp_dir()})\")\n        self.setup_logging(log_to_file=True)\n        os.mkdir(self.output_dir)\n\n        ffx_path = self.tool_path(\"ffx\")\n        ffx_env = self.ffx_cmd_env()\n\n        # Start ffx isolation\n        self.env_logger.info(\"Starting ffx isolation...\")\n        self.start_ffx_isolation()\n\n        # Stop any running emulators (there shouldn't be any)\n        check_call_with_logging(\n            [\n                ffx_path,\n                \"emu\",\n                \"stop\",\n                \"--all\",\n            ],","sourceCodeStart":445,"sourceCodeEnd":481,"githubUrl":"https://github.com/rust-lang/rust/blob/7088e4b63a9516ebfbfe2ab2d999cf01a528ac14/src/ci/docker/scripts/fuchsia-test-runner.py#L445-L481","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Run `fuchsia-test-runner.py stop` then `fuchsia-test-runner.py cleanup` to tear down the existing environment and remove temp files.","Manually delete the contents of the reported tmp_dir (rm -rf the path in the error).","Set TEST_TOOLCHAIN_TMP_DIR to a fresh, dedicated empty directory for this run.","Ensure no other instance of the runner is using the same tmp_dir concurrently."],"exampleFix":"// before\n$ fuchsia-test-runner.py start ...\n# Exception: Temp directory is not clean (in /path/to/tmp~)\n\n// after\n$ fuchsia-test-runner.py cleanup   # or: rm -rf /path/to/tmp~\n$ fuchsia-test-runner.py start ...","handlingStrategy":"validation","validationCode":"import os\nfrom pathlib import Path\n\ntmp_dir = Path(os.environ.get(\"TEST_TOOLCHAIN_TMP_DIR\") or (Path(__file__).parent / \"tmp~\"))\ntmp_dir.mkdir(parents=True, exist_ok=True)\nif os.listdir(tmp_dir):\n    raise SystemExit(\n        f\"tmp_dir {tmp_dir} is not empty; run `cleanup` or rm -rf it first.\"\n    )\n# safe to call start()\nenv.start()","typeGuard":"null","tryCatchPattern":"try:\n    test_env.start()\nexcept Exception as e:\n    if \"Temp directory is not clean\" in str(e):\n        logging.error(\"Run `fuchsia-test-runner.py cleanup` then retry.\")\n    raise","preventionTips":["Always pair a failed 'start' with 'stop'/'cleanup' before retrying.","Set TEST_TOOLCHAIN_TMP_DIR to a dedicated per-run directory in CI.","Never share a tmp_dir across concurrent runner invocations."],"tags":["fuchsia","temp-directory","state","filesystem"],"backgroundTag":null,"analyzedSha":"7088e4b63a9516ebfbfe2ab2d999cf01a528ac14","analyzedAt":"2026-08-10T14:17:03.603Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}