GridLab
Grid Application Toolkit

A simple API for Grid Applications
GAT

Menu



next up previous contents
Next: From rm to RM Up: Some Useful Programs Previous: A Fancy-Pants cp   Contents

Wow Your Friends with mv

Another program which is manna to Unix users everywhere is the program mv. The program mv moves a specified file to a specified location. So, for example, to move the file source to the location destination the program mv would be used as follows

% mv source destination

The next program will be a ``grid enabled'' version of this common command line tool. The full program is as follows

#include <stdio.h>
#include "GAT.h"

int main( int argc, char *argv[] )
{
  GATResult result;
  GATFile sourceFile;
  GATContext context;
  GATLocation sourceLocation;
  GATLocation destinationLocation;
  
  /* Check command line syntax */
  if( 3 != argc )
  {
     printf("usage: %s source destination\n", argv[0]);
     
     return 1;
  }
  
  /* Set result to a memory failure */
  result = GAT_MEMORYFAILURE;
  
  /* Create GATLocation sourceLocation */
  sourceLocation = GATLocation_Create( argv[1] );
  
  /* Check previous GATLocation creation */
  if( NULL != sourceLocation )
  {
    /* Create GATLocation destinationLocation */
    destinationLocation = GATLocation_Create( argv[2] );
    
    /* Check previous GATLocation creation */
    if( NULL != destinationLocation )
    {
      /* Create GATContext context */
      context = GATContext_Create();
      
      /* Check previous GATContext creation */
      if( NULL != context )
      {
        /* Create GATFile sourceFile */
        sourceFile = GATFile_Create( context, sourceLocation, NULL );
        
        /* Check GATFile creation */
        if( NULL != sourceFile )
        {
          /* Move sourceFile to destinationLocation */
          result = GATFile_Move( sourceFile, destinationLocation, GATFileMode_Overwrite );
          
          /* Destroy GATFile sourceFile */
          GATFile_Destroy( &sourceFile );
        }
        
        /* Destroy GATContext context */
        GATContext_Destroy( &context );
      }
      
      /* Destroy GATLocation destinationLocation */
      GATLocation_Destroy( &destinationLocation );
    }
    
    /* Destroy GATLocation sourceLocation */
    GATLocation_Destroy( &sourceLocation );
  }
  
  /* Check result for success and print error */
  if( GAT_FAILED( result) )
  {
    printf( "An error has occurred during the move operation\n");
    
    return 1;
  }
  
  return 0;
}

Again this entire program contains no novel code, all of its functions have been previously examined; so, we will not examine it line by line.



Andre Merzky 2004-05-13