IDEMPIERE-2397 packout should clear folder before run process.
This commit is contained in:
parent
ef107c0337
commit
dd4e1eba3a
|
@ -230,7 +230,7 @@ public class MAttachmentEntry
|
|||
{
|
||||
if (fileName == null || fileName.length() == 0)
|
||||
fileName = getName();
|
||||
return getFile (new File(fileName));
|
||||
return getFile (new File(System.getProperty("java.io.tmpdir") + File.separator + fileName));
|
||||
} // getFile
|
||||
|
||||
/**
|
||||
|
|
|
@ -19,6 +19,7 @@ package org.compiere.tools;
|
|||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.FilenameFilter;
|
||||
|
@ -427,4 +428,16 @@ public class FileUtil
|
|||
return localFile;
|
||||
}
|
||||
|
||||
public static boolean deleteFolderRecursive(File path) throws FileNotFoundException {
|
||||
if (!path.exists())
|
||||
throw new FileNotFoundException(path.getAbsolutePath());
|
||||
boolean ret = true;
|
||||
if (path.isDirectory()) {
|
||||
for (File f : path.listFiles()){
|
||||
ret = ret && deleteFolderRecursive(f);
|
||||
}
|
||||
}
|
||||
return ret && path.delete();
|
||||
}
|
||||
|
||||
} // FileUtil
|
||||
|
|
|
@ -235,7 +235,7 @@ public class PackIn {
|
|||
ArrayList<File> files = new ArrayList<File>();
|
||||
while (e.hasMoreElements()) {
|
||||
ZipEntry ze = (ZipEntry) e.nextElement();
|
||||
File file = new File(ze.getName());
|
||||
File file = new File(m_packageDirectory + File.separator + ze.getName());
|
||||
FileOutputStream fout = new FileOutputStream(file);
|
||||
InputStream in = zf.getInputStream(ze);
|
||||
for (int c = in.read(); c != -1; c = in.read()) {
|
||||
|
|
|
@ -21,13 +21,15 @@ import java.io.File;
|
|||
import java.sql.Timestamp;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.compiere.Adempiere;
|
||||
import org.compiere.model.MAttachment;
|
||||
import org.compiere.model.MAttachmentEntry;
|
||||
import org.compiere.model.X_AD_Package_Imp_Proc;
|
||||
import org.compiere.process.ProcessInfoParameter;
|
||||
import org.compiere.process.SvrProcess;
|
||||
import org.compiere.tools.FileUtil;
|
||||
import org.compiere.util.AdempiereSystemError;
|
||||
import org.compiere.util.CLogger;
|
||||
import org.compiere.util.Env;
|
||||
|
||||
/**
|
||||
* IntPackIn Tool.
|
||||
|
@ -79,12 +81,17 @@ public class PackInProcess extends SvrProcess {
|
|||
// Create Target directory if required
|
||||
String packageDirectory = adPackageImp.getAD_Package_Dir();
|
||||
if (packageDirectory == null || packageDirectory.trim().length() == 0) {
|
||||
packageDirectory = Adempiere.getAdempiereHome();
|
||||
packageDirectory = System.getProperty("java.io.tmpdir");
|
||||
}
|
||||
|
||||
String targetDirName = packageDirectory + File.separator + "packin";
|
||||
String targetDirName = packageDirectory + File.separator + "packin" + Env.getContext(getCtx(), "#AD_User_ID");
|
||||
File targetDir = new File(targetDirName);
|
||||
|
||||
if (targetDir.exists()) {
|
||||
if (!FileUtil.deleteFolderRecursive(targetDir)) {
|
||||
throw new AdempiereSystemError("Could not delete folder " + targetDirName + ", please check permissions");
|
||||
}
|
||||
}
|
||||
if (!targetDir.exists()) {
|
||||
boolean success = targetDir.mkdirs();
|
||||
if (!success) {
|
||||
|
@ -109,7 +116,7 @@ public class PackInProcess extends SvrProcess {
|
|||
Zipper.unpackFile(zipFilepath, targetDir);
|
||||
|
||||
String dict_file = packageDirectory + File.separator
|
||||
+ "packin" + File.separator + parentDir + File.separator
|
||||
+ "packin" + Env.getContext(getCtx(), "#AD_User_ID") + File.separator + parentDir + File.separator
|
||||
+ "dict" + File.separator + "PackOut.xml";
|
||||
|
||||
if (log.isLoggable(Level.INFO)) log.info("dict file->" + dict_file);
|
||||
|
@ -120,7 +127,7 @@ public class PackInProcess extends SvrProcess {
|
|||
m_UpdateDictionary = false;
|
||||
|
||||
m_packageDirectory = packageDirectory + File.separator
|
||||
+ "packin" + File.separator + parentDir + File.separator;
|
||||
+ "packin" + Env.getContext(getCtx(), "#AD_User_ID") + File.separator + parentDir + File.separator;
|
||||
|
||||
PackIn packIn = new PackIn();
|
||||
packIn.setPackageDirectory(m_packageDirectory);
|
||||
|
|
|
@ -43,11 +43,11 @@ import javax.xml.transform.stream.StreamResult;
|
|||
import org.compiere.model.MClient;
|
||||
import org.compiere.model.MSysConfig;
|
||||
import org.compiere.model.MTable;
|
||||
import org.compiere.tools.FileUtil;
|
||||
import org.compiere.util.CLogger;
|
||||
import org.compiere.util.Trx;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.helpers.AttributesImpl;
|
||||
|
||||
import org.adempiere.exceptions.AdempiereException;
|
||||
|
||||
/**
|
||||
|
@ -188,6 +188,7 @@ public class PackOut
|
|||
String includesdir = packoutDocument.getPackageName() + File.separator +"**";
|
||||
Zipper.zipFolder(srcFolder, destZipFile, includesdir);
|
||||
exportFile = destZipFile.getAbsolutePath();
|
||||
FileUtil.deleteFolderRecursive(new File(packageDirectory));
|
||||
} // doIt
|
||||
|
||||
private TransformerHandler createPackoutHandler(
|
||||
|
|
|
@ -26,7 +26,6 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.compiere.Adempiere;
|
||||
import org.compiere.model.I_AD_EntityType;
|
||||
import org.compiere.model.I_AD_Form;
|
||||
import org.compiere.model.I_AD_ImpFormat;
|
||||
|
@ -48,6 +47,7 @@ import org.compiere.model.MTable;
|
|||
import org.compiere.model.Query;
|
||||
import org.compiere.model.X_AD_Package_Exp_Detail;
|
||||
import org.compiere.process.SvrProcess;
|
||||
import org.compiere.util.Env;
|
||||
|
||||
/**
|
||||
* Convert AD to XML
|
||||
|
@ -99,10 +99,10 @@ public class PackOutProcess extends SvrProcess
|
|||
|
||||
if (packageExp.getAD_Package_Exp_ID() == p_PackOut_ID){
|
||||
//Create the package documentation
|
||||
packoutDirectory = Adempiere.getAdempiereHome().trim();
|
||||
packoutDirectory = System.getProperty("java.io.tmpdir");
|
||||
if (!packoutDirectory.endsWith("/") && !packoutDirectory.endsWith("\\"))
|
||||
packoutDirectory+= File.separator;
|
||||
packoutDirectory = packoutDirectory + "packout" + File.separator;
|
||||
packoutDirectory = packoutDirectory + "packout" + Env.getContext(getCtx(), "#AD_User_ID") + File.separator;
|
||||
|
||||
//create packout folder if needed
|
||||
File packoutDirectoryFile = new File(packoutDirectory);
|
||||
|
|
Loading…
Reference in New Issue