diff options
author | Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi> | 2013-05-01 11:53:45 +0300 |
---|---|---|
committer | Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi> | 2013-05-01 14:11:00 +0300 |
commit | 38e36228680b03831d5cbfa6593796320235bfba (patch) | |
tree | 90514747577f04c4e868b7623f3b85fe4a9436dd /acf | |
parent | b5cf596d6c17fc9c8b7c679fe445a9c70af2a16e (diff) | |
download | aconf-38e36228680b03831d5cbfa6593796320235bfba.tar.bz2 aconf-38e36228680b03831d5cbfa6593796320235bfba.tar.xz |
file system back-end: map references to symlinks
Diffstat (limited to 'acf')
-rw-r--r-- | acf/persistence/backends/files.lua | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/acf/persistence/backends/files.lua b/acf/persistence/backends/files.lua index e123e21..813dca5 100644 --- a/acf/persistence/backends/files.lua +++ b/acf/persistence/backends/files.lua @@ -9,6 +9,7 @@ local pth = require('acf.path') local util = require('acf.persistence.util') require 'posix' +require 'stringy' backend = require('acf.object').class() @@ -26,6 +27,19 @@ function backend:get(path, tpe) if t == 'regular' then self.cache[name] = util.read_file(name) + elseif t == 'link' then + -- TODO handle relative symlinks + local target = posix.readlink(name) + assert(target) + if not tpe then return target end + + assert(stringy.startswith(tpe, 'reference/files/')) + local scope = string.sub(tpe, 16, -1)..'/' + + local slen = string.len(scope) + assert(string.sub(target, 1, slen) == scope) + return string.sub(target, slen + 1, -1) + elseif t == 'directory' then local res = {} for _, fname in ipairs(posix.dir(name)) do @@ -36,8 +50,6 @@ function backend:get(path, tpe) return res else error('Unsupported file type: '..name) end - - -- TODO present symlinks as references end return self.cache[name] @@ -48,8 +60,6 @@ function backend:set(mods) local path, t, value = unpack(mod) local name = pth.join('/', unpack(path)) - -- TODO save references (t == 'reference') as symlinks - if not t then -- TODO del files & dirs print('DEL', name) @@ -57,6 +67,15 @@ function backend:set(mods) elseif t == 'table' then assert(posix.mkdir(name)) + elseif stringy.startswith(t, 'reference/files/') then + -- TODO use relative symlink + os.remove(name) + assert( + posix.link( + pth.to_absolute(value, string.sub(t, 16, -1)), name, true + ) + ) + else local file = util.open_file(name, 'w') file:write(tostring(value)) |