{"record":{"id":"222b0299aaded630","repo":"unslothai/unsloth","slug":"the-filesystem-root-cannot-be-registered-222b02","errorCode":null,"errorMessage":"The filesystem root cannot be registered","messagePattern":"The filesystem root cannot be registered","errorType":"validation","errorClass":"ValueError","httpStatus":400,"severity":"warning","filePath":"studio/backend/hub/storage/scan_folders.py","lineNumber":133,"sourceCode":"        conn.close()\n\n\ndef add_scan_folder_with_status(path: str) -> tuple[dict, bool]:\n    \"\"\"Add a readable scan folder and return its row plus whether it was inserted.\"\"\"\n    if not path or not path.strip():\n        raise ValueError(\"Path cannot be empty\")\n    normalized = os.path.realpath(os.path.expanduser(normalize_path(path.strip())))\n\n    if not os.path.exists(normalized):\n        raise ValueError(\"Path does not exist\")\n    if not os.path.isdir(normalized):\n        raise ValueError(\"Path must be a directory, not a file\")\n    if not os.access(normalized, os.R_OK | os.X_OK):\n        raise ValueError(\"Path is not readable\")\n    if is_local_filesystem_root(normalized):\n        # A local fs root (\"/\", \"C:\\\\\") would expose denied system dirs via browse;\n        # a UNC share root (\\\\server\\share) has none under it and stays registerable.\n        raise ValueError(\"The filesystem root cannot be registered\")\n    if _contains_sensitive_path_component(normalized):\n        raise ValueError(\"Credential or configuration directories are not allowed\")\n\n    is_win = platform.system() == \"Windows\"\n    check = os.path.normcase(normalized) if is_win else normalized\n    for prefix in _denied_path_prefixes():\n        if check == prefix or check.startswith(prefix + os.sep):\n            if prefix == \"/run\" and is_linux_run_media_path(check):\n                continue\n            raise ValueError(f\"Path under {prefix} is not allowed\")\n\n    conn = get_connection()\n    try:\n        _ensure_schema(conn)\n        now = datetime.now(timezone.utc).isoformat()\n        if is_win:\n            existing = conn.execute(\n                \"SELECT id, path, created_at FROM scan_folders WHERE path = ? COLLATE NOCASE\",","sourceCodeStart":115,"sourceCodeEnd":151,"githubUrl":"https://github.com/unslothai/unsloth/blob/203007d19051dcd2ae33876786d117c99f6b0368/studio/backend/hub/storage/scan_folders.py#L115-L151","documentation":"Validation error from add_scan_folder_with_status: is_local_filesystem_root(normalized) is True — the submitted path is a local filesystem root ('/' on POSIX, 'C:\\' on Windows). Registering a root would let the folder browser enumerate the whole disk, including denied system directories, so it is refused. UNC share roots (\\\\server\\share) are deliberately exempt because they contain no system dirs.","triggerScenarios":"Registering '/', '/.', 'C:\\', 'D:\\', or any path that realpath collapses to a drive root.","commonSituations":"Users wanting 'scan everything'; a UI defaulting a path picker to the filesystem root; Windows users entering a drive letter without a subfolder.","solutions":["Register specific top-level folders instead, e.g. /data, /mnt/models, D:\\AI-models.","For a USB/external drive, register a folder on it rather than the drive root.","If whole-disk coverage is truly needed, register the handful of top-level directories individually (each still passes the denylist)."],"exampleFix":"# before\nadd_scan_folder('/')\n# after\nadd_scan_folder('/data/models')\nadd_scan_folder('/home/user/hf-cache')","handlingStrategy":"validation","validationCode":"import ntpath, posixpath\n\ndef is_fs_root(path: str) -> bool:\n    p = posixpath.normpath(path)\n    if p == \"/\":\n        return True\n    drive, tail = ntpath.splitdrive(p)\n    return bool(drive) and tail in (\"\", \"\\\\\", \"/\")\n\ndef registerable(path: str) -> bool:\n    return not is_fs_root(path)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never offer '/' or drive roots in folder pickers; start the picker at the user's home or /data.","Want broad coverage? Register specific top-level directories one by one."],"tags":["validation","scan-folders","security","path-policy"],"backgroundTag":null,"analyzedSha":"203007d19051dcd2ae33876786d117c99f6b0368","analyzedAt":"2026-08-15T02:48:39.846Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}