implemented snapshot diff; started work on admin settings

This commit is contained in:
Jonathan Treffler 2023-08-08 11:52:21 +02:00 committed by root
parent 4c67bf71c4
commit 8b22d56e32
7 changed files with 423 additions and 8 deletions

View file

@ -2,15 +2,55 @@
namespace OCA\GroupfolderFilesystemSnapshots\Manager;
class SnapshotManager {
function get() {
$filesystem_path = "/srv/nextcloud/files/";
$filesystem_snapshot_path = "/srv/nextcloud/files/.zfs/snapshot/";
use OCA\GroupfolderFilesystemSnapshots\Manager\PathManager;
use OCA\GroupfolderFilesystemSnapshots\Manager\DiffManager;
$iterator = new \FilesystemIterator($filesystem_snapshot_path);
foreach ($iterator as $fileinfo) {
if(!$fileinfo->isDir()) continue;
yield $fileinfo->getFilename();
use OCA\GroupfolderFilesystemSnapshots\Entity\Snapshot;
class SnapshotManager {
private PathManager $pathManager;
private DiffManager $diffManager;
public function __construct(PathManager $pathManager, DiffManager $diffManager){
$this->pathManager = $pathManager;
$this->diffManager = $diffManager;
}
private function validSnapshotId(string $snapshotId) {
return (preg_match("/^[a-zA-Z0-9-_]+$/", $snapshotId) == 1);
}
function snapshotExists(string $snapshotId): bool {
if($this->validSnapshotId($snapshotId)) {
$path = $this->pathManager->getSnapshotPath($snapshotId);
return (file_exists($path) && is_dir($path));
} else {
return false;
}
}
function get(string $snapshotId) {
if(self::snapshotExists($snapshotId)) {
return new Snapshot($snapshotId);
} else {
return false;
}
}
function getAll() {
$iterator = new \FilesystemIterator($this->pathManager->getFilesystemSnapshotPath());
foreach ($iterator as $fileinfo) {
if(!$fileinfo->isDir()) continue;
yield new Snapshot($fileinfo->getFilename());
}
}
function getDiff(int $groupfolderId, string $snapshotId) {
$groupfolderPath = $this->pathManager->getGroupFolderDirectory($groupfolderId);
$snapshotPath = $this->pathManager->getGroupFolderSnapshotDirectory($groupfolderId, $snapshotId);
return $this->diffManager->diffDirectories($snapshotPath, $groupfolderPath);
}
}