analytics / lib /plausible /file.ex
Leon4gr45's picture
Upload folder using huggingface_hub (part 2)
8da2481 verified
Raw
History Blame Contribute Delete
685 Bytes
defmodule Plausible.File do
@moduledoc """
File helpers for Plausible.
"""
@doc """
Moves a file from one location to another.
Tries renaming first, and falls back to copying and deleting the original.
"""
@spec mv!(Path.t(), Path.t()) :: :ok
def mv!(source, destination) do
File.rename!(source, destination)
rescue
e in File.RenameError ->
try do
case e.reason do
# fallback to cp/rm for cross-device moves
# https://github.com/plausible/analytics/issues/4638
:exdev -> File.cp!(source, destination)
_ -> reraise(e, __STACKTRACE__)
end
after
File.rm(source)
end
end
end