You are here

public function FlysystemS3FileSystem::chmod in Flysystem - S3 2.0.x

Same name and namespace in other branches
  1. 8 src/File/FlysystemS3FileSystem.php \Drupal\flysystem_s3\File\FlysystemS3FileSystem::chmod()

Extend chmod(), respecting S3's ACL setting.

With Drupal's private files, chmod() is called by file_save_upload() to ensure the new file is readable by the file server, using the same file system permissions as the public file system. However, since private files are stored outside of the docroot, they are forced to go be accessed through Drupal's file permissions handling.

With S3, \Twistor\FlysystemStreamWrapper::stream_metadata() automatically maps chmod() calls to basic S3 ACLs, which means that while a file can be initially uploaded as 'private', Drupal will immediately chmod it to public using the default file mask in settings.php.

This method checks to see if we are using a private S3 scheme, and if so, ensures that group / other permissions are always unset, ensuring the stream wrapper preserves private permissions.

Parameters

string $uri: A string containing a URI file, or directory path.

int $mode: Integer value for the permissions. Consult PHP chmod() documentation for more information.

Return value

bool TRUE for success, FALSE in the event of an error.

Overrides FileSystem::chmod

See also

\Twistor\FlysystemStreamWrapper::stream_metadata

File

src/File/FlysystemS3FileSystem.php, line 62

Class

FlysystemS3FileSystem
Decorates the Drupal FileSystem service to handle chmod() for S3.

Namespace

Drupal\flysystem_s3\File

Code

public function chmod($uri, $mode = NULL) {
  $scheme = parent::uriScheme($uri);
  if ($this
    ->isPrivateS3Scheme($scheme)) {
    is_dir($uri) ? $mode = 0700 : ($mode = 0600);
  }
  return parent::chmod($uri, $mode);
}