Autopsy  4.19.3
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  private final boolean createTimestamp;
51  private final boolean accessTimestamp;
52  private final boolean modifiedTimestamp;
53 
80  AddLocalFilesTask(String deviceId, String rootVirtualDirectoryName, List<String> localFilePaths, Host host, boolean createTimestamp,
81  boolean accessTimestamp, boolean modifiedTimestamp, DataSourceProcessorProgressMonitor progressMonitor, DataSourceProcessorCallback callback) {
82  this.deviceId = deviceId;
83  this.rootVirtualDirectoryName = rootVirtualDirectoryName;
84  this.localFilePaths = localFilePaths;
85  this.host = host;
86  this.createTimestamp = createTimestamp;
87  this.accessTimestamp = accessTimestamp;
88  this.modifiedTimestamp = modifiedTimestamp;
89  this.callback = callback;
90  this.progress = progressMonitor;
91  }
92 
98  @Override
99  public void run() {
100  List<Content> newDataSources = new ArrayList<>();
101  List<String> errors = new ArrayList<>();
102  try {
103  progress.setIndeterminate(true);
104  FileManager fileManager = Case.getCurrentCaseThrows().getServices().getFileManager();
105  LocalFilesDataSource newDataSource = fileManager.addLocalFilesDataSource(deviceId, rootVirtualDirectoryName, "", host, localFilePaths, createTimestamp,
106  accessTimestamp, modifiedTimestamp, new ProgressUpdater());
107  newDataSources.add(newDataSource);
108  } catch (TskDataException | TskCoreException | NoCurrentCaseException ex) {
109  errors.add(ex.getMessage());
110  LOGGER.log(Level.SEVERE, String.format("Failed to add datasource: %s", ex.getMessage()), ex);
111  } finally {
112  DataSourceProcessorCallback.DataSourceProcessorResult result;
113  if (!errors.isEmpty()) {
114  result = DataSourceProcessorCallback.DataSourceProcessorResult.CRITICAL_ERRORS;
115  } else {
116  result = DataSourceProcessorCallback.DataSourceProcessorResult.NO_ERRORS;
117  }
118  callback.done(result, errors, newDataSources);
119  }
120  }
121 
126  private class ProgressUpdater implements FileManager.FileAddProgressUpdater {
127 
128  private int count;
129 
134  @Override
135  public void fileAdded(final AbstractFile file) {
136  ++count;
137  if (count % 10 == 0) {
138  progress.setProgressText(NbBundle.getMessage(this.getClass(),
139  "AddLocalFilesTask.localFileAdd.progress.text",
140  file.getParentPath(),
141  file.getName()));
142  }
143  }
144  }
145 }

Copyright © 2012-2022 Basis Technology. Generated on: Tue Jun 27 2023
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.