fix(webdav): native COPY honours destination filename (M8)

Threads `new_name: Option<&str>` through FileWritePort::copy_file and
FileManagementUseCase::copy_file_with_perms so a same-folder
COPY /a.txt → /b.txt picks up the destination name via a single
COALESCE($3::text, name) in the CTE. Without it the new row inherits
the source's filename and collides on the (folder_id, name, user_id)
unique index — the "Already Exists" 500 M8 was hitting.

handle_copy in the native WebDAV surface now passes
`(file.name != dest_name).then(|| dest_name.into())`, keeping the
"same name in a different folder" case at None so existing semantics
are preserved.
This commit is contained in:
Edouard Vanbelle
2026-06-17 01:43:13 +02:00
parent bacd5806d3
commit f9de7ac596
9 changed files with 83 additions and 26 deletions
+6
View File
@@ -255,11 +255,17 @@ pub trait FileManagementUseCase: Send + Sync + 'static {
) -> Result<FileDto, DomainError>;
/// Copies a file, enforcing that `caller_id` is the owner.
///
/// `new_name`, when `Some(_)`, becomes the copy's filename — without it
/// the copy keeps the source's name, which makes "same folder, different
/// name" copies (classic WebDAV `COPY /a.txt → /b.txt`) collide on the
/// `(folder, name, user)` unique index.
async fn copy_file_with_perms(
&self,
file_id: &str,
caller_id: Uuid,
target_folder_id: Option<String>,
new_name: Option<String>,
) -> Result<FileDto, DomainError>;
/// Renames a file, enforcing that `caller_id` is the owner.