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

handle permission error #7

Merged
merged 1 commit into from
Dec 5, 2021
Merged

handle permission error #7

merged 1 commit into from
Dec 5, 2021

Conversation

yoichi
Copy link
Contributor

@yoichi yoichi commented Dec 5, 2021

Current behavior

slotchmod spins the slot, even though it's certain that chmod will fail.

vagrant@vagrant:~/ghq/github.com/jiro4989/slotchmod$ mkdir d
vagrant@vagrant:~/ghq/github.com/jiro4989/slotchmod$ touch d/f
vagrant@vagrant:~/ghq/github.com/jiro4989/slotchmod$ chmod -x d
vagrant@vagrant:~/ghq/github.com/jiro4989/slotchmod$ ./slotchmod d/f
chmod 0555 d/f
panic: chmod d/f: permission denied

goroutine 1 [running]:
main.changeMode(0xc00001c0c0, {0xc000010050, 0x1, 0x6})
	/home/vagrant/ghq/github.com/jiro4989/slotchmod/main.go:86 +0x2e5
main.main()
	/home/vagrant/ghq/github.com/jiro4989/slotchmod/main.go:42 +0x155

Expected behavior

Like the case with the missing file, I think it is good to make an error first.

Behavior after the change

minimum permission:

vagrant@vagrant:~/ghq/github.com/jiro4989/slotchmod$ chmod 100 d
vagrant@vagrant:~/ghq/github.com/jiro4989/slotchmod$ ./slotchmod d/f
chmod 0026 d/f
vagrant@vagrant:~/ghq/github.com/jiro4989/slotchmod$ chmod 000 d/f
vagrant@vagrant:~/ghq/github.com/jiro4989/slotchmod$ echo $?
0

not enough permission:

vagrant@vagrant:~/ghq/github.com/jiro4989/slotchmod$ chmod 600 d
vagrant@vagrant:~/ghq/github.com/jiro4989/slotchmod$ ./slotchmod d/f
[ERR] d/f permission denied.
vagrant@vagrant:~/ghq/github.com/jiro4989/slotchmod$ chmod 000 d/f
chmod: cannot access 'd/f': Permission denied

@jiro4989
Copy link
Owner

jiro4989 commented Dec 5, 2021

awesome!

@jiro4989 jiro4989 merged commit 5f4bb54 into jiro4989:master Dec 5, 2021
@yoichi yoichi deleted the permission branch December 5, 2021 07:08
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