From c481c5aa04d76a33826d58b3011d20f8b561ba98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Fern=C3=A1ndez?= Date: Thu, 10 Dec 2020 16:59:14 +0100 Subject: [PATCH] move unpackArchive to Device, use native version on android (#6959) --- base | 2 +- .../apps/reader/modules/readerdictionary.lua | 2 +- frontend/device/android/device.lua | 4 +++ frontend/device/generic/device.lua | 26 +++++++++++++++++++ frontend/util.lua | 23 ---------------- platform/android/llapp_main.lua | 1 - platform/android/luajit-launcher | 2 +- 7 files changed, 33 insertions(+), 27 deletions(-) diff --git a/base b/base index 3ea2a698a..b7e8c15e2 160000 --- a/base +++ b/base @@ -1 +1 @@ -Subproject commit 3ea2a698aa6938dc866c0999574ee5fe11da34d3 +Subproject commit b7e8c15e2cde62d213fd7156c867a4165b2d3648 diff --git a/frontend/apps/reader/modules/readerdictionary.lua b/frontend/apps/reader/modules/readerdictionary.lua index bb8fdd6ac..24dcf70b1 100644 --- a/frontend/apps/reader/modules/readerdictionary.lua +++ b/frontend/apps/reader/modules/readerdictionary.lua @@ -974,7 +974,7 @@ function ReaderDictionary:downloadDictionary(dict, download_location, continue) return false end - local ok, error = util.unpackArchive(download_location, self.data_dir) + local ok, error = Device:unpackArchive(download_location, self.data_dir) if ok then available_ifos = false diff --git a/frontend/device/android/device.lua b/frontend/device/android/device.lua index afae22b90..8ae6b34ad 100644 --- a/frontend/device/android/device.lua +++ b/frontend/device/android/device.lua @@ -435,6 +435,10 @@ function Device:showLightDialog() end end +function Device:untar(archive, extract_to) + return android.untar(archive, extract_to) +end + android.LOGI(string.format("Android %s - %s (API %d) - flavor: %s", android.prop.version, getCodename(), Device.firmware_rev, android.prop.flavor)) diff --git a/frontend/device/generic/device.lua b/frontend/device/generic/device.lua index 7ba982205..72fb45c1f 100644 --- a/frontend/device/generic/device.lua +++ b/frontend/device/generic/device.lua @@ -7,6 +7,7 @@ This module defines stubs for common methods. local logger = require("logger") local util = require("util") local _ = require("gettext") +local T = require("ffi/util").template local function yes() return true end local function no() return false end @@ -497,4 +498,29 @@ function Device:isStartupScriptUpToDate() return true end +--- Unpack an archive. +-- Extract the contents of an archive, detecting its format by +-- filename extension. Inspired by luarocks archive_unpack() +-- @param archive string: Filename of archive. +-- @param extract_to string: Destination directory. +-- @return boolean or (boolean, string): true on success, false and an error message on failure. +function Device:unpackArchive(archive, extract_to) + require("dbg").dassert(type(archive) == "string") + local BD = require("ui/bidi") + local ok + if archive:match("%.tar%.bz2$") or archive:match("%.tar%.gz$") or archive:match("%.tar%.lz$") or archive:match("%.tgz$") then + ok = self:untar(archive, extract_to) + else + return false, T(_("Couldn't extract archive:\n\n%1\n\nUnrecognized filename extension."), BD.filepath(archive)) + end + if not ok then + return false, T(_("Extracting archive failed:\n\n%1"), BD.filepath(archive)) + end + return true +end + +function Device:untar(archive, extract_to) + return os.execute(("./tar xf %q -C %q"):format(archive, extract_to)) +end + return Device diff --git a/frontend/util.lua b/frontend/util.lua index 6407f3b61..0509b5d9c 100644 --- a/frontend/util.lua +++ b/frontend/util.lua @@ -3,7 +3,6 @@ This module contains miscellaneous helper functions for the KOReader frontend. ]] local BaseUtil = require("ffi/util") -local dbg = require("dbg") local _ = require("gettext") local T = BaseUtil.template @@ -1171,28 +1170,6 @@ function util.checkLuaSyntax(lua_text) return err end ---- Unpack an archive. --- Extract the contents of an archive, detecting its format by --- filename extension. Inspired by luarocks archive_unpack() --- @param archive string: Filename of archive. --- @param extract_to string: Destination directory. --- @return boolean or (boolean, string): true on success, false and an error message on failure. -function util.unpackArchive(archive, extract_to) - dbg.dassert(type(archive) == "string") - - local BD = require("ui/bidi") - local ok - if archive:match("%.tar%.bz2$") or archive:match("%.tar%.gz$") or archive:match("%.tar%.lz$") or archive:match("%.tgz$") then - ok = os.execute(("./tar xf %q -C %q"):format(archive, extract_to)) - else - return false, T(_("Couldn't extract archive:\n\n%1\n\nUnrecognized filename extension."), BD.filepath(archive)) - end - if not ok then - return false, T(_("Extracting archive failed:\n\n%1", BD.filepath(archive))) - end - return true -end - -- Simple startsWith / endsWith string helpers -- c.f., http://lua-users.org/wiki/StringRecipes -- @param str string: source string diff --git a/platform/android/llapp_main.lua b/platform/android/llapp_main.lua index dad408d1e..984086af3 100644 --- a/platform/android/llapp_main.lua +++ b/platform/android/llapp_main.lua @@ -68,7 +68,6 @@ end --- @todo Take care of this on extraction instead. -- Cf. . android.execute("chmod", "755", "./sdcv") -android.execute("chmod", "755", "./tar") -- set TESSDATA_PREFIX env var C.setenv("TESSDATA_PREFIX", path.."/koreader/data", 1) diff --git a/platform/android/luajit-launcher b/platform/android/luajit-launcher index 14e0e2367..5fb887600 160000 --- a/platform/android/luajit-launcher +++ b/platform/android/luajit-launcher @@ -1 +1 @@ -Subproject commit 14e0e236731a57f53767bdfeebc422f15bac6c24 +Subproject commit 5fb887600a55f99b63a8f034328e8cc8ff386357