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

Issue with UNC paths on Windows #74

Closed
gotdibbs opened this issue Sep 23, 2013 · 39 comments
Closed

Issue with UNC paths on Windows #74

gotdibbs opened this issue Sep 23, 2013 · 39 comments

Comments

@gotdibbs
Copy link

When a UNC path is provided as part of the pattern to match, it is incorrectly transformed to an invalid path on the local computer.

e.x. \\nas\node\ incorrectly becomes /nas/node which is treated as C:\nas\node\.

@treet
Copy link

treet commented Dec 2, 2013

Yes, I've run into this problem too. The readme states to only use forward slashes on Windows, but I'm wondering what the reasoning behind that restriction is.

Is there any fundamental problem that prevents implementing support for UNC paths?

@gotdibbs
Copy link
Author

gotdibbs commented Dec 2, 2013

@treet To be honest, I haven't had time to ramp up on node-globs code base to take a look at how support for this would work just yet. However, FYI this came up for me because Azure seems to use only UNC paths.

@tuxracer
Copy link

tuxracer commented Jan 3, 2014

As a workaround I've used:

path = require('path');
glob.sync(filename).map(function (item) {
  return path.resolve(item);
});

Example: https://github.com/tuxracer/stylus-import-tree/blob/master/src/index.coffee

@s-trooper
Copy link

i have the same problem.
i use plain js and the workaround don't help me.

staticshock added a commit to staticshock/node-glob that referenced this issue Oct 29, 2014
Wildcards that now work: \\host\directory\*

Wildcards that still don't work: \\host\*

Fixes isaacs#74
@staticshock
Copy link

Have a look at this pull request, which purports to implement decent UNC path handling. \\host\dirname is basically treated as if they were a drive letter, like C:, so wildcards don't work on that portion of the path, just like *: wouldn't have worked for a drive letter.

That can probably be improved, but, alas, I couldn't figure out a quick way to do it, because path.resolve("\\\\host") gets treated as a relative path and resolves to $PWD\host, so \\host can't be used as a valid root.

@staticshock
Copy link

I looked into it a bit more, and found another reason why \\host\dirname should probably remain as the root: fs.readdirSync("\\\\host") doesn't work anyway:

> fs.readdirSync("\\\\vboxsvr")
Error: ENOENT, no such file or directory 'C:\vboxsvr'
    at Object.fs.readdirSync (evalmachine.<anonymous>:654:18)
    at repl:1:5
    at REPLServer.self.eval (repl.js:110:21)
    at Interface.<anonymous> (repl.js:239:12)
    at Interface.EventEmitter.emit (events.js:95:17)
    at Interface._onLine (readline.js:202:10)
    at Interface._line (readline.js:531:8)
    at Interface._ttyWrite (readline.js:760:14)
    at ReadStream.onkeypress (readline.js:99:10)
    at ReadStream.EventEmitter.emit (events.js:98:17)
> fs.readdirSync("\\\\vboxsvr\\test")
[ 'child1',
  'child2' ]

staticshock added a commit to staticshock/node-glob that referenced this issue Nov 23, 2014
Wildcards that now work: \\host\directory\*

Wildcards that still don't work: \\host\*

Fixes isaacs#74
@staticshock
Copy link

Updated the PR to work with v4.2. I can change it further if you throw Feedback() at me.

@isaacs
Copy link
Owner

isaacs commented Dec 1, 2014

Sorry for the delay, I've been meaning to get to this, and hoped that I would over the thanksgiving holiday, but it slipped.

I'll try to land this week. Thanks for your patience.

@isaacs
Copy link
Owner

isaacs commented Dec 1, 2014

Don't worry about rebasing on master, I think the patch should land pretty cleanly, and it's relatively simple, so it shouldn't be too hard for me to pull forward if necessary.

staticshock added a commit to staticshock/node-glob that referenced this issue Dec 2, 2014
Wildcards that now work: \\host\directory\*

