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

fs.lstatSync doesn't handle specific Windows REPARSE POINTS #12737

Closed
paulbouwer opened this issue Apr 29, 2017 · 16 comments
Closed

fs.lstatSync doesn't handle specific Windows REPARSE POINTS #12737

paulbouwer opened this issue Apr 29, 2017 · 16 comments
Labels
fs Issues and PRs related to the fs subsystem / file system. windows Issues and PRs related to the Windows platform.

Comments

@paulbouwer
Copy link

  • Version: 7.9.0
  • Platform: Windows 10 (16179)
  • Subsystem: fs (lstat)

Referenced issues:

Issue

While tracking down an issue affecting hyper, it lead me to the use by gaze of fs.lstatSync.

It seems that on Windows, there is something different about the reparse point on OneDrive local sync folders, that results in a EINVAL error from fs.lstatSync. The fs.lstatSync correctly handles other junctions, folders and files in HOME with no error.

Error example - OneDrive

C:\> node
> fs.lstatSync('C:/Users/pabouwer/OneDrive')
Error: EINVAL: invalid argument, lstat 'C:\Users\pabouwer\OneDrive'
    at Object.fs.lstatSync (fs.js:961:11)
    at repl:1:4
    at ContextifyScript.Script.runInThisContext (vm.js:23:33)
    at REPLServer.defaultEval (repl.js:339:29)
    at bound (domain.js:280:14)
    at REPLServer.runBound [as eval] (domain.js:293:12)
    at REPLServer.onLine (repl.js:536:10)
    at emitOne (events.js:101:20)
    at REPLServer.emit (events.js:191:7)
    at REPLServer.Interface._onLine (readline.js:241:10)

C:\> junction -nobanner "C:/Users/pabouwer/OneDrive"
C:\Users\pabouwer\OneDrive: UNKNOWN MICROSOFT REPARSE POINT

Working example - My Documents

C:\> node
> fs.lstatSync('C:/Users/pabouwer/My Documents')
Stats {
  dev: 2348871125,
  mode: 41398,
  nlink: 1,
  uid: 0,
  gid: 0,
  rdev: 0,
  blksize: undefined,
  ino: 8444249301777451,
  size: 27,
  blocks: undefined,
  atime: 2017-04-23T23:24:58.150Z,
  mtime: 2017-04-23T23:24:58.150Z,
  ctime: 2017-04-23T23:24:58.185Z,
  birthtime: 2017-04-23T23:24:58.150Z }

C:\> junction -nobanner "C:/Users/pabouwer/My Documents"
C:\Users\pabouwer\My Documents: JUNCTION
   Print Name     : C:\Users\pabouwer\Documents
   Substitute Name: C:\Users\pabouwer\Documents
@Trott Trott added windows Issues and PRs related to the Windows platform. fs Issues and PRs related to the fs subsystem / file system. labels Apr 29, 2017
@Trott
Copy link
Member

Trott commented Apr 29, 2017

@nodejs/platform-windows @nodejs/fs

@refack
Copy link
Contributor

refack commented Apr 30, 2017

So windows likes to create these "Broken" junctions all over the place that have the equivalent of chmod 000, and I think they are only used internally for WIN32 to resolve the actual folder they link to. You can't navigate into them even native windows tools bork when interacting with them as @paulbouwer demonstrated

C:\> junction -nobanner "C:/Users/pabouwer/OneDrive"
C:\Users\pabouwer\OneDrive: UNKNOWN MICROSOFT REPARSE POINT

Does anyone think we should handle them in a special manner?

P.S. Just the first answer I found in Google https://goo.gl/Daj2vu (the jist: don't mess with them)

P.P.S Every user home has these and none of them work.

 <JUNCTION>     Application Data [C:\Users\refael\AppData\Roaming]
 <JUNCTION>     Cookies [C:\Users\refael\AppData\Roaming\Microsoft\Windows\Cookies]
 <JUNCTION>     Local Settings [C:\Users\refael\AppData\Local]
 <JUNCTION>     My Documents [C:\Users\refael\Documents]
 <JUNCTION>     NetHood [C:\Users\refael\AppData\Roaming\Microsoft\Windows\Network Shortcuts]
 <JUNCTION>     PrintHood [C:\Users\refael\AppData\Roaming\Microsoft\Windows\Printer Shortcuts]
 <JUNCTION>     Recent [C:\Users\refael\AppData\Roaming\Microsoft\Windows\Recent]
 <JUNCTION>     SendTo [C:\Users\refael\AppData\Roaming\Microsoft\Windows\SendTo]
 <JUNCTION>     Start Menu [C:\Users\refael\AppData\Roaming\Microsoft\Windows\Start Menu]
 <JUNCTION>     Templates [C:\Users\refael\AppData\Roaming\Microsoft\Windows\Templates]

@bzoz
Copy link
Contributor

bzoz commented May 18, 2017

Sorry, I can't reproduce this. I've tried different machines, a fresh Win10 install, with OneDrive uninstalled, etc. Each time lstatSync returned without error.

