List of usage examples for org.eclipse.jgit.dircache DirCache lock
public boolean lock() throws IOException
From source file:ezbake.deployer.publishers.openShift.RhcApplication.java
License:Apache License
public void addStreamAsFile(File p, InputStream ios, Set<PosixFilePermission> filePermissions) throws DeploymentException { File resolvedPath = Files.resolve(getGitRepoPath(), p); if (Files.isDirectory(resolvedPath)) { throw new DeploymentException( "Directory exist by the name of file wishing to write to: " + resolvedPath.toString()); }/* ww w .ja v a2 s . c o m*/ try { Files.createDirectories(resolvedPath.getParent()); OutputStream oos = new FileOutputStream(resolvedPath); boolean permissions = (filePermissions != null && !filePermissions.isEmpty()); DirCache cache = null; try { IOUtils.copy(ios, oos); if (permissions) { Files.setPosixFilePermissions(resolvedPath, filePermissions); } cache = gitRepo.add().addFilepattern(p.toString()).call(); if (permissions) { // Add executable permissions cache.lock(); // Most of these mthods throw an IOException so we will catch that and unlock DirCacheEntry entry = cache.getEntry(0); log.debug("Setting executable permissions for: " + entry.getPathString()); entry.setFileMode(FileMode.EXECUTABLE_FILE); cache.write(); cache.commit(); } } catch (IOException e) { log.error("[" + getApplicationName() + "]" + "Error writing to file: " + resolvedPath.toString(), e); // Most of the DirCache entries should just thow IOExceptions if (cache != null) { cache.unlock(); } throw new DeploymentException("Error writing to file: " + resolvedPath.toString()); } catch (GitAPIException e) { log.error("[" + getApplicationName() + "]" + "Error writing to file: " + resolvedPath.toString(), e); throw new DeploymentException("Error writing to file: " + resolvedPath.toString()); } finally { IOUtils.closeQuietly(oos); } } catch (IOException e) { log.error( "[" + getApplicationName() + "]" + "Error opening file for output: " + resolvedPath.toString(), e); throw new DeploymentException("Error opening file for output: " + resolvedPath.toString()); } }
From source file:org.jboss.arquillian.container.openshift.express.util.GitUtil.java
License:Apache License
private void updateCache(DirCache cache) throws IOException { if (!cache.lock()) { throw new IllegalStateException("Unable to lock Git repository cache"); }/*www .j a v a 2 s. c om*/ cache.write(); if (!cache.commit()) { throw new IllegalStateException("Unable to commit Git repository cache"); } }