New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Name all threads #383
Merged
Merged
Name all threads #383
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
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 |
---|---|---|
|
@@ -76,106 +76,113 @@ impl PollWatcher { | |
let event_handler = self.event_handler.clone(); | ||
let event_handler = move |res| emit_event(&event_handler, res); | ||
|
||
thread::spawn(move || { | ||
// In order of priority: | ||
// TODO: handle metadata events | ||
// TODO: handle renames | ||
// TODO: DRY it up | ||
let _ = thread::Builder::new() | ||
.name("notify-rs poll loop".to_string()) | ||
.spawn(move || { | ||
// In order of priority: | ||
// TODO: handle metadata events | ||
// TODO: handle renames | ||
// TODO: DRY it up | ||
|
||
loop { | ||
if !open.load(Ordering::SeqCst) { | ||
break; | ||
} | ||
loop { | ||
if !open.load(Ordering::SeqCst) { | ||
break; | ||
} | ||
|
||
if let Ok(mut watches) = watches.lock() { | ||
let current_time = Instant::now(); | ||
if let Ok(mut watches) = watches.lock() { | ||
let current_time = Instant::now(); | ||
|
||
for ( | ||
watch, | ||
&mut WatchData { | ||
is_recursive, | ||
ref mut paths, | ||
}, | ||
) in watches.iter_mut() | ||
{ | ||
match fs::metadata(watch) { | ||
Err(e) => { | ||
let err = Err(Error::io(e).add_path(watch.clone())); | ||
event_handler(err); | ||
continue; | ||
} | ||
Ok(metadata) => { | ||
if !metadata.is_dir() { | ||
let mtime = | ||
FileTime::from_last_modification_time(&metadata).seconds(); | ||
match paths.insert( | ||
watch.clone(), | ||
PathData { | ||
mtime, | ||
last_check: current_time, | ||
}, | ||
) { | ||
None => { | ||
unreachable!(); | ||
} | ||
Some(PathData { | ||
mtime: old_mtime, .. | ||
}) => { | ||
if mtime > old_mtime { | ||
let kind = MetadataKind::WriteTime; | ||
let meta = ModifyKind::Metadata(kind); | ||
let kind = EventKind::Modify(meta); | ||
let ev = Event::new(kind).add_path(watch.clone()); | ||
event_handler(Ok(ev)); | ||
for ( | ||
watch, | ||
&mut WatchData { | ||
is_recursive, | ||
ref mut paths, | ||
}, | ||
) in watches.iter_mut() | ||
{ | ||
match fs::metadata(watch) { | ||
Err(e) => { | ||
let err = Err(Error::io(e).add_path(watch.clone())); | ||
event_handler(err); | ||
continue; | ||
} | ||
Ok(metadata) => { | ||
if !metadata.is_dir() { | ||
let mtime = | ||
FileTime::from_last_modification_time(&metadata) | ||
.seconds(); | ||
match paths.insert( | ||
watch.clone(), | ||
PathData { | ||
mtime, | ||
last_check: current_time, | ||
}, | ||
) { | ||
None => { | ||
unreachable!(); | ||
} | ||
Some(PathData { | ||
mtime: old_mtime, .. | ||
}) => { | ||
if mtime > old_mtime { | ||
let kind = MetadataKind::WriteTime; | ||
let meta = ModifyKind::Metadata(kind); | ||
let kind = EventKind::Modify(meta); | ||
let ev = | ||
Event::new(kind).add_path(watch.clone()); | ||
event_handler(Ok(ev)); | ||
} | ||
} | ||
} | ||
} | ||
} else { | ||
let depth = if is_recursive { usize::max_value() } else { 1 }; | ||
for entry in WalkDir::new(watch) | ||
.follow_links(true) | ||
.max_depth(depth) | ||
.into_iter() | ||
.filter_map(|e| e.ok()) | ||
{ | ||
let path = entry.path(); | ||
} else { | ||
let depth = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here for the newline |
||
if is_recursive { usize::max_value() } else { 1 }; | ||
for entry in WalkDir::new(watch) | ||
.follow_links(true) | ||
.max_depth(depth) | ||
.into_iter() | ||
.filter_map(|e| e.ok()) | ||
{ | ||
let path = entry.path(); | ||
|
||
match entry.metadata() { | ||
Err(e) => { | ||
let err = Error::io(e.into()) | ||
.add_path(path.to_path_buf()); | ||
event_handler(Err(err)); | ||
} | ||
Ok(m) => { | ||
let mtime = | ||
FileTime::from_last_modification_time(&m) | ||
.seconds(); | ||
match paths.insert( | ||
path.to_path_buf(), | ||
PathData { | ||
mtime, | ||
last_check: current_time, | ||
}, | ||
) { | ||
None => { | ||
let kind = | ||
EventKind::Create(CreateKind::Any); | ||
let ev = Event::new(kind) | ||
.add_path(path.to_path_buf()); | ||
event_handler(Ok(ev)); | ||
} | ||
Some(PathData { | ||
mtime: old_mtime, .. | ||
}) => { | ||
if mtime > old_mtime { | ||
let kind = MetadataKind::WriteTime; | ||
let meta = ModifyKind::Metadata(kind); | ||
let kind = EventKind::Modify(meta); | ||
// TODO add new mtime as attr | ||
match entry.metadata() { | ||
Err(e) => { | ||
let err = Error::io(e.into()) | ||
.add_path(path.to_path_buf()); | ||
event_handler(Err(err)); | ||
} | ||
Ok(m) => { | ||
let mtime = | ||
FileTime::from_last_modification_time(&m) | ||
.seconds(); | ||
match paths.insert( | ||
path.to_path_buf(), | ||
PathData { | ||
mtime, | ||
last_check: current_time, | ||
}, | ||
) { | ||
None => { | ||
let kind = | ||
EventKind::Create(CreateKind::Any); | ||
let ev = Event::new(kind) | ||
.add_path(path.to_path_buf()); | ||
event_handler(Ok(ev)); | ||
} | ||
Some(PathData { | ||
mtime: old_mtime, .. | ||
}) => { | ||
if mtime > old_mtime { | ||
let kind = MetadataKind::WriteTime; | ||
let meta = | ||
ModifyKind::Metadata(kind); | ||
let kind = EventKind::Modify(meta); | ||
// TODO add new mtime as attr | ||
let ev = Event::new(kind) | ||
.add_path(path.to_path_buf()); | ||
event_handler(Ok(ev)); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
@@ -184,27 +191,26 @@ impl PollWatcher { | |
} | ||
} | ||
} | ||
} | ||
|
||
for (_, &mut WatchData { ref mut paths, .. }) in watches.iter_mut() { | ||
let mut removed = Vec::new(); | ||
for (path, &PathData { last_check, .. }) in paths.iter() { | ||
if last_check < current_time { | ||
let ev = Event::new(EventKind::Remove(RemoveKind::Any)) | ||
.add_path(path.clone()); | ||
event_handler(Ok(ev)); | ||
removed.push(path.clone()); | ||
for (_, &mut WatchData { ref mut paths, .. }) in watches.iter_mut() { | ||
let mut removed = Vec::new(); | ||
for (path, &PathData { last_check, .. }) in paths.iter() { | ||
if last_check < current_time { | ||
let ev = Event::new(EventKind::Remove(RemoveKind::Any)) | ||
.add_path(path.clone()); | ||
event_handler(Ok(ev)); | ||
removed.push(path.clone()); | ||
} | ||
} | ||
for path in removed { | ||
(*paths).remove(&path); | ||
} | ||
} | ||
for path in removed { | ||
(*paths).remove(&path); | ||
} | ||
} | ||
} | ||
|
||
thread::sleep(delay); | ||
} | ||
}); | ||
thread::sleep(delay); | ||
} | ||
}); | ||
} | ||
|
||
fn watch_inner(&mut self, path: &Path, recursive_mode: RecursiveMode) -> Result<()> { | ||
|
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is all this indentation noise from rustfmt ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah - it just jumps in a bit because the scope block indents one further.