Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoland Grunberg2015-09-03 17:29:44 +0000
committerRoland Grunberg2015-09-08 19:21:46 +0000
commite68ac8ec4e7bf6b41e6d3d730603829e12d00149 (patch)
treec80499217101c40741df5b7c87ac298c47fb2ccb
parenta7d5a2e1eac0427530f8748a1a61fee5cead8c12 (diff)
downloadorg.eclipse.linuxtools-e68ac8ec4e7bf6b41e6d3d730603829e12d00149.tar.gz
org.eclipse.linuxtools-e68ac8ec4e7bf6b41e6d3d730603829e12d00149.tar.xz
org.eclipse.linuxtools-e68ac8ec4e7bf6b41e6d3d730603829e12d00149.zip
Bug 476598: Validate the directory chosen for the image build.
The directory chosen for the image build must have all of its content readable as the build must generate a compressed archive stream of this content. Perform a simple check that the folder is readable in the wizard page, and do a more thorough check in the handler. Change-Id: Ie80347f9ab776363d64caccb26e73229b6f4ebe2 Reviewed-on: https://git.eclipse.org/r/55496 Tested-by: Hudson CI Reviewed-by: Roland Grunberg <rgrunber@redhat.com>
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/BuildImageCommandHandler.java60
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImageBuildPage.java8
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/WizardMessages.properties3
3 files changed, 70 insertions, 1 deletions
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/BuildImageCommandHandler.java b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/BuildImageCommandHandler.java
index 60b6059c54..1d87f4cb2b 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/BuildImageCommandHandler.java
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/BuildImageCommandHandler.java
@@ -10,6 +10,13 @@
*******************************************************************************/
package org.eclipse.linuxtools.internal.docker.ui.commands;
+import java.io.IOException;
+import java.nio.file.FileVisitResult;
+import java.nio.file.FileVisitor;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.nio.file.attribute.BasicFileAttributes;
+
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.runtime.IPath;
@@ -25,6 +32,7 @@ import org.eclipse.linuxtools.internal.docker.ui.views.DVMessages;
import org.eclipse.linuxtools.internal.docker.ui.views.DockerImagesView;
import org.eclipse.linuxtools.internal.docker.ui.views.ImageBuildProgressHandler;
import org.eclipse.linuxtools.internal.docker.ui.wizards.ImageBuild;
+import org.eclipse.linuxtools.internal.docker.ui.wizards.WizardMessages;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.handlers.HandlerUtil;
@@ -33,6 +41,7 @@ public class BuildImageCommandHandler extends AbstractHandler {
private final static String BUILD_IMAGE_JOB_TITLE = "ImageBuild.msg"; //$NON-NLS-1$
private static final String ERROR_BUILDING_IMAGE = "ImageBuildError.msg"; //$NON-NLS-1$
+ private static final String IMAGE_DIRECTORY_VALIDATE = "ImageDirectoryValidate.msg"; //$NON-NLS-1$
private IDockerConnection connection;
@@ -61,11 +70,60 @@ public class BuildImageCommandHandler extends AbstractHandler {
final String id = wizard.getImageName();
final int lines = wizard.getNumberOfLines();
final IPath path = wizard.getDirectory();
+
monitor.beginTask(DVMessages.getString(BUILD_IMAGE_JOB_TITLE),
- 1);
+ 2);
+ monitor.subTask(
+ WizardMessages.getString(IMAGE_DIRECTORY_VALIDATE));
+ try {
+ Files.walkFileTree(Paths.get(path.toString()),
+ new FileVisitor<java.nio.file.Path>() {
+ @Override
+ public FileVisitResult preVisitDirectory(
+ java.nio.file.Path dir,
+ BasicFileAttributes attrs) {
+ return FileVisitResult.CONTINUE;
+ }
+ @Override
+ public FileVisitResult visitFile(
+ java.nio.file.Path file,
+ BasicFileAttributes attrs) {
+ return FileVisitResult.CONTINUE;
+ }
+ @Override
+ public FileVisitResult visitFileFailed(
+ java.nio.file.Path file, IOException exc)
+ throws IOException {
+ throw exc;
+ }
+ @Override
+ public FileVisitResult postVisitDirectory(
+ java.nio.file.Path dir, IOException exc) {
+ return FileVisitResult.CONTINUE;
+ }
+ });
+ } catch (final IOException e) {
+ Display.getDefault().syncExec(new Runnable() {
+ @Override
+ public void run() {
+ MessageDialog.openError(
+ Display.getCurrent().getActiveShell(),
+ WizardMessages.getString(
+ "ErrorInvalidDirectory.msg"),
+ WizardMessages.getFormattedString(
+ "ErrorInvalidPermissions.msg",
+ path.toString()));
+ }
+ });
+ return Status.OK_STATUS;
+ }
+ monitor.worked(1);
+
// build the image and let the progress
// handler refresh the images when done
try {
+ monitor.subTask(
+ DVMessages.getString(BUILD_IMAGE_JOB_TITLE));
((DockerConnection) connection)
.buildImage(path, id,
new ImageBuildProgressHandler(connection,
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImageBuildPage.java b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImageBuildPage.java
index 532c173e3d..c0deaf8ff4 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImageBuildPage.java
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImageBuildPage.java
@@ -10,6 +10,9 @@
*******************************************************************************/
package org.eclipse.linuxtools.internal.docker.ui.wizards;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+
import org.eclipse.core.filesystem.EFS;
import org.eclipse.core.filesystem.IFileInfo;
import org.eclipse.core.filesystem.IFileStore;
@@ -45,6 +48,7 @@ public class ImageBuildPage extends WizardPage {
private final static String EDIT_LABEL = "EditButton.label"; //$NON-NLS-1$
private final static String NONEXISTENT_DIRECTORY = "ErrorNonexistentDirectory.msg"; //$NON-NLS-1$
private final static String INVALID_DIRECTORY = "ErrorInvalidDirectory.msg"; //$NON-NLS-1$
+ private final static String UNREADABLE_DIRECTORY = "ErrorUnreadableDirectory.msg"; //$NON-NLS-1$
private final static String INVALID_ID = "ErrorInvalidImageId.msg"; //$NON-NLS-1$
private final static String NO_DOCKER_FILE = "ErrorNoDockerFile.msg"; //$NON-NLS-1$
@@ -111,6 +115,10 @@ public class ImageBuildPage extends WizardPage {
} else if (!info.isDirectory()) {
error = true;
setErrorMessage(WizardMessages.getString(INVALID_DIRECTORY));
+ } else if (!Files.isReadable(Paths.get(dir))) {
+ error = true;
+ setErrorMessage(
+ WizardMessages.getString(UNREADABLE_DIRECTORY));
} else {
editButton.setEnabled(true);
IFileStore dockerStore = fileStore.getChild("Dockerfile"); //$NON-NLS-1$
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/WizardMessages.properties b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/WizardMessages.properties
index cc82a4344c..41d0f7d06e 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/WizardMessages.properties
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/WizardMessages.properties
@@ -111,9 +111,12 @@ ImageBuildName.toolTip=Enter the name of the new image (either REPOSITORY or REP
ImageBuildDirectory.label=Directory:
ImageBuildDirectory.toolTip=Enter or choose a directory containing a valid Dockerfile to build an image from
+ImageDirectoryValidate.msg=Validating the selected folder
ErrorNonexistentDirectory.msg=Directory specified does not exist
ErrorInvalidDirectory.msg=Directory specified is not a valid directory
+ErrorUnreadableDirectory.msg=Directory specified is not readable
ErrorNoDockerFile.msg=Directory specified does not contain a file called: Dockerfile
+ErrorInvalidPermissions.msg=The contents of {0} required for the image build have invalid permissions. Try using a directory with adequate permissions.
ImageRemove.label=Remove an image:
ImageRemove.desc=Specify images to remove from host.

Back to the top