]> git.eshelyaron.com Git - emacs.git/commitdiff
Improve Tramp for remote WebDAV
authorMichael Albinus <michael.albinus@gmx.de>
Sat, 1 Jul 2023 08:19:37 +0000 (10:19 +0200)
committerMichael Albinus <michael.albinus@gmx.de>
Sat, 1 Jul 2023 08:19:37 +0000 (10:19 +0200)
* lisp/net/tramp-gvfs.el (tramp-gvfs-do-copy-or-rename-file):
* lisp/net/tramp-rclone.el (tramp-rclone-do-copy-or-rename-file):
Improve stability for WebDAV.

lisp/net/tramp-gvfs.el
lisp/net/tramp-rclone.el

index 48467a92c14ceaa05a45d56edd4b327ed0d7e0b4..27dbf3249241e18530a9b6a964204475d34bc1a0 100644 (file)
@@ -1068,6 +1068,8 @@ file names."
          (when (and (file-directory-p newname)
                     (not (directory-name-p newname)))
            (tramp-error v 'file-error "File is a directory %s" newname))
+         (when (file-regular-p newname)
+           (delete-file newname))
 
          (cond
           ;; We cannot rename volatile files, as used by Google-drive.
index f71e4f732e22c1c49a143a1876c244faa8ba2a1b..df46bd5e20e25ecbe59af2dd31635e660ee1b5e7 100644 (file)
@@ -226,6 +226,7 @@ file names."
 
     (let ((t1 (tramp-tramp-file-p filename))
          (t2 (tramp-tramp-file-p newname))
+         (equal-remote (tramp-equal-remote filename newname))
          (rclone-operation (if (eq op 'copy) "copyto" "moveto"))
          (msg-operation (if (eq op 'copy) "Copying" "Renaming")))
 
@@ -236,8 +237,12 @@ file names."
          (when (and (file-directory-p newname)
                     (not (directory-name-p newname)))
            (tramp-error v 'file-error "File is a directory %s" newname))
+         (when (file-regular-p newname)
+           (delete-file newname))
 
-         (if (or (and t1 (not (tramp-rclone-file-name-p filename)))
+         (if (or (and equal-remote
+                      (tramp-get-connection-property v "direct-copy-failed"))
+                 (and t1 (not (tramp-rclone-file-name-p filename)))
                  (and t2 (not (tramp-rclone-file-name-p newname))))
 
              ;; We cannot copy or rename directly.
@@ -257,9 +262,20 @@ file names."
                        v rclone-operation
                        (tramp-rclone-remote-file-name filename)
                        (tramp-rclone-remote-file-name newname)))
-               (tramp-error
-                v 'file-error
-                "Error %s `%s' `%s'" msg-operation filename newname)))
+               (if (or (not equal-remote)
+                       (and equal-remote
+                            (tramp-get-connection-property
+                             v "direct-copy-failed")))
+                   (tramp-error
+                    v 'file-error
+                    "Error %s `%s' `%s'" msg-operation filename newname)
+
+                 ;; Some WebDAV server, like the one from QNAP, do
+                 ;; not support direct copy/move.  Try a fallback.
+                 (tramp-set-connection-property v "direct-copy-failed" t)
+                 (tramp-rclone-do-copy-or-rename-file
+                  op filename newname ok-if-already-exists keep-date
+                  preserve-uid-gid preserve-extended-attributes))))
 
            (when (and t1 (eq op 'rename))
              (while (file-exists-p filename)