← Back to team overview

registry team mailing list archive

[Bug 633636] Re: rpm cannot change directory to symlink

 

As  the reference in comment #2 can tell, this bug was solved year ago
with the introduction in rpm of the embedded lua engine and the
%pretrans scriptlet.

I have commited, in @rpm5.org CVS HEAD, two toy spec example for
changing a directory with a symlink, that use, in upgrade, the following
lua %pretrans

%pretrans  -p <lua>
-- Lua block of code for removing a directory recursively
-- The Lua function remove_directory_deep should be called
-- with a directory name or, in a spec file, also with
-- a rpm macro defined to a directory name. This function
-- is a possible lua equivalent of the shell command "rm -rf"
-- using the lua posix extension embedded in rpm 
local leaf_indent = '|   '
local tail_leaf_indent = '    '
local leaf_prefix = '|-- '
local tail_leaf_prefix = '`-- '
local link_prefix = ' -> '

local function printf(...)
    io.write(string.format(unpack(arg)))
end

local function remove_directory(directory, level, prefix)
    local num_dirs = 0
    local num_files = 0
    if  posix.access(directory,"rw") then
    local files = posix.dir(directory)
    local last_file_index = table.getn(files)
    table.sort(files)
    for i, name in ipairs(files) do
        if name ~= '.' and name ~= '..' then
            local full_name = string.format('%s/%s', directory, name)
            local info = assert(posix.stat(full_name))
            local is_tail = (i==last_file_index)
            local prefix2 = is_tail and tail_leaf_prefix or leaf_prefix
            local link = ''
            if info.type == 'link' then
                linked_name = assert(posix.readlink(full_name))
                link = string.format('%s%s', link_prefix, linked_name)
                posix.unlink(full_name)
            end
            
             -- printf('%s%s%s%s\n', prefix, prefix2, name, link)
            
            if info.type == 'directory' then
                local indent = is_tail and tail_leaf_indent or leaf_indent
                sub_dirs, sub_files = remove_directory(full_name, level+1,
                    prefix .. indent)
                num_dirs = num_dirs + sub_dirs + 1
                num_files = num_files + sub_files
                posix.rmdir(full_name)
            else
                posix.unlink(full_name)
                num_files = num_files + 1
            end
        end
    end
    end -- if access
    return num_dirs, num_files
end

local function remove_directory_deep(directory)
    
    -- print(directory)
    
    num_dirs, num_files = remove_directory(directory, 0, '')
    
    -- printf('\ndropped %d directories, %d files\n', num_dirs, num_files)
    
    posix.rmdir(directory)
end
remove_directory_deep("/tmp/%{name}")


The two toy rpm spec, previously cited, of a ipotetical package test-change-dir-to-symlink show how to solve, using lua in %pretrans with the above fragment of code, the problem of changing a symlink in the directory update in rpm. Tested with @rpm.org 4.4.2.xyz rpm (RHEL 5.5), in rpm 4.7.2 (FC12) in rpm 4.8.0 (RHEL6 Beta2)

The first version is

http://rpm5.org/cvs/fileview?f=rpm/tests/test-change-dir-to-
symlink-1.1.spec&v=1.1

and the second version is

http://rpm5.org/cvs/fileview?f=rpm/tests/test-change-dir-to-
symlink-1.2.spec&v=1.3

-- 
rpm cannot change directory to symlink
https://bugs.launchpad.net/bugs/633636
You received this bug notification because you are a member of Registry
Administrators, which is the registrant for Fedora.



References