Autopsy  4.7.0
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-2018 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.List;
23 import java.util.logging.Level;
24 import org.openide.util.NbBundle;
27 import org.sleuthkit.datamodel.AbstractFile;
28 import org.sleuthkit.datamodel.Content;
31 import org.sleuthkit.datamodel.LocalFilesDataSource;
32 import org.sleuthkit.datamodel.TskCoreException;
33 import org.sleuthkit.datamodel.TskDataException;
34 
40 class AddLocalFilesTask implements Runnable {
41 
42  private static final Logger LOGGER = Logger.getLogger(AddLocalFilesTask.class.getName());
43  private final String deviceId;
44  private final String rootVirtualDirectoryName;
45  private final List<String> localFilePaths;
46  private final DataSourceProcessorProgressMonitor progress;
47  private final DataSourceProcessorCallback callback;
48 
71  AddLocalFilesTask(String deviceId, String rootVirtualDirectoryName, List<String> localFilePaths, DataSourceProcessorProgressMonitor progressMonitor, DataSourceProcessorCallback callback) {
72  this.deviceId = deviceId;
73  this.rootVirtualDirectoryName = rootVirtualDirectoryName;
74  this.localFilePaths = localFilePaths;
75  this.callback = callback;
76  this.progress = progressMonitor;
77  }
78 
84  @Override
85  public void run() {
86  List<Content> newDataSources = new ArrayList<>();
87  List<String> errors = new ArrayList<>();
88  try {
89  progress.setIndeterminate(true);
90  FileManager fileManager = Case.getCurrentCaseThrows().getServices().getFileManager();
91  LocalFilesDataSource newDataSource = fileManager.addLocalFilesDataSource(deviceId, rootVirtualDirectoryName, "", localFilePaths, new ProgressUpdater());
92  newDataSources.add(newDataSource);
93  } catch (TskDataException | TskCoreException | NoCurrentCaseException ex) {
94  errors.add(ex.getMessage());
95  LOGGER.log(Level.SEVERE, String.format("Failed to add datasource: %s", ex.getMessage()), ex);
96  } finally {
97  DataSourceProcessorCallback.DataSourceProcessorResult result;
98  if (!errors.isEmpty()) {
99  result = DataSourceProcessorCallback.DataSourceProcessorResult.CRITICAL_ERRORS;
100  } else {
101  result = DataSourceProcessorCallback.DataSourceProcessorResult.NO_ERRORS;
102  }
103  callback.done(result, errors, newDataSources);
104  }
105  }
106 
111  private class ProgressUpdater implements FileManager.FileAddProgressUpdater {
112 
113  private int count;
114 
119  @Override
120  public void fileAdded(final AbstractFile file) {
121  ++count;
122  if (count % 10 == 0) {
123  progress.setProgressText(NbBundle.getMessage(this.getClass(),
124  "AddLocalFilesTask.localFileAdd.progress.text",
125  file.getParentPath(),
126  file.getName()));
127  }
128  }
129  }
130 }

Copyright © 2012-2016 Basis Technology. Generated on: Mon Jun 18 2018
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.