There is apparently a problem with deleting files attached to FileField field from disk. I have FileField connected with FileField Paths. Uploading generally works fine, after saving node the file is moved to proper location and everything is fine. Now let's assume there is a particular file attached with filefield widget, in only one node. When I try to delete that file it says ok, but the file stays on disk and in the database. Uploading a changed file with the same name causes it to be renamed during upload (sequence number appended to name) because a file with the same name already exists.

Comments

quicksketch’s picture

Category: bug » support
Priority: Major » Normal

I answer this question every few months, I'm sure a search would reveal the answer.

The reason for this is because clicking the "Remove" button does not immediately delete the file from disk when you're editing a node. The file is only removed from disk when you click the "Save" button on the node, since if you clicked "Remove", but then closed the window, you didn't "Save" your changes, so the file needs to continue to exist.

So if you edit a node and click "Remove", the file is still there. Then you upload a new file with the same name, it collides with the old file name so it gets _0 added to it. Then you click "Save" and the old file is deleted, but the new file still has the _0 addition.

Now you'll probably say "why can't the new image have the same name after save?" Well because if you were using a module like "Insert" to insert an image into the post while editing, the path of the image would have _0 added to it. So if you renamed it upon save, the image src attribute would break.

It's possible for a module (like FileField Paths) to solve this problem (it's already rewriting the body and textareas on save), but it's not something that will be a part of FileField (now the core "File" module in Drupal 7).

p0wer’s picture

I did a test:
- clicked Edit
- uploaded a new random file to a page, it got saved to a temporary dir on the server
- clicked save, FileField Paths moved the file to proper location
- clicked Edit once again
- removed the file from the page, right, nothing happened on disk
- clicked save.

Guess what - the file was still there, it was not deleted. It wasn't referenced anywhere else in the meantime. I'd like to track down what's causing this, any hints?

quicksketch’s picture

If you're using FileField Paths module, I suggest asking over there.

quicksketch’s picture

Status: Active » Closed (works as designed)
quicksketch’s picture

Issue summary: View changes

disk