Version 1.1.0

Updated all libraries to the current versions. Thus, the deletion of remote directories now works. Also, several additional bugs are now fixed by these external libraries. Thanks to the contributors for the good work.
This commit is contained in:
Thorsten Sommer 2016-03-15 17:58:51 +01:00
parent 312538a10f
commit 231e3c69f4

200
Main.go
View File

@ -1,100 +1,100 @@
package main package main
import ( import (
"fmt" "fmt"
"github.com/SommerEngineering/Sync/Sync" "github.com/SommerEngineering/Sync/Sync"
"golang.org/x/crypto/ssh" "golang.org/x/crypto/ssh"
"log" "log"
"os" "os"
"runtime" "runtime"
) )
func main() { func main() {
// Show the current version: // Show the current version:
log.Println(`Sync v1.0.0`) log.Println(`Sync v1.1.0`)
// Allow Go to use all CPUs: // Allow Go to use all CPUs:
runtime.GOMAXPROCS(runtime.NumCPU()) runtime.GOMAXPROCS(runtime.NumCPU())
// Read the configuration from the command-line args: // Read the configuration from the command-line args:
readFlags() readFlags()
// Check if the directories are provided: // Check if the directories are provided:
if localDir == `` || remoteDir == `` { if localDir == `` || remoteDir == `` {
log.Println(`Please provide the local and remote directory.`) log.Println(`Please provide the local and remote directory.`)
return return
} }
// Should I use the current working dir? // Should I use the current working dir?
if localDir == `.` { if localDir == `.` {
if currentWD, currentWDError := os.Getwd(); currentWDError != nil { if currentWD, currentWDError := os.Getwd(); currentWDError != nil {
log.Println("Cannot use the current working directory as local directory: " + currentWDError.Error()) log.Println("Cannot use the current working directory as local directory: " + currentWDError.Error())
return return
} else { } else {
log.Println("I use the current working directory as local directory: " + currentWD) log.Println("I use the current working directory as local directory: " + currentWD)
localDir = currentWD localDir = currentWD
} }
} }
// Remove trailing separators from both directories // Remove trailing separators from both directories
localDir = correctPath(localDir) localDir = correctPath(localDir)
remoteDir = correctPath(remoteDir) remoteDir = correctPath(remoteDir)
// Check if local dir exist // Check if local dir exist
if dirInfo, dirError := os.Stat(localDir); dirError != nil { if dirInfo, dirError := os.Stat(localDir); dirError != nil {
log.Println("There is an error with the local directory: " + dirError.Error()) log.Println("There is an error with the local directory: " + dirError.Error())
return return
} else { } else {
if !dirInfo.IsDir() { if !dirInfo.IsDir() {
log.Println("There is an error with the local directory: You provided a file instead!") log.Println("There is an error with the local directory: You provided a file instead!")
return return
} }
} }
// Check if the password was provided: // Check if the password was provided:
for true { for true {
if password == `` { if password == `` {
// Promt for the password: // Promt for the password:
fmt.Print(`Please provide the password for the connection: `) fmt.Print(`Please provide the password for the connection: `)
fmt.Scanln(&password) fmt.Scanln(&password)
} else { } else {
break break
} }
} }
// Give some information about the state // Give some information about the state
if supervised { if supervised {
log.Println("I use the supervised mode.") log.Println("I use the supervised mode.")
} else { } else {
log.Println("I do not use the supervised mode.") log.Println("I do not use the supervised mode.")
} }
if pushOnly { if pushOnly {
log.Println("I use the push only mode i.e. backup mode. Any remote change will be ignored.") log.Println("I use the push only mode i.e. backup mode. Any remote change will be ignored.")
} else { } else {
log.Println("I use the full mode and consider also remote changes.") log.Println("I use the full mode and consider also remote changes.")
} }
// Create the SSH configuration: // Create the SSH configuration:
Sync.SetPassword4Callback(password) Sync.SetPassword4Callback(password)
config := &ssh.ClientConfig{ config := &ssh.ClientConfig{
User: username, User: username,
Auth: []ssh.AuthMethod{ Auth: []ssh.AuthMethod{
ssh.Password(password), ssh.Password(password),
ssh.PasswordCallback(Sync.PasswordCallback), ssh.PasswordCallback(Sync.PasswordCallback),
ssh.KeyboardInteractive(Sync.KeyboardInteractiveChallenge), ssh.KeyboardInteractive(Sync.KeyboardInteractiveChallenge),
}, },
} }
// Connect to the SSH server: // Connect to the SSH server:
ssh := Sync.ConnectSSH(config, serverAddrString) ssh := Sync.ConnectSSH(config, serverAddrString)
if ssh == nil { if ssh == nil {
log.Println(`It was not possible to connect to the SSH server.`) log.Println(`It was not possible to connect to the SSH server.`)
return return
} }
defer ssh.Close() defer ssh.Close()
Sync.Synchronise(ssh, supervised, pushOnly, localDir, remoteDir) Sync.Synchronise(ssh, supervised, pushOnly, localDir, remoteDir)
log.Println("Synchronising done.") log.Println("Synchronising done.")
} }