Mesa (master): mesa: don't overwrite existing shader files with MESA_SHADER_CAPTURE_PATH

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Fri Apr 12 15:38:05 UTC 2019


Module: Mesa
Branch: master
Commit: 467ff6ebfe984c5a829acee2b89f996b241f3a0d
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=467ff6ebfe984c5a829acee2b89f996b241f3a0d

Author: Marek Olšák <marek.olsak at amd.com>
Date:   Wed Apr 10 20:31:40 2019 -0400

mesa: don't overwrite existing shader files with MESA_SHADER_CAPTURE_PATH

Reviewed-by: Tapani Pälli <tapani.palli at intel.com>

---

 src/mesa/main/shaderapi.c | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/src/mesa/main/shaderapi.c b/src/mesa/main/shaderapi.c
index 01342c04e8f..6b73e6c7e7a 100644
--- a/src/mesa/main/shaderapi.c
+++ b/src/mesa/main/shaderapi.c
@@ -1240,10 +1240,24 @@ link_program(struct gl_context *ctx, struct gl_shader_program *shProg,
    /* Capture .shader_test files. */
    const char *capture_path = _mesa_get_shader_capture_path();
    if (shProg->Name != 0 && shProg->Name != ~0 && capture_path != NULL) {
-      FILE *file;
-      char *filename = ralloc_asprintf(NULL, "%s/%u.shader_test",
+      /* Find an unused filename. */
+      char *filename = NULL;
+      for (unsigned i = 0;; i++) {
+         if (i) {
+            filename = ralloc_asprintf(NULL, "%s/%u-%u.shader_test",
+                                       capture_path, shProg->Name, i);
+         } else {
+            filename = ralloc_asprintf(NULL, "%s/%u.shader_test",
                                        capture_path, shProg->Name);
-      file = fopen(filename, "w");
+         }
+         FILE *file = fopen(filename, "r");
+         if (!file)
+            break;
+         fclose(file);
+         ralloc_free(filename);
+      }
+
+      FILE *file = fopen(filename, "w");
       if (file) {
          fprintf(file, "[require]\nGLSL%s >= %u.%02u\n",
                  shProg->IsES ? " ES" : "",




More information about the mesa-commit mailing list