为什么我的 busybox diff 会为每个文件对报告“公共子目录”?

为什么我的 busybox diff 会为每个文件对报告“公共子目录”?

我正在 Synology NAS 上使用此版本diff来验证备份:

xyz> diff
BusyBox v1.16.1 (2014-05-29 11:26:15 CST) multi-call binary.

Usage: diff [-abBdiNqrTstw] [-L LABEL] [-S FILE] [-U LINES] FILE1 FILE2

Compare files line by line and output the differences between them.
This implementation supports unified diffs only.

Options:
        -a      Treat all files as text
        -b      Ignore changes in the amount of whitespace
        -B      Ignore changes whose lines are all blank
        -d      Try hard to find a smaller set of changes
        -i      Ignore case differences
        -L      Use LABEL instead of the filename in the unified header
        -N      Treat absent files as empty
        -q      Output only whether files differ
        -r      Recurse
        -S      Start with FILE when comparing directories
        -T      Make tabs line up by prefixing a tab when necessary
        -s      Report when two files are the same
        -t      Expand tabs to spaces in output
        -U      Output LINES lines of context
        -w      Ignore all whitespace

现在,我使用 比较了 NAS 上的两个文件夹diff -q -r /a /b | tee xyz.log。但是,此命令似乎只比较文件名,而不比较文件的内容,因为它会Common subdirectories /a/file.ext and /b/file.ext针对每个文件对进行报告 - 即大约 150,000 次。为什么不比较文件内容,我应该使用哪个命令?

答案1

我在使用 Synology NAS(BusyBox v1.16.1)时遇到了类似/相同的问题:

diff -arq Dropbox/abc/ library/abc/ > abc.diff

产生了很多条目,就像Common subdirectories: Dropbox/abc/yz/tuv.pdf and library/abc/yz/tuv.pdf即使所述文件处于xyz/tuv.pdfx丢失)状态。

但以下命令(没有尾随/)按预期工作:

diff -arq Dropbox/abc library/abc > abc.diff

答案2

您正在使用 diff 实用程序,操作正确。

似乎系统调用报告这些文件实际上是目录。这可能是系统中其他地方的问题,而不是 busybox diff 中的问题。

这一切都归结为 editors/diff.c 中的以下几行代码:

if (S_ISDIR(stb[0].st_mode) && S_ISDIR(stb[1].st_mode))
                printf("Common subdirectories: %s and %s\n", fullpath[0], fullpath[1]);

此外,如果您有任何 busybox 问题,您可以向邮件列表报告,并且任何 busybox diff 问题您都可以直接向我报告。

相关内容