Comparing version 3.2.0 to 3.3.0
# Change Log | ||
## 3.3.0 | ||
* Traverse symlinks recursively (thanks @caitp, see[#57][#57]). | ||
* Upgrade to rewire@2.3.4 (thanks @mbarlock, see [#60][#60]). | ||
## 3.2.0 | ||
@@ -85,1 +90,3 @@ | ||
[#61]: https://github.com/tschaub/mock-fs/pull/61 | ||
[#60]: https://github.com/tschaub/mock-fs/pull/60 | ||
[#57]: https://github.com/tschaub/mock-fs/pull/57 |
@@ -497,6 +497,7 @@ 'use strict'; | ||
return maybeCallback(callback, this, function() { | ||
var dpath = dirpath; | ||
var dir = this._system.getItem(dirpath); | ||
if (dir instanceof SymbolicLink) { | ||
dir = this._system.getItem( | ||
path.resolve(path.dirname(dirpath), dir.getPath())); | ||
while (dir instanceof SymbolicLink) { | ||
dpath = path.resolve(path.dirname(dpath), dir.getPath()); | ||
dir = this._system.getItem(dpath); | ||
} | ||
@@ -503,0 +504,0 @@ if (!dir) { |
@@ -77,18 +77,21 @@ 'use strict'; | ||
var itemPath = '/'; | ||
var linkPath; | ||
var name; | ||
for (var i = 0, ii = parts.length; i < ii; ++i) { | ||
name = parts[i]; | ||
if (item instanceof SymbolicLink) { | ||
// Symbolic link being traversed as a directory | ||
linkPath = path.resolve(path.dirname(itemPath), item.getPath()); | ||
item = this.getItem(linkPath); | ||
while (item instanceof SymbolicLink) { | ||
// Symbolic link being traversed as a directory --- If link targets | ||
// another symbolic link, resolve target's path relative to the original | ||
// link's target, otherwise relative to the current item. | ||
itemPath = path.resolve(path.dirname(itemPath), item.getPath()); | ||
item = this.getItem(itemPath); | ||
} | ||
if (item instanceof Directory && name !== currentParts[i]) { | ||
// make sure traversal is allowed | ||
if (!item.canExecute()) { | ||
throw new FSError('EACCES', filepath); | ||
if (item) { | ||
if (item instanceof Directory && name !== currentParts[i]) { | ||
// make sure traversal is allowed | ||
if (!item.canExecute()) { | ||
throw new FSError('EACCES', filepath); | ||
} | ||
} | ||
item = item.getItem(name); | ||
} | ||
item = item.getItem(name); | ||
if (!item) { | ||
@@ -95,0 +98,0 @@ break; |
{ | ||
"name": "mock-fs", | ||
"description": "A configurable mock file system. You know, for testing.", | ||
"version": "3.2.0", | ||
"version": "3.3.0", | ||
"main": "lib/index.js", | ||
@@ -42,5 +42,5 @@ "homepage": "https://github.com/tschaub/mock-fs", | ||
"dependencies": { | ||
"rewire": "~2.0.0", | ||
"rewire": "~2.3.4", | ||
"semver": "^4.2.0" | ||
} | ||
} |
@@ -34,2 +34,3 @@ /* eslint-env mocha */ | ||
'one-link.txt': FileSystem.symlink({path: './one.txt'}), | ||
'one-link2.txt': FileSystem.symlink({path: './one-link.txt'}), | ||
'three.bin': new Buffer([1, 2, 3]), | ||
@@ -49,2 +50,3 @@ 'empty': {}, | ||
'dir-link': FileSystem.symlink({path: './non-empty'}), | ||
'dir-link2': FileSystem.symlink({path: './dir-link'}), | ||
'dead-link': FileSystem.symlink({path: './non-a-real-file'}) | ||
@@ -330,4 +332,5 @@ } | ||
assert.deepEqual(items.sort(), | ||
['dead-link', 'dir-link', 'empty', 'non-empty', 'one-link.txt', | ||
'one.txt', 'three.bin', 'two.txt']); | ||
['dead-link', 'dir-link', 'dir-link2', 'empty', 'non-empty', | ||
'one-link.txt', 'one-link2.txt', 'one.txt', 'three.bin', | ||
'two.txt']); | ||
done(); | ||
@@ -342,4 +345,5 @@ }); | ||
assert.deepEqual(items.sort(), | ||
['dead-link', 'dir-link', 'empty', 'non-empty', 'one-link.txt', | ||
'one.txt', 'three.bin', 'two.txt']); | ||
['dead-link', 'dir-link', 'dir-link2', 'empty', 'non-empty', | ||
'one-link.txt', 'one-link2.txt', 'one.txt', 'three.bin', | ||
'two.txt']); | ||
}); | ||
@@ -357,2 +361,13 @@ | ||
it('calls callback with file list for link to symbolic linked dir', | ||
function(done) { | ||
var binding = new Binding(system); | ||
binding.readdir(path.join('mock-dir', 'dir-link2'), function(err, items) { | ||
assert.isNull(err); | ||
assert.isArray(items); | ||
assert.deepEqual(items.sort(), ['a.txt', 'b.txt']); | ||
done(); | ||
}); | ||
}); | ||
it('calls callback with file list for symbolic linked dir (sync)', | ||
@@ -403,2 +418,13 @@ function() { | ||
it('calls callback with error for link to symbolic link to file', | ||
function(done) { | ||
var binding = new Binding(system); | ||
binding.readdir(path.join('mock-dir', 'one-link2.txt'), | ||
function(err, items) { | ||
assert.instanceOf(err, Error); | ||
assert.isUndefined(items); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
@@ -788,4 +814,5 @@ | ||
assert.deepEqual(items.sort(), | ||
['dead-link', 'dir-link', 'empty', 'non-empty', 'one-link.txt', | ||
'one.txt', 'three.bin', 'two.txt']); | ||
['dead-link', 'dir-link', 'dir-link2', 'empty', 'non-empty', | ||
'one-link.txt', 'one-link2.txt', 'one.txt', 'three.bin', | ||
'two.txt']); | ||
}); | ||
@@ -792,0 +819,0 @@ |
@@ -49,2 +49,26 @@ /* eslint-env mocha */ | ||
it('gets an item traversing links to symbolic links', function() { | ||
var system = FileSystem.create({ | ||
'dir-link': FileSystem.symlink({path: './b/dir-link2'}), | ||
'b': { | ||
'dir-link2': FileSystem.symlink({path: './c/dir'}), | ||
'c': { | ||
dir: { | ||
'a': 'file a', | ||
'b': { | ||
'c': 'file c', | ||
'd': 'file d' | ||
} | ||
} | ||
} | ||
} | ||
}); | ||
var file = system.getItem(path.join('dir-link', 'a')); | ||
assert.instanceOf(file, File); | ||
var dir = system.getItem(path.join('dir-link', 'b')); | ||
assert.instanceOf(dir, Directory); | ||
assert.deepEqual(dir.list().sort(), ['c', 'd']); | ||
}); | ||
}); | ||
@@ -51,0 +75,0 @@ |
591802
18498
+ Addedrewire@2.3.4(transitive)
- Removedrewire@2.0.1(transitive)
Updatedrewire@~2.3.4