lzwfs wip

This commit is contained in:
kepler155c@gmail.com
2019-11-05 12:14:01 -07:00
parent cecce156d7
commit 18441ffaef
3 changed files with 15 additions and 11 deletions

View File

@@ -157,9 +157,11 @@ local function split(str, pattern)
end end
local function matchesFilter(fname) local function matchesFilter(fname)
for _, filter in pairs(filters) do if not fname:find('lzwfs') then -- don't compress anything with lzwfs in name (sigh)
if fname:match(filter) then for _, filter in pairs(filters) do
return true if fname:match(filter) then
return true
end
end end
end end
end end
@@ -193,7 +195,7 @@ function fs.open(fname, flags)
end, end,
} }
elseif flags == 'w' or flags == 'a' then elseif flags == 'w' or flags == 'a' then
if not matchesFilter(fs.combine(fname, '')) or true then if not matchesFilter(fs.combine(fname, '')) then
return native.open(fname, flags) return native.open(fname, flags)
end end

View File

@@ -15,4 +15,4 @@ end
os.run(_ENV, '/packages/lzwfs/lzwfs.lua') os.run(_ENV, '/packages/lzwfs/lzwfs.lua')
fs.option('compression', 'filters', config.filters) fs.option('compression', 'filters', config.filters)
fs.option('compression', 'enable', config.enabled) fs.option('compression', 'enabled', config.enabled)

View File

@@ -7,9 +7,9 @@ local fs = _G.fs
local config = Config.load('lzwfs', { local config = Config.load('lzwfs', {
enabled = false, enabled = false,
filters = { filters = {
'/packages', 'packages/',
'/sys', 'sys/',
'/usr/config', 'usr/config/',
} }
}) })
@@ -70,8 +70,10 @@ local function rewriteFiles(p)
local function recurse(path) local function recurse(path)
_G._syslog('rewriting: ' .. path) _G._syslog('rewriting: ' .. path)
if fs.isDir(path) then if fs.isDir(path) then
for _, v in pairs(fs.list(path)) do for _, v in pairs(fs.listEx(path)) do
recurse(fs.combine(path, v)) if not v.isReadOnly then
recurse(fs.combine(path, v.name))
end
end end
else else
local c = Util.readFile(path) local c = Util.readFile(path)
@@ -116,7 +118,7 @@ function tab:eventHandler(event)
if self.checkbox.value ~= config.enabled then if self.checkbox.value ~= config.enabled then
if not self.checkbox.value then if not self.checkbox.value then
fs.option('compression', 'filters', { }) fs.option('compression', 'filters', { })
self:rewriteFiles(config.filters) rewriteFiles(config.filters)
fs.option('compression', 'enabled', false) fs.option('compression', 'enabled', false)
else else
fs.option('compression', 'enabled', true) fs.option('compression', 'enabled', true)