@Override public void move( final Path source, final Path target, final CopyOption... options ) throws DirectoryNotEmptyException, AtomicMoveNotSupportedException, IOException, SecurityException { checkNotNull( "source", source ); checkNotNull( "target", target ); try { copy( source, target, options ); delete( source ); } catch ( final Exception ex ) { throw new IOException( ex ); } }
public void deleteAsset( final JGitPathImpl path, final DeleteOption... options ) { final Pair<PathType, ObjectId> result = checkPath( path.getFileSystem().gitRepo(), path.getRefTree(), path.getPath() ); if ( result.getK1().equals( PathType.DIRECTORY ) ) { if ( deleteNonEmptyDirectory( options ) ) { deleteResource( path, options ); return; } final List<JGitPathInfo> content = listPathContent( path.getFileSystem().gitRepo(), path.getRefTree(), path.getPath() ); if ( content.size() == 1 && content.get( 0 ).getPath().equals( path.getPath().substring( 1 ) + "/.gitignore" ) ) { delete( path.resolve( ".gitignore" ) ); deleteResource( path, options ); return; } throw new DirectoryNotEmptyException( path.toString() ); } if ( result.getK1().equals( NOT_FOUND ) ) { throw new NoSuchFileException( path.toString() ); } deleteResource( path, options ); }
public boolean deleteAssetIfExists( final JGitPathImpl path, final DeleteOption... options ) { final Pair<PathType, ObjectId> result = checkPath( path.getFileSystem().gitRepo(), path.getRefTree(), path.getPath() ); if ( result.getK1().equals( PathType.DIRECTORY ) ) { if ( deleteNonEmptyDirectory( options ) ) { deleteResource( path, options ); return true; } final List<JGitPathInfo> content = listPathContent( path.getFileSystem().gitRepo(), path.getRefTree(), path.getPath() ); if ( content.size() == 1 && content.get( 0 ).getPath().equals( path.getPath().substring( 1 ) + "/.gitignore" ) ) { delete( path.resolve( ".gitignore" ) ); return true; } throw new DirectoryNotEmptyException( path.toString() ); } if ( result.getK1().equals( NOT_FOUND ) ) { return false; } deleteResource( path, options ); return true; }
@Test public void testDeleteBranch() throws IOException { final URI newRepo = URI.create( "git://delete-branch-test-repo" ); PROVIDER.newFileSystem( newRepo, EMPTY_ENV ); final Path path = PROVIDER.getPath( URI.create( "git://user_branch@delete-branch-test-repo/path/to/myfile.txt" ) ); final OutputStream outStream = PROVIDER.newOutputStream( path ); assertThat( outStream ).isNotNull(); outStream.write( "my cool content".getBytes() ); outStream.close(); PROVIDER.newInputStream( path ).close(); PROVIDER.delete( PROVIDER.getPath( URI.create( "git://user_branch@delete-branch-test-repo" ) ) ); try { PROVIDER.delete( PROVIDER.getPath( URI.create( "git://user_branch@delete-branch-test-repo" ) ) ); failBecauseExceptionWasNotThrown( NoSuchFileException.class ); } catch ( NoSuchFileException ex ) { } try { PROVIDER.delete( PROVIDER.getPath( URI.create( "git://some_user_branch@delete-branch-test-repo" ) ) ); failBecauseExceptionWasNotThrown( NoSuchFileException.class ); } catch ( NoSuchFileException ex ) { } }
PROVIDER.delete( PROVIDER.getPath( URI.create( "git://user_branch@delete1-test-repo/non_existent_path" ) ) ); failBecauseExceptionWasNotThrown( NoSuchFileException.class ); } catch ( NoSuchFileException ex ) { PROVIDER.delete( PROVIDER.getPath( URI.create( "git://user_branch@delete1-test-repo/path/to/" ) ) ); failBecauseExceptionWasNotThrown( DirectoryNotEmptyException.class ); } catch ( DirectoryNotEmptyException ex ) { PROVIDER.delete( path ); PROVIDER.delete( fsPath ); assertThat( fsPath.getFileSystem().isOpen() ).isEqualTo( false );
PROVIDER.delete( dir ); fail( "dir not empty" ); } catch ( final DirectoryNotEmptyException ignore ) { final CommentedOption op = new CommentedOption( "User Tester", "user.tester@example.com", "omg, erase dir!" ); PROVIDER.delete( dir, NON_EMPTY_DIRECTORIES, op ); } catch ( final DirectoryNotEmptyException ignore ) { fail( "dir should be deleted!" );