1
0
mirror of https://github.com/bitwarden/server.git synced 2024-12-05 14:23:30 +01:00
bitwarden-server/test/Core.Test/TempDirectory.cs

39 lines
763 B
C#
Raw Normal View History

2022-08-29 22:06:55 +02:00
namespace Bit.Core.Test;
public class TempDirectory : IDisposable
{
2022-08-29 22:06:55 +02:00
public string Directory { get; private set; }
2022-08-29 22:06:55 +02:00
public TempDirectory()
{
Directory = Path.Combine(Path.GetTempPath(), $"bitwarden_{Guid.NewGuid().ToString().Replace("-", "")}");
}
2022-08-29 22:06:55 +02:00
public override string ToString() => Directory;
2022-08-29 22:06:55 +02:00
#region IDisposable implementation
~TempDirectory()
{
Dispose(false);
}
2022-08-29 22:06:55 +02:00
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
2022-08-29 22:06:55 +02:00
public void Dispose(bool disposing)
{
if (disposing)
{
2022-08-29 22:06:55 +02:00
try
{
2022-08-29 22:06:55 +02:00
System.IO.Directory.Delete(Directory, true);
}
2022-08-29 22:06:55 +02:00
catch { }
}
}
2022-08-29 22:06:55 +02:00
# endregion
}