Skip to content

Commit

Permalink
tail: Fix argument parsing follow mode is not correctly parsed when -…
Browse files Browse the repository at this point in the history
…F together --retry
  • Loading branch information
Joining7943 committed Nov 10, 2022
1 parent 7ab5353 commit 0b07e57
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/uu/tail/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ impl Settings {
};

settings.retry =
matches.get_flag(options::RETRY) || matches.get_flag(options::FOLLOW_RETRY);
matches.get_flag(options::FOLLOW_RETRY) || matches.get_flag(options::RETRY);

if let Some(string) = matches.get_one::<String>(options::SLEEP_INT) {
settings.sleep_sec = match parse_duration(string) {
Expand Down Expand Up @@ -553,7 +553,6 @@ pub fn uu_app() -> Command {
Arg::new(options::FOLLOW_RETRY)
.short('F')
.help("Same as --follow=name --retry")
.overrides_with_all([options::RETRY, options::FOLLOW])
.action(ArgAction::SetTrue),
)
.arg(
Expand Down
25 changes: 25 additions & 0 deletions tests/by-util/test_tail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4628,6 +4628,30 @@ fn test_follow_when_file_and_symlink_are_pointing_to_same_file_and_append_data()
runner.assert_stdout_stderr(expected_stdout.as_str(), "");
}

#[test]
fn test_args_when_directory_given_shorthand_big_f_together_with_retry() {
let mut runner = TestRunner::new();

let dirname = "dir";
runner.fixtures().mkdir(dirname);
let expected_stdout = format!(
"tail: error reading '{0}': Is a directory\n\
tail: {0}: cannot follow end of this type of file\n",
dirname
);

runner
.retry(true)
.extra_args(&["-F"])
.files(&["dir"])
.stderr_to_stdout()
.run_no_wait(200);

runner.assert_alive();
runner.kill(true).unwrap();
runner.assert_stdout(&expected_stdout);
}

/// Fails on macos sometimes with
/// Diff < left / right > :
/// ==> data <==
Expand All @@ -4636,6 +4660,7 @@ fn test_follow_when_file_and_symlink_are_pointing_to_same_file_and_append_data()
/// <file datasame data
/// >file data
#[test]
#[cfg(not(target_vendor = "apple"))]
fn test_follow_when_files_are_pointing_to_same_relative_file_and_file_stays_same_size() {
let mut runner = TestRunner::new();

Expand Down

0 comments on commit 0b07e57

Please sign in to comment.