Wildcards that still don't work: \\host\*

Fixes isaacs#74 and isaacs#123
@staticshock
Copy link

No problem. I was thinking a bit about #123, though, and I realized that they have roughly the same solution, so here's a modified pull request that should fix the other issue as well (basically I just replaced isUnc with isAbsolute.)

@tomwayson
Copy link

This is keeping me from being able to use grunt-contrib-config to copy files from a network file share w/o first having to map the drive in Windows.

staticshock added a commit to staticshock/node-glob that referenced this issue Feb 13, 2015
Wildcards that now work: \\host\directory\*

Wildcards that still don't work: \\host\*

Fixes isaacs#74 and isaacs#123
@stefanpenner
Copy link

Ah, just ran into this one as well. I can confirm that @staticshock's fix appears to work.

@isaacs just a friendly reminder in-case this one has falling off your radar.

@isaacs
Copy link
Owner

isaacs commented Apr 24, 2015

@stefanpenner et al: See #146. I need a test that passes with the patch, and doesn't pass without the patch.

Nothing can be landed in this library with a valid test. I'm sorry for being so strict about this, but it's the only thing that makes maintenance of this module even remotely possible.

@stefanpenner
Copy link

Nothing can be landed in this library with a valid test. I'm sorry for being so strict about this, but it's the only thing that makes maintenance of this module even remotely possible.

I absolutely agree, good coverage is paramount.

I was sending the ping, not to merge, but to make sure you had not forgotten the issue in the first place. As there may have been a small chance you have time to address your own concerns. I suspect based on the comment you do not.

Although I have a work-around, I would prefer to not have to play wack-a-mole going forward. So let me see if I can nail down that test case for you this afternoon.

@staticshock
Copy link

I've already submitted a test case that works on Windows, and haven't really had any time to look at it since then. So if you tackle this, make sure your approach meets @isaacs's "must run on linux" criterion.

@stefanpenner
Copy link

@isaacs ah, it seems like this library should actually be run on a windows CI as well. What are your thoughts on this? I will gladly do the work to make it run on appveyor.

But, If it must provide "full coverage" on *nix, I can also dig in. Although doing it elegantly might require some more refactoring.

@isaacs
Copy link
Owner

isaacs commented Apr 24, 2015

