mirror of
https://github.com/github/codeql.git
synced 2025-12-17 09:13:20 +01:00
41 lines
1.1 KiB
C#
41 lines
1.1 KiB
C#
using System;
|
|
using System.IO;
|
|
using Semmle.Util.Logging;
|
|
|
|
namespace Semmle.Util
|
|
{
|
|
/// <summary>
|
|
/// A temporary directory that is created within the system temp directory.
|
|
/// When this object is disposed, the directory is deleted.
|
|
/// </summary>
|
|
public sealed class TemporaryDirectory : IDisposable
|
|
{
|
|
private readonly string userReportedDirectoryPurpose;
|
|
private readonly ILogger logger;
|
|
|
|
public DirectoryInfo DirInfo { get; }
|
|
|
|
public TemporaryDirectory(string path, string userReportedDirectoryPurpose, ILogger logger)
|
|
{
|
|
DirInfo = new DirectoryInfo(path);
|
|
DirInfo.Create();
|
|
this.userReportedDirectoryPurpose = userReportedDirectoryPurpose;
|
|
this.logger = logger;
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
try
|
|
{
|
|
DirInfo.Delete(true);
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
logger.LogInfo($"Couldn't delete {userReportedDirectoryPurpose} directory {exc.Message}");
|
|
}
|
|
}
|
|
|
|
public override string ToString() => DirInfo.FullName.ToString();
|
|
}
|
|
}
|