- @spec update_file(String.t(), String.t(), String.t(), String.t(), boolean()) ::
- {:ok, t()} | {:error, File.posix()} | {:error, :empty_values}
- def update_file(name, shortcode, new_shortcode, new_filename, force)
- when byte_size(name) > 0 and byte_size(shortcode) > 0 and byte_size(new_shortcode) > 0 and
- byte_size(new_filename) > 0 do
- with {_, %__MODULE__{} = pack} <- {:loaded, load_pack(name)},
- {_, {filename, files}} when not is_nil(filename) <-
- {:exists, Map.pop(pack.files, shortcode)},
- {_, true} <- {:not_used, force or is_nil(Emoji.get(new_shortcode))} do
- old_path = Path.join(pack.path, filename)
- old_dir = Path.dirname(old_path)
- new_path = Path.join(pack.path, new_filename)
-
- create_subdirs(new_path)
-
- :ok = File.rename(old_path, new_path)
-
- if String.contains?(filename, "/") and File.ls!(old_dir) == [] do
- File.rmdir!(old_dir)
+ @spec update_metadata(String.t(), map()) :: {:ok, t()} | {:error, File.posix()}
+ def update_metadata(name, data) do
+ with {:ok, pack} <- load_pack(name) do
+ if fallback_sha_changed?(pack, data) do
+ update_sha_and_save_metadata(pack, data)
+ else
+ save_metadata(data, pack)