Lines 64-71
Link Here
|
64 |
import javax.swing.SwingUtilities; |
64 |
import javax.swing.SwingUtilities; |
65 |
import org.netbeans.modules.dlight.libs.common.PathUtilities; |
65 |
import org.netbeans.modules.dlight.libs.common.PathUtilities; |
66 |
import org.netbeans.modules.nativeexecution.api.ExecutionEnvironment; |
66 |
import org.netbeans.modules.nativeexecution.api.ExecutionEnvironment; |
|
|
67 |
import org.netbeans.modules.nativeexecution.api.util.CommonTasksSupport; |
67 |
import org.netbeans.modules.nativeexecution.api.util.ConnectionListener; |
68 |
import org.netbeans.modules.nativeexecution.api.util.ConnectionListener; |
68 |
import org.netbeans.modules.nativeexecution.api.util.ConnectionManager; |
69 |
import org.netbeans.modules.nativeexecution.api.util.ConnectionManager; |
|
|
70 |
import org.netbeans.modules.nativeexecution.api.util.ConnectionManager.CancellationException; |
71 |
import org.netbeans.modules.nativeexecution.api.util.HostInfoUtils; |
69 |
import org.netbeans.modules.remote.api.ui.ConnectionNotifier; |
72 |
import org.netbeans.modules.remote.api.ui.ConnectionNotifier; |
70 |
import org.netbeans.modules.remote.spi.FileSystemCacheProvider; |
73 |
import org.netbeans.modules.remote.spi.FileSystemCacheProvider; |
71 |
import org.netbeans.modules.remote.impl.RemoteLogger; |
74 |
import org.netbeans.modules.remote.impl.RemoteLogger; |
Lines 114-119
Link Here
|
114 |
private final List<FileSystemProblemListener> problemListeners = |
117 |
private final List<FileSystemProblemListener> problemListeners = |
115 |
new ArrayList<FileSystemProblemListener>(); |
118 |
new ArrayList<FileSystemProblemListener>(); |
116 |
transient private final StatusImpl status = new StatusImpl(); |
119 |
transient private final StatusImpl status = new StatusImpl(); |
|
|
120 |
private final LinkedHashSet<String> deleteOnExitFiles = new LinkedHashSet<String>(); |
117 |
|
121 |
|
118 |
/*package*/ RemoteFileSystem(ExecutionEnvironment execEnv) throws IOException { |
122 |
/*package*/ RemoteFileSystem(ExecutionEnvironment execEnv) throws IOException { |
119 |
RemoteLogger.assertTrue(execEnv.isRemote()); |
123 |
RemoteLogger.assertTrue(execEnv.isRemote()); |
Lines 262-267
Link Here
|
262 |
return getRoot().getFileObject(name); |
266 |
return getRoot().getFileObject(name); |
263 |
} |
267 |
} |
264 |
} |
268 |
} |
|
|
269 |
|
270 |
@Override |
271 |
public FileObject getTempFolder() throws IOException { |
272 |
try { |
273 |
String tmpName = HostInfoUtils.getHostInfo(execEnv).getTempDir(); |
274 |
RemoteFileObject tmpDir = findResource(tmpName); |
275 |
if (tmpDir != null && tmpDir.isFolder() && tmpDir.isValid()) { |
276 |
return tmpDir; |
277 |
} |
278 |
} catch (CancellationException ex) { |
279 |
// |
280 |
} |
281 |
throw new IOException("Cannot find temporary folder"); // NOI18N |
282 |
} |
283 |
|
284 |
@Override |
285 |
public FileObject createTempFile(FileObject parent, String prefix, String suffix, boolean deleteOnExit) throws IOException { |
286 |
if (parent.isFolder() && parent.isValid()) { |
287 |
while(true) { |
288 |
File tmpFile = File.createTempFile(prefix, suffix); |
289 |
String tmpName = tmpFile.getName(); |
290 |
tmpFile.delete(); |
291 |
try { |
292 |
FileObject fo = parent.createData(tmpName); |
293 |
if (fo != null && fo.isData() && fo.isValid()) { |
294 |
if (deleteOnExit) { |
295 |
addDeleteOnExit(fo.getPath()); |
296 |
} |
297 |
return fo; |
298 |
} |
299 |
break; |
300 |
} catch (IOException ex) { |
301 |
FileObject test = parent.getFileObject(tmpName); |
302 |
if (test != null) { |
303 |
continue; |
304 |
} |
305 |
throw ex; |
306 |
} |
307 |
} |
308 |
} |
309 |
throw new IOException("Cannot create temporary file"); // NOI18N |
310 |
} |
265 |
|
311 |
|
266 |
/*package*/ RemoteFileObjectBase findResource(String name, Set<String> antiloop) { |
312 |
/*package*/ RemoteFileObjectBase findResource(String name, Set<String> antiloop) { |
267 |
if (name.isEmpty() || name.equals("/")) { // NOI18N |
313 |
if (name.isEmpty() || name.equals("/")) { // NOI18N |
Lines 520-530
Link Here
|
520 |
} |
566 |
} |
521 |
return new SystemAction[] {}; |
567 |
return new SystemAction[] {}; |
522 |
} |
568 |
} |
523 |
|
569 |
|
524 |
@Override |
570 |
@Override |
525 |
public Status getStatus() { |
571 |
public Status getStatus() { |
526 |
return status; |
572 |
return status; |
527 |
} |
573 |
} |
|
|
574 |
|
575 |
private void addDeleteOnExit(String path) { |
576 |
synchronized(deleteOnExitFiles) { |
577 |
if (deleteOnExitFiles.isEmpty()) { |
578 |
Runtime.getRuntime().addShutdownHook(new Thread() { |
579 |
|
580 |
@Override |
581 |
public void run() { |
582 |
releaseResources(); |
583 |
} |
584 |
|
585 |
}); |
586 |
} |
587 |
deleteOnExitFiles.add(path); |
588 |
} |
589 |
} |
590 |
|
591 |
private void releaseResources() { |
592 |
ArrayList<String> toBeDeleted; |
593 |
synchronized(deleteOnExitFiles) { |
594 |
toBeDeleted = new ArrayList<String>(deleteOnExitFiles); |
595 |
} |
596 |
Collections.reverse(toBeDeleted); |
597 |
for (String filename : toBeDeleted) { |
598 |
if (!ConnectionManager.getInstance().isConnectedTo(execEnv)) { |
599 |
return; |
600 |
} |
601 |
CommonTasksSupport.rmFile(execEnv, filename, null); |
602 |
} |
603 |
} |
528 |
|
604 |
|
529 |
private final class StatusImpl implements FileSystem.HtmlStatus, LookupListener, FileStatusListener { |
605 |
private final class StatusImpl implements FileSystem.HtmlStatus, LookupListener, FileStatusListener { |
530 |
|
606 |
|