{"record":{"id":"dbf669faa1435367","repo":"egametang/ET","slug":"error-dbf669","errorCode":null,"errorMessage":"父目录不能拷贝到子目录！","messagePattern":"父目录不能拷贝到子目录！","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"Packages/cn.etetet.core/Scripts/Core/Share/Helper/FileHelper.cs","lineNumber":55,"sourceCode":"\t\t\tforeach (string subdir in Directory.GetDirectories(dir))\n\t\t\t{\n\t\t\t\tDirectory.Delete(subdir, true);\t\t\n\t\t\t}\n\n\t\t\tforeach (string subFile in Directory.GetFiles(dir))\n\t\t\t{\n\t\t\t\tFile.Delete(subFile);\n\t\t\t}\n\t\t}\n\n\t\tpublic static void CopyDirectory(string srcDir, string tgtDir)\n\t\t{\n\t\t\tDirectoryInfo source = new DirectoryInfo(srcDir);\n\t\t\tDirectoryInfo target = new DirectoryInfo(tgtDir);\n\t\n\t\t\tif (target.FullName.StartsWith(source.FullName, StringComparison.CurrentCultureIgnoreCase))\n\t\t\t{\n\t\t\t\tthrow new Exception(\"父目录不能拷贝到子目录！\");\n\t\t\t}\n\t\n\t\t\tif (!source.Exists)\n\t\t\t{\n\t\t\t\treturn;\n\t\t\t}\n\t\n\t\t\tif (!target.Exists)\n\t\t\t{\n\t\t\t\ttarget.Create();\n\t\t\t}\n\t\n\t\t\tFileInfo[] files = source.GetFiles();\n\t\n\t\t\tfor (int i = 0; i < files.Length; i++)\n\t\t\t{\n\t\t\t\tFile.Copy(files[i].FullName, Path.Combine(target.FullName, files[i].Name), true);\n\t\t\t}","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/egametang/ET/blob/5cab01f7a8bee5f49f4781eebe9e2b1c6d7ebe0f/Packages/cn.etetet.core/Scripts/Core/Share/Helper/FileHelper.cs#L37-L73","documentation":"Thrown by FileHelper.CopyDirectory when the target directory is inside the source directory. Copying a parent into its own child would recurse infinitely (the copy would keep copying itself into the copy), so it is rejected up front.","triggerScenarios":"Passing srcDir as an ancestor of tgtDir; backup/copy tooling that writes the output under the source tree; build scripts whose output dir nests under the input.","commonSituations":"Generating output into a subfolder of the input; deploy/copy scripts with reversed or misnested paths; tooling that defaults output to ./input/out.","solutions":["Place the target directory outside the source tree entirely (sibling, not child).","If output must nest, copy to a temp dir outside source first, then move into place.","Validate `!target.FullName.StartsWith(source.FullName)` in your own caller before invoking CopyDirectory."],"exampleFix":"// before\nFileHelper.CopyDirectory(src, Path.Combine(src, \"out\"));   // out is inside src\n\n// after\nFileHelper.CopyDirectory(src, Path.Combine(parentOfSrc, \"out\"));","handlingStrategy":"validation","validationCode":"var src = new DirectoryInfo(srcDir).FullName;\nvar tgt = new DirectoryInfo(tgtDir).FullName;\nif (!tgt.StartsWith(src, StringComparison.OrdinalIgnoreCase))\n{\n    FileHelper.CopyDirectory(srcDir, tgtDir);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep output directories outside the source tree.","Validate containment before copying.","Copy to a temp dir first if nesting is required."],"tags":["filesystem","copy","path","core"],"backgroundTag":null,"analyzedSha":"5cab01f7a8bee5f49f4781eebe9e2b1c6d7ebe0f","analyzedAt":"2026-08-13T21:10:40.377Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}