Yes, the test needs to run on Unix (mostly so I don't inadvertently destroy it some day, which I probably will otherwise).

Windows CI would be awesome, and I'd greatly appreciate getting this module running somewhere. But it's not a replacement for a test that runs on Unix.

@stefanpenner
Copy link

Windows CI would be awesome, and I'd greatly appreciate getting this module running somewhere. But it's not a replacement for a test that runs on Unix.

proposed resolution:

  • get this project working running / testing on appveyor
  • ensure @staticshock's scenario is also testable in some way on nix

c/d ?

@isaacs
Copy link
Owner

isaacs commented Apr 24, 2015

Yes, plus one, would merge. I suggest hijacking or mocking whatever is necessary to make the patch in #146 testable on unix. That's actually all that's missing from getting to UNC support; appveyor is optional.

@stefanpenner
Copy link

If memory serves a mixture of UNC and cwd was the pandoras box I noticed. Basically if cwd was a UNC path, fun things would happen.

My PR (although some more massaging needed) even without the cwd support, would be a really good step in the correct direction. Fixing all the scenarios I could come across, except if a user changed the cwd to a UNC path. I suspect the cwd stuff could also be tackled, but maybe at a later time.

@isaacs would you be alright with improved UNC support being merged, but leaving some scenarios related to cwd also being on a UNC path for a future PR ?

Although not ideal, it would likely fix most users problems, without introducing any known regressions.

stefanpenner added a commit to stefanpenner/node-glob that referenced this issue Nov 14, 2015
Wildcards that now work: \\host\directory\*

Wildcards that still don't work: \\host\*

[fixes isaacs#74, isaacs#123, isaacs#146] handle UNC paths on win32

credit to @staticshock for the WinPath work
@cmawhorter
Copy link

has anyone explored require('path').normalize? from looking at the path.js source it looks like a lot of cross-platform work has been done and it supports UNC. i'm doing glob() { if (IS_WIN) path.normalize } in my workaround to fix my specific issue.

and there is cygwin paths which might be worth exploring?

@riteshatsencha
Copy link

Any updates on this issue? Facing the same issue. Thx.

@designerx2
Copy link

designerx2 commented Dec 20, 2016

Another user stung by the UNC issue. Is there a temporary work around for this issue? Any assistance is greatly appreciated. Thank you.

@michaeldewayneharris
Copy link

Any updates on this issue? Facing the same issue. Thx.

bdukes pushed a commit to bdukes/node-glob that referenced this issue Jul 13, 2017
Wildcards that now work: \\host\directory\*

Wildcards that still don't work: \\host\*

Fixes isaacs#74 and isaacs#123
bdukes pushed a commit to bdukes/node-glob that referenced this issue Jul 13, 2017
Wildcards that now work: \\host\directory\*

Wildcards that still don't work: \\host\*

Fixes isaacs#74 and isaacs#123
@Nepoxx
Copy link

Nepoxx commented Aug 14, 2017

Is this "simply" a case of passing the right path to the OS or is it more complicated in that you need some NFS specific code for node's fs?

@mpaland
Copy link

mpaland commented Nov 17, 2017

Late to this party... Having this issue on a Win10 node trying to access/scan a NAS like '\\host\my_media\**\*'.
@isaacs @stefanpenner Is there a mergable PR to fix this long standing UNC issue on Windows?
Would be very appreciated!

@pste
Copy link

pste commented Mar 2, 2018

@mpaland The party's not over :)
No needed to fix, use the cwd parameter:
glob("**/*.pdf", {cwd:"//host/my_media"}, (err, files) => { if (err) throw err; console.log(files) });

@bernardoadc
Copy link

@pste solution works with Windows drive letters as well ( {cwd:"C:"} )

@ray007
Copy link

ray007 commented Feb 28, 2019

I'm not using glob directly but through gulp.src(), and setting the cwd option there does not seem to help.

Not really familiar with the code, but after a quick look, could the problem be in the minimatch module?

@ray007
Copy link

ray007 commented Mar 8, 2019

Not sure what I did wrong last week, but the cwd option did just make things work.
Back to the original issue, because gulp.src() still fails.

@sangimed
Copy link

sangimed commented Apr 8, 2020

@mpaland The party's not over :)
No needed to fix, use the cwd parameter:
glob("**/*.pdf", {cwd:"//host/my_media"}, (err, files) => { if (err) throw err; console.log(files) });

EDIT: My bad :) I misplaced the sharedFolder so it's glob.sync("**/*.txt", {cwd:"//remoteComputerName/sharedFolder"}) instead of glob.sync("sharedFolder/**/*.txt", {cwd:"//remoteComputerName"})

Tried glob.sync("sharedFolder/**/*.txt", {cwd:"//remoteComputerName"}) in Windows Server 2012 R2 but didn't work (\\remoteComputerName works when accessed from the Explorer windows app).

PS: Only one folder is shared in the remoteComputerName (the very folder I need to run glob in) so I can't access to any drive of the remote.

@aza547
Copy link

aza547 commented Dec 12, 2022

@mpaland The party's not over :) No needed to fix, use the cwd parameter: glob("**/*.pdf", {cwd:"//host/my_media"}, (err, files) => { if (err) throw err; console.log(files) });

This works for me, but seems to be far less performant than the initial method (so much so that it's not viable in my application sadly).

@isaacs
Copy link
Owner

isaacs commented Feb 28, 2023

UNC paths are first class citizens now in v9. Only took 10 years to fix this bug 😬

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet