Skip to content

Commit

Permalink
Merge pull request #524 from MitrahSoft/LDEV_1609
Browse files Browse the repository at this point in the history
Fix for LDEV-1609
  • Loading branch information
micstriit committed Sep 5, 2018
2 parents 959007a + 3d1fa8d commit 7b7fd58
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
9 changes: 9 additions & 0 deletions core/src/main/java/lucee/runtime/tag/FileTag.java
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,15 @@ private void actionWrite() throws PageException {
if(output==null)
throw new ApplicationException("attribute output is not defined for tag file");
checkFile(pageContext, securityManager, file, serverPassword,createPath,true,false,true);
if(file.exists()) {
//Error
if(nameconflict==NAMECONFLICT_ERROR) throw new ApplicationException("destination file ["+file+"] already exist");
// SKIP
else if(nameconflict==NAMECONFLICT_SKIP) return;
// OVERWRITE
else if(nameconflict==NAMECONFLICT_OVERWRITE) file.delete();
}


setACL(pageContext,file,acl);
try {
Expand Down
15 changes: 13 additions & 2 deletions test/tickets/_LDEV1609.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,20 @@ component extends="org.lucee.cfml.test.LuceeTestCase"{
});

it( title='Checking cffile action ="write" with attribute nameConflict="error" ',body=function( currentSpec ) {
cffile( action="write", file="#variables.Dir#/test.txt", output="testName2", charset="utf-8", nameconflict="error" ){
var hasError = false;
try {
cffile( action="write", file="#variables.Dir#/test.txt", output="testName2", charset="utf-8", nameconflict="error" ){
}
} catch ( any e ){
hasError = true
}
expect(trim(fileRead("#variables.Dir#/test.txt"))).toBe('testName');
expect(hasError).toBeTrue();
});

it( title='Checking cffile action ="write" with attribute nameConflict="overwrite" ',body=function( currentSpec ) {
cffile( action="write", file="#variables.Dir#/test.txt", output="testName2", charset="utf-8", nameconflict="overwrite" ){
}
expect(trim(fileRead("#variables.Dir#/test.txt"))).toBe('testName2');
});
});
}
Expand Down

0 comments on commit 7b7fd58

Please sign in to comment.