Skip to content

docker: ignore symlinks if already present#5

Merged
piranna merged 1 commit intoNodeOS:masterfrom
luii:master
Jun 30, 2016
Merged

docker: ignore symlinks if already present#5
piranna merged 1 commit intoNodeOS:masterfrom
luii:master

Conversation

@luii
Copy link
Copy Markdown
Member

@luii luii commented Apr 12, 2016

No description provided.

Comment thread server.js Outdated
if(error && error.code != 'EEXIST') return callback(error)

fs.symlinkSync('/proc/mounts', '/etc/mtab')
var mtab = fs.lstatSync('/etc/mtab') // get stat of /etc/mtab
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mind using a try-catch instead of checking if it exists first? Besides that, you got the point ;-)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldnt it be better to check first if the symbolic link exists? And then create it.
In either way if we use docker the symbolic link wont be created, and on normal systems like qemu it creates the link.
I dont mind to try catch just fs.symlinkSync('/proc/mounts', '/etc/mtab') but for me it would be more like a bad manner.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldnt it be better to check first if the symbolic link exists? And then
create it.
I dont mind to try catch just fs.symlinkSync('/proc/mounts', '/etc/mtab')
but for me it would be more like a bad manner.

Au contraire mon ami, doing it this way you only access the filesystem one
time instead of two as would happen if you check first for the existence of
the file, and also it prevent a race condition. Remember, it's better to
say sorry than ask for permission ;-)

In either way if we use docker the symbolic link wont be created, and on
normal systems like qemu it creates the link.

Yes, that's the expected behaviour :-)

@luii
Copy link
Copy Markdown
Member Author

luii commented Apr 18, 2016

updated the PR

Comment thread server.js Outdated
try {
fs.symlinkSync('/proc/mounts', '/etc/mtab')
} catch (e) {
if (e && e.code != 'EPERM') return callback(e)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well... if there's an exception the e variable will always be set so there's no need to check for it's existence (left part of the conditional), but if you don't want to change it it's ok for me :-)

@piranna
Copy link
Copy Markdown
Member

piranna commented Jun 27, 2016

It was such a long time I forgot about this changes :-P Can you rebase them? I would gladly merge them later :-) If you want, you can be able to use async.parallel() using an object to map symlinks to targets and the async version of the symlink function since the async library is already a dependency... :-)

@luii
Copy link
Copy Markdown
Member Author

luii commented Jun 29, 2016

@piranna okay after trying to understand the rebasing in git i think i got it.
Wouldnt it be better to use Node.js es6 features like promises (promise.all)?

@luii luii changed the title create mtab symlink if not exists docker: ignore symlinks if already present Jun 29, 2016
@piranna
Copy link
Copy Markdown
Member

piranna commented Jun 29, 2016

@piranna okay after trying to understand the rebasing in git i think i got it.

Cool! :-)

Wouldnt it be better to use Node.js es6 features like promises (promise.all)?

It would, but since we are using functions from the Node.js core library that by design don't use (and will not) use Promises, since we are already using async.js I think it's better to stick with it. Yeah, we could use some wrapper functions and use promises, but I think it would get uglier.

@luii
Copy link
Copy Markdown
Member Author

luii commented Jun 30, 2016

@piranna you can merge it, and the for the async.parallel i make a new PR

@piranna piranna merged commit c2d12de into NodeOS:master Jun 30, 2016
@piranna
Copy link
Copy Markdown
Member

piranna commented Jun 30, 2016

Merged and published as v0.1.6.

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

Successfully merging this pull request may close these issues.

2 participants