From 566597503ce7b00c5c62ece919eb2e33c84bfc6b Mon Sep 17 00:00:00 2001 From: Eli Collins Date: Fri, 19 Nov 2010 03:56:15 +0000 Subject: [PATCH] HADOOP-7015. RawLocalFileSystem#listStatus does not deal with a directory whose entries are changing (e.g. in a multi-thread or multi-process environment). Contributed by Sanjay Radia git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1036729 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES.txt | 4 ++++ .../org/apache/hadoop/fs/RawLocalFileSystem.java | 15 +++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 0e01dac24be..e88d2b00cc4 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -15,6 +15,10 @@ Trunk (unreleased changes) BUG FIXES + HADOOP-7015. RawLocalFileSystem#listStatus does not deal with a directory + whose entries are changing (e.g. in a multi-thread or multi-process + environment). (Sanjay Radia via eli) + Release 0.22.0 - Unreleased INCOMPATIBLE CHANGES diff --git a/src/java/org/apache/hadoop/fs/RawLocalFileSystem.java b/src/java/org/apache/hadoop/fs/RawLocalFileSystem.java index 413ffd93836..053fd392def 100644 --- a/src/java/org/apache/hadoop/fs/RawLocalFileSystem.java +++ b/src/java/org/apache/hadoop/fs/RawLocalFileSystem.java @@ -28,6 +28,7 @@ import java.io.IOException; import java.io.OutputStream; import java.net.URI; import java.nio.ByteBuffer; +import java.util.Arrays; import java.util.EnumSet; import java.util.StringTokenizer; @@ -319,10 +320,20 @@ public class RawLocalFileSystem extends FileSystem { return null; } results = new FileStatus[names.length]; + int j = 0; for (int i = 0; i < names.length; i++) { - results[i] = getFileStatus(new Path(f, names[i])); + try { + results[j] = getFileStatus(new Path(f, names[i])); + j++; + } catch (FileNotFoundException e) { + // ignore the files not found since the dir list may have have changed + // since the names[] list was generated. + } } - return results; + if (j == names.length) { + return results; + } + return Arrays.copyOf(results, j); } /**