Back to index

lightning-sunbird  0.9+nobinonly
Functions
InstallCleanupUnix.cpp File Reference
#include "InstallCleanup.h"
#include <sys/stat.h>
#include <unistd.h>
#include <string.h>

Go to the source code of this file.

Functions

int NativeDeleteFile (const char *aFileToDelete)
int NativeReplaceFile (const char *replacementFile, const char *doomedFile)
int main (int argc, char *argv[])

Function Documentation

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

Definition at line 93 of file InstallCleanupUnix.cpp.

{
    HREG reg;
    int status = DONE;
    struct stat fileStack;

    if ( REGERR_OK == NR_StartupRegistry())
    {
        char regFilePath[256];
        strcpy(regFilePath, argv[0]);
        strcat(regFilePath, ".dat");
        if ( stat(regFilePath, &fileStack) != 0)
            regFilePath[0] =  '\0';
        if ( REGERR_OK == NR_RegOpen(regFilePath, &reg) )
        {
            do {
                status = PerformScheduledTasks(reg);
                if (status != DONE)
                   sleep(1);
            } while (status == TRY_LATER);
            NR_RegClose(&reg);
        }
        NR_ShutdownRegistry();
        unlink(regFilePath);
    }
    return(0);
}

Here is the call graph for this function:

int NativeDeleteFile ( const char *  aFileToDelete)

Definition at line 48 of file InstallCleanupUnix.cpp.

{
    struct stat fileStack;
    if (stat(aFileToDelete, &fileStack) != 0)
    {
      return DONE;// No file to delete, do nothing.
    }
    else 
    {
        if(unlink(aFileToDelete) != 0)
          return TRY_LATER;
    }
    return DONE;
}
int NativeReplaceFile ( const char *  replacementFile,
const char *  doomedFile 
)

Definition at line 66 of file InstallCleanupUnix.cpp.

{
    struct stat fileStack;

    // replacement file must exist, doomed file doesn't have to
    if (stat(replacementFile, &fileStack) != 0)
        return DONE;

    // don't have to do anything if the files are the same
    if (strcmp(replacementFile, doomedFile) == 0)
        return DONE;

    if (unlink(doomedFile) != 0)
    {
        if (stat(doomedFile, &fileStack) == 0)    
            return TRY_LATER;
    }
    else
    {
      // doomedFile is gone move new file into place
      if (rename(replacementFile, doomedFile) != 0)
          return TRY_LATER; // this shouldn't happen
    }

    return DONE;
}

Here is the call graph for this function: