Autopsy  4.19.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-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;
29 import org.sleuthkit.datamodel.AbstractFile;
30 import org.sleuthkit.datamodel.Content;
31 import org.sleuthkit.datamodel.Host;
32 import org.sleuthkit.datamodel.LocalFilesDataSource;
33 import org.sleuthkit.datamodel.TskCoreException;
34 import org.sleuthkit.datamodel.TskDataException;
35 
41 class AddLocalFilesTask implements Runnable {
42 
43  private static final Logger LOGGER = Logger.getLogger(AddLocalFilesTask.class.getName());
44  private final String deviceId;
45  private final String rootVirtualDirectoryName;
46  private final Host host;
47  private final List<String> localFilePaths;
48  private final DataSourceProcessorProgressMonitor progress;
49  private final DataSourceProcessorCallback callback;
50 
74  AddLocalFilesTask(String deviceId, String rootVirtualDirectoryName, List<String> localFilePaths, Host host, DataSourceProcessorProgressMonitor progressMonitor, DataSourceProcessorCallback callback) {
75  this.deviceId = deviceId;
76  this.rootVirtualDirectoryName = rootVirtualDirectoryName;
77  this.localFilePaths = localFilePaths;
78  this.host = host;
79  this.callback = callback;
80  this.progress = progressMonitor;
81  }
82 
88  @Override
89  public void run() {
90  List<Content> newDataSources = new ArrayList<>();
91  List<String> errors = new ArrayList<>();
92  try {
93  progress.setIndeterminate(true);
94  FileManager fileManager = Case.getCurrentCaseThrows().getServices().getFileManager();
95  LocalFilesDataSource newDataSource = fileManager.addLocalFilesDataSource(deviceId, rootVirtualDirectoryName, "", host, localFilePaths, new ProgressUpdater());
96  newDataSources.add(newDataSource);
97  } catch (TskDataException | TskCoreException | NoCurrentCaseException ex) {
98  errors.add(ex.getMessage());
99  LOGGER.log(Level.SEVERE, String.format("Failed to add datasource: %s", ex.getMessage()), ex);
100  } finally {
101  DataSourceProcessorCallback.DataSourceProcessorResult result;
102  if (!errors.isEmpty()) {
103  result = DataSourceProcessorCallback.DataSourceProcessorResult.CRITICAL_ERRORS;
104  } else {
105  result = DataSourceProcessorCallback.DataSourceProcessorResult.NO_ERRORS;
106  }
107  callback.done(result, errors, newDataSources);
108  }
109  }
110 
115  private class ProgressUpdater implements FileManager.FileAddProgressUpdater {
116 
117  private int count;
118 
123  @Override
124  public void fileAdded(final AbstractFile file) {
125  ++count;
126  if (count % 10 == 0) {
127  progress.setProgressText(NbBundle.getMessage(this.getClass(),
128  "AddLocalFilesTask.localFileAdd.progress.text",
129  file.getParentPath(),
130  file.getName()));
131  }
132  }
133  }
134 }

Copyright © 2012-2021 Basis Technology. Generated on: Thu Sep 30 2021
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.