Jguer / yay

Yet another Yogurt - An AUR Helper written in Go
GNU General Public License v3.0
11.1k stars 360 forks source link

failed to create directory '/yay': mkdir /yay: permission denied #2052

Open ArthurBorsboom opened 1 year ago

ArthurBorsboom commented 1 year ago

After switching to another desktop environment, I noticed that yay stopped working with the following error message.

failed to create directory '/yay': mkdir /yay: permission denied

Even yay --version and yay --help do not work.

After setting XDG_CACHE_HOME yay starts working again. According the XDG specifications, the variable XDG_CACHE_HOME is not mandatory and each application should automatically fallback.

$XDG_CACHE_HOME defines the base directory relative to which user-specific non-essential data files should be stored.
If $XDG_CACHE_HOME is either not set or empty, a default equal to $HOME/.cache should be used.

Source: https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html

Can yay be fixed so that it won't fail on the missing XDG_CACHE_HOME environment variable?

Jguer commented 1 year ago

yay uses both XDG_CACHE_HOME and HOME, otherwise it defaults to a tmpdir

func getCacheHome() (string, error) {
    uid := os.Geteuid()

    if cacheHome := os.Getenv("XDG_CACHE_HOME"); cacheHome != "" && uid != 0 {
        cacheDir := filepath.Join(cacheHome, "yay")
        if err := initDir(cacheDir); err == nil {
            return cacheDir, nil
        }
    }

    if cacheHome := os.Getenv("HOME"); cacheHome != "" && uid != 0 {
        cacheDir := filepath.Join(cacheHome, ".cache", "yay")
        if err := initDir(cacheDir); err == nil {
            return cacheDir, nil
        }
    }

    if uid == 0 && os.Getenv("SUDO_USER") == "" && os.Getenv("DOAS_USER") == "" {
        return systemdCache, nil // Don't create directory if systemd-run takes care of it
    }

    tmpDir := filepath.Join(os.TempDir(), "yay")

    return tmpDir, initDir(tmpDir)
}

Can you confirm if $HOME is set on your system?

As well check the ~/.config/yay/config.json's builddir for anything unusual

Jguer commented 1 year ago

I can reproduce this by setting config.json to

{
  "buildDir": "/yay"
}

why it gets set to that is my question

ArthurBorsboom commented 1 year ago

This issue happened a month ago (about). I will take some time to reproce the problem again and report back with more details.

On Mon, 3 Apr 2023, 18:18 Jo, @.***> wrote:

I can reproduce this by setting config.json to

{ "buildDir": "/yay" }

why it gets set to that is my question

— Reply to this email directly, view it on GitHub https://github.com/Jguer/yay/issues/2052#issuecomment-1494616779, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABSVB44UHFXVKCX7XELNPC3W7LZ6HANCNFSM6AAAAAAWRH5AL4 . You are receiving this because you authored the thread.Message ID: @.***>