Added current fileId to DiffTaskResult; implemented folder blocklist feature; fixed indentations of some files; bumped version
This commit is contained in:
parent
85d63d5ae2
commit
acf8990de1
6 changed files with 253 additions and 212 deletions
|
@ -5,7 +5,7 @@
|
|||
<name>Groupfolder Filesystem Snapshots</name>
|
||||
<summary>Allows restoring a groupfolder to a previous snapshot in the filesystem</summary>
|
||||
<description>App proving a PHP API for other apps, that allows (partially) restoring a groupfolder to a previous snapshot in the filesystem. Requires a filesystem with snapshot support (tested with and made for ZFS). It is made for other apps to integrate with, IT DOES NOT WORK STANDALONE</description>
|
||||
<version>1.3.1</version>
|
||||
<version>1.4.0</version>
|
||||
<licence>agpl</licence>
|
||||
<author homepage="https://verdigado.com/">verdigado eG</author>
|
||||
<author mail="jonathan.treffler@verdigado.com">Jonathan Treffler</author>
|
||||
|
|
|
@ -16,6 +16,8 @@ class DiffTaskResult extends Entity implements JsonSerializable {
|
|||
protected $beforeSize;
|
||||
|
||||
protected $currentFileExists;
|
||||
protected $currentFileId;
|
||||
|
||||
protected $currentPath;
|
||||
protected $currentSize;
|
||||
protected $reverted;
|
||||
|
@ -26,6 +28,7 @@ class DiffTaskResult extends Entity implements JsonSerializable {
|
|||
$this->addType('beforeFileExists','boolean');
|
||||
$this->addType('beforeSize','integer');
|
||||
$this->addType('currentFileExists','boolean');
|
||||
$this->addType('currentFileId','integer');
|
||||
$this->addType('currentSize','integer');
|
||||
$this->addType('reverted','boolean');
|
||||
}
|
||||
|
@ -42,6 +45,7 @@ class DiffTaskResult extends Entity implements JsonSerializable {
|
|||
],
|
||||
'current' => [
|
||||
'fileExists' => $this->currentFileExists,
|
||||
'fileId' => $this->currentFileId,
|
||||
'path' => $this->currentPath,
|
||||
'size' => $this->currentSize,
|
||||
],
|
||||
|
|
33
lib/Migration/Version140Date20250701164500.php
Normal file
33
lib/Migration/Version140Date20250701164500.php
Normal file
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
namespace OCA\GroupfolderFilesystemSnapshots\Migration;
|
||||
|
||||
use Closure;
|
||||
use OCP\DB\ISchemaWrapper;
|
||||
use OCP\DB\Types;
|
||||
use OCP\Migration\SimpleMigrationStep;
|
||||
use OCP\Migration\IOutput;
|
||||
|
||||
class Version140Date20250701164500 extends SimpleMigrationStep {
|
||||
const RESULTS_TABLE = "groupfolder_snapshots_task_results";
|
||||
|
||||
/**
|
||||
* @param IOutput $output
|
||||
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
|
||||
* @param array $options
|
||||
* @return null|ISchemaWrapper
|
||||
*/
|
||||
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) {
|
||||
/** @var ISchemaWrapper $schema */
|
||||
$schema = $schemaClosure();
|
||||
$table = $schema->getTable(self::RESULTS_TABLE);
|
||||
|
||||
if(!$table->hasColumn('current_file_id')) {
|
||||
$table->addColumn('current_file_id', Types::BIGINT, [
|
||||
'notnull' => false,
|
||||
]);
|
||||
}
|
||||
|
||||
return $schema;
|
||||
}
|
||||
}
|
|
@ -5,15 +5,6 @@ namespace OCA\GroupfolderFilesystemSnapshots;
|
|||
use OCA\GroupfolderFilesystemSnapshots\Helpers\FileHelper;
|
||||
|
||||
class RecursiveDiff {
|
||||
|
||||
public string $dir1;
|
||||
public string $dir2;
|
||||
|
||||
private $prefix;
|
||||
|
||||
private $newResultCallback;
|
||||
private $progressCallback;
|
||||
|
||||
private $scan1files = [];
|
||||
private $scan1folders = [];
|
||||
|
||||
|
@ -25,14 +16,14 @@ class RecursiveDiff {
|
|||
private $subJobProgress = [];
|
||||
private $progress = 0;
|
||||
|
||||
public function __construct($dir1, $dir2, $prefix = "", $newResultCallback, $progressCallback){
|
||||
$this->dir1 = $dir1;
|
||||
$this->dir2 = $dir2;
|
||||
$this->prefix = $prefix;
|
||||
|
||||
$this->newResultCallback = $newResultCallback;
|
||||
$this->progressCallback = $progressCallback;
|
||||
}
|
||||
public function __construct(
|
||||
public readonly string $dir1,
|
||||
public readonly string $dir2,
|
||||
private readonly string $prefix = "",
|
||||
private readonly array $folderBlocklist = [],
|
||||
private $newResultCallback,
|
||||
private $progressCallback,
|
||||
){}
|
||||
|
||||
public function scan() {
|
||||
$scan_num_files = 0;
|
||||
|
@ -54,8 +45,13 @@ class RecursiveDiff {
|
|||
$subdir1 = $this->dir1 . DIRECTORY_SEPARATOR . $folder;
|
||||
$subdir2 = $this->dir2 . DIRECTORY_SEPARATOR . $folder;
|
||||
$subprefix = $this->prefix . DIRECTORY_SEPARATOR . $folder;
|
||||
$subFolderBlocklist = $this->folderBlocklist[$folder] ?? [];
|
||||
|
||||
$newJob = new RecursiveDiff($subdir1, $subdir2, $subprefix, $this->newResultCallback, function($numDoneFiles) use ($key) {
|
||||
if($subFolderBlocklist === true) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$newJob = new RecursiveDiff($subdir1, $subdir2, $subprefix, $subFolderBlocklist, $this->newResultCallback, function($numDoneFiles) use ($key) {
|
||||
$this->subJobProgress[$key] = $numDoneFiles;
|
||||
|
||||
$this->updateProgress();
|
||||
|
|
|
@ -58,7 +58,8 @@ class DiffTaskService {
|
|||
}
|
||||
}
|
||||
|
||||
function create(string $relativePathInGroupfolder, int $groupfolderId, string $snapshotId, string $userId, Callable $progressCallback = null): ?DiffTask {
|
||||
function create(string $relativePathInGroupfolder, int $groupfolderId, string $snapshotId, string $userId, array $folderBlocklist, Callable $progressCallback = null): ?DiffTask {
|
||||
$parentNode = $this->pathManager->getGroupfolderMountById($groupfolderId)->get($relativePathInGroupfolder);
|
||||
$snapshotPath = $this->pathManager->getGroupFolderSnapshotDirectory($groupfolderId, $relativePathInGroupfolder, $snapshotId);
|
||||
$groupfolderPath = $this->pathManager->getGroupFolderDirectory($groupfolderId, $relativePathInGroupfolder);
|
||||
|
||||
|
@ -80,16 +81,25 @@ class DiffTaskService {
|
|||
$snapshotPath,
|
||||
$groupfolderPath,
|
||||
"",
|
||||
function(string $type, bool $beforeFileExists, ?string $beforePath, ?int $beforeSize, bool $currentFileExists, ?string $currentPath, ?int $currentSize) use ($task) {
|
||||
$folderBlocklist,
|
||||
function(string $type, bool $beforeFileExists, ?string $beforePath, ?int $beforeSize, bool $currentFileExists, ?string $currentPath, ?int $currentSize) use ($task, $parentNode) {
|
||||
$newResult = new DiffTaskResult();
|
||||
$newResult->setTaskId($task->getId());
|
||||
$newResult->setType($type);
|
||||
|
||||
$newResult->setBeforeFileExists($beforeFileExists);
|
||||
if($beforeFileExists) {
|
||||
$newResult->setBeforePath($beforePath);
|
||||
$newResult->setBeforeSize($beforeSize);
|
||||
}
|
||||
|
||||
$newResult->setCurrentFileExists($currentFileExists);
|
||||
if($currentFileExists) {
|
||||
$newResult->setCurrentFileId($parentNode->get($currentPath)?->getId());
|
||||
$newResult->setCurrentPath($currentPath);
|
||||
$newResult->setCurrentSize($currentSize);
|
||||
}
|
||||
|
||||
$newResult = $this->diffTaskResultMapper->insert($newResult);
|
||||
},
|
||||
function($numDoneFiles) use ($progressCallback, &$numFiles) {
|
||||
|
@ -97,8 +107,7 @@ class DiffTaskService {
|
|||
($progressCallback)([
|
||||
"overallFiles" => $numFiles,
|
||||
"doneFiles" => $numDoneFiles,
|
||||
"progress" => number_format(($numDoneFiles / $numFiles),2),
|
||||
"progressPercent" => (number_format(($numDoneFiles / $numFiles),2) * 100) . "%",
|
||||
"progress" => round(($numDoneFiles / $numFiles),2),
|
||||
]);
|
||||
}
|
||||
},
|
||||
|
@ -113,7 +122,6 @@ class DiffTaskService {
|
|||
"overallFiles" => $numFiles,
|
||||
"doneFiles" => $numFiles,
|
||||
"progress" => 1.0,
|
||||
"progressPercent" => "100.00%",
|
||||
"result" => $task,
|
||||
]);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue