Skip to content

Commit

Permalink
fix(recompile): not skipping file modifications
Browse files Browse the repository at this point in the history
  • Loading branch information
kkharji committed May 18, 2022
1 parent 38f14e4 commit 4abadd6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/watcher/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ async fn should_skip_event<'a>(
};

if !(last_run > 1) {
tracing::debug!("{:?}, paths: {:?}", event.kind, &event.paths);
tracing::debug!("Skipping {:?}, paths: {:?}", event.kind, &event.paths);
tracing::trace!("pass_threshold: {last_run}, {:?}", event);
return (Some(path), true);
}
Expand Down
26 changes: 10 additions & 16 deletions src/watcher/handle/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@ pub async fn create(args: WatchArguments) -> Result<(), WatchError> {
let Client { root, .. } = info.try_into_project()?;

if should_skip_compile(&event, &path, args.last_seen).await {
tracing::debug!("Skipping {:?}", &event.paths);
return Ok(());
}

tracing::trace!("[NewEvent] {:#?}", &event);

let ref name = root.file_name().unwrap().to_string_lossy().to_string();
let ref mut state = DAEMON_STATE.clone().lock_owned().await;
let mut debounce = args.debounce.lock().await;
Expand All @@ -42,53 +45,44 @@ pub async fn create(args: WatchArguments) -> Result<(), WatchError> {
}

async fn should_skip_compile(event: &Event, path: &PathBuf, last_seen: Arc<Mutex<String>>) -> bool {
tracing::trace!("[NewEvent] {:#?}", &event);

let skip = match &event.kind {
match &event.kind {
EventKind::Create(_) => {
tokio::time::sleep(Duration::new(1, 0)).await;
tracing::debug!("[FileCreated]: {:?}", path);
false
}

EventKind::Remove(_) => {
tokio::time::sleep(Duration::new(1, 0)).await;
tracing::debug!("[FileRemoved]: {:?}", path);
false
}

EventKind::Modify(m) => match m {
ModifyKind::Data(e) => match e {
DataChange::Content => {
if !path.display().to_string().contains("project.yml") {
true;
return true;
}
tokio::time::sleep(Duration::new(1, 0)).await;
tracing::debug!("[XcodeGenConfigUpdate]");
// HACK: Not sure why, but this is needed because xcodegen break.
false
}
_ => true,
_ => return true,
},

ModifyKind::Name(_) => {
let path_string = path.to_string_lossy();
// HACK: only account for new path and skip duplications
if !path.exists() || is_seen(last_seen.clone(), &path_string).await {
true;
return true;
}
tokio::time::sleep(Duration::new(1, 0)).await;
tracing::debug!("[FileRenamed]: {:?}", path);
false
}
_ => true,
_ => return true,
},

_ => true,
_ => return true,
};

if skip {
tracing::trace!("Skipping {:#?}", &event);
}
skip
false
}

0 comments on commit 4abadd6

Please sign in to comment.