[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Two utiities for getting Mac binaries into and out of a repository.

From: Cory West <corywest_at_creative-urge.com>
Date: 2004-12-26 22:19:26 CET

These two utilities aren't glamorous, but I threw them together out of
necessity last week and thought that others might also find them useful.

 

DTAdd is a utility to add a Mac binary file to a Subversion repository. It
preserves the resource fork and finder flags as properties on the file.

 

DTFix is a utility that will restore the resource fork and finder flags for
a Mac binary file stored in a Subversion repository.

 

These utilities probably should have been written in PERL. but I don't know
PERL. Actually, the Subversion client should probably just do this for you
if it's running on a Mac and encounters these situations :-).

 

Cheers,

-Cory

 

 

---- BEGIN SOURCE FILE DTFIX.CPP ---

 

//

// DTFix: Restore the resource fork and finder flags for a Mac binary file

// stored in a Subversion repository.

//

// This should simply compile with: g++ -o dtfix dtfix.cpp

//

// You need the Apple developer tools and the Subversion client

// installed for this utility to work.

//

// No warranty implied, fix 'em if you find 'em, you know the routine.

//

 

#include <stdio.h>

#include <string.h>

#include <sys/types.h>

#include <unistd.h>

#include <stdlib.h>

 

char g_szFinderFlags[1024];

char g_szCreator[1024];

char g_szType[1024];

 

void show_usage(void);

bool does_file_exist(const char* szPath);

bool get_property_string( char* szProperty, const char* szPath, char*
szPropertyData );

void do_restore_sequence( const char* szPath );

 

int main (int argc, const char * argv[])

{

    if( argc != 2 )

    {

        show_usage();

        return( -1 );

    }

 

    //

    // Make sure we can find all the things we're going to need.

    //

 

    if( !does_file_exist( argv[1] ) )

    {

        printf( "The specified file could not be opened.\n" );

        return( -1 );

    }

 

    if( !does_file_exist( "/Developer/Tools/GetFileInfo" ) )

    {

        printf( "Couldn't find GetFileInfo. Are the developer tools
installed?\n" );

        return( -1 );

    }

 

    if( !does_file_exist( "/usr/local/bin/svn" ) )

    {

        printf( "Couldn't find Subversion client. Is Subversion
installed?\n" );

        return( -1 );

    }

 

    //

    // Get the string properties from the repository.

    //

    

    if( !get_property_string( "macbinary:finder-flags", argv[1],
g_szFinderFlags ) )

    {

        printf( "Couldn't retrieve the finder flags from the repository?
Aborting...\n" );

        return( -1 );

    }

 

    if( !get_property_string( "macbinary:creator", argv[1], g_szCreator ) )

    {

        printf( "Couldn't retrieve the creator from the repository?
Aborting...\n" );

        return( -1 );

    }

 

    if( !get_property_string( "macbinary:type", argv[1], g_szType ) )

    {

        printf( "Couldn't retrieve the application type from the repository?
Aborting...\n" );

        return( -1 );

    }

    

    do_restore_sequence( argv[1] );

    return( 0 );

}

 

bool does_file_exist(const char* szPath)

{

    bool fExists = false;

    FILE *pFile = 0;

 

    pFile = fopen( szPath, "r" );

    if( pFile )

    {

        fclose( pFile );

        fExists = true;

    }

 

    return( fExists );

}

 

bool get_property_string( char* szProperty, const char* szPath, char*
szPropertyData )

{

    bool fSucceeded = false;

    FILE *pPropFile = 0;

    char szCommand[1024];

    char* szGetProperty = "svn propget ";

 

    system( "rm -f /tmp/dtfix_tmp" );

 

    strcpy( szCommand, szGetProperty );

    strcat( szCommand, szProperty );

    strcat( szCommand, " \"" );

    strcat( szCommand, szPath );

    strcat( szCommand, "\" > /tmp/dtfix_tmp" );

 

    do

    {

        if( 0 != system( szCommand )) break;

 

        pPropFile = fopen( "/tmp/dtfix_tmp", "r" );

        if( !pPropFile ) break;

 

        *szPropertyData = 0;

        fread( szPropertyData, 1024, 1024, pPropFile );

 

        char* szCurrent = szPropertyData;

        while( ( *szCurrent != 0 ) &&

               ( *szCurrent != '\r' ) &&

               ( *szCurrent != '\n' ) )

        {

            szCurrent++;

        }

 

        if( szCurrent != szPropertyData )

        {

            fSucceeded = true;

            *szCurrent = 0;

        }

    }

    while( false );

 

    if( !fSucceeded )

        printf( "Failed to retrieve this property: %s, aborting.\n",
szProperty );

 

 

    if( pPropFile ) fclose( pPropFile );

    system( "rm -f /tmp/dtfix_tmp" );

 

    return( fSucceeded );

}

 

void show_usage()

{

    printf( "DTFix v1.0\n" );

    printf( "Restore a mac binary from the Subversion repository.\n");

    printf( "Usage: dtfix <filename>\n\n" );

}

 

void do_restore_sequence( const char* szPath )

{

    char szCommand[1024];

 

    system( "rm -f /tmp/dtfix_rsrc" );

    

    do

    {

        strcpy( szCommand, "svn propget macbinary:resource-fork " );

        strcat( szCommand, szPath );

        strcat( szCommand, " > /tmp/dtfix_rsrc" );

        system( szCommand );

        if( !does_file_exist( "/tmp/dtfix_rsrc" ) )

        {

            printf( "Couldn't get the resource fork from the repository.
Aborting...\n" );

            break;

        }

 

        strcpy( szCommand, "cat /tmp/dtfix_rsrc > " );

        strcat( szCommand, szPath );

        strcat( szCommand, "/rsrc" );

        if( 0 != system( szCommand ) )

        {

            printf( "Failure occured while trying to restore the resource
fork? Aborting...\n" );

            break;

        }

 

        strcpy( szCommand, "SetFile -a " );

        strcat( szCommand, g_szFinderFlags );

        strcat( szCommand, " " );

        strcat( szCommand, szPath );

        if( 0 != system( szCommand ) )

        {

            printf( "Failure occured while restoring the finder flags?
Aborting...\n" );

            break;

        }

 

        strcpy( szCommand, "SetFile -c " );

        strcat( szCommand, g_szCreator );

        strcat( szCommand, " " );

        strcat( szCommand, szPath );

        if( 0 != system( szCommand ) )

        {

            printf( "Failure occured while restoring the creator?
Aborting...\n" );

            break;

        }

 

        strcpy( szCommand, "SetFile -t " );

        strcat( szCommand, g_szType );

        strcat( szCommand, " " );

        strcat( szCommand, szPath );

        if( 0 != system( szCommand ) )

        {

            printf( "Failure occured while restoring the application type?
Aborting...\n" );

            break;

        }

 

    }

    while( false );

 

    system( "rm -f /tmp/dtfix_rsrc" );

    return;

}

 

---- END SOURCE FILE DTFIX.CPP ---

 

 

---- BEGIN SOURCE FILE DTADD.CPP ---

 

//

// DTAdd: Utility to add a Mac binary file to a Subversion repository.

// This utility preserves the resource fork and finder flags as properties

// on the file.

//

// This should simply compile with: g++ -o dtadd dtadd.cpp

//

// You need the Apple developer tools and the Subversion client

// installed for this utility to work.

//

// No warranty implied, fix 'em if you find 'em, you know the routine.

//

 

#include <stdio.h>

#include <string.h>

#include <sys/types.h>

#include <unistd.h>

#include <stdlib.h>

 

char g_szFinderFlags[1024];

char g_szCreator[1024];

char g_szType[1024];

 

void show_usage(void);

bool does_file_exist(const char* szPath);

bool get_finder_info( const char* szPath );

bool get_fi_element( char* szTag, char* szInfo, char* szData );

void do_checkin_sequence( const char* szPath );

 

int main (int argc, const char * argv[])

{

    if( argc != 2 )

    {

        show_usage();

        return( -1 );

    }

 

    //

    // Make sure we can find all the things we're going to need.

    //

 

    if( !does_file_exist( argv[1] ) )

    {

        printf( "The specified file could not be opened.\n" );

        return( -1 );

    }

 

    if( !does_file_exist( "/Developer/Tools/GetFileInfo" ) )

    {

        printf( "Couldn't find GetFileInfo. Are the developer tools
installed?\n" );

        return( -1 );

    }

 

    if( !does_file_exist( "/usr/local/bin/svn" ) )

    {

        printf( "Couldn't find Subversion client. Is Subversion
installed?\n" );

        return( -1 );

    }

 

    //

    // Get the finder info for the file, then do the check-in sequence.

    //

    

    if( !get_finder_info( argv[1] ) ) return( -1 );

 

    do_checkin_sequence( argv[1] );

    return( 0 );

}

 

bool get_finder_info( const char* szPath )

{

    bool fSucceeded = false;

    FILE *pFIFile = 0;

    char szCommand[1024];

    char szFinderInfo[1024];

    char *szGetFileInfo = "/Developer/Tools/GetFileInfo \"";

 

    system( "rm -f /tmp/dtadd_tmp" );

 

    strcpy( szCommand, szGetFileInfo );

    strcat( szCommand, szPath );

    strcat( szCommand, "\" > /tmp/dtadd_tmp" );

 

    do

    {

        if( 0 != system( szCommand )) break;

 

        pFIFile = fopen( "/tmp/dtadd_tmp", "r" );

        if( !pFIFile ) break;

 

        fread( szFinderInfo, 1024, 1024, pFIFile );

 

        if( !get_fi_element( "attributes: ", szFinderInfo, g_szFinderFlags )
) break;

        if( !get_fi_element( "creator: ", szFinderInfo, g_szCreator ) )
break;

        if( !get_fi_element( "type: ", szFinderInfo, g_szType ) ) break;

 

        fSucceeded = true;

    }

    while( false );

 

    if( !fSucceeded )

        printf( "Couldn't get any finder info for this file...
aborting...\n" );

 

    if( pFIFile ) fclose( pFIFile );

    system( "rm -f /tmp/dtadd_tmp" );

 

    return( fSucceeded );

}

 

void show_usage()

{

    printf( "DTAdd v1.0\n" );

    printf( "Add a Mac binary to the Subversion repository.\n\n");

    printf( "Usage: dtadd <filename>\n\n" );

}

 

bool does_file_exist(const char* szPath)

{

    bool fExists = false;

    FILE *pFile = 0;

 

    pFile = fopen( szPath, "r" );

    if( pFile )

    {

        fclose( pFile );

        fExists = true;

    }

 

    return( fExists );

}

 

bool get_fi_element( char* szTag, char* szInfo, char* szData )

{

    bool fFoundTag = false;

    char* szCurrent = szInfo;

    char* szCurrentTag = szTag;

    char* szCurrentData = szData;

 

    while( ( *szCurrent != 0 ) && ( szCurrentTag != 0 ) )

    {

        if( *szCurrent == *szCurrentTag )

        {

            szCurrent++;

            szCurrentTag++;

 

            if( *szCurrentTag == 0 )

            {

                fFoundTag = true;

                break;

            }

        }

        else

        {

            szCurrentTag = szTag;

            szCurrent++;

        }

    }

 

    if( fFoundTag )

    {

        if( *szCurrent == '\"' ) szCurrent++;

 

        while( ( *szCurrent != 0 ) &&

               ( *szCurrent != ' ' ) &&

               ( *szCurrent != '\r' ) &&

               ( *szCurrent != '\"' ) &&

               ( *szCurrent != '\n' ) )

        {

            *szCurrentData = *szCurrent;

            szCurrentData++;

            szCurrent++;

        }

    }

 

    *szCurrentData = 0;

    return( fFoundTag );

}

 

void do_checkin_sequence( const char* szPath )

{

    char szCommand[1024];

 

    system( "rm -f /tmp/dtadd_rsrc" );

    

    do

    {

        strcpy( szCommand, "cat " );

        strcat( szCommand, szPath );

        strcat( szCommand, "/rsrc > /tmp/dtadd_rsrc" );

        system( szCommand );

        if( !does_file_exist( "/tmp/dtadd_rsrc" ) )

        {

            printf( "Couldn't get the resource fork for this file.
Aborting...\n" );

            break;

        }

 

        strcpy( szCommand, "svn add " );

        strcat( szCommand, szPath );

        if( 0 != system( szCommand ) )

        {

            printf( "Failure occured while adding the file to Subversion.
Are you in a working copy?\n" );

            break;

        }

 

        strcpy( szCommand, "svn propset macbinary:resource-fork -F
/tmp/dtadd_rsrc " );

        strcat( szCommand, szPath );

        if( 0 != system( szCommand ) )

        {

            printf( "Failure occured while adding the resource fork to
Subversion. Are you in a working copy?\n" );

            break;

        }

 

        strcpy( szCommand, "svn propset macbinary:creator " );

        strcat( szCommand, g_szCreator );

        strcat( szCommand, " " );

        strcat( szCommand, szPath );

        if( 0 != system( szCommand ) )

        {

            printf( "Failure occured while setting the creator to
Subversion. Are you in a working copy?\n" );

            break;

        }

 

        strcpy( szCommand, "svn propset macbinary:type " );

        strcat( szCommand, g_szType );

        strcat( szCommand, " " );

        strcat( szCommand, szPath );

        if( 0 != system( szCommand ) )

        {

            printf( "Failure occured while setting the type to Subversion.
Are you in a working copy?\n" );

            break;

        }

 

        strcpy( szCommand, "svn propset macbinary:finder-flags " );

        strcat( szCommand, g_szFinderFlags );

        strcat( szCommand, " " );

        strcat( szCommand, szPath );

        if( 0 != system( szCommand ) )

        {

            printf( "Failure occured while setting the finder flags to
Subversion. Are you in a working copy?\n" );

            break;

        }

 

        //

        // Looks like we succeeded!

        //

 

        printf( "The mac binary has been added to your working copy!\n" );

        printf( "You can commit your changes when you are ready.\n" );

 

    }

    while( false );

 

    system( "rm -f /tmp/dtadd_rsrc" );

    return;

}

    

---- END SOURCE FILE DTADD.CPP ---

 
Received on Tue Dec 28 00:04:53 2004

This is an archived mail posted to the Subversion Users mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.