- // This function does not in general need to separately check that the returned path exists; that’s racy, and callers will fail accessing the file anyway.
- // We are checking for os.IsNotExist here only to give the user better guidance what to do in this special case.
- _, err := os.Stat(runtimeDir)
- if os.IsNotExist(err) {
- // This means the user set the XDG_RUNTIME_DIR variable and either forgot to create the directory
- // or made a typo while setting the environment variable,
- // so return an error referring to $XDG_RUNTIME_DIR instead of xdgRuntimeDirPath inside.
- return "", errors.Wrapf(err, "%q directory set by $XDG_RUNTIME_DIR does not exist. Either create the directory or unset $XDG_RUNTIME_DIR.", runtimeDir)
- } // else ignore err and let the caller fail accessing xdgRuntimeDirPath.