Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

MDL-39177 make sure we don't remove existing directories when cleanin…

…g up unzip
  • Loading branch information...
commit caaad8b08d9e103ffd0b5f64d16e1b721c10d8b0 1 parent d917dc9
@marinaglancy marinaglancy authored stronk7 committed
Showing with 11 additions and 6 deletions.
  1. +11 −6 repository/draftfiles_ajax.php
View
17 repository/draftfiles_ajax.php
@@ -219,6 +219,8 @@
// Find unused name for directory to extract the archive.
$temppath = $fs->get_unused_dirname($user_context->id, 'user', 'draft', $draftid, $filepath. pathinfo($filename, PATHINFO_FILENAME). '/');
+ $donotremovedirs = array();
+ $doremovedirs = array($temppath);
// Extract archive and move all files from $temppath to $filepath
if ($file->extract_to_storage($zipper, $user_context->id, 'user', 'draft', $draftid, $temppath, $USER->id) !== false) {
$extractedfiles = $fs->get_directory_files($user_context->id, 'user', 'draft', $draftid, $temppath, true);
@@ -233,8 +235,12 @@
// File or directory did not exist, just move it.
$file->rename($realpath, $file->get_filename());
} else if (!$file->is_directory()) {
- // File already existed, overwrite it (nothing to do with existing directories).
+ // File already existed, overwrite it
repository::overwrite_existing_draftfile($draftid, $realpath, $file->get_filename(), $file->get_filepath(), $file->get_filename());
+ } else {
+ // Directory already existed, remove temporary dir but make sure we don't remove the existing dir
+ $doremovedirs[] = $file->get_filepath();
+ $donotremovedirs[] = $realpath;
}
}
$return = new stdClass();
@@ -243,11 +249,10 @@
$return = false;
}
// Remove remaining temporary directories.
- foreach ($fs->get_directory_files($user_context->id, 'user', 'draft', $draftid, $temppath, true, true, 'filepath desc, filename desc') as $file) {
- $file->delete();
- }
- if ($file = $fs->get_file($user_context->id, 'user', 'draft', $draftid, $temppath, '.')) {
- $file->delete();
+ foreach (array_diff($doremovedirs, $donotremovedirs) as $filepath) {
+ if ($file = $fs->get_file($user_context->id, 'user', 'draft', $draftid, $filepath, '.')) {
+ $file->delete();
+ }
}
die(json_encode($return));
Please sign in to comment.
Something went wrong with that request. Please try again.