Skip to content

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

@kmuto

Description

@kmuto

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions