aboutsummaryrefslogtreecommitdiff
path: root/src/WixToolset.Core/Bind/TransferFilesCommand.cs
diff options
context:
space:
mode:
authorRob Mensching <rob@firegiant.com>2021-03-16 10:49:09 -0700
committerRob Mensching <rob@firegiant.com>2021-03-16 11:07:44 -0700
commit60f75abcd1fe49052c118a2597ac59a82c372b64 (patch)
tree1fd88e6c67846b97e61dbc3bf6f5f440516829a2 /src/WixToolset.Core/Bind/TransferFilesCommand.cs
parent1c23520ed490b56e292dc1544463af83807745ad (diff)
downloadwix-60f75abcd1fe49052c118a2597ac59a82c372b64.tar.gz
wix-60f75abcd1fe49052c118a2597ac59a82c372b64.tar.bz2
wix-60f75abcd1fe49052c118a2597ac59a82c372b64.zip
Migrate PInvoke out of Core to Core.Native
Diffstat (limited to 'src/WixToolset.Core/Bind/TransferFilesCommand.cs')
-rw-r--r--src/WixToolset.Core/Bind/TransferFilesCommand.cs52
1 files changed, 29 insertions, 23 deletions
diff --git a/src/WixToolset.Core/Bind/TransferFilesCommand.cs b/src/WixToolset.Core/Bind/TransferFilesCommand.cs
index b9c54a14..9c104187 100644
--- a/src/WixToolset.Core/Bind/TransferFilesCommand.cs
+++ b/src/WixToolset.Core/Bind/TransferFilesCommand.cs
@@ -6,6 +6,7 @@ namespace WixToolset.Core.Bind
6 using System.Collections.Generic; 6 using System.Collections.Generic;
7 using System.IO; 7 using System.IO;
8 using System.Security.AccessControl; 8 using System.Security.AccessControl;
9 using WixToolset.Core.Native;
9 using WixToolset.Data; 10 using WixToolset.Data;
10 using WixToolset.Extensibility; 11 using WixToolset.Extensibility;
11 using WixToolset.Extensibility.Data; 12 using WixToolset.Extensibility.Data;
@@ -15,23 +16,23 @@ namespace WixToolset.Core.Bind
15 { 16 {
16 public TransferFilesCommand(IMessaging messaging, IEnumerable<ILayoutExtension> extensions, IEnumerable<IFileTransfer> fileTransfers, bool suppressAclReset) 17 public TransferFilesCommand(IMessaging messaging, IEnumerable<ILayoutExtension> extensions, IEnumerable<IFileTransfer> fileTransfers, bool suppressAclReset)
17 { 18 {
18 this.FileSystem = new FileSystem(extensions); 19 this.Extensions = extensions;
19 this.Messaging = messaging; 20 this.Messaging = messaging;
20 this.FileTransfers = fileTransfers; 21 this.FileTransfers = fileTransfers;
21 this.SuppressAclReset = suppressAclReset; 22 this.SuppressAclReset = suppressAclReset;
22 } 23 }
23 24
24 private FileSystem FileSystem { get; }
25
26 private IMessaging Messaging { get; } 25 private IMessaging Messaging { get; }
27 26
27 private IEnumerable<ILayoutExtension> Extensions { get; }
28
28 private IEnumerable<IFileTransfer> FileTransfers { get; } 29 private IEnumerable<IFileTransfer> FileTransfers { get; }
29 30
30 private bool SuppressAclReset { get; } 31 private bool SuppressAclReset { get; }
31 32
32 public void Execute() 33 public void Execute()
33 { 34 {
34 List<string> destinationFiles = new List<string>(); 35 var destinationFiles = new List<string>();
35 36
36 foreach (var fileTransfer in this.FileTransfers) 37 foreach (var fileTransfer in this.FileTransfers)
37 { 38 {
@@ -42,7 +43,7 @@ namespace WixToolset.Core.Bind
42 continue; 43 continue;
43 } 44 }
44 45
45 bool retry = false; 46 var retry = false;
46 do 47 do
47 { 48 {
48 try 49 try
@@ -50,12 +51,12 @@ namespace WixToolset.Core.Bind
50 if (fileTransfer.Move) 51 if (fileTransfer.Move)
51 { 52 {
52 this.Messaging.Write(VerboseMessages.MoveFile(fileTransfer.Source, fileTransfer.Destination)); 53 this.Messaging.Write(VerboseMessages.MoveFile(fileTransfer.Source, fileTransfer.Destination));
53 this.TransferFile(true, fileTransfer.Source, fileTransfer.Destination); 54 this.MoveFile(fileTransfer.Source, fileTransfer.Destination);
54 } 55 }
55 else 56 else
56 { 57 {
57 this.Messaging.Write(VerboseMessages.CopyFile(fileTransfer.Source, fileTransfer.Destination)); 58 this.Messaging.Write(VerboseMessages.CopyFile(fileTransfer.Source, fileTransfer.Destination));
58 this.TransferFile(false, fileTransfer.Source, fileTransfer.Destination); 59 this.CopyFile(fileTransfer.Source, fileTransfer.Destination);
59 } 60 }
60 61
61 retry = false; 62 retry = false;
@@ -73,7 +74,7 @@ namespace WixToolset.Core.Bind
73 throw; 74 throw;
74 } 75 }
75 76
76 string directory = Path.GetDirectoryName(fileTransfer.Destination); 77 var directory = Path.GetDirectoryName(fileTransfer.Destination);
77 this.Messaging.Write(VerboseMessages.CreateDirectory(directory)); 78 this.Messaging.Write(VerboseMessages.CreateDirectory(directory));
78 Directory.CreateDirectory(directory); 79 Directory.CreateDirectory(directory);
79 retry = true; 80 retry = true;
@@ -91,7 +92,7 @@ namespace WixToolset.Core.Bind
91 this.Messaging.Write(VerboseMessages.RemoveDestinationFile(fileTransfer.Destination)); 92 this.Messaging.Write(VerboseMessages.RemoveDestinationFile(fileTransfer.Destination));
92 93
93 // try to ensure the file is not read-only 94 // try to ensure the file is not read-only
94 FileAttributes attributes = File.GetAttributes(fileTransfer.Destination); 95 var attributes = File.GetAttributes(fileTransfer.Destination);
95 try 96 try
96 { 97 {
97 File.SetAttributes(fileTransfer.Destination, attributes & ~FileAttributes.ReadOnly); 98 File.SetAttributes(fileTransfer.Destination, attributes & ~FileAttributes.ReadOnly);
@@ -131,7 +132,7 @@ namespace WixToolset.Core.Bind
131 this.Messaging.Write(VerboseMessages.RemoveDestinationFile(fileTransfer.Destination)); 132 this.Messaging.Write(VerboseMessages.RemoveDestinationFile(fileTransfer.Destination));
132 133
133 // ensure the file is not read-only, then delete it 134 // ensure the file is not read-only, then delete it
134 FileAttributes attributes = File.GetAttributes(fileTransfer.Destination); 135 var attributes = File.GetAttributes(fileTransfer.Destination);
135 File.SetAttributes(fileTransfer.Destination, attributes & ~FileAttributes.ReadOnly); 136 File.SetAttributes(fileTransfer.Destination, attributes & ~FileAttributes.ReadOnly);
136 try 137 try
137 { 138 {
@@ -161,8 +162,6 @@ namespace WixToolset.Core.Bind
161 162
162 try 163 try
163 { 164 {
164 //WixToolset.Core.Native.NativeMethods.ResetAcls(destinationFiles.ToArray(), (uint)destinationFiles.Count);
165
166 foreach (var file in destinationFiles) 165 foreach (var file in destinationFiles)
167 { 166 {
168 new FileInfo(file).SetAccessControl(aclReset); 167 new FileInfo(file).SetAccessControl(aclReset);
@@ -175,23 +174,30 @@ namespace WixToolset.Core.Bind
175 } 174 }
176 } 175 }
177 176
178 private void TransferFile(bool move, string source, string destination) 177 private void CopyFile(string source, string destination)
179 { 178 {
180 bool complete = false; 179 foreach (var extension in this.Extensions)
181
182 if (move)
183 { 180 {
184 complete = this.FileSystem.MoveFile(source, destination); 181 if (extension.CopyFile(source, destination))
185 } 182 {
186 else 183 return;
187 { 184 }
188 complete = this.FileSystem.CopyFile(source, destination);
189 } 185 }
190 186
191 if (!complete) 187 FileSystem.CopyFile(source, destination, allowHardlink: true);
188 }
189
190 private void MoveFile(string source, string destination)
191 {
192 foreach (var extension in this.Extensions)
192 { 193 {
193 throw new InvalidOperationException(); // TODO: something needs to be said here that none of the binder file managers returned a result. 194 if (extension.MoveFile(source, destination))
195 {
196 return;
197 }
194 } 198 }
199
200 FileSystem.MoveFile(source, destination);
195 } 201 }
196 } 202 }
197} 203}