OLD | NEW |
| (Empty) |
1 /* | |
2 Copyright 2011 Google Inc | |
3 | |
4 Licensed under the Apache License, Version 2.0 (the "License"); | |
5 you may not use this file except in compliance with the License. | |
6 You may obtain a copy of the License at | |
7 | |
8 http://www.apache.org/licenses/LICENSE-2.0 | |
9 | |
10 Unless required by applicable law or agreed to in writing, software | |
11 distributed under the License is distributed on an "AS IS" BASIS, | |
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 See the License for the specific language governing permissions and | |
14 limitations under the License. | |
15 */ | |
16 | |
17 using System.IO; | |
18 | |
19 namespace Google.Build.Tester | |
20 { | |
21 /// <summary> | |
22 /// Utility class. | |
23 /// </summary> | |
24 internal class Utils | |
25 { | |
26 /// <summary> | |
27 /// Copies all files and directories from the source to the destination. | |
28 /// </summary> | |
29 public static void CopyFiles(string source, string dest) | |
30 { | |
31 foreach (var file in Directory.GetFiles(source, "*", SearchOption.Al
lDirectories)) | |
32 { | |
33 string fileDest = Path.Combine(dest, GetRelativePath(file, sourc
e)); | |
34 string dir = Path.GetDirectoryName(fileDest); | |
35 | |
36 if (!string.IsNullOrEmpty(dir) && !Directory.Exists(dir)) | |
37 { | |
38 Directory.CreateDirectory(dir); | |
39 } | |
40 | |
41 File.Copy(file, fileDest, true); | |
42 } | |
43 } | |
44 | |
45 /// <summary> | |
46 /// Retrieves the relative path from the parent to the child. | |
47 /// </summary> | |
48 public static string GetRelativePath(string child, string parent) | |
49 { | |
50 string absoluteChild = Path.GetFullPath(child); | |
51 string absoluteParent = Path.GetFullPath(parent); | |
52 | |
53 if (!absoluteChild.StartsWith(absoluteParent Path.DirectorySeparat
orChar)) | |
54 { | |
55 return absoluteChild; // Nothing in common. | |
56 } | |
57 | |
58 return absoluteChild.Substring(absoluteParent.Length 1); | |
59 } | |
60 } | |
61 } | |
OLD | NEW |