-
-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2478 from zspitzer/LDEV-3312-fileSetAttribute
LDEV-3312 use nio for fileSetAttribute readonly
- Loading branch information
Showing
4 changed files
with
68 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,65 @@ | ||
component extends="org.lucee.cfml.test.LuceeTestCase"{ | ||
function beforeAll(){ | ||
variables.base = GetDirectoryFromPath(getcurrentTemplatepath()); | ||
variables.path = base&"LDEV2410\example.txt"; | ||
if(!directoryExists(base&"LDEV2410")){ | ||
directoryCreate(base&'LDEV2410'); | ||
} | ||
variables.testfile = getTempFile( getTempDirectory(), "LDEV-2410", ".txt" ); | ||
} | ||
|
||
function run( testResults, testBox ){ | ||
describe( "test case for LDEV-2410", function() { | ||
|
||
it(title = "checking the file with READONLY Attribute", body = function( currentSpec ) { | ||
variables.myfile = FileOpen(path, "write"); | ||
FileWrite(path,"I am in readonly file"); | ||
fileSetAttribute(path,'readonly'); | ||
expect(getfileinfo(path).canRead).toBe(true); | ||
expect(getfileinfo(path).canWrite).toBe(false); | ||
if (!isWindows()) return; | ||
FileWrite( testfile, "I am a writeable file" ); | ||
|
||
FileSetAttribute( testfile, 'readonly' ); | ||
var info = getFileInfo( testfile ); | ||
expect( info.canRead ).toBe( true ); | ||
expect( info.canWrite ).toBe( false ); | ||
expect (function(){ | ||
FileWrite( testfile, "I am in readonly file" ); | ||
}).toThrow(); | ||
}); | ||
|
||
it(title = "checking the file with NORMAL Attribute", body = function( currentSpec ) { | ||
if (!isWindows()) return; | ||
FileSetAttribute( testfile, 'normal' ); | ||
var info = getFileInfo( testfile ); | ||
expect( info.canWrite ).toBe( true ); | ||
FileWrite( testfile, "I am in normal (writable) file" ); | ||
}); | ||
|
||
it(title = "checking settting a file to readOnly on linux", body = function( currentSpec ) { | ||
if (isWindows()) return; | ||
|
||
var info = getFileInfo( testfile ); | ||
expect( info.canWrite ).toBe( true ); | ||
FileWrite( testfile, "I am in normal (writable) file" ); | ||
|
||
FileSetAccessMode( testfile, "444" ); // i.e. readonly | ||
info = getFileInfo( testfile ); | ||
expect( info.canWrite ).toBe( false); | ||
expect (function(){ | ||
FileWrite( testfile, "I am in readonly file" ); | ||
}).toThrow(); | ||
|
||
FileSetAccessMode( testfile, "644" ); | ||
info = getFileInfo( testfile ); | ||
expect( info.canWrite ).toBe( true ); | ||
expect (function(){ | ||
FileWrite( testfile, "I am in normal (writable) file" ); | ||
}).notToThrow(); | ||
|
||
}); | ||
// this fails on windows, disabling | ||
it(title = "checking the file with NORMAL Attribute", skip=true, body = function( currentSpec ) { | ||
fileSetAttribute(path,'normal'); | ||
FileWrite(path,"I am in normal file"); | ||
expect(getfileinfo(path).canRead).toBe(true); | ||
expect(getfileinfo(path).canWrite).toBe(true); | ||
}); | ||
}); | ||
} | ||
|
||
function afterAll(){ | ||
if(directoryExists(base&"LDEV2410")){ | ||
directoryDelete(base&"LDEV2410",true); | ||
if ( FileExists( variables.testfile ) ) { | ||
FileDelete( variables.testfile ); | ||
} | ||
} | ||
|
||
private function isWindows(){ | ||
return (server.os.name contains "windows"); | ||
} | ||
|
||
} |