From 056e11295d76a35e7fa0626af7b940435ee7b2d1 Mon Sep 17 00:00:00 2001 From: Marcus Holland-Moritz Date: Sat, 5 Dec 2020 22:31:04 +0100 Subject: [PATCH] Remove Lua scripting support --- CMakeLists.txt | 10 +--- dwarfs.lua | 87 --------------------------- include/dwarfs/lua_script.h | 44 -------------- src/dwarfs/lua_script.cpp | 116 ------------------------------------ src/mkdwarfs.cpp | 48 +-------------- 5 files changed, 3 insertions(+), 302 deletions(-) delete mode 100644 dwarfs.lua delete mode 100644 include/dwarfs/lua_script.h delete mode 100644 src/dwarfs/lua_script.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 565a2de5..0e64e305 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,7 +21,6 @@ project(dwarfs) cmake_minimum_required(VERSION 3.13.4) option(WITH_TESTS "build with tests" OFF) -option(WITH_LUA "build with Lua scripting support" OFF) set(default_build_type "Release") @@ -118,9 +117,6 @@ list( src/dwarfs/util.cpp src/dwarfs/worker_group.cpp) -if(WITH_LUA) - list(APPEND LIBDWARFS_SRC src/dwarfs/lua_script.cpp) -endif() add_library(dwarfs ${LIBDWARFS_SRC}) @@ -265,8 +261,7 @@ foreach(tgt dwarfs ${BINARY_TARGETS}) PRIVATE DWARFS_VERSION=\"${DWARFS_VERSION}\" $<$:DWARFS_HAVE_LIBLZ4> $<$:DWARFS_HAVE_LIBLZMA> - $<$:DWARFS_HAVE_LIBZSTD> - $<$:DWARFS_HAVE_LUA>) + $<$:DWARFS_HAVE_LIBZSTD>) target_compile_options(${tgt} PRIVATE -Wall -Wextra -pedantic) @@ -292,9 +287,6 @@ foreach(tgt ${BINARY_TARGETS}) PkgConfig::LIBLZMA PkgConfig::LIBZSTD) - if(WITH_LUA) - target_link_libraries(${tgt} luabind lua) - endif() endforeach() target_link_libraries(dwarfs-bin PkgConfig::FUSE3) diff --git a/dwarfs.lua b/dwarfs.lua deleted file mode 100644 index 3cf7399b..00000000 --- a/dwarfs.lua +++ /dev/null @@ -1,87 +0,0 @@ --- --- Copyright (c) Marcus Holland-Moritz --- --- This file is part of dwarfs. --- --- dwarfs is free software: you can redistribute it and/or modify it under the --- terms of the GNU General Public License as published by the Free Software --- Foundation, either version 3 of the License, or (at your option) any later --- version. --- --- dwarfs is distributed in the hope that it will be useful, but WITHOUT ANY --- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR --- A PARTICULAR PURPOSE. See the GNU General Public License for more details. --- --- You should have received a copy of the GNU General Public License along with --- dwarfs. If not, see . --- - -function filter(f) - -- if f.name == 'Jamroot' or (f.name == 'test' and f.type == 'dir') then - -- return false - -- end - return true -end - -function autovivify(C, args, num) - for i = 1, num do - local v = args[i] - if C[v] == nil then C[v] = {} end - C = C[v] - end - return C -end - -function incr(C, ...) - local args = { n = select("#", ...), ... } - C = autovivify(C, args, args.n - 2) - local field = args[args.n - 1] - C[field] = (C[field] or 0) + args[args.n] -end - -function push(C, ...) - local args = { n = select("#", ...), ... } - C = autovivify(C, args, args.n - 1) - table.insert(C, args[args.n]) -end - -function sortbysize(tbl) - return function (a, b) - return tbl[b]["size"]/tbl[b]["num"] < tbl[a]["size"]/tbl[a]["num"] - end -end - -function order(filelist) - local C = {} - for _, f in pairs(filelist) do - local _, _, base, ext = string.find(f.name, "(.*)(%.%w+)$") - if ext == nil or string.find(ext, "[a-z]") == nil then - base, ext = f.name, "" - end - incr(C, ext, "size", f.size) - incr(C, ext, "num", 1) - incr(C, ext, "name", base, "size", f.size) - incr(C, ext, "name", base, "num", 1) - push(C, ext, "name", base, "files", f) - end - local ordered = {} - local exts = {} - for k, _ in pairs(C) do table.insert(exts, k) end - table.sort(exts, sortbysize(C)) - for _, ext in ipairs(exts) do - local N = C[ext]["name"] - local bases = {} - for k, _ in pairs(N) do table.insert(bases, k) end - table.sort(bases, sortbysize(N)) - for _, base in ipairs(bases) do - local files = N[base]["files"] - table.sort(files, function (a, b) - return b.size < a.size - end) - for _, file in ipairs(files) do - table.insert(ordered, file) - end - end - end - return ordered -end diff --git a/include/dwarfs/lua_script.h b/include/dwarfs/lua_script.h deleted file mode 100644 index f0d19f1f..00000000 --- a/include/dwarfs/lua_script.h +++ /dev/null @@ -1,44 +0,0 @@ -/* vim:set ts=2 sw=2 sts=2 et: */ -/** - * \author Marcus Holland-Moritz (github@mhxnet.de) - * \copyright Copyright (c) Marcus Holland-Moritz - * - * This file is part of dwarfs. - * - * dwarfs is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * dwarfs is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with dwarfs. If not, see . - */ - -#pragma once - -#include - -#include "dwarfs/script.h" - -namespace dwarfs { - -class logger; - -class lua_script : public script { - public: - lua_script(logger& lgr, const std::string& file); - ~lua_script(); - - bool filter(file_interface const& fi) const override; - void order(file_vector& fvi) const override; - - private: - class impl; - std::unique_ptr impl_; -}; -} // namespace dwarfs diff --git a/src/dwarfs/lua_script.cpp b/src/dwarfs/lua_script.cpp deleted file mode 100644 index 757081d1..00000000 --- a/src/dwarfs/lua_script.cpp +++ /dev/null @@ -1,116 +0,0 @@ -/* vim:set ts=2 sw=2 sts=2 et: */ -/** - * \author Marcus Holland-Moritz (github@mhxnet.de) - * \copyright Copyright (c) Marcus Holland-Moritz - * - * This file is part of dwarfs. - * - * dwarfs is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * dwarfs is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with dwarfs. If not, see . - */ - -#include "dwarfs/lua_script.h" - -#include -#include - -#include - -#include "dwarfs/logger.h" - -extern "C" { -#include -} - -namespace dwarfs { - -class lua_script::impl { - public: - impl(logger& lgr, const std::string& file); - ~impl(); - - bool filter(file_interface const& fi) const; - void order(file_vector& fv) const; - - private: - lua_State* L_; - log_proxy log_; -}; - -lua_script::impl::impl(logger& lgr, const std::string& file) - : L_(luaL_newstate()) - , log_(lgr) { - luabind::open(L_); - - luabind::module(L_)[luabind::class_("file_interface") - .property("path", &file_interface::path) - .property("name", &file_interface::name) - .property("size", &file_interface::size) - .property("type", &file_interface::type_string)]; - - luaL_openlibs(L_); - luaL_dofile(L_, file.c_str()); -} - -lua_script::impl::~impl() { lua_close(L_); } - -bool lua_script::impl::filter(file_interface const& fi) const { - return luabind::call_function(L_, "filter", &fi); -} - -void lua_script::impl::order(file_vector& fv) const { - luabind::object in = luabind::newtable(L_); - - for (size_t i = 0; i < fv.size(); ++i) { - in[i + 1] = fv[i]; - } - - log_.info() << "ordering " << fv.size() << " entries..."; - - luabind::object out; - - { - auto ti = log_.timed_info(); - out = luabind::call_function(L_, "order", in); - ti << fv.size() << " entries ordered"; - } - - if (luabind::type(out) != LUA_TTABLE) { - // TODO: better error handling - throw std::runtime_error("unexpected result type"); - } - - std::unordered_map vmap; - - for (luabind::iterator i(out), end; i != end; ++i) { - size_t key = luabind::object_cast(i.key()) - 1; - auto val = luabind::object_cast(*i); - vmap[val] = key; - } - - fv.sort([&](const file_interface* a, const file_interface* b) { - return vmap.at(a) < vmap.at(b); - }); -} - -lua_script::lua_script(logger& lgr, const std::string& file) - : impl_(new impl(lgr, file)) {} - -lua_script::~lua_script() = default; - -bool lua_script::filter(file_interface const& fi) const { - return impl_->filter(fi); -} - -void lua_script::order(file_vector& fv) const { impl_->order(fv); } -} // namespace dwarfs diff --git a/src/mkdwarfs.cpp b/src/mkdwarfs.cpp index 3a245621..ff5cbb5c 100644 --- a/src/mkdwarfs.cpp +++ b/src/mkdwarfs.cpp @@ -68,9 +68,6 @@ #include "dwarfs/script.h" #include "dwarfs/util.h" -#ifdef DWARFS_HAVE_LUA -#include "dwarfs/lua_script.h" -#endif namespace po = boost::program_options; @@ -87,16 +84,9 @@ namespace { #endif #endif -#ifdef DWARFS_HAVE_LUA -constexpr const char* script_name = "dwarfs.lua"; -#endif - const std::map order_choices{ {"none", file_order_mode::NONE}, {"path", file_order_mode::PATH}, -#ifdef DWARFS_HAVE_LUA - {"script", file_order_mode::SCRIPT}, -#endif {"similarity", file_order_mode::SIMILARITY}}; } // namespace @@ -115,35 +105,11 @@ void validate(boost::any& v, const std::vector& values, v = boost::any(it->second); } + } // namespace dwarfs namespace { -#ifdef DWARFS_HAVE_LUA -std::string find_default_script() { - using namespace boost::filesystem; - - path program(get_program_path()); - path dir(program.parent_path()); - - std::vector candidates; - candidates.emplace_back(script_name); - - if (!dir.empty()) { - candidates.emplace_back(dir / script_name); - candidates.emplace_back(dir / ".." / "share" / "dwarfs" / script_name); - } - - for (const auto& cand : candidates) { - if (exists(cand)) { - return canonical(cand).string(); - } - } - - return std::string(); -} -#endif - size_t get_term_width() { struct ::winsize w; ::ioctl(STDOUT_FILENO, TIOCGWINSZ, &w); @@ -315,12 +281,6 @@ int mkdwarfs(int argc, char** argv) { po::value(&options.file_order) ->default_value(file_order_mode::SIMILARITY, "similarity"), order_desc.c_str()) -#ifdef DWARFS_HAVE_LUA - ("script", - po::value(&script_path) - ->default_value(find_default_script()), - "Lua script for file acceptance/ordering") -#endif ("blockhash-window-sizes", po::value(&window_sizes), "window sizes for block hashing") @@ -466,11 +426,6 @@ int mkdwarfs(int argc, char** argv) { std::shared_ptr