Autopsy  3.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
AddLocalFilesTask.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2013-2014 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.casemodule;
20 
21 import java.util.ArrayList;
22 import java.util.Collections;
23 import java.util.List;
24 import java.util.logging.Level;
25 
26 import org.openide.util.NbBundle;
34 
42 class AddLocalFilesTask implements Runnable {
43 
44  private final Logger logger = Logger.getLogger(AddLocalFilesTask.class.getName());
45 
46  private final String dataSourcePath;
47  private final DataSourceProcessorProgressMonitor progressMonitor;
48  private final DataSourceProcessorCallback callbackObj;
49 
50  private final Case currentCase;
51 
52  // synchronization object for cancelRequested
53  private final Object lock = new Object();
54  // true if the process was requested to stop
55  private volatile boolean cancelRequested = false;
56 
57  private boolean hasCritError = false;
58 
59  private final List<String> errorList = new ArrayList<>();
60  private final List<Content> newContents = Collections.synchronizedList(new ArrayList<Content>());
61 
62  public AddLocalFilesTask(String dataSourcePath, DataSourceProcessorProgressMonitor aProgressMonitor, DataSourceProcessorCallback cbObj) {
63 
64  currentCase = Case.getCurrentCase();
65 
66  this.dataSourcePath = dataSourcePath;
67  this.callbackObj = cbObj;
68  this.progressMonitor = aProgressMonitor;
69  }
70 
78  @Override
79  public void run() {
80 
81  errorList.clear();
82 
83  final LocalFilesAddProgressUpdater progUpdater = new LocalFilesAddProgressUpdater(progressMonitor);
84  try {
85 
86  progressMonitor.setIndeterminate(true);
87  progressMonitor.setProgress(0);
88 
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);
94  }
95  newContents.add(fileManager.addLocalFilesDirs(absLocalPaths, progUpdater));
96  } catch (TskCoreException ex) {
97  logger.log(Level.WARNING, "Errors occurred while running add logical files. ", ex); //NON-NLS
98  hasCritError = true;
99  errorList.add(ex.getMessage());
100  }
101 
102  // handle done
103  postProcess();
104 
105  }
106 
107  private void postProcess() {
108 
109  if (cancelRequested() || hasCritError) {
110  logger.log(Level.WARNING, "Handling errors or interruption that occured in logical files process"); //NON-NLS
111  }
112  if (!errorList.isEmpty()) {
113  //data error (non-critical)
114  logger.log(Level.WARNING, "Handling non-critical errors that occured in logical files process"); //NON-NLS
115  }
116 
117  if (!(cancelRequested() || hasCritError)) {
118  progressMonitor.setProgress(100);
119  progressMonitor.setIndeterminate(false);
120  }
121 
122  // invoke the callBack, unless the caller cancelled
123  if (!cancelRequested()) {
124  doCallBack();
125  }
126 
127  }
128 
129  /*
130  * Call the callback with results, new content, and errors, if any
131  */
132  private void doCallBack() {
133  DataSourceProcessorCallback.DataSourceProcessorResult result;
134 
135  if (hasCritError) {
136  result = DataSourceProcessorCallback.DataSourceProcessorResult.CRITICAL_ERRORS;
137  } else if (!errorList.isEmpty()) {
138  result = DataSourceProcessorCallback.DataSourceProcessorResult.NONCRITICAL_ERRORS;
139  } else {
140  result = DataSourceProcessorCallback.DataSourceProcessorResult.NO_ERRORS;
141  }
142 
143  // invoke the callback, passing it the result, list of new contents, and list of errors
144  callbackObj.done(result, errorList, newContents);
145  }
146 
147  /*
148  * cancel the files addition, if possible
149  */
150  public void cancelTask() {
151  synchronized (lock) {
152  cancelRequested = true;
153  }
154  }
155 
156  private boolean cancelRequested() {
157  synchronized (lock) {
158  return cancelRequested;
159  }
160  }
161 
165  private class LocalFilesAddProgressUpdater implements FileManager.FileAddProgressUpdater {
166 
167  private int count = 0;
169 
171 
172  this.progressMonitor = progressMonitor;
173  }
174 
175  @Override
176  public void fileAdded(final AbstractFile newFile) {
177  if (count++ % 10 == 0) {
178  progressMonitor.setProgressText(
179  NbBundle.getMessage(this.getClass(), "AddLocalFilesTask.localFileAdd.progress.text",
180  newFile.getParentPath(), newFile.getName()));
181  }
182  }
183  }
184 }

Copyright © 2012-2015 Basis Technology. Generated on: Mon Oct 19 2015
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.