feat: store original storage id and path in object store metadata

Signed-off-by: Robin Appelman <robin@icewind.nl>
pull/51779/head
Robin Appelman 6 months ago
parent 94114b99f7
commit 8aae332622
No known key found for this signature in database
GPG Key ID: 42B69D8A64526EFB
  1. 2
      lib/private/Files/ObjectStore/ObjectStoreStorage.php
  2. 12
      lib/private/Files/ObjectStore/S3.php
  3. 17
      lib/private/Files/ObjectStore/S3ObjectTrait.php
  4. 2
      lib/public/Files/ObjectStore/IObjectStoreMetaData.php

@ -482,6 +482,8 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common implements IChunkedFil
$mimetype = $mimetypeDetector->detectPath($path);
$metadata = [
'mimetype' => $mimetype,
'original-storage' => $this->getId(),
'original-path' => $path,
];
$stat['mimetype'] = $mimetype;

@ -95,6 +95,16 @@ class S3 implements IObjectStore, IObjectStoreMultiPartUpload, IObjectStoreMetaD
]);
}
private function parseS3Metadata(array $metadata): array {
$result = [];
foreach ($metadata as $key => $value) {
if (str_starts_with($key, 'x-amz-meta-')) {
$result[substr($key, strlen('x-amz-meta-'))] = $value;
}
}
return $result;
}
public function getObjectMetaData(string $urn): array {
$object = $this->getConnection()->headObject([
'Bucket' => $this->bucket,
@ -104,7 +114,7 @@ class S3 implements IObjectStore, IObjectStoreMultiPartUpload, IObjectStoreMetaD
'mtime' => $object['LastModified'],
'etag' => trim($object['ETag'], '"'),
'size' => (int)($object['Size'] ?? $object['ContentLength']),
];
] + $this->parseS3Metadata($object['Metadata'] ?? []);
}
public function listObjects(string $prefix = ''): \Iterator {

@ -77,6 +77,13 @@ trait S3ObjectTrait {
return $fh;
}
private function buildS3Metadata(array $metadata): array {
$result = [];
foreach ($metadata as $key => $value) {
$result['x-amz-meta-' . $key] = $value;
}
return $result;
}
/**
* Single object put helper
@ -87,12 +94,15 @@ trait S3ObjectTrait {
* @throws \Exception when something goes wrong, message will be logged
*/
protected function writeSingle(string $urn, StreamInterface $stream, array $metaData): void {
$mimetype = $metaData['mimetype'] ?? null;
unset($metaData['mimetype']);
$this->getConnection()->putObject([
'Bucket' => $this->bucket,
'Key' => $urn,
'Body' => $stream,
'ACL' => 'private',
'ContentType' => $metaData['mimetype'] ?? null,
'ContentType' => $mimetype,
'Metadata' => $this->buildS3Metadata($metaData),
'StorageClass' => $this->storageClass,
] + $this->getSSECParameters());
}
@ -107,13 +117,16 @@ trait S3ObjectTrait {
* @throws \Exception when something goes wrong, message will be logged
*/
protected function writeMultiPart(string $urn, StreamInterface $stream, array $metaData): void {
$mimetype = $metaData['mimetype'] ?? null;
unset($metaData['mimetype']);
$uploader = new MultipartUploader($this->getConnection(), $stream, [
'bucket' => $this->bucket,
'concurrency' => $this->concurrency,
'key' => $urn,
'part_size' => $this->uploadPartSize,
'params' => [
'ContentType' => $metaData['mimetype'] ?? null,
'ContentType' => $mimetype,
'Metadata' => $this->buildS3Metadata($metaData),
'StorageClass' => $this->storageClass,
] + $this->getSSECParameters(),
]);

@ -9,7 +9,7 @@ namespace OCP\Files\ObjectStore;
/**
* Interface IObjectStoreMetaData
*
* @psalm-type ObjectMetaData = array{mtime?: \DateTime, etag?: string, size?: int, mimetype?: string, filename?: string}
* @psalm-type ObjectMetaData = array{mtime?: \DateTime, etag?: string, size?: int, mimetype?: string, filename?: string, original-path?: string, original-storage?: string}
*
* @since 32.0.0
*/

Loading…
Cancel
Save