-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
503 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,9 @@ jobs: | |
- name: Build Release | ||
run: cargo build --verbose --release | ||
|
||
- name: Run `ark-cli watch` test | ||
run: ./integration/ark-cli-watch.sh | ||
|
||
- name: Install JDK | ||
uses: actions/[email protected] | ||
with: | ||
|
@@ -71,6 +74,9 @@ jobs: | |
- name: Run tests | ||
run: cargo test --workspace --verbose | ||
|
||
- name: Run `ark-cli watch` test | ||
run: ./integration/ark-cli-watch.sh | ||
|
||
- name: Install JDK | ||
uses: actions/[email protected] | ||
with: | ||
|
@@ -100,6 +106,9 @@ jobs: | |
- name: Run tests | ||
run: cargo test --workspace --verbose | ||
|
||
- name: Run `ark-cli watch` test | ||
run: ./integration/ark-cli-watch.sh | ||
|
||
- name: Install JDK | ||
uses: actions/[email protected] | ||
with: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
use std::path::PathBuf; | ||
|
||
use futures::{pin_mut, StreamExt}; | ||
|
||
use fs_index::{watch_index, WatchEvent}; | ||
|
||
use crate::{AppError, DateTime, ResourceId, Utc}; | ||
|
||
#[derive(Clone, Debug, clap::Args)] | ||
#[clap( | ||
name = "watch", | ||
about = "Watch the ark managed folder for changes and update the index accordingly" | ||
)] | ||
pub struct Watch { | ||
#[clap( | ||
help = "Path to the directory to watch for changes", | ||
default_value = ".", | ||
value_parser | ||
)] | ||
path: PathBuf, | ||
} | ||
|
||
impl Watch { | ||
pub async fn run(&self) -> Result<(), AppError> { | ||
let stream = watch_index::<_, ResourceId>(&self.path); | ||
pin_mut!(stream); | ||
|
||
while let Some(value) = stream.next().await { | ||
match value { | ||
WatchEvent::UpdatedOne(update) => { | ||
println!("Index updated with a single file change"); | ||
|
||
let added = update.added(); | ||
let removed = update.removed(); | ||
for file in added { | ||
let time_stamped_path = file.1.iter().next().unwrap(); | ||
let file_path = time_stamped_path.item(); | ||
let last_modified = time_stamped_path.last_modified(); | ||
let last_modified: DateTime<Utc> = last_modified.into(); | ||
println!( | ||
"\tAdded file: {:?} (last modified: {})", | ||
file_path, | ||
last_modified.format("%d/%m/%Y %T") | ||
); | ||
} | ||
for file in removed { | ||
println!("\tRemoved file with hash: {:?}", file); | ||
} | ||
} | ||
WatchEvent::UpdatedAll(update) => { | ||
println!("Index fully updated"); | ||
|
||
let added = update.added(); | ||
let removed = update.removed(); | ||
|
||
for file in added { | ||
let time_stamped_path = file.1.iter().next().unwrap(); | ||
let file_path = time_stamped_path.item(); | ||
let last_modified = time_stamped_path.last_modified(); | ||
println!( | ||
"\tAdded file: {:?} (last modified: {:?})", | ||
file_path, last_modified | ||
); | ||
} | ||
for file in removed { | ||
println!("\tRemoved file with hash: {:?}", file); | ||
} | ||
} | ||
} | ||
} | ||
|
||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use std::path::Path; | ||
|
||
use anyhow::Result; | ||
use futures::{pin_mut, StreamExt}; | ||
|
||
use dev_hash::Blake3; | ||
use fs_index::{watch_index, WatchEvent}; | ||
|
||
/// A simple example of using `watch_index` to monitor a directory for file | ||
/// changes. This asynchronously listens for updates and prints the paths of | ||
/// changed files. | ||
#[tokio::main] | ||
async fn main() -> Result<()> { | ||
env_logger::init(); | ||
|
||
// Change this to the path of the directory you want to watch | ||
let root = Path::new("test-assets"); | ||
|
||
let stream = watch_index::<_, Blake3>(root); | ||
|
||
pin_mut!(stream); // needed for iteration | ||
|
||
while let Some(value) = stream.next().await { | ||
match value { | ||
WatchEvent::UpdatedOne(update) => { | ||
println!("Updated file: {:?}", update); | ||
} | ||
WatchEvent::UpdatedAll(update) => { | ||
println!("Updated all: {:?}", update); | ||
} | ||
} | ||
} | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
mod index; | ||
mod serde; | ||
mod utils; | ||
#[cfg(feature = "watch")] | ||
mod watch; | ||
|
||
pub use index::{IndexUpdate, ResourceIndex}; | ||
pub use utils::load_or_build_index; | ||
|
||
pub use index::ResourceIndex; | ||
#[cfg(feature = "watch")] | ||
pub use watch::{watch_index, WatchEvent}; | ||
|
||
#[cfg(test)] | ||
mod tests; |
Oops, something went wrong.