Sanitize filename for vfat, fix #2433 (#2464)

pull/2484/head
Robert 7 years ago committed by Qingping Hou
parent 6b8ff76507
commit 7bfbc9f06a

@ -471,6 +471,15 @@ function OPDSBrowser:downloadFile(item, format, remote_url)
-- download to user selected directory or last opened dir
local lastdir = G_reader_settings:readSetting("lastdir")
local download_dir = G_reader_settings:readSetting("download_dir") or lastdir
local utl = require("frontend/util")
local file_system = utl.getFilesystemType(download_dir)
if file_system == "vfat" or file_system == "fuse.fsp" then
item.author = utl.replaceInvalidChars(item.author)
item.title = utl.replaceInvalidChars(item.title)
else
item.author = utl.replaceSlashChar(item.author)
item.title = utl.replaceSlashChar(item.title)
end
local local_path = download_dir .. "/" .. item.author .. ' - ' .. item.title .. "." .. string.lower(format)
logger.dbg("downloading file", local_path, "from", remote_url)

@ -221,4 +221,35 @@ function util.isSplitable(c, next_c, prev_c)
return false
end
function util.getFilesystemType(path)
local mounts = io.open("/proc/mounts", "r")
if not mounts then return nil end
local type
while true do
local line
local mount = {}
line = mounts:read()
if line == nil then
break
end
for param in line:gmatch("%S+") do table.insert(mount, param) end
if string.match(path, mount[2]) then
type = mount[3]
if mount[2] ~= '/' then
break
end
end
end
mounts:close()
return type
end
function util.replaceInvalidChars(str)
return str:gsub('[\\,%/,:,%*,%?,%",%<,%>,%|]','_')
end
function util.replaceSlashChar(str)
return str:gsub('%/','_')
end
return util

Loading…
Cancel
Save