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.

Files: 
CommentFileSizeAuthor
#4 filefield_delete_temporary.patch2.24 KBquicksketch

Comments

Title:Uploaded files not deleted in all casesDelete 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.

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.

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.

Status:Active» Needs review
StatusFileSize
new2.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.

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.