require "proto" require "lfs" require "umake" require "upath" -- Metaacls: path meta user call constr -- #metaacl# / type Admin new recursive -- #metaacl# / requires Admin new recursive -- #metaacl# / requires Admin delete recursive -- #metaacl# / generates Admin new recursive -- #metaacl# / generates Admin delete recursive -- #metaacl# /_uwiki/ type Admin new recursive -- #metaacl# /_uwiki/ requires Admin new recursive -- #metaacl# /_uwiki/ requires Admin delete recursive -- #metaacl# /_uwiki/ generates Admin new recursive -- #metaacl# /_uwiki/ generates Admin delete recursive local import = Object:clone() function import:invoke(session, request, response) response:write("
")

    local scm = session:scm_load(session.path)
    local thefile = scm:enter(session.path)

    assert(upath.exists(thefile), "EEXIST:File does not exist")

    -- with a new file a new acl might be established
    if request.params.aclenable == 'on' then
        -- TODO must not have an acl already
        session:acl_new(session.path, acl.parse(request.params.newacl))
    end

    -- first chance to commit a file    TODO before, after, never
    if request.params.commitctl == "before" then
        local comment = request.params.comment
        if not comment or comment == "" then
            comment = "Imported "..thefile
        end
        scm:commit(session, thefile, comment)
    end

    local types = {}

    if request.params.doctype then
        local doctypes
        if type(request.params.doctype) == 'string' then
            -- got only one
            doctypes = {request.params.doctype}
        else
            -- got many
            doctypes = request.params.doctype
        end

        for _,typename in ipairs(doctypes) do
            local type = session:type_load(typename)
            types[typename] = type
            if type:check(session.path) then
                type:register(session.path)
            end
        end
    end

    -- build or rebuild the document
    umake.build(session, session.path, types,
                function(type, path, dest)
                    response:write("compiled "..path.." to "..dest.." with "..type.."\n")
                end)

    -- second chance to commit the file
    if request.params.commitctl == "after" then
        local comment = request.params.comment
        if not comment or comment == "" then
            comment = "Imported "..thefile
        end
        scm:commit(session, thefile, comment)
    end

    response:write("
") scm:leave() session:done() return response:finish() end return import -- Local Variables: -- mode: lua -- lua-indent-level: 4 -- indent-tabs-mode: nil -- End: