-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
path: tilde expansion #684
Comments
> var fs = require('fs');
undefined
> fs.mkdirSync('~test');
undefined
> fs.writeFileSync('~test/~file', 'myData');
undefined
> fs.readFileSync('~test/~file', 'utf8');
'myData' Seeing as right now one can viably and reliably write to / read from / create directories with a tilde as a prefix, I'd say that this would cause a breaking change and require |
I'm -1 on this. On the one hand yes, many developers may expect There's also other issues:
|
-1, similar reasons to @mscdex, mainly because this is a shell construct and we are not building a shell. |
Good point. While shells allow a simple |
I think it's decided then. For anyone needing tilde expansion, have a look at untildify. I'm planning to add support for the more exotic tilde expansions of bash to it too. |
This functionality could be added to the posix._makeLong() function (lib/path.js), and that avoids the problem of what to do on Windows. win32._makeLong() has it's own logic for resolving path names, for POSIX there is no 'smart' logic. |
has this been fixed? it's causing aws-sdk to break, which uses ~/.aws/credentials CredentialsError: Missing credentials in config |
I just tested node 6.3.1 and it's not fixed. You can test it by doing something like |
No. You can use |
For everyone who stumbles upon this. Here's what I came up with (if you're working with a file in a directory / directories): let credentials = '~/root/foo/bar/key.json';
const credParts = credentials.split(path.sep);
if (credParts[0] === '~') {
credParts[0] = os.homedir();
credentials = credParts.reduce((memo, part) => path.join(memo, part), '');
} |
Two other variations: let credentials = '~/root/foo/bar/key.json';
credentials = credentials.replace(/^~/, os.homedir()); If you use node >= v6 let credentials = '~/root/foo/bar/key.json';
const credParts = credentials.split(path.sep);
if (credParts[0] === '~') {
credParts[0] = os.homedir();
}
credentials = path.join(...credParts); |
Your examples will fail on files named |
That's valid (asking as an occasional non-expert *inx user)? |
Sure, filenames can start with a literal |
We are using `spawn` method to execute a CodeChecker command. If the executable path starts with a `~` (e.g.: `~/CodeChecker/bin/CodeChecker`), the `spawn` method doesn't work properly and will give an exception. For more information see: nodejs/node#684 To solve this problem we will expand the `~` in the file path before executing the command.
We are using `spawn` method to execute a CodeChecker command. If the executable path starts with a `~` (e.g.: `~/CodeChecker/bin/CodeChecker`), the `spawn` method doesn't work properly and will give an exception. For more information see: nodejs/node#684 To solve this problem we will expand the `~` in the file path before executing the command.
Carrying over this often-requested feature from nodejs/node-v0.x-archive#2857. There's two mechanisms in Unix concering the tilde in paths:
~
at the beginning of a path string to the current user's home directory.~user
at the beginning of a path string to the given user's home directory.The first part should be quite trivial to add if #682 get implemented. The second part is far more uncommon and would likely require
passwd
parsing (for which consensus seems to be that it's libuv territory - libuv/libuv#11), and god-knows-what on Windows.Would we be satisified if only the first part gets added to all relevant
path
functions? I assume this could be added in a non-breaking way, which wouldn't require a semver-major bump.The text was updated successfully, but these errors were encountered: