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

Re: svn commit: r16293 - trunk/subversion/libsvn_wc

From: Erik Huelsmann <ehuels_at_gmail.com>
Date: 2005-09-27 23:39:25 CEST

> > Finally, although this might be premature generalization: maybe it
> > would be better to wrap the new functionality in a new API,
> > svn_io_rename_insist() or something, so that we don't reimplement this
> > logic in other places? At least, I know that I won't remember to look
> > back here in update_editor.c if this ever comes up again...
>
> Ok. How about the patch below?

[patch snipped because of non-compilation problem]

Ok, this is a patch which actually compiles:

Index: subversion/include/svn_io.h
===================================================================
--- subversion/include/svn_io.h (revision 16265)
+++ subversion/include/svn_io.h (working copy)
@@ -899,6 +899,15 @@
                     apr_pool_t *pool);

+/** Wrapper for svn_io_file_rename(), which falls back to svn_io_copy if
+ * a cross device rename is encountered. @a from_path and @a to_path
+ * are utf8-encoded.
+ */
+svn_error_t *
+svn_io_file_rename_ensure (const char *from_path, const char *to_path,
+ apr_pool_t *pool);
+
+
 /** Wrapper for apr_dir_make(), which see. @a path is utf8-encoded. */
 svn_error_t *
 svn_io_dir_make (const char *path, apr_fileperms_t perm, apr_pool_t *pool);
Index: subversion/libsvn_subr/io.c
===================================================================
--- subversion/libsvn_subr/io.c (revision 16265)
+++ subversion/libsvn_subr/io.c (working copy)
@@ -2425,6 +2425,47 @@
 }

+svn_error_t *
+svn_io_file_rename_ensure (const char *from_path, const char *to_path,
+ apr_pool_t *pool)
+{
+ svn_error_t *err = svn_io_file_rename (from_path, to_path, pool);
+
+ if (err && APR_STATUS_IS_EXDEV (err->apr_err))
+ {
+ svn_error_clear (err);
+
+ err = svn_io_copy_file (from_path, to_path, TRUE, pool);
+ if (err)
+ {
+ svn_error_clear (svn_io_remove_file (to_path, pool));
+ return err;
+ }
+
+#ifdef WIN32
+ /* Windows won't let us delete a file marked as read-only,
+ so, mark as read+write */
+ err = svn_io_set_file_read_write (from_path, FALSE, pool);
+ if (err)
+ goto failed;
+#endif
+
+ err = svn_io_remove_file (from_path, pool);
+ if (err)
+ goto failed;
+
+ return SVN_NO_ERROR;
+
+ failed:
+#ifdef WIN32
+ svn_error_clear (svn_io_set_file_read_write (to_path, FALSE, pool));
+#endif
+ svn_error_clear (svn_io_remove_file (to_path, pool));
+ }
+
+ return err;
+}
+
 /* Common implementation of svn_io_dir_make and svn_io_dir_make_hidden.
    HIDDEN determines if the hidden attribute
    should be set on the newly created directory. */
Received on Tue Sep 27 23:40:27 2005

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