private void initChildren(final FsEntry parent) throws IOException { boolean hasDirs = false; try(DirectoryStream<Path> stream = Files.newDirectoryStream(parent.p)) { for(Path c : stream) { if(!pathFilters.isEmpty() && isFiltered(parent, c.getFileName().toString())) { continue; } hasDirs |= new FsEntry(parent, c).dir; } } if(hasDirs) { for(FsEntry child : parent.getChildren()) { if(!child.dir) { continue; } initChildren(child); } } }
private static void readHashes(FsEntry parent, List<FsEntry> dirs) throws ProvisioningException { int dirsTotal = 0; try(DirectoryStream<Path> stream = Files.newDirectoryStream(parent.getPath())) { for(Path child : stream) { if(child.getFileName().toString().equals(Constants.HASHES)) { try(BufferedReader reader = Files.newBufferedReader(child)) { String line = reader.readLine(); while(line != null) { new FsEntry(parent, line, HashUtils.hexStringToByteArray(reader.readLine())); line = reader.readLine(); } } catch (IOException e) { throw new ProvisioningException("Failed to read hashes", e); } } else { dirs.add(new FsEntry(parent, child)); ++dirsTotal; } } } catch (IOException e) { throw new ProvisioningException("Failed to read hashes", e); } while(dirsTotal > 0) { readHashes(dirs.remove(dirs.size() - 1), dirs); --dirsTotal; } }
public FsEntry forPath(Path p) throws ProvisioningException { final FsEntry entry = new FsEntry(null, p); if(entry.dir) { try { initChildren(entry); } catch (IOException e) { throw new ProvisioningException(Errors.fsEntryInit(p), e); } } return entry; }
final Path hashesDir = LayoutUtils.getHashesDir(getInstallationHome()); if(Files.exists(hashesDir)) { final FsEntry originalState = new FsEntry(null, hashesDir); readHashes(originalState, new ArrayList<>()); final FsEntry currentState = getDefaultFsEntryFactory().forPath(getInstallationHome());