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

Throws error if path leading to a file doesn't exist yet. #99

Open
ZeeCoder opened this issue Jan 28, 2020 · 4 comments
Open

Throws error if path leading to a file doesn't exist yet. #99

ZeeCoder opened this issue Jan 28, 2020 · 4 comments

Comments

@ZeeCoder
Copy link

First of all: thanks for the great lib!

I've encountered a weird issue.

This works fine even if the file doesn't exist:

lockfile.lock('./file.txt');

This however throws errors, when the path doesn't exist yet:

lockfile.lock('./path/that/does/not/exist/file.txt');

For the time being I've just made sure to use a wrapper that ensures directory paths leading to files that are about to be locked (whether existing or not yet) exist.

@satazor
Copy link
Contributor

satazor commented Jan 28, 2020

Hello! That’s because we try to resolve the real path of the file. You may disable the realpath option to disable this behavior.

@ZeeCoder
Copy link
Author

Yeah I tried that. 🤔

With realpath: false I get this error:

ENOENT: no such file or directory, mkdir (...)

With realpath: true, I get this:

Error: ENOENT: no such file or directory, lstat (...)

@satazor
Copy link
Contributor

satazor commented Jan 28, 2020

Oh I misunderstood the question. At the moment, the path to the file must exist.

Perhaps we could create the directory first with the mkdirp package, perhaps under and option. Are you willing to take some time to contribute? I'm happy to review a PR that implements this.

@ZeeCoder
Copy link
Author

Yeah I might, I've simply used fs-extra's ensureDir function at the moment, not sure if graceful-fs has anything like it:
https://github.com/jprichardson/node-fs-extra/blob/master/docs/ensureDir.md

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

No branches or pull requests

2 participants