{"record":{"id":"282b6ffa946e03fe","repo":"libnyanpasu/clash-nyanpasu","slug":"staged-file-is-not-a-regular-file","errorCode":null,"errorMessage":"staged file is not a regular file","messagePattern":"staged file is not a regular file","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/tauri/src/service/profile_file.rs","lineNumber":780,"sourceCode":"        };\n        let link_metadata = match std::fs::symlink_metadata(&link_path) {\n            Ok(metadata) => Some(metadata),\n            Err(error) if error.kind() == std::io::ErrorKind::NotFound => None,\n            Err(error) => {\n                return Err(error).with_context(|| {\n                    format!(\n                        \"inspect staged symlink specification {}\",\n                        link_path.display()\n                    )\n                });\n            }\n        };\n        if file_metadata.is_some() && link_metadata.is_some() {\n            bail!(\"materialization has multiple staged resources\");\n        }\n        if let Some(metadata) = file_metadata {\n            if is_symlink_or_reparse(&metadata) || !metadata.is_file() {\n                bail!(\"staged file is not a regular file\");\n            }\n            let content = std::fs::read(&file_path)?;\n            if hash_tagged(b\"file\", &content) != expected_hash {\n                bail!(\"staged file hash mismatch\");\n            }\n            return Ok(Some(StoredResource::File { path: file_path }));\n        }\n        if let Some(metadata) = link_metadata {\n            if is_symlink_or_reparse(&metadata) || !metadata.is_file() {\n                bail!(\"staged symlink specification is not a regular file\");\n            }\n            let target = std::fs::read_to_string(&link_path)?;\n            if hash_tagged(b\"symlink\", target.as_bytes()) != expected_hash {\n                bail!(\"staged symlink hash mismatch\");\n            }\n            return Ok(Some(StoredResource::Symlink {\n                target: ExternalProfilePath::new(target)?,\n            }));","sourceCodeStart":762,"sourceCodeEnd":798,"githubUrl":"https://github.com/libnyanpasu/clash-nyanpasu/blob/f7dbce2997c633e484f54788035e770b3ee99773/backend/tauri/src/service/profile_file.rs#L762-L798","documentation":"read_staged_resource validates that the staged file blob is a plain regular file before reading it. The path exists but is not a regular file (it is a symlink/reparse point, directory, FIFO, or other non-regular node). The code bails instead of reading it, protecting against following malicious or corrupted links in the staging area.","triggerScenarios":"The staged file path (stage_file_path(root, operation_id)) exists but symlink_metadata shows it is a symlink/reparse point or not a regular file — e.g. someone replaced the staged blob with a symlink, or the staging dir sits on a filesystem (like some network/overlay mounts) that reports unusual file types.","commonSituations":"Staging directory tampering or accidental replacement; WSL/Windows reparse points; NFS/SMB/overlay filesystems misreporting file types; a build/tool swapped the file for a link.","solutions":["Remove the non-regular node at the staged file path and re-run materialization so the blob is rewritten as a regular file.","Ensure the staging root is on a local filesystem that does not turn files into reparse points (avoid network shares/overlay mounts for the staging dir).","Check nothing (sync tools, antivirus, junction creation) is converting files in the staging directory into symlinks.","If you moved or restored the staging area manually, restore a regular-file blob with the expected content."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"let md = std::fs::symlink_metadata(staged_file_path)?;\nif md.is_symlink() || !md.is_file() {\n    std::fs::remove_file(staged_file_path)?; // clear invalid node before retry\n}","typeGuard":"fn is_regular_file_node(p: &Path) -> bool {\n    std::fs::symlink_metadata(p).map(|m| !m.is_symlink() && m.is_file()).unwrap_or(false)\n}","tryCatchPattern":"match result {\n    Err(e) if e.to_string().contains(\"staged file is not a regular file\") => {\n        remove_stale_staging(root, op_id)?;\n        retry()\n    }\n    other => other,\n}","preventionTips":["Keep staging roots on plain local filesystems, not network shares or OneDrive-synced folders.","Don't manually touch or replace files in the staging directory.","Exclude the staging directory from backup/sync tools."],"tags":["filesystem","symlink","profile-materialization","rust"],"backgroundTag":"unsupported-operation","analyzedSha":"f7dbce2997c633e484f54788035e770b3ee99773","analyzedAt":"2026-09-08T01:24:59.197Z","contentChangedAt":"2026-09-08T01:24:59.197Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}