From f4221bc281e34e3171ba8bc4b1e49d1f53aaf118 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Fri, 24 Jan 2025 08:37:42 +0100 Subject: Delete target file if generating tool fails, ensuring no half written/corrupted files are left on disk. --- src/task_fn.cc | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'src/task_fn.cc') diff --git a/src/task_fn.cc b/src/task_fn.cc index 1ff72f9..b6b50ea 100644 --- a/src/task_fn.cc +++ b/src/task_fn.cc @@ -74,10 +74,16 @@ int TaskFn::runInner() std::cout << output << std::flush; } - return config.function(sourceFile.string(), - targetFile().string(), - config, - settings); + auto res = config.function(sourceFile.string(), + targetFile().string(), + config, + settings); + if(res != 0) + { + std::filesystem::remove(targetFile()); + } + + return res; } int TaskFn::clean() -- cgit v1.2.3