From e350874842f65566dcd3e373a3194a438b5cb2bd Mon Sep 17 00:00:00 2001 From: Oleg Zhurakousky Date: Fri, 6 May 2011 14:37:03 -0400 Subject: [PATCH] polishing, cleaned up SftpSession rename() method --- .../integration/sftp/session/SftpSession.java | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/session/SftpSession.java b/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/session/SftpSession.java index 6067b5338e..fce80a3af9 100644 --- a/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/session/SftpSession.java +++ b/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/session/SftpSession.java @@ -140,25 +140,31 @@ class SftpSession implements Session { try { this.channel.rename(pathFrom, pathTo); } - catch (SftpException e) { - try { - logger.debug("Initial File rename failed, possibly becouse file already exists. Will attempt to delete file: " + catch (SftpException sftpex) { + if (logger.isDebugEnabled()){ + logger.debug("Initial File rename failed, possibly because file already exists. Will attempt to delete file: " + pathTo + " and execute rename again."); + } + try { this.remove(pathTo); - logger.debug("Delete file: " + pathTo + " succeeded"); + if (logger.isDebugEnabled()){ + logger.debug("Delete file: " + pathTo + " succeeded. Will attempt rename again"); + } } - catch (Exception ex) { - // ignore since the exception might be thrown + catch (IOException ioex) { + throw new NestedIOException("Failed to delete file " + pathTo, ioex); } try { // attempt to rename again this.channel.rename(pathFrom, pathTo); } - catch (Exception e2) { - throw new NestedIOException("failed to rename from " + pathFrom + " to " + pathTo, e); + catch (SftpException sftpex2) { + throw new NestedIOException("failed to rename from " + pathFrom + " to " + pathTo, sftpex2); } } - logger.debug("File: " + pathFrom + " was successfully renamed to " + pathTo); + if (logger.isDebugEnabled()){ + logger.debug("File: " + pathFrom + " was successfully renamed to " + pathTo); + } } public void mkdir(String directory) throws IOException {