private void copyDirectory( final JGitPathImpl source, final JGitPathImpl target, final CopyOption... options ) { final List<JGitPathImpl> directories = new ArrayList<JGitPathImpl>(); for ( final Path path : newDirectoryStream( source, null ) ) { final JGitPathImpl gPath = toPathImpl( path ); final Pair<PathType, ObjectId> pathResult = checkPath( gPath.getFileSystem().gitRepo(), gPath.getRefTree(), gPath.getPath() ); if ( pathResult.getK1() == DIRECTORY ) { directories.add( gPath ); continue; } final JGitPathImpl gTarget = composePath( target, (JGitPathImpl) gPath.getFileName() ); copyFile( gPath, gTarget ); } for ( final JGitPathImpl directory : directories ) { createDirectory( composePath( target, (JGitPathImpl) directory.getFileName() ) ); } }
PROVIDER.createDirectory( dir1 );
PROVIDER.createDirectory( crazyPath );
@Test public void testCreateDirectory() throws Exception { final URI newRepo = URI.create( "git://xcreatedir-test-repo" ); PROVIDER.newFileSystem( newRepo, EMPTY_ENV ); final JGitPathImpl path = (JGitPathImpl) PROVIDER.getPath( URI.create( "git://master@xcreatedir-test-repo/some/path/to/" ) ); final Pair<PathType, ObjectId> result = JGitUtil.checkPath( path.getFileSystem().gitRepo(), path.getRefTree(), path.getPath() ); assertThat( result.getK1() ).isEqualTo( PathType.NOT_FOUND ); PROVIDER.createDirectory( path ); final Pair<PathType, ObjectId> resultAfter = JGitUtil.checkPath( path.getFileSystem().gitRepo(), path.getRefTree(), path.getPath() ); assertThat( resultAfter.getK1() ).isEqualTo( PathType.DIRECTORY ); try { PROVIDER.createDirectory( path ); failBecauseExceptionWasNotThrown( FileAlreadyExistsException.class ); } catch ( FileAlreadyExistsException e ) { } }