{"record":{"id":"9278314c5fb0f67b","repo":"LykosAI/StabilityMatrix","slug":"failed-to-delete-file-filepath-fullpath","errorCode":null,"errorMessage":"Failed to delete file {filePath.FullPath}","messagePattern":"Failed to delete file (.+?)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"StabilityMatrix.Core/Extensions/DirectoryPathExtensions.cs","lineNumber":93,"sourceCode":"        // Recursively delete all subdirectories\n        foreach (var subDir in directory.EnumerateDirectories())\n        {\n            DeleteVerbose(subDir, logger, cancellationToken);\n        }\n\n        // Delete all files in the directory\n        foreach (var filePath in directory.EnumerateFiles())\n        {\n            cancellationToken.ThrowIfCancellationRequested();\n\n            try\n            {\n                filePath.Info.Attributes = FileAttributes.Normal;\n                filePath.Delete();\n            }\n            catch (IOException ex)\n            {\n                throw new IOException($\"Failed to delete file {filePath.FullPath}\", ex);\n            }\n        }\n\n        // Delete this directory\n        try\n        {\n            directory.Delete(false);\n        }\n        catch (IOException ex)\n        {\n            throw new IOException($\"Failed to delete directory {directory}\", ex);\n        }\n    }\n}\n","sourceCodeStart":75,"sourceCodeEnd":108,"githubUrl":"https://github.com/LykosAI/StabilityMatrix/blob/af93d6ef57c01cd890d7e0ad0a9ea8c9fcda3002/StabilityMatrix.Core/Extensions/DirectoryPathExtensions.cs#L75-L108","documentation":"DeleteVerbose wraps file deletion failures in an IOException naming the file path. Before deleting it attempts to reset attributes to FileAttributes.Normal (to defeat read-only flags), but if filePath.Delete() still throws IOException the error is rethrown with the path in the message. This is the per-file stage of the recursive DeleteVerbose walk.","triggerScenarios":"A file inside the directory being deleted is read-only and attribute reset failed, locked by another process, or an I/O error occurs during unlink.","commonSituations":"Deleting a model/venv directory while the app (or an external editor, indexer, or malware scanner) still has files open; files marked read-only inherited from an archive that lost executable attribute metadata; files on a network share that went offline.","solutions":["Find and close the process holding the file open, then retry DeleteVerbose","Check disk/AV logs for I/O errors; exclude the directory from antivirus real-time scanning","Verify the file is not read-only and permissions allow deletion","If the reset to FileAttributes.Normal failed, clear attributes manually before deleting"],"exampleFix":"// before\nfilePath.Info.Attributes = FileAttributes.Normal;\nfilePath.Delete();\n// after\nvar attrs = File.GetAttributes(filePath.FullPath);\nFile.SetAttributes(filePath.FullPath, attrs & ~(FileAttributes.ReadOnly | FileAttributes.Hidden | FileAttributes.System));\nfilePath.Delete();","handlingStrategy":"try-catch","validationCode":"if (!Directory.Exists(dir)) return;\nforeach (var f in Directory.EnumerateFiles(dir, \"*\", SearchOption.AllDirectories))\n{\n    var attrs = File.GetAttributes(f);\n    if (attrs.HasFlag(FileAttributes.ReadOnly))\n        File.SetAttributes(f, attrs & ~FileAttributes.ReadOnly);\n}","typeGuard":null,"tryCatchPattern":"try { DirectoryPathExtensions.DeleteVerbose(dir, logger, ct); }\ncatch (IOException ex)\n{\n    logger.LogError(ex, \"File delete failed under {Dir}; determine locking process\", dir);\n    // inspect ex.InnerException for Win32 error, retry after closing handles\n}","preventionTips":["Clear read-only attributes recursively before deleting archive-extracted files","Ensure app processes dispose file handles before cleanup","Pause AV real-time scanning for large deletes","Retry deletes with backoff on Windows"],"tags":["io","filesystem","file-locked"],"backgroundTag":"file-delete-failed","analyzedSha":"af93d6ef57c01cd890d7e0ad0a9ea8c9fcda3002","analyzedAt":"2026-09-12T19:02:43.389Z","contentChangedAt":"2026-09-12T19:02:43.389Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}