mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-11-09 13:44:53 +08:00
Check for flag instead of non-empty dir (#2176)
This commit is contained in:
parent
3ab0ab495d
commit
7ff6103475
1 changed files with 4 additions and 6 deletions
|
|
@ -290,18 +290,20 @@ defmodule Livebook.Session do
|
||||||
@spec fetch_assets(pid(), String.t()) :: :ok | {:error, String.t()}
|
@spec fetch_assets(pid(), String.t()) :: :ok | {:error, String.t()}
|
||||||
def fetch_assets(pid, hash) do
|
def fetch_assets(pid, hash) do
|
||||||
local_assets_path = local_assets_path(hash)
|
local_assets_path = local_assets_path(hash)
|
||||||
|
flag_path = Path.join(local_assets_path, ".lb-done")
|
||||||
|
|
||||||
if non_empty_dir?(local_assets_path) do
|
if File.exists?(flag_path) do
|
||||||
:ok
|
:ok
|
||||||
else
|
else
|
||||||
with {:ok, runtime, archive_path} <-
|
with {:ok, runtime, archive_path} <-
|
||||||
GenServer.call(pid, {:get_runtime_and_archive_path, hash}, @timeout) do
|
GenServer.call(pid, {:get_runtime_and_archive_path, hash}, @timeout) do
|
||||||
fun = fn ->
|
fun = fn ->
|
||||||
# Make sure the file hasn't been fetched by this point
|
# Make sure the file hasn't been fetched by this point
|
||||||
unless non_empty_dir?(local_assets_path) do
|
unless File.exists?(flag_path) do
|
||||||
{:ok, archive_binary} = Runtime.read_file(runtime, archive_path)
|
{:ok, archive_binary} = Runtime.read_file(runtime, archive_path)
|
||||||
extract_archive!(archive_binary, local_assets_path)
|
extract_archive!(archive_binary, local_assets_path)
|
||||||
gzip_files(local_assets_path)
|
gzip_files(local_assets_path)
|
||||||
|
File.touch(flag_path)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -315,10 +317,6 @@ defmodule Livebook.Session do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
defp non_empty_dir?(path) do
|
|
||||||
match?({:ok, [_ | _]}, File.ls(path))
|
|
||||||
end
|
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
Sends notebook attributes update to the server.
|
Sends notebook attributes update to the server.
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue