summaryrefslogtreecommitdiffstats
path: root/src/DotNetOpenAuth.BuildTasks/HardLinkCopy.cs
diff options
context:
space:
mode:
authorAndrew Arnott <andrewarnott@gmail.com>2010-01-31 21:34:41 -0800
committerAndrew Arnott <andrewarnott@gmail.com>2010-01-31 21:34:41 -0800
commit17e1e88e7f75c86a6d4494dd2cb59eb9a7e75280 (patch)
tree27c1e400cdb7712a05b1577d0583cf6d5de49375 /src/DotNetOpenAuth.BuildTasks/HardLinkCopy.cs
parent7b741da22d416744bf8f6f75c7a55552d1c1feca (diff)
parent4341ce681fbe4ff9b4a6b80127f495347f647dc7 (diff)
downloadDotNetOpenAuth-17e1e88e7f75c86a6d4494dd2cb59eb9a7e75280.zip
DotNetOpenAuth-17e1e88e7f75c86a6d4494dd2cb59eb9a7e75280.tar.gz
DotNetOpenAuth-17e1e88e7f75c86a6d4494dd2cb59eb9a7e75280.tar.bz2
Upgraded solution to Visual Studio 2010.
Merge branch 'master-Dev10'
Diffstat (limited to 'src/DotNetOpenAuth.BuildTasks/HardLinkCopy.cs')
-rw-r--r--src/DotNetOpenAuth.BuildTasks/HardLinkCopy.cs61
1 files changed, 61 insertions, 0 deletions
diff --git a/src/DotNetOpenAuth.BuildTasks/HardLinkCopy.cs b/src/DotNetOpenAuth.BuildTasks/HardLinkCopy.cs
new file mode 100644
index 0000000..af2d1d0
--- /dev/null
+++ b/src/DotNetOpenAuth.BuildTasks/HardLinkCopy.cs
@@ -0,0 +1,61 @@
+//-----------------------------------------------------------------------
+// <copyright file="HardLinkCopy.cs" company="Andrew Arnott">
+// Copyright (c) Andrew Arnott. All rights reserved.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace DotNetOpenAuth.BuildTasks {
+ using System;
+ using System.Collections.Generic;
+ using System.Linq;
+ using System.Text;
+ using Microsoft.Build.Framework;
+ using Microsoft.Build.Utilities;
+ using System.IO;
+
+ public class HardLinkCopy : Task {
+ [Required]
+ public ITaskItem[] SourceFiles { get; set; }
+
+ [Required]
+ public ITaskItem[] DestinationFiles { get; set; }
+
+ /// <summary>
+ /// Executes this instance.
+ /// </summary>
+ public override bool Execute() {
+ if (this.SourceFiles.Length != this.DestinationFiles.Length) {
+ this.Log.LogError("SourceFiles has {0} elements and DestinationFiles has {1} elements.", this.SourceFiles.Length, this.DestinationFiles.Length);
+ return false;
+ }
+
+ for (int i = 0; i < this.SourceFiles.Length; i++) {
+ bool hardLink;
+ bool.TryParse(this.DestinationFiles[i].GetMetadata("HardLink"), out hardLink);
+ string sourceFile = this.SourceFiles[i].ItemSpec;
+ string destinationFile = this.DestinationFiles[i].ItemSpec;
+ this.Log.LogMessage(
+ MessageImportance.Low,
+ "Copying {0} -> {1}{2}.",
+ sourceFile,
+ destinationFile,
+ hardLink ? " as hard link" : string.Empty);
+
+ if (!Directory.Exists(Path.GetDirectoryName(destinationFile))) {
+ Directory.CreateDirectory(Path.GetDirectoryName(destinationFile));
+ }
+
+ if (hardLink) {
+ if (File.Exists(destinationFile)) {
+ File.Delete(destinationFile);
+ }
+ NativeMethods.CreateHardLink(sourceFile, destinationFile);
+ } else {
+ File.Copy(sourceFile, destinationFile, true);
+ }
+ }
+
+ return !this.Log.HasLoggedErrors;
+ }
+ }
+}