From: <lin...@us...> - 2008-12-13 20:21:28
|
Revision: 2185 http://daisymfc.svn.sourceforge.net/daisymfc/?rev=2185&view=rev Author: linusericson Date: 2008-12-13 20:21:25 +0000 (Sat, 13 Dec 2008) Log Message: ----------- perform operation in a temp dir if input and/or output directory contains non-western unicode characters Modified Paths: -------------- trunk/dmfc/transformers/int_daisy_mathAltCreator/com/dessci/mathflow/MathFlowAltCreator.java Modified: trunk/dmfc/transformers/int_daisy_mathAltCreator/com/dessci/mathflow/MathFlowAltCreator.java =================================================================== --- trunk/dmfc/transformers/int_daisy_mathAltCreator/com/dessci/mathflow/MathFlowAltCreator.java 2008-12-13 20:19:04 UTC (rev 2184) +++ trunk/dmfc/transformers/int_daisy_mathAltCreator/com/dessci/mathflow/MathFlowAltCreator.java 2008-12-13 20:21:25 UTC (rev 2185) @@ -24,6 +24,7 @@ import org.daisy.pipeline.core.transformer.TransformerDelegateListener; import org.daisy.util.execution.Command; +import org.daisy.util.file.Directory; import org.daisy.util.file.FileUtils; import org.daisy.util.file.FilenameOrFileURI; import org.daisy.util.file.TempFile; @@ -97,14 +98,36 @@ * @see int_daisy_mathAltCreator.IMathAltCreator#execute() */ public void execute() throws Exception { + File input = mInputDoc; + File output = mOutputDoc; + boolean copyInput = false; + boolean moveOutput = false; + Directory safeDir = null; + if (!Command.isSafePath(mInputDoc)) { + // Input doc path is unsafe. Copy to temp dir + copyInput = true; + safeDir = new Directory(TempFile.createDir()); + input = new File(new File(safeDir, "input"), mInputDoc.getName()); + FileUtils.copyFile(mInputDoc, input); + } + if (!Command.isSafePath(mOutputDoc)) { + // Output doc path is unsafe. Write to temp dir instead + moveOutput = true; + if (safeDir == null) { + safeDir = new Directory(TempFile.createDir()); + } + output = new File(new File(safeDir, "output"), mOutputDoc.getName()); + FileUtils.createDirectory(output.getParentFile()); + } + ArrayList<String> commandArgs = new ArrayList<String>(); commandArgs.add(mComposerPath.getAbsolutePath()); commandArgs.add("-inputdoc"); - commandArgs.add(mInputDoc.getAbsolutePath()); + commandArgs.add(input.getAbsolutePath()); commandArgs.add("-outputdoc"); - commandArgs.add(mOutputDoc.getAbsolutePath()); + commandArgs.add(output.getAbsolutePath()); commandArgs.add("-imagefolder"); commandArgs.add(mImagesPath); @@ -120,6 +143,19 @@ if(ret != 0) { throw new IOException("MathDAISY failed. Exit status was " + ret); } + + if (moveOutput) { + // Move the result back to the real output location + FileUtils.moveFile(output, mOutputDoc); + Directory tempImages = new Directory(new File(output.getParentFile(), mImagesPath).getCanonicalFile()); + Directory destImages = new Directory(new File(mOutputDoc.getParentFile(), mImagesPath).getCanonicalFile()); + tempImages.copyChildrenTo(destImages, true); + } + if (copyInput || moveOutput) { + // Delete temp dir + safeDir.deleteContents(true); + safeDir.delete(); + } tempFix(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |