19 package org.sleuthkit.autopsy.casemodule;
21 import java.util.ArrayList;
22 import java.util.Collections;
23 import java.util.List;
24 import java.util.logging.Level;
26 import org.openide.util.NbBundle;
42 class AddLocalFilesTask
implements Runnable {
44 private final Logger logger = Logger.getLogger(AddLocalFilesTask.class.getName());
46 private final String dataSourcePath;
47 private final DataSourceProcessorProgressMonitor progressMonitor;
48 private final DataSourceProcessorCallback callbackObj;
50 private final Case currentCase;
53 private final Object lock =
new Object();
55 private volatile boolean cancelRequested =
false;
57 private boolean hasCritError =
false;
59 private final List<String> errorList =
new ArrayList<>();
60 private final List<Content> newContents = Collections.synchronizedList(
new ArrayList<Content>());
62 public AddLocalFilesTask(String dataSourcePath, DataSourceProcessorProgressMonitor aProgressMonitor, DataSourceProcessorCallback cbObj) {
64 currentCase = Case.getCurrentCase();
66 this.dataSourcePath = dataSourcePath;
67 this.callbackObj = cbObj;
68 this.progressMonitor = aProgressMonitor;
83 final LocalFilesAddProgressUpdater progUpdater =
new LocalFilesAddProgressUpdater(progressMonitor);
86 progressMonitor.setIndeterminate(
true);
87 progressMonitor.setProgress(0);
89 final FileManager fileManager = currentCase.getServices().getFileManager();
90 String[] paths = dataSourcePath.split(LocalFilesPanel.FILES_SEP);
91 List<String> absLocalPaths =
new ArrayList<>();
92 for (String path : paths) {
93 absLocalPaths.add(path);
95 newContents.add(fileManager.addLocalFilesDirs(absLocalPaths, progUpdater));
96 }
catch (TskCoreException ex) {
97 logger.log(Level.WARNING,
"Errors occurred while running add logical files. ", ex);
99 errorList.add(ex.getMessage());
107 private void postProcess() {
109 if (cancelRequested() || hasCritError) {
110 logger.log(Level.WARNING,
"Handling errors or interruption that occured in logical files process");
112 if (!errorList.isEmpty()) {
114 logger.log(Level.WARNING,
"Handling non-critical errors that occured in logical files process");
117 if (!(cancelRequested() || hasCritError)) {
118 progressMonitor.setProgress(100);
119 progressMonitor.setIndeterminate(
false);
123 if (!cancelRequested()) {
132 private void doCallBack() {
133 DataSourceProcessorCallback.DataSourceProcessorResult result;
136 result = DataSourceProcessorCallback.DataSourceProcessorResult.CRITICAL_ERRORS;
137 }
else if (!errorList.isEmpty()) {
138 result = DataSourceProcessorCallback.DataSourceProcessorResult.NONCRITICAL_ERRORS;
140 result = DataSourceProcessorCallback.DataSourceProcessorResult.NO_ERRORS;
144 callbackObj.done(result, errorList, newContents);
150 public void cancelTask() {
151 synchronized (lock) {
152 cancelRequested =
true;
156 private boolean cancelRequested() {
157 synchronized (lock) {
158 return cancelRequested;
177 if (count++ % 10 == 0) {
179 NbBundle.getMessage(
this.getClass(),
"AddLocalFilesTask.localFileAdd.progress.text",
void setProgressText(String text)
void fileAdded(final AbstractFile newFile)
final DataSourceProcessorProgressMonitor progressMonitor