THIS MESSAGE WAS DESCRIBING THE PROBLEM, WHICH TURNED OUT NOT A BEING A SUSPECTED BUG, AND WAS EXPLAINED CORRECTLY BY BELOW.


Dear All,

in my code a temporary file is used to store intermediate results, which are passed from one routine to another.

However the file disappears somewhere during the transition from one procedure to another.

The following is the debug trace which localizes the problem:
Array



The code is essentially:

Code:
// ---------------------------------------------------------
FILE: campreport.ado
// ---------------------------------------------------------

program define campreport
    syntax , results(string)
    putpdf begin
    // .....................
    set tracedepth 7
    set trace on
    display "BEGIN"
    confirm file `"`results'"'                    
    display "BEFORE"
    puttextfile `"`results'"'
    display "AFTER"
    set trace off
    // .....................
end

program define puttextfile
    syntax [anything]
    display as input `"[[`anything']]"'
    confirm file `"`anything'"'
    display "File confirmed"
    // .................................
end

// ---------------------------------------------------------

This is being executed in Stata 16.0 on Windows 10 platform. The user name redacted in the screenshot is irrelevant to the problem and is the same in all instances where it is redacted.
There is absolutely no other code between the green line where the file is confirmed and the red line where the file is refuted.

Finally, the most baffling part is that if I run step-by-step, the file does actually exist on the disk when the blue line is running. But then disappears by the red line.

In the absence of any other suspect, I believe this is a bug.

If this matters for the investigation:
  • the name of the file is coming from the Stata's tempfile command and obtained at several levels-higher procedure;
  • the file is a log file with properly executed log using and log close commands;
  • the saved log is then trickled down through a series of nested calls to the output routine campreport in campreport.ado;
  • the report building procedure is called before the end of the scope in which the temporary file name was obtained;
  • I have further waited for a few minutes on the blue line to see if the file disappears from disk on its own and it doesn't. It is only removed when it is further addressed in the code (whether with the confirm or with subsequent file open statement).
  • this behavior was observed in multiple runs and is not a one-off random behavior.
  • the temp folder is not part of any dropbox/google drive or similar system which may be locking the files for external reasons.
Any insights would be greatly appreciated.

Thank you, Sergiy Radyakin