Op verzoek van Tim ook file:// urls aankunnen

This commit is contained in:
Ward Wouts 2009-03-02 08:27:44 +00:00
parent d80217a5e9
commit 3305750de2

View file

@ -160,7 +160,17 @@ end
def fetch(uri_str, limit = 10)
# You should choose better exception.
raise ArgumentError, 'HTTP redirect too deep' if limit == 0
if URI.parse(uri_str).scheme.to_s == "file"
response = ""
if FileTest.exists?(URI.parse(uri_str).path)
File.open(URI.parse(uri_str).path).each_line{|line|
response += line
}
else
raise "Not found"
end
response
else
host = URI.parse(uri_str).host
port = URI.parse(uri_str).port
path = URI.parse(uri_str).path
@ -176,21 +186,22 @@ def fetch(uri_str, limit = 10)
req.basic_auth @user, @pass
response = http.request(req)
case response
when Net::HTTPSuccess then response
when Net::HTTPSuccess then response.body
when Net::HTTPRedirection then fetch(response['location'], limit - 1)
when Net::HTTPUnauthorized then puts "401 Authorization Required #{uri_str}"
when Net::HTTPUnauthorized then puts "401 Authorization Required #{uri_str}"
when Net::HTTPForbidden then puts "403 Forbidden #{uri_str}"
i# when Net::HTTPNotFound then puts "404 Not Found #{uri_str}"
# when Net::HTTPNotFound then puts "404 Not Found #{uri_str}"
else
response.error!
end
end
end
def svnparse(url)
puts "\n#{url}"
begin
body = fetch("#{url}/.svn/entries").body
body = fetch("#{url}/.svn/entries")
rescue
end
if body.nil?
@ -255,7 +266,7 @@ def cvsparse(url)
puts "\n#{url}"
body=[]
begin
body = fetch("#{url}/CVS/Entries").body
body = fetch("#{url}/CVS/Entries")
rescue
end
if body.nil?
@ -281,7 +292,7 @@ def dsparse(url)
ds = DSParse.new
dirs = Array.new
begin
body = fetch("#{url}/.DS_Store").body
body = fetch("#{url}/.DS_Store")
rescue
end
if body.nil?
@ -298,7 +309,7 @@ def dsparse(url)
if entries[x] == '.' or entries[x] == '..'
next
end
body = fetch("#{url}/#{entries[x]}/.DS_Store").body
body = fetch("#{url}/#{entries[x]}/.DS_Store")
dscheck = DSParse.new
dscheck.readstring(body)
if dscheck.isds?
@ -317,7 +328,7 @@ end
def checksvn(url)
begin
puts "==================================================="
body = fetch("#{url}/.svn/entries").body
body = fetch("#{url}/.svn/entries")
puts "Subversion info found:"
svnparse(url)
rescue
@ -327,7 +338,7 @@ end
def checkcvs(url)
begin
puts "==================================================="
body = fetch("#{url}/CVS/Entries").body
body = fetch("#{url}/CVS/Entries")
puts "CVS info found:"
cvsparse(url)
rescue
@ -337,7 +348,7 @@ end
def checkds(url)
begin
puts "==================================================="
body = fetch("#{url}/.DS_Store").body
body = fetch("#{url}/.DS_Store")
puts ".DS_Store file found:"
dsparse(url)
rescue
@ -348,7 +359,7 @@ options = cmdline
if options["-u"].nil?
usage
else
if ! options["-u"].match(/^http/)
if ! options["-u"].match(/^(http|file)/)
options["-u"] = "http://#{options["-u"]}"
end
end