public static void CopyTo(this DirectoryInfo source, DirectoryInfo target) { if (!target.Exists) { target.Create(); Chmod.chmod(target.FullName, Chmod.P_755); } foreach (var i in source.GetFiles()) { i.CopyTo(Path.Combine(target.FullName, i.Name), true); Chmod.chmod(Path.Combine(target.FullName, i.Name), Chmod.P_755); } foreach (var d in source.GetDirectories()) { d.CopyTo(new DirectoryInfo(Path.Combine(target.FullName, d.Name))); } }
private List <(string Docker, string Host, bool Readonly)> instantiateNode(JsonObject node, DirectoryInfo targetDirectory, string relativePath) { var rv = new List <(string Docker, string Host, bool Readonly)>(); bool shared; string path; bool ro; if (!node.TryGetJsonString(PathKey, out var pathv)) { return(rv); } else { path = pathv; } if (node.TryGetJsonBool(SharedKey, out var sharedv)) { shared = sharedv; } else { shared = false; } if (node.TryGetJsonBool(ReadonlyKey, out var readonlyv)) { ro = readonlyv; } else { ro = shared; } if (!node.TryGetJsonObject(SubKey, out JsonObject sub)) { sub = null; } if (!targetDirectory.Exists) { targetDirectory.Create(); Chmod.chmod(targetDirectory.FullName, Chmod.P_755); } if (shared) { rv.Add((relativePath, path, ro)); if (sub != null) { foreach (var i in sub.Values) { if (!(i.Value is JsonObject nextNode)) { continue; } var name = i.Key; var nextTargetDir = new DirectoryInfo(Path.Combine(targetDirectory.FullName, i.Key)); var nextRelPath = relativePath + DirSeparator + i.Key; rv.AddRange(instantiateNode(nextNode, nextTargetDir, nextRelPath)); } } } else { if (relativePath == ".") { rv.Add((relativePath, targetDirectory.FullName, ro)); } var pathInfo = new DirectoryInfo(path); foreach (var i in pathInfo.GetFiles()) { i.CopyTo(Path.Combine(targetDirectory.FullName, i.Name), true); Chmod.chmod(Path.Combine(targetDirectory.FullName, i.Name), Chmod.P_755); } foreach (var i in pathInfo.GetDirectories()) { if (sub != null && sub.TryGetJsonObject(i.Name, out var nextNode)) { rv.AddRange(instantiateNode(nextNode, new DirectoryInfo(Path.Combine(targetDirectory.FullName, i.Name)), relativePath + DirSeparator + i.Name)); } else { i.CopyTo(new DirectoryInfo(Path.Combine(targetDirectory.FullName, i.Name))); } } } return(rv); }
// encoding is utf-8 no bom // wo yi jing qin ding le private string ensuredirNode(string path, JsonObject node) { bool isFile = false; string pathSpecified = null; string content = null; bool returnthis = false; bool overwrite = false; string rv = null; if (node.TryGetJsonBool(IsFileKey, out var isFileBool)) { isFile = isFileBool; } if (node.TryGetJsonBool(OverwriteKey, out var overwriteBool)) { overwrite = overwriteBool; } if (node.TryGetJsonString(ContentKey, out var contentStr)) { content = contentStr; } if (node.TryGetJsonBool(ReturnThisKey, out var returnThisBool)) { returnthis = returnThisBool; } if (node.TryGetJsonString(PathSpecifiedKey, out var pathSpecifiedStr)) { pathSpecified = pathSpecifiedStr; } if (pathSpecified != null) { path = pathSpecified; } if (isFile) { var info = new FileInfo(path); content = content ?? ""; if (!info.Exists || overwrite) { writeToPath(info, content); } Chmod.chmod(path, Chmod.P_755); } else { var info = new DirectoryInfo(path); if (!info.Exists) { info.Create(); } Chmod.chmod(path, Chmod.P_755); foreach (var i in node.Values) { if (((string)(i.Key))[0] != '@' && i.Value is JsonObject nextNode) { rv = ensuredirNode(Path.Combine(path, i.Key), nextNode); } } } if (returnthis) { return(path); } return(rv == null ? path : rv); }