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

Refactor RealEnvStore methods to use uv_os_getenv/setenv/unsetenv #27211

Closed
joyeecheung opened this issue Apr 13, 2019 · 3 comments
Closed

Refactor RealEnvStore methods to use uv_os_getenv/setenv/unsetenv #27211

joyeecheung opened this issue Apr 13, 2019 · 3 comments
Labels
c++ Issues and PRs that require attention from people who are familiar with C++. good first issue Issues that are suitable for first-time contributors. os Issues and PRs related to the os subsystem. process Issues and PRs related to the process subsystem.

Comments

@joyeecheung
Copy link
Member

joyeecheung commented Apr 13, 2019

From a glance I think the uv_os_* methods are adequate to replace our conditional switches in the RealEnvStore methods.

I think this is a good first issue if you are familiar with C++ and has some idea on how to use libuv methods, but you may need to read into the libuv implementation to make sure the refactor does not change the functionality.

Pointers:

const char* val = getenv(*key);

setenv(*key, *val, 1);

if (getenv(*key)) return 0;

unsetenv(*key);

docs:

http://docs.libuv.org/en/v1.x/misc.html?highlight=uv_os_getenv#c.uv_os_getenv
http://docs.libuv.org/en/v1.x/misc.html?highlight=uv_os_getenv#c.uv_os_setenv
http://docs.libuv.org/en/v1.x/misc.html?highlight=uv_os_getenv#c.uv_os_unsetenv

@joyeecheung joyeecheung added good first issue Issues that are suitable for first-time contributors. os Issues and PRs related to the os subsystem. process Issues and PRs related to the process subsystem. c++ Issues and PRs that require attention from people who are familiar with C++. labels Apr 13, 2019
@joyeecheung
Copy link
Member Author

joyeecheung commented Apr 13, 2019

Prior work: #14641

It seems easier to refactor uv_os_setenv and uv_os_unsetenv, uv_os_getenv is trickier due to how the buffer allocation is handled - the caller needs to retry when the allocated buffer is not large enough.

@devasci
Copy link
Contributor

devasci commented Apr 15, 2019

Hi, It seems to be a good item for me as a first timer. I will work one this and will share the updates soon.

@devasci
Copy link
Contributor

devasci commented Apr 19, 2019

Modified as Joyee Cheung suggested and tested by following contributors guide.

Created pull request: #27310

addaleax pushed a commit to devasci/node that referenced this issue Aug 20, 2019
Modified RealEnvStore::Get - removed os switch statements
and replaced logic to use libuv uv_getos_env method.

Fixes: nodejs#27211
Refs: http://docs.libuv.org/en/v1.x/misc.html
addaleax pushed a commit to devasci/node that referenced this issue Aug 20, 2019
Modified RealEnvStore::Get, Set, Query and Delete methods
to use libuv methods environment variables operations instead
of using os specific logic and switches.

Fixes: nodejs#27211
Refs: http://docs.libuv.org/en/v1.x/misc.html
addaleax pushed a commit to devasci/node that referenced this issue Aug 20, 2019
Below review comments are taken care in this submission:
1. followed snake case naming convention for local variables
2. dropped sizeof(char) since it is obvious value 1
3. Used MaybeLocal<String> instead of Local<String> to check
for
   empty strings and throw exception if empty.

Fixes: nodejs#27211
Refs: https://v8docs.nodesource.com/node-4.8/annotated.html
addaleax pushed a commit to devasci/node that referenced this issue Aug 20, 2019
addaleax pushed a commit to devasci/node that referenced this issue Aug 20, 2019
Below review comments by Anna Henningsen are taken care:
	1. avoided Yoda style comparisons
	2. used MaybeStackBuffer instead of raw char pointers
	3. used MaybeLocal<String> to inspect for empty string value
            and then raise exception and return empty Local<String> handle.
            (Changing return type of RealEnvStore::Get method to MaybeLocal<String>
              is pending, and planning to submit in next commit)

Fixes: nodejs#27211
Refs: nodejs#27310 (comment)
addaleax pushed a commit to devasci/node that referenced this issue Aug 20, 2019
Modified KVStore::Get return type to MaybeLocal and also modified
RealEnvStore::Get, MapKVStore::Get respectively.

Fixes: nodejs#27211
Refs: nodejs#27310 (comment)
addaleax pushed a commit to devasci/node that referenced this issue Aug 20, 2019
Removed exception throwing if value is empty, since the same is handled
in caller and returned immediately.

Fixes: nodejs#27211
Refs: nodejs#27310 (comment)
addaleax pushed a commit to devasci/node that referenced this issue Aug 20, 2019
1. All tests were failing due to the exception raising from within 

   RealEnvStore::Get method, removed the exception raising since 

   the caller are checking for empty handles and taking necessary 
actions.
2. Used MayLocal<String>’s ToLocalChecked() function instead of
FromMaybe().

Fixes: nodejs#27211
Refs: nodejs#27310 (comment)
addaleax pushed a commit to devasci/node that referenced this issue Aug 20, 2019
Modified an if statment and formatted the code as per Joyee Cheung's
review comments

Fixes: nodejs#27211
Refs: nodejs#27310 (comment)
Refs: nodejs#27310 (comment)
addaleax pushed a commit to devasci/node that referenced this issue Aug 20, 2019
All windows tests were failing after previous commit, as per
Joyee Cheung suggestion modified to inspect the first character
of env variable key’s on windows machine for the character ‘=‘
and skip if the key contains. Since these keys are hidden/read-only
env vars in windows machines.

Fixes: nodejs#27211
Refs: nodejs#27310 (comment)
targos pushed a commit that referenced this issue Sep 20, 2019
Modified RealEnvStore::Get, Set, Query and Delete methods
to use libuv methods environment variables operations instead
of using os specific logic and switches.

Fixes: #27211
Refs: http://docs.libuv.org/en/v1.x/misc.html

PR-URL: #27310
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
BridgeAR pushed a commit that referenced this issue Sep 25, 2019
Modified RealEnvStore::Get, Set, Query and Delete methods
to use libuv methods environment variables operations instead
of using os specific logic and switches.

Fixes: #27211
Refs: http://docs.libuv.org/en/v1.x/misc.html

PR-URL: #27310
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ Issues and PRs that require attention from people who are familiar with C++. good first issue Issues that are suitable for first-time contributors. os Issues and PRs related to the os subsystem. process Issues and PRs related to the process subsystem.
Projects
None yet
Development

No branches or pull requests

2 participants