|
|
@@ -11,6 +11,7 @@
|
|
|
|
|
|
namespace PrivateBin\Data;
|
|
|
|
|
|
+use DirectoryIterator;
|
|
|
use GlobIterator;
|
|
|
use PrivateBin\Exception\JsonException;
|
|
|
use PrivateBin\Json;
|
|
|
@@ -121,21 +122,24 @@ class Filesystem extends AbstractData
|
|
|
$pastedir = $this->_dataid2path($pasteid);
|
|
|
if (is_dir($pastedir)) {
|
|
|
// Delete the paste itself.
|
|
|
- if (is_file($pastedir . $pasteid . '.php')) {
|
|
|
- unlink($pastedir . $pasteid . '.php');
|
|
|
+ $pastefile = $pastedir . $pasteid . '.php';
|
|
|
+ if (is_file($pastefile)) {
|
|
|
+ if (!unlink($pastefile)) {
|
|
|
+ error_log('Error deleting paste: ' . $pastefile);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// Delete discussion if it exists.
|
|
|
$discdir = $this->_dataid2discussionpath($pasteid);
|
|
|
if (is_dir($discdir)) {
|
|
|
// Delete all files in discussion directory
|
|
|
- $dir = dir($discdir);
|
|
|
- while (false !== ($filename = $dir->read())) {
|
|
|
- if (is_file($discdir . $filename)) {
|
|
|
- unlink($discdir . $filename);
|
|
|
+ foreach (new DirectoryIterator($discdir) as $file) {
|
|
|
+ if ($file->isFile()) {
|
|
|
+ if (!unlink($file->getPathname())) {
|
|
|
+ error_log('Error deleting comment: ' . $file->getPathname());
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- $dir->close();
|
|
|
rmdir($discdir);
|
|
|
}
|
|
|
}
|
|
|
@@ -159,14 +163,11 @@ class Filesystem extends AbstractData
|
|
|
// convert comments, too
|
|
|
$discdir = $this->_dataid2discussionpath($pasteid);
|
|
|
if (is_dir($discdir)) {
|
|
|
- $dir = dir($discdir);
|
|
|
- while (false !== ($filename = $dir->read())) {
|
|
|
- if (substr($filename, -4) !== '.php' && strlen($filename) >= 16) {
|
|
|
- $commentFilename = $discdir . $filename . '.php';
|
|
|
- $this->_prependRename($discdir . $filename, $commentFilename);
|
|
|
+ foreach (new DirectoryIterator($discdir) as $file) {
|
|
|
+ if ($file->getExtension() !== 'php' && strlen($file->getFilename()) >= 16) {
|
|
|
+ $this->_prependRename($file->getPathname(), $file->getPathname() . '.php');
|
|
|
}
|
|
|
}
|
|
|
- $dir->close();
|
|
|
}
|
|
|
}
|
|
|
return is_readable($pastePath);
|
|
|
@@ -207,15 +208,14 @@ class Filesystem extends AbstractData
|
|
|
$comments = array();
|
|
|
$discdir = $this->_dataid2discussionpath($pasteid);
|
|
|
if (is_dir($discdir)) {
|
|
|
- $dir = dir($discdir);
|
|
|
- while (false !== ($filename = $dir->read())) {
|
|
|
+ foreach (new DirectoryIterator($discdir) as $file) {
|
|
|
// Filename is in the form pasteid.commentid.parentid.php:
|
|
|
// - pasteid is the paste this reply belongs to.
|
|
|
// - commentid is the comment identifier itself.
|
|
|
// - parentid is the comment this comment replies to (It can be pasteid)
|
|
|
- if (is_file($discdir . $filename)) {
|
|
|
- $comment = $this->_get($discdir . $filename);
|
|
|
- $items = explode('.', $filename);
|
|
|
+ if ($file->isFile()) {
|
|
|
+ $comment = $this->_get($file->getPathname());
|
|
|
+ $items = explode('.', $file->getBasename('.php'));
|
|
|
// Add some meta information not contained in file.
|
|
|
$comment['id'] = $items[1];
|
|
|
$comment['parentid'] = $items[2];
|
|
|
@@ -228,7 +228,6 @@ class Filesystem extends AbstractData
|
|
|
$comments[$key] = $comment;
|
|
|
}
|
|
|
}
|
|
|
- $dir->close();
|
|
|
|
|
|
// Sort comments by date, oldest first.
|
|
|
ksort($comments);
|
|
|
@@ -522,6 +521,8 @@ class Filesystem extends AbstractData
|
|
|
file_put_contents($destFile, $handle, FILE_APPEND);
|
|
|
fclose($handle);
|
|
|
}
|
|
|
- unlink($srcFile);
|
|
|
+ if (!unlink($srcFile)) {
|
|
|
+ error_log('Error deleting converted document: ' . $srcFile);
|
|
|
+ }
|
|
|
}
|
|
|
}
|