protected Path getDeploymentContentFile(byte[] deploymentHash) { return getDeploymentContentFile(deploymentHash, false); }
@Override public boolean hasContent(byte[] hash) { return Files.exists(getDeploymentContentFile(hash)); }
private void unlock(byte[] hash) { String hashHex = HashUtil.bytesToHexString(hash); synchronized (lockedContents) { if (lockedContents.containsKey(hashHex)) { ReentrantLock lock = lockedContents.get(hashHex); if (lock.isHeldByCurrentThread()) { lock.unlock(); if (!Files.exists(getDeploymentContentFile(hash))) { lockedContents.remove(hashHex); } } } } }
@Override public VirtualFile getContent(byte[] hash) { Assert.checkNotNullParam("hash", hash); return VFS.getChild(getDeploymentContentFile(hash, true).toUri()); }
@Override public void copyExplodedContent(byte[] deploymentHash, final Path target) throws ExplodedContentException { final Path contentPath = getDeploymentContentFile(deploymentHash); try { if (Files.exists(contentPath) && Files.isDirectory(contentPath)) { copyRecursively(contentPath, target, false); } } catch (IOException ioex) { DeploymentRepositoryLogger.ROOT_LOGGER.warn(ioex); throw DeploymentRepositoryLogger.ROOT_LOGGER.errorCopyingDeployment(ioex, target.toString()); } }
@Override public void copyExplodedContentFiles(byte[] deploymentHash, List<String> relativePaths, Path target) throws ExplodedContentException { final Path contentPath = getDeploymentContentFile(deploymentHash); try { if (Files.exists(contentPath) && Files.isDirectory(contentPath)) { for (String relativePath : relativePaths) { copyRecursively(resolveSecurely(contentPath, relativePath), resolveSecurely(target, relativePath), true); } } } catch (IOException ioex) { DeploymentRepositoryLogger.ROOT_LOGGER.warn(ioex); throw DeploymentRepositoryLogger.ROOT_LOGGER.errorCopyingDeployment(ioex, target.toString()); } }
final Path realFile = getDeploymentContentFile(sha1Bytes, true); if (hasContent(sha1Bytes)) {
@Override public byte[] explodeContent(byte[] deploymentHash) throws ExplodedContentException { Path contentPath = getDeploymentContentFile(deploymentHash); if (!Files.exists(contentPath)) { throw DeploymentRepositoryLogger.ROOT_LOGGER.archiveNotFound(contentPath.toString()); unzip(contentPath, contentDir); byte[] sha1Bytes = HashUtil.hashPath(messageDigest, contentDir); final Path realFile = getDeploymentContentFile(sha1Bytes, true); if (hasContent(sha1Bytes)) {
@Override public byte[] removeContentFromExploded(byte[] deploymentHash, List<String> paths) throws ExplodedContentException { Path contentPath = getDeploymentContentFile(deploymentHash); try { if (Files.exists(contentPath) && Files.isDirectory(contentPath) && this.readWrite) { final Path realFile = getDeploymentContentFile(sha1Bytes, true); if (hasContent(sha1Bytes)) {
@Override public TypedInputStream readContent(byte[] deploymentHash, String path) throws ExplodedContentException { Path tmpDir = null; try { if(!lock(deploymentHash)) { throw DeploymentRepositoryLogger.ROOT_LOGGER.errorLockingDeployment(); } Path src = resolveSecurely(getDeploymentContentFile(deploymentHash), path); tmpDir = Files.createTempDirectory(tmpRoot.toPath(), HashUtil.bytesToHexString(deploymentHash)); Path file = PathUtil.readFile(src, tmpDir); Path tmp = Files.createTempFile(tmpRoot.toPath(), CONTENT, getFileExtension(src)); Files.copy(file, tmp, StandardCopyOption.COPY_ATTRIBUTES, StandardCopyOption.REPLACE_EXISTING); return new TemporaryFileInputStream(tmp); } catch (InterruptedException ex) { Thread.currentThread().interrupt(); throw new RuntimeException(ex); } catch (IOException ex) { DeploymentRepositoryLogger.ROOT_LOGGER.warn(ex); throw DeploymentRepositoryLogger.ROOT_LOGGER.errorAccessingDeployment(ex); } finally { unlock(deploymentHash); deleteSilentlyRecursively(tmpDir); } }
@Override public byte[] addContentToExploded(byte[] deploymentHash, List<ExplodedContent> addFiles, boolean overwrite) throws ExplodedContentException { Path contentPath = getDeploymentContentFile(deploymentHash); try { if (Files.exists(contentPath) && Files.isDirectory(contentPath) && this.readWrite) { final Path realFile = getDeploymentContentFile(sha1Bytes, true); if (hasContent(sha1Bytes)) {
@Override public List<ContentRepositoryElement> listContent(byte[] deploymentHash, String path, ContentFilter filter) throws ExplodedContentException { Path tmpDir = null; try { if (!lock(deploymentHash)) { throw DeploymentRepositoryLogger.ROOT_LOGGER.errorLockingDeployment(); } tmpDir = Files.createTempDirectory(tmpRoot.toPath(), HashUtil.bytesToHexString(deploymentHash)); final Path rootPath = resolveSecurely(getDeploymentContentFile(deploymentHash), path); List<ContentRepositoryElement> result = PathUtil.listFiles(rootPath, tmpDir, filter); return result; } catch (InterruptedException ex) { Thread.currentThread().interrupt(); throw new RuntimeException(ex); } catch (IOException ex) { DeploymentRepositoryLogger.ROOT_LOGGER.warn(ex); throw DeploymentRepositoryLogger.ROOT_LOGGER.errorAccessingDeployment(ex); } finally { unlock(deploymentHash); if(tmpDir != null) { deleteSilentlyRecursively(tmpDir); } } }
@Override public byte[] explodeSubContent(byte[] deploymentHash, String relativePath) throws ExplodedContentException { Path contentPath = getDeploymentContentFile(deploymentHash); Path sourcePath = resolveSecurely(contentPath, relativePath); try { final Path realFile = getDeploymentContentFile(sha1Bytes, true); if (hasContent(sha1Bytes)) {
contentPath = Paths.get(reference.getContentIdentifier()); } else { contentPath = getDeploymentContentFile(reference.getHash(), false);