From 2dfb5fd1b8533341fabb859ee95b8ad20da4b707 Mon Sep 17 00:00:00 2001 From: Robert Paciorek Date: Sat, 17 Feb 2024 00:28:40 +0000 Subject: [PATCH] better handle proxy cache rename error --- src/Middleware/AssetMiddleware.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Middleware/AssetMiddleware.cs b/src/Middleware/AssetMiddleware.cs index 0a69a7b..ed59369 100644 --- a/src/Middleware/AssetMiddleware.cs +++ b/src/Middleware/AssetMiddleware.cs @@ -107,7 +107,13 @@ public class AssetMiddleware } // after successfully write data to temporary file, rename it to proper asset filename - File.Move(filePathTmp, filePath); + try { + File.Move(filePathTmp, filePath); + } catch (System.IO.IOException) { + // this can happen for example if two clients request the same file in the same time + // TODO: avoid redundant download in those cases + File.Delete(filePathTmp); + } } else { await inputStream.CopyToAsync(context.Response.Body); }