Zeyad Khaled
Zeyad Khaled

Reputation: 11

Error with the Lua File System(LFS), when importing the library

i needed to add a code that checks in a specific dir for cases and checks if any case (witch will be in a folder shape)in that dir that has passed 2days or more then archive it to speed up my server so i made this code down-below

In my Lua code:


-- Define the path to the LuaFileSystem library
local lfs_path = "/usr/local/lib/lua/5.1/lfs.so" -- Update this path to the actual location of lfs.so

-- Add the path to package.cpath
package.cpath = package.cpath .. ";" .. lfs_path

-- Load the LuaFileSystem library
local lfs = require("lfs")

local function isOlderThanTwoDays(path)
    local attr = lfs.attributes(path)
    if attr and attr.mode == "directory" then
        local age = os.difftime(os.time(), attr.modification)
        return age > 2 * 24 * 60 * 60
    end
    return false
end

local function archiveFolder(path)
    local archiveName = path .. ".tar.gz"
    os.execute(string.format("tar -czf %s %s", archiveName, path))
    os.execute(string.format("rm -rf %s", path))
end

local function checkAndArchiveFolders(dirs)
    for _, dir in ipairs(dirs) do
        for file in lfs.dir(dir) do
            if file ~= "." and file ~= ".." then
                local fullPath = dir .. "/" .. file
                if isOlderThanTwoDays(fullPath) then
                    archiveFolder(fullPath)
                end
            end
        end
    end
end


-- Usage
local directoriesToCheck = {
    "/etc/orthanc/ClientRpts/IVH"
    -- "/path/to/your/second_directory",
    -- Add more directories as needed
}

This code gives me an error while loading the lfs library the error said:

E0728 12:51:42.507733 MAIN OrthancException.cpp:61] Cannot execute a Lua command: error loading module 'lfs' from file '/usr/local/lib/lua/5.1/lfs.so': /usr/local/lib/lua/5.1/lfs.so: undefined symbol: lua_gettop E0728 12:51:42.508185 MAIN ServerIndex.cpp:348] INTERNAL ERROR: ServerIndex::Stop() should be invoked manually to avoid mess in the destruction order!

at first which is the start i ran luarocks install luafilesystem in the console/terminal to install lfs and then i got prompted with the error I mentioned above so i tried to add

local lfs_path = "/usr/local/lib/lua/5.1/lfs.so" -- Update this path to the actual location of lfs.so

-- Add the path to package.cpath
package.cpath = package.cpath .. ";" .. lfs_path

to inform the code that there is a lib called lfs.so

but that went with no use

Upvotes: 1

Views: 79

Answers (1)

Paul Kulchenko
Paul Kulchenko

Reputation: 26744

You usually get this error when the Lua interpreter executable you're loading a Lua module from doesn't export any symbols (so lua_gettop is not found). See this SO answer for details and a potential solution.

Upvotes: 0

Related Questions