{"record":{"id":"012e3e6309503392","repo":"astrid-runtime/astrid","slug":"permissiondenied-012e3e","errorCode":"PermissionDenied","errorMessage":"legacy dedicated source is not owned by the current user: {}","messagePattern":"legacy dedicated source is not owned by the current user: (.+?)","errorType":"error_code","errorClass":"io::Error","httpStatus":null,"severity":"error","filePath":"crates/astrid-kernel/src/legacy_migration_barrier/legacy_tmp.rs","lineNumber":55,"sourceCode":"        Ok(metadata) => metadata,\n        Err(error) if error.kind() == io::ErrorKind::NotFound => return Ok(()),\n        Err(error) => return Err(error),\n    };\n    if metadata.file_type().is_symlink() || !metadata.is_dir() {\n        return Err(io::Error::new(\n            io::ErrorKind::InvalidData,\n            format!(\n                \"legacy dedicated source is not a regular directory: {}\",\n                path.display()\n            ),\n        ));\n    }\n    astrid_core::platform_fs::verify_no_redirects(path)?;\n    #[cfg(unix)]\n    {\n        use std::os::unix::fs::MetadataExt as _;\n        if metadata.uid() != nix::unistd::getuid().as_raw() {\n            return Err(io::Error::new(\n                io::ErrorKind::PermissionDenied,\n                format!(\n                    \"legacy dedicated source is not owned by the current user: {}\",\n                    path.display()\n                ),\n            ));\n        }\n    }\n    astrid_core::platform_fs::ensure_private_directory(path)?;\n    for entry in fs::read_dir(path)? {\n        let entry = entry?;\n        let child = entry.path();\n        let child_metadata = fs::symlink_metadata(&child)?;\n        if child_metadata.file_type().is_symlink() {\n            return Err(io::Error::new(\n                io::ErrorKind::InvalidData,\n                format!(\n                    \"legacy dedicated source contains a redirect: {}\",","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/astrid-runtime/astrid/blob/affd8760f44190dbdfbec23403f4c4b642c33112/crates/astrid-kernel/src/legacy_migration_barrier/legacy_tmp.rs#L37-L73","documentation":"Before tightening permissions on a legacy dedicated tree, the current user must own it (unix). If the directory's uid differs from the process uid, the function raises PermissionDenied rather than chmod-ing someone else's directory, which could break other users' data or fail midway.","triggerScenarios":"tighten_dedicated_tree (called by tighten_legacy_dedicated_directories) runs on unix; metadata.uid() != nix::unistd::getuid().as_raw() for the inspected directory.","commonSituations":"The legacy directory was created by root or another service account and the migration runs as the regular user; files were restored from a backup preserving foreign ownership; a shared multi-user machine hosts the home directory.","solutions":["chown the legacy tree to the current user (sudo chown -R $(id -u) <path>) and re-run","Run the migration as the user that owns the legacy tree","If the tree belongs to another account intentionally, move it out of this home's migration scope","Fix backup/restore tooling to preserve or correct ownership for the owning user"],"exampleFix":"// before: directory owned by root, migration runs as user\n// after\nsudo chown -R $(id -u):$(id -g) ~/.local/share/astrid/legacy-dedicated","handlingStrategy":"try-catch","validationCode":"#[cfg(unix)]\n{\n    use std::os::unix::fs::MetadataExt;\n    let md = std::fs::symlink_metadata(path)?;\n    if md.uid() != nix::unistd::getuid().as_raw() {\n        // chown or switch user before calling the API\n    }\n}","typeGuard":null,"tryCatchPattern":"if let Err(e) = tighten_legacy_dedicated_directories(&home) {\n    if e.kind() == std::io::ErrorKind::PermissionDenied\n        && e.to_string().contains(\"not owned by the current user\") {\n        eprintln!(\"chown the tree to the current user and retry\");\n    }\n}","preventionTips":["Run migrations as the user who owns the astrid home","Fix ownership after restores from backups (chown -R)","Avoid sharing one astrid home across multiple user accounts"],"tags":["permissions","ownership","unix","migration"],"backgroundTag":"permission-denied","analyzedSha":"affd8760f44190dbdfbec23403f4c4b642c33112","analyzedAt":"2026-09-09T21:28:12.402Z","contentChangedAt":"2026-09-09T21:28:12.402Z","schemaVersion":2},"datasetVersion":"2026-09-17T20:17:13.540Z"}