{"record":{"id":"991123871323d970","repo":"unslothai/unsloth","slug":"studio-does-not-have-permission-to-write-to-this-f","errorCode":null,"errorMessage":"Studio does not have permission to write to this folder.","messagePattern":"Studio does not have permission to write to this folder\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"studio/backend/utils/hf_cache_settings.py","lineNumber":282,"sourceCode":"        raise ValueError(\"System folders cannot be used for model downloads.\")\n    if contains_sensitive_path_component is not None and contains_sensitive_path_component(\n        str(resolved)\n    ):\n        raise ValueError(\"Credential or config folders cannot be used for model downloads.\")\n\n    parent = resolved.parent\n    if not parent.exists() or not parent.is_dir():\n        raise ValueError(\"The parent folder does not exist.\")\n    try:\n        resolved.mkdir(exist_ok = True)\n        if not resolved.is_dir():\n            raise ValueError(\"The selected cache location is not a folder.\")\n        for child in (resolved / \"hub\", resolved / \"xet\"):\n            child.mkdir(exist_ok = True)\n            with tempfile.NamedTemporaryFile(prefix = \".unsloth-write-test-\", dir = child):\n                pass\n    except PermissionError as exc:\n        raise ValueError(\"Studio does not have permission to write to this folder.\") from exc\n    except OSError as exc:\n        raise ValueError(f\"Studio cannot use this cache folder: {exc}\") from exc\n    return resolved\n\n\ndef _stored_history() -> list[Path]:\n    try:\n        from storage.studio_db import get_app_setting\n        raw = get_app_setting(CACHE_HISTORY_SETTING_KEY, [])\n    except Exception:\n        raw = []\n    if not isinstance(raw, list):\n        return []\n    out: list[Path] = []\n    seen: set[str] = set()\n    for value in raw:\n        if not isinstance(value, str) or not value.strip():\n            continue","sourceCodeStart":264,"sourceCodeEnd":300,"githubUrl":"https://github.com/unslothai/unsloth/blob/203007d19051dcd2ae33876786d117c99f6b0368/studio/backend/utils/hf_cache_settings.py#L264-L300","documentation":"Raised when the mkdir/write-probe block (mkdir of the cache dir, mkdir of hub/ and xet/ subfolders, and a NamedTemporaryFile write test inside each) raises PermissionError. It converts the raw OS error into a message the user can act on: the process (Studio backend) lacks write permission on the chosen location.","triggerScenarios":"set_hf_cache_home() pointing at a directory owned by another user or root with no write bit for the backend's user; macOS App Sandbox / full-disk-access denial; a read-only mount (exFAT/NTFS mounts, read-only Docker volumes); SELinux/AppArmor denying writes despite mode bits looking fine.","commonSituations":"Picking /opt or /srv (root-owned) without sudo; a second drive formatted NTFS mounted read-only on Linux; running the backend as a different user than the one that owns the external drive; corporate endpoint protection blocking writes.","solutions":["chown the folder to the backend user or chmod it writable: chown -R $(whoami) /data/hf-cache","Relocate to a user-writable path such as ~/hf-cache","Remount read-only volumes read-write (e.g. fix ntfs mount options, or the Docker volume perms)","On macOS, grant the terminal/app Full Disk Access or pick a location outside protected folders"],"exampleFix":"# before\nset_hf_cache_home('/opt/hf-cache')  # PermissionError -> ValueError\n\n# after\nsudo chown -R $USER /opt/hf-cache   # or use a home-dir path\nset_hf_cache_home('/opt/hf-cache')  # ok","handlingStrategy":"try-catch","validationCode":"import os, tempfile\nfrom pathlib import Path\n\ndef writable_probe(raw: str) -> bool:\n    p = Path(raw).expanduser().resolve(strict=False)\n    try:\n        p.mkdir(parents=True, exist_ok=True)\n        with tempfile.NamedTemporaryFile(dir=p):\n            pass\n        return True\n    except (PermissionError, OSError):\n        return False","typeGuard":null,"tryCatchPattern":"try:\n    set_hf_cache_home(path)\nexcept ValueError as exc:\n    if 'permission' in str(exc).lower():\n        prompt_fix_permissions(path)\n    else:\n        raise","preventionTips":["Run the backend as the user who owns the cache volume","Check mount options (ro flags) before selecting network/external drives"],"tags":["huggingface","cache","permissions","filesystem","validation"],"backgroundTag":null,"analyzedSha":"203007d19051dcd2ae33876786d117c99f6b0368","analyzedAt":"2026-08-15T02:48:39.846Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}