Return-Path: Delivered-To: apmail-hadoop-common-commits-archive@www.apache.org Received: (qmail 21006 invoked from network); 8 Oct 2009 18:38:02 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 8 Oct 2009 18:38:02 -0000 Received: (qmail 64240 invoked by uid 500); 8 Oct 2009 18:38:02 -0000 Delivered-To: apmail-hadoop-common-commits-archive@hadoop.apache.org Received: (qmail 64172 invoked by uid 500); 8 Oct 2009 18:38:02 -0000 Mailing-List: contact common-commits-help@hadoop.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: common-dev@hadoop.apache.org Delivered-To: mailing list common-commits@hadoop.apache.org Received: (qmail 64162 invoked by uid 99); 8 Oct 2009 18:38:02 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 08 Oct 2009 18:38:02 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 08 Oct 2009 18:37:59 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 1A1BA23888DB; Thu, 8 Oct 2009 18:37:38 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r823263 - in /hadoop/common/trunk: CHANGES.txt src/java/org/apache/hadoop/fs/FileUtil.java Date: Thu, 08 Oct 2009 18:37:37 -0000 To: common-commits@hadoop.apache.org From: szetszwo@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20091008183738.1A1BA23888DB@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: szetszwo Date: Thu Oct 8 18:37:37 2009 New Revision: 823263 URL: http://svn.apache.org/viewvc?rev=823263&view=rev Log: HADOOP-6283. Improve the exception messages thrown by FileUtil$HardLink.getLinkCount(..). Modified: hadoop/common/trunk/CHANGES.txt hadoop/common/trunk/src/java/org/apache/hadoop/fs/FileUtil.java Modified: hadoop/common/trunk/CHANGES.txt URL: http://svn.apache.org/viewvc/hadoop/common/trunk/CHANGES.txt?rev=823263&r1=823262&r2=823263&view=diff ============================================================================== --- hadoop/common/trunk/CHANGES.txt (original) +++ hadoop/common/trunk/CHANGES.txt Thu Oct 8 18:37:37 2009 @@ -12,6 +12,9 @@ IMPROVEMENTS + HADOOP-6283. Improve the exception messages thrown by + FileUtil$HardLink.getLinkCount(..). (szetszwo) + OPTIMIZATIONS BUG FIXES Modified: hadoop/common/trunk/src/java/org/apache/hadoop/fs/FileUtil.java URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/java/org/apache/hadoop/fs/FileUtil.java?rev=823263&r1=823262&r2=823263&view=diff ============================================================================== --- hadoop/common/trunk/src/java/org/apache/hadoop/fs/FileUtil.java (original) +++ hadoop/common/trunk/src/java/org/apache/hadoop/fs/FileUtil.java Thu Oct 8 18:37:37 2009 @@ -628,14 +628,18 @@ * Retrieves the number of links to the specified file. */ public static int getLinkCount(File fileName) throws IOException { + if (!fileName.exists()) { + throw new FileNotFoundException(fileName + " not found."); + } + int len = getLinkCountCommand.length; String[] cmd = new String[len + 1]; for (int i = 0; i < len; i++) { cmd[i] = getLinkCountCommand[i]; } cmd[len] = fileName.toString(); - String inpMsg = ""; - String errMsg = ""; + String inpMsg = null; + String errMsg = null; int exitValue = -1; BufferedReader in = null; BufferedReader err = null; @@ -647,14 +651,11 @@ in = new BufferedReader(new InputStreamReader( process.getInputStream())); inpMsg = in.readLine(); - if (inpMsg == null) inpMsg = ""; - err = new BufferedReader(new InputStreamReader( process.getErrorStream())); errMsg = err.readLine(); - if (errMsg == null) errMsg = ""; - if (exitValue != 0) { - throw new IOException(inpMsg + errMsg); + if (inpMsg == null || exitValue != 0) { + throw createIOException(fileName, inpMsg, errMsg, exitValue, null); } if (getOSType() == OSType.OS_TYPE_SOLARIS) { String[] result = inpMsg.split("\\s+"); @@ -663,13 +664,9 @@ return Integer.parseInt(inpMsg); } } catch (NumberFormatException e) { - throw new IOException(StringUtils.stringifyException(e) + - inpMsg + errMsg + - " on file:" + fileName); + throw createIOException(fileName, inpMsg, errMsg, exitValue, e); } catch (InterruptedException e) { - throw new IOException(StringUtils.stringifyException(e) + - inpMsg + errMsg + - " on file:" + fileName); + throw createIOException(fileName, inpMsg, errMsg, exitValue, e); } finally { process.destroy(); if (in != null) in.close(); @@ -678,6 +675,16 @@ } } + /** Create an IOException for failing to get link count. */ + static private IOException createIOException(File f, String message, + String error, int exitvalue, Exception cause) { + final String s = "Failed to get link count on file " + f + + ": message=" + message + + "; error=" + error + + "; exit value=" + exitvalue; + return cause == null? new IOException(s): new IOException(s, cause); + } + /** * Create a soft link between a src and destination * only on a local disk. HDFS does not support this