Bug 410485 - Windows updater broken from bug 396052, r=luser
authorbenjamin@smedbergs.us
Wed, 02 Jan 2008 10:05:01 -0800
changeset 9761 44766038293b3d3732d4840cd364f0ecf4890b69
parent 9760 696d5f6cc38a25f4856900936c3f9214985f74db
child 9762 0fb44962ba877bef2dcfffc1c818249081fd8b52
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersluser
bugs410485, 396052
milestone1.9b3pre
Bug 410485 - Windows updater broken from bug 396052, r=luser
modules/libmar/src/mar.h
modules/libmar/src/mar_read.c
toolkit/mozapps/update/src/updater/archivereader.cpp
toolkit/mozapps/update/src/updater/archivereader.h
toolkit/mozapps/update/src/updater/updater.cpp
--- a/modules/libmar/src/mar.h
+++ b/modules/libmar/src/mar.h
@@ -71,16 +71,20 @@ typedef int (* MarItemCallback)(MarFile 
 /**
  * Open a MAR file for reading.
  * @param path      Specifies the path to the MAR file to open.  This path must
  *                  be compatible with fopen.
  * @returns         NULL if an error occurs.
  */
 MarFile *mar_open(const char *path);
 
+#ifdef XP_WIN
+MarFile *mar_wopen(const PRUnichar *path);
+#endif
+
 /**
  * Close a MAR file that was opened using mar_open.
  * @param mar       The MarFile object to close.
  */
 void mar_close(MarFile *mar);
 
 /**
  * Find an item in the MAR file by name.
--- a/modules/libmar/src/mar_read.c
+++ b/modules/libmar/src/mar_read.c
@@ -174,23 +174,23 @@ static int mar_read_index(MarFile *mar) 
   bufptr = buf;
   bufend = buf + size_of_index;
   while (bufptr < bufend && mar_consume_index(mar, &bufptr, bufend) == 0);
 
   free(buf);
   return (bufptr == bufend) ? 0 : -1;
 }
 
-MarFile *mar_open(const char *path) {
+/**
+ * Internal shared code for mar_open and mar_wopen.
+ * On failure, will fclose(fp).
+ */
+static MarFile *mar_fpopen(FILE *fp)
+{
   MarFile *mar;
-  FILE *fp;
-
-  fp = fopen(path, "rb");
-  if (!fp)
-    return NULL;
 
   mar = (MarFile *) malloc(sizeof(*mar));
   if (!mar) {
     fclose(fp);
     return NULL;
   }
 
   mar->fp = fp;
@@ -198,16 +198,38 @@ MarFile *mar_open(const char *path) {
   if (mar_read_index(mar)) {
     mar_close(mar);
     return NULL;
   }
 
   return mar;
 }
 
+MarFile *mar_open(const char *path) {
+  FILE *fp;
+
+  fp = fopen(path, "rb");
+  if (!fp)
+    return NULL;
+
+  return mar_fpopen(fp);
+}
+
+#ifdef XP_WIN
+MarFile *mar_wopen(const PRUnichar *path) {
+  FILE *fp;
+
+  fp = _wfopen(path, L"rb");
+  if (!fp)
+    return NULL;
+
+  return mar_fpopen(fp);
+}
+#endif
+
 void mar_close(MarFile *mar) {
   MarItem *item;
   int i;
 
   fclose(mar->fp);
 
   for (i = 0; i < TABLESIZE; ++i) {
     item = mar->item_table[i];
--- a/toolkit/mozapps/update/src/updater/archivereader.cpp
+++ b/toolkit/mozapps/update/src/updater/archivereader.cpp
@@ -44,22 +44,30 @@
 
 #if defined(XP_UNIX)
 # include <sys/types.h>
 #elif defined(XP_WIN)
 # include <io.h>
 #endif
 
 int
+#ifdef XP_WIN
+ArchiveReader::Open(const WCHAR *path)
+#else
 ArchiveReader::Open(const char *path)
+#endif
 {
   if (mArchive)
     Close();
 
+#ifdef XP_WIN
+  mArchive = mar_wopen(path);
+#else
   mArchive = mar_open(path);
+#endif
   if (!mArchive)
     return READ_ERROR;
 
   return OK;
 }
 
 void
 ArchiveReader::Close()
--- a/toolkit/mozapps/update/src/updater/archivereader.h
+++ b/toolkit/mozapps/update/src/updater/archivereader.h
@@ -44,17 +44,22 @@
 
 // This class provides an API to extract files from an update archive.
 class ArchiveReader
 {
 public:
   ArchiveReader() : mArchive(NULL) {}
   ~ArchiveReader() { Close(); }
 
+#ifdef XP_WIN
+  int Open(const WCHAR *path);
+#else
   int Open(const char *path);
+#endif
+
   void Close();
 
   int ExtractFile(const char *item, const char *destination);
   int ExtractFileToStream(const char *item, FILE *fp);
 
 private:
   int ExtractItemToStream(const MarItem *item, FILE *fp);
 
--- a/toolkit/mozapps/update/src/updater/updater.cpp
+++ b/toolkit/mozapps/update/src/updater/updater.cpp
@@ -1122,20 +1122,20 @@ LaunchCallbackApp(const NS_tchar *workin
 #endif
 }
 
 static void
 WriteStatusFile(int status)
 {
   // This is how we communicate our completion status to the main application.
 
-  char filename[MAXPATHLEN];
-  snprintf(filename, MAXPATHLEN, "%s/update.status", gSourcePath);
+  NS_tchar filename[MAXPATHLEN];
+  NS_tsnprintf(filename, MAXPATHLEN, NS_T("%s/update.status"), gSourcePath);
 
-  AutoFD fd = ensure_open(filename, O_WRONLY | O_TRUNC | O_CREAT | _O_BINARY, 0644);
+  AutoFD fd = NS_topen(filename, O_WRONLY | O_TRUNC | O_CREAT | _O_BINARY, 0644);
   if (fd < 0)
     return;
 
   const char *text;
 
   char buf[32];
   if (status == OK) {
     text = "succeeded\n";
@@ -1146,18 +1146,18 @@ WriteStatusFile(int status)
   write(fd, text, strlen(text));
 }
 
 static void
 UpdateThreadFunc(void *param)
 {
   // open ZIP archive and process...
 
-  char dataFile[MAXPATHLEN];
-  snprintf(dataFile, MAXPATHLEN, "%s/update.mar", gSourcePath);
+  NS_tchar dataFile[MAXPATHLEN];
+  NS_tsnprintf(dataFile, MAXPATHLEN, NS_T("%s/update.mar"), gSourcePath);
 
   int rv = gArchiveReader.Open(dataFile);
   if (rv == OK) {
     rv = DoUpdate();
     gArchiveReader.Close();
   }
 
   if (rv)