Skip to content

Commit

Permalink
allow to define a target path as a string and add a test case for it
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeloffner committed Nov 1, 2023
1 parent 809857d commit 0f15aa3
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 9 deletions.
4 changes: 2 additions & 2 deletions build.number
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#Build Number for ANT. Do not edit!
#Tue Oct 31 20:27:20 CET 2023
build.number=5
#Wed Nov 01 18:24:40 CET 2023
build.number=6
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,18 @@ public static Object toResource(PageContext pc, Object value) {
public static Resource toResource(PageContext pc, Object value, boolean needToExist, Resource defaultValue) {
if (value instanceof CharSequence) {
String str = value.toString();
if (str.length() <= 10240 && needToExist) {
try {
return CFMLEngineFactory.getInstance().getResourceUtil().toResourceExisting(pc, str);
}
catch (Exception e) {
if (needToExist) {
if (str.length() <= 10240) {

try {
return CFMLEngineFactory.getInstance().getResourceUtil().toResourceExisting(pc, str);
}
catch (Exception e) {
}

}
}
else return CFMLEngineFactory.getInstance().getCastUtil().toResource(str, defaultValue);
}
else if (value instanceof Resource) return (Resource) value;
else if (value instanceof File) return CFMLEngineFactory.getInstance().getCastUtil().toResource(value, defaultValue);
Expand Down
20 changes: 18 additions & 2 deletions tests/functions/S3Download.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ Sorglos";
assertEquals(len(data),12);
assertEquals(data, content);
});

it(title="download to file", body = function( currentSpec ) {

//////// FILE ///////////
it(title="download to file (fileOpen)", body = function( currentSpec ) {
var target=getDirectoryFromPath(getCurrentTemplatePath())&"temp.txt";
try {
s3Download(bucket:bucketName,object:objectName,target:fileOpen(target,"write"),accessKeyId:cred.ACCESS_KEY_ID,secretAccessKey:cred.SECRET_KEY);
Expand All @@ -44,6 +45,21 @@ Sorglos";
}
});


it(title="download to file (string path)", body = function( currentSpec ) {
var target=getDirectoryFromPath(getCurrentTemplatePath())&"temp.txt";
try {
s3Download(bucket:bucketName,object:objectName,target:target,accessKeyId:cred.ACCESS_KEY_ID,secretAccessKey:cred.SECRET_KEY);
var data=fileRead(target);
assertTrue(isSimpleValue(data));
assertEquals(len(data),12);
assertEquals(data, content);
}
finally {
if(fileExists(target)) fileDelete(target);
}
});

//////// UDF ///////////
it(title="download to UDF:line", body = function( currentSpec ) {
var data="";
Expand Down

0 comments on commit 0f15aa3

Please sign in to comment.