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

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