bug-coreutils
[Top][All Lists]
Advanced

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

Re: [bug-gnulib] bug fix: mv and 'cp -r' no longer fail when ...


From: Bruno Haible
Subject: Re: [bug-gnulib] bug fix: mv and 'cp -r' no longer fail when ...
Date: Fri, 15 Sep 2006 20:17:21 +0200
User-agent: KMail/1.9.1

Hi,

Jim Meyering wrote:
> +static inline bool
> +has_trailing_slash (char const *file, size_t len)
> +{
> +  /* Don't count "/" as having a trailing slash.  */
> +  if (len <= 1)
> +    return false;
> +
> +  char last = file[len - 1];
> +  return ISSLASH (last);

Since you use ISSLASH, you apparently care about non-POSIX systems. But
then shouldn't the first test be this?

     if (len <= FILE_SYSTEM_PREFIX_LEN (file) + 1)
       return false;

> +  {
> +    /* Fail now, unless SRC is a directory.  */
> +    struct stat sb;
> +    if (lstat (src, &sb) != 0 || ! S_ISDIR (sb.st_mode))
> +      return ret_val;
> +  }
> +
> +  /* Don't call rename again if there are no trailing slashes.  */
> +  d_len = strlen (dst);
> +  if ( ! has_trailing_slash (dst, d_len))
> +    return ret_val;

How about reversing the order of these two tests? Doing an strlen
is much cheaper than a system call. If you do the trailing slash first,
you save a system call in many cases.

Bruno




reply via email to

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