Commit d90e7b51 authored by Stavros Korokithakis's avatar Stavros Korokithakis

Streamline the console message production

parent d3678595
......@@ -74,18 +74,11 @@ fn add_files_to_ipfs() {
}));
}
fn files_changed(event: notify::DebouncedEvent, add_to_ipfs: bool) {
// This function gets triggered when inotify notices files having changed.
fn notify_ipfs(add_to_ipfs: bool) {
// Emit messages to the console and add files to IPFS.
//
// add_to_ipfs will be true when we actually need to add the files to IPFS (ie when enough time
// has passed after debouncing).
match event {
notify::DebouncedEvent::Create(_) => {}
notify::DebouncedEvent::Remove(_) => {}
notify::DebouncedEvent::Rename(_, _) => {}
notify::DebouncedEvent::Write(_) => {}
_ => return,
}
// This does the proper debouncing (on top of the inotify debouncer) to emit the necessary
// messages to the console when we are expecting changes/are done with changes.
// If the variable wasn't updated, there's nothing for us to do.
if DEBOUNCING_DONE.compare_and_swap(!add_to_ipfs, add_to_ipfs, Ordering::Relaxed) == add_to_ipfs {
......@@ -100,6 +93,22 @@ fn files_changed(event: notify::DebouncedEvent, add_to_ipfs: bool) {
}
}
fn files_changed(event: notify::DebouncedEvent, add_to_ipfs: bool) {
// This function gets triggered when inotify notices files having changed.
//
// add_to_ipfs will be true when we actually need to add the files to IPFS (ie when enough time
// has passed after debouncing).
match event {
notify::DebouncedEvent::Create(_) => {}
notify::DebouncedEvent::Remove(_) => {}
notify::DebouncedEvent::Rename(_, _) => {}
notify::DebouncedEvent::Write(_) => {}
_ => return,
}
notify_ipfs(add_to_ipfs);
}
fn start_ipfs() {
println!("Initializing IPFS...");
......@@ -114,11 +123,14 @@ fn start_ipfs() {
println!("Starting IPFS daemon...");
// Print the correct message to the console because we'll add some files.
notify_ipfs(false);
// Add everything, because files might have been changed while we weren't looking.
thread::spawn(|| {
// Wait for the daemon to start up...
thread::sleep(Duration::from_millis(5000));
add_files_to_ipfs();
notify_ipfs(true);
});
let output = Command::new(IPFS_EXECUTABLE)
......
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