Skip to content

Commit 6aad670

Browse files
authored
Merge pull request #2723 from JuliaLang/backports-release-1.6
Backports release 1.6
2 parents ab8f6c8 + 9f74abe commit 6aad670

File tree

2 files changed

+46
-9
lines changed

2 files changed

+46
-9
lines changed

src/API.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1337,7 +1337,9 @@ function instantiate(ctx::Context; manifest::Union{Bool, Nothing}=nothing,
13371337
return instantiate(Context(); manifest=manifest, update_registry=update_registry, verbose=verbose, kwargs...)
13381338
end
13391339
if (!isfile(ctx.env.manifest_file) && manifest === nothing) || manifest == false
1340-
up(ctx; update_registry=update_registry)
1340+
# given no manifest exists, only allow invoking a registry update if there are project deps
1341+
allow_registry_update = isfile(ctx.env.project_file) && !isempty(ctx.env.project.deps)
1342+
up(ctx; update_registry = update_registry && allow_registry_update)
13411343
return
13421344
end
13431345
if !isfile(ctx.env.manifest_file) && manifest == true

src/Types.jl

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -436,15 +436,50 @@ function write_env_usage(source_file::AbstractString, usage_filepath::AbstractSt
436436
# Ensure that log dir exists
437437
!ispath(logdir()) && mkpath(logdir())
438438

439-
# Generate entire entry as a string first
440-
entry = sprint() do io
441-
TOML.print(io, Dict(source_file => [Dict("time" => now())]))
442-
end
443-
444-
# Append entry to log file in one chunk
445439
usage_file = joinpath(logdir(), usage_filepath)
446-
open(usage_file, append=true) do io
447-
write(io, entry)
440+
timestamp = now()
441+
442+
## Atomically write usage file
443+
while true
444+
# read existing usage file
445+
usage = if isfile(usage_file)
446+
TOML.parsefile(usage_file)
447+
else
448+
Dict{String, Any}()
449+
end
450+
451+
# record new usage
452+
usage[source_file] = [Dict("time" => timestamp)]
453+
454+
# keep only latest usage info
455+
for k in keys(usage)
456+
times = map(d -> Dates.DateTime(d["time"]), usage[k])
457+
usage[k] = [Dict("time" => maximum(times))]
458+
end
459+
460+
# Write to a temp file in the same directory as the destination
461+
temp_usage_file = tempname(logdir())
462+
open(temp_usage_file, "w") do io
463+
TOML.print(io, usage, sorted=true)
464+
end
465+
466+
# Move the temp file into place, replacing the original
467+
mv(temp_usage_file, usage_file, force = true)
468+
469+
# Check that the new file has what we want in it
470+
new_usage = if isfile(usage_file)
471+
TOML.parsefile(usage_file)
472+
else
473+
Dict{String, Any}()
474+
end
475+
if haskey(new_usage, source_file)
476+
for e in new_usage[source_file]
477+
if Dates.DateTime(e["time"]) >= timestamp
478+
return
479+
end
480+
end
481+
end
482+
# If not, try again
448483
end
449484
end
450485

0 commit comments

Comments
 (0)