Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feature/override-visibility-on-c…
Browse files Browse the repository at this point in the history
…opy'
  • Loading branch information
kuzmin.dn committed Sep 26, 2017
2 parents cabbb0a + bac95d4 commit 963b771
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/AwsS3Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ class AwsS3Adapter extends AbstractAdapter implements CanOverwriteFiles
*/
protected $options = [];

/**
* @var string
*/
protected $overrideVisibilityOnCopy;

/**
* Constructor.
*
Expand All @@ -72,6 +77,12 @@ public function __construct(S3Client $client, $bucket, $prefix = '', array $opti
$this->s3Client = $client;
$this->bucket = $bucket;
$this->setPathPrefix($prefix);

if (array_key_exists('override_visibility_on_copy', $options)) {
$this->overrideVisibilityOnCopy = $options['override_visibility_on_copy'] === AdapterInterface::VISIBILITY_PUBLIC
? 'public-read' : 'private';
unset($options['force_visibility']);
}
$this->options = $options;
}

Expand Down Expand Up @@ -390,14 +401,19 @@ public function updateStream($path, $resource, Config $config)
*/
public function copy($path, $newpath)
{
if ($this->overrideVisibilityOnCopy) {
$acl = $this->overrideVisibilityOnCopy;
} else {
$acl = $this->getRawVisibility($path) === AdapterInterface::VISIBILITY_PUBLIC ? 'public-read' : 'private';
}

$command = $this->s3Client->getCommand(
'copyObject',
[
'Bucket' => $this->bucket,
'Key' => $this->applyPathPrefix($newpath),
'CopySource' => urlencode($this->bucket . '/' . $this->applyPathPrefix($path)),
'ACL' => $this->getRawVisibility($path) === AdapterInterface::VISIBILITY_PUBLIC
? 'public-read' : 'private',
'ACL' => $acl,
] + $this->options
);

Expand Down

0 comments on commit 963b771

Please sign in to comment.