2013-10-28 19:14:23 -04:00
|
|
|
<?php
|
2024-05-23 03:26:56 -04:00
|
|
|
|
2013-10-28 19:14:23 -04:00
|
|
|
/**
|
2024-05-23 03:26:56 -04:00
|
|
|
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
2013-10-28 19:14:23 -04:00
|
|
|
*/
|
|
|
|
|
namespace OC\Files\Storage;
|
2018-01-14 17:44:59 -05:00
|
|
|
|
2016-02-29 11:43:23 -05:00
|
|
|
use OC\Files\Cache\HomePropagator;
|
2023-08-14 09:50:05 -04:00
|
|
|
use OCP\IUser;
|
2013-10-28 19:14:23 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Specialized version of Local storage for home directory usage
|
|
|
|
|
*/
|
2014-07-01 11:29:57 -04:00
|
|
|
class Home extends Local implements \OCP\Files\IHomeStorage {
|
2013-11-12 09:46:01 -05:00
|
|
|
/**
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
|
|
|
|
protected $id;
|
|
|
|
|
|
2013-10-28 19:14:23 -04:00
|
|
|
/**
|
|
|
|
|
* @var \OC\User\User $user
|
|
|
|
|
*/
|
|
|
|
|
protected $user;
|
|
|
|
|
|
2013-11-21 06:17:47 -05:00
|
|
|
/**
|
2014-05-19 11:50:53 -04:00
|
|
|
* Construct a Home storage instance
|
2018-01-14 17:44:59 -05:00
|
|
|
*
|
2013-11-21 06:17:47 -05:00
|
|
|
* @param array $arguments array with "user" containing the
|
2016-12-21 05:10:14 -05:00
|
|
|
* storage owner
|
2013-11-21 06:17:47 -05:00
|
|
|
*/
|
2013-10-28 19:14:23 -04:00
|
|
|
public function __construct($arguments) {
|
|
|
|
|
$this->user = $arguments['user'];
|
2013-11-02 15:22:12 -04:00
|
|
|
$datadir = $this->user->getHome();
|
2016-12-21 05:10:14 -05:00
|
|
|
$this->id = 'home::' . $this->user->getUID();
|
2013-11-02 15:22:12 -04:00
|
|
|
|
2018-01-14 17:44:59 -05:00
|
|
|
parent::__construct(['datadir' => $datadir]);
|
2013-10-28 19:14:23 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getId() {
|
2013-11-12 09:46:01 -05:00
|
|
|
return $this->id;
|
2013-10-28 19:14:23 -04:00
|
|
|
}
|
2013-11-08 06:57:28 -05:00
|
|
|
|
2013-11-21 06:17:47 -05:00
|
|
|
/**
|
|
|
|
|
* @return \OC\Files\Cache\HomeCache
|
|
|
|
|
*/
|
2014-06-12 11:23:34 -04:00
|
|
|
public function getCache($path = '', $storage = null) {
|
|
|
|
|
if (!$storage) {
|
|
|
|
|
$storage = $this;
|
|
|
|
|
}
|
2013-11-08 06:57:28 -05:00
|
|
|
if (!isset($this->cache)) {
|
2023-08-15 12:41:53 -04:00
|
|
|
$this->cache = new \OC\Files\Cache\HomeCache($storage, $this->getCacheDependencies());
|
2013-11-08 06:57:28 -05:00
|
|
|
}
|
2024-09-15 11:14:37 -04:00
|
|
|
/** @var \OC\Files\Cache\HomeCache */
|
2013-11-08 06:57:28 -05:00
|
|
|
return $this->cache;
|
|
|
|
|
}
|
2013-11-21 06:17:47 -05:00
|
|
|
|
2016-02-29 11:43:23 -05:00
|
|
|
public function getPropagator($storage = null) {
|
|
|
|
|
if (!$storage) {
|
|
|
|
|
$storage = $this;
|
|
|
|
|
}
|
|
|
|
|
if (!isset($this->propagator)) {
|
2016-02-25 07:14:20 -05:00
|
|
|
$this->propagator = new HomePropagator($storage, \OC::$server->getDatabaseConnection());
|
2016-02-29 11:43:23 -05:00
|
|
|
}
|
2024-09-15 11:14:37 -04:00
|
|
|
/** @var \OC\Files\Cache\Propagator */
|
2016-02-29 11:43:23 -05:00
|
|
|
return $this->propagator;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2013-11-21 06:17:47 -05:00
|
|
|
/**
|
2014-05-19 11:50:53 -04:00
|
|
|
* Returns the owner of this home storage
|
2018-01-14 17:44:59 -05:00
|
|
|
*
|
2013-11-21 06:17:47 -05:00
|
|
|
* @return \OC\User\User owner of this home storage
|
|
|
|
|
*/
|
2023-08-14 09:50:05 -04:00
|
|
|
public function getUser(): IUser {
|
2013-11-21 06:17:47 -05:00
|
|
|
return $this->user;
|
|
|
|
|
}
|
2014-07-21 10:59:59 -04:00
|
|
|
|
2024-09-16 10:00:30 -04:00
|
|
|
public function getOwner($path): string|false {
|
2014-07-21 10:59:59 -04:00
|
|
|
return $this->user->getUID();
|
|
|
|
|
}
|
2013-10-28 19:14:23 -04:00
|
|
|
}
|