Example #1
0
static bool file_saveBackup (const std::string& path)
{
    if (file_writeable(path)) {
        std::string backup = os::stripExtension(path) + ".bak";

        return (!file_exists(backup) || file_remove(backup)) // remove backup
               && file_move(path, backup); // rename current to backup
    }

    globalErrorStream() << "ERROR: map path is not writeable: " << path << "\n";
    return false;
}
Example #2
0
bool file_saveBackup(const char* path)
{
  if(file_writeable(path))
  {
	  StringOutputStream backup(256);
    backup << StringRange(path, path_get_extension(path)) << "bak";

    return (!file_exists(backup.c_str()) || file_remove(backup.c_str())) // remove backup
      && file_move(path, backup.c_str()); // rename current to backup
  }

  globalErrorStream() << "map path is not writeable: " << makeQuoted(path) << "\n";
  return false;
}
Example #3
0
static void
make1d(
#ifdef OPT_SERIAL_OUTPUT_EXT
	const char*	outputname,
#endif
	void	*closure,
	int	status )
{
	TARGET	*t = (TARGET *)closure;
	CMD	*cmd = (CMD *)t->cmds;

#ifdef OPT_DEBUG_MAKE1_LOG_EXT
	if (DEBUG_MAKE1) {
	    printf( "make1d\t--\t%s\n" ,
		    t->name );
	}
#endif
	/* Execcmd() has completed.  All we need to do is fiddle with the */
	/* status and signal our completion so make1c() can run the next */
	/* command.  On interrupts, we bail heavily. */

	if( status == EXEC_CMD_FAIL && ( cmd->rule->flags & RULE_IGNORE ) )
	    status = EXEC_CMD_OK;

	/* On interrupt, set intr so _everything_ fails */

	if( status == EXEC_CMD_INTR )
	    ++intr;

#ifndef OPT_SERIAL_OUTPUT_EXT
	if( status == EXEC_CMD_FAIL && DEBUG_MAKE )
	{
	    /* Print command text on failure */

	    if( !DEBUG_EXEC )
		printf( "%s\n", buffer_ptr( &cmd->commandbuff ) );
#ifdef OPT_RESPONSE_FILES
	    if (!DEBUG_EXEC)
	    {
		printResponseFiles(cmd);
	    }
#endif

	    printf( "*** failed %s ", cmd->rule->name );
	    list_print( lol_get( &cmd->args, 0 ) );
	    printf( "...\n" );

	    if( globs.quitquick ) ++intr;
	}
#else
	if( DEBUG_MAKE )
	{
	    if( DEBUG_MAKEQ || ! ( cmd->rule->flags & RULE_QUIETLY ) )
	    {
#ifdef OPT_PERCENT_DONE_EXT
		    /* CWM - added '@' and %done to front of output */
		    int done = counts->skipped + counts->failed + counts->made;
		    float percent = (done * 99.0f) / globs.updating;
		    printf( "@ %2.0f%% %s ", percent, cmd->rule->name );
#else
		    /* CWM - Added '@' to front of output */
			printf( "@ %s ", cmd->rule->name );
#endif
#ifdef OPT_DEBUG_MAKE_PRINT_TARGET_NAME
		if (globs.printtarget) {
		    printf("%s ", t->name);
		} else {
		    list_print( lol_get( &cmd->args, 0 ) );
		}
#else
		list_print( lol_get( &cmd->args, 0 ) );
#endif
		printf( "\n" );
	    }
	}

	if( DEBUG_EXEC || (status == EXEC_CMD_FAIL && DEBUG_MAKE) )
	{
	    printf( "%s\n", buffer_ptr(&cmd->commandbuff) );
#ifdef OPT_RESPONSE_FILES
	    printResponseFiles(cmd);
#endif
	}

	/* Print the output now, if there was any */
	if( outputname )
	{
		FILE		*fp;
		size_t		n;
		char		buf[4096];

		fp = fopen( outputname, "r" );
		if (fp)
		{
			n = fread(buf, sizeof(char), sizeof buf, fp);
//			if (verifyIsRealOutput (buf, n))
			{
				fwrite(buf, sizeof(char), n, stdout);
				n = fread(buf, sizeof(char), sizeof buf, fp);
				while (n > 0)
				{
					fwrite(buf, sizeof(char), n, stdout);
					n = fread(buf, sizeof(char), sizeof buf, fp);
				}
			}
			fclose(fp);
		}
	}

	if( status == EXEC_CMD_FAIL && DEBUG_MAKE )
	{
	    printf( "*** failed %s ", cmd->rule->name );
#ifdef OPT_DEBUG_MAKE_PRINT_TARGET_NAME
	    if (globs.printtarget) {
		printf("%s ", t->name);
	    } else {
		list_print( lol_get( &cmd->args, 0 ) );
	    }
#else
	    list_print( lol_get( &cmd->args, 0 ) );
#endif
	    printf( "...\n" );

	    if (globs.quitquick)
	    {
		++intr;
	    }
	}
#endif /* OPT_SERIAL_OUTPUT_EXT */

	/* If the command was interrupted or failed and the target */
	/* is not "precious", remove the targets. */
	/* Precious == 'actions updated' -- the target maintains state. */

	if( status != EXEC_CMD_OK )
	{
		if ( !( cmd->rule->flags & RULE_UPDATED ) ) {
	    LIST *targets = lol_get( &cmd->args, 0 );

#ifdef OPT_NODELETE_READONLY
	    for( ; targets; targets = list_next( targets ) )
		if( file_writeable( targets->string ) &&
		    !unlink( targets->string ) )
		    printf( "*** removing %s\n", targets->string );
#else
	    for( ; targets; targets = list_next( targets ) )
		if( !unlink( targets->string ) )
		    printf( "*** removing %s\n", targets->string );
#endif
	}
	}
#ifdef OPT_BUILTIN_MD5CACHE_EXT
	else
	{
	    LIST *targets = lol_get( &cmd->args, 0 );

	    for( ; targets; targets = list_next( targets ) )
	    {
		TARGET *t = bindtarget( targets->string );
		filecache_update( t );
	    }
	}
#endif

	/* Free this command and call make1c() to move onto next command. */

	t->status = (char)status;
	t->cmds = (char *)cmd_next( cmd );

	cmd_free( cmd );

	make1c( t );
}