Re: File Module: $target in file:copy()

On 2 December 2013 18:42, Christian Grün wrote:

>>   Why do not copy the directory itself in the latter case?

> This is how file:copy and file:move is actually specified in the
> latest spec: “if $target is a directory, the source directory with all
> its files will be copied into the target directory”. [1]

  Oops, yes indeed, I was looking at the current spec at
http://expath.org/spec/file.  Which says: "if $target is a directory,
the source directory with all its files will be copied into the target
directory. If a file already exists, it will be overwritten."

  What does it mean, "overwritten", for a directory?  Is it going to
be completely deleted first?  Are are all files from the source copied
(recursively) to the target, each overriding any corresponding target
if they exist?

>>   2) Furthermore, I wonder whether we should not rather use the
>> convention that directories are identified by a trailing slash.

> [...]
> Instead, we’d have to add various error checks to cover cases in
> which the string syntax does not match the actual operation (e.g.:
> file:create-dir("abc") ).

  The trailing slash convention would give the user this ability, just
by using a different name.  E.g. both following expressions would be
equivalent (both would throw an error if 'target' already exist and is
a file):

    (
      if ( file:is-dir('target') ) then
        ()
      else
        file:create-dir('target'),
      file:copy('...', 'target')
    )

    file:copy('...', 'target/')

  Just my 2 cents.  Regards,

-- 
Florent Georges
http://fgeorges.org/
http://h2oconsulting.be/

Received on Monday, 2 December 2013 18:42:41 UTC