You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-dev@hadoop.apache.org by "Suresh Srinivas (JIRA)" <ji...@apache.org> on 2009/01/16 22:41:59 UTC

[jira] Commented: (HADOOP-5045) Remove deprecated FileSystem.isDirectory()

    [ https://issues.apache.org/jira/browse/HADOOP-5045?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12664694#action_12664694 ] 

Suresh Srinivas commented on HADOOP-5045:
-----------------------------------------

I am not sure why we deprecated {{FileSystem.isDirectory(path)}} method in favor of using {{FileSystem.getFileStatus(path).isDir()}}. The method is implemented as in org.apache.hadoop.fs.FileSystem.java as:

{noformat}

/** True iff the named path is a directory. */
/** @deprecated Use getFileStatus() instead */ @Deprecated
public boolean isDirectory(Path f) throws IOException {
  try {
    return getFileStatus(f).isDir();
  } catch (FileNotFoundException e) {
    return false;               // f does not exist
  }
}
{noformat}

It is convenient in the following cases (there are many instance of this in the code):
{noformat}
  if (fs.isDirectory(path)) {
    // do something
  }
{noformat}

Changing it to use {{getFileStatus}} requires catching the exception thrown by the method when the file does not exist as follows:
{noformat}
  boolean directory = false;
  try {
    FileStatus filestatus = fs.getFileStatus(path);
    directory = filestatus.isDir();
  } catch (FileNotFoundException ex) {
    // path does not exist
  }
  
  if (directory) {
    // do something
  }
{noformat}

The above code needs to be added at all the places where isDirectory() is being checked. This functionality is what the deprecated method provides, and it gives the convenience of not repeating the try-catch every where.


> Remove deprecated FileSystem.isDirectory()
> ------------------------------------------
>
>                 Key: HADOOP-5045
>                 URL: https://issues.apache.org/jira/browse/HADOOP-5045
>             Project: Hadoop Core
>          Issue Type: Sub-task
>          Components: fs
>            Reporter: Tsz Wo (Nicholas), SZE
>            Assignee: Suresh Srinivas
>
> We should remove FileSystem.isDirectory().

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.