Bug 616775 - Use OpenNSPRFileDesc instead of OpenANSIFileDesc in nsUpdateDriver.cpp. r=dtownsend, a=approval2.0

This commit is contained in:
Robert Strong 2010-12-07 12:06:22 -08:00
parent 17dc66ec01
commit 077a44e8d2

View File

@ -193,17 +193,16 @@ GetStatusFile(nsIFile *dir, nsCOMPtr<nsILocalFile> &result)
static PRBool
IsPending(nsILocalFile *statusFile)
{
nsresult rv;
FILE *fp;
rv = statusFile->OpenANSIFileDesc("r", &fp);
PRFileDesc *fd = nsnull;
nsresult rv = statusFile->OpenNSPRFileDesc(PR_RDONLY, 0660, &fd);
if (NS_FAILED(rv))
return PR_FALSE;
char buf[32];
char *result = fgets(buf, sizeof(buf), fp);
fclose(fp);
if (!result)
const PRInt32 n = PR_Read(fd, buf, sizeof(buf));
PR_Close(fd);
if (n < 0)
return PR_FALSE;
const char kPending[] = "pending";
@ -211,15 +210,17 @@ IsPending(nsILocalFile *statusFile)
}
static PRBool
SetStatus(nsILocalFile *statusFile, const char *status)
SetStatusApplying(nsILocalFile *statusFile)
{
FILE *fp;
nsresult rv = statusFile->OpenANSIFileDesc("w", &fp);
PRFileDesc *fd = nsnull;
nsresult rv = statusFile->OpenNSPRFileDesc(PR_WRONLY, 0660, &fd);
if (NS_FAILED(rv))
return PR_FALSE;
fprintf(fp, "%s\n", status);
fclose(fp);
static const char kApplying[] = "Applying\n";
PR_Write(fd, kApplying, sizeof(kApplying) - 1);
PR_Close(fd);
return PR_TRUE;
}
@ -234,23 +235,21 @@ GetVersionFile(nsIFile *dir, nsCOMPtr<nsILocalFile> &result)
static PRBool
IsOlderVersion(nsILocalFile *versionFile, const char *&appVersion)
{
nsresult rv;
FILE *fp;
rv = versionFile->OpenANSIFileDesc("r", &fp);
PRFileDesc *fd = nsnull;
nsresult rv = versionFile->OpenNSPRFileDesc(PR_RDONLY, 0660, &fd);
if (NS_FAILED(rv))
return PR_TRUE;
char buf[32];
char *result = fgets(buf, sizeof(buf), fp);
fclose(fp);
if (!result)
return PR_TRUE;
const PRInt32 n = PR_Read(fd, buf, sizeof(buf));
PR_Close(fd);
// Trim off any trailing newline
int len = strlen(result);
if (len > 0 && result[len - 1] == '\n')
result[len - 1] = '\0';
if (n < 0)
return PR_FALSE;
// Trim off the trailing newline
if (buf[n - 1] == '\n')
buf[n - 1] = '\0';
// If the update xml doesn't provide the application version the file will
// contain the string "null" and it is assumed that the update is not older.
@ -258,7 +257,7 @@ IsOlderVersion(nsILocalFile *versionFile, const char *&appVersion)
if (strncmp(buf, kNull, sizeof(kNull) - 1) == 0)
return PR_FALSE;
if (NS_CompareVersions(appVersion, result) > 0)
if (NS_CompareVersions(appVersion, buf) > 0)
return PR_TRUE;
return PR_FALSE;
@ -433,7 +432,7 @@ ApplyUpdate(nsIFile *greDir, nsIFile *updateDir, nsILocalFile *statusFile,
if (NS_FAILED(rv))
return;
if (!SetStatus(statusFile, "applying")) {
if (!SetStatusApplying(statusFile)) {
LOG(("failed setting status to 'applying'\n"));
return;
}