mirror of
https://github.com/chromebrew/chromebrew.git
synced 2026-01-09 15:37:56 -05:00
deb_utils: Ignore trailing newline (#6880)
* deb_utils: Ignore trailing newline * Fix trailing newline detection * Change comment location
This commit is contained in:
@@ -12,6 +12,7 @@ module DebUtils
|
|||||||
#
|
#
|
||||||
file_found = false
|
file_found = false
|
||||||
src_fileIO = File.open(file, 'rb')
|
src_fileIO = File.open(file, 'rb')
|
||||||
|
file_size = src_fileIO.size
|
||||||
# get first line of the given file, should be a signature string (`!<arch>\n`) if it is a valid deb file
|
# get first line of the given file, should be a signature string (`!<arch>\n`) if it is a valid deb file
|
||||||
signature = src_fileIO.gets
|
signature = src_fileIO.gets
|
||||||
|
|
||||||
@@ -19,13 +20,21 @@ module DebUtils
|
|||||||
|
|
||||||
# process each file in archive
|
# process each file in archive
|
||||||
while (line = src_fileIO.gets) do
|
while (line = src_fileIO.gets) do
|
||||||
|
if line.chomp.empty? and file_size == src_fileIO.tell
|
||||||
|
# early return if trailing newline is detected
|
||||||
|
break
|
||||||
|
elsif line.chomp.empty?
|
||||||
|
STDERR.puts "Unexpected newline in offset #{src_fileIO.tell}, ignoring...".yellow
|
||||||
|
next
|
||||||
|
end
|
||||||
|
|
||||||
# read file meta
|
# read file meta
|
||||||
name, modtime, uid, gid, mode, size, end_char = \
|
name, modtime, uid, gid, mode, size, end_char = \
|
||||||
line.scan(/(.{16})(.{12})(.{6})(.{6})(.{8})(.{10})(.{1})/).flatten.map(&:strip)
|
line.scan(/(.{16})(.{12})(.{6})(.{6})(.{8})(.{10})(.{1})/).flatten.map(&:strip)
|
||||||
|
|
||||||
# remove slash suffix from filename (if any)
|
# remove slash suffix from filename (if any)
|
||||||
# (a `.deb` ar archive does not support any directories, so we can confirm that all entries are normal files)
|
# (a `.deb` ar archive does not support any directories, so we can confirm that all entries are normal files)
|
||||||
name.sub!(/\/$/, '')
|
name&.sub!(/\/$/, '')
|
||||||
|
|
||||||
# check ending byte
|
# check ending byte
|
||||||
abort 'Malformed archive :/'.lightred unless end_char == '`'
|
abort 'Malformed archive :/'.lightred unless end_char == '`'
|
||||||
|
|||||||
Reference in New Issue
Block a user