Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
The iterator gets gets messed up when modifying the directory. Thus w…
…e copy() instead of rename() and remove the whole folders/files afterwards in a separate iteration.

Signed-off-by: CaCO3 <[email protected]>
  • Loading branch information
CaCO3 committed Oct 28, 2023
commit 16ff4ac4d18e0e0f79bb932a64a0f1d9e6d8ef40
28 changes: 21 additions & 7 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -995,24 +995,38 @@ private function moveWithExclusions(string $dataLocation, array $excludedElement
throw new \Exception('Could not mkdir ' . $this->baseDir . '/../' . dirname($fileName));
}
}
$state = rename($path, $this->baseDir . '/../' . $fileName);
$state = copy($path, $this->baseDir . '/../' . $fileName);
if ($state === false) {
throw new \Exception(
sprintf(
'Could not rename %s to %s',
'Could not copy %s to %s',
$path,
$this->baseDir . '/../' . $fileName
)
);
}
}
if ($fileInfo->isDir()) {
$state = rmdir($path);
if ($state === false) {
throw new \Exception('Could not rmdir ' . $path);
}

// Cleanup (delete $path)
foreach ($this->getRecursiveDirectoryIterator($dataLocation) as $path => $fileInfo) {
$this->silentLog('[info] ' . explode($dataLocation, $path)[1]);

$fileName = explode($dataLocation, $path)[1];
$folderStructure = explode('/', $fileName, -1);

// Exclude the exclusions
if (isset($folderStructure[0])) {
if (array_search($folderStructure[0], $excludedElements) !== false) {
$this->silentLog('[info] skipped fileName: ' . $fileName);
continue;
}
} else {
if (array_search($fileName, $excludedElements) !== false) {
$this->silentLog('[info] skipped fileName: ' . $fileName);
continue;
}
}
}
}

/**
Expand Down