/*******************************************************************************
 * Copyright (c) 2012-2017 Codenvy, S.A.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *   Codenvy, S.A. - initial API and implementation
 *******************************************************************************/
package org.eclipse.che.plugin.docker.machine.cleaner;

import com.google.inject.Inject;
import com.google.inject.Singleton;
import com.google.inject.name.Named;

import org.eclipse.che.api.core.model.workspace.Workspace;
import org.eclipse.che.api.workspace.server.WorkspaceFilesCleaner;
import org.eclipse.che.commons.lang.IoUtil;
import org.eclipse.che.plugin.docker.machine.local.node.provider.LocalWorkspaceFolderPathProvider;

import java.io.File;
import java.io.IOException;

/**
 * Local implementation of the {@link WorkspaceFilesCleaner}.
 *
 * @author Alexander Andrienko
 */
@Singleton
public class LocalWorkspaceFilesCleaner implements WorkspaceFilesCleaner {

    private final LocalWorkspaceFolderPathProvider workspaceFolderPathProvider;

    @Inject(optional = true)
    @Named("host.projects.root")
    private String hostProjectsFolder;

    @Inject
    public LocalWorkspaceFilesCleaner(LocalWorkspaceFolderPathProvider workspaceFolderPathProvider) {
        this.workspaceFolderPathProvider = workspaceFolderPathProvider;
    }

    @Override
    public void clear(Workspace workspace) throws IOException {
        String workspacePath = workspaceFolderPathProvider.getPathByName(workspace.getConfig().getName());
        File workspaceStorage = new File(workspacePath);
        if (!workspacePath.equals(hostProjectsFolder) && workspaceStorage.exists()) {
            IoUtil.deleteRecursive(workspaceStorage);
        }
    }
}

@@ -808,52 +808,8 @@
 er;%0A
-import org.eclipse.che.commons.lang.IoUtil;%0A
 impo
@@ -954,16 +954,123 @@
 ption;%0A%0A
+import static java.lang.System.getenv;%0Aimport static org.eclipse.che.commons.lang.IoUtil.deleteRecursive;%0A%0A
 /**%0A * L
@@ -1161,16 +1161,40 @@
 drienko%0A
+ * @author Igor Vinokur%0A
  */%0A@Sin
@@ -1849,142 +1849,145 @@
     
-File workspaceStorage = new File(workspacePath);%0A        if (!workspacePath.equals(hostProjectsFolder) && workspaceStorage.exists()) %7B
+if (!workspacePath.equals(hostProjectsFolder)) %7B%0A            // Remove the workspace folder located in the Che instance docker container.
 %0A   
@@ -1995,23 +1995,16 @@
         
-IoUtil.
 deleteRe
@@ -2015,24 +2015,67 @@
 ive(
-workspaceStorage
+new File(workspacePath.replace(getenv(%22CHE_INSTANCE%22), %22%22))
 );%0A 

Fix deletion of WS folder on WS deletion (#4122)