Hi,

try the following.

- define a new CCK content type with a filefield, which is set to be required
- create a new node of this content type and upload a file
- edit the node, remove the uploaded file and try to delete the node
---> It will say that a file must be uploaded, because the filefield is required.
- upload a new file and hit delete of the node again
---> Node gets deleted, but the newly uploaded file is not deleted.

CommentFileSizeAuthor
#4 filefield_delete_temporary.patch2.24 KBquicksketch
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

quicksketch’s picture

Title: Uploaded files not deleted in all cases » Delete Temporary Files Sooner
Category: bug » task

Hi there, yes what you say is true, but the file is not "abandoned", it's recorded in the database as "temporary" and will be deleted after 6 hours if the file is not made permanent. You're right though in that it should be possible to make a record of temporary files that were created while editing the node, then delete them immediately when the node is saved or when the file is removed from the form.

advseb’s picture

Ah ok, I see. Does that mean the file gets automatically deleted after 6 hours also from the harddisk or is just the entry in the files table removed? In the first case (file gets deleted from the harddisk), I think this is fine and I suggest to close this report.

quicksketch’s picture

Does that mean the file gets automatically deleted after 6 hours also from the harddisk or is just the entry in the files table removed?

The file is deleted both from disk and from the database. Of course this requires cron to be running in order for the cleanup to occur. See the system_cron() function for details of the delete.

quicksketch’s picture

Status: Active » Needs review
FileSize
2.24 KB

Turns out this task was much easier than I thought it was going to be. Since we have the convenience of the temporary status and FileField's reference counting, it's a piece of cake to simply check if the file is in use when the "Remove" button is clicked. This patch immediately deletes files when they're not needed.

quicksketch’s picture

Status: Needs review » Fixed

Committed. Please reopen if this change has caused any problems.

Status: Fixed » Closed (fixed)

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