Skip to content

Commit

Permalink
Merge branch '6.2' of https://github.com/lucee/Lucee into 6.2
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeloffner committed Jan 6, 2025
2 parents 4eb3ddf + 778314d commit a93a4eb
Show file tree
Hide file tree
Showing 57 changed files with 1,217 additions and 546 deletions.
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ jobs:
sudo -u postgres psql -c 'create database lucee;'
sudo -u postgres psql -c "create user lucee with encrypted password 'lucee'";
sudo -u postgres psql -c 'grant all privileges on database lucee to lucee;'
sudo -u postgres psql -c 'grant all on schema public to lucee;' -d lucee
- name: Start MongoDB (docker)
uses: supercharge/mongodb-github-action@1.6.0
with:
Expand Down
10 changes: 9 additions & 1 deletion core/src/main/cfml/context/admin/ext.applications.list.cfm
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,15 @@ Latest version: #latest.v#</cfif>"><cfif hasUpdates>
// OSGi compatible version
if(arr.len()==4 && isNumeric(arr[1]) && isNumeric(arr[2]) && isNumeric(arr[3])) {
try{ return toOSGiVersion(version).sortable; }catch(local.e){};
try{
osgiVersion = variables.toOSGiVersion(version);
if (structCount(osgiVersion)) {
return variables.toOSGiVersion(version).sortable;
}
}
catch(local.e){
//systemOutput(version & " " & e.message, true);
};
}
rtn="";
Expand Down
19 changes: 13 additions & 6 deletions core/src/main/cfml/context/admin/ext.functions.cfm
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,15 @@
// OSGi compatible version
if(arr.len()==4 && isNumeric(arr[1]) && isNumeric(arr[2]) && isNumeric(arr[3])) {
try{return variables.toOSGiVersion(version).sortable}catch(local.e){};
try{
osgiVersion = variables.toOSGiVersion(version);
if (structCount(osgiVersion)) {
return variables.toOSGiVersion(version).sortable;
}
}
catch(local.e){
//systemOutput(version & " " & e.message, true);
};
}
Expand All @@ -666,7 +674,8 @@
if(arr.len()!=4 || !isNumeric(arr[1]) || !isNumeric(arr[2]) || !isNumeric(arr[3])) {
if(ignoreInvalidVersion) return {};
throw "version number ["&arguments.version&"] is invalid";
return {};
//throw "version number ["&arguments.version&"] is invalid";
}
local.sct={major:arr[1]+0,minor:arr[2]+0,micro:arr[3]+0,qualifier_appendix:"",qualifier_appendix_nbr:100};
Expand All @@ -686,7 +695,7 @@
if(sct.qualifier_appendix1 =="ALPHA" || sct.qualifier_appendix2 == 'SNAPSHOT' )sct.qualifier_appendix_nbr=25;
else sct.qualifier_appendix_nbr=75; // every other appendix is better than SNAPSHOT
}
else throw "version number ["&arguments.version&"] is invalid";
else return {}; // throw "version number ["&arguments.version&"] is invalid";
sct.pure=
sct.major
&"."&sct.minor
Expand All @@ -695,14 +704,12 @@
sct.display=
sct.pure
&(sct.qualifier_appendix==""?"":"-"&sct.qualifier_appendix);
sct.sortable=repeatString("0",2-len(sct.major))&sct.major
&"."&repeatString("0",3-len(sct.minor))&sct.minor
&"."&repeatString("0",3-len(sct.micro))&sct.micro
&"."&repeatString("0",4-len(sct.micro))&sct.micro
&"."&repeatString("0",4-len(sct.qualifier))&sct.qualifier
& #sct.keyExists("qualifier_appendix1") && isNumeric(sct.qualifier_appendix1)? "."&repeatString("0",4-len(sct.qualifier_appendix1))&sct.qualifier_appendix1 : ""#
&"."&repeatString("0",3-len(sct.qualifier_appendix_nbr))&sct.qualifier_appendix_nbr;
return sct;
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/cfml/context/admin/info.bundle.list.cfm
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
<td>
<input type="hidden" name="virtual_#bundles.currentrow#" value="#bundles.title#">
#bundles.title#<cfif bundles.symbolicName != bundles.title> (#bundles.symbolicName#)</cfif>
<cfif len(bundles.description)><br><span class="comment">#bundles.description.trim()#</span></cfif>
<cfif len(bundles.description)><br><span class="comment">#trim(bundles.description)#</span></cfif>
</td>

