@@ -216,10 +216,27 @@ namespace AppInstaller::CLI::Portable
216216 {
217217 PortableIndex existingIndex = PortableIndex::Open (existingIndexPath.u8string (), SQLiteStorageBase::OpenDisposition::ReadWrite);
218218
219+ std::exception_ptr firstRemoveException;
219220 for (auto expectedEntry : m_expectedEntries)
220221 {
221- RemoveFile (expectedEntry);
222- existingIndex.RemovePortableFile (expectedEntry);
222+ try
223+ {
224+ RemoveFile (expectedEntry);
225+ existingIndex.RemovePortableFile (expectedEntry);
226+ }
227+ catch (...)
228+ {
229+ // Capture first failure but continue so that all entries (especially symlinks)
230+ // are cleaned up, preventing cascade failures in shared state like PATH.
231+ if (!firstRemoveException)
232+ {
233+ firstRemoveException = std::current_exception ();
234+ }
235+ }
236+ }
237+ if (firstRemoveException)
238+ {
239+ std::rethrow_exception (firstRemoveException);
223240 }
224241
225242 deleteIndex = existingIndex.IsEmpty ();
@@ -233,9 +250,24 @@ namespace AppInstaller::CLI::Portable
233250 }
234251 else
235252 {
253+ std::exception_ptr firstRemoveException;
236254 for (auto expectedEntry : m_expectedEntries)
237255 {
238- RemoveFile (expectedEntry);
256+ try
257+ {
258+ RemoveFile (expectedEntry);
259+ }
260+ catch (...)
261+ {
262+ if (!firstRemoveException)
263+ {
264+ firstRemoveException = std::current_exception ();
265+ }
266+ }
267+ }
268+ if (firstRemoveException)
269+ {
270+ std::rethrow_exception (firstRemoveException);
239271 }
240272 }
241273
0 commit comments