fix repository create issue with directory structures

This commit is contained in:
Sebastian Sdorra
2011-11-24 22:09:58 +01:00
parent 7d8b46f1a9
commit 6e49c1ff19

View File

@@ -64,6 +64,9 @@ public abstract class AbstractSimpleRepositoryHandler<C extends SimpleRepository
/** Field description */
public static final String DIRECTORY_REPOSITORY = "repositories";
/** Field description */
public static final String DOT = ".";
/** the logger for AbstractSimpleRepositoryHandler */
private static final Logger logger =
LoggerFactory.getLogger(AbstractSimpleRepositoryHandler.class);
@@ -106,6 +109,7 @@ public abstract class AbstractSimpleRepositoryHandler<C extends SimpleRepository
throw new RepositoryAllreadyExistExeption();
}
checkPath(directory);
fileSystem.create(directory);
create(repository, directory);
postCreate(repository, directory);
@@ -308,6 +312,48 @@ public abstract class AbstractSimpleRepositoryHandler<C extends SimpleRepository
protected void postCreate(Repository repository, File directory)
throws IOException, RepositoryException {}
//~--- get methods ----------------------------------------------------------
/**
* Returns true if the directory is a repository.
*
*
* @param directory directory to check
*
* @return true if the directory is a repository
* @since 1.9
*/
protected boolean isRepository(File directory)
{
return new File(directory, DOT.concat(getType().getName())).exists();
}
//~--- methods --------------------------------------------------------------
/**
* Check path for existing repositories
*
*
* @param directory repository target directory
*
* @throws RepositoryAllreadyExistExeption
*/
private void checkPath(File directory) throws RepositoryAllreadyExistExeption
{
File repositoryDirectory = config.getRepositoryDirectory();
File parent = directory.getParentFile();
while ((parent != null) && ! repositoryDirectory.equals(parent))
{
if (isRepository(parent))
{
throw new RepositoryAllreadyExistExeption();
}
parent = parent.getParentFile();
}
}
//~--- fields ---------------------------------------------------------------
/** Field description */