static bool load_or_save_variables(bool save) { const wcstring wdir = fishd_get_config(); const std::string dir = wcs2string(wdir); if (dir.empty()) return false; const std::string machine_id = get_machine_identifier(); const std::string machine_id_path = get_variables_file_path(dir, machine_id); bool success = load_or_save_variables_at_path(save, machine_id_path); if (! success && ! save && errno == ENOENT) { /* We failed to load, because the file was not found. Older fish used the hostname only. Try *moving* the filename based on the hostname into place; if that succeeds try again. Silently "upgraded." */ std::string hostname_id; if (get_hostname_identifier(&hostname_id) && hostname_id != machine_id) { std::string hostname_path = get_variables_file_path(dir, hostname_id); if (0 == rename(hostname_path.c_str(), machine_id_path.c_str())) { /* We renamed - try again */ success = load_or_save_variables_at_path(save, machine_id_path); } } } return success; }
static wcstring default_vars_path() { wcstring wdir = fishd_get_config(); const std::string dir = wcs2string(wdir); if (dir.empty()) return L""; const std::string machine_id = get_machine_identifier(); const std::string machine_id_path = get_variables_file_path(dir, machine_id); return str2wcstring(machine_id_path); }