use of org.jboss.galleon.diff.FsEntry in project galleon by wildfly.
the class BasicFsEntriesFilteringTestCase method assertRootEntry.
@Override
protected void assertRootEntry(FsEntry rootEntry) throws Exception {
final FsEntry expectedRoot = new FsEntry(null, root);
final FsEntry a = new FsEntry(expectedRoot, root.resolve("a"));
final FsEntry b = new FsEntry(a, root.resolve("a/b"));
new FsEntry(b, root.resolve("a/b/file2.txt"));
new FsEntry(b, root.resolve("a/b/f"));
final FsEntry d = new FsEntry(a, root.resolve("a/d"));
new FsEntry(d, root.resolve("a/d/file1.txt"));
final FsEntry e = new FsEntry(expectedRoot, root.resolve("e"));
new FsEntry(e, root.resolve("e/file1.txt"));
new FsEntry(expectedRoot, root.resolve("file1.txt"));
new FsEntry(expectedRoot, root.resolve("g"));
assertIdentical(expectedRoot, rootEntry);
}
use of org.jboss.galleon.diff.FsEntry in project galleon by wildfly.
the class ProvisioningManager method readHashes.
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;
}
}
use of org.jboss.galleon.diff.FsEntry in project galleon by wildfly.
the class ProvisioningManager method getFsDiff.
/**
* Returns the status of the filesystem describing which files have been
* added, removed and modified since the last provisioning state transition.
*
* @return current status of the filesystem
* @throws ProvisioningException in case of an error during the status check
*/
public FsDiff getFsDiff() throws ProvisioningException {
final ProvisioningConfig config = getProvisioningConfig();
if (config == null || !config.hasFeaturePackDeps()) {
return null;
}
log.verbose("Detecting user changes");
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());
return FsDiff.diff(originalState, currentState);
}
try (ProvisioningRuntime rt = getRuntime(config)) {
rt.provision();
final FsEntryFactory fsFactory = getDefaultFsEntryFactory();
final FsEntry originalState = fsFactory.forPath(rt.getStagedDir());
final FsEntry currentState = fsFactory.forPath(getInstallationHome());
final long startTime = log.isVerboseEnabled() ? System.nanoTime() : -1;
final FsDiff fsDiff = FsDiff.diff(originalState, currentState);
if (startTime != -1) {
log.verbose(Errors.tookTime(" filesystem diff", startTime));
}
return fsDiff;
}
}
use of org.jboss.galleon.diff.FsEntry in project galleon by wildfly.
the class ProvisioningManager method persistChildHashes.
private void persistChildHashes(Path hashes, FsEntry entry, List<FsEntry> dirs, final Path target) throws ProvisioningException {
int dirsTotal = 0;
BufferedWriter writer = null;
try {
for (FsEntry child : entry.getChildren()) {
if (!child.isDir()) {
if (writer == null) {
writer = Files.newBufferedWriter(target.resolve(Constants.HASHES));
}
writer.write(child.getName());
writer.newLine();
writer.write(HashUtils.bytesToHexString(child.getHash()));
writer.newLine();
} else {
dirs.add(child);
++dirsTotal;
}
}
} catch (IOException e) {
throw new ProvisioningException(Errors.hashesNotPersisted(), e);
} finally {
if (writer != null) {
try {
writer.close();
} catch (IOException e) {
log.error(e, Errors.fileClose(target.resolve(Constants.HASHES)));
}
}
}
while (dirsTotal > 0) {
persistDirHashes(hashes, dirs.remove(dirs.size() - 1), dirs);
--dirsTotal;
}
}
use of org.jboss.galleon.diff.FsEntry in project galleon by wildfly.
the class ProvisioningManager method persistHashes.
private void persistHashes(ProvisioningRuntime runtime) throws ProvisioningException {
final long startTime = log.isVerboseEnabled() ? System.nanoTime() : -1;
final FsEntry root = getDefaultFsEntryFactory().forPath(runtime.getStagedDir());
if (root.hasChildren()) {
final Path hashes = LayoutUtils.getHashesDir(runtime.getStagedDir());
try {
Files.createDirectories(hashes);
} catch (IOException e) {
throw new ProvisioningException("Failed to persist hashes", e);
}
final List<FsEntry> dirs = new ArrayList<>();
persistChildHashes(hashes, root, dirs, hashes);
if (!dirs.isEmpty()) {
for (int i = dirs.size() - 1; i >= 0; --i) {
persistDirHashes(hashes, dirs.get(i), dirs);
}
}
}
if (startTime != -1) {
log.verbose(Errors.tookTime("Hashing", startTime));
}
}
Aggregations