<!--- version --->
Expand Down
59 changes: 53 additions & 6 deletions core/src/main/java/lucee/commons/i18n/FormatterWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class FormatterWrapper {
private final boolean hasComma;
private final boolean hasSlash;
private final boolean hasColon;
private final boolean hasSpace;
private final boolean hasWhitespace;
private final boolean hasHyphen;

FormatterWrapper(DateTimeFormatter formatter, String pattern, short type, ZoneId zone) {
Expand All @@ -29,7 +29,7 @@ public class FormatterWrapper {
this.hasSlash = pattern.indexOf('/') != -1;
this.hasHyphen = pattern.indexOf('-') != -1;
this.hasColon = pattern.indexOf(':') != -1;
this.hasSpace = pattern.indexOf(' ') != -1;
this.hasWhitespace = pattern.chars().anyMatch(Character::isWhitespace);
}

FormatterWrapper(DateTimeFormatter formatter, String pattern, short type, ZoneId zone, boolean custom) {
Expand All @@ -44,7 +44,7 @@ public class FormatterWrapper {
this.hasSlash = pattern.indexOf('/') != -1;
this.hasHyphen = pattern.indexOf('-') != -1;
this.hasColon = pattern.indexOf(':') != -1;
this.hasSpace = pattern.indexOf(' ') != -1;
this.hasWhitespace = pattern.chars().anyMatch(Character::isWhitespace);
}

public boolean valid(String str) {
Expand Down Expand Up @@ -78,13 +78,60 @@ public boolean valid(String str) {
if (str.indexOf(':') != -1) return false;
}

if (hasSpace) {
if (str.indexOf(' ') == -1) return false;
if (hasWhitespace) {
if (!str.chars().anyMatch(Character::isWhitespace)) return false;
}
else {
if (str.indexOf(' ') != -1) return false;
if (str.chars().anyMatch(Character::isWhitespace)) return false;
}
return true;
}

public boolean validx(String str) {
if (pattern.length() > str.length()) return false;

boolean foundComma = false;
boolean foundHyphen = false;
boolean foundSlash = false;
boolean foundColon = false;
boolean foundWhitespace = false;

// Single pass through the string
for (int i = 0; i < str.length(); i++) {
char c = str.charAt(i);
switch (c) {
case ',':
if (!hasComma) return false;
foundComma = true;
break;
case '-':
if (!hasHyphen) return false;
foundHyphen = true;
break;
case '/':
if (!hasSlash) return false;
foundSlash = true;
break;
case ':':
if (!hasColon) return false;
foundColon = true;
break;
default:
if (Character.isWhitespace(c)) {
if (!hasWhitespace) return false;
foundWhitespace = true;
}
}
}

// Only check for required characters we haven't found
if (hasComma && !foundComma) return false;
if (hasHyphen && !foundHyphen) return false;
if (hasSlash && !foundSlash) return false;
if (hasColon && !foundColon) return false;
if (hasWhitespace && !foundWhitespace) return false;

return true;
}

}
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 @@ -69,6 +69,26 @@ private static int _toOctalMode(String strMode) {
return mode;
}

public static String fromOctalMode(int mode) throws IOException {
String octalString = String.format("%03o", mode);
if (octalString.length() <= 4 && octalString.length() > 3)
throw new IOException("can't translate [" + mode + "] to a permissions string");
String permString = "";
for (char c : octalString.toCharArray()) {
switch (c) {
case '0': permString += "---"; break;
case '1': permString += "--x"; break;
case '2': permString += "-w-"; break;
case '3': permString += "-wx"; break;
case '4': permString += "r--"; break;
case '5': permString += "r-x"; break;
case '6': permString += "rw-"; break;
case '7': permString += "rwx"; break;
}
}
return permString;
}

/**
* Extracts the permission bits from the mode value. Logs a message if the file type bits are
* removed and logging is enabled.
Expand Down
44 changes: 26 additions & 18 deletions core/src/main/java/lucee/commons/io/compress/CompressUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,12 @@ private static void extractTar(Resource tarFile, Resource targetDir) throws IOEx
return;
}

// read the zip file and build a query from its contents
// read the tar file and extract its contents
TarArchiveInputStream tis = null;
try {
tis = new TarArchiveInputStream(IOUtil.toBufferedInputStream(tarFile.getInputStream()));
TarArchiveEntry entry;
int mode;
while ((entry = tis.getNextTarEntry()) != null) {
// print.ln(entry);
Resource target = targetDir.getRealResource(entry.getName());
Expand All @@ -220,6 +221,10 @@ private static void extractTar(Resource tarFile, Resource targetDir) throws IOEx
IOUtil.copy(tis, target, false);
}
target.setLastModified(entry.getModTime().getTime());
mode = entry.getMode();
if (mode > 0) {
target.setMode(ModeUtil.extractPermissions(mode, false));
}
}
}
finally {
Expand Down Expand Up @@ -544,29 +549,32 @@ public static void compressTar(String parent, Resource[] sources, TarArchiveOutp
}

private static void compressTar(String parent, Resource source, TarArchiveOutputStream tos, int mode) throws IOException {
if (source.isFile()) {
// TarEntry entry = (source instanceof FileResource)?new TarEntry((FileResource)source):new
// TarEntry(parent);
TarArchiveEntry entry = new TarArchiveEntry(parent);
String _parent = parent;
if (!source.isFile() && parent.charAt(parent.length() - 1) != '/')
_parent += "/"; // indicates this is a directory

entry.setName(parent);
TarArchiveEntry entry = new TarArchiveEntry(_parent);

// mode
if (mode > 0) entry.setMode(ModeUtil.extractPermissions(mode, false));
else if ((mode = source.getMode()) > 0) entry.setMode(ModeUtil.extractPermissions(mode, false));
entry.setName(parent);
// mode
if (mode > 0) entry.setMode(ModeUtil.extractPermissions(mode, false));
else if (source.getMode() > 0) entry.setMode(ModeUtil.extractPermissions(source.getMode(), false));

if (source.isFile())
entry.setSize(source.length());
entry.setModTime(source.lastModified());
tos.putArchiveEntry(entry);
try {
entry.setModTime(source.lastModified());
tos.putArchiveEntry(entry);
try {
if (source.isFile())
IOUtil.copy(source, tos, false);
}
finally {
tos.closeArchiveEntry();
}
}
else if (source.isDirectory()) {
compressTar(parent, source.listResources(), tos, mode);
finally {
tos.closeArchiveEntry();
}

if (source.isDirectory()) {
Resource[] sources = source.listResources();
compressTar(parent, sources, tos, mode);
}
}

Expand Down
37 changes: 15 additions & 22 deletions core/src/main/java/lucee/commons/io/res/type/file/FileResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,16 @@
import java.nio.file.Files;
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.nio.file.StandardOpenOption;
import java.nio.file.attribute.DosFileAttributes;
import java.nio.file.attribute.PosixFileAttributes;
import java.nio.file.attribute.PosixFilePermission;
import java.nio.file.attribute.PosixFilePermissions;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import lucee.commons.cli.Command;
import lucee.commons.io.IOUtil;
Expand Down Expand Up @@ -429,14 +434,9 @@ public int getMode() {
if (!exists()) return 0;
if (SystemUtil.isUnix()) {
try {
// TODO geht nur fuer file
String line = Command.execute("ls -ld " + getPath(), false).getOutput();

line = line.trim();
line = line.substring(0, line.indexOf(' '));
// print.ln(getPath());
return ModeUtil.toOctalMode(line);

PosixFileAttributes attrs = Files.readAttributes(Paths.get(getPath()), PosixFileAttributes.class);
Set<PosixFilePermission> permissions = attrs.permissions();
return ModeUtil.toOctalMode(PosixFilePermissions.toString(permissions));
}
catch (Exception e) {
LogUtil.warn("file-resource-provider", e);
Expand All @@ -453,14 +453,9 @@ public static int getMode(Path path) {
if (!Files.exists(path)) return 0;
if (SystemUtil.isUnix()) {
try {
// TODO geht nur fuer file
String line = Command.execute("ls -ld " + path.toAbsolutePath().toString(), false).getOutput();

line = line.trim();
line = line.substring(0, line.indexOf(' '));
// print.ln(getPath());
return ModeUtil.toOctalMode(line);

PosixFileAttributes attrs = Files.readAttributes( path, PosixFileAttributes.class);
Set<PosixFilePermission> permissions = attrs.permissions();
return ModeUtil.toOctalMode(PosixFilePermissions.toString(permissions));
}
catch (Exception e) {
LogUtil.warn("file-resource-provider", e);
Expand All @@ -478,14 +473,12 @@ public void setMode(int mode) throws IOException {
// 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 {
provider.lock(this);
// print.ln(ModeUtil.toStringMode(mode));
if (Runtime.getRuntime().exec(new String[] { "chmod", ModeUtil.toStringMode(mode), getPath() }).waitFor() != 0)
throw new IOException("chmod [" + ModeUtil.toStringMode(mode) + "] [" + toString() + "] failed");
}
catch (InterruptedException e) {
throw new IOException("Interrupted waiting for chmod [" + toString() + "]");
Files.setPosixFilePermissions(Paths.get(getPath()), PosixFilePermissions.fromString(ModeUtil.fromOctalMode(mode)));
} catch (IOException e) {
throw new IOException("Interrupted setPosixFilePermissions [" + toString() + "]");
}
finally {
provider.unlock(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,18 +94,20 @@ public byte[] getContentAsByteArray() throws IOException {
}

public Array getLocations() {
try {
List<URI> locations = ((HttpClientContext) context).getRedirectLocations();
if (locations != null) {
Array arr = new ArrayImpl();
for (URI loc: locations) {
arr.appendEL(loc.toString());
if (context instanceof HttpClientContext){ // on error it's BasicHttpContext
try {
List<URI> locations = ((HttpClientContext) context).getRedirectLocations();
if (locations != null) {
Array arr = new ArrayImpl();
for (URI loc: locations) {
arr.appendEL(loc.toString());
}
return arr;
}
return arr;
}
}
catch (Exception e) {
LogUtil.warn("http-response", e);
catch (Exception e) {
LogUtil.warn("http-response", e);
}
}
return null;
}
Expand Down
Loading

0 comments on commit a93a4eb

Please sign in to comment.