Skip to content

Commit

Permalink
Ensure all temp files created in subfolder of %TEMP%
Browse files Browse the repository at this point in the history
Fixes #492.
  • Loading branch information
drewnoakes committed Jul 24, 2024
1 parent e25d796 commit 8471eb4
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ private void AnyEvent(object sender, BuildEventArgs args)
return;
}

var logPath = Path.Combine(Path.GetTempPath(), $"{Guid.NewGuid()}.binlog");
var logPath = PathUtil.GetTempFileName($"{Guid.NewGuid()}.binlog");
var binaryLogger = new BinaryLogger
{
Parameters = logPath,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ protected string GetLogPath(Build build)

var filename = $"{Path.GetFileNameWithoutExtension(build.ProjectPath)}_{dimensionsString}{build.BuildType}_{build.StartTime:o}.binlog".Replace(':', '_');

return Path.Combine(Path.GetTempPath(), filename);
return PathUtil.GetTempFileName(filename);
}

protected void Copy(string from, string to)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ internal sealed class ProjectLogger : LoggerBase
public ProjectLogger(BackEndBuildTableDataSource dataSource, bool isDesignTime) :
base(dataSource)
{
_logPath = Path.Combine(Path.GetTempPath(), $"{Guid.NewGuid()}.binlog");
_logPath = PathUtil.GetTempFileName($"{Guid.NewGuid()}.binlog");
_binaryLogger = new BinaryLogger
{
Parameters = _logPath,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ private class RoslynTraceListener : TraceListener

public RoslynTraceListener(IImmutableSet<string> roslynEvents)
{
LogPath = Path.Combine(Path.GetTempPath(), $"RoslynLog-{Guid.NewGuid()}.txt");
LogPath = PathUtil.GetTempFileName($"RoslynLog-{Guid.NewGuid()}.txt");

_set = roslynEvents;

Expand Down
18 changes: 18 additions & 0 deletions src/ProjectSystemTools/Utilities/PathUtil.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the MIT license. See the LICENSE.md file in the project root for more information.

using Microsoft.IO;

namespace Microsoft.VisualStudio.ProjectSystem.Tools;

internal static class PathUtil
{
public static string GetTempFileName(string fileName)
{
string tempPath = Path.Combine(Path.GetTempPath(), "project-system-tools");

// Ensure our directory exists
Directory.CreateDirectory(tempPath);

return Path.Combine(tempPath, fileName);
}
}

0 comments on commit 8471eb4

Please sign in to comment.