Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use GetRandomFileName when creating random temp folder to avoid conflict #5229

Merged
merged 5 commits into from
Jun 11, 2020
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 2 additions & 23 deletions src/Microsoft.ML.Core/Data/Repository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,32 +118,11 @@ internal Repository(bool needDir, IExceptionContext ectx)

private static string GetShortTempDir()
{
var rnd = RandomUtils.Create();
string path;
do
{
path = Path.Combine(Path.GetTempPath(), "TLC_" + rnd.Next().ToString("X"));
path = Path.GetFullPath(path);
Directory.CreateDirectory(path);
}
while (!EnsureDirectory(path));
var path = Path.Combine(Path.GetFullPath(Path.GetTempPath()), "ml_dotnet");
Directory.CreateDirectory(path);
return path;
}

private static bool EnsureDirectory(string path)
{
path = Path.GetFullPath(Path.Combine(path, ".lock"));
try
{
using (var stream = new FileStream(path, FileMode.CreateNew))
return true;
}
catch
{
return false;
}
}

~Repository()
{
if (!Disposed)
Expand Down