Skip to content

Commit a6ab735

Browse files
committed
Moved temp folder creation to FileUtils
1 parent b69beb2 commit a6ab735

File tree

4 files changed

+35
-34
lines changed

4 files changed

+35
-34
lines changed

src/Dotnet.Script.DependencyModel/Environment/RuntimeHelper.cs

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -95,37 +95,6 @@ private static string GetRuntimeIdentifier()
9595
return runtimeIdentifier;
9696
}
9797

98-
public static string CreateTempFolder(string targetDirectory)
99-
{
100-
if (!Path.IsPathRooted(targetDirectory))
101-
{
102-
throw new ArgumentOutOfRangeException(nameof(targetDirectory), "Must be a root path");
103-
}
104-
105-
var tempDirectory = Path.GetTempPath();
106-
var pathRoot = Path.GetPathRoot(targetDirectory);
107-
var targetDirectoryWithoutRoot = targetDirectory.Substring(pathRoot.Length);
108-
if (pathRoot.Length > 0 && IsWindows)
109-
{
110-
var driveLetter = pathRoot.Substring(0, 1);
111-
if (driveLetter == "\\")
112-
{
113-
targetDirectoryWithoutRoot = targetDirectoryWithoutRoot.TrimStart(new char[] { '\\' });
114-
driveLetter = "UNC";
115-
}
116-
117-
targetDirectoryWithoutRoot = Path.Combine(driveLetter, targetDirectoryWithoutRoot);
118-
}
119-
var pathToProjectDirectory = Path.Combine(tempDirectory, "scripts", targetDirectoryWithoutRoot);
120-
121-
if (!Directory.Exists(pathToProjectDirectory))
122-
{
123-
Directory.CreateDirectory(pathToProjectDirectory);
124-
}
125-
126-
return pathToProjectDirectory;
127-
}
128-
12998
internal static bool AppliesToCurrentRuntime(string runtime)
13099
{
131100
return string.IsNullOrWhiteSpace(runtime) || RuntimeMatcher.IsMatch(runtime);

src/Dotnet.Script.DependencyModel/ProjectSystem/FileUtils.cs

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
using Dotnet.Script.DependencyModel.Environment;
2+
using System;
23
using System.Collections.Generic;
34
using System.IO;
45
using System.Text;
@@ -17,5 +18,36 @@ public static string ReadFile(string path)
1718
}
1819
}
1920
}
21+
22+
public static string CreateTempFolder(string targetDirectory)
23+
{
24+
if (!Path.IsPathRooted(targetDirectory))
25+
{
26+
throw new ArgumentOutOfRangeException(nameof(targetDirectory), "Must be a root path");
27+
}
28+
29+
var tempDirectory = Path.GetTempPath();
30+
var pathRoot = Path.GetPathRoot(targetDirectory);
31+
var targetDirectoryWithoutRoot = targetDirectory.Substring(pathRoot.Length);
32+
if (pathRoot.Length > 0 && ScriptEnvironment.Instance.IsWindows)
33+
{
34+
var driveLetter = pathRoot.Substring(0, 1);
35+
if (driveLetter == "\\")
36+
{
37+
targetDirectoryWithoutRoot = targetDirectoryWithoutRoot.TrimStart(new char[] { '\\' });
38+
driveLetter = "UNC";
39+
}
40+
41+
targetDirectoryWithoutRoot = Path.Combine(driveLetter, targetDirectoryWithoutRoot);
42+
}
43+
var pathToProjectDirectory = Path.Combine(tempDirectory, "scripts", targetDirectoryWithoutRoot);
44+
45+
if (!Directory.Exists(pathToProjectDirectory))
46+
{
47+
Directory.CreateDirectory(pathToProjectDirectory);
48+
}
49+
50+
return pathToProjectDirectory;
51+
}
2052
}
2153
}

src/Dotnet.Script.DependencyModel/ProjectSystem/ScriptProjectProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ private void CopyNuGetConfigFile(string targetDirectory, string pathToProjectFil
109109

110110
private static string GetPathToProjectFile(string targetDirectory)
111111
{
112-
var pathToProjectDirectory = RuntimeHelper.CreateTempFolder(targetDirectory);
112+
var pathToProjectDirectory = FileUtils.CreateTempFolder(targetDirectory);
113113
var pathToProjectFile = Path.Combine(pathToProjectDirectory, "script.csproj");
114114
return pathToProjectFile;
115115
}

src/Dotnet.Script.Tests/ScriptPackagesTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ private static void BuildScriptPackages()
153153
private static string GetPathToPackagesFolder()
154154
{
155155
var targetDirectory = TestPathUtils.GetFullPathToTestFixture(Path.Combine("ScriptPackage", "packages"));
156-
return RuntimeHelper.CreateTempFolder(targetDirectory);
156+
return DependencyModel.ProjectSystem.FileUtils.CreateTempFolder(targetDirectory);
157157
}
158158

159159
private static void RemoveDirectory(string path)

0 commit comments

Comments
 (0)