# HG changeset patch # User Vladimir Kvashin # Date 1326964897 -10800 # Branch release701_fixes # Node ID 1bb04a2a17d053c69942941e4f3c245f4217eb3d # Parent 60f7f1aa9dd48df8afd2be953c375661146cc2c7 fixing #207116 - NPE when deleting a directory in remote browser diff -r 60f7f1aa9dd4 -r 1bb04a2a17d0 dlight.remote.impl/src/org/netbeans/modules/remote/impl/fs/RemoteFileUrlMapper.java --- a/dlight.remote.impl/src/org/netbeans/modules/remote/impl/fs/RemoteFileUrlMapper.java Wed Jan 18 14:59:34 2012 +0400 +++ b/dlight.remote.impl/src/org/netbeans/modules/remote/impl/fs/RemoteFileUrlMapper.java Thu Jan 19 12:21:37 2012 +0300 @@ -80,6 +80,30 @@ FileObject fo = fs.findResource(url.getFile()); return new FileObject[] { fo }; } + } else if (url.getProtocol().equals("file")) { + String host = url.getHost(); + String user = url.getUserInfo(); + int port = url.getPort(); + if (host != null) { + ExecutionEnvironment env; + if (user != null) { + env = ExecutionEnvironmentFactory.createNew(user, host, port); + } else { + RemoteLogger.assertTrue(false, "Trying to access remote file system without user name"); + env = RemoteFileSystemUtils.getExecutionEnvironment(host, port); + if (env == null) { + user = System.getProperty("user.name"); + if (user != null) { + env = ExecutionEnvironmentFactory.createNew(user, host, port); + } + } + } + if (env != null) { + RemoteFileSystem fs = RemoteFileSystemManager.getInstance().getFileSystem(env); + FileObject fo = fs.findResource(url.getFile()); + return new FileObject[] { fo }; + } + } } return null; } diff -r 60f7f1aa9dd4 -r 1bb04a2a17d0 dlight.remote/src/org/netbeans/modules/remote/api/ui/FileObjectBasedFile.java --- a/dlight.remote/src/org/netbeans/modules/remote/api/ui/FileObjectBasedFile.java Wed Jan 18 14:59:34 2012 +0400 +++ b/dlight.remote/src/org/netbeans/modules/remote/api/ui/FileObjectBasedFile.java Thu Jan 19 12:21:37 2012 +0300 @@ -47,6 +47,10 @@ import java.io.IOException; import java.io.StringWriter; import java.io.Writer; +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; import java.util.ArrayList; import java.util.List; import java.util.concurrent.Callable; @@ -61,7 +65,9 @@ import org.netbeans.modules.remote.support.RemoteLogger; import org.openide.filesystems.FileLock; import org.openide.filesystems.FileObject; +import org.openide.filesystems.FileStateInvalidException; import org.openide.filesystems.FileUtil; +import org.openide.util.Exceptions; import org.openide.util.RequestProcessor; import org.openide.util.Utilities; @@ -245,6 +251,47 @@ } @Override + public boolean delete() { + if (fo == null) { + fo = FileSystemProvider.getFileObject(env, path); + } + if (fo != null) { + try { + fo.delete(); + return true; + } catch (IOException ex) { + return false; + } + } + return false; + } + + @Override + public URL toURL() throws MalformedURLException { + URL url = getURL(env, path, isDirectory()); + return url; + } + + private static URL getURL(ExecutionEnvironment env, String path, boolean folder) throws MalformedURLException { + String host = env.getUser() + '@' + env.getHost(); + URL url = new URL("file", host, env.getSSHPort(), path); + String ext = url.toExternalForm() + (folder ? "/" : ""); // is there a way to set authority? // NOI18N + return new URL(ext); + } + + + @Override + public URI toURI() { + try { + return toURL().toURI(); + } catch (URISyntaxException ex) { + throw new Error(ex); // should never happen + } catch (MalformedURLException ex) { + throw new Error(ex); // should never happen + } + } + + @Override public String getName() { return (fo == null) ? PathUtilities.getBaseName(path): fo.getNameExt(); }