1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-20 07:25:23 +02:00

CygpathTranslator should not accept native path without device

This commit is contained in:
Anton Leherbauer 2008-03-18 15:15:30 +00:00
parent 616baf0dd6
commit ca5dd7b786

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2004, 2007 IBM Corporation and others. * Copyright (c) 2004, 2008 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,9 +7,11 @@
* *
* Contributors: * Contributors:
* IBM - Initial API and implementation * IBM - Initial API and implementation
* Anton Leherbauer (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.make.internal.core.scannerconfig.util; package org.eclipse.cdt.make.internal.core.scannerconfig.util;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
@ -32,6 +34,8 @@ import org.eclipse.core.runtime.Platform;
* @author vhirsl * @author vhirsl
*/ */
public class CygpathTranslator { public class CygpathTranslator {
/** Default Cygwin root dir */
private static final String DEFAULT_CYGWIN_ROOT= "C:\\cygwin"; //$NON-NLS-1$
// private static final String CYGPATH_ERROR_MESSAGE = "CygpathTranslator.NotAvailableErrorMessage"; //$NON-NLS-1$ // private static final String CYGPATH_ERROR_MESSAGE = "CygpathTranslator.NotAvailableErrorMessage"; //$NON-NLS-1$
private CygPath cygPath = null; private CygPath cygPath = null;
private boolean isAvailable = false; private boolean isAvailable = false;
@ -56,8 +60,12 @@ public class CygpathTranslator {
// No CygPath specified in BinaryParser page or not supported. // No CygPath specified in BinaryParser page or not supported.
// Hoping that cygpath is on the path. // Hoping that cygpath is on the path.
if (cygPath == null && Platform.getOS().equals(Platform.OS_WIN32)) { if (cygPath == null && Platform.getOS().equals(Platform.OS_WIN32)) {
if (new File(DEFAULT_CYGWIN_ROOT).exists()) {
cygPath = new CygPath(DEFAULT_CYGWIN_ROOT + "\\bin\\cygpath.exe"); //$NON-NLS-1$
} else {
cygPath = new CygPath("cygpath"); //$NON-NLS-1$ cygPath = new CygPath("cygpath"); //$NON-NLS-1$
isAvailable = true; }
isAvailable = cygPath.getFileName("test").equals("test"); //$NON-NLS-1$ //$NON-NLS-2$
} }
} }
catch (CoreException e) { catch (CoreException e) {
@ -93,13 +101,14 @@ public class CygpathTranslator {
} }
CygpathTranslator cygpath = new CygpathTranslator(project); CygpathTranslator cygpath = new CygpathTranslator(project);
if (cygpath.cygPath == null) return sumIncludes;
List translatedIncludePaths = new ArrayList(); List translatedIncludePaths = new ArrayList();
for (Iterator i = sumIncludes.iterator(); i.hasNext(); ) { for (Iterator i = sumIncludes.iterator(); i.hasNext(); ) {
String includePath = (String) i.next(); String includePath = (String) i.next();
IPath realPath = new Path(includePath); IPath realPath = new Path(includePath);
if (realPath.toFile().exists()) { // only allow native pathes if they have a device prefix
// to avoid matches on the current drive, e.g. /usr/bin = C:\\usr\\bin
if (realPath.getDevice() != null && realPath.toFile().exists()) {
translatedIncludePaths.add(includePath); translatedIncludePaths.add(includePath);
} }
else { else {
@ -111,6 +120,18 @@ public class CygpathTranslator {
catch (IOException e) { catch (IOException e) {
TraceUtil.outputError("CygpathTranslator unable to translate path: ", includePath); //$NON-NLS-1$ TraceUtil.outputError("CygpathTranslator unable to translate path: ", includePath); //$NON-NLS-1$
} }
} else if (realPath.segmentCount() >= 2) {
// try default conversions
// /cygdrive/x/ --> X:\
// /usr/ --> C:\Cygwin\\usr\\
if ("cygdrive".equals(realPath.segment(0))) { //$NON-NLS-1$
String drive= realPath.segment(1);
if (drive.length() == 1) {
translatedPath= realPath.removeFirstSegments(2).setDevice(drive.toUpperCase() + ':').toOSString();
}
} else {
translatedPath= DEFAULT_CYGWIN_ROOT + realPath.toOSString();
}
} }
if (!translatedPath.equals(includePath)) { if (!translatedPath.equals(includePath)) {
// Check if the translated path exists // Check if the translated path exists