Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Path normalization is broken for paths like C:\ (makes Atom misbehave) #109

Open
magv opened this issue Jul 15, 2016 · 1 comment
Open

Comments

@magv
Copy link

magv commented Jul 15, 2016

Hi. I've been investigating a broken behavior in Atom, and traced it down to this library.

In short, if you create a Directory for C:\ like so:

var pw = require("pathwatcher");
var d = new pw.Directory("C:\\");
console.log(d.path);
// "C:" is printed

... the path is normalized to C: (see directory.cofee; introduced in 0630c38). This normalization is incorrect; path should remain at C:\.

The problem is that libaries like node's path recognize C:\ as an absolute directory (path.isAbsolute("C:\\") is true), but not C: (path.isAbsolute("C:") is false). This, among other things, leads to various problems when you pass C:, where C:\ should have been.

The impact of the problem is this: when you add a project path to Atom and select a drive, like C: (or, Z: in my case; it's a network mapped drive), atom.pickFolder returns path in the correct form C:\. After you exit Atom, ~/.atom/storage says that initialPath is actually C:. This is due to normalization that pathwatcher performs (note that path.normalize and fs-plus.absolute all preserve the final slash). When you reopen Atom, it will try to create a new file called C (located in Atom's installation path) in addition to opening directories. This behavior is bogus, and does not happen if initialPath is set to C:\.

I think pathwatcher should change it's normalization somehow. Maybe abolish it altogether. Maybe always add a trailing slash instead of removing it. Whatever you think is best. I look forward to not having my Atom broken.

@jcush
Copy link

jcush commented Nov 25, 2016

I've experienced a similar issue which I think this is the cause of.

When I go to create a new file in a project by right-clicking on a folder and choosing New File the pre-filled file path in the resulting popup misses off the drive's backslash as @magv has outlined above. This produces the following error on submitting the proposed file name:

image

Manually adding the backslash to the drive fixes the issue, obviously, but it's a bit of a minor inconvenience having to do it every time.

I must say I'm suprised nobody else has mentioned this already (unless I've just missed the boat on that one?) since adding a file must be a common action, no?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants