diff options
-rw-r--r-- | .gitmodules | 6 | ||||
-rwxr-xr-x | build.sh | 12 | ||||
m--------- | lib/libarchive | 0 | ||||
m--------- | lib/liblzma | 0 | ||||
-rw-r--r-- | lpm.c | 54 | ||||
-rw-r--r-- | lpm.lua | 18 |
6 files changed, 78 insertions, 12 deletions
diff --git a/.gitmodules b/.gitmodules index 0ee8ee3..73d5ad3 100644 --- a/.gitmodules +++ b/.gitmodules @@ -14,3 +14,9 @@ [submodule "lib/curl"] path = lib/curl url = https://github.com/curl/curl.git +[submodule "lib/libarchive"] + path = lib/libarchive + url = https://github.com/libarchive/libarchive.git +[submodule "lib/liblzma"] + path = lib/liblzma + url = https://github.com/kobolabs/liblzma.git @@ -8,11 +8,11 @@ SRCS="*.c" LDFLAGS="$LDFLAGS -lm -pthread -static-libgcc" -[[ "$@" == "clean" ]] && rm -rf lib/libgit2/build lib/zlib/build lib/openssl/build lib/curl/build lib/prefix $BIN *.exe && exit 0 +[[ "$@" == "clean" ]] && rm -rf lib/libgit2/build lib/zlib/build lib/openssl/build lib/curl/build lib/libarchive/build-tmp lib/libzma/build lib/prefix $BIN *.exe && exit 0 [[ $OSTYPE == 'msys'* || $CC == *'mingw'* ]] && SSL_CONFIGURE="mingw64" # Build supporting libraries, libgit2, libz, libssl (with libcrypto), libpcre -[[ "$@" != *"-lz"* ]] && CFLAGS="$CFLAGS -Ilib/zlib" && SRCS="$SRCS lib/zlib/*.c" +# [[ "$@" != *"-lz"* ]] && CFLAGS="$CFLAGS -Ilib/zlib" && SRCS="$SRCS lib/zlib/*.c" if [[ "$@" != *"-lz"* ]]; then [ ! -e "lib/zlib" ] && echo "Make sure you've cloned submodules. (git submodule update --init --depth=1)" && exit -1 [ ! -e "lib/zlib/build" ] && cd lib/zlib && mkdir build && cd build && ../configure --prefix=`pwd`/../../prefix && $MAKE -j $JOBS && $MAKE install && cd ../../../ @@ -30,6 +30,14 @@ if [[ "$@" != *"-lcurl"* ]]; then [ ! -e "lib/curl/build" ] && cd lib/curl && mkdir build && cd build && cmake .. -G="Unix Makefiles" $CURL_CONFIGURE -DCURL_USE_LIBPSL=OFF -DCURL_DISABLE_LDAPS=ON -DUSE_OPENSSL=ON -DCURL_DISABLE_LDAP=ON -DCMAKE_INSTALL_PREFIX=`pwd`/../../prefix -DUSE_LIBIDN2=OFF -DENABLE_UNICODE=OFF -DBUILD_CURL_EXE=OFF -DCURL_USE_LIBSSH2=OFF -DOPENSSL_ROOT_DIR=`pwd`/../../prefix -DBUILD_SHARED_LIBS=OFF -DCMAKE_INSTALL_LIBDIR=lib && $MAKE -j $JOBS && $MAKE install && cd ../../../ LDFLAGS="-Llib/curl/build -Llib/prefix/lib -l:libcurl.a $LDFLAGS" && CFLAGS="$CFLAGS -Ilib/prefix/include -DCURL_STATICLIB" fi +if [[ "$@" != *"-lzma"* ]]; then + [ ! -e "lib/liblzma/build" ] && cd lib/liblzma && mkdir build && cd build && ../configure $LZMA_CONFIGURE --prefix=`pwd`/../../prefix && $MAKE -j $JOBS && $MAKE install && cd ../../../ + LDFLAGS="-Llib/liblzma/build -Llib/prefix/lib -l:liblzma.a $LDFLAGS" && CFLAGS="$CFLAGS -Ilib/prefix/include" +fi +if [[ "$@" != *"-larchive"* ]]; then + [ ! -e "lib/libarchive/build-tmp" ] && cd lib/libarchive && mkdir build-tmp && cd build-tmp && cmake .. -G="Unix Makefiles" $ARCHIVE_CONFIGURE -DCMAKE_INSTALL_PREFIX=`pwd`/../../prefix -DBUILD_SHARED_LIBS=OFF -DCMAKE_INSTALL_LIBDIR=lib -DENABLE_CAT=OFF -DENABLE_CPIO=OFF -DENABLE_BZip2=OFF -DENABLE_OPENSSL=OFF -DENABLE_LIBXML2=OFF -DENABLE_PCREPOSIX=OFF && $MAKE -j $JOBS && $MAKE install && cd ../../../ + LDFLAGS="-Llib/libarchive/build-tmp -Llib/prefix/lib -l:libarchive.a $LDFLAGS" && CFLAGS="$CFLAGS -Ilib/prefix/include" +fi [[ "$@" != *"-llua"* ]] && CFLAGS="$CFLAGS -Ilib/lua -DMAKE_LIB=1" && SRCS="$SRCS lib/lua/onelua.c" # Build the pre-packaged lua file into the executbale. diff --git a/lib/libarchive b/lib/libarchive new file mode 160000 +Subproject 552547eacf6bfbdf5052f33cad57f181b6f92a6 diff --git a/lib/liblzma b/lib/liblzma new file mode 160000 +Subproject 87b7682ce4b1c849504e2b3641cebaad62aaef8 @@ -8,6 +8,8 @@ #include <lualib.h> #include <dirent.h> #include <unistd.h> +#include <archive.h> +#include <archive_entry.h> #include <sys/stat.h> #include <git2.h> @@ -18,6 +20,8 @@ #include <direct.h> #include <windows.h> #include <fileapi.h> +#else + #define MAX_PATH PATH_MAX #endif static char hex_digits[] = "0123456789abcdef"; @@ -375,13 +379,60 @@ static int lpm_certs(lua_State* L) { return 0; } +static int lpm_extract(lua_State* L) { + const char* src = luaL_checkstring(L, 1); + const char* dst = luaL_optstring(L, 2, "./"); + + struct archive_entry *entry; + const void *buff; + int flags = 0; + int r; + size_t size; +#if ARCHIVE_VERSION_NUMBER >= 3000000 + int64_t offset; +#else + off_t offset; +#endif + struct archive *ar = archive_read_new(); + struct archive *aw = archive_write_disk_new(); + archive_write_disk_set_options(aw, flags); + archive_read_support_format_tar(ar); + archive_read_support_format_zip(ar); + if ((r = archive_read_open_filename(ar, src, 10240))) + luaL_error(L, "error extracting archive %s: %s", src, archive_error_string(ar)); + for (;;) { + int r = archive_read_next_header(ar, &entry); + if (r == ARCHIVE_EOF) + break; + if (r != ARCHIVE_OK) + luaL_error(L, "error extracting archive %s: %s", src, archive_error_string(ar)); + char path[MAX_PATH]; + strcpy(path, dst); + strncat(path, archive_entry_pathname(entry), sizeof(path) - 3); path[MAX_PATH-1] = 0; + archive_entry_set_pathname(entry, path); + if (archive_write_header(aw, entry) != ARCHIVE_OK) + return luaL_error(L, "error extracting archive %s: %s", src, archive_error_string(aw)); + for (;;) { + int r = archive_read_data_block(ar, &buff, &size, &offset); + if (r == ARCHIVE_EOF) + break; + if (r != ARCHIVE_OK) + return luaL_error(L, "error extracting archive %s: %s", src, archive_error_string(ar)); + if (archive_write_data_block(aw, buff, size, offset) != ARCHIVE_OK) + return luaL_error(L, "error extracting archive %s: %s", src, archive_error_string(aw)); + } + if (archive_write_finish_entry(aw) != ARCHIVE_OK) + return luaL_error(L, "error extracting archive %s: %s", src, archive_error_string(aw)); + } + return 0; +} + static size_t lpm_curl_write_callback(char *ptr, size_t size, size_t nmemb, void *BL) { luaL_Buffer* B = BL; luaL_addlstring(B, ptr, size*nmemb); return size*nmemb; } - static int lpm_get(lua_State* L) { long response_code; const char* url = luaL_checkstring(L, 1); @@ -440,6 +491,7 @@ static const luaL_Reg system_lib[] = { { "fetch", lpm_fetch }, // Updates a git repository with the specified remote. { "reset", lpm_reset }, // Updates a git repository to the specified commit/hash/branch. { "get", lpm_get }, // HTTP(s) GET request. + { "extract", lpm_extract }, // Opens .tar.gz files. { "certs", lpm_certs }, // Sets the SSL certificate chain folder/file. { NULL, NULL } }; @@ -819,7 +819,7 @@ function Repository:add() system.init(path, self.remote) system.fetch(path) system.reset(path, self.commit or ("refs/remotes/origin/" .. self.branch), "hard") - log_action("Retrieved " .. self.remote .. ":" .. (self.commit or self.branch) .. "...") + log_action("Retrieved " .. self:url() .. "...") self.manifest = nil end local manifest, remotes = self:parse_manifest() @@ -842,7 +842,7 @@ function Repository:update() local path = self.local_path .. PATHSEP .. self.branch system.fetch(path) system.reset(path, "refs/remotes/origin/" .. self.branch, "hard") - log_action("Updated " .. self.remote .. ":" .. (self.commit or self.branch)) + log_action("Updated " .. self:url()) self.manifest = nil manifest, remotes = self:parse_manifest() end @@ -875,7 +875,7 @@ function LiteXL.new(repository, metadata) tags = metadata.tags or {}, mod_version = metadata.mod_version, path = metadata.path, - hash = system.hash((repository and (repository.url .. ":" .. (repository.commit or repository.branch)) or "") .. "-" .. metadata.version), + hash = system.hash((repository and repository:url() or "") .. "-" .. metadata.version), files = metadata.files or {} }, LiteXL) self.local_path = CACHEDIR .. PATHSEP .. "lite-xls" .. PATHSEP .. self.hash @@ -1142,12 +1142,12 @@ local function lpm_lite_xl_list() }) end for i,repo in ipairs(repositories) do - if not repo.lite_xls then error("can't find lite-xl for repo " .. repo.remote .. ":" .. (repo.commit or repo.branch or "master")) end + if not repo.lite_xls then error("can't find lite-xl for repo " .. repo:url()) end for j, lite_xl in ipairs(repo.lite_xls) do table.insert(result["lite-xl"], { version = lite_xl.version, mod_version = lite_xl.mod_version, - repository = repo.remote .. ":" .. (repo.commit or repo.branch), + repository = repo:url(), tags = lite_xl.tags }) end @@ -1216,14 +1216,14 @@ local function lpm_plugin_reinstall(...) for i, name in ipairs({ ... }) do pcall local function lpm_repo_list() if JSON then - io.stdout:write(json.encode({ repositories = common.map(repositories, function(repo) return { remote = repo.remote, commit = repo.commit, branch = repo.branch, path = repo.local_path .. PATHSEP .. (repo.commit or repo.branch), remotes = common.map(repo.remotes or {}, function(r) return remote.remote .. ":" .. (remote.commit or remote.branch) end) } end) }) .. "\n") + io.stdout:write(json.encode({ repositories = common.map(repositories, function(repo) return { remote = repo.remote, commit = repo.commit, branch = repo.branch, path = repo.local_path .. PATHSEP .. (repo.commit or repo.branch), remotes = common.map(repo.remotes or {}, function(r) return r:url() end) } end) }) .. "\n") else for i, repository in ipairs(repositories) do local _, remotes = repository:parse_manifest() if i ~= 0 then print("---------------------------") end - print("Remote : " .. repository.remote .. ":" .. (repository.commit or repository.branch)) + print("Remote : " .. repository:url()) print("Path : " .. repository.local_path .. PATHSEP .. (repository.commit or repository.branch)) - print("Remotes: " .. json.encode(common.map(repository.remotes or {}, function(r) return remote.remote .. ":" .. (remote.commit or remote.branch) end))) + print("Remotes: " .. json.encode(common.map(repository.remotes or {}, function(r) return r:url() end))) end end end @@ -1244,7 +1244,7 @@ local function lpm_plugin_list() tags = plugin.tags, type = plugin.type, organization = plugin.organization, - repository = repo and (repo.remote .. ":" .. (repo.commit or repo.branch)) + repository = repo and repo:url() }) end if JSON then |