Index: java/org/apache/jackrabbit/core/RepositoryImpl.java =================================================================== --- java/org/apache/jackrabbit/core/RepositoryImpl.java (revision 279468) +++ java/org/apache/jackrabbit/core/RepositoryImpl.java (working copy) @@ -78,6 +78,11 @@ private static Logger log = Logger.getLogger(RepositoryImpl.class); /** + * repository home lock + */ + private static final String REPOSITORY_LOCK = ".lock"; + + /** * hardcoded uuid of the repository root node */ private static final String ROOT_NODE_UUID = "cafebabe-cafe-babe-cafe-babecafebabe"; @@ -144,8 +149,11 @@ * @param repConfig */ protected RepositoryImpl(RepositoryConfig repConfig) throws RepositoryException { + this.repConfig = repConfig; + this.acquireRepositoryLock() ; + // setup file systems repStore = repConfig.getFileSystem(); String fsRootPath = "/meta"; @@ -221,8 +229,39 @@ } }); } + + /** + * Lock the repository home. + * @throws RepositoryException + * if the repository lock can not be acquired + */ + private void acquireRepositoryLock() throws RepositoryException { + File home = new File(this.repConfig.getHomeDir()); + File lock = new File(home, REPOSITORY_LOCK) ; + if (lock.exists()) { + throw new RepositoryException("The repository home at " + home.getAbsolutePath() + + " appears to be in use. If you are sure it's not in use please delete the file at " + + lock.getAbsolutePath() + ". Probably the repository was not shutdown properly."); + } + try { + lock.createNewFile() ; + } catch (IOException e) { + throw new RepositoryException("Unable to create lock file at " + lock.getAbsolutePath()); + } + } /** + * Release repository lock + */ + private void releaseRepositoryLock() { + File home = new File(this.repConfig.getHomeDir()); + File lock = new File(home, REPOSITORY_LOCK) ; + if (!lock.delete()) { + log.error("Unable to release repository lock") ; + } + } + + /** * Returns the root node uuid. * @param fs * @return @@ -644,6 +683,7 @@ // there's nothing to do here because the repository has already been shut down return; } + this.releaseRepositoryLock() ; // close active user sessions for (Iterator it = activeSessions.values().iterator(); it.hasNext();) {