@ -47,15 +47,33 @@ import java.io.File;
import java.io.IOException ;
import java.io.IOException ;
import java.nio.file.Files ;
import java.nio.file.Files ;
import java.nio.file.LinkOption ;
import java.nio.file.LinkOption ;
import java.nio.file.NoSuchFileException ;
import java.nio.file.Path ;
import java.nio.file.Path ;
import java.nio.file.attribute.BasicFileAttributeView ;
import java.nio.file.attribute.BasicFileAttributes ;
import java.nio.file.attribute.FileTime ;
import java.nio.file.attribute.FileTime ;
import java.nio.file.attribute.PosixFileAttributeView ;
import java.nio.file.attribute.PosixFileAttributes ;
import java.nio.file.attribute.PosixFilePermission ;
import java.text.Normalizer ;
import java.text.Normalizer ;
import java.text.Normalizer.Form ;
import java.text.Normalizer.Form ;
import org.eclipse.jgit.lib.Constants ;
import org.eclipse.jgit.lib.Constants ;
import org.eclipse.jgit.util.FS.Attributes ;
class FileUtil {
class FileUtil {
static class Java7BasicAttributes extends Attributes {
Java7BasicAttributes ( FS fs , File fPath , boolean exists ,
boolean isDirectory , boolean isExecutable ,
boolean isSymbolicLink , boolean isRegularFile ,
long creationTime , long lastModifiedTime , long length ) {
super ( fs , fPath , exists , isDirectory , isExecutable , isSymbolicLink ,
isRegularFile , creationTime , lastModifiedTime , length ) ;
}
}
static String readSymlink ( File path ) throws IOException {
static String readSymlink ( File path ) throws IOException {
Path nioPath = path . toPath ( ) ;
Path nioPath = path . toPath ( ) ;
Path target = Files . readSymbolicLink ( nioPath ) ;
Path target = Files . readSymbolicLink ( nioPath ) ;
@ -145,4 +163,63 @@ class FileUtil {
Files . delete ( nioPath ) ;
Files . delete ( nioPath ) ;
}
}
static Attributes getFileAttributesBasic ( FS fs , File path ) {
try {
Path nioPath = path . toPath ( ) ;
BasicFileAttributes readAttributes = nioPath
. getFileSystem ( )
. provider ( )
. getFileAttributeView ( nioPath ,
BasicFileAttributeView . class ,
LinkOption . NOFOLLOW_LINKS ) . readAttributes ( ) ;
Attributes attributes = new FileUtil . Java7BasicAttributes ( fs , path ,
true ,
readAttributes . isDirectory ( ) ,
fs . supportsExecute ( ) ? path . canExecute ( ) : false ,
readAttributes . isSymbolicLink ( ) ,
readAttributes . isRegularFile ( ) , //
readAttributes . creationTime ( ) . toMillis ( ) , //
readAttributes . lastModifiedTime ( ) . toMillis ( ) ,
readAttributes . isSymbolicLink ( ) ? Constants
. encode ( FileUtils . readSymLink ( path ) ) . length
: readAttributes . size ( ) ) ;
return attributes ;
} catch ( NoSuchFileException e ) {
return new FileUtil . Java7BasicAttributes ( fs , path , false , false ,
false , false , false , 0L , 0L , 0L ) ;
} catch ( IOException e ) {
return new Attributes ( path , fs ) ;
}
}
static Attributes getFileAttributesPosix ( FS fs , File path ) {
try {
Path nioPath = path . toPath ( ) ;
PosixFileAttributes readAttributes = nioPath
. getFileSystem ( )
. provider ( )
. getFileAttributeView ( nioPath ,
PosixFileAttributeView . class ,
LinkOption . NOFOLLOW_LINKS ) . readAttributes ( ) ;
Attributes attributes = new FileUtil . Java7BasicAttributes (
fs ,
path ,
true , //
readAttributes . isDirectory ( ) , //
readAttributes . permissions ( ) . contains (
PosixFilePermission . OWNER_EXECUTE ) ,
readAttributes . isSymbolicLink ( ) ,
readAttributes . isRegularFile ( ) , //
readAttributes . creationTime ( ) . toMillis ( ) , //
readAttributes . lastModifiedTime ( ) . toMillis ( ) ,
readAttributes . size ( ) ) ;
return attributes ;
} catch ( NoSuchFileException e ) {
return new FileUtil . Java7BasicAttributes ( fs , path , false , false ,
false , false , false , 0L , 0L , 0L ) ;
} catch ( IOException e ) {
return new Attributes ( path , fs ) ;
}
}
}
}