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

[Fix #2407] Use Etc.getpwuid.name to retrieve user login #2408

Merged
merged 2 commits into from Nov 10, 2015

Conversation

jujugrrr
Copy link
Contributor

@jujugrrr jujugrrr commented Nov 9, 2015

#2407.

Might be a better approach than #2406 as it keeps the "per login" cache feature.
I'll close when any of the 2 PR got merged.

@martinb3
Copy link

martinb3 commented Nov 9, 2015

👍 #2374 broke rubocop for us, since it missed some nil handling.

@bbatsov
Copy link
Collaborator

bbatsov commented Nov 9, 2015

So, this is not going to return nil ever, right?

@jujugrrr
Copy link
Contributor Author

jujugrrr commented Nov 9, 2015

So, this is not going to return nil ever, right?

It will definitely help to fallback to some default values. Same thing for Dir.tmpdir. The original PR passed without the safeguard, so I'm just changing the used method to what seems (I'm not an expert in getting user login 😉 ) less likely to error.

If we set some default values, then we need to chose what they are. If #2406 is a better approach it's cool for me too. It seems there was no test for 88dc507 before (or even the cache_root). Not sure how to test it easily. I've giving it a try

@alexdowad
Copy link
Contributor

Just looked at the MRI source.

Etc.getlogin is a thin wrapper around getlogin (function prototype in unistd.h), Etc.getpwuid is a thin wrapper around getpwuid (function prototype in pwd.h).

The manpage on getlogin is very vague about how it gets its information. getpwuid is clear enough -- it reads from /etc/passwd.

@alexdowad
Copy link
Contributor

The point here is to de-duplicate, right? It doesn't really matter if the file path uses the username or something else. Why don't you use a numeric UID? That won't require reading /etc/passwd or anything.

@bbatsov
Copy link
Collaborator

bbatsov commented Nov 9, 2015

Why don't you use a numeric UID? That won't require reading /etc/passwd or anything.

Fine by me.

@alexdowad
Copy link
Contributor

You can do that using Process.uid.

@bbatsov
Copy link
Collaborator

bbatsov commented Nov 9, 2015

We can also check for the username and fallback the uid if it's nil, as usernames definitely create easier to comprehend folder names. Not a biggie, but still someone might take a look at the folders.

@jujugrrr
Copy link
Contributor Author

jujugrrr commented Nov 9, 2015

We can also check for the username and fallback the uid if it's nil, as usernames definitely create easier to comprehend folder names

It's what I've done based on #2406. I've tried to add tests too, but you probably want stuffs to be moved around or renamed.

  the cache path when we cannot find the user name
    is created within the rubocop_cache folder
  the cache path when we can find the user name
    is created within a user name folder

@jujugrrr
Copy link
Contributor Author

jujugrrr commented Nov 9, 2015

hum it seems, it's failing on jruby...

@alexdowad
Copy link
Contributor

You're falling back to a blank string, not to a numeric UID.

@jujugrrr
Copy link
Contributor Author

jujugrrr commented Nov 9, 2015

You're falling back to a blank string, not to a numeric UID.

You want me to fallback to Process.uid ?

@alexdowad
Copy link
Contributor

I got the following through e-mail:

Actually it would defeat the purpose of the cache I guess as it will change every time you run it.

Your user ID number will not change every time you run RuboCop, unless you log out and log in again using a different account.

The point of using a user ID number is that the cache will still be per-user, rather than global. Every process has a user ID, and there is little that can go wrong when retrieving it. (Unlike retrieving the user name, which as we have seen, can be problematic sometimes.)

@jujugrrr
Copy link
Contributor Author

jujugrrr commented Nov 9, 2015

Your user ID number will not change every time you run RuboCop, unless you log out and log in again using a different account.

yep, my bad that's why I removed the comment 😉 . I read it quickly in my head and it sounded like pid.

@jujugrrr jujugrrr force-pushed the safer_login_retrieval branch 3 times, most recently from 5015e57 to 0ca5d8f Compare November 9, 2015 16:04
@jujugrrr
Copy link
Contributor Author

jujugrrr commented Nov 9, 2015

I've pushed the fix.

@masarakki
Copy link
Contributor

👍

@bbatsov
Copy link
Collaborator

bbatsov commented Nov 10, 2015

@jujugrrr ping :-)

@jujugrrr
Copy link
Contributor Author

@bbatsov had suggested that a username is desirable when it is available... could you use Etc.getpwuid.name, and fall back to Process.uid.to_s if that is nil or empty?

Etc.getpwuid.name failed the test for jruby implementation, I've never used Jruby, Maybe using getlogin then falling back to Process.uid is enough and compatible with all the platforms.

@jujugrrr ping :-)

@bbatsov Please comment above and I'm happy to submit a latest PR 😉

@jujugrrr jujugrrr force-pushed the safer_login_retrieval branch 2 times, most recently from 3c35302 to ec78dc9 Compare November 10, 2015 10:42
@jujugrrr
Copy link
Contributor Author

continuous-integration/travis-ci/pr

Gem::InstallError: tins requires Ruby version >= 2.0.
An error occurred while installing tins (1.7.0), and Bundler cannot continue.
Make sure that `gem install tins -v '1.7.0'` succeeds before bundling.

It seems tins new release (10th November) is not compatible with ruby 1.9.
I've pinned it in the gemspec.

No idea on how to fix the code coverage getting lower as I've added more tests...

@alexdowad
Copy link
Contributor

Forget about the code coverage getting lower. Coveralls is the bane of this project.

@jujugrrr
Copy link
Contributor Author

issues on jruby. Not sure how the original change passed

