cffile problem on Unix

2008 February 06
tags: ColdFusion
by Nick

I was working with some legacy code on a Unix server recently and kept running into a permissions error... The cleanup process of this particular task would fail with the message: "Delete" cannot be performed. The problem was with a cffile tag:

<cffile action="delete" file="#directory#/#file#"/>

I was curious to see whether or not the same action could be performed using shell commands instead... I've used cfexecute on Windows servers before, but never tried to run commands on a Unix server. The following tag worked as a replacement for cffile:

<cfexecute name="/bin/rm" arguments="#directory#/#file#" timeOut="15"/>

Which is equivalent to running this at the command prompt:
$/bin/rm /path/file

This is a good alternative to keep in mind should a configuration problem keep a particular tag from running. I don't particularly like it because it keeps the code from being portable, but I guess that could be easily remedied using a conditional based on #server.os.name#:

...

<!--- clear expired files based on platform --->
<cfif server.OS.Name contains "windows">
<!--- delete files --->
<cffile action="delete" file="#directory#/#file#"/>
<cfelse>
<!--- run shell command for solaris --->
<cfexecute name="/bin/rm" arguments="#directory#/#file#" timeOut="15"/>
</cfif>

...
No Responses leave one →

Leave a Reply