Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Verify statefile integrity in cache #152

Merged
merged 1 commit into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions src/Actions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ using Base64
using FromFile

@from "./MoreAnalysis.jl" import bound_variable_connections_graph
@from "./Export.jl" import try_get_exact_pluto_version, try_fromcache, try_tocache
@from "./Export.jl" import try_get_exact_pluto_version,
try_fromcache, try_tocache, write_statefile
@from "./Types.jl" import NotebookSession, RunningNotebook, FinishedNotebook, RunResult
@from "./Configuration.jl" import PlutoDeploySettings, is_glob_match
@from "./FileHelpers.jl" import find_notebook_files_recursive
Expand Down Expand Up @@ -271,12 +272,6 @@ function generate_static_export(
@debug "Written to $(export_html_path)"
end

function write_statefile(path, state)
data = Pluto.pack(state)
write(path, data)
@assert read(path) == data
end

tryrm(x) = isfile(x) && rm(x)

function remove_static_export(path; settings, output_dir)
Expand Down
17 changes: 14 additions & 3 deletions src/Export.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@ import Pluto: Pluto, ServerSession
using HTTP
import Pkg

export write_statefile

function write_statefile(path, state; verify::Bool=true)
data = Pluto.pack(state)
write(path, data)
if verify
input_data = read(path)
@assert input_data == data
input_state = Pluto.unpack(input_data)
@assert sort(collect(keys(state))) == sort(collect(keys(input_state)))
end
end


## CACHE

Expand Down Expand Up @@ -32,9 +45,7 @@ try_fromcache(cache_dir::Nothing, current_hash) = nothing
function try_tocache(cache_dir::String, current_hash::String, state)
mkpath(cache_dir)
try
open(cache_filename(cache_dir, current_hash), "w") do io
Pluto.pack(io, state)
end
write_statefile(cache_filename(cache_dir, current_hash), state)
catch e
@warn "Failed to write to cache file" current_hash exception =
(e, catch_backtrace())
Expand Down
Loading