diff --git a/toolkit/mozapps/update/updater/updater.cpp b/toolkit/mozapps/update/updater/updater.cpp index 7d574fa064b..0a6402438cb 100644 --- a/toolkit/mozapps/update/updater/updater.cpp +++ b/toolkit/mozapps/update/updater/updater.cpp @@ -22,6 +22,13 @@ * be the first entry in the update manifest. The type is used to support * downgrades by causing the actions defined in precomplete to be performed. * + * updatev3.manifest + * ----------------- + * method = "add" | "add-if" | "add-if-not" | "patch" | "patch-if" | + * "remove" | "rmdir" | "rmrfdir" | type + * + * 'add-if-not' adds a file if it doesn't exist. + * * precomplete * ----------- * method = "remove" | "rmdir" @@ -1580,6 +1587,67 @@ AddIfFile::Finish(int status) AddFile::Finish(status); } +class AddIfNotFile : public AddFile +{ +public: + AddIfNotFile() : mTestFile(NULL) { } + + virtual int Parse(NS_tchar *line); + virtual int Prepare(); + virtual int Execute(); + virtual void Finish(int status); + +protected: + const NS_tchar *mTestFile; +}; + +int +AddIfNotFile::Parse(NS_tchar *line) +{ + // format "" "" + + mTestFile = get_valid_path(&line); + if (!mTestFile) + return PARSE_ERROR; + + // consume whitespace between args + NS_tchar *q = mstrtok(kQuote, &line); + if (!q) + return PARSE_ERROR; + + return AddFile::Parse(line); +} + +int +AddIfNotFile::Prepare() +{ + // If the test file exists, then skip this action. + if (!NS_taccess(mTestFile, F_OK)) { + mTestFile = NULL; + return OK; + } + + return AddFile::Prepare(); +} + +int +AddIfNotFile::Execute() +{ + if (!mTestFile) + return OK; + + return AddFile::Execute(); +} + +void +AddIfNotFile::Finish(int status) +{ + if (!mTestFile) + return; + + AddFile::Finish(status); +} + class PatchIfFile : public PatchFile { public: @@ -3624,9 +3692,9 @@ int DoUpdate() ensure_parent_dir(manifest); // extract the manifest - int rv = gArchiveReader.ExtractFile("updatev2.manifest", manifest); + int rv = gArchiveReader.ExtractFile("updatev3.manifest", manifest); if (rv) { - rv = gArchiveReader.ExtractFile("update.manifest", manifest); + rv = gArchiveReader.ExtractFile("updatev2.manifest", manifest); if (rv) { LOG(("DoUpdate: error extracting manifest file")); return rv; @@ -3702,6 +3770,9 @@ int DoUpdate() else if (NS_tstrcmp(token, NS_T("add-if")) == 0) { // Add if exists action = new AddIfFile(); } + else if (NS_tstrcmp(token, NS_T("add-if-not")) == 0) { // Add if not exists + action = new AddIfNotFile(); + } else if (NS_tstrcmp(token, NS_T("patch-if")) == 0) { // Patch if exists action = new PatchIfFile(); }