Why is there no `file:move` (was: Why, [...] maps but array?)

Hugo Mills hugo@REDACTED
Wed Aug 18 09:12:10 CEST 2021


   On POSIX systems at least, that's got very limited capabilities --
you can't rename a file across a mount boundary. Things like mv start
with that, but then have to fall back to making reflink copies(*) and
then simple byte-by-byte copy if the reflink fails. If it can't use
rename, it has to deal with copying all of the metadata as well as all
the file contents, as it's creating a new file before deleting the old
one.

   Python has os.rename, which implements only the rename(2) syscall,
but then expands on that with the much more involved shutil module,
which has copy and copy2 functions, which do all the complicated
fallbacks and metadata duplication (to different levels of precision).

   Hugo.

(*) Server-side copy, for some networked filesystems; CoW filesystems
have something that behaves similarly. btrfs calls it a reflink copy.

On Wed, Aug 18, 2021 at 09:01:34AM +0200, Andrei Dziahel wrote:
> Try file:rename
> 
> On Tue, Aug 17, 2021, 17:33 Michael P. <empro2@REDACTED> wrote:
> 
> > On Sat, 14 Aug 2021 18:42:40 -0400
> > "Lloyd R. Prentice" <lloyd@REDACTED> wrote:
> >
> > I cannot assess the perils that may lurk within this:
> > ```
> > move_file(From, To) ->
> >     Content = file:read_file(From),
> >     file:write_file(To, Content),
> >     file:delete(From).
> >
> > ```
> > Thus, such is not fit for inclusion in "the library".
> >
> > It may serve some purpose, but its flaws
> > would lead to people desiring, requesting,
> > and possibly demanding some `file:DWIM...`.
> > And relieving such desire is not feasible:
> > deeper look into system => more dread => more work.
> >
> > So each gets to write their own DWYW function or module,
> > be content with it, maybe spread it,
> > suffer from its flaws, develop it, discuss it.
> > And, at some time, possibly, it may be included in "the library",
> > making Erlang a better language.
> >
> > ~Michael
> >

-- 
Hugo Mills             | The gates of heaven will always be closed to the
hugo@REDACTED carfax.org.uk | Morris dancers.
http://carfax.org.uk/  |
PGP: E2AB1DE4          |                                        William Prynne


More information about the erlang-questions mailing list