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

util: Flatpak BOINC data directory resolution fails when native BOINC package is installed. #2650

Open
jamescowens opened this issue Mar 5, 2023 · 1 comment
Assignees
Labels
Milestone

Comments

@jamescowens
Copy link
Member

jamescowens commented Mar 5, 2023

A user on Discord reported the wallet produced an error that it could not find the BOINC data directory. This was on Ubuntu 22.04.

After investigation, I determined that both the native and flatpak BOINC was installed.

The current wallet BOINC data directory resolution code in boinc.cpp reads as follows:

fs::path GRC::GetBoincDataDir()
{
    std::string path = gArgs.GetArg("-boincdatadir", "");

    if (!path.empty()) {
        return fs::path(path);
    }

    #ifdef WIN32
    HKEY hKey;
    if (RegOpenKeyEx(
        HKEY_LOCAL_MACHINE,
        L"SOFTWARE\\Space Sciences Laboratory, U.C. Berkeley\\BOINC Setup\\",
        0,
        KEY_READ|KEY_WOW64_64KEY,
        &hKey) == ERROR_SUCCESS)
    {
        wchar_t szPath[MAX_PATH];
        DWORD dwSize = sizeof(szPath);

        if (RegQueryValueEx(
            hKey,
            L"DATADIR",
            nullptr,
            nullptr,
            (LPBYTE)&szPath,
            &dwSize) == ERROR_SUCCESS)
        {
            RegCloseKey(hKey);

            fs::path path = std::wstring(szPath);

            if (fs::exists(path)){
                return path;
            } else {
                LogPrintf("Cannot find BOINC data dir %s.", path.string());
            }
        }

        RegCloseKey(hKey);
    }

    if (fs::exists("C:\\ProgramData\\BOINC\\")){
        return "C:\\ProgramData\\BOINC\\";
    } else if(fs::exists("C:\\Documents and Settings\\All Users\\Application Data\\BOINC\\")) {
        return "C:\\Documents and Settings\\All Users\\Application Data\\BOINC\\";
    }
    #endif

    #ifdef __linux__
    // For Linux, native first, then flatpack...
    if (fs::exists("/var/lib/boinc-client/")) {
        return "/var/lib/boinc-client/";
    } else if (fs::exists("/var/lib/boinc/")) {
        return "/var/lib/boinc/";
    }

    // This is for flatpack path resolution
    char* pszHome = getenv("HOME");

    // If there is a home path then try the flatpack path.
    if (pszHome && strlen(pszHome) > 0) {

        fs::path flatpack_path = fs::path(pszHome) / ".var/app/edu.berkeley.BOINC/";

        if (fs::exists(flatpack_path)) {
            return flatpack_path;
        }
    }
    #endif

    #ifdef __APPLE__
    if (fs::exists("/Library/Application Support/BOINC Data/")) {
        return "/Library/Application Support/BOINC Data/";
    }
    #endif

    error("%s: Cannot find BOINC data directory. You may need to manually specify in the gridcoinresearch.conf file "
          "the data directory location by using boincdatadir=<data directory location>.", __func__);

    return "";
}

In particular note that the fs::exists tests for the native paths do NOT check for the existence of the client_state.xml file, only the path. This means a native package installation, even if never actually run, will be sufficient to prevent the resolver to continue on to the flatpak part.

We need to consider doing the fs::exists on the client_state.xml file. There may be problems with that though, because someone could start the wallet for the first time AFTER installing the native package but before running BOINC, in which case the wallet will fail to load if we require the client_state.xml file to be there at that time.

We may have to do something more sophisticated.

@jamescowens jamescowens added the bug label Mar 5, 2023
@jamescowens jamescowens self-assigned this Mar 5, 2023
@jamescowens jamescowens added this to the Miss Piggy milestone Mar 5, 2023
@jamescowens jamescowens modified the milestones: Miss Piggy, Natasha Feb 29, 2024
@jamescowens
Copy link
Member Author

Moving this to Natasha to align with the other Flatpack stuff.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant