diff --git a/lib/livebook/settings.ex b/lib/livebook/settings.ex
index 078414024..11d8afa89 100644
--- a/lib/livebook/settings.ex
+++ b/lib/livebook/settings.ex
@@ -11,18 +11,40 @@ defmodule Livebook.Settings do
@type file_system_id :: :local | String.t()
@doc """
- Returns the autosave path.
-
- TODO: Make this configurable in the UI.
+ Returns the current autosave path.
"""
@spec autosave_path() :: String.t() | nil
def autosave_path() do
case storage().fetch_key(:settings, "global", :autosave_path) do
{:ok, value} -> value
- :error -> Path.join(Livebook.Config.data_path(), "autosaved")
+ :error -> default_autosave_path()
end
end
+ @doc """
+ Returns the default autosave path.
+ """
+ @spec default_autosave_path() :: String.t()
+ def default_autosave_path() do
+ Path.join(Livebook.Config.data_path(), "autosaved")
+ end
+
+ @doc """
+ Sets the current autosave path.
+ """
+ @spec set_autosave_path(String.t()) :: :ok
+ def set_autosave_path(autosave_path) do
+ storage().insert(:settings, "global", autosave_path: autosave_path)
+ end
+
+ @doc """
+ Restores the default autosave path.
+ """
+ @spec reset_autosave_path() :: :ok
+ def reset_autosave_path() do
+ storage().delete_key(:settings, "global", :autosave_path)
+ end
+
@doc """
Returns all known filesystems with their associated ids.
diff --git a/lib/livebook/storage.ex b/lib/livebook/storage.ex
index bd0cbb979..deaed9a8e 100644
--- a/lib/livebook/storage.ex
+++ b/lib/livebook/storage.ex
@@ -49,6 +49,11 @@ defmodule Livebook.Storage do
"""
@callback delete(namespace(), entity_id()) :: :ok
+ @doc """
+ Deletes an attribute from given entity.
+ """
+ @callback delete_key(namespace(), entity_id(), attribute()) :: :ok
+
@spec current() :: module()
def current(), do: Application.fetch_env!(:livebook, :storage)
end
diff --git a/lib/livebook/storage/ets.ex b/lib/livebook/storage/ets.ex
index d095b574f..cc77d9186 100644
--- a/lib/livebook/storage/ets.ex
+++ b/lib/livebook/storage/ets.ex
@@ -75,6 +75,11 @@ defmodule Livebook.Storage.Ets do
GenServer.call(__MODULE__, {:delete, namespace, entity_id})
end
+ @impl Livebook.Storage
+ def delete_key(namespace, entity_id, key) do
+ GenServer.call(__MODULE__, {:delete_key, namespace, entity_id, key})
+ end
+
@spec start_link(keyword()) :: GenServer.on_start()
def start_link(opts) do
GenServer.start_link(__MODULE__, opts, name: __MODULE__)
@@ -99,14 +104,9 @@ defmodule Livebook.Storage.Ets do
@impl GenServer
def handle_call({:insert, namespace, entity_id, attributes}, _from, %{table: table} = state) do
- match_head = {{namespace, entity_id}, :"$1", :_, :_}
+ keys_to_delete = Enum.map(attributes, fn {key, _val} -> key end)
- guards =
- Enum.map(attributes, fn {key, _val} ->
- {:==, :"$1", key}
- end)
-
- :ets.select_delete(table, [{match_head, guards, [true]}])
+ delete_keys(table, namespace, entity_id, keys_to_delete)
timestamp = System.os_time(:millisecond)
@@ -125,6 +125,12 @@ defmodule Livebook.Storage.Ets do
{:reply, :ok, state, {:continue, :save_to_file}}
end
+ @impl GenServer
+ def handle_call({:delete_key, namespace, entity_id, key}, _from, %{table: table} = state) do
+ delete_keys(table, namespace, entity_id, [key])
+ {:reply, :ok, state, {:continue, :save_to_file}}
+ end
+
@impl GenServer
def handle_continue(:save_to_file, %{table: table} = state) do
file_path = String.to_charlist(config_file_path())
@@ -151,4 +157,12 @@ defmodule Livebook.Storage.Ets do
:ets.new(__MODULE__, [:protected, :duplicate_bag])
end
end
+
+ defp delete_keys(table, namespace, entity_id, keys) do
+ match_head = {{namespace, entity_id}, :"$1", :_, :_}
+
+ guards = Enum.map(keys, &{:==, :"$1", &1})
+
+ :ets.select_delete(table, [{match_head, guards, [true]}])
+ end
end
diff --git a/lib/livebook_web/live/settings_live.ex b/lib/livebook_web/live/settings_live.ex
index 90b5ae06b..522e15c8c 100644
--- a/lib/livebook_web/live/settings_live.ex
+++ b/lib/livebook_web/live/settings_live.ex
@@ -14,6 +14,10 @@ defmodule LivebookWeb.SettingsLive do
|> SidebarHelpers.shared_home_handlers()
|> assign(
file_systems: file_systems,
+ autosave_path_state: %{
+ file: autosave_dir(),
+ dialog_opened?: false
+ },
page_title: "Livebook - Settings"
)}
end
@@ -34,8 +38,8 @@ defmodule LivebookWeb.SettingsLive do
Here you can change global Livebook configuration. Keep in mind - that this configuration is not persisted and gets discarded as - soon as you stop the application. + that this configuration gets persisted and will be restored on application + launch.
@@ -57,6 +61,18 @@ defmodule LivebookWeb.SettingsLive do <% end %> + ++ A directory to temporarily keep notebooks until they are persisted. +
+