Commit c80ed92 for stable-diffusion.cpp

commit c80ed92a5463b125a21a3af6fa332f447c7e5e9f
Author: KuhnChris <761911+kuhnchris@users.noreply.github.com>
Date:   Fri Nov 27 17:44:49 2026 +0100

    feat(server): configurable write directory via --output-dir (#2442)

diff --git a/examples/server/README.md b/examples/server/README.md
index deea974..ce97cb2 100644
--- a/examples/server/README.md
+++ b/examples/server/README.md
@@ -176,7 +176,9 @@ Scripts are listed and saved in the server's working directory under
 are relative to the server's working directory. Model files and their
 dependencies must reside under one of the configured `--model-dir` roots.
 Write results under `output/` in the working directory. For example,
-`image::save("output/result.png", image)` saves a PNG.
+`image::save("output/result.png", image)` saves a PNG. Use `--output-dir` to
+redirect writable output to another directory; writes outside the resolved
+output directory are denied.

 ## Model management

diff --git a/examples/server/async_jobs.cpp b/examples/server/async_jobs.cpp
index 6a35a85..0621ffc 100644
--- a/examples/server/async_jobs.cpp
+++ b/examples/server/async_jobs.cpp
@@ -711,8 +711,12 @@ namespace {
 }

 void configure_server_file_access(ServerModels& models, const SDSvrParams& params, const SDContextParams& config) {
-    auto& policy                 = models.file_access;
-    policy                       = {get_model_roots(params), fs::weakly_canonical(fs::current_path()) / "output", {}, {}};
+    auto& policy = models.file_access;
+    const fs::path output_root =
+        params.output_dir.empty()
+            ? fs::weakly_canonical(fs::current_path()) / "output"
+            : fs::weakly_canonical(fs::absolute(fs::u8path(params.output_dir)));
+    policy                       = {get_model_roots(params), output_root, {}, {}};
     models.workspace_file_access = policy;
     for (const auto* directory : {&config.lora_model_dir, &config.hires_upscalers_dir})
         if (!directory->empty())
diff --git a/examples/server/runtime.cpp b/examples/server/runtime.cpp
index 0a3497c..0a6b80b 100644
--- a/examples/server/runtime.cpp
+++ b/examples/server/runtime.cpp
@@ -304,6 +304,8 @@ ArgOptions SDSvrParams::get_options() {
         {"-l", "--listen-ip", "server listen ip (default: 127.0.0.1)", 0, &listen_ip},
         {"", "--serve-html-path", "path to HTML file to serve at root (optional)", 0, &serve_html_path},
         {"", "--dgl-dir", "Web UI script directory (default: dgl)", 0, &dgl_dir},
+        {"", "--output-dir", "directory generated files may be written to (default: <working directory>/output)", 0,
+         &output_dir},
     };

     options.int_options = {
diff --git a/examples/server/runtime.h b/examples/server/runtime.h
index 50a5fb4..7989104 100644
--- a/examples/server/runtime.h
+++ b/examples/server/runtime.h
@@ -30,6 +30,7 @@ struct SDSvrParams {
     std::string dgl_dir = "dgl";
     bool media_view = true;
     std::vector<std::string> model_dirs;
+    std::string output_dir;
     std::vector<std::string> api_keys;
     std::string api_key_file;
     std::vector<std::string> cors_origins;