예제 #1
0
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;
}
예제 #2
0
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);
}
예제 #3
0
파일: fishd.cpp 프로젝트: Soares/fish-shell
/**
   Load or save all variables
*/
static void load_or_save( int save)
{
	const wcstring wdir = fishd_get_config();
	char hostname[HOSTNAME_LEN];
	connection_t c;
	int fd;
	
	if (wdir.empty())
		return;
	
	std::string dir = wcs2string( wdir );
	
	gethostname( hostname, HOSTNAME_LEN );
	
    std::string name;
    name.append(dir);
    name.append("/");
    name.append(FILE);
    name.append(hostname);
	
	debug( 4, L"Open file for %s: '%s'", 
		   save?"saving":"loading", 
		   name.c_str() );
	
    /* OK to not use CLO_EXEC here because fishd is single threaded */
	fd = open(name.c_str(), save?(O_CREAT | O_TRUNC | O_WRONLY):O_RDONLY, 0600);
	
	if( fd == -1 )
	{
		debug( 1, L"Could not open load/save file. No previous saves?" );
		wperror( L"open" );
		return;		
	}
	debug( 4, L"File open on fd %d", c.fd );

	connection_init( &c, fd );

	if( save )
	{
		
		write_loop( c.fd, SAVE_MSG, strlen(SAVE_MSG) );
		enqueue_all( &c );
	}
	else
		read_message( &c );

	connection_destroy( &c );	
}