field_file_save_file($temp_filepath, array(), $filepath, FILE_EXISTS_REPLACE); creates a duplicate records in {files}.

CommentFileSizeAuthor
#5 filefield_replace_1.patch1.38 KBamitaibu
Snap1.png7.89 KBamitaibu

Comments

dopry’s picture

Status: Active » Postponed (maintainer needs more info)

Does it also create a duplicate copy of the file in the files folder?

amitaibu’s picture

No, it doesn't create a duplicate file (FILE_EXISTS_REPLACE).

dopry’s picture

Status: Postponed (maintainer needs more info) » Active

hmm..well that is dirty... I guess we should correct it a some point.. do you have time to write a patch?

amitaibu’s picture

I'd love to help. Can you point me in the right direction, i.e. how you would like it to be fixed.

[EDIT]: I've started working on a patch, i'll roll soon.

amitaibu’s picture

Status: Active » Needs review
StatusFileSize
new1.38 KB

Attached file makes sure that when FILE_EXISTS_REPLACE is used file isn't renamed and if a database record already exists it is updated.

drewish’s picture

Well this ties in nicely with a core issue: #334303: Handling overwriting of managed files (with unittests!). You reminded me that file_save_upload() also need to take replacement into account. That said I'm not sure we should be replacing a permanent fid with a temporary one...

dopry’s picture

Priority: Normal » Critical

upping to critical to keep it on my radar.

dopry’s picture

Status: Needs review » Fixed

just to make my life easier since this stuff is intended for filefield only... I removed the replace option all together... delete then update if you need to path to be saved correctly...

This also applies to field_file_save_upload.

Status: Fixed » Closed (fixed)

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