bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Our thought about fixing the problem of cp --recursive


From: Jim Meyering
Subject: Re: Our thought about fixing the problem of cp --recursive
Date: Thu, 27 Dec 2007 14:19:56 +0100

Cai Xianchao <address@hidden> wrote:
> hi, Jim
>
> We decide to take your suggestion after researching fts and remove.c.
> Use fts to perform the source-tree traversal and traverse the destination
> tree by keeping two file descriptors.
> Thank you for your suggestion.   :-)
>
> But we find some problems during our research. There are some coreutils
> library functions that may fail due to ENAMETOOLONG. Such as
> same_name
> utimecmp
> futimens
> utimens
> gl_futimens
> euidaccess
> savedir
> copy_acl
> set_acl
> qset_acl
> areadlink_with_size
>
> Functions that call the above function(s) may fail, so we decide to
> rewrite these coreutils library functions. Do you have any better
> suggestions?

Yes, you will need file-descriptor-based versions of those
functions.  For example, a same_name_at function would
take two file descriptors and two entry names and perform operations
very similar to those of the existing same_name function.
The only difference is that all operations in the new function
would use file descriptor *at functions, like fstatat, rather
than lstat or stat, and fpathconf rather than pathconf.
In fact, since the directory file descriptors will be provided,
the new function won't have to perform any *stat* call at all.

A properly written version of cp will avoid even forming
the full name of each copied file.  The only reason to form
a full name is to present it in a diagnostic or in an interactive
prompt.

Bear in mind that many of those functions are gnulib modules.
For each module you write, you will want to create the following
new files, e.g.,

  gl/modules/same-name-at
  gl/m4/same-name-at.m4
  gl/lib/same-name-at.c
  gl/lib/same-name-at.h

Then add same-name-at to the list of modules in coreutils'
bootstrap.conf.

There is already a futimensat function in recent Linux
kernels, and it should be easy to add emulation support
for it in gnulib.

Note that euidaccess is problematic.
Since you've been reading remove.c, you may have already noticed
the long comment in the write_protected_non_symlink function.
copy.c will need something similar.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]