{"record":{"id":"137b214c8957c1c6","repo":"anomalyco/sst","slug":"failed-to-clean-up-extracted-directory-w","errorCode":null,"errorMessage":"failed to clean up extracted directory: %w","messagePattern":"failed to clean up extracted directory: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"pkg/runtime/python/build.go","lineNumber":466,"sourceCode":"}\n\n// moveExtractedPackage moves the extracted package to the correct location\nfunc moveExtractedPackage(extractedDir, targetDir, baseName string) error {\n\t// For src layout, flatten src/{package_name} to {package_name}\n\tsrcPath := filepath.Join(extractedDir, \"src\", baseName)\n\tif _, err := os.Stat(srcPath); err == nil {\n\t\tif err := os.RemoveAll(targetDir); err != nil {\n\t\t\treturn fmt.Errorf(\"failed to remove old directory: %w\", err)\n\t\t}\n\n\t\t// Move src/{package_name} to target\n\t\tif err := os.Rename(srcPath, targetDir); err != nil {\n\t\t\treturn fmt.Errorf(\"failed to move src directory contents: %w\", err)\n\t\t}\n\n\t\t// Clean up extracted directory\n\t\tif err := os.RemoveAll(extractedDir); err != nil {\n\t\t\treturn fmt.Errorf(\"failed to clean up extracted directory: %w\", err)\n\t\t}\n\t} else {\n\t\t// No src directory — check if package needs flattening\n\t\tif shouldFlattenPackage(extractedDir) {\n\t\t\treturn flattenPackageToRoot(extractedDir, targetDir)\n\t\t}\n\n\t\t// Standard case: rename directory\n\t\tif err := os.RemoveAll(targetDir); err != nil {\n\t\t\treturn fmt.Errorf(\"failed to remove old directory: %w\", err)\n\t\t}\n\n\t\tif err := os.Rename(extractedDir, targetDir); err != nil {\n\t\t\treturn fmt.Errorf(\"failed to rename directory: %w\", err)\n\t\t}\n\t}\n\n\treturn nil","sourceCodeStart":448,"sourceCodeEnd":484,"githubUrl":"https://github.com/anomalyco/sst/blob/a0bd20f762883e72a35caccb4896c42ce5b3f707/pkg/runtime/python/build.go#L448-L484","documentation":"Once src/{package_name} has been moved into place, moveExtractedPackage removes the temporary extracted directory. Failure is wrapped as \"failed to clean up extracted directory\". By this point the package is already installed, so this is a hygiene/temp-disk issue rather than a broken build.","triggerScenarios":"os.RemoveAll(extractedDir) fails, usually because some file in the temp directory is still open/locked, is owned by another user, or sits on a read-only or full filesystem.","commonSituations":"A virus scanner or indexer holds files in the temp dir on macOS/Windows; a forked process keeps a cwd inside extractedDir; root-owned leftovers from a previous sudo build; temp dir on a volume that went read-only.","solutions":["Treat as non-fatal: the package is installed; delete the extracted dir manually later (rm -rf)","Close/stop any process holding files in the temp directory","Check for root-owned files (ls -la) and chown or delete them with appropriate privileges","Ensure temp storage is writable and not full (df -h)","Clear the whole temp/build cache on the next clean build"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := processPackageArchive(...); err != nil {\n    if strings.Contains(err.Error(), \"failed to clean up extracted directory\") {\n        // package already installed; log and schedule temp cleanup, don't fail the build\n        return nil\n    }\n    return err\n}","preventionTips":["Ensure no processes keep cwd or open handles inside the temp extraction dir","Run builds as a consistent user to avoid root-owned leftovers","Schedule periodic cleanup of build temp dirs","Exclude build temp dirs from antivirus/indexer scanning"],"tags":["filesystem","cleanup","temp-files","python"],"backgroundTag":"temp-cleanup-failed","analyzedSha":"a0bd20f762883e72a35caccb4896c42ce5b3f707","analyzedAt":"2026-08-30T11:26:00.383Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}