diff --git a/src/Actions.jl b/src/Actions.jl index 3b5c55a..4a0f411 100644 --- a/src/Actions.jl +++ b/src/Actions.jl @@ -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 @@ -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) diff --git a/src/Export.jl b/src/Export.jl index 277c4ae..d5a7a5f 100644 --- a/src/Export.jl +++ b/src/Export.jl @@ -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 @@ -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())