Media: 7.x-2.0-unstable7+56-dev
File_entity: 7.x-2.0-unstable7+91-dev

Not sure if my setup is not configured correctly or if this is a bug. When I try to replace a file, a new file is created. The file I am trying to replace remains and nothing changes. The replacement file becomes a new file with a new id. When I edit the new file the "replace file" field does not appear.
When I try to link to the new file through ckeditor the url is ..../system/temporary/file.pdf instead of .../sites/default/files/file.pdf

When replacing a file I would not expect a new file to be created, but simply the old phisical file to be replaced, and maybe the name updated if they differ.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Dave Reid’s picture

Status: Active » Postponed (maintainer needs more info)

What are you doing to perform the file replacement? This isn't at all how the file replacement functionality actually works so I just need to know a bit more about what you're doing.

plinto’s picture

FileSize
30.02 KB
34.5 KB
34.21 KB
7.73 KB
  1. Select Content from admin menu
  2. Select the Files tab
  3. Select Edit for the file that needs replacement
  4. Select Replace File and select the new file
  5. Save

My document file type has been modified, I added a term reference field but I don't know if this would cause the issue

The permissions on the file directory are drwxrwxrwx so there should be no problems replacing the files either.

Before:
Before replace
edit screen
After:
After replace
edit screen of new file

Thanks for any assistance you can provide

gmclelland’s picture

@plinto - I was also a little confused at first. This is also how my setup works. If you look at the file paths of the two files, the one that got replaced will show a temporary://something.pdf.

Those temporary files will be deleted by cron after 6 hours I think.

@Dave Reid - maybe we shouldn't show temp files in the files tab? Maybe it would help eliminate some confusion?

plinto’s picture

@gmclelland - I ran cron manually a few times, and I also left it overnight to see what happens (I have cron set to run every 3h) but nothing changed.

The older file has not been replaced and there are still 2 versions

If the new file where temporary and deleted that would be ok. The main problem is that the file needing replacement is not being replaced, it is still the old file.

gmclelland’s picture

plinto - If the older file still has usage, then it won't be deleted. Check the usage link on admin/content/file for both files(old one and new one) and see if it has any usage.

Something else may be using the old file. Could be a node revision or a file field using the file?

gmclelland’s picture

bneil’s picture

Status: Postponed (maintainer needs more info) » Active
ianthomas_uk’s picture

file_entity_edit_validate() saves the replacement file, and file_entity_edit_submit() then copies the replacement file over the original (using file_unmanaged_copy), but I can't see where the temporary replacement file is meant to be cleaned up. Should there be a call to file_delete() after the call to file_unmanaged_copy() in file_entity_edit_submit()?

Dave Reid’s picture

No, we don't need to be responsible for removing the temporary upload file because the system is supposed to take care of that for you. I suppose we could use file_unmanaged_move() instead of file_unmanaged_copy() though.

ianthomas_uk’s picture

It seems like the file itself is being cleaned up, but an entry is being left in the file_managed table.

This shows up at admin/content/file and is also causing PDO errors when trying to upload a file with the same filename (which should probably be filed as a separate bug anyway).

acbramley’s picture

I'm seeing this behaviour and it confused both me and my users. We shouldn't be displaying temporary files in the file overview in my opinion. Note: This can be worked around by adding a filter to the admin view to exclude files with paths that start with temporary://

sheldonkreger’s picture

I followed the same steps as #2.

I'm using Media 2.x-alpha2 and the original file remains in the media root, attached to nodes, etc. The file I'm trying to replace it with is actually being moved to tmp to be deleted by cron. So, the old file stays in place, and my new file is moved directly to tmp.

This is backwards of what we're intending to do here, right?

Before the upgrade to Media and FE 2.x, we were using the filefield_paths module. That module was uninstalled before we updated. The way my files are placed in the filesystem makes it clear that filefield_paths obviously isn't doing anything anymore (it's all dictated by Media settings now).

It's also worth noting that I'm using brightcove_media and media_internet.

sheldonkreger’s picture

RE: #10

