@Override public boolean isHidden( final Path path ) throws IllegalArgumentException, IOException, SecurityException { checkNotNull( "path", path ); final JGitPathImpl gPath = toPathImpl( path ); if ( gPath.getFileName() == null ) { return false; } return toPathImpl( path.getFileName() ).toString( false ).startsWith( "." ); }
private JGitPathImpl composePath( final JGitPathImpl directory, final JGitPathImpl fileName, final CopyOption... options ) { if ( directory.getPath().endsWith( "/" ) ) { return toPathImpl( getPath( URI.create( directory.toUri().toString() + fileName.toString( false ) ) ) ); } return toPathImpl( getPath( URI.create( directory.toUri().toString() + "/" + fileName.toString( false ) ) ) ); }
@Override public Map<String, Object> readAttributes( final Path path, final String attributes, final LinkOption... options ) throws UnsupportedOperationException, IllegalArgumentException, IOException, SecurityException { checkNotNull( "path", path ); checkNotEmpty( "attributes", attributes ); final String[] s = split( attributes ); if ( s[ 0 ].length() == 0 ) { throw new IllegalArgumentException( attributes ); } final ExtendedAttributeView view = getFileAttributeView( toPathImpl( path ), s[ 0 ], options ); if ( view == null ) { throw new UnsupportedOperationException( "View '" + s[ 0 ] + "' not available" ); } return view.readAttributes( s[ 1 ].split( "," ) ); }
@Override public void copy( final Path source, final Path target, final CopyOption... options ) throws UnsupportedOperationException, FileAlreadyExistsException, DirectoryNotEmptyException, IOException, SecurityException { checkNotNull( "source", source ); checkNotNull( "target", target ); final JGitPathImpl gSource = toPathImpl( source ); final JGitPathImpl gTarget = toPathImpl( target ); final boolean isSourceBranch = isBranch( gSource ); final boolean isTargetBranch = isBranch( gTarget ); if ( isSourceBranch && isTargetBranch ) { copyBranch( gSource, gTarget ); return; } copyAsset( gSource, gTarget, options ); }
@Override public void setAttribute( final Path path, final String attribute, final Object value, final LinkOption... options ) throws UnsupportedOperationException, IllegalArgumentException, ClassCastException, IOException, SecurityException { checkNotNull( "path", path ); checkNotEmpty( "attributes", attribute ); if ( attribute.equals( FileSystemState.FILE_SYSTEM_STATE_ATTR ) ) { try { state = FileSystemState.valueOf( value.toString() ); FileSystemState.valueOf( value.toString() ); } catch ( final Exception ex ) { state = FileSystemState.NORMAL; } hadCommitOnBatchState = false; return; } final String[] s = split( attribute ); if ( s[ 0 ].length() == 0 ) { throw new IllegalArgumentException( attribute ); } final ExtendedAttributeView view = getFileAttributeView( toPathImpl( path ), s[ 0 ], options ); if ( view == null ) { throw new UnsupportedOperationException( "View '" + s[ 0 ] + "' not available" ); } view.setAttribute( s[ 1 ], value ); }
@Override public FileStore getFileStore( final Path path ) throws IOException, SecurityException { checkNotNull( "path", path ); return new JGitFileStore( toPathImpl( path ).getFileSystem().gitRepo().getRepository() ); }
@Override public void createDirectory( final Path path, final FileAttribute<?>... attrs ) throws UnsupportedOperationException, FileAlreadyExistsException, IOException, SecurityException { checkNotNull( "path", path ); final JGitPathImpl gPath = toPathImpl( path ); final Pair<PathType, ObjectId> result = checkPath( gPath.getFileSystem().gitRepo(), gPath.getRefTree(), gPath.getPath() ); if ( !result.getK1().equals( NOT_FOUND ) ) { throw new FileAlreadyExistsException( path.toString() ); } try { final OutputStream outputStream = newOutputStream( path.resolve( ".gitignore" ) ); outputStream.write( "# empty\n".getBytes() ); outputStream.close(); } catch ( final Exception e ) { throw new IOException( e ); } }
@Override public InputStream newInputStream( final Path path, final OpenOption... options ) throws IllegalArgumentException, UnsupportedOperationException, NoSuchFileException, IOException, SecurityException { checkNotNull( "path", path ); final JGitPathImpl gPath = toPathImpl( path ); return resolveInputStream( gPath.getFileSystem().gitRepo(), gPath.getRefTree(), gPath.getPath() ); }
@Override public void checkAccess( final Path path, final AccessMode... modes ) throws UnsupportedOperationException, NoSuchFileException, AccessDeniedException, IOException, SecurityException { checkNotNull( "path", path ); final JGitPathImpl gPath = toPathImpl( path ); final Pair<PathType, ObjectId> result = checkPath( gPath.getFileSystem().gitRepo(), gPath.getRefTree(), gPath.getPath() ); if ( result.getK1().equals( NOT_FOUND ) ) { throw new NoSuchFileException( path.toString() ); } }
@Override public boolean deleteIfExists( final Path path, final DeleteOption... options ) throws DirectoryNotEmptyException, IOException, SecurityException { checkNotNull( "path", path ); if ( path instanceof JGitFSPath ) { return deleteRepo( path.getFileSystem() ); } final JGitPathImpl gPath = toPathImpl( path ); if ( isBranch( gPath ) ) { return deleteBranchIfExists( gPath ); } return deleteAssetIfExists( gPath, options ); }
final FileAttribute<?>... attrs ) throws IllegalArgumentException, UnsupportedOperationException, FileAlreadyExistsException, IOException, SecurityException { final JGitPathImpl gPath = toPathImpl( path );
@Override public void delete( final Path path, final DeleteOption... options ) throws DirectoryNotEmptyException, NoSuchFileException, IOException, SecurityException { checkNotNull( "path", path ); if ( path instanceof JGitFSPath ) { deleteRepo( path.getFileSystem() ); return; } final JGitPathImpl gPath = toPathImpl( path ); if ( isBranch( gPath ) ) { deleteBranch( gPath ); return; } deleteAsset( gPath, options ); }
@Override public boolean isSameFile( final Path pathA, final Path pathB ) throws IOException, SecurityException { checkNotNull( "pathA", pathA ); checkNotNull( "pathB", pathB ); final JGitPathImpl gPathA = toPathImpl( pathA ); final JGitPathImpl gPathB = toPathImpl( pathB ); final Pair<PathType, ObjectId> resultA = checkPath( gPathA.getFileSystem().gitRepo(), gPathA.getRefTree(), gPathA.getPath() ); final Pair<PathType, ObjectId> resultB = checkPath( gPathB.getFileSystem().gitRepo(), gPathB.getRefTree(), gPathB.getPath() ); if ( resultA.getK1() == PathType.FILE && resultA.getK2().equals( resultB.getK2() ) ) { return true; } return pathA.equals( pathB ); }
checkNotNull( "path", path ); final JGitPathImpl gPath = toPathImpl( path );
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() ) ); } }
@Override public <A extends BasicFileAttributes> A readAttributes( final Path path, final Class<A> type, final LinkOption... options ) throws NoSuchFileException, UnsupportedOperationException, IOException, SecurityException { checkNotNull( "path", path ); checkNotNull( "type", type ); final JGitPathImpl gPath = toPathImpl( path ); final Pair<PathType, ObjectId> pathResult = checkPath( gPath.getFileSystem().gitRepo(), gPath.getRefTree(), gPath.getPath() ); if ( pathResult.getK1().equals( NOT_FOUND ) ) { throw new NoSuchFileException( path.toString() ); } if ( type == BasicFileAttributesImpl.class || type == BasicFileAttributes.class || type == VersionAttributes.class ) { final JGitVersionAttributeView view = getFileAttributeView( path, JGitVersionAttributeView.class, options ); return (A) view.readAttributes(); } return null; }
@Override public <V extends FileAttributeView> V getFileAttributeView( final Path path, final Class<V> type, final LinkOption... options ) throws NoSuchFileException { checkNotNull( "path", path ); checkNotNull( "type", type ); final JGitPathImpl gPath = toPathImpl( path ); final Pair<PathType, ObjectId> pathResult = checkPath( gPath.getFileSystem().gitRepo(), gPath.getRefTree(), gPath.getPath() ); if ( pathResult.getK1().equals( NOT_FOUND ) ) { throw new NoSuchFileException( path.toString() ); } final V resultView = gPath.getAttrView( type ); if ( resultView == null && ( type == BasicFileAttributeView.class || type == VersionAttributeView.class || type == JGitVersionAttributeView.class ) ) { final V newView = (V) new JGitVersionAttributeView( gPath ); gPath.addAttrView( newView ); return newView; } return resultView; }
final JGitPathImpl gPath = toPathImpl( path );