Commit 374b469f authored by Stavros Korokithakis's avatar Stavros Korokithakis

Streamline IPFS execution

parent ea293044
......@@ -31,10 +31,11 @@ lazy_static! {
};
}
static IPFS_EXECUTABLE: &str = "ipfs";
fn add_files_to_ipfs() -> String {
println!("Adding files to IPFS...");
let output = Command::new("./ipfs")
let output = Command::new(IPFS_EXECUTABLE)
.env("IPFS_PATH", &*IPFS_PATH)
.args(&["add", "-r", "-Q", HEARTH_DIR.to_str().unwrap()])
.output()
......@@ -43,7 +44,6 @@ fn add_files_to_ipfs() -> String {
hash
}
fn notify_ipfs(event: notify::DebouncedEvent) {
match event {
notify::DebouncedEvent::Create(_) => {}
......@@ -52,30 +52,36 @@ fn notify_ipfs(event: notify::DebouncedEvent) {
notify::DebouncedEvent::Write(_) => {}
_ => return,
}
println!("https://www.eternum.io/ipfs/{}", add_files_to_ipfs());
let hash = add_files_to_ipfs();
println!("https://www.eternum.io/ipfs/{}", hash);
}
fn spawn_ipfs_thread() {
thread::spawn(move || {
println!("Initializing IPFS...");
Command::new("./ipfs")
Command::new(IPFS_EXECUTABLE)
.env("IPFS_PATH", &*IPFS_PATH)
.args(&["init"])
.output()
.expect("Could not initialize IPFS.");
.unwrap_or_else(|_| {
println!("Could not initialize IPFS.");
process::exit(1)
});
println!("Starting IPFS daemon...");
Command::new("./ipfs")
Command::new(IPFS_EXECUTABLE)
.env("IPFS_PATH", &*IPFS_PATH)
.args(&["daemon", "--writable", "--enable-gc"])
.output()
.expect("Could not launch IPFS daemon.");
.unwrap_or_else(|_| {
println!("Could not launch IPFS daemon.");
process::exit(1)
});
});
}
fn main() {
println!("Starting hearth...");
......@@ -98,7 +104,8 @@ fn main() {
// Add a path to be watched. All files and directories at that path and
// below will be monitored for changes.
watcher.watch(&*HEARTH_DIR, RecursiveMode::Recursive)
watcher
.watch(&*HEARTH_DIR, RecursiveMode::Recursive)
.expect("There was an error when trying to watch the Hearth directory for changes.");
loop {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment