webdav: deal with buggy webdav servers in renameExport

box.com already had a special case, since its renaming was known buggy.
In its case, renaming to the temp file succeeds, but then renaming the temp
file to final destination fails.

Then this 4shared server has buggy handling of renames across directories.
While already worked around with for the temp files when storing exports
now being in the same directory as the final filename, that also affected
renameExport when the file moves between directories.

I'm not entirely clear what happens on the 4shared server when it fails
this way. It kind of looks like it may rename the file to destination and
then still fail.

To handle both, when rename fails, delete both the source and the
destination, and fall back to uploading the content again. In the box.com
case, the temp file is the source, and deleting it makes sure the temp file
gets cleaned up. In the 4shared case, the file may have been renamed to the
destination and so cleaning that up avoids any interference with the
re-upload to the destination.
This commit is contained in:
Joey Hess 2021-03-22 13:08:18 -04:00
parent 0af9d1dcb6
commit 5d75cbcdcf
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
5 changed files with 41 additions and 10 deletions

View file

@ -280,7 +280,10 @@ data ExportActions a = ExportActions
, checkPresentExport :: Key -> ExportLocation -> a Bool
-- Renames an already exported file.
--
-- If the remote does not support renames, it can return Nothing.
-- If the remote does not support the requested rename,
-- it can return Nothing. It's ok if the remove deletes
-- the file in such a situation too; it will be re-exported to
-- recover.
--
-- Throws an exception if the remote cannot be accessed, or
-- the file doesn't exist or cannot be renamed.
@ -393,3 +396,4 @@ data ImportActions a = ImportActions
-> [ContentIdentifier]
-> a Bool
}