Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclude the base directory when is a symlink and the followSymbolicLinks option is disabled #300

Open
alexander-akait opened this issue Dec 16, 2020 · 2 comments
Assignees
Milestone

Comments

@alexander-akait
Copy link

Environment

  • OS Version: linux ubuntu
  • Node.js Version: v12.20.0

Actual behavior

My structure:

├── dir
│   └── file.txt
├── symlink -> ./dir
└── file.txt

Running code sample I get:

[ 'dir/file.txt', 'symlink/file.txt' ]

If I create new symlink inside dir or symlink, it will be ignored as expected, but when I put path to symlink as an argument to fast-glob followSymbolicLinks is ignored

Expected behavior

[ 'dir/file.txt']

Steps to reproduce

  1. Run code below

Code sample

const fg = require('fast-glob');

async function problem() {
    const entries = await fg(['dir/**/*', 'symlink/**/*'], {followSymbolicLinks: false});
    
    console.log(entries)
}

problem();
@alexander-akait
Copy link
Author

@mrmlnc Can I help you to fix it?

@mrmlnc
Copy link
Owner

mrmlnc commented Jun 27, 2021

@alexander-akait,

After a few approaches, I think it's not a bug, but an inaccuracy in the documentation. But we can change this behavior in the future.

When the directory structure has the following form and the issue-300/** pattern:

issue-300/
├── directory
│   └── file.txt
└── symlink -> ./directory

Here we have a base directory (issue-300) from which we start reading deeper. When we encounter a symlink (./issue-300/symlink) we ignore it due to the followSymbolicLinks option.

In the other case, when two patterns (./issue-300/directory/** and ./issue-300/symlink/**) are specified we have two different base directories (./issue-300/directory, ./issue-300/symlink) from which the reading starts in depth. We do not check that the base directory is a symlink or not, because we consider it a cwd.

To me, it looks like right now we should fix the documentation based on the follow option description from node-glob.

Follow symlinked directories when expanding ** patterns. Note that this can result in a lot of duplicate references in the presence of cyclic links.
https://github.com/isaacs/node-glob#options

Then I looked at the behavior of ripgrep and it seems that the last call displays what you want.

# rg '' --no-follow -g '**' .
directory/file.txt

# rg '' --no-follow -g '**' directory symlink
directory/file.txt
symlink/file.txt

# rg '' --no-follow -g '{directory,symlink}/**' .
directory/file.txt

The current architecture makes it difficult to implement this behavior. We must stop using the base directory as cwd in favor of handling it through all our filters. Looks like this query requires an implementation of the feature request from #47.

Right now, I'll fix the documentation and mark this issue as feature request. Unfortunately now you have to consider adding filtering on your side.

@mrmlnc mrmlnc changed the title bug with followSymbolicLinks Exclude the base directory when is a symlink and the followSymbolicLinks option is disabled Jun 27, 2021
@mrmlnc mrmlnc added this to the 4.0.0 milestone Apr 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants