File tree Expand file tree Collapse file tree 1 file changed +20
-3
lines changed Expand file tree Collapse file tree 1 file changed +20
-3
lines changed Original file line number Diff line number Diff line change @@ -468,11 +468,28 @@ function write_env_usage(source_file::AbstractString, usage_filepath::AbstractSt
468468 TOML. print (io, Dict (source_file => [Dict (" time" => now ())]))
469469 end
470470
471- # Append entry to log file in one chunk
471+ # # Atomically write usage file
472472 usage_file = joinpath (logdir (), usage_filepath)
473- open (usage_file, append= true ) do io
474- write (io, entry)
473+ while true
474+ # read existing usage file
475+ existing_usage = isfile (usage_file) ? read (usage_file, String) : " "
476+
477+ # Write to a temp file in the same directory as the destination
478+ temp_usage_file = tempname (logdir ())
479+ open (temp_usage_file, " w" ) do io
480+ write (io, existing_usage)
481+ write (io, entry)
482+ end
483+
484+ # Move the temp file into place, replacing the original
485+ mv (temp_usage_file, usage_file, force = true )
486+
487+ # Check that the new file has what we want in it
488+ new_usage = read (usage_file, String)
489+ occursin (entry, new_usage) && break
490+ # If not, try again
475491 end
492+
476493end
477494
478495function read_package (path:: String )
You can’t perform that action at this time.
0 commit comments