diff options
author | Keith Dahlby <dahlbyk@gmail.com> | 2013-06-13 00:40:03 +0400 |
---|---|---|
committer | nulltoken <emeric.fermas@gmail.com> | 2013-06-17 10:08:42 +0400 |
commit | 7b8472d0afefb06b3668061f35baa619054e2637 (patch) | |
tree | a335f99fce03d13dfc4b38ed9b8a2f1e7330e06a /LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs | |
parent | 39716ec93b7be33e2c8c5117124d352a68ae6c69 (diff) |
Touch() should ensure parent directory exists
Diffstat (limited to 'LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs')
-rw-r--r-- | LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs b/LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs index 1c17c77c..eb9c2905 100644 --- a/LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs +++ b/LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Globalization; using System.IO; using System.Linq; @@ -213,14 +214,12 @@ namespace LibGit2Sharp.Tests.TestHelpers protected string Touch(string parent, string file, string content = null) { - var lastIndex = file.LastIndexOf('/'); - if (lastIndex > 0) - { - var parents = file.Substring(0, lastIndex); - Directory.CreateDirectory(Path.Combine(parent, parents)); - } + string filePath = Path.Combine(parent, file); + string dir = Path.GetDirectoryName(filePath); + Debug.Assert(dir != null); + + Directory.CreateDirectory(dir); - var filePath = Path.Combine(parent, file); File.AppendAllText(filePath, content ?? string.Empty, Encoding.ASCII); return file; |