keg_relocate.rb: add binary_file? method
This commit is contained in:
parent
67512aed56
commit
3d2d1edaa3
@ -177,13 +177,18 @@ class Keg
|
|||||||
|
|
||||||
def egrep_args
|
def egrep_args
|
||||||
grep_bin = "grep"
|
grep_bin = "grep"
|
||||||
grep_args = recursive_fgrep_args
|
grep_args = [
|
||||||
grep_args += "Pa"
|
"--files-with-matches",
|
||||||
|
"--perl-regexp",
|
||||||
|
"--binary-files=text",
|
||||||
|
]
|
||||||
|
|
||||||
[grep_bin, grep_args]
|
[grep_bin, grep_args]
|
||||||
end
|
end
|
||||||
alias generic_egrep_args egrep_args
|
alias generic_egrep_args egrep_args
|
||||||
|
|
||||||
def each_unique_file(io, block)
|
def each_unique_file_matching(string)
|
||||||
|
Utils.popen_read("fgrep", recursive_fgrep_args, string, to_s) do |io|
|
||||||
hardlinks = Set.new
|
hardlinks = Set.new
|
||||||
|
|
||||||
until io.eof?
|
until io.eof?
|
||||||
@ -193,25 +198,18 @@ class Keg
|
|||||||
|
|
||||||
# To avoid returning hardlinks, only return files with unique inodes.
|
# To avoid returning hardlinks, only return files with unique inodes.
|
||||||
# Hardlinks will have the same inode as the file they point to.
|
# Hardlinks will have the same inode as the file they point to.
|
||||||
block.call file if hardlinks.add? file.stat.ino
|
yield file if hardlinks.add? file.stat.ino
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def each_unique_file_matching(string, &block)
|
def binary_file?(file)
|
||||||
Utils.popen_read("fgrep", recursive_fgrep_args, string, to_s) do |io|
|
|
||||||
each_unique_file(io, block)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def each_unique_binary_file(&block)
|
|
||||||
grep_bin, grep_args = egrep_args
|
grep_bin, grep_args = egrep_args
|
||||||
|
|
||||||
# We need to pass NULL_BYTE_STRING, the literal string "\x00", to grep
|
# We need to pass NULL_BYTE_STRING, the literal string "\x00", to grep
|
||||||
# rather than NULL_BYTE, a literal null byte, because grep will internally
|
# rather than NULL_BYTE, a literal null byte, because grep will internally
|
||||||
# convert the literal string "\x00" to a null byte.
|
# convert the literal string "\x00" to a null byte.
|
||||||
Utils.popen_read(grep_bin, grep_args, NULL_BYTE_STRING, to_s) do |io|
|
Utils.popen_read(grep_bin, *grep_args, NULL_BYTE_STRING, file).present?
|
||||||
each_unique_file(io, block)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def lib
|
def lib
|
||||||
|
Loading…
x
Reference in New Issue
Block a user