Skip to content

Commit

Permalink
tail: remove manual polling
Browse files Browse the repository at this point in the history
  • Loading branch information
jhscheer committed Jun 15, 2022
1 parent 0c4bd9a commit f4359e2
Showing 1 changed file with 1 addition and 63 deletions.
64 changes: 1 addition & 63 deletions src/uu/tail/src/tail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -779,12 +779,6 @@ fn follow(files: &mut FileHandling, settings: &mut Settings) -> UResult<()> {
_timeout_counter = 0;
}

// Workarounds for limitations of `notify::PollWatcher`
if settings.use_polling {
// TODO: not necessary anymore since compare_contents: true ?
// manual_polling(files, settings)?;
}

let mut paths = vec![]; // Paths worth checking for new content to print
match rx_result {
Ok(Ok(event)) => {
Expand Down Expand Up @@ -857,62 +851,6 @@ fn follow(files: &mut FileHandling, settings: &mut Settings) -> UResult<()> {
Ok(())
}

/// Poll all watched files manually and check for events that
/// `Notify::PollWatcher` does not handle suitable to our use case
fn manual_polling(files: &mut FileHandling, settings: &Settings) -> UResult<()> {
if settings.follow.is_some() {
for path in &files
.keys()
.map(|p| p.to_path_buf())
.collect::<Vec<PathBuf>>()
{
if !path.exists() && settings.retry {
let pd = files.get(path);
if let Some(old_md) = &pd.metadata {
if old_md.is_tailable() && pd.reader.is_some() {
/*
NOTE: This is a workaround to pass: "gnu/tests/tail-2/F-vs-rename.sh"
For `mv a b` `notify::PollWatcher` handles events for b first, then a.
However, `F-vs-rename` requires the handling of events vice versa,
i.e. this test requires that "has [..] replaced/inaccessible" is
shown before new content is printed.
Without this `mv a b` would result in the contents of b being
printed before the "a has become inaccessible" message is shown.
*/
// show_error!(
// "{} {}: {}",
// pd.display_name.quote(),
// text::BECOME_INACCESSIBLE,
// text::NO_SUCH_FILE
// );
// files.reset_reader(path);
}
}
}
if let Ok(new_md) = path.metadata() {
let pd = files.get(path);
if let Some(old_md) = &pd.metadata {
if old_md.is_tailable()
&& new_md.is_tailable()
&& old_md.got_truncated(&new_md)?
{
/*
NOTE: This is a workaround because PollWatcher tends to miss events.
e.g. `echo "X1" > missing ; sleep 0.1 ; echo "X" > missing ;`
should trigger an event, but PollWatcher doesn't recognize it.
This is relevant to pass, e.g.: "gnu/tests/tail-2/truncate.sh"
*/
// show_error!("{}: file truncated", pd.display_name.display());
// files.update_metadata(path, Some(new_md));
// files.update_reader(path)?;
}
}
}
}
}
Ok(())
}

fn handle_event(
event: &notify::Event,
files: &mut FileHandling,
Expand Down Expand Up @@ -1619,7 +1557,7 @@ impl MetadataExtTail for Metadata {
use std::os::windows::prelude::*;
if let Some(self_id) = self.file_index() {
if let Some(other_id) = other.file_index() {
return self_id.eq(other_id);
return self_id.eq(&other_id);
}
}
false
Expand Down

0 comments on commit f4359e2

Please sign in to comment.