added relative_path functionality to getGroupFolderDirectory
This commit is contained in:
parent
93cf10d00d
commit
c13e8dfcb2
1 changed files with 69 additions and 40 deletions
|
@ -5,19 +5,28 @@ namespace OCA\GroupfolderFilesystemSnapshots\Manager;
|
||||||
use OCP\IConfig;
|
use OCP\IConfig;
|
||||||
use OCP\Files\IRootFolder;
|
use OCP\Files\IRootFolder;
|
||||||
use OCA\GroupFolders\Folder\FolderManager;
|
use OCA\GroupFolders\Folder\FolderManager;
|
||||||
|
use OCA\GroupFolders\Mount\MountProvider;
|
||||||
|
|
||||||
class PathManager {
|
class PathManager {
|
||||||
private IConfig $config;
|
private IConfig $config;
|
||||||
private IRootFolder $rootFolder;
|
private IRootFolder $rootFolder;
|
||||||
private FolderManager $groupfolderFolderManager;
|
private FolderManager $groupfolderFolderManager;
|
||||||
|
/** @var MountProvider */
|
||||||
|
protected $mountProvider;
|
||||||
|
|
||||||
const FILESYSTEM_ROOT_PATH = "/srv/nextcloud/files/";
|
const FILESYSTEM_ROOT_PATH = "/srv/nextcloud/files/";
|
||||||
const FILESYSTEM_SNAPSHOT_PATH = "/srv/nextcloud/files/.zfs/snapshot/";
|
const FILESYSTEM_SNAPSHOT_PATH = "/srv/nextcloud/files/.zfs/snapshot/";
|
||||||
|
|
||||||
public function __construct(IConfig $config, IRootFolder $rootFolder, FolderManager $manager){
|
public function __construct(
|
||||||
|
IConfig $config,
|
||||||
|
IRootFolder $rootFolder,
|
||||||
|
FolderManager $manager,
|
||||||
|
MountProvider $mountProvider,
|
||||||
|
){
|
||||||
$this->config = $config;
|
$this->config = $config;
|
||||||
$this->groupfolderFolderManager = $manager;
|
$this->groupfolderFolderManager = $manager;
|
||||||
$this->rootFolder = $rootFolder;
|
$this->rootFolder = $rootFolder;
|
||||||
|
$this->mountProvider = $mountProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getFilesystemSnapshotPath() {
|
public function getFilesystemSnapshotPath() {
|
||||||
|
@ -49,6 +58,15 @@ class PathManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Groupfolders
|
// Groupfolders
|
||||||
|
public function getGroupfolderById(int $groupfolderId) {
|
||||||
|
$storageId = $this->getRootFolderStorageId();
|
||||||
|
if (!is_null($storageId)) {
|
||||||
|
return $this->groupfolderFolderManager->getFolder($groupfolderId, $storageId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public function getGroupfolderMountById(int $groupfolderId) {
|
||||||
|
return $this->mountProvider->getFolder($groupfolderId, False);
|
||||||
|
}
|
||||||
private function checkIfGroupfolderExists(int $groupfolderId): bool {
|
private function checkIfGroupfolderExists(int $groupfolderId): bool {
|
||||||
$storageId = $this->getRootFolderStorageId();
|
$storageId = $this->getRootFolderStorageId();
|
||||||
if ($storageId === null) {
|
if ($storageId === null) {
|
||||||
|
@ -63,16 +81,27 @@ class PathManager {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getGroupFolderDirectory(int $groupfolderId) {
|
public function getGroupFolderDirectory(int $groupfolderId, string $relativePath) {
|
||||||
$folderExistsCheck = $this->checkIfGroupfolderExists($groupfolderId);
|
$groupFolder = $this->getGroupfolderMountById($groupfolderId);
|
||||||
if(!$folderExistsCheck) {
|
$relativeToDataDirectoryPath = $groupFolder->get($relativePath)->getInternalPath();
|
||||||
return $folderExistsCheck;
|
$minPath = realpath($this->getDataDirectory() . DIRECTORY_SEPARATOR . $groupFolder->getInternalPath() . DIRECTORY_SEPARATOR);
|
||||||
|
$realPath = realpath($this->getDataDirectory() . DIRECTORY_SEPARATOR . $relativeToDataDirectoryPath . DIRECTORY_SEPARATOR);
|
||||||
|
|
||||||
|
// Data directory and groupfolder directory have to actually exist
|
||||||
|
if(!file_exists($minPath) || !file_exists($realPath)) {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return realpath($this->getDataDirectory() . DIRECTORY_SEPARATOR . "__groupfolders" . DIRECTORY_SEPARATOR . $groupfolderId . DIRECTORY_SEPARATOR);
|
// the group subfolder directory always has to start with the groupfolder directory
|
||||||
|
// prevents usage of ".." in relativePath to escape out of groupfolder or even data directory
|
||||||
|
if(!str_starts_with($realPath, $minPath)) {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getGroupFolderSnapshotDirectory(int $groupfolderId, string $snapshotId) {
|
return $realPath;
|
||||||
return $this->convertToSnapshotPath($this->getGroupFolderDirectory($groupfolderId), $snapshotId);
|
}
|
||||||
|
|
||||||
|
public function getGroupFolderSnapshotDirectory(int $groupfolderId, string $relativePath, string $snapshotId) {
|
||||||
|
return $this->convertToSnapshotPath($this->getGroupFolderDirectory($groupfolderId, $relativePath), $snapshotId);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue