HDFS-14028. HDFS OIV temporary dir deletes folder.
Contributed by Adam Antal.
(cherry picked from commit 4f10d7e23f
)
This commit is contained in:
parent
c61b00f307
commit
3cbb028dd2
|
@ -20,7 +20,6 @@ package org.apache.hadoop.hdfs.tools.offlineImageViewer;
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import org.apache.commons.io.FileUtils;
|
|
||||||
import org.apache.hadoop.conf.Configuration;
|
import org.apache.hadoop.conf.Configuration;
|
||||||
import org.apache.hadoop.fs.Path;
|
import org.apache.hadoop.fs.Path;
|
||||||
import org.apache.hadoop.fs.permission.PermissionStatus;
|
import org.apache.hadoop.fs.permission.PermissionStatus;
|
||||||
|
@ -298,7 +297,8 @@ abstract class PBImageTextWriter implements Closeable {
|
||||||
LevelDBMetadataMap(String baseDir) throws IOException {
|
LevelDBMetadataMap(String baseDir) throws IOException {
|
||||||
File dbDir = new File(baseDir);
|
File dbDir = new File(baseDir);
|
||||||
if (dbDir.exists()) {
|
if (dbDir.exists()) {
|
||||||
FileUtils.deleteDirectory(dbDir);
|
throw new IOException("Folder " + dbDir + " already exists! Delete " +
|
||||||
|
"manually or provide another (not existing) directory!");
|
||||||
}
|
}
|
||||||
if (!dbDir.mkdirs()) {
|
if (!dbDir.mkdirs()) {
|
||||||
throw new IOException("Failed to mkdir on " + dbDir);
|
throw new IOException("Failed to mkdir on " + dbDir);
|
||||||
|
|
|
@ -662,6 +662,25 @@ public class TestOfflineImageViewer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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)
|
private void testPBDelimitedWriter(String db)
|
||||||
throws IOException, InterruptedException {
|
throws IOException, InterruptedException {
|
||||||
final String DELIMITER = "\t";
|
final String DELIMITER = "\t";
|
||||||
|
|
Loading…
Reference in New Issue