Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LDEV-5312 add function FileModeToSymbolic #2506

Open
wants to merge 1 commit into
base: 6.2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
*
* Copyright (c) 2014, the Railo Company Ltd. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
**/
package lucee.runtime.functions.file;

import java.io.IOException;

import lucee.commons.io.ModeUtil;
import lucee.runtime.PageContext;
import lucee.runtime.exp.PageException;
import lucee.runtime.op.Caster;

public class FileModeToSymbolic {

public static String call(PageContext pc, String strMode) throws PageException {
try {
return ModeUtil.fromOctalMode(ModeUtil.toOctalMode(strMode));
}
catch (IOException e) {
throw Caster.toPageException(e);
}
}
}
35 changes: 35 additions & 0 deletions core/src/main/java/resource/fld/core-base.fld
Original file line number Diff line number Diff line change
Expand Up @@ -5460,6 +5460,41 @@ For example, 400 specifies that only the owner can read the file; 004 specifies
<type>void</type>
</return>
</function>

<!-- FileModeToSymbolic -->
<function>
<name>FileModeToSymbolic</name>
<class>lucee.runtime.functions.file.FileModeToSymbolic</class>
<description>Converts a mode mask to it's symbolic representation.</description>
<argument>
<name>mode</name>
<type>string</type>
<required>Yes</required>
<description>
A three-digit value, in which each digit specifies the file access for individuals and groups:
- The first digit represents the owner.
- The second digit represents a group.
- The third digit represents anyone.

Each digit of this code sets permissions for the appropriate individual or group:
- 4 specifies read permission.
- 2 specifies write permission.
- 1 specifies execute permission.

You use the sums of these numbers to indicate combinations of the permissions:
- 3 specifies write and execute permission.
- 5 specifies read and execute permission.
- 6 indicates read and write permission.
- 7 indicates read, write, and execute permission.

For example, 400 specifies that only the owner can read the file; 004 specifies that anyone can read the file.
</description>
</argument>
<return>
<type>string</type>
</return>
</function>

<!-- FileSetAttribute -->
<function>
<name>FileSetAttribute</name>
Expand Down
20 changes: 20 additions & 0 deletions test/functions/FileModeToSymbolic.cfc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
component extends="org.lucee.cfml.test.LuceeTestCase" {

function run( testResults, testBox ){
describe( "tests for FileModeToSymbolic", function(){
it( title="test converting masks to symbolic", body=function(){
var stringModes = {
644: "rw-r--r--",
755: "rwxr-xr-x",
777: "rwxrwxrwx",
400: "r--------"
};
for (var mode in stringModes ){
//systemOutput( "mode: #mode# " & FileModeToSymbolic(mode), true );
expect( FileModeToSymbolic( mode ) ).toBe( stringModes[ mode ] );
}
});
} );
}

}
Loading