Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d22bb03

Browse files
committed
Added -L to find to visit symlinked folders too.
1 parent 4b6b17a commit d22bb03

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

src/find.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ var path = require('path');
22
var common = require('./common');
33
var _ls = require('./ls');
44

5-
common.register('find', _find, {});
5+
common.register('find', _find, {
6+
cmdOptions: {
7+
'L': 'link',
8+
},
9+
});
610

711
//@
812
//@ ### find(path [, path ...])
@@ -51,7 +55,7 @@ function _find(options, paths) {
5155
pushFile(file);
5256

5357
if (stat.isDirectory()) {
54-
_ls({ recursive: true, all: true }, file).forEach(function (subfile) {
58+
_ls({ recursive: true, all: true, link: options.link }, file).forEach(function (subfile) {
5559
pushFile(path.join(file, subfile));
5660
});
5761
}

test/find.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ test('current path', t => {
3030
t.is(result.code, 0);
3131
t.truthy(result.indexOf('.hidden') > -1);
3232
t.truthy(result.indexOf('dir1/dir11/a_dir11') > -1);
33-
t.is(result.length, 11);
33+
t.is(result.length, 12);
3434
shell.cd('../..');
3535
});
3636

@@ -40,7 +40,7 @@ test('simple path', t => {
4040
t.is(result.code, 0);
4141
t.truthy(result.indexOf('test/resources/find/.hidden') > -1);
4242
t.truthy(result.indexOf('test/resources/find/dir1/dir11/a_dir11') > -1);
43-
t.is(result.length, 11);
43+
t.is(result.length, 12);
4444
});
4545

4646
test('multiple paths - comma', t => {
@@ -66,3 +66,11 @@ test('nonexistent path', t => {
6666
t.is(shell.error(), 'find: no such file or directory: test/resources/find/nonexistent');
6767
t.is(result.code, 1);
6868
});
69+
70+
test('-L flag, folder is symlinked', t => {
71+
const result = shell.find('-L', 'test/resources/find');
72+
t.falsy(shell.error());
73+
t.is(result.code, 0);
74+
t.truthy(result.indexOf('test/resources/find/dir2_link/a_dir1') > -1);
75+
t.is(result.length, 13);
76+
});

test/resources/find/dir2_link

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dir2

0 commit comments

Comments
 (0)