This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 186316
Collapse All | Expand All

(-)a/dlight.nativeexecution/src/org/netbeans/modules/nativeexecution/pty/PtyAllocator.java (-2 / +9 lines)
Lines 53-58 Link Here
53
import org.netbeans.modules.nativeexecution.api.HostInfo;
53
import org.netbeans.modules.nativeexecution.api.HostInfo;
54
import org.netbeans.modules.nativeexecution.api.pty.Pty;
54
import org.netbeans.modules.nativeexecution.api.pty.Pty;
55
import org.netbeans.modules.nativeexecution.api.util.HostInfoUtils;
55
import org.netbeans.modules.nativeexecution.api.util.HostInfoUtils;
56
import org.netbeans.modules.nativeexecution.api.util.MacroMap;
56
import org.netbeans.modules.nativeexecution.api.util.Shell;
57
import org.netbeans.modules.nativeexecution.api.util.Shell;
57
import org.netbeans.modules.nativeexecution.api.util.WindowsSupport;
58
import org.netbeans.modules.nativeexecution.api.util.WindowsSupport;
58
import org.netbeans.modules.nativeexecution.pty.PtyOpenUtility.PtyInfo;
59
import org.netbeans.modules.nativeexecution.pty.PtyOpenUtility.PtyInfo;
Lines 93-107 Link Here
93
94
94
        try {
95
        try {
95
            if (env.isLocal()) {
96
            if (env.isLocal()) {
97
                ProcessBuilder pb = new ProcessBuilder(hostInfo.getShell(), "-s"); // NOI18N
98
96
                if (Utilities.isWindows()) {
99
                if (Utilities.isWindows()) {
97
                    // Only works with cygwin...
100
                    // Only works with cygwin...
98
                    if (hostInfo.getShell() == null || WindowsSupport.getInstance().getActiveShell().type != Shell.ShellType.CYGWIN) {
101
                    if (hostInfo.getShell() == null || WindowsSupport.getInstance().getActiveShell().type != Shell.ShellType.CYGWIN) {
99
                        throw new IOException("terminal support requires Cygwin to be installed"); // NOI18N
102
                        throw new IOException("terminal support requires Cygwin to be installed"); // NOI18N
100
                    }
103
                    }
101
                    ptyOpenUtilityPath = WindowsSupport.getInstance().convertToCygwinPath(ptyOpenUtilityPath);
104
                    ptyOpenUtilityPath = WindowsSupport.getInstance().convertToCygwinPath(ptyOpenUtilityPath);
105
106
                    // cygwin requires cygwin1.dll to be in the path...
107
                    // take already 'tuned' path from the MacroMap.forExecEnv()
108
                    String path = MacroMap.forExecEnv(env).get("PATH"); // NOI18N
109
                    pb.environment().put("Path", path); // NOI18N
102
                }
110
                }
103
111
104
                ProcessBuilder pb = new ProcessBuilder(hostInfo.getShell(), "-s"); // NOI18N
105
                Process pty = pb.start();
112
                Process pty = pb.start();
106
                output = pty.getOutputStream();
113
                output = pty.getOutputStream();
107
                input = pty.getInputStream();
114
                input = pty.getInputStream();
Lines 119-125 Link Here
119
                error = streams.err;
126
                error = streams.err;
120
            }
127
            }
121
128
122
            output.write(("exec " + ptyOpenUtilityPath + "\n").getBytes()); // NOI18N
129
            output.write(("exec \"" + ptyOpenUtilityPath + "\"\n").getBytes()); // NOI18N
123
            output.flush();
130
            output.flush();
124
131
125
            PtyInfo ptyInfo = PtyOpenUtility.getInstance().readSatelliteOutput(input);
132
            PtyInfo ptyInfo = PtyOpenUtility.getInstance().readSatelliteOutput(input);
(-)a/dlight.nativeexecution/src/org/netbeans/modules/nativeexecution/support/HelperUtility.java (-2 / +77 lines)
Lines 42-48 Link Here
42
package org.netbeans.modules.nativeexecution.support;
42
package org.netbeans.modules.nativeexecution.support;
43
43
44
import java.io.File;
44
import java.io.File;
45
import java.io.FileInputStream;
46
import java.io.FileOutputStream;
45
import java.io.IOException;
47
import java.io.IOException;
48
import java.nio.channels.FileChannel;
46
import java.text.ParseException;
49
import java.text.ParseException;
47
import java.util.HashMap;
50
import java.util.HashMap;
48
import java.util.MissingResourceException;
51
import java.util.MissingResourceException;
Lines 72-78 Link Here
72
    /**
75
    /**
73
     *
76
     *
74
     * @param env
77
     * @param env
75
     * @return the ready-to-use remote path for the utility
78
     * @return the ready-to-use remote path for the utility. It is quaranteed
79
     * that returned path contain no spaces nor non-ascii chars.
76
     * @throws IOException
80
     * @throws IOException
77
     */
81
     */
78
    public final String getPath(final ExecutionEnvironment env) throws IOException {
82
    public final String getPath(final ExecutionEnvironment env) throws IOException {
Lines 95-101 Link Here
95
                    String localFile = getLocalFileLocationFor(env);
99
                    String localFile = getLocalFileLocationFor(env);
96
100
97
                    if (env.isLocal()) {
101
                    if (env.isLocal()) {
98
                        result = localFile;
102
                        // We want to be sure that utility is in a 'good' location,
103
                        // which means path contains no spaces nor non-ascii chars in it.
104
                        // This will help to avoid a number of problems.
105
                        // So will use the 'original' if it is 'good' or will
106
                        // make a copy to user's tmp if it is not.
107
108
                        boolean pathIsOK = checkPath(localFile);
109
110
                        if (pathIsOK) {
111
                            result = localFile;
112
                        } else {
113
                            // copy to a tmp dir
114
                            File orig = new File(localFile);
115
                            File newFile = new File(hinfo.getTempDirFile(), orig.getName());
116
117
                            if (newFile.exists()) {
118
                                // result will be cached. So this is done once
119
                                // per IDE invocation...
120
                                // also it is a localhost, so should be fast to
121
                                // copy (not slower than taking and comparing md5sums)
122
                                // force-copying every time will ensure that
123
                                // utility is up-to-date
124
                                newFile.delete();
125
                            }
126
127
                            result = newFile.getAbsolutePath();
128
                            copyLocalFile(orig, newFile);
129
130
                            // give execution permissions to
131
                            // the file...
132
                            CommonTasksSupport.chmod(env, result, 0755, null).get();
133
                        }
99
                    } else {
134
                    } else {
100
                        final String fileName = new File(localFile).getName();
135
                        final String fileName = new File(localFile).getName();
101
                        final String remoteFile = hinfo.getTempDir() + '/' + fileName;
136
                        final String remoteFile = hinfo.getTempDir() + '/' + fileName;
Lines 134-137 Link Here
134
169
135
        return file.getAbsolutePath();
170
        return file.getAbsolutePath();
136
    }
171
    }
172
173
    private static void copyLocalFile(final File from, final File to) throws IOException {
174
        FileChannel inChannel = new FileInputStream(from).getChannel();
175
        FileChannel outChannel = new FileOutputStream(to).getChannel();
176
177
        try {
178
            inChannel.transferTo(0, inChannel.size(), outChannel);
179
        } catch (IOException e) {
180
            throw e;
181
        } finally {
182
            if (inChannel != null) {
183
                inChannel.close();
184
            }
185
            if (outChannel != null) {
186
                outChannel.close();
187
            }
188
        }
189
    }
190
191
    private static boolean checkPath(String path) {
192
        for (int i = 0; i < path.length(); i++) {
193
            char c = path.charAt(i);
194
195
            if (Character.isDigit(c) || c == '_' || c == '/' || c == '\\' || c == '-') {
196
                continue;
197
            }
198
199
            if (c >= 'A' && c <= 'Z') {
200
                continue;
201
            }
202
203
            if (c >= 'a' && c <= 'z') {
204
                continue;
205
            }
206
207
            return false;
208
        }
209
210
        return true;
211
    }
137
}
212
}

Return to bug 186316