extensions/urho3d: Remove useless commented-out stuff

master
Perttu Ahola 2014-10-20 10:00:59 +03:00
parent b8ea69d92f
commit 10faca4461
1 changed files with 0 additions and 100 deletions

View File

@ -11,106 +11,6 @@ local safe_classes = dofile(buildat.extension_path("urho3d").."/safe_classes.lua
local Safe = {}
local Unsafe = {}
--[[
--
-- ResourceCache support code
--
-- Checks that this is not an absolute file path or anything funny
local allowed_name_pattern = '^[a-zA-Z0-9_][a-zA-Z0-9/._ ]*$'
function Unsafe.check_safe_resource_name(name)
if type(name) ~= "string" then
error("Unsafe resource name: "..dump(name).." (not string)")
end
if string.match(name, '^/.*$') then
error("Unsafe resource name: "..dump(name).." (absolute path)")
end
if not string.match(name, allowed_name_pattern) then
error("Unsafe resource name: "..dump(name).." (unneeded chars)")
end
if string.match(name, '[.][.]') then
error("Unsafe resource name: "..dump(name).." (contains ..)")
end
--log:verbose("Safe resource name: "..name)
return name
end
-- Basic tests
assert(pcall(function()
Unsafe.check_safe_resource_name("/etc/passwd")
end) == false)
assert(pcall(function()
Unsafe.check_safe_resource_name(" /etc/passwd")
end) == false)
assert(pcall(function()
Unsafe.check_safe_resource_name("\t /etc/passwd")
end) == false)
assert(pcall(function()
Unsafe.check_safe_resource_name("Safeodels/Box.mdl")
end) == true)
assert(pcall(function()
Unsafe.check_safe_resource_name("Fonts/Anonymous Pro.ttf")
end) == true)
assert(pcall(function()
Unsafe.check_safe_resource_name("test1/pink_texture.png")
end) == true)
assert(pcall(function()
Unsafe.check_safe_resource_name(" Box.mdl ")
end) == false)
assert(pcall(function()
Unsafe.check_safe_resource_name("../../foo")
end) == false)
assert(pcall(function()
Unsafe.check_safe_resource_name("abc$de")
end) == false)
local hack_resaved_files = {} -- name -> temporary target file
-- Create temporary file with wanted file name to make Urho3D load it correctly
function Unsafe.resave_file(resource_name)
Unsafe.check_safe_resource_name(resource_name)
local path2 = hack_resaved_files[resource_name]
if path2 == nil then
local path = __buildat_get_file_path(resource_name)
if path == nil then
-- Not found in data received by server.
-- Could be missing, or could be a local file.
return nil
end
path2 = __buildat_get_path("tmp").."/"..resource_name
dir2 = string.match(path2, '^(.*)/.+$')
if dir2 then
if not __buildat_mkdir(dir2) then
error("Failed to create directory: \""..dir2.."\"")
end
end
log:info("Temporary path: "..path2)
local src = io.open(path, "rb")
local dst = io.open(path2, "wb")
while true do
local buf = src:read(100000)
if buf == nil then break end
dst:write(buf)
end
src:close()
dst:close()
hack_resaved_files[resource_name] = path2
end
return path2
end
-- Callback from core
function __buildat_file_updated_in_cache(name, hash, cached_path)
log:debug("__buildat_file_updated_in_cache(): name="..dump(name)..
", cached_path="..dump(cached_path))
if hack_resaved_files[name] then
log:verbose("__buildat_file_updated_in_cache(): Re-saving: "..dump(name))
hack_resaved_files[name] = nil -- Force re-copy
Unsafe.resave_file(name)
end
end
--]]
--
-- Safe interface
--