@ianmthomasuk, I cannot reproduce that problem, using identical file names. Instead, I get two files with the same name, with the replacement file uploaded into /tmp. The original file remains in place on the nodes. The file browser at admin/content/file shows two files with the same name, but different URLs.

So, my issue, I believe is related to this thread. If you're getting a PDO exception from duplicate file names, then you should open a separate issue. Please post a link to that here.

sheldonkreger’s picture

sheldonkreger’s picture

The issue above has been closed in favor of #2028089: Too much restriction for temporary files. I submitted a patch there which fixes the temp files issue described in comment 11 here.

Dave Reid’s picture

Had robeano run into this today and reviewed the replacement code again, and there definitely is a problem leaving the temporary file around if the replacement was successful.

robeano’s picture

I am able to replicate this issue as described in comment 2.

* Select Content from admin menu
* Select the Files tab
* Select Edit for the file that needs replacement
* Select Replace File and select the new file
* Save

Two files appear in /admin/content/file: the original and the file I just uploaded to replace the original. As stated above in comment 9, Core will remove these temporary files. Having to wait 6 hours for the removal of temporary files causes confusion for site administrators and editors.

If the file is successfully replaced, then the temporary file should be deleted immediately.

Dave Reid’s picture

Title: Replace File not working correctly? » Replacing a file leaves an unwanted temporary file that duplicates the replaced file
Version: 7.x-2.0-unstable7 » 7.x-2.x-dev
Issue summary: View changes
Status: Active » Needs review
FileSize
5.8 KB

Here's my first stab at the fix, which is one line of code and a bunch of changes to our tests to assume that the default files are not temporary, so that this is easier to test if a temporary file exists or not. It passes my local install so let's see if it passes the bot.

Status: Needs review » Needs work

The last submitted patch, 18: 2045611-replace-file-delete-temp-file.patch, failed testing.

Dave Reid’s picture

Status: Needs work » Needs review
FileSize
5.81 KB

Let's try this one to fix the file access tests.

Status: Needs review » Needs work

The last submitted patch, 20: 2045611-replace-file-delete-temp-file.patch, failed testing.

Dave Reid’s picture

Issue tags: +7.x-2.0 beta blocker
kmoll’s picture

Tests were failing when testing file access. By default view permission for public permanent file is set to TRUE. In the test, since we are testing trying to view access to a file without this permission, we now remove it in the setUp function of the test

kmoll’s picture

Assigned: Unassigned » kmoll
Status: Needs work » Needs review
Dave Reid’s picture

Status: Needs review » Fixed

Thanks everyone! Committed to 7.x-2.x.

  • Commit 1377ddd on 7.x-2.x by Dave Reid:
    Issue #2045611 by Dave Reid, kmoll | plinto: Fixed Replacing a file...

Status: Fixed » Closed (fixed)

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

estepix’s picture

Version: 7.x-2.x-dev » 7.x-2.0

I can reproduce this problem again in current version 7.x-2.0. It seems that some code from this other issue:

https://www.drupal.org/node/2112491

has been ported to current 2.0 version, especifically:

    if (pathinfo($replacement->uri, PATHINFO_EXTENSION) == pathinfo($file->uri, PATHINFO_EXTENSION)) {
        file_unmanaged_copy($replacement->uri, $file->uri, FILE_EXISTS_REPLACE);
    } else {

on function file_entity_edit_submit, file file_entity.pages.inc

I wonder if this could be reverted to its previous state since the feature requested in #2112491 does not seem to be implemented. I can provide diff with the relevant changes, however not sure if I should attache a patch file here or any other way.

Regards,

estepix’s picture

Sending patch

jenlampton’s picture

I am also still seeing the behavior described in #2 in the 7.x-2.2 version of file_entity. It was also happening in 7.x-2.1. Unfortunately, it looks like we can't reopen this issue. Should I open a new one?

edit: here's a duplicate issue: https://www.drupal.org/node/2887487

estepix’s picture

FYI: https://www.drupal.org/node/2887487#comment-12200833 fskreuz's patch fixes the problem and it has already gone into v2.4 of the module.