@Override public VersionAttributes readAttributes() throws IOException { if ( attrs == null ) { attrs = JGitUtil.buildVersionAttributes( path.getFileSystem(), path.getRefTree(), path.getPath() ); } return attrs; }
public static JGitPathImpl createRoot( final JGitFileSystem fs, final String path, final String host, boolean isRealPath ) { return new JGitPathImpl( fs, setupPath( path ), setupHost( host ), null, true, isRealPath, true ); }
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; }
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; }
@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; }
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() ) ); } }
private void createBranch( final JGitPathImpl source, final JGitPathImpl target ) { JGitUtil.createBranch( source.getFileSystem().gitRepo(), source.getRefTree(), target.getRefTree() ); }
@Override public Path getPath( final String first, final String... more ) throws InvalidPathException { checkClose(); if ( first == null || first.trim().isEmpty() ) { return new JGitFSPath( this ); } if ( more == null || more.length == 0 ) { return JGitPathImpl.create( this, first, JGitPathImpl.DEFAULT_REF_TREE + "@" + name, false ); } final StringBuilder sb = new StringBuilder(); for ( final String segment : more ) { if ( segment.length() > 0 ) { if ( sb.length() > 0 ) { sb.append( getSeparator() ); } sb.append( segment ); } } return JGitPathImpl.create( this, sb.toString(), first + "@" + name, false ); }
public void deleteBranch( final JGitPathImpl path ) { final Ref branch = getBranch( path.getFileSystem().gitRepo(), path.getRefTree() ); if ( branch == null ) { throw new NoSuchFileException( path.toString() ); } JGitUtil.deleteBranch( path.getFileSystem().gitRepo(), branch ); }
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 File toFile() throws UnsupportedOperationException { if ( file == null ) { synchronized ( this ) { if ( isRegularFile() ) { try { file = File.createTempFile( "git", "temp" ); final InputStream in = getFileSystem().provider().newInputStream( this ); final OutputStream out = new FileOutputStream( file ); internalCopy( in, out ); in.close(); out.close(); } catch ( final Exception ex ) { file = null; } } else { throw new UnsupportedOperationException(); } } } return file; }
private boolean hasSameFileSystem( final JGitPathImpl source, final JGitPathImpl target ) { return source.getFileSystem().equals( target ); }
final Path root = JGitPathImpl.createRoot( fs, "/", host, false ); final Path oldPath; if ( !diffEntry.getOldPath().equals( DiffEntry.DEV_NULL ) ) { oldPath = JGitPathImpl.create( fs, "/" + diffEntry.getOldPath(), host, null, false ); } else { oldPath = null; if ( !diffEntry.getNewPath().equals( DiffEntry.DEV_NULL ) ) { JGitPathInfo pathInfo = resolvePath( fs.gitRepo(), tree, diffEntry.getNewPath() ); newPath = JGitPathImpl.create( fs, "/" + pathInfo.getPath(), host, pathInfo.getObjectId(), false ); } else { newPath = null;
@Override public String getSegmentId() { return getRefTree(); } }
@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( "." ); }
@Override protected Path newPath( final JGitFileSystem fs, final String substring, final String host, final boolean isRealPath, final boolean isNormalized ) { return new JGitPathImpl( fs, substring, host, null, false, isRealPath, isNormalized ); }
private void copyAsset( final JGitPathImpl source, final JGitPathImpl target, final CopyOption... options ) { final Pair<PathType, ObjectId> sourceResult = checkPath( source.getFileSystem().gitRepo(), source.getRefTree(), source.getPath() ); final Pair<PathType, ObjectId> targetResult = checkPath( target.getFileSystem().gitRepo(), target.getRefTree(), target.getPath() ); if ( !isRoot( target ) && targetResult.getK1() != NOT_FOUND ) { if ( !contains( options, StandardCopyOption.REPLACE_EXISTING ) ) { throw new FileAlreadyExistsException( target.toString() ); } } if ( sourceResult.getK1() == NOT_FOUND ) { throw new NoSuchFileException( target.toString() ); } if ( sourceResult.getK1() == DIRECTORY ) { copyDirectory( source, target, options ); return; } copyFile( source, target, options ); }
private boolean existsBranch( final JGitPathImpl path ) { return hasBranch( path.getFileSystem().gitRepo(), path.getRefTree() ); }
@Override public Path getPath( final URI uri ) throws IllegalArgumentException, FileSystemNotFoundException, SecurityException { checkNotNull( "uri", uri ); checkCondition( "uri scheme not supported", uri.getScheme().equals( getScheme() ) || uri.getScheme().equals( "default" ) ); checkURI( "uri", uri ); final JGitFileSystem fileSystem = fileSystems.get( extractRepoName( uri ) ); if ( fileSystem == null ) { throw new FileSystemNotFoundException(); } try { return JGitPathImpl.create( fileSystem, URIUtil.decode( extractPath( uri ) ), extractHost( uri ), false ); } catch ( final URIException e ) { return null; } }