Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes
PatchFile Class Reference
Inheritance diagram for PatchFile:
Inheritance graph
[legend]
Collaboration diagram for PatchFile:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 PatchFile ()
virtual ~PatchFile ()
virtual int Parse (char *line)
virtual int Prepare ()
virtual int Execute ()
virtual void Finish (int status)

Private Member Functions

int LoadSourceFile (int ofd)

Private Attributes

const char * mPatchFile
const char * mFile
int mPatchIndex
MBSPatchHeader header
int pfd
unsigned char * buf

Static Private Attributes

static int sPatchIndex = 0

Detailed Description

Definition at line 712 of file updater.cpp.


Constructor & Destructor Documentation

PatchFile::PatchFile ( ) [inline]

Definition at line 715 of file updater.cpp.

: mPatchIndex(-1), pfd(-1), buf(NULL) { }
PatchFile::~PatchFile ( ) [virtual]

Definition at line 738 of file updater.cpp.

{
  if (pfd >= 0)
    close(pfd);

  // delete the temporary patch file
  char spath[MAXPATHLEN];
  snprintf(spath, MAXPATHLEN, "%s/%d.patch", gSourcePath, mPatchIndex);
  ensure_remove(spath);

  free(buf);
}

Here is the call graph for this function:


Member Function Documentation

int PatchFile::Execute ( ) [virtual]

Implements Action.

Reimplemented in PatchIfFile.

Definition at line 853 of file updater.cpp.

{
  LOG(("EXECUTE PATCH %s\n", mFile));

  // Create backup copy of the destination file before proceeding.

  struct stat ss;
  if (stat(mFile, &ss))
    return READ_ERROR;

  int rv = backup_create(mFile);
  if (rv)
    return rv;

  rv = ensure_remove(mFile);
  if (rv)
    return WRITE_ERROR;

  AutoFD ofd = ensure_open(mFile, O_WRONLY | O_TRUNC | O_CREAT | _O_BINARY, ss.st_mode);
  if (ofd < 0)
    return WRITE_ERROR;

  return MBS_ApplyPatch(&header, pfd, buf, ofd);
}

Here is the call graph for this function:

void PatchFile::Finish ( int  status) [virtual]

Implements Action.

Reimplemented in PatchIfFile.

Definition at line 879 of file updater.cpp.

{
  LOG(("FINISH PATCH %s\n", mFile));

  backup_finish(mFile, status);
}

Here is the call graph for this function:

int PatchFile::LoadSourceFile ( int  ofd) [private]

Definition at line 752 of file updater.cpp.

{
  struct stat os;
  int rv = fstat(ofd, &os);
  if (rv)
    return READ_ERROR;

  if (PRUint32(os.st_size) != header.slen)
    return UNEXPECTED_ERROR;

  buf = (unsigned char*) malloc(header.slen);
  if (!buf)
    return MEM_ERROR;

  int r = header.slen;
  unsigned char *rb = buf;
  while (r) {
    int c = read(ofd, rb, mmin(BUFSIZ,r));
    if (c < 0)
      return READ_ERROR;

    r -= c;
    rb += c;

    if (c == 0 && r)
      return UNEXPECTED_ERROR;
  }

  // Verify that the contents of the source file correspond to what we expect.

  unsigned int crc = crc32(buf, header.slen);

  if (crc != header.scrc32) {
    LOG(("CRC check failed\n"));
    return CRC_ERROR;
  }
  
  return OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int PatchFile::Parse ( char *  line) [virtual]

Implements Action.

Reimplemented in PatchIfFile.

Definition at line 793 of file updater.cpp.

{
  // format "<patchfile>" "<filetopatch>"

  mPatchFile = mstrtok(kQuote, &line);
  if (!mPatchFile)
    return PARSE_ERROR;

  // consume whitespace between args
  char *q = mstrtok(kQuote, &line);
  if (!q)
    return PARSE_ERROR;

  mFile = mstrtok(kQuote, &line);
  if (!mFile)
    return PARSE_ERROR;

  return OK;
}

Here is the call graph for this function:

int PatchFile::Prepare ( ) [virtual]

Implements Action.

Reimplemented in PatchIfFile.

Definition at line 814 of file updater.cpp.

{
  LOG(("PREPARE PATCH %s\n", mFile));

  // extract the patch to a temporary file
  mPatchIndex = sPatchIndex++;

  char spath[MAXPATHLEN];
  snprintf(spath, MAXPATHLEN, "%s/%d.patch", gSourcePath, mPatchIndex);

  ensure_remove(spath);

  int rv = gArchiveReader.ExtractFile(mPatchFile, spath);
  if (rv)
    return rv;

  // XXXdarin from here down should be moved into the Execute command.
  //          no need to open all of the patch files and read all of 
  //          the source files before applying any patches.

  pfd = open(spath, O_RDONLY | _O_BINARY);
  if (pfd < 0)
    return READ_ERROR;

  rv = MBS_ReadHeader(pfd, &header);
  if (rv)
    return rv;

  AutoFD ofd = open(mFile, O_RDONLY | _O_BINARY);
  if (ofd < 0)
    return READ_ERROR;

  rv = LoadSourceFile(ofd);
  if (rv)
    LOG(("LoadSourceFile failed\n"));
  return rv;
}

Here is the call graph for this function:


Member Data Documentation

unsigned char* PatchFile::buf [private]

Definition at line 733 of file updater.cpp.

Definition at line 731 of file updater.cpp.

const char* PatchFile::mFile [private]

Definition at line 729 of file updater.cpp.

const char* PatchFile::mPatchFile [private]

Definition at line 728 of file updater.cpp.

Definition at line 730 of file updater.cpp.

int PatchFile::pfd [private]

Definition at line 732 of file updater.cpp.

int PatchFile::sPatchIndex = 0 [static, private]

Definition at line 726 of file updater.cpp.


The documentation for this class was generated from the following file: