20 package org.sleuthkit.autopsy.datamodel.utils;
23 import java.util.HashMap;
25 import java.util.logging.Level;
44 SleuthkitCase.CaseDbTransaction globalTrans = null;
45 boolean useSingleTransaction =
true;
46 SleuthkitCase sleuthkitCase;
55 this.sleuthkitCase = sleuthkitCase;
56 this.useSingleTransaction =
false;
66 public LocalFileImporter(SleuthkitCase sleuthkitCase, SleuthkitCase.CaseDbTransaction trans) {
67 this.sleuthkitCase = sleuthkitCase;
68 this.globalTrans = trans;
69 this.useSingleTransaction =
true;
91 public AbstractFile
addLocalFile(File fileOnDisk, String name, String parentPath,
92 Long ctime, Long crtime, Long atime, Long mtime,
93 DataSource dataSource)
throws TskCoreException {
98 SleuthkitCase.CaseDbTransaction trans = null;
100 if (useSingleTransaction) {
103 trans = sleuthkitCase.beginTransaction();
108 if (fileOnDisk.exists()) {
109 size = fileOnDisk.length();
113 AbstractFile file = sleuthkitCase.addLocalFile(name, fileOnDisk.getAbsolutePath(), size,
114 ctime, crtime, atime, mtime,
115 true, TskData.EncodingType.NONE, parentDir, trans);
117 if (! useSingleTransaction) {
121 }
catch (TskCoreException ex) {
122 if ((!useSingleTransaction) && (null != trans)) {
125 }
catch (TskCoreException ex2) {
126 logger.log(Level.SEVERE, String.format(
"Failed to rollback transaction after exception: %s", ex.getMessage()), ex2);
145 if ((directory == null) || directory.getPath().isEmpty()) {
146 throw new TskCoreException(
"Can not create directory from null path");
150 if (localFileDirMap.containsKey(directory.toString())) {
151 return localFileDirMap.get(directory.toString());
154 File parent = directory.getParentFile();
155 if (parent == null) {
158 localFileDirMap.put(directory.getName(), dir);
165 localFileDirMap.put(directory.getPath(), dir);
181 SleuthkitCase.CaseDbTransaction trans = null;
184 if (useSingleTransaction) {
187 trans = sleuthkitCase.beginTransaction();
189 SpecialDirectory dir;
191 dir = sleuthkitCase.addLocalDirectory(parentId, name, trans);
193 if (! useSingleTransaction) {
197 }
catch (TskCoreException ex) {
198 if (( !useSingleTransaction) && (null != trans)) {
201 }
catch (TskCoreException ex2) {
202 logger.log(Level.SEVERE, String.format(
"Failed to rollback transaction after exception: %s", ex.getMessage()), ex2);
SpecialDirectory getOrMakeDirInDataSource(File directory, Content dataSource)
static final Logger logger
LocalFileImporter(SleuthkitCase sleuthkitCase, SleuthkitCase.CaseDbTransaction trans)
final Map< String, SpecialDirectory > localFileDirMap
AbstractFile addLocalFile(File fileOnDisk, String name, String parentPath, Long ctime, Long crtime, Long atime, Long mtime, DataSource dataSource)
SpecialDirectory createLocalFilesDir(long parentId, String name)
synchronized static Logger getLogger(String name)
LocalFileImporter(SleuthkitCase sleuthkitCase)