Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion config/config.sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -1847,7 +1847,9 @@
// if omitted
'serviceName' => 'swift',
// The Interface / URL Type, optional
'urlType' => 'internal'
'urlType' => 'internal',
// Maximum amount of data that can be uploaded
'totalSizeLimit' => 1024 * 1024 * 1024,
],
],

Expand Down
32 changes: 32 additions & 0 deletions lib/private/Files/ObjectStore/ObjectStoreStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use OC\Files\Cache\Cache;
use OC\Files\Cache\CacheEntry;
use OC\Files\Storage\PolyFill\CopyDirectory;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\Files\Cache\ICache;
use OCP\Files\Cache\ICacheEntry;
use OCP\Files\Cache\IScanner;
Expand All @@ -26,6 +27,8 @@
use OCP\Files\ObjectStore\IObjectStoreMultiPartUpload;
use OCP\Files\Storage\IChunkedFileWrite;
use OCP\Files\Storage\IStorage;
use OCP\IDBConnection;
use OCP\Server;
use Psr\Log\LoggerInterface;

class ObjectStoreStorage extends \OC\Files\Storage\Common implements IChunkedFileWrite {
Expand All @@ -40,6 +43,7 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common implements IChunkedFil
private bool $handleCopiesAsOwned;
protected bool $validateWrites = true;
private bool $preserveCacheItemsOnDelete = false;
private ?int $totalSizeLimit = null;

/**
* @param array $parameters
Expand All @@ -63,6 +67,9 @@ public function __construct(array $parameters) {
$this->validateWrites = (bool)$parameters['validateWrites'];
}
$this->handleCopiesAsOwned = (bool)($parameters['handleCopiesAsOwned'] ?? false);
if (isset($parameters['totalSizeLimit'])) {
$this->totalSizeLimit = $parameters['totalSizeLimit'];
}

$this->logger = \OCP\Server::get(LoggerInterface::class);
}
Expand Down Expand Up @@ -755,6 +762,7 @@ public function putChunkedWritePart(
if (!$this->objectStore instanceof IObjectStoreMultiPartUpload) {
throw new GenericFileException('Object store does not support multipart upload');
}

$cacheEntry = $this->getCache()->get($targetPath);
$urn = $this->getURN($cacheEntry->getId());

Expand Down Expand Up @@ -812,4 +820,28 @@ public function cancelChunkedWrite(string $targetPath, string $writeToken): void
public function setPreserveCacheOnDelete(bool $preserve) {
$this->preserveCacheItemsOnDelete = $preserve;
}

public function free_space(string $path): int|float|false {
if ($this->totalSizeLimit === null) {
return FileInfo::SPACE_UNLIMITED;
}

// To avoid iterating all objects in the object store, calculate the sum of the cached sizes of the root folders of all object storages.
$qb = Server::get(IDBConnection::class)->getQueryBuilder();
$result = $qb->select($qb->func()->sum('f.size'))
->from('storages', 's')
->leftJoin('s', 'filecache', 'f', $qb->expr()->eq('f.storage', 's.numeric_id'))
->where($qb->expr()->like('s.id', 'object::%', IQueryBuilder::PARAM_STR))
->andWhere($qb->expr()->eq('f.path', $qb->createNamedParameter('')))
->executeQuery();
$used = $result->fetchOne();
$result->closeCursor();

$available = $this->totalSizeLimit - $used;
if ($available < 0) {
$available = 0;
}

return $available;
}
}
Loading