mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-12-04 23:24:35 +00:00
Moved temporary files into a folder of their own below the data directory (#1245)
This commit is contained in:
1 parent
ddfc632b63
commit
12d3e1ec6c
52 files changed
+1219
-396
No files matched your search
@@ -1,4 +1,5 @@
|
||||
using System.Diagnostics;
|
||||
using System.Text;
|
||||
|
||||
using AIStudio.Tools.Rust;
|
||||
using AIStudio.Tools.Services;
|
||||
@@ -17,26 +18,33 @@ public sealed class PandocProcessBuilder
|
||||
// Tracks whether the first log has been written to avoid log spam on repeated calls:
|
||||
private static bool HAS_LOGGED_ONCE;
|
||||
|
||||
private string? providedInputFile;
|
||||
private string? providedOutputFile;
|
||||
private string? providedInputFormat;
|
||||
private string? providedOutputFormat;
|
||||
private bool useStandaloneMode;
|
||||
|
||||
private bool readsStandardInput;
|
||||
|
||||
private readonly List<string> additionalArguments = new();
|
||||
|
||||
|
||||
private PandocProcessBuilder()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
public static PandocProcessBuilder Create() => new();
|
||||
|
||||
public PandocProcessBuilder WithInputFile(string inputFile)
|
||||
|
||||
/// <summary>
|
||||
/// Lets Pandoc read its input from the standard input of the process, in UTF-8 without a byte order mark,
|
||||
/// which Pandoc expects; a mark would end up as a stray character at the start of the document.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// A text which AI Studio holds anyway thus needs no temporary file, see TemporaryFiles.
|
||||
/// </remarks>
|
||||
public PandocProcessBuilder WithStandardInput()
|
||||
{
|
||||
this.providedInputFile = inputFile;
|
||||
this.readsStandardInput = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public PandocProcessBuilder WithOutputFile(string outputFile)
|
||||
{
|
||||
this.providedOutputFile = outputFile;
|
||||
@@ -79,14 +87,17 @@ public sealed class PandocProcessBuilder
|
||||
CreateNoWindow = true
|
||||
};
|
||||
|
||||
if (this.readsStandardInput)
|
||||
{
|
||||
startInfo.RedirectStandardInput = true;
|
||||
startInfo.StandardInputEncoding = new UTF8Encoding(false);
|
||||
}
|
||||
|
||||
// Use argument tokens instead of a single command string so paths with spaces
|
||||
// or Unicode characters are passed to Pandoc unchanged on all platforms.
|
||||
if (this.useStandaloneMode)
|
||||
startInfo.ArgumentList.Add("--standalone");
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(this.providedInputFile))
|
||||
startInfo.ArgumentList.Add(this.providedInputFile);
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(this.providedInputFormat))
|
||||
{
|
||||
startInfo.ArgumentList.Add("-f");
|
||||
@@ -149,8 +160,9 @@ public sealed class PandocProcessBuilder
|
||||
}
|
||||
else if (!Directory.Exists(localInstallationRootDirectory))
|
||||
{
|
||||
// The usual case until the user installs Pandoc through AI Studio, so no warning:
|
||||
if (shouldLog)
|
||||
LOGGER.LogWarning("The local Pandoc installation directory does not exist: '{LocalInstallationRootDirectory}'.", localInstallationRootDirectory);
|
||||
LOGGER.LogInformation("The local Pandoc installation directory does not exist: '{LocalInstallationRootDirectory}'.", localInstallationRootDirectory);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -223,7 +235,7 @@ public sealed class PandocProcessBuilder
|
||||
// When no local installation was found, we assume that the pandoc executable is in the system PATH:
|
||||
//
|
||||
if (shouldLog)
|
||||
LOGGER.LogWarning("Falling back to system PATH for the Pandoc executable: '{ExecutableName}'.", PandocExecutableName);
|
||||
LOGGER.LogInformation("Falling back to system PATH for the Pandoc executable: '{ExecutableName}'.", PandocExecutableName);
|
||||
|
||||
return new(PandocExecutableName, false);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user