From 3f110995a4ca8b440e5b0695a2d9dd9ef0aec65d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A2u=20Cao?= Date: Thu, 8 Feb 2024 13:02:47 +0100 Subject: [PATCH] Add timestamp to icon filenames There can be race condition when a background job is supposed to delete an icon while there is a new one being attached. Also, this encodes the date/time when the icon has been added, for inspection and convenience. --- app/services/app_catalog_manager/update_metadata.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/services/app_catalog_manager/update_metadata.rb b/app/services/app_catalog_manager/update_metadata.rb index a23b3d6..d212a45 100644 --- a/app/services/app_catalog_manager/update_metadata.rb +++ b/app/services/app_catalog_manager/update_metadata.rb @@ -42,8 +42,8 @@ module AppCatalogManager else download_url = "#{@app.url}/#{icon["src"].gsub(/^\//,'')}" end - filename = "#{attachment_name}.png" - key = "web_apps/#{@app.id}/icons/#{attachment_name}.png" + filename = "#{attachment_name}-#{Time.now.to_i}.png" + key = "web_apps/#{@app.id}/icons/#{filename}" begin tempfile = Down.download(download_url)