From 530924d1c6e06d4cb39fce5d7c915aeba504b497 Mon Sep 17 00:00:00 2001 From: Guy Oliver Date: Thu, 12 Mar 2015 07:23:28 -0400 Subject: [PATCH] Modified combinePaths to work like Path.Combine to fix fsharp/FAKE#670 The original combinePaths insisted on stripping leading characters off of the second path, causing it to not behave like Path.Combine. /a/b/c joined with /d/e/f is supposed to come out as /d/e/f, but since the / was stripped on before we got /a/b/c/d/e/f, which caused certain operations to fail. --- src/app/Fake.Deploy/DeploymentHelper.fs | 12 ++++---- src/app/FakeLib/EnvironmentHelper.fs | 2 +- .../Test.FAKECore/EnvironmentHelperSpecs.cs | 30 +++++++++++++++++++ src/test/Test.FAKECore/Test.FAKECore.csproj | 3 +- 4 files changed, 39 insertions(+), 8 deletions(-) create mode 100644 src/test/Test.FAKECore/EnvironmentHelperSpecs.cs diff --git a/src/app/Fake.Deploy/DeploymentHelper.fs b/src/app/Fake.Deploy/DeploymentHelper.fs index ff596e40241..65303f4e849 100644 --- a/src/app/Fake.Deploy/DeploymentHelper.fs +++ b/src/app/Fake.Deploy/DeploymentHelper.fs @@ -29,7 +29,7 @@ let getActiveReleases dir = !!(dir @@ deploymentRootDir @@ "**/active/*.nupkg") /// Retrieves the NuSpec information for the active release of the given app. let getActiveReleaseFor dir (app : string) = - !!(dir @@ deploymentRootDir @@ app @@ "/active/*.nupkg") + !!(dir @@ deploymentRootDir @@ app @@ "active/*.nupkg") |> Seq.map GetMetaDataFromPackageFile |> Seq.head @@ -38,7 +38,7 @@ let getAllReleases dir = !!(dir @@ deploymentRootDir @@ "**/*.nupkg") |> Seq.map /// Retrieves the NuSpec information for all releases of the given app. let getAllReleasesFor dir (app : string) = - !!(dir @@ deploymentRootDir @@ app @@ "/**/*.nupkg") |> Seq.map GetMetaDataFromPackageFile + !!(dir @@ deploymentRootDir @@ app @@ "**/*.nupkg") |> Seq.map GetMetaDataFromPackageFile /// Returns statistics about the machine environment. let getStatistics() = getMachineEnvironment() @@ -102,7 +102,7 @@ let runDeploymentFromPackageFile workDir packageFileName scriptArgs = /// Rolls the given app back to the specified version let rollback workDir (app : string) (version : string) = try - let currentPackageFileName = !!(workDir @@ deploymentRootDir @@ app @@ "/active/*.nupkg") |> Seq.head + let currentPackageFileName = !!(workDir @@ deploymentRootDir @@ app @@ "active/*.nupkg") |> Seq.head let backupPackageFileName = getBackupFor workDir app version if currentPackageFileName = backupPackageFileName then Failure { Messages = Seq.empty @@ -138,10 +138,10 @@ let getVersionFromNugetFileName (app : string) (fileName : string) = /// Returns the version no. of the latest backup of the given app let getPreviousPackageVersionFromBackup dir app versions = let currentPackageFileName = - !!(dir @@ deploymentRootDir @@ app @@ "/active/*.nupkg") + !!(dir @@ deploymentRootDir @@ app @@ "active/*.nupkg") |> Seq.head |> getVersionFromNugetFileName app - !!(dir @@ deploymentRootDir @@ app @@ "/backups/*.nupkg") + !!(dir @@ deploymentRootDir @@ app @@ "backups/*.nupkg") |> Seq.map (getVersionFromNugetFileName app) |> Seq.filter (fun x -> x < currentPackageFileName) |> Seq.toList @@ -166,4 +166,4 @@ let rollbackTo workDir app versionInfo = Message = sprintf "Rollback to version (%s-%s) failed" app versionInfo Timestamp = DateTimeOffset.UtcNow } ] IsError = true - Exception = e } \ No newline at end of file + Exception = e } diff --git a/src/app/FakeLib/EnvironmentHelper.fs b/src/app/FakeLib/EnvironmentHelper.fs index 8c5dcee01f6..56dc1922a87 100644 --- a/src/app/FakeLib/EnvironmentHelper.fs +++ b/src/app/FakeLib/EnvironmentHelper.fs @@ -18,7 +18,7 @@ type EnvironTarget = EnvironmentVariableTarget let environVar name = Environment.GetEnvironmentVariable name /// Combines two path strings using Path.Combine -let inline combinePaths path1 (path2 : string) = Path.Combine(path1, path2.TrimStart [| '\\'; '/' |]) +let inline combinePaths path1 path2 = Path.Combine(path1, path2) /// Combines two path strings using Path.Combine let inline (@@) path1 path2 = combinePaths path1 path2 diff --git a/src/test/Test.FAKECore/EnvironmentHelperSpecs.cs b/src/test/Test.FAKECore/EnvironmentHelperSpecs.cs new file mode 100644 index 00000000000..efd71425c13 --- /dev/null +++ b/src/test/Test.FAKECore/EnvironmentHelperSpecs.cs @@ -0,0 +1,30 @@ +using System.Linq; +using Fake; +using Machine.Specifications; + +namespace Test.FAKECore +{ + public class when_combining_paths + { + It should_act_as_path_combine = + () => { + var testValues = new []{ + new []{"c:\\test", "dir\\asdf"}, + new []{"\\test", "dir\\asdf"}, + new []{"test", "dir\\asdf"}, + new []{"/test", "dir/asdf"}, + new []{"/test", "/dir/asdf"}, + new []{"c:\\test", "d:\\dir\\asdf"}, + new []{"/asdf/asdf/asdf/", "/asdf/asdf"}, + new []{"c:\\test", "\\\\dir\\asdf"}, + new []{"c:\\test", "/dir\\asdf"}, + }; + + foreach(var item in testValues) + { + EnvironmentHelper.combinePaths(item[0], item[1]) + .ShouldEqual(System.IO.Path.Combine(item[0], item[1])); + } + }; + } +} diff --git a/src/test/Test.FAKECore/Test.FAKECore.csproj b/src/test/Test.FAKECore/Test.FAKECore.csproj index 15a94b0f76f..ce1e48bcc99 100644 --- a/src/test/Test.FAKECore/Test.FAKECore.csproj +++ b/src/test/Test.FAKECore/Test.FAKECore.csproj @@ -108,6 +108,7 @@ + @@ -556,4 +557,4 @@ - \ No newline at end of file +