mirror of
https://github.com/internetarchive/heritrix3.git
synced 2026-08-03 13:21:20 +00:00
Fix HER-1935 Many calls to File.mkdirs() and other file/dir methods don't check the return value. Also fix bug where pointless empty directories were created in scratch dir.
* BasicProfileTest.java, SelfTestBase.java, CrawlControllerTest.java, PrecedenceLoader.java, MigrateH1to3Tool.java, CrawlerLoggerModule.java, StatisticsTracker.java, CheckpointUtils.java, BdbUriUniqFilter.java, ARCWriterProcessorTest.java, WARCWriterProcessorTest.java, PersistProcessor.java, WriterPoolProcessor.java, PrefixFinderTest.java, StoredQueueTest.java, FileUtilsTest.java, ObjectIdentityBdbManualCacheTest.java, ObjectIdentityBdbCacheTest.java, ObjectPlusFilesOutputStream.java, TestUtils.java, TmpDirTestCase.java, Engine.java
Replace calls to File.mkdirs() with FileUtils.ensureWriteableDirectory(dir). In these cases the calls were either already in a spot where the possible IOException would be handled appropriately, or the line was trivially moved into such a block.
* ActionDirectory.java, Engine.java
replace calls to File.mkdirs() with FileUtils.ensureWriteableDirectory(dir), and throw IllegalStateException on failure
* BdbModule.java
setup() - replace call to File.mkdirs() with FileUtils.ensureWriteableDirectory(dir) and add "throws IOException" - conveniently the place where this method is called was already in a try block that catches IOException
* Checkpoint.java
generateFrom() - replace call to File.mkdirs() with FileUtils.ensureWriteableDirectory(dir) and add "throws IOException"
* CheckpointService.java
move call to Checkpoint.generateFrom() inside existing try block since it now can throw IOException
* Recorder.java
ensure(File) - replace call to File.mkdirs() with FileUtils.ensureWriteableDirectory(dir), and throw IllegalStateException on failure
new Recorder(File,String,int,int) - call ensure() on the correct object, the containing directory; and remove redundant call to ensure()
This commit is contained in:
@@ -30,6 +30,7 @@ import org.archive.modules.net.BdbServerCache;
|
||||
import org.archive.spring.ConfigPath;
|
||||
import org.archive.state.ModuleTestBase;
|
||||
import org.archive.util.ArchiveUtils;
|
||||
import org.archive.util.FileUtils;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -45,9 +46,7 @@ public class CrawlControllerTest extends ModuleTestBase {
|
||||
tmpPath = DEFAULT_TEST_TMP_DIR;
|
||||
}
|
||||
File tmp = new File(tmpPath);
|
||||
if (!tmp.exists()) {
|
||||
tmp.mkdirs();
|
||||
}
|
||||
FileUtils.ensureWriteableDirectory(tmp);
|
||||
|
||||
FileWriter fileWriter = null;
|
||||
try {
|
||||
@@ -59,10 +58,10 @@ public class CrawlControllerTest extends ModuleTestBase {
|
||||
}
|
||||
|
||||
File state = new File(tmp, "state");
|
||||
state.mkdirs();
|
||||
FileUtils.ensureWriteableDirectory(state);
|
||||
|
||||
File checkpoints = new File(tmp, "checkpoints");
|
||||
checkpoints.mkdirs();
|
||||
FileUtils.ensureWriteableDirectory(checkpoints);
|
||||
|
||||
BdbModule bdb = new BdbModule();
|
||||
bdb.setDir(new ConfigPath("test",state.getAbsolutePath()));
|
||||
|
||||
@@ -90,7 +90,7 @@ public abstract class SelfTestBase extends TmpDirTestCase {
|
||||
if(profileTemplate.exists()) {
|
||||
org.apache.commons.io.FileUtils.copyDirectory(profileTemplate, tmpDefProfile);
|
||||
} else {
|
||||
tmpDefProfile.mkdirs();
|
||||
org.archive.util.FileUtils.ensureWriteableDirectory(tmpDefProfile);
|
||||
}
|
||||
|
||||
// Start up a Jetty that serves the selftest's content directory.
|
||||
@@ -98,7 +98,7 @@ public abstract class SelfTestBase extends TmpDirTestCase {
|
||||
|
||||
// Copy configuration for eg Logging over
|
||||
File tmpConfDir = new File(tmpTestDir, "conf");
|
||||
tmpConfDir.mkdirs();
|
||||
org.archive.util.FileUtils.ensureWriteableDirectory(tmpConfDir);
|
||||
File srcConf = new File(src.getParentFile(), "conf");
|
||||
FileUtils.copyDirectory(srcConf, tmpConfDir);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user