private void onSyncPackageJson(Config conf, Path workDirectory, Throwing.Consumer<String> action) throws IOException { Path tmp = Paths.get(conf.getString("application.tmpdir"), "package.json"); Files.createDirectories(tmp); String sha1 = Hashing.sha256() .hashBytes(Files.readAllBytes(workDirectory.resolve("package.json"))) .toString(); Path lastSha1 = tmp.resolve(sha1); if (!Files.exists(lastSha1) || !Files.exists(workDirectory.resolve("node_modules"))) { action.accept("install"); Try.of(Files.walk(tmp)) .run(files -> files.filter(f -> !f.equals(tmp)).forEach(throwingConsumer(Files::deleteIfExists))); Files.write(tmp.resolve(lastSha1), Arrays.asList("")); } }
@Override public void close() throws Exception { try { Optional.ofNullable(resource) .ifPresent(Throwing.throwingConsumer(AutoCloseable::close)); } finally { if (parent instanceof ProxyCloseable) { ((ProxyCloseable) parent).close(); } else { Optional.ofNullable(parentResource) .ifPresent(Throwing.throwingConsumer(AutoCloseable::close)); } } }