Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -65,7 +65,18 @@ public SftpSession(SftpClient sftpClient) {

@Override
public boolean remove(String path) throws IOException {
this.sftpClient.remove(path);
try {
this.sftpClient.remove(path);
}
catch (SftpException sftpEx) {
if (SftpConstants.SSH_FX_NO_SUCH_FILE == sftpEx.getStatus()) {
return false;
}
else {
throw sftpEx;
}
}

return true;
}

Expand Down Expand Up @@ -174,19 +185,8 @@ public void rename(String pathFrom, String pathTo) throws IOException {
this.sftpClient.rename(pathFrom, pathTo, SftpClient.CopyMode.Overwrite);
}
else {
try {
this.sftpClient.rename(pathFrom, pathTo);
}
catch (SftpException sftpex) {
if (SftpConstants.SSH_FX_FILE_ALREADY_EXISTS == sftpex.getStatus()) {
remove(pathTo);
// attempt to rename again
this.sftpClient.rename(pathFrom, pathTo);
}
else {
throw sftpex;
}
}
remove(pathTo);
this.sftpClient.rename(pathFrom, pathTo);
}
}

Expand Down