Skip to content

Commit 60e88d5

Browse files
author
Michael Babker
committed
Add file_exists checks before deleting files on revert
1 parent c108343 commit 60e88d5

File tree

1 file changed

+14
-8
lines changed
  • administrator/components/com_patchtester/PatchTester/Model

1 file changed

+14
-8
lines changed

administrator/components/com_patchtester/PatchTester/Model/PullModel.php

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -326,21 +326,27 @@ public function revert($id)
326326
);
327327
}
328328

329-
if (!\JFile::delete(JPATH_COMPONENT . '/backups/' . md5($file->old) . '.txt'))
329+
if (file_exists(JPATH_COMPONENT . '/backups/' . md5($file->old) . '.txt'))
330330
{
331-
throw new \RuntimeException(
332-
\JText::sprintf('COM_PATCHTESTER_ERROR_CANNOT_DELETE_FILE', JPATH_COMPONENT . '/backups/' . md5($file->old) . '.txt')
333-
);
331+
if (!\JFile::delete(JPATH_COMPONENT . '/backups/' . md5($file->old) . '.txt'))
332+
{
333+
throw new \RuntimeException(
334+
\JText::sprintf('COM_PATCHTESTER_ERROR_CANNOT_DELETE_FILE', JPATH_COMPONENT . '/backups/' . md5($file->old) . '.txt')
335+
);
336+
}
334337
}
335338

336339
break;
337340

338341
case 'added':
339-
if (!\JFile::delete(\JPath::clean(JPATH_ROOT . '/' . $file->new)))
342+
if (file_exists(JPATH_ROOT . '/' . $file->new))
340343
{
341-
throw new \RuntimeException(
342-
\JText::sprintf('COM_PATCHTESTER_ERROR_CANNOT_DELETE_FILE', JPATH_ROOT . '/' . $file->new)
343-
);
344+
if (!\JFile::delete(JPATH_ROOT . '/' . $file->new))
345+
{
346+
throw new \RuntimeException(
347+
\JText::sprintf('COM_PATCHTESTER_ERROR_CANNOT_DELETE_FILE', JPATH_ROOT . '/' . $file->new)
348+
);
349+
}
344350
}
345351

346352
break;

0 commit comments

Comments
 (0)