Skip to content

Commit

Permalink
LDEV-5034 - extract permission part from mode and only use that
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeloffner committed Aug 13, 2024
1 parent 60897bc commit cc16117
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 4 deletions.
20 changes: 20 additions & 0 deletions core/src/main/java/lucee/commons/io/ModeUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@

import java.io.IOException;

import lucee.commons.io.log.Log;
import lucee.commons.io.log.LogUtil;

public final class ModeUtil {

public static final int PERM_READ = 04;
Expand Down Expand Up @@ -66,6 +69,23 @@ private static int _toOctalMode(String strMode) {
return mode;
}

/**
* Extracts the permission bits from the mode value. Logs a message if the file type bits are
* removed and logging is enabled.
*
* @param mode The mode value that includes file type and permission bits.
* @param log If true, log a message if file type bits are removed.
* @return The permission bits (e.g., 0700).
*/
public static int extractPermissions(int mode, boolean log) {
int permissionBits = mode & 07777;

if (log && (mode != permissionBits)) {
LogUtil.log(Log.LEVEL_WARN, "mode", "File type bits removed from mode: original=" + toStringMode(mode) + ", extracted=" + toStringMode(permissionBits));
}
return permissionBits;
}

/**
* translate an octal mode value (73) to a string representation ("111")
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.apache.commons.compress.compressors.bzip2.BZip2CompressorOutputStream;

import lucee.commons.io.IOUtil;
import lucee.commons.io.ModeUtil;
import lucee.commons.io.SystemUtil;
import lucee.commons.io.res.Resource;
import lucee.commons.io.res.ResourceProvider;
Expand Down Expand Up @@ -221,7 +222,9 @@ private static void extractTar(Resource tarFile, Resource targetDir) throws IOEx
}
target.setLastModified(entry.getModTime().getTime());
mode = entry.getMode();
if (mode > 0) target.setMode(mode);
if (mode > 0) {
target.setMode(ModeUtil.extractPermissions(mode, false));
}
// tis.closeEntry() ;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -439,8 +439,9 @@ public static int getMode(Path path) {

@Override
public void setMode(int mode) throws IOException {
// TODO unter windows mit setReadable usw.
// TODO for windows do it with help of NIO functions
if (!SystemUtil.isUnix()) return;
mode = ModeUtil.extractPermissions(mode, true); // we only need the permission part
provider.lock(this);
try {
// print.ln(ModeUtil.toStringMode(mode));
Expand Down
2 changes: 1 addition & 1 deletion loader/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<project default="core" basedir="." name="Lucee"
xmlns:resolver="antlib:org.apache.maven.resolver.ant">

<property name="version" value="6.1.1.58-SNAPSHOT"/>
<property name="version" value="6.1.1.59-SNAPSHOT"/>

<taskdef uri="antlib:org.apache.maven.resolver.ant" resource="org/apache/maven/resolver/ant/antlib.xml">
<classpath>
Expand Down
2 changes: 1 addition & 1 deletion loader/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<groupId>org.lucee</groupId>
<artifactId>lucee</artifactId>
<version>6.1.1.58-SNAPSHOT</version>
<version>6.1.1.59-SNAPSHOT</version>
<packaging>jar</packaging>

<name>Lucee Loader Build</name>
Expand Down

0 comments on commit cc16117

Please sign in to comment.