Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobin Rosenberg2012-12-26 22:37:07 +0000
committerMatthias Sohn2014-02-28 10:41:50 +0000
commitdafe9ae5ed3da3fe87d5a48707b769959f875f0d (patch)
tree344e197b663f3f1bf454ffd8dfd40b01f0fb163c
parent4700835fb6161aa78ef3b9355bdcf5a492de4068 (diff)
downloadegit-dafe9ae5ed3da3fe87d5a48707b769959f875f0d.tar.gz
egit-dafe9ae5ed3da3fe87d5a48707b769959f875f0d.tar.xz
egit-dafe9ae5ed3da3fe87d5a48707b769959f875f0d.zip
Make the ContainerTreeIterator recognize symbolic links
We cannot rely on Eclipse's resource handling here since it looks at the link target rather than the link itself. Change-Id: I94bfd493805478f2a232229ce6d25a0d810bfd0f Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
-rw-r--r--org.eclipse.egit.core/src/org/eclipse/egit/core/ContainerTreeIterator.java92
1 files changed, 60 insertions, 32 deletions
diff --git a/org.eclipse.egit.core/src/org/eclipse/egit/core/ContainerTreeIterator.java b/org.eclipse.egit.core/src/org/eclipse/egit/core/ContainerTreeIterator.java
index 13056b3f95..377db469f3 100644
--- a/org.eclipse.egit.core/src/org/eclipse/egit/core/ContainerTreeIterator.java
+++ b/org.eclipse.egit.core/src/org/eclipse/egit/core/ContainerTreeIterator.java
@@ -9,6 +9,7 @@
package org.eclipse.egit.core;
+import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
@@ -288,28 +289,39 @@ public class ContainerTreeIterator extends WorkingTreeIterator {
rsrc = f;
this.hasInheritedResourceFilters = hasInheritedResourceFilters;
- switch (f.getType()) {
- case IResource.FILE:
+ FileMode mode = null;
+ try {
File file = asFile();
- if (FS.DETECTED.supportsExecute() && file != null
- && FS.DETECTED.canExecute(file))
- mode = FileMode.EXECUTABLE_FILE;
- else
- mode = FileMode.REGULAR_FILE;
- break;
- case IResource.PROJECT:
- case IResource.FOLDER: {
- final IContainer c = (IContainer) f;
- if (c.findMember(Constants.DOT_GIT) != null)
- mode = FileMode.GITLINK;
- else
- mode = FileMode.TREE;
- break;
- }
- default:
+ if (FS.DETECTED.supportsSymlinks() && file != null
+ && FS.DETECTED.isSymLink(file))
+ mode = FileMode.SYMLINK;
+ else {
+ switch (f.getType()) {
+ case IResource.FILE:
+ if (FS.DETECTED.supportsExecute()
+ && FS.DETECTED.canExecute(file))
+ mode = FileMode.EXECUTABLE_FILE;
+ else
+ mode = FileMode.REGULAR_FILE;
+ break;
+ case IResource.PROJECT:
+ case IResource.FOLDER: {
+ final IContainer c = (IContainer) f;
+ if (c.findMember(Constants.DOT_GIT) != null)
+ mode = FileMode.GITLINK;
+ else
+ mode = FileMode.TREE;
+ break;
+ }
+ default:
+ mode = FileMode.MISSING;
+ break;
+ }
+ }
+ } catch (IOException e) {
mode = FileMode.MISSING;
- break;
}
+ this.mode = mode;
}
@Override
@@ -328,12 +340,16 @@ public class ContainerTreeIterator extends WorkingTreeIterator {
@Override
public long getLength() {
if (length < 0)
- if (rsrc instanceof IFile) {
- File file = asFile();
- if (file != null)
- length = file.length();
- else
+ if (rsrc instanceof IFile || mode == FileMode.SYMLINK) {
+ try {
+ File file = asFile();
+ if (file != null)
+ length = FS.DETECTED.length(asFile());
+ else
+ length = 0;
+ } catch (IOException e) {
length = 0;
+ }
} else
length = 0;
return length;
@@ -341,19 +357,31 @@ public class ContainerTreeIterator extends WorkingTreeIterator {
@Override
public long getLastModified() {
+ if (mode == FileMode.SYMLINK) {
+ try {
+ return FS.DETECTED.lastModified(asFile());
+ } catch (IOException e) {
+ return 0;
+ }
+ }
return rsrc.getLocalTimeStamp();
}
@Override
public InputStream openInputStream() throws IOException {
- if (rsrc.getType() == IResource.FILE)
- try {
- return ((IFile) rsrc).getContents(true);
- } catch (CoreException err) {
- final IOException ioe = new IOException(err.getMessage());
- ioe.initCause(err);
- throw ioe;
- }
+ if (mode == FileMode.SYMLINK) {
+ return new ByteArrayInputStream(FS.DETECTED.readSymLink(
+ asFile()).getBytes(Constants.CHARACTER_ENCODING));
+ } else {
+ if (rsrc.getType() == IResource.FILE)
+ try {
+ return ((IFile) rsrc).getContents(true);
+ } catch (CoreException err) {
+ final IOException ioe = new IOException(err.getMessage());
+ ioe.initCause(err);
+ throw ioe;
+ }
+ }
throw new IOException("Not a regular file: " + rsrc); //$NON-NLS-1$
}

Back to the top