From 9c0f3c310a9fcfacc4db7d97fc7292f18dc9401a Mon Sep 17 00:00:00 2001
From: Tobias Frisch <tfrisch@uni-koblenz.de>
Date: Sun, 18 Jul 2021 00:22:29 +0200
Subject: [PATCH] [#100] Fixed temporary files stacking up locally

Signed-off-by: Tobias Frisch <tfrisch@uni-koblenz.de>
---
 modules/upscaling/src/vkcv/upscaling/FSRUpscaling.cpp | 10 +++++++++-
 src/vkcv/File.cpp                                     |  3 ++-
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/modules/upscaling/src/vkcv/upscaling/FSRUpscaling.cpp b/modules/upscaling/src/vkcv/upscaling/FSRUpscaling.cpp
index bf386538..eab6fd07 100644
--- a/modules/upscaling/src/vkcv/upscaling/FSRUpscaling.cpp
+++ b/modules/upscaling/src/vkcv/upscaling/FSRUpscaling.cpp
@@ -61,7 +61,15 @@ namespace vkcv::upscaling {
 		
 		return compiler.compileSource(vkcv::ShaderStage::COMPUTE,
 									  FSR_PASS_GLSL_SHADER.c_str(),
-									  compiled, directory);
+									  [&directory, &compiled] (vkcv::ShaderStage shaderStage,
+									  		const std::filesystem::path& path) {
+				if (compiled) {
+					compiled(shaderStage, path);
+				}
+				
+				std::filesystem::remove_all(directory);
+			}, directory
+		);
 	}
 	
 	FSRUpscaling::FSRUpscaling(Core& core) :
diff --git a/src/vkcv/File.cpp b/src/vkcv/File.cpp
index df303afc..f4f07bd4 100644
--- a/src/vkcv/File.cpp
+++ b/src/vkcv/File.cpp
@@ -31,7 +31,7 @@ namespace vkcv {
 			return "";
 		}
 #else
-		int fd = mkstemp(name);
+		int fd = mkstemp(name); // creates a file locally
 		
 		if (fd == -1) {
 			vkcv_log(LogLevel::ERROR, "Temporary file path could not be generated");
@@ -39,6 +39,7 @@ namespace vkcv {
 		}
 		
 		close(fd);
+		remove(name); // removes the local file again
 #endif
 		
 		return tmp / name;
-- 
GitLab