CFFILE not deleting "read-only" files
I have a simple loop that is used to clean up old files within a directory:
<cfdirectory action="list" name="qDir" directory="#variables.path#">
<cfloop query="qDir">
<cfif qDir.Type eq "File">
<cfif DateDiff("h", qDir.DateLastModified, Now()) gt attributes.keep_for_hours>
<cfset variables.full_file_path = variables.path & qDir.Name>
<cfif FileExists(variables.full_file_path)>
<cffile action="delete" file="#variables.full_file_path#">
</cfif>
</cfif>
</cfif>
</cfloop>This is on Linux where ColdFusion is running as apache.
Recently a system scan process has been leaving behind files owned by root within the directory resulting in an error stating:
“The file or directory <filename> provided as the Source is read-only. - The Delete cannot be performed.”
While it’s true that the file is read-only, apache owns the directory the file is in and should still be able to delete the file.
How do I go about encouraging CFFILE to remove the file anyway?
