master
Spencer Kohan 4 years ago
parent 84402e475f
commit d007e8b6c2

@ -21,8 +21,6 @@ pub struct CliOptions {
pub subcommand: Option<SubCommand> pub subcommand: Option<SubCommand>
} }
#[derive(Debug)] #[derive(Debug)]
#[derive(StructOpt)] #[derive(StructOpt)]
#[derive(Clone)] #[derive(Clone)]

@ -1,10 +1,7 @@
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::fs; use std::fs;
use std::path::PathBuf; use std::path::PathBuf;
use crate::cli::RemoteConfigRecord; use crate::cli::RemoteConfigRecord;
// use std::error::Error;
// use ssh_config::SSHConfig;
use crate::cli::CliOptions; use crate::cli::CliOptions;
@ -29,7 +26,6 @@ impl Config {
} }
} }
impl RemoteConfigRecord { impl RemoteConfigRecord {
fn host_string(&self) -> String { fn host_string(&self) -> String {
let mut s: String = String::new(); let mut s: String = String::new();
@ -48,10 +44,8 @@ pub struct SessionConfig {
pub local_root: String, pub local_root: String,
pub remote: RemoteConfigRecord, pub remote: RemoteConfigRecord,
pub ignore_gitignore: bool, pub ignore_gitignore: bool,
} }
impl SessionConfig { impl SessionConfig {
pub fn host_port_string(&self) -> String { pub fn host_port_string(&self) -> String {

@ -16,18 +16,11 @@ fn create_dirsync_dirs() -> Result<(), std::io::Error> {
} }
pub fn init_dirsync_dir(remote_options: RemoteConfigRecord) -> Result<(), InitError> { pub fn init_dirsync_dir(remote_options: RemoteConfigRecord) -> Result<(), InitError> {
create_dirsync_dirs().map_err(|err| InitError::Io(err))?; create_dirsync_dirs().map_err(|err| InitError::Io(err))?;
let _ignore_file = File::create("./.dirsync/ignore").map_err(|err| InitError::Io(err))?; let _ignore_file = File::create("./.dirsync/ignore").map_err(|err| InitError::Io(err))?;
let mut config_file = File::create("./.dirsync/config.json").map_err(|err| InitError::Io(err))?; let mut config_file = File::create("./.dirsync/config.json").map_err(|err| InitError::Io(err))?;
let config = Config::new(remote_options); let config = Config::new(remote_options);
let json = serde_json::to_string_pretty(&config).map_err(|err| InitError::Serde(err))?; let json = serde_json::to_string_pretty(&config).map_err(|err| InitError::Serde(err))?;
config_file.write_all(json.as_bytes()).map_err(|err| InitError::Io(err))?; config_file.write_all(json.as_bytes()).map_err(|err| InitError::Io(err))?;
Ok(()) Ok(())
} }

@ -89,7 +89,6 @@ fn filter(event: DebouncedEvent) -> Option<DebouncedEvent> {
fn start_main_loop(config: &SessionConfig) { fn start_main_loop(config: &SessionConfig) {
println!("config: {:?}", config); println!("config: {:?}", config);
rsync(&config); rsync(&config);
@ -122,7 +121,6 @@ fn start_main_loop(config: &SessionConfig) {
fn main() { fn main() {
let opts = CliOptions::from_args(); let opts = CliOptions::from_args();
match opts.subcommand { match opts.subcommand {

@ -3,33 +3,10 @@ use std::io::prelude::*;
use std::net::TcpStream; use std::net::TcpStream;
use std::path::PathBuf; use std::path::PathBuf;
use ssh2::Session; use ssh2::Session;
use ssh2::ExtendedData; use ssh2::ExtendedData;
use crate::config::SessionConfig; use crate::config::SessionConfig;
// pub fn echo() {
// let tcp = TcpStream::connect("pc:22").unwrap();
// let mut sess = Session::new().unwrap();
// sess.set_tcp_stream(tcp);
// sess.handshake().unwrap();
// // Try to authenticate with the first identity in the agent.
// sess.userauth_agent("skohan").unwrap();
// // Make sure we succeeded
// assert!(sess.authenticated());
// let mut channel = sess.channel_session().unwrap();
// channel.exec("ls").unwrap();
// let mut s = String::new();
// channel.read_to_string(&mut s).unwrap();
// println!("{}", s);
// channel.wait_close();
// println!("{}", channel.exit_status().unwrap());
// }
pub struct Remote { pub struct Remote {
session: ssh2::Session, session: ssh2::Session,
@ -40,7 +17,6 @@ impl Remote {
// todo: this shouold take configuration arguemnts // todo: this shouold take configuration arguemnts
pub fn connect(config: &SessionConfig) -> Remote { pub fn connect(config: &SessionConfig) -> Remote {
let tcp = TcpStream::connect( let tcp = TcpStream::connect(
&config.host_port_string().as_str() &config.host_port_string().as_str()
).unwrap(); ).unwrap();
@ -61,11 +37,9 @@ impl Remote {
session: sess, session: sess,
root: root root: root
} }
} }
fn exec(&mut self, command: &str) -> String { fn exec(&mut self, command: &str) -> String {
let path = self.root.clone(); let path = self.root.clone();
let path_str = path.to_str().unwrap(); let path_str = path.to_str().unwrap();
let cmd = &format!("cd {} && {}", &path_str, &command); let cmd = &format!("cd {} && {}", &path_str, &command);
@ -124,7 +98,6 @@ impl Remote {
let command2 = &format!("{}", &path_str); let command2 = &format!("{}", &path_str);
self.exec_stream(&command2); self.exec_stream(&command2);
} }
} }
Loading…
Cancel
Save