{"record":{"id":"0b8fdd031450c099","repo":"Kareadita/Kavita","slug":"source-directory-does-not-exist-or-could-not-be-fo","errorCode":null,"errorMessage":"Source directory does not exist or could not be found: ","messagePattern":"Source directory does not exist or could not be found: ","errorType":"exception","errorClass":"DirectoryNotFoundException","httpStatus":null,"severity":"error","filePath":"Kavita.Services/DirectoryService.cs","lineNumber":249,"sourceCode":"\n    /// <summary>\n    /// Copies all files and subdirectories within a directory to a target location\n    /// </summary>\n    /// <param name=\"sourceDirName\">Directory to copy from. Does not copy the parent folder</param>\n    /// <param name=\"destDirName\">Destination to copy to. Will be created if doesn't exist</param>\n    /// <param name=\"searchPattern\">Defaults to all files</param>\n    /// <returns>If was successful</returns>\n    /// <exception cref=\"DirectoryNotFoundException\">Thrown when source directory does not exist</exception>\n    public bool CopyDirectoryToDirectory(string? sourceDirName, string destDirName, string searchPattern = \"\")\n    {\n        if (string.IsNullOrEmpty(sourceDirName)) return false;\n\n        // Get the subdirectories for the specified directory.\n        var dir = FileSystem.DirectoryInfo.New(sourceDirName);\n\n        if (!dir.Exists)\n        {\n            throw new DirectoryNotFoundException(\n                \"Source directory does not exist or could not be found: \"\n                + sourceDirName);\n        }\n\n        var dirs = dir.GetDirectories();\n\n        // If the destination directory doesn't exist, create it.\n        ExistOrCreate(destDirName);\n\n        // Get the files in the directory and copy them to the new location.\n        var files = GetFilesWithExtension(dir.FullName, searchPattern).Select(n => FileSystem.FileInfo.New(n));\n        foreach (var file in files)\n        {\n            var tempPath = FileSystem.Path.Combine(destDirName, file.Name);\n            file.CopyTo(tempPath, false);\n        }\n\n        // If copying subdirectories, copy them and their contents to new location.","sourceCodeStart":231,"sourceCodeEnd":267,"githubUrl":"https://github.com/Kareadita/Kavita/blob/9c3e5400007f8a0282f7d883f2ad5e71716e514d/Kavita.Services/DirectoryService.cs#L231-L267","documentation":"A standard .NET DirectoryNotFoundException thrown by CopyDirectoryToDirectory when the source directory path does not exist on disk. The code creates a DirectoryInfo wrapper via the abstracted FileSystem and checks dir.Exists before proceeding. Unlike KavitaException, this is a raw BCL exception that will propagate as a 500 if uncaught.","triggerScenarios":"Source directory path is misspelled, has been moved or deleted, lives on an unmounted network share, or the process lacks permissions to enumerate the directory (Exists can return false for inaccessible paths).","commonSituations":"Library root moved after initial scan; NAS or USB drive disconnected; path casing issues on case-sensitive filesystems; containerized deployment with a misconfigured volume mount; permissions changed by another process.","solutions":["Verify the source directory path exists at the OS level: 'ls /path/to/source' or equivalent","If the library root moved, update the library folder configuration in Kavita Settings","Check that the volume or mount point is active in container deployments","Verify the Kavita process user has read + traverse permissions on the source directory"],"exampleFix":"// Guard before copying:\n// if (!directoryService.FileSystem.Directory.Exists(sourceDirName)) {\n//     logger.LogWarning(\"Source directory not found: {Path}\", sourceDirName);\n//     return false;\n// }","handlingStrategy":"validation","validationCode":"// Check directory existence before copying:\n// if (!directoryService.FileSystem.Directory.Exists(sourceDirName)) {\n//     logger.LogWarning(\"Source directory not found: {Path}\", sourceDirName);\n//     return false;\n// }","typeGuard":null,"tryCatchPattern":"// try {\n//     directoryService.CopyDirectoryToDirectory(sourceDir, destDir, searchPattern);\n// } catch (DirectoryNotFoundException ex) {\n//     logger.LogWarning(ex, \"Source directory missing: {Path}\", sourceDir);\n//     return false; // or re-scan library\n// }","preventionTips":["Validate directory paths before passing them to copy operations","Use library scans to detect and report missing directories proactively","Mount persistent volumes correctly in containerized deployments before starting Kavita"],"tags":["filesystem","directory","not-found","io"],"backgroundTag":null,"analyzedSha":"9c3e5400007f8a0282f7d883f2ad5e71716e514d","analyzedAt":"2026-08-13T19:06:05.897Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}