From 00b051e2d7f5a8d8b3cc759d9855cef433ceefde Mon Sep 17 00:00:00 2001 From: Eric Mc Sween Date: Mon, 17 Oct 2022 09:53:48 -0400 Subject: [PATCH] Merge pull request #9973 from overleaf/em-duplicate-filenames-conflict Fix the automatic fixing of duplicate filenames GitOrigin-RevId: 8ecdeb22c0c7f3c28983d4bf0f50c573193703b4 --- .../Project/ProjectEntityUpdateHandler.js | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/services/web/app/src/Features/Project/ProjectEntityUpdateHandler.js b/services/web/app/src/Features/Project/ProjectEntityUpdateHandler.js index e5886c318a..366618c2fe 100644 --- a/services/web/app/src/Features/Project/ProjectEntityUpdateHandler.js +++ b/services/web/app/src/Features/Project/ProjectEntityUpdateHandler.js @@ -1522,6 +1522,26 @@ const ProjectEntityUpdateHandler = { } ) } + + // Avoid conflicts by processing renames in the reverse order. If we have + // the following starting situation: + // + // somefile.tex + // somefile.tex + // somefile.tex (1) + // + // somefile.tex would be processed first, and then somefile.tex (1), + // yielding the following renames: + // + // somefile.tex -> somefile.tex (1) + // somefile.tex (1) -> somefile.tex (2) + // + // When the first rename was decided, we didn't know that somefile.tex (1) + // existed, so that created a conflict. By processing renames in the + // reverse order, we start with the files that had the most extensive + // information about existing files. + renames.reverse() + async.eachSeries(renames, doRename, callback) },