@alexdowad I let you investigate

@bbatsov
Copy link
Collaborator

bbatsov commented Nov 10, 2015

I don't even know what tins is.

@alexdowad
Copy link
Contributor

I don't even know what tins is.

It's a dependency of my favorite gem, coveralls!

@alexdowad
Copy link
Contributor

I suggest that we just use a numeric UID. All of this messing around just for making the name of a temp directory look pretty is not worth it.

@bbatsov
Copy link
Collaborator

bbatsov commented Nov 10, 2015

Fair enough.

I'd also appreciate an alternative of coveralls, so if someone can I find one I'm instantly getting rid of this junk.

@jujugrrr
Copy link
Contributor Author

I suggest that we just use a numeric UID. All of this messing around just for making the name of a temp directory look pretty is not worth it.

Fair enough

Fair enough.

I would suggest to review 3 things based on this PR though :

  • how did this change get in in the first place: If you wanted test and handle different cases, then the first PR should not have been merged
  • how to deal with breaking changes : It's a breaking change for a lot of people using Jenkins or other CI environment (gitlab). By delaying rollback/fix you are forcing people to pin down to an old rubocop version
  • how to deal with contributors : I've redone the PR 5 times because you changed your mind on the approach to follow and because you are asking for a much higher quality than the origin PR (I had to implement test for a method which has never been tested).

My feedback is, most people will be reluctant to contribute again to the project after this kind of experience. Which is the shame 😉. I let the branch there, feel free to use it or not.

@jujugrrr jujugrrr closed this Nov 10, 2015
schisamo added a commit to chef-boneyard/delivery-truck that referenced this pull request Nov 10, 2015
If a builder executes the `rubocop` command with the latest version the
job fails with a `no implicit conversion of nil into String` error. This
is a known issue with this version and has a fix pending:
rubocop/rubocop#2407
rubocop/rubocop#2408

The easiest delivery-truck workaround is to ensure $USER is set in the
subprocess that executes the linting.
@bbatsov
Copy link
Collaborator

bbatsov commented Nov 10, 2015

how did this change get in in the first place: If you wanted test and handle different cases, then the first PR should not have been merged

Obviously we didn't envision this would ever return nil. That's just a fact of life - errors do happen. :-)

how to deal with breaking changes : It's a breaking change for a lot of people using Jenkins or other CI environment (gitlab). By delaying rollback/fix you are forcing people to pin down to an old rubocop version

Same here - this wasn't supposed to be a breaking change. It's regrettable that this happened, but RuboCop is not my life and I can't start jumping through hoops, so that everyone would be happy. I've invested an enormous amount of personal time in the project, so I really don't feel that I owe anything more to the users. I want to solve issues as fast as possible, but this is not always possible.

how to deal with contributors : I've redone the PR 5 times because you changed your mind on the approach to follow and because you are asking for a much higher quality than the origin PR (I had to implement test for a method which has never been tested).

That's just how open-source works - ideas get discussed, implemented, rethought. I don't see the problem with that. I definitely don't want to waste anyone's time, but I'm not always certain what be best course of action is until some ideas have been brought to the table. Everyone who has contributed to RuboCop knows that I'm pretty rigid and hard to please at times and still issues do manage to squeeze in. Imagine what would have happened otherwise. Let's just reopen this and wrap it.

@bbatsov bbatsov reopened this Nov 10, 2015
@@ -79,7 +79,12 @@ def self.cleanup(config_store, verbose, cache_root = nil)

def self.cache_root(config_store)
root = config_store.for('.')['AllCops']['CacheRootDirectory']
root = File.join(Dir.tmpdir, Etc.getlogin) if root == '/tmp'
if Etc.getlogin.nil? || Etc.getlogin.empty?
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's just simplify this to using the UID and be done with it. We've wasted enough time already.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure

@bbatsov
Copy link
Collaborator

bbatsov commented Nov 10, 2015

I'm very thankful to every contributor and I most certainly appreciate their time and desire to help the project!

@jujugrrr
Copy link
Contributor Author

I'm very thankful to every contributor and I most certainly appreciate their time and desire to help the project!

hehe I know, it's just to make sure they have a good experience(or not a bad one). which is different from appreciating what they are doing.

@alexdowad
Copy link
Contributor

Thanks @jujugrrr!

@jujugrrr
Copy link
Contributor Author

Here it is

bbatsov added a commit that referenced this pull request Nov 10, 2015
[Fix #2407] Use Etc.getpwuid.name to retrieve user login
@bbatsov bbatsov merged commit 888a67a into rubocop:master Nov 10, 2015
@bbatsov
Copy link
Collaborator

bbatsov commented Nov 10, 2015

👍

@bbatsov
Copy link
Collaborator

bbatsov commented Nov 10, 2015

0.35.1 is out.

@alexdowad
Copy link
Contributor

Thanks @bbatsov!

@deivid-rodriguez
Copy link
Contributor

I'd also appreciate an alternative of coveralls, so if someone can I find one I'm instantly getting rid of this junk.

I use codeclimate-test-reporter myself, which has a smaller set of dependencies:

coveralls (0.8.5)
  json (~> 1.8)
  rest-client (>= 1.6.8, < 2)
   simplecov (~> 0.10.0)
   term-ansicolor (~> 1.3)
   thor (~> 0.19.

vs

codeclimate-test-reporter (0.4.8)
   simplecov (>= 0.7.1, < 1.0.0)

@jujugrrr jujugrrr deleted the safer_login_retrieval branch November 11, 2015 08:22
koic added a commit that referenced this pull request Nov 20, 2023
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.

None yet

6 participants