Main patch for Bug 759469 - Add new updater instruction to add a file if it doesn't exist in the destination. r=bbondy

This commit is contained in:
Robert Strong 2014-03-05 11:43:11 -08:00
Родитель d86e99dd28
Коммит 5b22b1861b
1 изменённых файлов: 73 добавлений и 2 удалений

Просмотреть файл

@ -22,6 +22,13 @@
* be the first entry in the update manifest. The type is used to support * 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. * 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 * precomplete
* ----------- * -----------
* method = "remove" | "rmdir" * method = "remove" | "rmdir"
@ -1580,6 +1587,67 @@ AddIfFile::Finish(int status)
AddFile::Finish(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 "<testfile>" "<newfile>"
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 class PatchIfFile : public PatchFile
{ {
public: public:
@ -3624,9 +3692,9 @@ int DoUpdate()
ensure_parent_dir(manifest); ensure_parent_dir(manifest);
// extract the manifest // extract the manifest
int rv = gArchiveReader.ExtractFile("updatev2.manifest", manifest); int rv = gArchiveReader.ExtractFile("updatev3.manifest", manifest);
if (rv) { if (rv) {
rv = gArchiveReader.ExtractFile("update.manifest", manifest); rv = gArchiveReader.ExtractFile("updatev2.manifest", manifest);
if (rv) { if (rv) {
LOG(("DoUpdate: error extracting manifest file")); LOG(("DoUpdate: error extracting manifest file"));
return rv; return rv;
@ -3702,6 +3770,9 @@ int DoUpdate()
else if (NS_tstrcmp(token, NS_T("add-if")) == 0) { // Add if exists else if (NS_tstrcmp(token, NS_T("add-if")) == 0) { // Add if exists
action = new AddIfFile(); 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 else if (NS_tstrcmp(token, NS_T("patch-if")) == 0) { // Patch if exists
action = new PatchIfFile(); action = new PatchIfFile();
} }