Autopsy  4.16.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
GetFilesCountVisitor.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2012-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.ingest;
20 
21 import java.util.List;
22 import java.util.logging.Level;
26 import org.sleuthkit.datamodel.Content;
27 import org.sleuthkit.datamodel.ContentVisitor;
28 import org.sleuthkit.datamodel.FileSystem;
29 import org.sleuthkit.datamodel.LayoutFile;
30 import org.sleuthkit.datamodel.SleuthkitCase;
31 import org.sleuthkit.datamodel.TskCoreException;
32 import org.sleuthkit.datamodel.TskData;
33 
40 final class GetFilesCountVisitor extends ContentVisitor.Default<Long> {
41 
42  private static final Logger logger = Logger.getLogger(GetFilesCountVisitor.class.getName());
43 
44  @Override
45  public Long visit(FileSystem fs) {
46  //recursion stop here
47  //case of a real fs, query all files for it
48  SleuthkitCase sc;
49  try {
50  sc = Case.getCurrentCaseThrows().getSleuthkitCase();
51  } catch (NoCurrentCaseException ex) {
52  logger.log(Level.SEVERE, "Exception while getting open case.", ex); //NON-NLS
53  return 0L;
54  }
55  StringBuilder queryB = new StringBuilder();
56  queryB.append("( (fs_obj_id = ").append(fs.getId()); //NON-NLS
57  //queryB.append(") OR (fs_obj_id = NULL) )");
58  queryB.append(") )");
59  queryB.append(" AND ( (meta_type = ").append(TskData.TSK_FS_META_TYPE_ENUM.TSK_FS_META_TYPE_REG.getValue()); //NON-NLS
60  queryB.append(") OR (meta_type = ").append(TskData.TSK_FS_META_TYPE_ENUM.TSK_FS_META_TYPE_DIR.getValue()); //NON-NLS
61  queryB.append(") OR (meta_type = ").append(TskData.TSK_FS_META_TYPE_ENUM.TSK_FS_META_TYPE_VIRT_DIR.getValue()); //NON-NLS
62  queryB.append(") OR (meta_type = ").append(TskData.TSK_FS_META_TYPE_ENUM.TSK_FS_META_TYPE_VIRT.getValue()); //NON-NLS
63  queryB.append(" AND (name != '.') AND (name != '..')"); //NON-NLS
64  queryB.append(") )");
65  //queryB.append( "AND (type = ");
66  //queryB.append(TskData.TSK_DB_FILES_TYPE_ENUM.FS.getFileType());
67  //queryB.append(")");
68  try {
69  final String query = queryB.toString();
70  return sc.countFilesWhere(query);
71  } catch (TskCoreException ex) {
72  logger.log(Level.SEVERE, "Couldn't get count of all files in FileSystem", ex); //NON-NLS
73  return 0L;
74  }
75  }
76 
77  @Override
78  public Long visit(LayoutFile lf) {
79  //recursion stop here
80  //case of LayoutFile child of Image or Volume
81  return 1L;
82  }
83 
84  private long getCountFromChildren(Content content) {
85  long count = 0;
86  try {
87  List<Content> children = content.getChildren();
88  if (children.size() > 0) {
89  for (Content child : children) {
90  count += child.accept(this);
91  }
92  } else {
93  count = 1;
94  }
95  } catch (TskCoreException ex) {
96  logger.log(Level.WARNING, "Could not get count of objects from children to get num of total files to be ingested", ex); //NON-NLS
97  }
98  return count;
99  }
100 
101  @Override
102  protected Long defaultVisit(Content cntnt) {
103  //recurse assuming this is image/vs/volume
104  //recursion stops at fs or unalloc file
105  return getCountFromChildren(cntnt);
106  }
107 }

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