When replacing a file that is located in a sub directory, the original location (manage fields > file destination) is not respected. The file is pulled out of its sub folder and upload to the ROOT of the public or private destination instead.

I think this might be a bug. Because when swapping files between private and public locations, File Entity tries to keep the sub directory path intact. You just have to make sure the same sub directories exist on both sides. But when 'replacing files' the original sub directory is not taken into account.

Could anyone please have a look? I'm a themer, not a developer, but I can help test and review possible patches.

Many thanks

Comments

markgifford’s picture

I can confirm this. Using 2.0-beta1.

Steps to reproduce:

- Add a file field to a content type
- In field settings, define a subdirectory "mysubdir" in which to store the files
- Create item of content, attaching the file
- Check it's uploaded to public://mysubdir
- Go to /admin/content/file, edit the file, replace the file
- The replaced file won't be in public://mysubdir, but will instead be in public://

yazzbe’s picture

Title: Replace file does not respect original file directory when sub folder is used » Replace file does not respect original file location or sub directory
Issue summary: View changes
dave reid’s picture

Version: 7.x-2.0-beta1 » 7.x-2.x-dev
Status: Active » Needs work
StatusFileSize
new826 bytes

Confirmed. Looks like we're missing test coverage for this, but this should fix it in the meantime.

yazzbe’s picture

Many thanks Dave, appreciated.
I've applied the patch. However, in my local install replacing files

  • works correctly for files in sub directories now
  • doesn't work for files in the public/private root any more

I got an error "destination directory is not properly configured", when trying to replace a file in the (public or private) root folder.

colan’s picture

+++ b/file_entity.pages.inc
@@ -807,7 +807,7 @@ function file_entity_edit_submit($form, &$form_state) {
+    $destination_uri = dirname($file->uri) . '/' . drupal_basename($replacement->uri);

I think #3 needs to be using drupal_dirname(), not dirname(). Otherwise we're losing the scheme.

dave reid’s picture

Status: Needs work » Needs review
StatusFileSize
new833 bytes

Good point, and again, lack of test coverage for this seems to be a problem. Re-rolled using drupal_dirname().

colan’s picture

Status: Needs review » Reviewed & tested by the community

Looks good & works for me.

The last submitted patch, 3: 2353351-replace-file-in-subdir.patch, failed testing.

yazzbe’s picture

Tested patch #6 against 2.0-beta-1 successfully.

Thanks guys !

  • aaron committed 0dafee6 on 7.x-2.x
    Issue #2353351 by Dave Reid: fixed Replace file does not respect...
aaron’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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