[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

svn_io_file_rename preserves *destination* file permission on Windows

From: Ivan Zhakov <chemodax_at_gmail.com>
Date: 2005-11-14 19:52:12 CET

Hi, Brane and Devs!
Today we with Erik Huelsman tried to fix switch_tests.py 17 test
failing on Windows. After investigation we found very strange thing:
svn_io_file_rename preserves *destination* file permissions on
Windows. Please look to code (I have removed all #ifdef to improve
readabilty):
svn_error_t *
svn_io_file_rename (const char *from_path, const char *to_path,
                    apr_pool_t *pool)
{
  apr_status_t status = APR_SUCCESS;
  const char *from_path_apr, *to_path_apr;

  /* Set the file writable but only on Windows, because Windows will
     not allow us to rename files that are read-only. But preserve the
     state of the read-only flag on the destination. */
  svn_boolean_t was_read_only;
  apr_finfo_t finfo;

  SVN_ERR (svn_io_set_file_read_write (from_path, FALSE, pool));

  SVN_ERR (svn_path_cstring_from_utf8 (&from_path_apr, from_path, pool));
  SVN_ERR (svn_path_cstring_from_utf8 (&to_path_apr, to_path, pool));

  status = apr_stat (&finfo, to_path_apr, APR_FINFO_PROT, pool);
  if (APR_STATUS_IS_ENOENT (status))
    {
      was_read_only = FALSE;
      status = APR_SUCCESS;
    }
  else if (!status)
    {
      /* Note: apr_stat doesn't look at just the read-only bit. It's
         concievable that we get a positive result here because of
         file permissions. But that shouldn't happen in a Subversion
         working copy, and then set_read_write will fail, so the end
         result is the same. */
      was_read_only = !(finfo.protection
                        & (APR_UWRITE | APR_GWRITE | APR_WWRITE));
      if (was_read_only)
        SVN_ERR (svn_io_set_file_read_write (to_path, FALSE, pool));
    }

  if (!status)
    {
      status = apr_file_rename (from_path_apr, to_path_apr, pool);
      WIN32_RETRY_LOOP (status,
                        apr_file_rename (from_path_apr, to_path_apr, pool));
    }

  if (status)
    return svn_error_wrap_apr (status, _("Can't move '%s' to '%s'"),
                               svn_path_local_style (from_path, pool),
                               svn_path_local_style (to_path, pool));

  if (was_read_only)
    SVN_ERR (svn_io_set_file_read_only (to_path, FALSE, pool));

  return SVN_NO_ERROR;
}

This behavior was added in r14304 by Brane for fix issue #2278. I
understand for what we clear destinition file's read-only.
On Linux mv doesn't preserves destination permisions, why we have
different behavior on Windows?

--
Ivan Zhakov
Received on Mon Nov 14 19:53:30 2005

This is an archived mail posted to the Subversion Dev mailing list.