Bugfix: Error while deleting remote dirs
This commit is contained in:
parent
96183890ac
commit
71ba42bec8
16
Sync/ByLength.go
Normal file
16
Sync/ByLength.go
Normal file
@ -0,0 +1,16 @@
|
||||
package Sync
|
||||
|
||||
type ByLength []string
|
||||
|
||||
func (s ByLength) Len() int {
|
||||
return len(s)
|
||||
}
|
||||
|
||||
func (s ByLength) Swap(i, j int) {
|
||||
s[i], s[j] = s[j], s[i]
|
||||
}
|
||||
|
||||
// Longer strings will appear first.
|
||||
func (s ByLength) Less(i, j int) bool {
|
||||
return len(s[i]) > len(s[j])
|
||||
}
|
@ -2,8 +2,6 @@ package Sync
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/pkg/sftp"
|
||||
"golang.org/x/crypto/ssh"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
@ -11,6 +9,9 @@ import (
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/sftp"
|
||||
"golang.org/x/crypto/ssh"
|
||||
)
|
||||
|
||||
func Synchronise(ssh *ssh.Client, supervised, pushOnly bool, localDir, remoteDir string) {
|
||||
@ -156,7 +157,7 @@ func Synchronise(ssh *ssh.Client, supervised, pushOnly bool, localDir, remoteDir
|
||||
log.Printf("Found %d remote files to delete.\n", len(deleteRemoteFiles))
|
||||
|
||||
if len(deleteRemoteFiles) > 0 {
|
||||
sort.Strings(deleteRemoteFiles)
|
||||
sort.Sort(ByLength(deleteRemoteFiles))
|
||||
shouldDeleteRemoteFiles := true
|
||||
if supervised {
|
||||
fmt.Println(`=================================================================`)
|
||||
@ -193,7 +194,6 @@ func Synchronise(ssh *ssh.Client, supervised, pushOnly bool, localDir, remoteDir
|
||||
continue
|
||||
}
|
||||
|
||||
// TODO: Does not work: File an issue!
|
||||
removeError := sftp.Remove(normalised2remoteFiles[remoteFileNormalised] + `/`)
|
||||
if removeError != nil {
|
||||
log.Printf("Was not able to delete the remote directory %s: %s\n", normalised2remoteFiles[remoteFileNormalised], removeError.Error())
|
||||
|
Loading…
Reference in New Issue
Block a user