Return-Path: Mailing-List: contact ant-dev-help@jakarta.apache.org; run by ezmlm Delivered-To: mailing list ant-dev@jakarta.apache.org Received: (qmail 6104 invoked from network); 18 Feb 2000 23:14:56 -0000 Received: from ux4.sp.cs.cmu.edu (128.2.198.104) by locus.apache.org with SMTP; 18 Feb 2000 23:14:56 -0000 Received: from TURTLE.CORAL.CS.CMU.EDU by ux4.sp.cs.cmu.edu id aa27940; 18 Feb 2000 18:14 EST Date: Fri, 18 Feb 2000 18:14:26 -0500 From: William Uther To: ant-dev@jakarta.apache.org Subject: Copying meta-info on a mac (and small bug fix) Message-ID: <1030629.3159886466@turtle.coral.cs.cmu.edu> Originator-Info: login-id=will; server=postoffice.srv.cs.cmu.edu X-Mailer: Mulberry (MacOS) [1.4.4, s/n S-100002] MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Content-Disposition: inline Hi all, As I'm sure most of you know, Macs carry meta-info around with their files. Currently ANT's copyFile methods don't copy that. I've modified the Project.copyFile() method to copy that data. My modifications use this open source java library: . At the same time I noticed that the copyFile method will leave the file open if an IOException is thrown. I've added try/finally blocks to close the files. Both modifications should have no effect on Non-Mac platforms. You'll need to download the library though. later, \x/ill :-} Here is the replacement copyFile method. Sorry, I don't have a 'diff' utility on my Mac, so this is the entire method: public void copyFile(File sourceFile, File destFile, boolean filtering) throws IOException { if (destFile.lastModified() < sourceFile.lastModified()) { log("Copy: " + sourceFile.getAbsolutePath() + " > " + destFile.getAbsolutePath(), MSG_VERBOSE); // ensure that parent dir of dest file exists! // not using getParentFile method to stay 1.1 compat File parent = new File(destFile.getParent()); if (!parent.exists()) { parent.mkdirs(); } if (filtering) { BufferedReader in = null; BufferedWriter out = null; try { int length; String line; String newline = null; in = new BufferedReader(new FileReader(sourceFile)); out = new BufferedWriter(new FileWriter(destFile)); line = in.readLine(); while (line != null) { if (line.length() == 0) { out.newLine(); } else { newline = replace(line, filters); out.write(newline); out.newLine(); } line = in.readLine(); } } finally { if (out != null) out.close(); if (in != null) in.close(); } } else { FileInputStream in = null; FileOutputStream out = null; try { in = new FileInputStream(sourceFile); out = new FileOutputStream(destFile); byte[] buffer = new byte[8 * 1024]; int count = 0; do { out.write(buffer, 0, count); count = in.read(buffer, 0, buffer.length); } while (count != -1); } finally { if (in != null) in.close(); if (out != null) out.close(); } } // now copy the mac resource fork and other Meta-Info. // Should never filter the Meta-Info! if (glguerin.util.MacPlatform.getJDirectVersion() == 2) { glguerin.mac.io.MacFileForker.SetFactoryName("glguerin.mac.io.imp.macos.JD 2.JD2Forker"); glguerin.mac.io.MacFileForker sourceFF = glguerin.mac.io.MacFileForker.MakeOne( new glguerin.mac.io.MacFilePathname(sourceFile)); glguerin.mac.io.MacFileForker destFF = glguerin.mac.io.MacFileForker.MakeOne( new glguerin.mac.io.MacFilePathname(destFile)); if (!sourceFile.isDirectory()) { InputStream in = null; OutputStream out = null; try { in = sourceFF.makeForkInputStream(true); out = destFF.makeForkOutputStream(true); byte[] buffer = new byte[8 * 1024]; int count = 0; do { out.write(buffer, 0, count); count = in.read(buffer, 0, buffer.length); } while (count != -1); } finally { if (in != null) in.close(); if (out != null) out.close(); } } destFF.setCatalogInfo(sourceFF.getCatalogInfo(true)); } } }