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

Switch/installation fails #13

Closed
michaellopez opened this issue Oct 20, 2015 · 11 comments
Closed

Switch/installation fails #13

michaellopez opened this issue Oct 20, 2015 · 11 comments

Comments

@michaellopez
Copy link

I had an installation of Homebrew already in /usr/local.

Ran sudo ./brewdo switch inside my clone of zigg/brewdo. It gave me an error that /Library/Caches/Homebrew/Formula does not exist.

$ sudo ./brewdo switch
./brewdo:325:in `stat': No such file or directory - /Library/Caches/Homebrew/Formula (Errno::ENOENT)
    from ./brewdo:325:in `file_owner'
    from ./brewdo:335:in `switch_owners'
    from ./brewdo:361:in `cmd_migrate'
    from ./brewdo:298:in `cmd_switch'
    from ./brewdo:392:in `<main>'

Trying to do another switch gave me:

$ sudo ./brewdo switch
./brewdo:129:in `cmd_adduser': owner account exists (OwnerExistsError)
    from ./brewdo:296:in `cmd_switch'
    from ./brewdo:392:in `<main>'

After a sudo ./brewdo deluser I tried to switch again:

./brewdo:192:in `mkdir': File exists - /var/log/homebrew (Errno::EEXIST)
    from ./brewdo:192:in `create_homebrew_log'
    from ./brewdo:275:in `cmd_mklogdir'
    from ./brewdo:297:in `cmd_switch'
    from ./brewdo:392:in `<main>'

After a sudo ./brewdo deluser && rm -rf /var/log/homebrew I managed to switch again but gave me the first error message again (understandably, I hadn't created the path).

I think all the above shouldn't error out. The paths should be optional and the user account creation should be satisfied that it exists rather than throwing an error saying that it already exists.

Please don't add HOMEBREW_CACHE to the directories created by cmd_mkdirs to fix the first error message above! If it does not exist, it is still a valid and working Homebrew installation. I don't want unnecessary folders loitering on my system.

What are your thoughts on this? @Zigg

@michaellopez
Copy link
Author

More failures. After the above I did mkdir -p /Library/Caches/Homebrew/Formula so that the first error message does not show. That passed, but gave me this instead:

$ sudo ./brewdo switch
./brewdo:325:in `stat': No such file or directory - /usr/local/Library/ENV/pkgconfig/fuse/fuse.pc (Errno::ENOENT)
    from ./brewdo:325:in `file_owner'
    from ./brewdo:345:in `block in switch_owners'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/find.rb:43:in `block in find'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/find.rb:42:in `catch'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/find.rb:42:in `find'
    from ./brewdo:344:in `switch_owners'
    from ./brewdo:361:in `cmd_migrate'
    from ./brewdo:298:in `cmd_switch'
    from ./brewdo:392:in `<main>'

The file /usr/local/Library/ENV/pkgconfig/fuse/fuse.pc is a symlink, maybe that is why its choking?

Some more output:

$ ls -la /usr/local/Library/ENV/pkgconfig/fuse/fuse.pc
lrwxrwxr-x  1 dev  admin  32 May  5 09:55 /usr/local/Library/ENV/pkgconfig/fuse/fuse.pc -> /usr/local/lib/pkgconfig/fuse.pc
$ stat /usr/local/Library/ENV/pkgconfig/fuse/fuse.pc
16777218 537076 lrwxrwxr-x 1 dev admin 0 32 "May  5 09:55:20 2015" "May  5 09:55:20 2015" "May  8 13:54:49 2015" "May  5 09:55:20 2015" 4096 8 0 /usr/local/Library/ENV/pkgconfig/fuse/fuse.pc
$ brew ls
autoconf    gettext     libgpg-error    nano        openssl     tree
automake    git     libksba     ncurses     pcre
bash-completion iftop       libtool     nginx-full  pkg-config
brew-cask   jenkins     libyaml     nvm     readline

@michaellopez
Copy link
Author

For any future users: this is the equivalent of what the script is doing:

sudo chown -R _homebrew:wheel /usr/local/
sudo chown -R _homebrew:admin /Library/Caches/Homebrew/Formula
sudo chmod 755 /usr/local
sudo chmod 755 /Library/Caches/Homebrew/Formula

Try that in the mean time this issue gets resolved.

@frdmn
Copy link

frdmn commented Oct 20, 2015

Thanks for letting us know, Michael 👍

@mattieb
Copy link
Collaborator

mattieb commented Oct 20, 2015

Wondering if that symlink might be dangling, i.e. the file that references it is missing? I might be able to test this and try to fix it this evening. Sorry it's giving you so much trouble; I appreciate your willingness to dig into it.

@michaellopez
Copy link
Author

@Zigg Yes, good catch. It is dangling. I think that this should be guarded against in line 345@4057ca01

I'm glad to help. Let me know if there is something else I can help with.

@mattieb
Copy link
Collaborator

mattieb commented Nov 1, 2015

I'm looking into this today and I'm wondering if the correct solution is to avoid trying to chown symlinks at all.

If a symlink happened to point outside the homebrew home, then we could end up touching files outside. Not good.

And on the other side of that coin, symlink ownership really doesn't matter, unless there's a case I'm not thinking of.

Thoughts?

Aside: I'm having some bothersome issues with the OS X VMs I usually use to test out bigger things like brewdo switch, so a fix may be slow in coming.

@mattieb mattieb closed this as completed Nov 1, 2015
@mattieb mattieb reopened this Nov 1, 2015
@michaellopez
Copy link
Author

@Zigg The only significance I know of symlink ownership is tied to launchctl/launchd. It won't startup services that have "dubious" ownerships. In my case above ignoring the symlink, regardless if it exists or not, would have worked. But I would like to have the symlink itself owned by _homebrew just for aesthetics of ls -la in a folder.

@mattieb
Copy link
Collaborator

mattieb commented Nov 5, 2015

I'm still wrestling with VMs—see timsutton/osx-vm-templates#43.

But I did do a little bit of digging and I'm wondering if perhaps replacing chown(2) calls with lchown(2) calls would solve the issue, and be a better citizen regarding files living outside /usr/local as well.

When presented with a symlink, lchown(2) will change ownership on the symlink and leave the referenced file alone. If presented with a normal file or directory, it behaves the same as chown(2).

Ruby's File class has lchown and it appears to operate correctly.

@michaellopez
Copy link
Author

@Zigg I think lchown could be a solution.

@mattieb
Copy link
Collaborator

mattieb commented Nov 7, 2015

Hi @michaellopez,

Have a look at 2.0.2. I've converted brewdo to use lchown and lstat to avoid symlink-following problems.

@mattieb mattieb closed this as completed Nov 7, 2015
@michaellopez
Copy link
Author

@Zigg I am unable to test this again as I do not have that setup available anymore. But glad to see an action was taken to hopefully make things better on this point!

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

3 participants