@@ -15,6 +15,7 @@ import ..Pkg, ..Registry
1515import .. Pkg: GitTools, depots, depots1, logdir, set_readonly, safe_realpath, pkg_server, stdlib_dir, stdlib_path, isurl, stderr_f
1616import Base. BinaryPlatforms: Platform
1717using .. Pkg. Versions
18+ import .. Pkg. Pidfile
1819
1920import Base: SHA1
2021using SHA
@@ -466,9 +467,8 @@ function write_env_usage(source_file::AbstractString, usage_filepath::AbstractSt
466467 usage_file = joinpath (logdir (), usage_filepath)
467468 timestamp = now ()
468469
469- # # Atomically write usage file
470- while true
471- # read existing usage file
470+ # # Atomically write usage file using process id locking
471+ Pidfile. mkpidlock (usage_file * " .pidlock" ) do
472472 usage = if isfile (usage_file)
473473 TOML. parsefile (usage_file)
474474 else
@@ -484,30 +484,11 @@ function write_env_usage(source_file::AbstractString, usage_filepath::AbstractSt
484484 usage[k] = [Dict (" time" => maximum (times))]
485485 end
486486
487- # Write to a temp file in the same directory as the destination
488- temp_usage_file = tempname (logdir ())
489- open (temp_usage_file, " w" ) do io
487+ open (usage_file, " w" ) do io
490488 TOML. print (io, usage, sorted= true )
491489 end
492-
493- # Move the temp file into place, replacing the original
494- mv (temp_usage_file, usage_file, force = true )
495-
496- # Check that the new file has what we want in it
497- new_usage = if isfile (usage_file)
498- TOML. parsefile (usage_file)
499- else
500- Dict {String, Any} ()
501- end
502- if haskey (new_usage, source_file)
503- for e in new_usage[source_file]
504- if Dates. DateTime (e[" time" ]) >= timestamp
505- return
506- end
507- end
508- end
509- # If not, try again
510490 end
491+ return
511492end
512493
513494function read_package (path:: String )
0 commit comments