You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by lg...@apache.org on 2018/04/23 07:55:47 UTC
[2/3] mina-sshd git commit: [SSHD-814] Added signalling of failing to
remove SFTP local file/folder due to preconditions having failed
[SSHD-814] Added signalling of failing to remove SFTP local file/folder due to preconditions having failed
Project: http://git-wip-us.apache.org/repos/asf/mina-sshd/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina-sshd/commit/08a774e0
Tree: http://git-wip-us.apache.org/repos/asf/mina-sshd/tree/08a774e0
Diff: http://git-wip-us.apache.org/repos/asf/mina-sshd/diff/08a774e0
Branch: refs/heads/master
Commit: 08a774e0a42c3784f1000725f6df009f42d57c65
Parents: 092a8bb
Author: Goldstein Lyor <ly...@c-b4.com>
Authored: Mon Apr 23 08:09:42 2018 +0300
Committer: Goldstein Lyor <ly...@c-b4.com>
Committed: Mon Apr 23 10:55:36 2018 +0300
----------------------------------------------------------------------
.../sftp/AbstractSftpSubsystemHelper.java | 26 +++++++++++++++-----
.../server/subsystem/sftp/SftpSubsystem.java | 4 +--
2 files changed, 22 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/08a774e0/sshd-sftp/src/main/java/org/apache/sshd/server/subsystem/sftp/AbstractSftpSubsystemHelper.java
----------------------------------------------------------------------
diff --git a/sshd-sftp/src/main/java/org/apache/sshd/server/subsystem/sftp/AbstractSftpSubsystemHelper.java b/sshd-sftp/src/main/java/org/apache/sshd/server/subsystem/sftp/AbstractSftpSubsystemHelper.java
index b67163c..bdcb0c5 100644
--- a/sshd-sftp/src/main/java/org/apache/sshd/server/subsystem/sftp/AbstractSftpSubsystemHelper.java
+++ b/sshd-sftp/src/main/java/org/apache/sshd/server/subsystem/sftp/AbstractSftpSubsystemHelper.java
@@ -1451,7 +1451,7 @@ public abstract class AbstractSftpSubsystemHelper
if (Files.isDirectory(p, options)) {
doRemove(id, p);
} else {
- throw new NotDirectoryException(p.toString());
+ throw signalRemovalPreConditionFailure(id, path, p, new NotDirectoryException(p.toString()));
}
}
@@ -1546,17 +1546,31 @@ public abstract class AbstractSftpSubsystemHelper
Boolean status = IoUtils.checkFileExists(p, options);
if (status == null) {
- throw new AccessDeniedException(p.toString(), p.toString(), "Cannot determine existence of remove candidate");
- }
- if (!status) {
- throw new NoSuchFileException(p.toString(), p.toString(), "Removal candidate not found");
+ throw signalRemovalPreConditionFailure(id, path, p,
+ new AccessDeniedException(p.toString(), p.toString(), "Cannot determine existence of remove candidate"));
+ } else if (!status) {
+ throw signalRemovalPreConditionFailure(id, path, p,
+ new NoSuchFileException(p.toString(), p.toString(), "Removal candidate not found"));
} else if (Files.isDirectory(p, options)) {
- throw new SftpException(SftpConstants.SSH_FX_FILE_IS_A_DIRECTORY, p.toString() + " is a folder");
+ throw signalRemovalPreConditionFailure(id, path, p,
+ new SftpException(SftpConstants.SSH_FX_FILE_IS_A_DIRECTORY, p.toString() + " is a folder"));
} else {
doRemove(id, p);
}
}
+ protected <E extends IOException> E signalRemovalPreConditionFailure(int id, String pathValue, Path path, E thrown) throws IOException {
+ SftpEventListener listener = getSftpEventListenerProxy();
+ ServerSession session = getServerSession();
+ if (log.isDebugEnabled()) {
+ log.debug("signalRemovalPreConditionFailure(id={})[{}] signal {} for {}: {}",
+ id, pathValue, thrown.getClass().getSimpleName(), path, thrown.getMessage());
+ }
+ listener.removing(session, path);
+ listener.removed(session, path, thrown);
+ return thrown;
+ }
+
protected void doExtended(Buffer buffer, int id) throws IOException {
executeExtendedCommand(buffer, id, buffer.getString());
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/08a774e0/sshd-sftp/src/main/java/org/apache/sshd/server/subsystem/sftp/SftpSubsystem.java
----------------------------------------------------------------------
diff --git a/sshd-sftp/src/main/java/org/apache/sshd/server/subsystem/sftp/SftpSubsystem.java b/sshd-sftp/src/main/java/org/apache/sshd/server/subsystem/sftp/SftpSubsystem.java
index 3cc5265..bd1f251 100644
--- a/sshd-sftp/src/main/java/org/apache/sshd/server/subsystem/sftp/SftpSubsystem.java
+++ b/sshd-sftp/src/main/java/org/apache/sshd/server/subsystem/sftp/SftpSubsystem.java
@@ -522,8 +522,8 @@ public class SftpSubsystem
*/
if (requestsCount.get() > 0L) {
sendStatus(prepareReply(buffer), id,
- SftpConstants.SSH_FX_FAILURE,
- "Version selection not the 1st request for proposal = " + proposed);
+ SftpConstants.SSH_FX_FAILURE,
+ "Version selection not the 1st request for proposal = " + proposed);
session.close(true);
return;
}