Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IMT-109 / DDST-536: Suppress writability #24

Merged
merged 5 commits into from
Sep 23, 2024
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
2 changes: 1 addition & 1 deletion src/Plugin/migrate/source/Foxml.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ protected function generateIds() : \Traversable {
*/
protected function generatePaths() : \Traversable {
foreach ($this->generateIds() as $id) {
yield $id => $this->objectStorage->dereference($id);
yield $id => "foxml://object/{$id}";
}
}

Expand Down
17 changes: 17 additions & 0 deletions src/StreamWrapper/Foxml.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
*/
class Foxml extends LocalReadOnlyStream {

use NotWritableTrait;

/**
* The datastream low-level adapter manager service.
*
Expand Down Expand Up @@ -133,4 +135,19 @@ public function getDescription() {
return 'FOXML object/datastream storage dereferencing.';
}

/**
* {@inheritDoc}
* phpcs:disable Drupal.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
*/
public function url_stat($uri, $flags) {
return static::applyMask(parent::url_stat($uri, $flags));
}

/**
* {@inheritDoc}
*/
public function stream_stat() {
return static::applyMask(parent::stream_stat());
} // phpcs:enable Drupal.NamingConventions.ValidFunctionName.ScopeNotCamelCaps

}
29 changes: 29 additions & 0 deletions src/StreamWrapper/NotWritableTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Drupal\foxml\StreamWrapper;

/**
* Helper trait to mask writability from file modes.
*/
trait NotWritableTrait {

/**
* Apply mask to suppress writability being reported.
*
* @param array|false $result
* The stat() result in which to mask the mode.
*
* @return array|false
* The masked stat() result.
*/
protected static function applyMask(array|false $result) : array|false {
if (!$result) {
return FALSE;
}

$result[2] = ($result['mode'] &= ~0o222);

return $result;
}

}
6 changes: 4 additions & 2 deletions src/StreamWrapper/Substream.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
class Substream extends ReadOnlyStream {
const SCHEME = 'foxml.substream';

use NotWritableTrait;

/**
* The target resource from which to extract the substream.
*
Expand Down Expand Up @@ -202,7 +204,7 @@ public function stream_tell() {
* {@inheritdoc}
*/
public function stream_stat() {
return fstat($this->proxy);
return static::applyMask(fstat($this->proxy));
}

/**
Expand Down Expand Up @@ -260,7 +262,7 @@ public function url_stat($path, $flags) {
$target_stat = stat($target);

if ($target_stat) {
return $stat + $target_stat;
return static::applyMask($stat + $target_stat);
}
else {
throw new \Exception(strtr('Failed to stat target !file for !path', [
Expand Down
Loading