{"record":{"id":"4a7e8f8ca616340a","repo":"astrid-runtime/astrid","slug":"ordinary-legacy-file-is-not-owned-by-the-current-u","errorCode":null,"errorMessage":"ordinary legacy file is not owned by the current user: {path}","messagePattern":"ordinary legacy file is not owned by the current user: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/astrid-kernel/src/principal_home_migration/mod.rs","lineNumber":873,"sourceCode":"    }\n    Ok((\n        ByteCount::new(bytes),\n        ContentDigest::from_blake3(hasher.finalize()),\n    ))\n}\n\nfn validate_regular_file(path: &Path) -> io::Result<()> {\n    let metadata = fs::symlink_metadata(path)?;\n    if metadata.file_type().is_symlink() || !metadata.is_file() {\n        return Err(invalid_source(path, \"ordinary entry is not a regular file\"));\n    }\n    astrid_core::platform_fs::verify_no_redirects(path)?;\n    #[cfg(unix)]\n    {\n        use std::os::unix::fs::MetadataExt as _;\n\n        if metadata.uid() != nix::unistd::getuid().as_raw() {\n            return Err(io::Error::new(\n                io::ErrorKind::PermissionDenied,\n                format!(\n                    \"ordinary legacy file is not owned by the current user: {}\",\n                    path.display()\n                ),\n            ));\n        }\n        if metadata.mode() & 0o022 != 0 {\n            return Err(io::Error::new(\n                io::ErrorKind::PermissionDenied,\n                format!(\n                    \"ordinary legacy file is group/world writable: {}\",\n                    path.display()\n                ),\n            ));\n        }\n    }\n    Ok(())","sourceCodeStart":855,"sourceCodeEnd":891,"githubUrl":"https://github.com/astrid-runtime/astrid/blob/affd8760f44190dbdfbec23403f4c4b642c33112/crates/astrid-kernel/src/principal_home_migration/mod.rs#L855-L891","documentation":"Raised by validate_regular_file when an ordinary legacy file's owner uid differs from the current process uid (unix only). Migration refuses to ingest files the current user does not own, since trusting foreign-owned files would be a security risk. ErrorKind::PermissionDenied.","triggerScenarios":"Calling digest_file or publish_directory_files (via migrate_legacy_principal_homes) when a regular file under the legacy source tree has metadata.uid() != getuid().","commonSituations":"Legacy homes copied with sudo/root ownership, files restored from backups as root, shared multi-user machines where another user created files in the migrated tree.","solutions":["chown the legacy files to the current user (e.g. sudo chown -R $(id -u) <path>)","Re-copy the legacy home as the current user without sudo","Run the migration as the owner of the files","Exclude the foreign-owned files from the legacy source tree"],"exampleFix":"// before: migration fails on root-owned files\nsudo cp -r /old/home ~/legacy-home   # files owned by root\n// after: take ownership first\nsudo chown -R $(id -u):$(id -g) ~/legacy-home","handlingStrategy":"validation","validationCode":"#[cfg(unix)]\nfn all_files_owned_by_me(root: &Path) -> bool {\n    use std::os::unix::fs::MetadataExt;\n    walk(root).all(|p| p.metadata().map(|m| m.uid() == nix::unistd::getuid().as_raw()).unwrap_or(false))\n}","typeGuard":"#[cfg(unix)]\nfn owned_by_current_user(m: &std::fs::Metadata) -> bool {\n    use std::os::unix::fs::MetadataExt;\n    m.uid() == nix::unistd::getuid().as_raw()\n}","tryCatchPattern":"match migrate(...) {\n    Err(e) if e.kind() == io::ErrorKind::PermissionDenied => {\n        eprintln!(\"fix ownership: chown -R $(id -u) <legacy home>\");\n        Err(e)\n    }\n    other => other,\n}","preventionTips":["Never copy legacy homes with sudo; copy as the migrating user","Run chown -R before migration when files arrive from backups","Run the migration under the same account that owns the legacy data"],"tags":["permissions","unix","ownership","security"],"backgroundTag":"permission-denied","analyzedSha":"affd8760f44190dbdfbec23403f4c4b642c33112","analyzedAt":"2026-09-09T21:28:12.402Z","contentChangedAt":"2026-09-09T21:28:12.402Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}