Ejemplo n.º 1
0
 protected void validateDir(File dir) {
   if (!dir.exists()) {
     if (!dir.mkdirs()) {
       throw DeploymentRepositoryMessages.MESSAGES.cannotCreateDirectory(
           dir.getAbsolutePath());
     }
   } else if (!dir.isDirectory()) {
     throw DeploymentRepositoryMessages.MESSAGES.notADirectory(dir.getAbsolutePath());
   } else if (!dir.canWrite()) {
     throw DeploymentRepositoryMessages.MESSAGES.directoryNotWritable(dir.getAbsolutePath());
   }
 }
Ejemplo n.º 2
0
      protected ContentRepositoryImpl(final File repoRoot) {
        if (repoRoot == null) throw DeploymentRepositoryMessages.MESSAGES.nullVar("repoRoot");
        if (repoRoot.exists()) {
          if (!repoRoot.isDirectory()) {
            throw DeploymentRepositoryMessages.MESSAGES.notADirectory(repoRoot.getAbsolutePath());
          } else if (!repoRoot.canWrite()) {
            throw DeploymentRepositoryMessages.MESSAGES.directoryNotWritable(
                repoRoot.getAbsolutePath());
          }
        } else if (!repoRoot.mkdirs()) {
          throw DeploymentRepositoryMessages.MESSAGES.cannotCreateDirectory(
              repoRoot.getAbsolutePath());
        }
        this.repoRoot = repoRoot;

        try {
          this.messageDigest = MessageDigest.getInstance("SHA-1");
        } catch (NoSuchAlgorithmException e) {
          throw DeploymentRepositoryMessages.MESSAGES.cannotObtainSha1(
              e, MessageDigest.class.getSimpleName());
        }
      }
Ejemplo n.º 3
0
 protected File getDeploymentHashDir(final byte[] deploymentHash, final boolean validate) {
   final String sha1 = HashUtil.bytesToHexString(deploymentHash);
   final String partA = sha1.substring(0, 2);
   final String partB = sha1.substring(2);
   final File base = new File(getRepoRoot(), partA);
   if (validate) {
     validateDir(base);
   }
   final File hashDir = new File(base, partB);
   if (validate && !hashDir.exists() && !hashDir.mkdirs()) {
     throw DeploymentRepositoryMessages.MESSAGES.cannotCreateDirectory(
         hashDir.getAbsolutePath());
   }
   return hashDir;
 }
Ejemplo n.º 4
0
 @Override
 public VirtualFile getContent(byte[] hash) {
   if (hash == null) throw DeploymentRepositoryMessages.MESSAGES.nullVar("hash");
   return VFS.getChild(getDeploymentContentFile(hash, true).toURI());
 }