diff options
author | Rob Mensching <rob@firegiant.com> | 2021-03-16 14:43:36 -0700 |
---|---|---|
committer | Rob Mensching <rob@firegiant.com> | 2021-03-16 14:45:34 -0700 |
commit | d056d00e1e1111b6ef68c57f1f03ef6843204723 (patch) | |
tree | d9c034fde572033e1998ca79dde85de31da46583 | |
parent | ecf0f8e0a3038e65d18cb3ace71b845af27407ae (diff) | |
download | wix-d056d00e1e1111b6ef68c57f1f03ef6843204723.tar.gz wix-d056d00e1e1111b6ef68c57f1f03ef6843204723.tar.bz2 wix-d056d00e1e1111b6ef68c57f1f03ef6843204723.zip |
Move ResetAcls to Core.Native from Core
Also simplify copying/moving files directory creation.
-rw-r--r-- | src/WixToolset.Core.Native/FileSystem.cs | 35 | ||||
-rw-r--r-- | src/WixToolset.Core.Native/WixToolset.Core.Native.csproj | 1 |
2 files changed, 27 insertions, 9 deletions
diff --git a/src/WixToolset.Core.Native/FileSystem.cs b/src/WixToolset.Core.Native/FileSystem.cs index b9691d44..d843a9e8 100644 --- a/src/WixToolset.Core.Native/FileSystem.cs +++ b/src/WixToolset.Core.Native/FileSystem.cs | |||
@@ -3,8 +3,10 @@ | |||
3 | namespace WixToolset.Core.Native | 3 | namespace WixToolset.Core.Native |
4 | { | 4 | { |
5 | using System; | 5 | using System; |
6 | using System.Collections.Generic; | ||
6 | using System.IO; | 7 | using System.IO; |
7 | using System.Runtime.InteropServices; | 8 | using System.Runtime.InteropServices; |
9 | using System.Security.AccessControl; | ||
8 | 10 | ||
9 | /// <summary> | 11 | /// <summary> |
10 | /// File system helpers. | 12 | /// File system helpers. |
@@ -19,10 +21,7 @@ namespace WixToolset.Core.Native | |||
19 | /// <param name="allowHardlink">Allow hardlinks.</param> | 21 | /// <param name="allowHardlink">Allow hardlinks.</param> |
20 | public static void CopyFile(string source, string destination, bool allowHardlink) | 22 | public static void CopyFile(string source, string destination, bool allowHardlink) |
21 | { | 23 | { |
22 | if (File.Exists(destination)) | 24 | EnsureDirectoryWithoutFile(destination); |
23 | { | ||
24 | File.Delete(destination); | ||
25 | } | ||
26 | 25 | ||
27 | if (!allowHardlink || !CreateHardLink(destination, source, IntPtr.Zero)) | 26 | if (!allowHardlink || !CreateHardLink(destination, source, IntPtr.Zero)) |
28 | { | 27 | { |
@@ -41,18 +40,36 @@ namespace WixToolset.Core.Native | |||
41 | /// <param name="destination">The destination file.</param> | 40 | /// <param name="destination">The destination file.</param> |
42 | public static void MoveFile(string source, string destination) | 41 | public static void MoveFile(string source, string destination) |
43 | { | 42 | { |
44 | if (File.Exists(destination)) | 43 | EnsureDirectoryWithoutFile(destination); |
44 | |||
45 | File.Move(source, destination); | ||
46 | } | ||
47 | |||
48 | /// <summary> | ||
49 | /// Reset the ACLs on a set of files. | ||
50 | /// </summary> | ||
51 | /// <param name="files">The list of file paths to set ACLs.</param> | ||
52 | public static void ResetAcls(IEnumerable<string> files) | ||
53 | { | ||
54 | var aclReset = new FileSecurity(); | ||
55 | aclReset.SetAccessRuleProtection(false, false); | ||
56 | |||
57 | foreach (var file in files) | ||
45 | { | 58 | { |
46 | File.Delete(destination); | 59 | new FileInfo(file).SetAccessControl(aclReset); |
47 | } | 60 | } |
61 | } | ||
62 | |||
63 | private static void EnsureDirectoryWithoutFile(string path) | ||
64 | { | ||
65 | File.Delete(path); | ||
66 | |||
67 | var directory = Path.GetDirectoryName(path); | ||
48 | 68 | ||
49 | var directory = Path.GetDirectoryName(destination); | ||
50 | if (!String.IsNullOrEmpty(directory)) | 69 | if (!String.IsNullOrEmpty(directory)) |
51 | { | 70 | { |
52 | Directory.CreateDirectory(directory); | 71 | Directory.CreateDirectory(directory); |
53 | } | 72 | } |
54 | |||
55 | File.Move(source, destination); | ||
56 | } | 73 | } |
57 | 74 | ||
58 | [DllImport("Kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)] | 75 | [DllImport("Kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)] |
diff --git a/src/WixToolset.Core.Native/WixToolset.Core.Native.csproj b/src/WixToolset.Core.Native/WixToolset.Core.Native.csproj index 4069b6b4..94ab812a 100644 --- a/src/WixToolset.Core.Native/WixToolset.Core.Native.csproj +++ b/src/WixToolset.Core.Native/WixToolset.Core.Native.csproj | |||
@@ -35,6 +35,7 @@ | |||
35 | 35 | ||
36 | <ItemGroup> | 36 | <ItemGroup> |
37 | <PackageReference Include="WixToolset.Data" Version="4.0.*" /> | 37 | <PackageReference Include="WixToolset.Data" Version="4.0.*" /> |
38 | <PackageReference Include="System.IO.FileSystem.AccessControl" Version="4.6.0" /> | ||
38 | </ItemGroup> | 39 | </ItemGroup> |
39 | 40 | ||
40 | <ItemGroup> | 41 | <ItemGroup> |