1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-07 17:56:01 +02:00

Bug 278769. Adding includes with ".." in the path.

This commit is contained in:
Sergey Prigogin 2009-06-03 07:23:33 +00:00
parent 92e056c154
commit 31e63bd47a

View file

@ -14,6 +14,7 @@
package org.eclipse.cdt.internal.ui.editor; package org.eclipse.cdt.internal.ui.editor;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.net.URI; import java.net.URI;
import java.util.ArrayList; import java.util.ArrayList;
@ -563,13 +564,13 @@ public class AddIncludeOnSelectionAction extends TextEditorAction {
} }
// The file has never been included before. // The file has never been included before.
IPath targetLocation = PathUtil.getCanonicalPath(new Path(file.getLocation().getURI().getPath())); URI targetUri = file.getLocation().getURI();
IPath targetLocation = PathUtil.getCanonicalPath(new Path(targetUri.getPath()));
IPath sourceLocation = PathUtil.getCanonicalPath(fTu.getResource().getLocation()); IPath sourceLocation = PathUtil.getCanonicalPath(fTu.getResource().getLocation());
boolean isSystemIncludePath = false; boolean isSystemIncludePath = false;
IPath path = PathUtil.makeRelativePathToIncludes(targetLocation, fIncludePath); IPath path = PathUtil.makeRelativePathToIncludes(targetLocation, fIncludePath);
if (path != null && if (path != null && ResourceLookup.findFilesForLocationURI(targetUri).length == 0) {
ResourceLookup.findFilesForLocationURI(URI.create(targetLocation.toString())).length == 0) {
// A header file in the include path but outside the workspace is included with angle brackets. // A header file in the include path but outside the workspace is included with angle brackets.
isSystemIncludePath = true; isSystemIncludePath = true;
} }
@ -584,6 +585,11 @@ public class AddIncludeOnSelectionAction extends TextEditorAction {
targetLocation.getDevice().equalsIgnoreCase(sourceDirectory.getDevice())) { targetLocation.getDevice().equalsIgnoreCase(sourceDirectory.getDevice())) {
path = path.setDevice(null); path = path.setDevice(null);
} }
if (path.isAbsolute() && path.getDevice() == null &&
ResourceLookup.findFilesForLocationURI(targetUri).length != 0) {
// The file is inside workspace. Include with a relative path.
path = PathUtil.makeRelativePath(path, sourceDirectory);
}
} }
return new RequiredInclude(path.toString(), isSystemIncludePath); return new RequiredInclude(path.toString(), isSystemIncludePath);
} }
@ -604,10 +610,14 @@ public class AddIncludeOnSelectionAction extends TextEditorAction {
if (include.isSystemInclude()) { if (include.isSystemInclude()) {
return false; return false;
} }
return target.equals(new File(new File(fTu.getLocationURI().getPath()).getParent(), includeName)); String directory = new File(fTu.getLocationURI().getPath()).getParent();
return target.equals(new File(directory, includeName).getCanonicalFile());
} catch (CoreException e) { } catch (CoreException e) {
CUIPlugin.log(e); CUIPlugin.log(e);
return false; return false;
} catch (IOException e) {
CUIPlugin.log(e);
return false;
} }
} }