From 4d326bf0d92eefc4b70c502b5229ddc1ecfc04df Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Tue, 31 Dec 2024 07:49:27 +0000 Subject: [PATCH] fix: upload attachments with unique filename This prevents any clashes with uploading two files with the same name at the same time. Closes: kemitix/trello-to-deck#9 --- src/import/attachment.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/import/attachment.rs b/src/import/attachment.rs index 0db7f84..71cf341 100644 --- a/src/import/attachment.rs +++ b/src/import/attachment.rs @@ -51,10 +51,8 @@ impl Actor for ImportAttachmentActor { this.trello_attachment.name ); // - - - download the attachment from trello - let dir_path = this.ctx.temp_fs.base().join(&*this.trello_attachment.id); - let dir = this.ctx.temp_fs.dir(&dir_path); - dir.create()?; // FIXME: (#6) handle error - let file_path = dir_path.join(&*this.trello_attachment.name); + let file_name = f!("{}-{}", this.trello_attachment.id, this.trello_attachment.name); + let file_path = this.ctx.temp_fs.base().join(&file_name); ask!(this.rate_limit_actor, RequestToken)?; // FIXME: (#6) handle error let attachment_path = this .ctx @@ -101,8 +99,6 @@ impl Actor for ImportAttachmentActor { attachment_file .remove() .with_context(|| f!("deleting temp file {attachment_file}"))?; // FIXME: (#6) handle error - dir.remove() - .with_context(|| f!("deleting temp dir {dir}"))?; // FIXME: (#6) handle error tracing::info!("ImportAttachmentActor finished"); Ok(actor_ref.stop_gracefully().await?)