adding local files: handle case when listFiles() returns null

This commit is contained in:
adam-m 2013-07-06 11:36:31 -04:00
parent 84e6791e02
commit d929a6793b

View File

@ -197,7 +197,8 @@ public class FileManager implements Closeable {
} }
/** /**
* Interface for receiving notifications on folders being added via a callback * Interface for receiving notifications on folders being added via a
* callback
*/ */
public interface FileAddProgressUpdater { public interface FileAddProgressUpdater {
@ -304,12 +305,18 @@ public class FileManager implements Closeable {
if (isDir) { if (isDir) {
//create virtual folder //create virtual folder
final VirtualDirectory childVd = tskCase.addVirtualDirectory(parentVd.getId(), childLocalFile.getName()); final VirtualDirectory childVd = tskCase.addVirtualDirectory(parentVd.getId(), childLocalFile.getName());
if (childVd != null && addProgressUpdater != null ) { if (childVd != null && addProgressUpdater != null) {
addProgressUpdater.fileAdded(childVd); addProgressUpdater.fileAdded(childVd);
} }
//add children recursively //add children recursively
for (java.io.File childChild : childLocalFile.listFiles()) { final java.io.File[] childrenFiles = childLocalFile.listFiles();
addLocalDirectoryRecInt(childVd, childChild, addProgressUpdater); if (childrenFiles != null) {
for (java.io.File childChild : childrenFiles) {
addLocalDirectoryRecInt(childVd, childChild, addProgressUpdater);
}
} else {
//add leaf file, base case
this.addLocalFileSingle(childLocalFile.getAbsolutePath(), parentVd);
} }
} else { } else {
//add leaf file, base case //add leaf file, base case
@ -428,7 +435,7 @@ public class FileManager implements Closeable {
* closed * closed
* *
*/ */
private synchronized LocalFile addLocalFileSingle(String localAbsPath, AbstractFile parentFile ) throws TskCoreException { private synchronized LocalFile addLocalFileSingle(String localAbsPath, AbstractFile parentFile) throws TskCoreException {
if (tskCase == null) { if (tskCase == null) {
throw new TskCoreException("Attempted to use FileManager after it was closed."); throw new TskCoreException("Attempted to use FileManager after it was closed.");