| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 // TODO(adlr): get rid of commented out lines or comment them back in. | |
| 6 // Look for "// re-add" next to those comments. | |
| 7 | |
| 8 #include <sys/types.h> | |
| 9 #include <sys/stat.h> | |
| 10 #include <unistd.h> | |
| 11 | |
| 12 #include <set> | |
| 13 #include <string> | |
| 14 #include <vector> | |
| 15 | |
| 16 #include <gflags/gflags.h> | |
| 17 #include <glib.h> | |
| 18 #include "chromeos/obsolete_logging.h" | |
| 19 | |
| 20 #include "update_engine/delta_diff_generator.h" | |
| 21 #include "update_engine/delta_diff_parser.h" | |
| 22 #include "update_engine/filesystem_copier_action.h" | |
| 23 // #include "update_engine/install_action.h" // re-add | |
| 24 #include "update_engine/install_plan.h" | |
| 25 #include "update_engine/test_utils.h" | |
| 26 #include "update_engine/update_metadata.pb.h" | |
| 27 #include "update_engine/utils.h" | |
| 28 | |
| 29 // This file contains a simple program that unpacks a delta diff into a | |
| 30 // directory. | |
| 31 | |
| 32 using std::set; | |
| 33 using std::string; | |
| 34 using std::vector; | |
| 35 using std::tr1::shared_ptr; | |
| 36 | |
| 37 DEFINE_string(delta, "", "the delta file"); | |
| 38 DEFINE_string(output_dev, "", "the output device"); | |
| 39 DEFINE_string(root, "", "the fake system root"); | |
| 40 DEFINE_string(dump_delta, "", "path to delta file to dump"); | |
| 41 | |
| 42 namespace chromeos_update_engine { | |
| 43 | |
| 44 class TestInstaller : public ActionProcessorDelegate { | |
| 45 public: | |
| 46 TestInstaller(GMainLoop *loop, | |
| 47 const string& sys_root, | |
| 48 const string& delta_path, | |
| 49 const string& install_path) | |
| 50 : loop_(loop), | |
| 51 sys_root_(sys_root), | |
| 52 install_path_(install_path) {} | |
| 53 void Update(); | |
| 54 | |
| 55 // Delegate method: | |
| 56 void ProcessingDone(const ActionProcessor* processor, bool success); | |
| 57 private: | |
| 58 vector<shared_ptr<AbstractAction> > actions_; | |
| 59 ActionProcessor processor_; | |
| 60 GMainLoop *loop_; | |
| 61 string sys_root_; | |
| 62 string install_path_; | |
| 63 }; | |
| 64 | |
| 65 // Returns true on success. If there was no update available, that's still | |
| 66 // success. | |
| 67 // If force_full is true, try to force a full update. | |
| 68 void TestInstaller::Update() { | |
| 69 CHECK(!processor_.IsRunning()); | |
| 70 processor_.set_delegate(this); | |
| 71 | |
| 72 // Actions: | |
| 73 shared_ptr<ObjectFeederAction<InstallPlan> > object_feeder_action( | |
| 74 new ObjectFeederAction<InstallPlan>); | |
| 75 shared_ptr<FilesystemCopierAction> filesystem_copier_action( | |
| 76 new FilesystemCopierAction); | |
| 77 // shared_ptr<InstallAction> install_action( // re-add | |
| 78 // new InstallAction); | |
| 79 | |
| 80 actions_.push_back(object_feeder_action); | |
| 81 actions_.push_back(filesystem_copier_action); | |
| 82 // actions_.push_back(install_action); // re-add | |
| 83 | |
| 84 // Enqueue the actions | |
| 85 for (vector<shared_ptr<AbstractAction> >::iterator it = actions_.begin(); | |
| 86 it != actions_.end(); ++it) { | |
| 87 processor_.EnqueueAction(it->get()); | |
| 88 } | |
| 89 | |
| 90 // Bond them together. We have to use the leaf-types when calling | |
| 91 // BondActions(). | |
| 92 BondActions(object_feeder_action.get(), filesystem_copier_action.get()); | |
| 93 // re-add | |
| 94 // BondActions(filesystem_copier_action.get(), install_action.get()); | |
| 95 | |
| 96 InstallPlan install_plan(false, | |
| 97 "", | |
| 98 "", | |
| 99 install_path_); | |
| 100 filesystem_copier_action->set_copy_source(sys_root_); | |
| 101 object_feeder_action->set_obj(install_plan); | |
| 102 processor_.StartProcessing(); | |
| 103 } | |
| 104 | |
| 105 void TestInstaller::ProcessingDone(const ActionProcessor* processor, | |
| 106 bool success) { | |
| 107 LOG(INFO) << "install " << (success ? "succeeded" : "failed"); | |
| 108 actions_.clear(); | |
| 109 g_main_loop_quit(loop_); | |
| 110 } | |
| 111 | |
| 112 gboolean TestInstallInMainLoop(void* arg) { | |
| 113 TestInstaller* test_installer = reinterpret_cast<TestInstaller*>(arg); | |
| 114 test_installer->Update(); | |
| 115 return FALSE; // Don't call this callback function again | |
| 116 } | |
| 117 | |
| 118 | |
| 119 void usage(const char* argv0) { | |
| 120 printf("usage: %s --root=system_root --delta=delta_file " | |
| 121 "--output_dev=output_dev\n", argv0); | |
| 122 exit(1); | |
| 123 } | |
| 124 | |
| 125 bool Main(int argc, char** argv) { | |
| 126 g_thread_init(NULL); | |
| 127 google::ParseCommandLineFlags(&argc, &argv, true); | |
| 128 logging::InitLogging("", | |
| 129 logging::LOG_ONLY_TO_SYSTEM_DEBUG_LOG, | |
| 130 logging::DONT_LOCK_LOG_FILE, | |
| 131 logging::APPEND_TO_OLD_LOG_FILE); | |
| 132 | |
| 133 LOG(INFO) << "starting"; | |
| 134 | |
| 135 // Create the single GMainLoop | |
| 136 GMainLoop* loop = g_main_loop_new(g_main_context_default(), FALSE); | |
| 137 | |
| 138 chromeos_update_engine::TestInstaller test_installer(loop, | |
| 139 FLAGS_root, | |
| 140 FLAGS_delta, | |
| 141 FLAGS_output_dev); | |
| 142 | |
| 143 g_timeout_add(0, &chromeos_update_engine::TestInstallInMainLoop, | |
| 144 &test_installer); | |
| 145 | |
| 146 g_main_loop_run(loop); | |
| 147 g_main_loop_unref(loop); | |
| 148 | |
| 149 LOG(INFO) << "Done."; | |
| 150 return true; | |
| 151 } | |
| 152 | |
| 153 } // namespace chromeos_update_engine | |
| 154 | |
| 155 int main(int argc, char** argv) { | |
| 156 return chromeos_update_engine::Main(argc, argv) ? 0 : 1; | |
| 157 } | |
| OLD | NEW |