Search in sources :

Example 1 with FsEntry

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);
}
Also used : FsEntry(org.jboss.galleon.diff.FsEntry)

Example 2 with FsEntry

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;
    }
}
Also used : Path(java.nio.file.Path) FsEntry(org.jboss.galleon.diff.FsEntry) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException)

Example 3 with FsEntry

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;
    }
}
Also used : ProvisioningConfig(org.jboss.galleon.config.ProvisioningConfig) Path(java.nio.file.Path) FsEntry(org.jboss.galleon.diff.FsEntry) ProvisioningRuntime(org.jboss.galleon.runtime.ProvisioningRuntime) FsDiff(org.jboss.galleon.diff.FsDiff) FsEntryFactory(org.jboss.galleon.diff.FsEntryFactory)

Example 4 with FsEntry

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;
    }
}
Also used : FsEntry(org.jboss.galleon.diff.FsEntry) IOException(java.io.IOException) BufferedWriter(java.io.BufferedWriter)

Example 5 with FsEntry

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));
    }
}
Also used : Path(java.nio.file.Path) FsEntry(org.jboss.galleon.diff.FsEntry) ArrayList(java.util.ArrayList) IOException(java.io.IOException)

Aggregations

FsEntry (org.jboss.galleon.diff.FsEntry)7 IOException (java.io.IOException)3 Path (java.nio.file.Path)3 BufferedReader (java.io.BufferedReader)1 BufferedWriter (java.io.BufferedWriter)1 ArrayList (java.util.ArrayList)1 ProvisioningConfig (org.jboss.galleon.config.ProvisioningConfig)1 FsDiff (org.jboss.galleon.diff.FsDiff)1 FsEntryFactory (org.jboss.galleon.diff.FsEntryFactory)1 ProvisioningRuntime (org.jboss.galleon.runtime.ProvisioningRuntime)1