diff options
Diffstat (limited to 'org.eclipse.jgit.java7')
4 files changed, 101 insertions, 2 deletions
diff --git a/org.eclipse.jgit.java7/src/org/eclipse/jgit/util/FS_POSIX_Java7.java b/org.eclipse.jgit.java7/src/org/eclipse/jgit/util/FS_POSIX_Java7.java index 6a98481797..e8307fc2b0 100644 --- a/org.eclipse.jgit.java7/src/org/eclipse/jgit/util/FS_POSIX_Java7.java +++ b/org.eclipse.jgit.java7/src/org/eclipse/jgit/util/FS_POSIX_Java7.java @@ -46,8 +46,6 @@ package org.eclipse.jgit.util; import java.io.File; import java.io.IOException; -import org.eclipse.jgit.util.FS; - /** * FS implementation for Java7 on unix like systems */ @@ -150,4 +148,12 @@ public class FS_POSIX_Java7 extends FS_POSIX { public void createSymLink(File path, String target) throws IOException { FileUtil.createSymLink(path, target); } + + /** + * @since 3.3 + */ + @Override + public Attributes getAttributes(File path) { + return FileUtil.getFileAttributesPosix(this, path); + } } diff --git a/org.eclipse.jgit.java7/src/org/eclipse/jgit/util/FS_Win32_Java7.java b/org.eclipse.jgit.java7/src/org/eclipse/jgit/util/FS_Win32_Java7.java index 5551632228..4a9d5f0bb7 100644 --- a/org.eclipse.jgit.java7/src/org/eclipse/jgit/util/FS_Win32_Java7.java +++ b/org.eclipse.jgit.java7/src/org/eclipse/jgit/util/FS_Win32_Java7.java @@ -151,4 +151,12 @@ public class FS_Win32_Java7 extends FS_Win32 { public void createSymLink(File path, String target) throws IOException { FileUtil.createSymLink(path, target); } + + /** + * @since 3.3 + */ + @Override + public Attributes getAttributes(File path) { + return FileUtil.getFileAttributesBasic(this, path); + } } diff --git a/org.eclipse.jgit.java7/src/org/eclipse/jgit/util/FS_Win32_Java7Cygwin.java b/org.eclipse.jgit.java7/src/org/eclipse/jgit/util/FS_Win32_Java7Cygwin.java index 3db2e53e42..e40d7cf0b5 100644 --- a/org.eclipse.jgit.java7/src/org/eclipse/jgit/util/FS_Win32_Java7Cygwin.java +++ b/org.eclipse.jgit.java7/src/org/eclipse/jgit/util/FS_Win32_Java7Cygwin.java @@ -127,4 +127,12 @@ public class FS_Win32_Java7Cygwin extends FS_Win32_Cygwin { public void createSymLink(File path, String target) throws IOException { FileUtil.createSymLink(path, target); } + + /** + * @since 3.3 + */ + @Override + public Attributes getAttributes(File path) { + return FileUtil.getFileAttributesBasic(this, path); + } } diff --git a/org.eclipse.jgit.java7/src/org/eclipse/jgit/util/FileUtil.java b/org.eclipse.jgit.java7/src/org/eclipse/jgit/util/FileUtil.java index 0fd19bcdd1..78dc2c3934 100644 --- a/org.eclipse.jgit.java7/src/org/eclipse/jgit/util/FileUtil.java +++ b/org.eclipse.jgit.java7/src/org/eclipse/jgit/util/FileUtil.java @@ -47,15 +47,33 @@ import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.nio.file.LinkOption; +import java.nio.file.NoSuchFileException; 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.PosixFileAttributeView; +import java.nio.file.attribute.PosixFileAttributes; +import java.nio.file.attribute.PosixFilePermission; import java.text.Normalizer; import java.text.Normalizer.Form; import org.eclipse.jgit.lib.Constants; +import org.eclipse.jgit.util.FS.Attributes; 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 { Path nioPath = path.toPath(); Path target = Files.readSymbolicLink(nioPath); @@ -145,4 +163,63 @@ class FileUtil { 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); + } + } + } |