master
Spencer Kohan 4 years ago
parent 84402e475f
commit d007e8b6c2

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

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

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

@ -3,33 +3,10 @@ use std::io::prelude::*;
use std::net::TcpStream;
use std::path::PathBuf;
use ssh2::Session;
use ssh2::ExtendedData;
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 {
session: ssh2::Session,
@ -40,7 +17,6 @@ impl Remote {
// todo: this shouold take configuration arguemnts
pub fn connect(config: &SessionConfig) -> Remote {
let tcp = TcpStream::connect(
&config.host_port_string().as_str()
).unwrap();
@ -61,11 +37,9 @@ impl Remote {
session: sess,
root: root
}
}
fn exec(&mut self, command: &str) -> String {
let path = self.root.clone();
let path_str = path.to_str().unwrap();
let cmd = &format!("cd {} && {}", &path_str, &command);
@ -124,7 +98,6 @@ impl Remote {
let command2 = &format!("{}", &path_str);
self.exec_stream(&command2);
}
}
Loading…
Cancel
Save