tracker issue : CF-4203313

select a category, or use search below
(searches all categories and all time range)
Title:

fileWrite() not equivalent to <cffile action="write"...> as does not support a "mode" parameter

| View in Tracker

Status/Resolution/Reason: To Fix//BugReVerified

Reporter/Name(from Bugbase): Tim Saunders / ()

Created: 09/03/2018

Components: File Management, CFFile

Versions: 11.0

Failure Type: Incorrect w/Workaround

Found In Build/Fixed In Build: 11,0,14,307976 /

Priority/Frequency: Normal / Some users will encounter

Locale/System: UK English / CentOS 7.2

Vote Count: 2

Problem Description:As far as I can tell I can't set the permissions of a file I create in cfscript without first creating the file and then using fileSetAccessMode()

Steps to Reproduce:
<!--- works fine --->
<cffile action="write" file="file" output="content" mode="664">

<!--- creates file with wrong access mode, fileWrite() does not support a mode parameter --->
<cfscript>
    fileWrite( file, content, '664' );
</cfscript>

Actual Result: fileWrite() creates files with incorrect access modes

Expected Result: fileWrite() should create files with the correct access mode

Any Workarounds: Use tag function, but cfscript shouldn't be 2nd class

Attachments:

Comments:

Hi Tim, This is clearly a bug. Filewrite function supports only three parameters -> filepath, data, charset. However, there are lot of parameters supported by <cfile action='write'> tag such as mode, addnewline etc. Script syntax should have the support as well. We should provide support for all of them(including mode) in filewrite function. Moving it  to to->fix.
Comment by Poonam J.
29689 | September 12, 2018 05:24:11 AM GMT
Hi Poonam, Agreed, well, mostly.. :) Regarding addnewline: AddNewLine1: FileWrite() doesn't add a new line. FileWriteLine() adds a new line. AddNewLine2: FileAppend() is undocumented* and adds a new line. FileAppendLine() doesn't exist. Suggestions for addnewline: AddNewLineA: Add `addnewline` parameter, w/ default=false, to FileWrite() and FileAppend() (making FileWriteLine() obsolete and FileAppendLine() unneeded). -or- AddNewLineB: Change FileAppend() to not add a new line (FileAppend is undocumented*, thus could still be changed), and introduce FileAppendLine() for adding new line. Regarding fileObject vs filePath parameter: FileObjPath1: FileWrite() and FileAppend() work on a file object or a file path. FileWriteLine() only works on a file object, not on a file path. Suggestion for fileObject vs filePath parameter: FileObjPathA: FileWriteLine() should also work on a file path. FileObjPathB: FileAppendLine(), if added, should work on both a file object or a file path. Regarding charset parameter: Charset1: FileWrite() has an optional charset parameter. Charset2: FileWriteLine() is missing the charset parameter. Charset3: FileAppend() has a required* charset parameter. Suggestion for charset parameter: CharsetA: FileWriteLine() should have an optional charset parameter. CharsetB: FileAppend()'s charset parameter should be made optional (FileAppend is undocumented*, thus could still be changed). CharsetC: FileAppendLine, if added, should have an optional charset parameter. And, of course, if FileAppendLine() is added, it should work on ram:// and s3:// paths. * - Credit to Matthew Brown for discovering these. Thanks!, -Aaron
Comment by Aaron N.
30286 | February 16, 2019 11:05:01 PM GMT
+1 - But CF-4204029 is a blocker.
Vote by Aaron N.
30290 | February 17, 2019 05:02:41 AM GMT
Hi Adobe, Please ensure FileWrite() and FileAppend() take the same parameters and defaults, just as <cffile action="write"> and <cffile action="append"> take the same attributes and defaults. Related ticket: CF-4204029 Thanks!, -Aaron
Comment by Aaron N.
30702 | May 09, 2019 12:38:33 AM GMT
I realize addnewline defaults to *true* in <cffile action="write"> and <cffile action="append">, but backward-compat says <cffile>/FileWrite/FileAppend cannot have matching addnewline default.
Comment by Aaron N.
30703 | May 09, 2019 12:53:56 AM GMT