|
@@ -21,13 +21,13 @@ import java.io.*;
|
|
|
import java.util.*;
|
|
|
|
|
|
import org.apache.hadoop.conf.Configuration;
|
|
|
+import org.apache.hadoop.fs.FileStatus;
|
|
|
import org.apache.hadoop.fs.Path;
|
|
|
import org.apache.hadoop.fs.ContentSummary;
|
|
|
import org.apache.hadoop.fs.permission.*;
|
|
|
import org.apache.hadoop.metrics.MetricsRecord;
|
|
|
import org.apache.hadoop.metrics.MetricsUtil;
|
|
|
import org.apache.hadoop.metrics.MetricsContext;
|
|
|
-import org.apache.hadoop.hdfs.protocol.DFSFileInfo;
|
|
|
import org.apache.hadoop.hdfs.protocol.FSConstants;
|
|
|
import org.apache.hadoop.hdfs.protocol.Block;
|
|
|
import org.apache.hadoop.hdfs.protocol.QuotaExceededException;
|
|
@@ -657,7 +657,7 @@ class FSDirectory implements FSConstants, Closeable {
|
|
|
* This function is admittedly very inefficient right now. We'll
|
|
|
* make it better later.
|
|
|
*/
|
|
|
- public DFSFileInfo[] getListing(String src) {
|
|
|
+ public FileStatus[] getListing(String src) {
|
|
|
String srcs = normalizePath(src);
|
|
|
|
|
|
synchronized (rootDir) {
|
|
@@ -665,15 +665,15 @@ class FSDirectory implements FSConstants, Closeable {
|
|
|
if (targetNode == null)
|
|
|
return null;
|
|
|
if (!targetNode.isDirectory()) {
|
|
|
- return new DFSFileInfo[]{new DFSFileInfo(srcs, targetNode)};
|
|
|
+ return new FileStatus[]{createFileStatus(srcs, targetNode)};
|
|
|
}
|
|
|
List<INode> contents = ((INodeDirectory)targetNode).getChildren();
|
|
|
- DFSFileInfo listing[] = new DFSFileInfo[contents.size()];
|
|
|
+ FileStatus listing[] = new FileStatus[contents.size()];
|
|
|
if(! srcs.endsWith(Path.SEPARATOR))
|
|
|
srcs += Path.SEPARATOR;
|
|
|
int i = 0;
|
|
|
for (INode cur : contents) {
|
|
|
- listing[i] = new DFSFileInfo(srcs+cur.getLocalName(), cur);
|
|
|
+ listing[i] = createFileStatus(srcs+cur.getLocalName(), cur);
|
|
|
i++;
|
|
|
}
|
|
|
return listing;
|
|
@@ -685,7 +685,7 @@ class FSDirectory implements FSConstants, Closeable {
|
|
|
* @return object containing information regarding the file
|
|
|
* or null if file not found
|
|
|
*/
|
|
|
- DFSFileInfo getFileInfo(String src) {
|
|
|
+ FileStatus getFileInfo(String src) {
|
|
|
String srcs = normalizePath(src);
|
|
|
synchronized (rootDir) {
|
|
|
INode targetNode = rootDir.getNode(srcs);
|
|
@@ -693,7 +693,7 @@ class FSDirectory implements FSConstants, Closeable {
|
|
|
return null;
|
|
|
}
|
|
|
else {
|
|
|
- return new DFSFileInfo(srcs, targetNode);
|
|
|
+ return createFileStatus(srcs, targetNode);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -1106,4 +1106,21 @@ class FSDirectory implements FSConstants, Closeable {
|
|
|
}
|
|
|
return status;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Create FileStatus by file INode
|
|
|
+ */
|
|
|
+ private static FileStatus createFileStatus(String path, INode node) {
|
|
|
+ // length is zero for directories
|
|
|
+ return new FileStatus(node.isDirectory() ? 0 : node.computeContentSummary().getLength(),
|
|
|
+ node.isDirectory(),
|
|
|
+ node.isDirectory() ? 0 : ((INodeFile)node).getReplication(),
|
|
|
+ node.isDirectory() ? 0 : ((INodeFile)node).getPreferredBlockSize(),
|
|
|
+ node.getModificationTime(),
|
|
|
+ node.getAccessTime(),
|
|
|
+ node.getFsPermission(),
|
|
|
+ node.getUserName(),
|
|
|
+ node.getGroupName(),
|
|
|
+ new Path(path));
|
|
|
+ }
|
|
|
}
|