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

gulp.src does not work with unc server path #2294

Open
ray007 opened this issue Feb 27, 2019 · 13 comments
Open

gulp.src does not work with unc server path #2294

ray007 opened this issue Feb 27, 2019 · 13 comments

Comments

@ray007
Copy link

ray007 commented Feb 27, 2019

Copying some files are feeding them to gulp-zip from a connected network drive works when using the path with the drive-letter, but not with the unc server path. Trying to do so gives the following error:

[16:58:43] Error: File not found with singular glob: //server.domain.name/share/some/folders/manual.doc (if this was purposeful, use `allowEmpty` option)
    at Glob.<anonymous> (C:\sandbox\workdir\node_modules\glob-stream\readable.js:84:17)
    at Object.onceWrapper (events.js:277:13)
    at Glob.emit (events.js:189:13)
    at Glob.EventEmitter.emit (domain.js:441:20)
    at Glob._finish (C:\sandbox\workdir\node_modules\glob\glob.js:197:8)
    at done (C:\sandbox\workdir\node_modules\glob\glob.js:182:14)
    at Glob._processSimple2 (C:\sandbox\workdir\node_modules\glob\glob.js:688:12)
    at C:\sandbox\workdir\node_modules\glob\glob.js:676:10
    at Glob._stat2 (C:\sandbox\workdir\node_modules\glob\glob.js:772:12)
    at lstatcb_ (C:\sandbox\workdir\node_modules\glob\glob.js:764:12)
    at RES (C:\sandbox\workdir\node_modules\inflight\inflight.js:31:16)
    at f (C:\sandbox\workdir\node_modules\once\once.js:25:25)
    at FSReqWrap.oncomplete (fs.js:154:21)

What version of gulp are you using?
4.0.0
What versions of npm and node are you using?

$ node --version
v10.15.1

$ npm --version
6.8.0

All that on Windows 10.

@phated
Copy link
Member

phated commented Feb 27, 2019

Hey @ray007

Does that file exist before you run the gulp.src? It sounds like it does but I just wanted to check. gulp 4 doesn't support singular globs that don't resolve to an actual file (the error mentions that you can use the { allowEmpty: true } option to opt-out of that behavior)

We use the https://www.npmjs.com/package/glob library internally, so you may need to adjust the settings as documented at https://gulpjs.com/docs/en/api/src#options

@phated
Copy link
Member

phated commented Feb 27, 2019

There's also a long-standing issue on node-glob about UNC paths: isaacs/node-glob#74

There's a possible solution at isaacs/node-glob#74 (comment) which says to set the cwd option to your UNC base. I just checked and we pass the cwd option through into node-glob so you should give that a try.

@ray007
Copy link
Author

ray007 commented Feb 28, 2019

@phated Yes, the file does exist, I even get a command-line tab completion for it.

The error above also happens since I directly supply the path to 1 file without any wildcards, otherwise there's no error but also no files copied.

I already tried with setting the base and cwd options (and just tried again), but it didn't help.
Setting the realpath option to true also has no effect.

Looking at the options for the glob package, nonull has a promising description, but I don't think that gets passed along.

Looking at the output with setting debug to true, I see this in the output just before the error message:

//server.domain.name/share/some/folders/manual.doc [ [ '',
    'server.domain.name',
    'share',
    'some',
    'folders',
    'manual.doc' ] ]

Does that help?

@ray007
Copy link
Author

ray007 commented Feb 28, 2019

Note: for gulp.dest() a UNC path does work.
Guess that means the glob module is somehow to blame for this.

@phated
Copy link
Member

phated commented Mar 7, 2019

@ray007 can you try this:

var glob = require('glob');

console.log(glob.sync('//server.domain.name/share/some/folders/manual.doc'));

@ray007
Copy link
Author

ray007 commented Mar 8, 2019

I've already tried this interactive in the node shell, and it does not work.

@ray007
Copy link
Author

ray007 commented Mar 8, 2019

Update:

var glob = require('glob');
glob.sync('manual.doc', {cwd: //server.domain.name/share/some/folders});

does work. But

function () {
  let sDir = '//server.domain.name/share/some/folders';
  return gulp.src('manual.doc', {cwd: '//server.domain.name/share/some/folders'})
    .pipe(...);
}

does not.
Setting options base and/or cwdbase also does not help.
I'd suspect cwd and/or base being combined with the pattern and passed to glob() instead of setting the cwd option there...

@phated
Copy link
Member

phated commented Mar 8, 2019

@ray007 thanks for testing those out. It seems that glob breaks when the path is absolute but it's actually pointing at a UNC server path. And we make all paths absolute because of some other problems with glob 😭 I'm not sure of the path forward in fixing this because our PRs to glob have largely been ignored

@ray007
Copy link
Author

ray007 commented Mar 11, 2019

It's unfortunate if glob does not fix the bug.
But it is possible to work around the glob bug by not passing an absolute path, but setting the cwd option to directory containing all possible matches and remove that part from the glob expression.

Edit: or just not create an absolute path when you get a cwd option to gulp.src()?

@ray007
Copy link
Author

ray007 commented Mar 12, 2019

I did some debugging, and the problem seems to start in glob-stream/readable.js, when all globs are converted to absolute (line 61). Not even setting the root option does avoid this conversion.

Guess that's the only point where one can place a workaround, if there's no way to get glob fixed for this.

@phated
Copy link
Member

phated commented Mar 12, 2019

@ray007 yeah, unfortunately making all paths absolute is a thing we must do. I forget exactly what it solves but it was something important.

@ray007
Copy link
Author

ray007 commented Mar 13, 2019

@ray007 yeah, unfortunately making all paths absolute is a thing we must do. I forget exactly what it solves but it was something important.

I cannot imagine must, but if you say it makes something easier, that I can easily believe.

@mkormendy
Copy link

I'm wondering if this is now fixed based on this?

@phated phated added this to post-v5 Feb 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

No branches or pull requests

3 participants