diff --git a/frontend/ui/widget/opdsbrowser.lua b/frontend/ui/widget/opdsbrowser.lua index c9cd664e8..ac39e7b85 100644 --- a/frontend/ui/widget/opdsbrowser.lua +++ b/frontend/ui/widget/opdsbrowser.lua @@ -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) diff --git a/frontend/util.lua b/frontend/util.lua old mode 100644 new mode 100755 index 1eff06e65..afa77bf91 --- a/frontend/util.lua +++ b/frontend/util.lua @@ -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