When trying to do a file_unmanaged_copy() between two URIs to files stored on S3, I got this error from PHP:

The specified file storage-field-image://images/article/2013/02/27/lotus.jpg was not copied because it would overwrite itself.

The error comes from file_unmanaged_copy() which expects the realpath of source and destination to be different OR realpath of source to be FALSE.

Since no code is implemented in the method, it returns NULL for both source and destination, so file_unmanaged_copy() thinks the paths are equal.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

esbenvb’s picture

This patch solves the problem.

IMPORTANT: When porting the patch, make sure to provide proper author information as specified on http://drupal.org/user/989064 - thanks.

Island Usurper’s picture

I like it. It'd be kind of nice if it would detect if it's using the Filesystem service and return a good value then, but it's probably not necessary.

jbrown’s picture

DrupalStorageStreamWrapper is just a hack so that file and image fields can utilise Storage API. It is not intended to be used in this manner.

esbenvb’s picture

#4 But it's not unusual that a module tries to copy from one file URI to another - and without this patch, it will fail because NULL == NULL and NULL !==FALSE...

bgilhome’s picture

Is this on the right track?

  public function realpath() {
    try {
      $storage = storage_core_bridge_load($this->uri);
    }
    catch (StorageException $e) {
      return;
    }
	$container = $storage->selectContainerInstance();
	if ($container && get_class($container) == 'StorageFS')
	  return drupal_realpath($storage->getUri());
	else 
	  return FALSE;
  }
dansanjou’s picture

#5 works for me, I just did a little change to the return value it wasn't returning the correct path with the $storage->getUri

dansanjou’s picture

Issue summary: View changes

typo

queenvictoria’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community

Works for me and fixes an issue with Storage API and PDF to Image
https://www.drupal.org/project/pdf_to_imagefield

Thanks @dansanjou

RTBC +1

Perignon’s picture

Assigned: Unassigned » Perignon
Perignon’s picture

Have to re-roll this patch because of file changes.

  • Perignon committed 20ceb0e on 7.x-1.x authored by dansanjou
    Issue #1929100 by esbenvb, dansanjou: DrupalStorageStreamWrapper::...
Perignon’s picture

Status: Reviewed & tested by the community » Fixed

In dev! Thanks for the review!

Perignon’s picture

Issue tags: +Storage API 7.x-1.7

Tagging for release documentation.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.