@refack
Copy link
Contributor

refack commented May 19, 2017

Sorry, I can't reproduce this. I've tried different machines, a fresh Win10 install, with OneDrive uninstalled, etc. Each time lstatSync returned without error.

Someone is behaving better either the OS or libuv.

@bzoz
Copy link
Contributor

bzoz commented Jun 20, 2017

@paulbouwer can you provide some more info about your setup?

@refack
Copy link
Contributor

refack commented Jun 20, 2017

I was reading today about "OneDrive Files On-Demand", maybe that is the case, I'll try repro.

@UsmanMohammad
Copy link

Having the same issue, I am using insider build 16215 and have OneDrive Files On-Demand enabled
image

@refack
Copy link
Contributor

refack commented Jun 28, 2017

@UsmanMohammad thank you for the info.

@paulbouwer
Copy link
Author

@bzoz - I have this issue on Windows 10 that is pre the OneDrive Files On-Demand feature. I'll check what other additional info I can find.

@cerebrate
Copy link

cerebrate commented Jun 29, 2017

@paulbouwer Unfortunately, there're quite a lot of Windows features build on reparse points and have been since W2K, any of which can cause this error - mounting a volume on a folder, remote storage, distributed file system, junction points/symbolic links (which I believe lstat understands as equivalent to Unix-style symlinks, or at least it doesn't fail on them), single-instance storage, and that's not even counting the non-Microsoft stuff. Any of those other than junction points, I believe, will produce the same lstat()/lstatSync() error.

(Edited for thinko.)

bzoz added a commit to JaneaSystems/libuv that referenced this issue Jul 13, 2017
Allow for running uv_fs_stat and uv_fs_lstat on all reparse points

Ref: nodejs/node#12737
@bzoz
Copy link
Contributor

bzoz commented Jul 13, 2017

I've opened a PR to fix this in libuv: libuv/libuv#1419

bzoz added a commit to JaneaSystems/libuv that referenced this issue Jul 26, 2017
Allow for running uv_fs_stat and uv_fs_lstat on all reparse points

Ref: nodejs/node#12737
bzoz added a commit to libuv/libuv that referenced this issue Jul 26, 2017
Allow for running uv_fs_stat and uv_fs_lstat on all reparse points

Ref: nodejs/node#12737
PR-URL: #1419
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
@MikeKovarik
Copy link

So... uhhh... this is awkward. 4 months later and I still can't use OneDrive. :(

@bzoz
Copy link
Contributor

bzoz commented Aug 28, 2017

The fix was added to libuv 1.14.0. A PR for updating libuv in Node.js is already open: #14866

@refack
Copy link
Contributor

refack commented Aug 29, 2017

Also for context, this is a pre-release feature (OneDrive Files On-Demand). If all goes smoothly @bzoz's fix will be in node before this feature goes RTM.

@MikeKovarik
Copy link

It's not only affecting the on demand feature but it has become a problem for the whole OneDrive as of couple of last Win Insider builds. One of my PCs I have not been using on-demand on became affected recently and giving me a hard time working. So I'm glad to see this finally come to an end.

@wadetb
Copy link

wadetb commented Sep 6, 2017

I somehow missed this issue and fix last week, so I independently developed and submitted a new PR to libuv - libuv/libuv#1522. Compared to e5024c5, my PR solves this issue and other issues, so it may still be worth integrating.

The issue with the accepted change is that by preventing fs__stat_handle from failing, the retry logic in fs__stat_impl has become impossible to activate. The retry logic re-opens the file without FILE_FLAG_OPEN_REPARSE_POINT when symlink detection fails, and is the correct way to deal with non-symlink reparse points.

@cjihrig cjihrig closed this as completed in 8485a7c Sep 6, 2017
MylesBorins pushed a commit that referenced this issue Sep 10, 2017
Fixes: #12737
Fixes: #13581
Fixes: #15117
PR-URL: #14866
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
MylesBorins pushed a commit that referenced this issue Sep 11, 2017
Fixes: #12737
Fixes: #13581
Fixes: #15117
PR-URL: #14866
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
MylesBorins pushed a commit that referenced this issue Sep 12, 2017
Fixes: #12737
Fixes: #13581
Fixes: #15117
PR-URL: #14866
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
addaleax pushed a commit to addaleax/node that referenced this issue Sep 13, 2017
Fixes: nodejs#12737
Fixes: nodejs#13581
Fixes: nodejs#15117
PR-URL: nodejs#14866
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
MylesBorins pushed a commit that referenced this issue Oct 16, 2017
Fixes: #12737
Fixes: #13581
Fixes: #15117
PR-URL: #14866
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
MylesBorins pushed a commit that referenced this issue Oct 25, 2017
Fixes: #12737
Fixes: #13581
Fixes: #15117
PR-URL: #14866
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fs Issues and PRs related to the fs subsystem / file system. windows Issues and PRs related to the Windows platform.
Projects
None yet
Development

No branches or pull requests

8 participants