116 private final String path;
117 private final long objectID;
127 transient private static final List<String> KNOWN_MOUNTPOINTS
130 "/storage/emulated/");
149 this.path = normalizePath(pathName);
151 String fileName = path.substring(path.lastIndexOf(
'/') + 1);
152 if (fileName.isEmpty()) {
153 throw new TskCoreException(String.format(
"No file name specified for attachment file: %s, on data source = %d", path, dataSource.getId()));
156 String parentPathSubString = (path.lastIndexOf(
'/') < 0) ?
"" : path.substring(0, path.lastIndexOf(
'/'));
159 objectID = findAttachmentFile(caseDb, fileName, parentPathSubString, dataSource);
175 objectID = derivedFile.getId();
176 path = derivedFile.getUniquePath();
185 objectID = abstractFile.
getId();
216 private String normalizePath(String path) {
218 String adjustedPath = path.replace(
"\\",
"/").replace(
"%20",
" ");
221 for (String mountPoint : KNOWN_MOUNTPOINTS) {
222 if (adjustedPath.toLowerCase().startsWith(mountPoint)) {
223 adjustedPath = (
"/").concat(adjustedPath.substring(mountPoint.length()));
249 String whereClause = String.format(
"LOWER(name) = LOWER('%s') AND LOWER(parent_path) LIKE LOWER('%%%s%%')", fileName, parentPathSubstring);
250 List<AbstractFile> matchedFiles = caseDb.findAllFilesWhere(whereClause);
254 List<Long> allocFileMatchesOnSameDatasource =
new ArrayList<>();
255 List<Long> allocFileMatchesOnOtherDatasources =
new ArrayList<>();
256 List<Long> unallocFileMatches =
new ArrayList<>();
260 if (dataSource.getId() == file.getDataSource().getId()) {
261 allocFileMatchesOnSameDatasource.add(file.getId());
263 allocFileMatchesOnOtherDatasources.add(file.getId());
266 unallocFileMatches.add(file.getId());
271 return pickBestMatchFile(allocFileMatchesOnSameDatasource, allocFileMatchesOnOtherDatasources, unallocFileMatches);
302 private long pickBestMatchFile(List<Long> allocFileMatchesOnSameDatasource,
303 List<Long> allocFileMatchesOnOtherDatasources,
304 List<Long> unallocFileMatches) {
307 if (!allocFileMatchesOnSameDatasource.isEmpty() && allocFileMatchesOnSameDatasource.size() == 1) {
308 return allocFileMatchesOnSameDatasource.get(0);
311 if (!allocFileMatchesOnOtherDatasources.isEmpty()
312 && allocFileMatchesOnOtherDatasources.size() == 1) {
313 return allocFileMatchesOnOtherDatasources.get(0);
316 if (!unallocFileMatches.isEmpty()
317 && unallocFileMatches.size() == 1) {
318 return unallocFileMatches.get(0);
332 return this.objectID;