mirror of
https://github.com/koreader/koreader
synced 2024-10-31 21:20:20 +00:00
Don't assert() around io.popen() and use generic FileExists().
This commit is contained in:
parent
ac46f7237f
commit
2fdecb7b40
19
fileinfo.lua
19
fileinfo.lua
@ -35,10 +35,20 @@ function FileInfo:FormatSize(size)
|
||||
end
|
||||
end
|
||||
|
||||
function FileExists(path)
|
||||
local f = io.open(path, "r")
|
||||
if f then
|
||||
f:close()
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
function getUnpackedZipSize(zipfile)
|
||||
-- adding quotes allows us to avoid crash on zips which filename contains space(s)
|
||||
local cmd='unzip -l \"'..zipfile..'\" | tail -1 | sed -e "s/^ *\\([0-9][0-9]*\\) *.*/\\1/"'
|
||||
local p = assert(io.popen(cmd, "r"))
|
||||
local p = io.popen(cmd, "r")
|
||||
local res = assert(p:read("*a"))
|
||||
p:close()
|
||||
res = string.gsub(res, "[\n\r]+", "")
|
||||
@ -60,7 +70,7 @@ end
|
||||
|
||||
function FileInfo:getFolderContent()
|
||||
InfoMessage:show("Scanning folder...", 1)
|
||||
local tmp = assert(io.popen('du -a \"'..self.pathfile..'\"', "r"))
|
||||
local tmp = io.popen('du -a \"'..self.pathfile..'\"', "r")
|
||||
local dirs, files, books, size, name, output, ftype, j = -1, 0, 0, 0
|
||||
for output in tmp:lines() do
|
||||
j = output:find("/")
|
||||
@ -136,8 +146,7 @@ function FileInfo:init(path, fname)
|
||||
if fname then
|
||||
-- if the document was already opened
|
||||
local history = DocToHistory(self.pathfile)
|
||||
local file, msg = io.open(history, "r")
|
||||
if not file then
|
||||
if not FileExists(history) then
|
||||
table.insert(self.result, {dir = "Last read", name = "Never"})
|
||||
else
|
||||
table.insert(self.result, {dir = "Last read", name = self:FileCreated(history, "change")})
|
||||
@ -161,7 +170,7 @@ end
|
||||
|
||||
function FileInfo:show(path, name)
|
||||
-- at first, one has to test whether the file still exists or not: necessary for last documents
|
||||
if name and not io.open(path.."/"..name,"r") then return nil end
|
||||
if name and not FileExists(path.."/"..name) then return nil end
|
||||
-- then goto main functions
|
||||
self:init(path,name)
|
||||
-- local variables
|
||||
|
Loading…
Reference in New Issue
Block a user