diff --git a/src/StreamWrapper/Foxml.php b/src/StreamWrapper/Foxml.php index d677073..601ab11 100644 --- a/src/StreamWrapper/Foxml.php +++ b/src/StreamWrapper/Foxml.php @@ -66,7 +66,13 @@ protected function getLocalPath($uri = NULL) { $uri = $this->uri; } $target = $this->getTarget($uri); - [$subtype, $target_actual] = explode('/', $target, 2); + $exploded = explode('/', $target, 2); + if (count($exploded) === 1) { + // XXX: `foxml://object` and `foxml://datastream` on their own do not + // really point anywhere. + return FALSE; + } + [$subtype, $target_actual] = $exploded; assert(in_array($subtype, ['object', 'datastream']), 'Valid URI.'); try { diff --git a/src/Utility/Fedora3/ArchivalObjectLowLevelAdapter.php b/src/Utility/Fedora3/ArchivalObjectLowLevelAdapter.php index 282e022..c604e19 100644 --- a/src/Utility/Fedora3/ArchivalObjectLowLevelAdapter.php +++ b/src/Utility/Fedora3/ArchivalObjectLowLevelAdapter.php @@ -48,15 +48,25 @@ public function getIterator() : \Traversable { // Recurse through the directory. $files = new \RecursiveDirectoryIterator($this->basePath, $flags); + // Pre-filter deletable files away. + // Adapted from: https://github.com/discoverygarden/akubra_adapter/blob/38000f45a25cf99c5f34a53cf93193e6fdff88b9/src/Utility/Fedora3/ObjectLowLevelAdapter.php#L35-L42 + $non_deletable_files = new \RecursiveCallbackFilterIterator( + $files, + function (\SplFileInfo $file) { + return $file->isDir() || ($file->isFile() && $file->isReadable() && + !$file->isWritable() && !$file->getPathInfo()->isWritable()); + } + ); + // A filter could be added here if necessary. if ($this->pattern) { $filter = new \RecursiveCallbackFilterIterator( - $files, + $non_deletable_files, [$this, 'filterCallback'] ); } else { - $filter = $files; + $filter = $non_deletable_files; } // Get an iterator of our iterator... @@ -87,28 +97,20 @@ public function getIteratorType() : int { * * @param \SplFileInfo $current * The item being considered. - * @param mixed $key - * The key for the item being considered. - * @param \Iterator $iterator - * The iterator in which this filter callback is being used. * * @return bool * TRUE if the given item should be considered; otherwise, FALSE. * * @see https://github.com/discoverygarden/migrate_directory/blob/87d47cd69f037f5d239af0c8124c3ed433146413/src/Plugin/migrate/source/MigrateDirectory.php#L49-L62 */ - protected function filterCallback(\SplFileInfo $current, $key, \Iterator $iterator) : bool { - // Get the current item's name. - /** @var \SplFileInfo $current */ - $filename = $current->getFilename(); - + protected function filterCallback(\SplFileInfo $current) : bool { if ($current->isDir()) { // Always descend into directories. return TRUE; } // Match the filename against the pattern. - return preg_match($this->pattern, $filename) === 1; + return preg_match($this->pattern, $current->getFilename()) === 1; } /**