Skip to content

Commit

Permalink
Also use the path that was specified with SetTempDirectory when Magic…
Browse files Browse the repository at this point in the history
…kNET needs to create temporary files.
  • Loading branch information
dlemstra committed Oct 19, 2023
1 parent d284055 commit cd07e1e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Magick.NET/Helpers/TemporaryFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ internal sealed class TemporaryFile : IDisposable
private readonly FileInfo _tempFile;

public TemporaryFile()
=> _tempFile = new FileInfo(Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()));
=> _tempFile = new FileInfo(Path.Combine(MagickNET.TemporaryDirectory, Guid.NewGuid().ToString()));

public long Length
{
Expand Down
9 changes: 7 additions & 2 deletions src/Magick.NET/MagickNET.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@ string IMagickNET.ImageMagickVersion
string IMagickNET.Version
=> Version;

internal static string TemporaryDirectory { get; private set; } = Path.GetTempPath();

/// <summary>
/// Gets the environment variable with the specified name.
/// </summary>
Expand Down Expand Up @@ -244,7 +246,7 @@ public static string Initialize(IConfigurationFiles configFiles)
{
Throw.IfNull(nameof(configFiles), configFiles);

var path = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
var path = Path.Combine(TemporaryDirectory, Guid.NewGuid().ToString());
Directory.CreateDirectory(path);

InitializeConfiguration(configFiles, path);
Expand Down Expand Up @@ -358,7 +360,10 @@ public static void SetNativeLibraryDirectory(string path)
/// </summary>
/// <param name="path">The path where temp files will be written.</param>
public static void SetTempDirectory(string path)
=> Environment.SetEnv("MAGICK_TEMPORARY_PATH", FileHelper.GetFullPath(path));
{
TemporaryDirectory = FileHelper.GetFullPath(path);
Environment.SetEnv("MAGICK_TEMPORARY_PATH", TemporaryDirectory);
}

/// <summary>
/// Sets the pseudo-random number generator secret key.
Expand Down

0 comments on commit cd07e1e

Please sign in to comment.