httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s.@apache.org
Subject svn commit: r834019 - /httpd/httpd/trunk/modules/dav/fs/repos.c
Date Mon, 09 Nov 2009 11:17:05 GMT
Author: sf
Date: Mon Nov  9 11:17:01 2009
New Revision: 834019

URL: http://svn.apache.org/viewvc?rev=834019&view=rev
Log:
Instead of checking device ids, try rename first and in case of EXDEV,
fallback to copy.

>From rename(2) on Linux: Linux permits a file system to be mounted at multiple
points, but  rename()  does  not  work  across  different  mount points, even
if the same file system is mounted on both.

Modified:
    httpd/httpd/trunk/modules/dav/fs/repos.c

Modified: httpd/httpd/trunk/modules/dav/fs/repos.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/dav/fs/repos.c?rev=834019&r1=834018&r2=834019&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/dav/fs/repos.c (original)
+++ httpd/httpd/trunk/modules/dav/fs/repos.c Mon Nov  9 11:17:01 2009
@@ -506,9 +506,13 @@
     dst = apr_pstrcat(p, dst, "/", dst_file, NULL);
 
     /* copy/move the file now */
-    if (is_move && src_finfo.device == dst_state_finfo.device) {
-        /* simple rename is possible since it is on the same device */
-        if (apr_file_rename(src, dst, p) != APR_SUCCESS) {
+    if (is_move) {
+        /* try simple rename first */
+        rv = apr_file_rename(src, dst, p);
+        if (APR_STATUS_IS_EXDEV(rv)) {
+            return dav_fs_copymove_file(is_move, p, src, dst, NULL, NULL, pbuf);
+        }
+        if (rv != APR_SUCCESS) {
             /* ### use something besides 500? */
             return dav_new_error(p, HTTP_INTERNAL_SERVER_ERROR, 0,
                                  "Could not move state file.");
@@ -1204,7 +1208,7 @@
     dav_resource_private *srcinfo = src->info;
     dav_resource_private *dstinfo = dst->info;
     dav_error *err;
-    int can_rename = 0;
+    apr_status_t rv;
 
 #if DAV_DEBUG
     if (src->hooks != dst->hooks) {
@@ -1218,39 +1222,12 @@
     }
 #endif
 
-    /* determine whether a simple rename will work.
-     * Assume source exists, else we wouldn't get called.
-     */
-    if (dstinfo->finfo.filetype != 0) {
-        if (dstinfo->finfo.device == srcinfo->finfo.device) {
-            /* target exists and is on the same device. */
-            can_rename = 1;
-        }
-    }
-    else {
-        const char *dirpath;
-        apr_finfo_t finfo;
-        apr_status_t rv;
-
-        /* destination does not exist, but the parent directory should,
-         * so try it
-         */
-        dirpath = ap_make_dirstr_parent(dstinfo->pool, dstinfo->pathname);
-        /*
-         * XXX: If missing dev ... then what test?
-         * Really need a try and failover for those platforms.
-         *
-         */
-        rv = apr_stat(&finfo, dirpath, APR_FINFO_DEV, dstinfo->pool);
-        if ((rv == APR_SUCCESS || rv == APR_INCOMPLETE)
-            && (finfo.valid & srcinfo->finfo.valid & APR_FINFO_DEV)
-            && (finfo.device == srcinfo->finfo.device)) {
-            can_rename = 1;
-        }
-    }
+
+    /* try rename first */
+    rv = apr_file_rename(srcinfo->pathname, dstinfo->pathname, srcinfo->pool);
 
     /* if we can't simply rename, then do it the hard way... */
-    if (!can_rename) {
+    if (APR_STATUS_IS_EXDEV(rv)) {
         if ((err = dav_fs_copymove_resource(1, src, dst, DAV_INFINITY,
                                             response)) == NULL) {
             /* update resource states */
@@ -1263,20 +1240,16 @@
         return err;
     }
 
-    /* a rename should work. do it, and move properties as well */
-
     /* no multistatus response */
     *response = NULL;
 
-    /* ### APR has no rename? */
-    if (apr_file_rename(srcinfo->pathname, dstinfo->pathname,
-                       srcinfo->pool) != APR_SUCCESS) {
+    if (rv != APR_SUCCESS) {
         /* ### should have a better error than this. */
         return dav_new_error(srcinfo->pool, HTTP_INTERNAL_SERVER_ERROR, 0,
                              "Could not rename resource.");
     }
 
-    /* update resource states */
+    /* Rename did work. Update resource states and move properties as well */
     dst->exists = 1;
     dst->collection = src->collection;
     src->exists = 0;



Mime
View raw message