Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
micstriit committed Dec 15, 2010
1 parent 489ae82 commit 58413ab
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 16 deletions.
3 changes: 1 addition & 2 deletions railo-java/railo-core/src/railo/commons/io/CompressUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ private static void extractTar(Resource tarFile, Resource targetDir) throws IOEx
else {
Resource parent=target.getParentResource();
if(!parent.exists())parent.mkdirs();

IOUtil.copy(tis,target,false);
}
target.setLastModified(entry.getModTime().getTime());
Expand Down Expand Up @@ -223,7 +222,7 @@ private static void extractZipOld(Resource zipFile, Resource targetDir) throws I
}

private static void extractZip(Resource zipFile, Resource targetDir) throws IOException {
if(!targetDir.exists() || !targetDir.isDirectory())
if(!targetDir.exists() || !targetDir.isDirectory())
throw new IOException(targetDir+" is not a existing directory");

if(!zipFile.exists())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,17 @@

import org.apache.commons.compress.archivers.tar.TarOutputStream;

import railo.commons.digest.MD5;
import railo.commons.io.CompressUtil;
import railo.commons.io.IOUtil;
import railo.commons.io.SystemUtil;
import railo.commons.io.res.Resource;
import railo.commons.io.res.ResourceProvider;
import railo.commons.io.res.type.ram.RamResourceProviderOld;
import railo.commons.io.res.util.ResourceUtil;
import railo.runtime.config.Config;
import railo.runtime.engine.ThreadLocalPageContext;
import railo.runtime.functions.other.CreateUUID;
import railo.runtime.op.Caster;

public final class Compress {
Expand All @@ -29,7 +34,7 @@ public final class Compress {
private final static Map files=new WeakHashMap();

private final Resource ffile;
private ResourceProvider ramProvider;
//private ResourceProvider ramProvider;
private long syn=-1;
private Resource root;
private Synchronizer synchronizer;
Expand All @@ -39,6 +44,7 @@ public final class Compress {
private int format;
private int mode;
private boolean caseSensitive;
private Resource temp;

/**
* private Constructor of the class, will be invoked be getInstance
Expand Down Expand Up @@ -76,12 +82,50 @@ private void load(boolean caseSensitive) {
lastCheck=System.currentTimeMillis();
Map args = new HashMap();
args.put("case-sensitive", Caster.toBoolean(caseSensitive));
ramProvider = new RamResourceProviderOld().init("ram",args);
root=ramProvider.getResource("/");
try {
//ramProvider = new RamResourceProviderOld().init("ram",args);
//root=ramProvider.getResource("/");

if(temp==null){
String cid="";
try {
Config config = ThreadLocalPageContext.getConfig();
if(config!=null){
cid=config.getId();
temp = config.getTempDirectory();
}
if(temp==null)temp=SystemUtil.getTempDirectory();

temp=temp.getRealResource("compress");
temp=temp.getRealResource(MD5.getDigestAsString(cid+"-"+ffile.getAbsolutePath()));
if(!temp.exists())temp.createDirectory(true);

}
catch(Throwable t){}
}

if(temp!=null) {
ResourceUtil.removeChildrenEL(temp);
/*String name;
try {
name=MD5Checksum.getMD5Checksum(ffile);
}
catch (Exception e) {
name=CreateUUID.invoke();
}*/
String name=CreateUUID.invoke();
root=temp.getRealResource(name);
root.mkdirs();
}
else {
ResourceProvider ramProvider = new RamResourceProviderOld().init("ram",args);
root=ramProvider.getResource("/");
}


/*try {
root.setMode(mode);
}
catch (IOException e) {}
catch (IOException e) {}*/
_load();
}

Expand All @@ -102,7 +146,7 @@ private void _load() {
}
}

public ResourceProvider getRamProvider() {
public Resource getRamProviderResource(String path) {
long t=System.currentTimeMillis();
if(t>lastCheck+2000){

Expand All @@ -113,7 +157,7 @@ public ResourceProvider getRamProvider() {
load(caseSensitive);
}
}
return ramProvider;
return root.getRealResource(path);//ramProvider.getResource(path);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public final class CompressResource extends ResourceSupport {
* @return return ram resource that contain the data
*/
private Resource getRamResource() {
return zip.getRamProvider().getResource(path);
return zip.getRamProviderResource(path);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ public boolean setLastModified(long time) {
provider.lock(this);
return super.setLastModified(time);
}
catch (IOException e) {
catch (Throwable t) {// IllegalArgumentException or IOException
return false;
}
finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ public static void load(ConfigServerImpl configServer, ConfigImpl config, Docume


loadConstants(configServer,config,doc);

loadTempDirectory(configServer, config, doc);
loadId(config);
loadVersion(config,doc);
loadSecurity(configServer,config,doc);
Expand Down Expand Up @@ -2291,6 +2291,34 @@ private static void loadTag(ConfigServerImpl configServer, ConfigImpl config, Do

}



private static void loadTempDirectory(ConfigServerImpl configServer, ConfigImpl config, Document doc) throws ExpressionException, TagLibException, FunctionLibException {
Resource configDir=config.getConfigDir();
boolean hasCS=configServer!=null;


Element fileSystem= getChildByName(doc.getDocumentElement(),"file-system");
if(fileSystem==null)fileSystem= getChildByName(doc.getDocumentElement(),"filesystem");

String strTempDirectory=null;
if(fileSystem!=null) strTempDirectory=ConfigWebUtil.translateOldPath(fileSystem.getAttribute("temp-directory"));

// Temp Dir
if(!StringUtil.isEmpty(strTempDirectory)) {
config.setTempDirectory(ConfigWebUtil.getFile(configDir,strTempDirectory,
null, // create no default
configDir,FileUtil.TYPE_DIR,config));
}
else if(hasCS) {
config.setTempDirectory(configServer.getTempDirectory());
}
if(config.getTempDirectory()==null) {
config.setTempDirectory(ConfigWebUtil.getFile(configDir,"temp",
null, // create no default
configDir,FileUtil.TYPE_DIR,config));
}
}

/**
* @param configServer
Expand Down Expand Up @@ -2320,7 +2348,7 @@ private static void loadFilesystem(ConfigServerImpl configServer, ConfigImpl con

String strAllowRealPath=null;
String strDeployDirectory=null;
String strTempDirectory=null;
//String strTempDirectory=null;
String strTLDDirectory=null;
String strFLDDirectory=null;
String strTagDirectory=null;
Expand All @@ -2329,7 +2357,7 @@ private static void loadFilesystem(ConfigServerImpl configServer, ConfigImpl con
if(fileSystem!=null) {
strAllowRealPath=ConfigWebUtil.translateOldPath(fileSystem.getAttribute("allow-realpath"));
strDeployDirectory=ConfigWebUtil.translateOldPath(fileSystem.getAttribute("deploy-directory"));
strTempDirectory=ConfigWebUtil.translateOldPath(fileSystem.getAttribute("temp-directory"));
//strTempDirectory=ConfigWebUtil.translateOldPath(fileSystem.getAttribute("temp-directory"));
strTLDDirectory=ConfigWebUtil.translateOldPath(fileSystem.getAttribute("tld-directory"));
strFLDDirectory=ConfigWebUtil.translateOldPath(fileSystem.getAttribute("fld-directory"));
strTagDirectory=ConfigWebUtil.translateOldPath(fileSystem.getAttribute("tag-directory"));
Expand All @@ -2348,7 +2376,7 @@ private static void loadFilesystem(ConfigServerImpl configServer, ConfigImpl con
//}

// Temp Dir
if(!StringUtil.isEmpty(strTempDirectory)) {
/*if(!StringUtil.isEmpty(strTempDirectory)) {
config.setTempDirectory(ConfigWebUtil.getFile(configDir,strTempDirectory,
null, // create no default
configDir,FileUtil.TYPE_DIR,config));
Expand All @@ -2360,7 +2388,7 @@ else if(hasCS) {
config.setTempDirectory(ConfigWebUtil.getFile(configDir,"temp",
null, // create no default
configDir,FileUtil.TYPE_DIR,config));
}
}*/

// TLD Dir
//if(hasCS) {
Expand Down

0 comments on commit 58413ab

Please sign in to comment.