Browse Source

git begin

fix-typo
Coin de Gamma 3 months ago
parent
commit
b1de728eb9
  1. 39
      src/git.rs
  2. 6
      src/paths.rs
  3. 3
      src/storage.rs

39
src/git.rs

@ -1,5 +1,6 @@
use std::process::Command;
use crate::paths;
use std::process::Command;
use std::io;
@ -7,12 +8,38 @@ pub struct Git {
}
impl Git {
pub fn commit(db_path: String) -> io::Result<()> {
// TODO: impllement
// Command::new("git")
// .arg("add")
pub fn sync() -> io::Result<()> {
let sp = paths::get_storage_path()?;
Command::new("git")
.arg("add")
.arg(paths::PATH_DB)
.current_dir(&sp)
.status()
.map_err(|e| io::Error::new(
io::ErrorKind::Other,
format!("Failed to execute git add: {}", e)
))?;
Command::new("git")
.arg("commit")
.arg("-m")
.arg("\"sync\"")
.current_dir(&sp)
.status()
.map_err(|e| io::Error::new(
io::ErrorKind::Other,
format!("Failed to execute git commit: {}", e)
))?;
Command::new("git")
.arg("push")
.arg(paths::PATH_DB)
.current_dir(&sp)
.status()
.map_err(|e| io::Error::new(
io::ErrorKind::Other,
format!("Failed to execute git push: {}", e)
))?;
Ok(())
}
}

6
src/paths.rs

@ -2,10 +2,10 @@ use std::env;
use std::io;
static ENV_MPS_HOME: &str = "MPS_HOME";
pub static ENV_MPS_HOME: &str = "MPS_HOME";
static PATH_STORAGE: &str = "storage"; // should be under git
static PATH_DB: &str = "db.mps";
pub static PATH_STORAGE: &str = "storage"; // should be under git
pub static PATH_DB: &str = "db.mps";
pub fn get_storage_path() -> io::Result<String> {

3
src/storage.rs

@ -3,7 +3,6 @@ use crate::encoder;
use crate::git;
use encoder::Encoder;
use git::Git;
use std::collections::HashSet;
use std::hash::{Hash, Hasher};
@ -202,7 +201,7 @@ impl Storage {
let content = self.encoder.encrypt(&item.content)?;
writeln!(file, "{}", content)?;
}
// TODO: run git commit
git::Git::sync()?;
Ok(())
}
}

Loading…
Cancel
Save