dumpert voor mlocate databases
This commit is contained in:
parent
6061f7e14e
commit
7b0f469d24
1 changed files with 98 additions and 0 deletions
98
mlocatedb-dump/mlocatedb-dump.rb
Executable file
98
mlocatedb-dump/mlocatedb-dump.rb
Executable file
|
|
@ -0,0 +1,98 @@
|
||||||
|
#!/usr/bin/env ruby
|
||||||
|
|
||||||
|
# $Id$
|
||||||
|
# $URL$
|
||||||
|
|
||||||
|
# Parser voor mlocate.db bestanden. Toont een filelisting van alle bestanden
|
||||||
|
# uit de database.
|
||||||
|
|
||||||
|
# Zie ook: http://linux.die.net/man/5/mlocate.db
|
||||||
|
|
||||||
|
# Geen argumenten. Probeert gewoon een bestand met de naam 'mlocate.db'
|
||||||
|
# in de huidige dir te openen
|
||||||
|
|
||||||
|
def arr2long(arr)
|
||||||
|
return (arr[0]<<24) + (arr[1]<<16) + (arr[2]<<8) + arr[3]
|
||||||
|
end
|
||||||
|
|
||||||
|
def arr2string(arr)
|
||||||
|
string = ""
|
||||||
|
(0...arr.length).step(2){|i|
|
||||||
|
string += ((arr[i]<<8) + (arr[i+1])).chr
|
||||||
|
}
|
||||||
|
return string
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
fh = File.new("mlocate.db", "r")
|
||||||
|
|
||||||
|
magic_number=fh.read(8)
|
||||||
|
if magic_number == "\000mlocate"
|
||||||
|
# puts "mlocate database found"
|
||||||
|
else
|
||||||
|
puts "Not an mlocate database"
|
||||||
|
exit
|
||||||
|
end
|
||||||
|
|
||||||
|
configuration_block_size=arr2long(fh.read(4))
|
||||||
|
#puts "config block #{configuration_block_size}"
|
||||||
|
|
||||||
|
file_format_version=fh.read(1).to_i
|
||||||
|
#puts "FF vers #{file_format_version}"
|
||||||
|
|
||||||
|
require_visibility=fh.read(1).to_i
|
||||||
|
#puts "require visibility #{require_visibility}"
|
||||||
|
|
||||||
|
# get rid of padding
|
||||||
|
fh.read(2)
|
||||||
|
|
||||||
|
#
|
||||||
|
dbroot=''
|
||||||
|
while (b=fh.read(1)) != "\000"
|
||||||
|
dbroot += b
|
||||||
|
end
|
||||||
|
|
||||||
|
#puts "DB root: #{dbroot}"
|
||||||
|
|
||||||
|
# skip configuration, we don't care much
|
||||||
|
bla = fh.read(configuration_block_size)
|
||||||
|
#p bla
|
||||||
|
|
||||||
|
# skip dir header. Blijkbaar is die toch echt 2 keer 8 bytes
|
||||||
|
fh.read(16)
|
||||||
|
|
||||||
|
curdir=''
|
||||||
|
while (b=fh.read(1)) != "\000"
|
||||||
|
curdir += b
|
||||||
|
end
|
||||||
|
puts curdir
|
||||||
|
if curdir == '/'
|
||||||
|
curdir = ''
|
||||||
|
end
|
||||||
|
|
||||||
|
while true
|
||||||
|
type = fh.read(1)
|
||||||
|
case type
|
||||||
|
when "\000" then
|
||||||
|
file=''
|
||||||
|
while (b=fh.read(1)) != "\000"
|
||||||
|
file += b
|
||||||
|
end
|
||||||
|
puts "#{curdir}/#{file}"
|
||||||
|
when "\001" then
|
||||||
|
subdir=''
|
||||||
|
while (b=fh.read(1)) != "\000"
|
||||||
|
subdir += b
|
||||||
|
end
|
||||||
|
# puts "#{curdir}/#{subdir}/"
|
||||||
|
when "\002" then
|
||||||
|
# dan komt er vast een nieuwe
|
||||||
|
fh.read(16)
|
||||||
|
|
||||||
|
curdir=''
|
||||||
|
while (b=fh.read(1)) != "\000"
|
||||||
|
curdir += b
|
||||||
|
end
|
||||||
|
puts "#{curdir}/"
|
||||||
|
end
|
||||||
|
end
|
||||||
Loading…
Add table
Add a link
Reference in a new issue