level-filesystem
Advanced tools
Comparing version 1.0.2 to 1.1.0
@@ -403,5 +403,10 @@ var fwd = require('fwd-stream'); | ||
fs.watch = function(key, opts, cb) { | ||
if (typeof opts === 'function') return fs.watch(key, null, opts) | ||
return listeners.watcher(ps.normalize(key), cb); | ||
}; | ||
fs.notify = function(cb) { | ||
listeners.on('change', cb) | ||
} | ||
fs.open = function(key, flags, mode, cb) { | ||
@@ -408,0 +413,0 @@ if (typeof mode === 'function') return fs.open(key, flags, null, mode); |
{ | ||
"name": "level-filesystem", | ||
"version": "1.0.2", | ||
"version": "1.1.0", | ||
"description": "Full implementation of the fs module on top of leveldb", | ||
@@ -5,0 +5,0 @@ "repository": "git://github.com:mafintosh/level-filesystem.git", |
20
paths.js
@@ -69,8 +69,24 @@ var path = require('path'); | ||
var resolve = function(dir, cb) { | ||
var root = '/'; | ||
var parts = dir.split('/').slice(1); | ||
var loop = function() { | ||
that.get(path.join(root, parts.shift()), function(err, doc, key) { | ||
if (err) return cb(err, doc, dir); | ||
root = doc.target || key; | ||
if (!parts.length) return cb(null, doc, key); | ||
loop(); | ||
}); | ||
}; | ||
loop(); | ||
}; | ||
that.follow = function(key, cb) { | ||
that.get(key, function loop(err, doc, key) { | ||
resolve(normalize(key), function loop(err, doc, key) { | ||
if (err) return cb(err, null, key); | ||
if (doc.target) return that.get(doc.target, loop); | ||
cb(null, stat(doc), key); | ||
}) | ||
}); | ||
}; | ||
@@ -77,0 +93,0 @@ |
@@ -20,2 +20,18 @@ var test = require('./helpers/test'); | ||
test('symlink parent', function(fs, t) { | ||
fs.mkdir('/hello', function() { | ||
fs.writeFile('/hello/world.txt', 'hello', function(err) { | ||
t.ok(!err) | ||
fs.symlink('/hello', '/hi', function(err) { | ||
t.ok(!err) | ||
fs.readFile('/hi/world.txt', function(err, data) { | ||
t.ok(!err) | ||
t.same(data.toString(), 'hello') | ||
t.end() | ||
}) | ||
}) | ||
}) | ||
}) | ||
}); | ||
test('symlink unlink', function(fs, t) { | ||
@@ -22,0 +38,0 @@ fs.writeFile('/test.txt', 'hello', function(err) { |
@@ -5,3 +5,3 @@ var events = require('events'); | ||
var listeners = {}; | ||
var that = {}; | ||
var that = new events.EventEmitter(); | ||
@@ -42,2 +42,3 @@ that.watch = function(key, cb) { | ||
if (listeners[key]) listeners[key].emit('change'); | ||
that.emit('change', key); | ||
}; | ||
@@ -44,0 +45,0 @@ |
48396
1575