<cffile action="rename"> and nameconflict
Reading about Jeremy Battle's woes inadvertently overwriting existing files when renaming uploads recently, I was reminded of being similarly bitten not long ago. As Jeremy points out:
While this was a logical error, I would have thought that since CFFile rename has no arguments for how to handle name conflicts like CFFile upload that it would have errored out on the rename explaining that the file already existed. But after a simple test, I found out this is in fact not the case and it will overwrite a file.
This was not the first blog post I'd read on the issue (Raymond Camden dealt with it a while ago), but I was surprised to find no requests on the Adobe Bug Tracker for an enhancement to add a "nameconflict" attribute for <cffile action="rename">
as exists with the <cffile action="upload">
tag.
So I duly hit the New Bug button and started entering the details. But as I was typing, I began to question whether CF should in fact be offering to handle name conflicts in this case.
With <cffile action="upload">
, your primary intent is to transfer a file to the server. It's possible that a file with the same name already exists in the destination location so it's convenient to have CF deal with that in various ways (error, skip, overwrite or makeunique).
If you use <cffile action="rename">
, however, CF is surely entitled to assume that your main goal is to give the file the new name you specify regardless of anything else. It's up to you to first ensure the new name is unique if it needs to be (and Raymond's post includes code for doing that).
I'm not saying it wouldn't be useful to have the option of having CF handle conflicts across all the file operations, but I can see the rationale for it only being available for uploads.
What would be good though is to have a script version, i.e. FileRename()
, which seems to be the only equivalent missing from the File functions now that upload has been implemented in 9.0.1 Please feel free to vote if you agree.
Comments