From 9b3350ebe4f01303a981c231ec4d50dd6123d4ec Mon Sep 17 00:00:00 2001 From: Ian Sinclair Date: Mon, 25 Sep 2023 15:10:59 -0400 Subject: [PATCH] Handle disk full errors --- lib/briefly.ex | 1 + lib/briefly/entry.ex | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/lib/briefly.ex b/lib/briefly.ex index 02a9e38..a51fa37 100644 --- a/lib/briefly.ex +++ b/lib/briefly.ex @@ -24,6 +24,7 @@ defmodule Briefly do """ @spec create(create_opts) :: {:ok, binary} + | {:no_space, binary} | {:too_many_attempts, binary, pos_integer} | {:no_tmp, [binary]} def create(opts \\ []) do diff --git a/lib/briefly/entry.ex b/lib/briefly/entry.ex index 05b6afe..d029a43 100644 --- a/lib/briefly/entry.ex +++ b/lib/briefly/entry.ex @@ -173,8 +173,14 @@ defmodule Briefly.Entry do :ets.insert(@path_table, {self(), path}) {:ok, path} + {:error, :enospc} -> + {:no_space, path} + {:error, reason} when reason in [:eexist, :eacces] -> open(options, tmp, attempts + 1) + + error -> + error end end @@ -186,8 +192,14 @@ defmodule Briefly.Entry do :ets.insert(@path_table, {self(), path}) {:ok, path} + {:error, :enospc} -> + {:no_space, path} + {:error, reason} when reason in [:eexist, :eacces] -> open(options, tmp, attempts + 1) + + error -> + error end end