move unpackArchive to Device, use native version on android (#6959)

reviewable/pr6975/r1
Martín Fernández 3 years ago committed by GitHub
parent 89e1c406f2
commit c481c5aa04
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1 +1 @@
Subproject commit 3ea2a698aa6938dc866c0999574ee5fe11da34d3
Subproject commit b7e8c15e2cde62d213fd7156c867a4165b2d3648

@ -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

@ -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))

@ -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

@ -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

@ -68,7 +68,6 @@ end
--- @todo Take care of this on extraction instead.
-- Cf. <https://github.com/koreader/koreader/issues/5347#issuecomment-529476693>.
android.execute("chmod", "755", "./sdcv")
android.execute("chmod", "755", "./tar")
-- set TESSDATA_PREFIX env var
C.setenv("TESSDATA_PREFIX", path.."/koreader/data", 1)

@ -1 +1 @@
Subproject commit 14e0e236731a57f53767bdfeebc422f15bac6c24
Subproject commit 5fb887600a55f99b63a8f034328e8cc8ff386357
Loading…
Cancel
Save