Skip to content
This repository was archived by the owner on Nov 28, 2022. It is now read-only.

Commit

Permalink
Don't allow user to create/bind projects in codewind-data dir
Browse files Browse the repository at this point in the history
  • Loading branch information
eharris369 committed Nov 21, 2019
1 parent 1e5a5f2 commit 8a11fea
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -234,4 +234,17 @@ public static String getEnvPath() {
return path;
}

public static IPath getCodewindDataPath() {
if (isWindows()) {
return new Path("C:/codewind-data");
}
String userDir = System.getProperty("user.dir");
if (userDir != null && !userDir.isEmpty()) {
return new Path(userDir).append("codewind-data");
}
// This should not happen
Logger.logError("The user.dir system property was null or empty.");
return null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ public class Messages extends NLS {
public static String NewProjectPage_NoLocationError;
public static String NewProjectPage_LocationNotValid;
public static String NewProjectPage_NoTemplateSelected;
public static String ProjectLocationInCodewindDataDirError;

public static String AppOverviewEditorCreateError;
public static String AppOverviewEditorPartName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ NewProjectPage_EmptyTemplateList=There are no available templates. Use the Manag
NewProjectPage_NoLocationError=Specify a location for the project.
NewProjectPage_LocationNotValid=The location specified is not a directory.
NewProjectPage_NoTemplateSelected=Select a template to use for the new project.
ProjectLocationInCodewindDataDirError=Projects cannot be located in the {0} folder. This is where Codewind user configuration files are kept.

AppOverviewEditorCreateError=The application overview editor could not be created for the input: {0}. Check the logs for more details.
AppOverviewEditorPartName=Application Overview: {0}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.regex.Pattern;

import org.eclipse.codewind.core.internal.CodewindManager;
import org.eclipse.codewind.core.internal.CoreUtil;
import org.eclipse.codewind.core.internal.Logger;
import org.eclipse.codewind.core.internal.ProcessHelper.ProcessResult;
import org.eclipse.codewind.core.internal.cli.InstallStatus;
Expand All @@ -37,9 +38,11 @@
import org.eclipse.codewind.ui.internal.views.ViewHelper;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.operation.IRunnableWithProgress;
Expand Down Expand Up @@ -477,6 +480,12 @@ private boolean validate() {
setErrorMessage(Messages.NewProjectPage_LocationNotValid);
return false;
}
// It is an error if the project is located in the codewind-data folder
IPath dataPath = CoreUtil.getCodewindDataPath();
if (dataPath != null && dataPath.isPrefixOf(new Path(location))) {
setErrorMessage(NLS.bind(Messages.ProjectLocationInCodewindDataDirError, dataPath.toOSString()));
return false;
}
if (selectionTable.getSelectionCount() != 1) {
setErrorMessage(Messages.NewProjectPage_NoTemplateSelected);
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

package org.eclipse.codewind.ui.internal.wizards;

import org.eclipse.codewind.core.internal.CoreUtil;
import org.eclipse.codewind.core.internal.connection.CodewindConnection;
import org.eclipse.codewind.ui.internal.IDEUtil;
import org.eclipse.codewind.ui.internal.messages.Messages;
Expand Down Expand Up @@ -265,6 +266,12 @@ private void validate() {
if (hasValidProjects) {
Object[] checked = projectList.getCheckedElements();
project = checked.length == 1 ? (IProject) checked[0] : null;
// It is an error if the project is located in the codewind-data folder
IPath dataPath = CoreUtil.getCodewindDataPath();
if (dataPath != null && dataPath.isPrefixOf(project.getFullPath())) {
errorMsg = NLS.bind(Messages.ProjectLocationInCodewindDataDirError, dataPath.toOSString());
project = null;
}
projectPath = null;
}
} else {
Expand All @@ -287,6 +294,13 @@ private void validate() {
if (existingProject.exists() && !path.toFile().equals(existingProject.getLocation().toFile())) {
errorMsg = NLS.bind(Messages.SelectProjectPageProjectExistsError, path.lastSegment());
projectPath = null;
} else {
// It is an error if the project is located in the codewind-data folder
IPath dataPath = CoreUtil.getCodewindDataPath();
if (dataPath != null && dataPath.isPrefixOf(path)) {
errorMsg = NLS.bind(Messages.ProjectLocationInCodewindDataDirError, dataPath.toOSString());
projectPath = null;
}
}
}
}
Expand Down

0 comments on commit 8a11fea

Please sign in to comment.