air-verse / air

☁️ Live reload for Go apps
GNU General Public License v3.0
17.63k stars 803 forks source link

Getting permission denied on a fresh install #388

Closed nandohos closed 1 year ago

nandohos commented 1 year ago

Hello, I just did a fresh install using go (go install github.com/cosmtrek/air@latest) on WSL ubuntu 22.04. Ran the following commands

air init && air -c .air.toml

The second command creates a folder tmp with a file inside when it runs, however it throws an error 'Permission denied'

[nando@DESKTOP] ~/Folder$ air -c .air.toml / /\ | | | |) //--\ || || _ , built with Go

watching . !exclude tmp building... running... /bin/sh: 1: /home/nando/Folder/tmp/main: Permission denied

Checking the permissions of the file that it created

[nando@DESKTOP] ~/Folder/tmp$ ls -la .rw-r--r-- 16k nando nando 31 Jan 23:39 main

The issue #113 didn't help, even after reinstalling and logging out still getting the same issue

nandohos commented 1 year ago

I tried the solution that @ryoshindo gave in #349 and it worked.

I had the same error, but in my case it was because the package name of the file with main() was not main. Thus, the error disappeared by modifying the file as follows

- package app
+ package main

My IDE created the package with the folder name and thus this error occurred.

r6q commented 1 year ago

Leaving my solution if someone stumbles upon this. I just ran air command without any arguments which resulted in:

/bin/sh: /Users/[username]/projects/my-project/tmp/main: Permission denied

To fix it I had to explicitly specify build command, i.e.:

air --build.cmd "go build -o ./tmp/main ./cmd/myproj/main.go"
sonewman commented 1 year ago

Leaving my solution if someone stumbles upon this. I just ran air command without any arguments which resulted in:

/bin/sh: /Users/[username]/projects/my-project/tmp/main: Permission denied

To fix it I had to explicitly specify build command, i.e.:

air --build.cmd "go build -o ./tmp/main ./cmd/myproj/main.go"

this also fixed my problem, thanks for posting this. This problem did not occur until i moved my main.go inside the ./cmd folder, i don't know if this is intended behaviour? But it appears the ./tmp/main binary was being created with the wrong permissions -rw-r--r-- instead of -rwxr-xr-x

itschip commented 4 months ago

It's a relatively easy fix to this.

Make sure air doesn't delete the tmp folder. Give exec perms to the tmp/main binary.

If you're using a structure like /cmd/whatever...make sure that the package name is 'main' and you should be good to go.

jtmuller5 commented 2 days ago

I had a similar fix. My project had an /api/cmd/api folder containing my main.go file.

In .air.toml, I updated this line:

-  cmd = "go build -o ./tmp/main ."
+  cmd = "go build -o ./tmp/main ./cmd/api"