Skip to content
Snippets Groups Projects
Commit 59197a5e authored by tjc's avatar tjc
Browse files

tidy

git-svn-id: svn+ssh://svn.internal.sanger.ac.uk/repos/svn/pathsoft/artemis/trunk@3476 ee4ac58c-ac51-4696-9907-e4b3aa274f04
parent 8348d63d
No related branches found
No related tags found
No related merge requests found
......@@ -360,15 +360,26 @@ public class SshFileTree extends JTree implements DragGestureListener,
* @param child child to test for
*
*/
public boolean nodeExists(RemoteFileNode parentNode,String child)
public boolean nodeExists(RemoteFileNode parentNode, final String child)
{
if(!parentNode.isDirectory())
parentNode = (RemoteFileNode)parentNode.getParent();
RemoteFileNode childNode = getChildNode(parentNode,child);
if(childNode != null)
{
String ls = System.getProperty("line.separator");
JOptionPane.showMessageDialog(null, child+ls+" already exists!",
Runnable warnMsg = new Runnable()
{
public void run ()
{
String ls = System.getProperty("line.separator");
JOptionPane.showMessageDialog(null, child+ls+" already exists!",
"File Exists",
JOptionPane.ERROR_MESSAGE);
};
};
SwingUtilities.invokeLater(warnMsg);
return true;
}
......@@ -633,6 +644,7 @@ public class SshFileTree extends JTree implements DragGestureListener,
{
RemoteFileNode childNode = (RemoteFileNode)children.nextElement();
String nodeName = childNode.getServerName();
// System.out.println(nodeName+" childName= "+childName);
if(childName.equals(nodeName))
return childNode;
}
......@@ -757,7 +769,19 @@ public class SshFileTree extends JTree implements DragGestureListener,
else
dropFile = fdropPath.getFile()+"/"+fn.getFile();
if(!nodeExists(fdropPath,fdropPath.getServerName()+fn.getFile()))
if(!fdropPath.isDirectory())
fdropPath= (RemoteFileNode)fdropPath.getParent();
String serverName;
if(fdropPath.getServerName().endsWith("/"))
serverName = fdropPath.getServerName()+fn.getFile();
else
serverName = fdropPath.getServerName()+"/"+fn.getFile();
if(!fdropPath.isExplored())
exploreNode(fdropPath);
if(!nodeExists(fdropPath,serverName))
rename(fn.getRootDir(),fn.getFullName(),
fdropPath.getPathName(),
dropFile, fn, fdropPath);
......@@ -777,8 +801,16 @@ public class SshFileTree extends JTree implements DragGestureListener,
File lfn = fn.getFile();
RemoteFileNode pn = (RemoteFileNode)dropPath.getLastPathComponent();
if(!pn.isDirectory())
pn = (RemoteFileNode)pn.getParent();
String serverName;
if(pn.getServerName().endsWith("/"))
serverName = pn.getServerName()+lfn.getName();
else
serverName = pn.getServerName()+"/"+lfn.getName();
if(!nodeExists(pn,pn.getServerName()+lfn.getName()))
if(!nodeExists(pn,serverName))
{
pn.put(lfn);
try
......
......@@ -85,10 +85,30 @@ public class SshFileManager
ssh = sshLogin.getSshClient();
}
private void rescue()
{
ssh.disconnect();
SshLogin sshLogin = new SshLogin();
ssh = sshLogin.getSshClient();
}
private SftpClient getSftpClient()
throws IOException
{
SftpClient sftp;
try
{
sftp = ssh.getActiveSftpClient();
return sftp;
}
catch(IOException ioe){}
return ssh.openSftpClient();
}
public boolean remoteList(String remoteRootDir)
throws IOException
{
SftpClient sftp = ssh.openSftpClient();
SftpClient sftp = getSftpClient();
try
{
......@@ -112,7 +132,7 @@ public class SshFileManager
file_list.add(sfile.getFilename());
}
sftp.quit();
// sftp.quit();
return true;
}
......@@ -120,9 +140,9 @@ public class SshFileManager
{
try
{
SftpClient sftp = ssh.openSftpClient();
SftpClient sftp = getSftpClient();
sftp.rm(filename);
sftp.quit();
// sftp.quit();
}
catch(IOException ioe)
{
......@@ -137,9 +157,9 @@ public class SshFileManager
{
try
{
SftpClient sftp = ssh.openSftpClient();
SftpClient sftp = getSftpClient();
sftp.mkdir(dir);
sftp.quit();
// sftp.quit();
}
catch(IOException ioe)
{
......@@ -155,9 +175,9 @@ public class SshFileManager
String pwd = null;
try
{
SftpClient sftp = ssh.openSftpClient();
SftpClient sftp = getSftpClient();
pwd = sftp.pwd();
sftp.quit();
// sftp.quit();
}
catch(IOException ioe)
{
......@@ -171,12 +191,14 @@ public class SshFileManager
{
try
{
SftpClient sftp = ssh.openSftpClient();
SftpClient sftp = getSftpClient();
sftp.rename(old_file,new_file);
sftp.quit();
// sftp.quit();
}
catch(IOException ioe)
{
rescue();
rename(old_file, new_file);
ioe.printStackTrace();
return false;
}
......@@ -197,7 +219,7 @@ public class SshFileManager
try
{
sftp = ssh.openSftpClient();
sftp = getSftpClient();
FileAttributes attr = sftp.stat(dir+"/"+local_file.getName());
if(attr.isDirectory())
......@@ -231,7 +253,7 @@ public class SshFileManager
{
sftp.put(local_file.getCanonicalPath(),
dir+"/"+local_file.getName());
sftp.quit();
// sftp.quit();
}
catch(IOException ioe)
{
......@@ -253,11 +275,11 @@ public class SshFileManager
{
try
{
SftpClient sftp = ssh.openSftpClient();
SftpClient sftp = getSftpClient();
ByteArrayOutputStream os = new ByteArrayOutputStream();
sftp.get(file, os);
sftp.quit();
// sftp.quit();
return os.toByteArray();
}
catch(IOException ioe)
......
......@@ -82,7 +82,7 @@ public class SshLogin
fh.setFormatter(new SimpleFormatter());
Logger.getLogger("com.sshtools").setUseParentHandlers(false);
Logger.getLogger("com.sshtools").addHandler(fh);
Logger.getLogger("com.sshtools").setLevel(Level.ALL);
Logger.getLogger("com.sshtools").setLevel(Level.WARNING);
}
else
Logger.getLogger("com.sshtools").setLevel(Level.OFF);
......
......@@ -131,7 +131,7 @@ public class RemoteFileDocument extends Document
if(write_file.exists())
{
int n = JOptionPane.showConfirmDialog(null,
"The file\n"+getName()+
"The file :\n"+getName()+
"\nalready exists on the local disk.\nOverwrite?",
"Overwrite "+getName(),
JOptionPane.YES_NO_OPTION);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment