From cafc97132678e7d5a14431d91e57784fb77cdc59 Mon Sep 17 00:00:00 2001
From: Johannes Pfeifer <jpfeifer@gmx.de>
Date: Thu, 19 Oct 2023 20:16:24 +0200
Subject: [PATCH] bug: do not remove +subfolder with fast option

Otherwise, expected files are not present

(cherry picked from commit 643face6ed380e34c1238e073f5036a91985a56c)
---
 doc/manual/source/running-dynare.rst | 8 +++++---
 matlab/dynare.m                      | 9 ++++++---
 2 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/doc/manual/source/running-dynare.rst b/doc/manual/source/running-dynare.rst
index 9b1c23fd6d..585c6d4bc5 100644
--- a/doc/manual/source/running-dynare.rst
+++ b/doc/manual/source/running-dynare.rst
@@ -408,9 +408,11 @@ by the ``dynare`` command.
 
     .. option:: fast
 
-        Only useful with model option :opt:`use_dll`. Don’t recompile the
-        MEX files when running again the same model file and the lists
-        of variables and the equations haven’t changed. We use a 32
+        Don’t rewrite the output files otherwise written to the disk by the preprocessor 
+        when re-running the same model file while the lists of variables and the equations 
+        haven’t changed. Note that the whole model still needs to be preprocessed. This option 
+        is most useful with model option :opt:`use_dll`, because 
+        the time-consuming compilation of the MEX files will be skipped. We use a 32
         bit checksum, stored in ``<model filename>/checksum``. There
         is a very small probability that the preprocessor misses a
         change in the model. In case of doubt, re-run without the fast
diff --git a/matlab/dynare.m b/matlab/dynare.m
index 2839ae1d5e..b57ebf83ce 100644
--- a/matlab/dynare.m
+++ b/matlab/dynare.m
@@ -180,6 +180,7 @@ preprocessoroutput = ~ismember('nopreprocessoroutput', varargin) && ...
 nolog = ismember('nolog', varargin) || ismember('nolog', file_opts);
 onlymacro = ismember('onlymacro', varargin) || ismember('onlymacro', file_opts);
 onlyjson = ismember('onlyjson', varargin) || ismember('onlyjson', file_opts);
+fast = ismember('fast', varargin) || ismember('fast', file_opts);
 
 % Start journal
 diary off
@@ -222,11 +223,13 @@ end
 % On MATLAB+Windows, the +folder may be locked by MATLAB, preventing its
 % removal by the preprocessor.
 % Trying to delete it here will actually fail, but surprisingly this allows
-% the preprocessor to actually remove the folder (see ModFile::writeOutputFiles())
+% the preprocessor to actually remove the folder (see ModFile::writeMOutput())
 % For an instance of this bug, see:
 % https://forum.dynare.org/t/issue-with-dynare-preprocessor-4-6-1/15448/1
-if ispc && ~isoctave && exist(['+',fname(1:end-4)],'dir')
-    [~,~]=rmdir(['+', fname(1:end-4)],'s');
+if ~fast
+    if ispc && ~isoctave && exist(['+',fname(1:end-4)],'dir')
+        [~,~]=rmdir(['+', fname(1:end-4)],'s');
+    end
 end
 
 % Under Windows, make sure the MEX file is unloaded (in the use_dll case),
-- 
GitLab