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

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

Comments

Projects
None yet
2 participants
@joyeecheung
Copy link
Member

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

This comment has been minimized.

Copy link
Member Author

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

This comment has been minimized.

Copy link

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 added a commit to devasci/node that referenced this issue Apr 19, 2019

src: modified RealEnvStore::Get method to use libuv functions
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

devasci added a commit to devasci/node that referenced this issue Apr 19, 2019

src: modified RealEnvStore methods to use libuv functions
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
@devasci

This comment has been minimized.

Copy link

commented Apr 19, 2019

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

Created pull request: #27310

devasci added a commit to devasci/node that referenced this issue Apr 19, 2019

src: removed unnecessary blank line causing linter fail
Removed a unnecessary blank line causing linter fail while
building as per devsnek’s review comments.

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

devasci added a commit to devasci/node that referenced this issue Apr 19, 2019

src: modified RealEnvStore::Get method to use libuv functions
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

devasci added a commit to devasci/node that referenced this issue Apr 19, 2019

src: modified RealEnvStore methods to use libuv functions
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

devasci added a commit to devasci/node that referenced this issue Apr 19, 2019

src: removed unnecessary blank line causing linter fail
Removed a unnecessary blank line causing linter fail while
building as per devsnek’s review comments.

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

devasci added a commit to devasci/node that referenced this issue Apr 19, 2019

src: Modified src/node_env_var.cc as per Joyee Cheung’s review comments
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

devasci added a commit to devasci/node that referenced this issue Apr 19, 2019

devasci added a commit to devasci/node that referenced this issue Apr 20, 2019

src: modified RealEnvStore::Get method to use libuv functions
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

devasci added a commit to devasci/node that referenced this issue Apr 20, 2019

src: modified RealEnvStore methods to use libuv functions
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

devasci added a commit to devasci/node that referenced this issue Apr 20, 2019

src: removed unnecessary blank line causing linter fail
Removed a unnecessary blank line causing linter fail while
building as per devsnek’s review comments.

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

devasci added a commit to devasci/node that referenced this issue Apr 20, 2019

src: Modified src/node_env_var.cc as per Joyee Cheung’s review comments
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

devasci added a commit to devasci/node that referenced this issue Apr 20, 2019

devasci added a commit to devasci/node that referenced this issue Apr 20, 2019

src: refactor RealEnvStore methods - review comments fixing - 1
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)

devasci added a commit to devasci/node that referenced this issue Apr 20, 2019

src: refactor RealEnvStore methods - review comments fixing - 2
Modified KVStore::Get return type to MaybeLocal and also modified
RealEnvStore::Get, MapKVStore::Get respectively.

Fixes: nodejs#27211
Refs: nodejs#27310 (comment)

devasci added a commit to devasci/node that referenced this issue Apr 20, 2019

src: refactor RealEnvStore methods - review comments fixing - 2a
Removed exception throwing if value is empty, since the same is handled
in caller and returned immediately.

Fixes: nodejs#27211
Refs: nodejs#27310 (comment)

devasci added a commit to devasci/node that referenced this issue Apr 22, 2019

src: refactor RealEnvStore methods - review comments fixing - 3
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)

devasci added a commit to devasci/node that referenced this issue Apr 24, 2019

src: modified RealEnvStore::Get method to use libuv functions
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

devasci added a commit to devasci/node that referenced this issue Apr 24, 2019

src: modified RealEnvStore methods to use libuv functions
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

devasci added a commit to devasci/node that referenced this issue Apr 24, 2019

src: removed unnecessary blank line causing linter fail
Removed a unnecessary blank line causing linter fail while
building as per devsnek’s review comments.

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

devasci added a commit to devasci/node that referenced this issue Apr 24, 2019

src: Modified src/node_env_var.cc as per Joyee Cheung’s review comments
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

devasci added a commit to devasci/node that referenced this issue Apr 24, 2019

devasci added a commit to devasci/node that referenced this issue Apr 24, 2019

src: refactor RealEnvStore methods - review comments fixing - 1
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)

devasci added a commit to devasci/node that referenced this issue Apr 24, 2019

src: refactor RealEnvStore methods - review comments fixing - 2
Modified KVStore::Get return type to MaybeLocal and also modified
RealEnvStore::Get, MapKVStore::Get respectively.

Fixes: nodejs#27211
Refs: nodejs#27310 (comment)

devasci added a commit to devasci/node that referenced this issue Apr 24, 2019

src: refactor RealEnvStore methods - review comments fixing - 2a
Removed exception throwing if value is empty, since the same is handled
in caller and returned immediately.

Fixes: nodejs#27211
Refs: nodejs#27310 (comment)

devasci added a commit to devasci/node that referenced this issue Apr 24, 2019

src: refactor RealEnvStore methods - review comments fixing - 3
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)

devasci added a commit to devasci/node that referenced this issue Apr 24, 2019

src: refactor RealEnvStore methods - Joyee Cheung’s review remarks fixed
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)

devasci added a commit to devasci/node that referenced this issue Apr 30, 2019

src: handle windows hidden/read-only env keys in set/query methods
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.