Skip to content
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

difference is ignored when it exists after the block size #16

Open
kmuto opened this issue Nov 17, 2021 · 0 comments
Open

difference is ignored when it exists after the block size #16

kmuto opened this issue Nov 17, 2021 · 0 comments
Labels

Comments

@kmuto
Copy link

kmuto commented Nov 17, 2021

Describe the problem

If there is a difference after the block size (4096 on my Linux filesystem), it will be ignored.

Steps to reproduce the problem

I created a small test.

./diff.rb
SHA1 sum for 4096-a.txt: 8c92a77e8e627a3977d35e0c4e4bd8a3c30e1a08
SHA1 sum for 4096-b.txt: 74e5a50dfc7a0e68c02396776e395a3ef5eff0a3
        diff  4096-a.txt and 4096-b.txt
No differences found

4096-a.txt

aaa...(repeats 4096 times)..aaaA

4096-b.txt

aaa...(repeats 4096 times)..aaaB

check

TTY::File.diff("4096-a.txt", "4096-b.txt")

Actual behaviour

diff is ignored.

Expected behaviour

The diff check continues after the first block size.

I suspect lib/tty/file/compare_files.rb :32

      def call(file_a, file_b, file_a_path, file_b_path)
        differ = Differ.new(format: @format, context_lines: @context_lines)
        block_size = file_a.lstat.blksize
        file_a_chunk = file_a.read(block_size)
        file_b_chunk = file_b.read(block_size)
        hunks = differ.(file_a_chunk, file_b_chunk)

        return "" if file_a_chunk.empty? && file_b_chunk.empty?
        return "No differences found\n" if hunks.empty? <-- **

It worked when I commented out this line, but not sure what this code intended.

Describe your environment

  • OS version: Debian GNU/Linux 11.1
  • Ruby version:2.7.4
  • TTY::File version:0.10.0
    diff.zip
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant