From 4f10d7e23fc0b757a9e94bc448187a6211b90f10 Mon Sep 17 00:00:00 2001 From: Anu Engineer Date: Fri, 26 Oct 2018 16:41:23 -0700 Subject: [PATCH] HDFS-14028. HDFS OIV temporary dir deletes folder. Contributed by Adam Antal. --- .../offlineImageViewer/PBImageTextWriter.java | 4 ++-- .../TestOfflineImageViewer.java | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/PBImageTextWriter.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/PBImageTextWriter.java index 5a1644ca63..ee7839521a 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/PBImageTextWriter.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/PBImageTextWriter.java @@ -20,7 +20,6 @@ import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; -import org.apache.commons.io.FileUtils; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.permission.PermissionStatus; @@ -298,7 +297,8 @@ protected boolean removeEldestEntry(Map.Entry entry) { LevelDBMetadataMap(String baseDir) throws IOException { File dbDir = new File(baseDir); if (dbDir.exists()) { - FileUtils.deleteDirectory(dbDir); + throw new IOException("Folder " + dbDir + " already exists! Delete " + + "manually or provide another (not existing) directory!"); } if (!dbDir.mkdirs()) { throw new IOException("Failed to mkdir on " + dbDir); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/TestOfflineImageViewer.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/TestOfflineImageViewer.java index 5574d7b4a9..8c8d404228 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/TestOfflineImageViewer.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/TestOfflineImageViewer.java @@ -669,6 +669,25 @@ public void testOfflineImageViewerHelpMessage() throws Throwable { } } + @Test(expected = IOException.class) + public void testDelimitedWithExistingFolder() throws IOException, + InterruptedException { + File tempDelimitedDir = null; + try { + String tempDelimitedDirName = "tempDirDelimited"; + String tempDelimitedDirPath = new FileSystemTestHelper(). + getTestRootDir() + "/" + tempDelimitedDirName; + tempDelimitedDir = new File(tempDelimitedDirPath); + Assert.assertTrue("Couldn't create temp directory!", + tempDelimitedDir.mkdirs()); + testPBDelimitedWriter(tempDelimitedDirPath); + } finally { + if (tempDelimitedDir != null) { + FileUtils.deleteDirectory(tempDelimitedDir); + } + } + } + private void testPBDelimitedWriter(String db) throws IOException, InterruptedException { final String DELIMITER = "\t";