private ExtendedAttributeView getFileAttributeView( final JGitPathImpl path, final String name, final LinkOption... options ) { final ExtendedAttributeView view = path.getAttrView( name ); if ( view == null && ( name.equals( "basic" ) || name.equals( "version" ) ) ) { final JGitVersionAttributeView newView = new JGitVersionAttributeView( path ); path.addAttrView( newView ); return newView; } return view; }
@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; }
assertThat( attrs.readAttributes().history().records().size() ).isEqualTo( 1 ); assertThat( attrs.readAttributes().history().records().get( 0 ).uri() ).isNotNull(); assertThat( attrs.readAttributes().isDirectory() ).isFalse(); assertThat( attrs.readAttributes().isRegularFile() ).isTrue(); assertThat( attrs.readAttributes().creationTime() ).isNotNull(); assertThat( attrs.readAttributes().lastModifiedTime() ).isNotNull(); assertThat( attrs.readAttributes().size() ).isEqualTo( 15L );
@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; }