mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-02-06 22:59:12 +01:00
fix repository create issue with directory structures
This commit is contained in:
@@ -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 */
|
||||
|
||||
Reference in New Issue
Block a user