| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 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 |
| 5 #include <sys/types.h> | 8 #include <sys/types.h> |
| 6 #include <sys/stat.h> | 9 #include <sys/stat.h> |
| 7 #include <unistd.h> | 10 #include <unistd.h> |
| 8 | 11 |
| 9 #include <set> | 12 #include <set> |
| 10 #include <string> | 13 #include <string> |
| 11 #include <vector> | 14 #include <vector> |
| 12 | 15 |
| 13 #include <gflags/gflags.h> | 16 #include <gflags/gflags.h> |
| 14 #include <glib.h> | 17 #include <glib.h> |
| 15 #include "chromeos/obsolete_logging.h" | 18 #include "chromeos/obsolete_logging.h" |
| 16 | 19 |
| 17 #include "update_engine/delta_diff_generator.h" | 20 #include "update_engine/delta_diff_generator.h" |
| 18 #include "update_engine/delta_diff_parser.h" | 21 #include "update_engine/delta_diff_parser.h" |
| 19 #include "update_engine/filesystem_copier_action.h" | 22 #include "update_engine/filesystem_copier_action.h" |
| 20 #include "update_engine/install_action.h" | 23 // #include "update_engine/install_action.h" // re-add |
| 21 #include "update_engine/install_plan.h" | 24 #include "update_engine/install_plan.h" |
| 22 #include "update_engine/test_utils.h" | 25 #include "update_engine/test_utils.h" |
| 23 #include "update_engine/update_metadata.pb.h" | 26 #include "update_engine/update_metadata.pb.h" |
| 24 #include "update_engine/utils.h" | 27 #include "update_engine/utils.h" |
| 25 | 28 |
| 26 // This file contains a simple program that unpacks a delta diff into a | 29 // This file contains a simple program that unpacks a delta diff into a |
| 27 // directory. | 30 // directory. |
| 28 | 31 |
| 29 using std::set; | 32 using std::set; |
| 30 using std::string; | 33 using std::string; |
| 31 using std::vector; | 34 using std::vector; |
| 32 using std::tr1::shared_ptr; | 35 using std::tr1::shared_ptr; |
| 33 | 36 |
| 34 DEFINE_string(delta, "", "the delta file"); | 37 DEFINE_string(delta, "", "the delta file"); |
| 35 DEFINE_string(output_dev, "", "the output device"); | 38 DEFINE_string(output_dev, "", "the output device"); |
| 36 DEFINE_string(root, "", "the fake system root"); | 39 DEFINE_string(root, "", "the fake system root"); |
| 37 DEFINE_string(dump_delta, "", "path to delta file to dump"); | 40 DEFINE_string(dump_delta, "", "path to delta file to dump"); |
| 38 | 41 |
| 39 namespace chromeos_update_engine { | 42 namespace chromeos_update_engine { |
| 40 | 43 |
| 41 class TestInstaller : public ActionProcessorDelegate { | 44 class TestInstaller : public ActionProcessorDelegate { |
| 42 public: | 45 public: |
| 43 TestInstaller(GMainLoop *loop, | 46 TestInstaller(GMainLoop *loop, |
| 44 const string& sys_root, | 47 const string& sys_root, |
| 45 const string& delta_path, | 48 const string& delta_path, |
| 46 const string& install_path) | 49 const string& install_path) |
| 47 : loop_(loop), | 50 : loop_(loop), |
| 48 sys_root_(sys_root), | 51 sys_root_(sys_root), |
| 49 delta_path_(delta_path), | |
| 50 install_path_(install_path) {} | 52 install_path_(install_path) {} |
| 51 void Update(); | 53 void Update(); |
| 52 | 54 |
| 53 // Delegate method: | 55 // Delegate method: |
| 54 void ProcessingDone(const ActionProcessor* processor, bool success); | 56 void ProcessingDone(const ActionProcessor* processor, bool success); |
| 55 private: | 57 private: |
| 56 vector<shared_ptr<AbstractAction> > actions_; | 58 vector<shared_ptr<AbstractAction> > actions_; |
| 57 ActionProcessor processor_; | 59 ActionProcessor processor_; |
| 58 GMainLoop *loop_; | 60 GMainLoop *loop_; |
| 59 string sys_root_; | 61 string sys_root_; |
| 60 string delta_path_; | |
| 61 string install_path_; | 62 string install_path_; |
| 62 }; | 63 }; |
| 63 | 64 |
| 64 // Returns true on success. If there was no update available, that's still | 65 // Returns true on success. If there was no update available, that's still |
| 65 // success. | 66 // success. |
| 66 // If force_full is true, try to force a full update. | 67 // If force_full is true, try to force a full update. |
| 67 void TestInstaller::Update() { | 68 void TestInstaller::Update() { |
| 68 CHECK(!processor_.IsRunning()); | 69 CHECK(!processor_.IsRunning()); |
| 69 processor_.set_delegate(this); | 70 processor_.set_delegate(this); |
| 70 | 71 |
| 71 // Actions: | 72 // Actions: |
| 72 shared_ptr<ObjectFeederAction<InstallPlan> > object_feeder_action( | 73 shared_ptr<ObjectFeederAction<InstallPlan> > object_feeder_action( |
| 73 new ObjectFeederAction<InstallPlan>); | 74 new ObjectFeederAction<InstallPlan>); |
| 74 shared_ptr<FilesystemCopierAction> filesystem_copier_action( | 75 shared_ptr<FilesystemCopierAction> filesystem_copier_action( |
| 75 new FilesystemCopierAction); | 76 new FilesystemCopierAction); |
| 76 shared_ptr<InstallAction> install_action( | 77 // shared_ptr<InstallAction> install_action( // re-add |
| 77 new InstallAction); | 78 // new InstallAction); |
| 78 | 79 |
| 79 actions_.push_back(object_feeder_action); | 80 actions_.push_back(object_feeder_action); |
| 80 actions_.push_back(filesystem_copier_action); | 81 actions_.push_back(filesystem_copier_action); |
| 81 actions_.push_back(install_action); | 82 // actions_.push_back(install_action); // re-add |
| 82 | 83 |
| 83 // Enqueue the actions | 84 // Enqueue the actions |
| 84 for (vector<shared_ptr<AbstractAction> >::iterator it = actions_.begin(); | 85 for (vector<shared_ptr<AbstractAction> >::iterator it = actions_.begin(); |
| 85 it != actions_.end(); ++it) { | 86 it != actions_.end(); ++it) { |
| 86 processor_.EnqueueAction(it->get()); | 87 processor_.EnqueueAction(it->get()); |
| 87 } | 88 } |
| 88 | 89 |
| 89 // Bond them together. We have to use the leaf-types when calling | 90 // Bond them together. We have to use the leaf-types when calling |
| 90 // BondActions(). | 91 // BondActions(). |
| 91 BondActions(object_feeder_action.get(), filesystem_copier_action.get()); | 92 BondActions(object_feeder_action.get(), filesystem_copier_action.get()); |
| 92 BondActions(filesystem_copier_action.get(), install_action.get()); | 93 // re-add |
| 94 // BondActions(filesystem_copier_action.get(), install_action.get()); |
| 93 | 95 |
| 94 InstallPlan install_plan(false, | 96 InstallPlan install_plan(false, |
| 95 "", | 97 "", |
| 96 "", | 98 "", |
| 97 delta_path_, | |
| 98 install_path_); | 99 install_path_); |
| 99 filesystem_copier_action->set_copy_source(sys_root_); | 100 filesystem_copier_action->set_copy_source(sys_root_); |
| 100 object_feeder_action->set_obj(install_plan); | 101 object_feeder_action->set_obj(install_plan); |
| 101 processor_.StartProcessing(); | 102 processor_.StartProcessing(); |
| 102 } | 103 } |
| 103 | 104 |
| 104 void TestInstaller::ProcessingDone(const ActionProcessor* processor, | 105 void TestInstaller::ProcessingDone(const ActionProcessor* processor, |
| 105 bool success) { | 106 bool success) { |
| 106 LOG(INFO) << "install " << (success ? "succeeded" : "failed"); | 107 LOG(INFO) << "install " << (success ? "succeeded" : "failed"); |
| 107 actions_.clear(); | 108 actions_.clear(); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 124 bool Main(int argc, char** argv) { | 125 bool Main(int argc, char** argv) { |
| 125 g_thread_init(NULL); | 126 g_thread_init(NULL); |
| 126 google::ParseCommandLineFlags(&argc, &argv, true); | 127 google::ParseCommandLineFlags(&argc, &argv, true); |
| 127 logging::InitLogging("", | 128 logging::InitLogging("", |
| 128 logging::LOG_ONLY_TO_SYSTEM_DEBUG_LOG, | 129 logging::LOG_ONLY_TO_SYSTEM_DEBUG_LOG, |
| 129 logging::DONT_LOCK_LOG_FILE, | 130 logging::DONT_LOCK_LOG_FILE, |
| 130 logging::APPEND_TO_OLD_LOG_FILE); | 131 logging::APPEND_TO_OLD_LOG_FILE); |
| 131 | 132 |
| 132 LOG(INFO) << "starting"; | 133 LOG(INFO) << "starting"; |
| 133 | 134 |
| 134 if (!FLAGS_dump_delta.empty()) { | |
| 135 CHECK(FLAGS_delta.empty()); | |
| 136 CHECK(FLAGS_root.empty()); | |
| 137 CHECK(FLAGS_output_dev.empty()); | |
| 138 | |
| 139 DeltaDiffParser parser(FLAGS_dump_delta); | |
| 140 for (DeltaDiffParser::Iterator it = parser.Begin(); | |
| 141 it != parser.End(); it.Increment()) { | |
| 142 DeltaArchiveManifest_File file = it.GetFile(); | |
| 143 const char* format = "---"; | |
| 144 ssize_t offset = -1; | |
| 145 ssize_t length = -1; | |
| 146 if (file.has_data_format()) { | |
| 147 switch (file.data_format()) { | |
| 148 case DeltaArchiveManifest_File_DataFormat_FULL: | |
| 149 format = "FULL"; | |
| 150 break; | |
| 151 case DeltaArchiveManifest_File_DataFormat_FULL_GZ: | |
| 152 format = "FULL_GZ"; | |
| 153 break; | |
| 154 case DeltaArchiveManifest_File_DataFormat_BSDIFF: | |
| 155 format = "BSDIFF"; | |
| 156 break; | |
| 157 case DeltaArchiveManifest_File_DataFormat_COURGETTE: | |
| 158 format = "COURGETTE"; | |
| 159 break; | |
| 160 default: | |
| 161 format = "???"; | |
| 162 } | |
| 163 if (file.has_data_offset()) | |
| 164 offset = file.data_offset(); | |
| 165 if (file.has_data_length()) | |
| 166 length = file.data_length(); | |
| 167 } | |
| 168 printf("%s %o %s %d %d\n", it.path().c_str(), file.mode(), format, offset, | |
| 169 length); | |
| 170 } | |
| 171 exit(0); | |
| 172 } | |
| 173 | |
| 174 CHECK(!FLAGS_delta.empty()); | |
| 175 CHECK(!FLAGS_root.empty()); | |
| 176 CHECK(!FLAGS_output_dev.empty()); | |
| 177 | |
| 178 // Create the single GMainLoop | 135 // Create the single GMainLoop |
| 179 GMainLoop* loop = g_main_loop_new(g_main_context_default(), FALSE); | 136 GMainLoop* loop = g_main_loop_new(g_main_context_default(), FALSE); |
| 180 | 137 |
| 181 chromeos_update_engine::TestInstaller test_installer(loop, | 138 chromeos_update_engine::TestInstaller test_installer(loop, |
| 182 FLAGS_root, | 139 FLAGS_root, |
| 183 FLAGS_delta, | 140 FLAGS_delta, |
| 184 FLAGS_output_dev); | 141 FLAGS_output_dev); |
| 185 | 142 |
| 186 g_timeout_add(0, &chromeos_update_engine::TestInstallInMainLoop, | 143 g_timeout_add(0, &chromeos_update_engine::TestInstallInMainLoop, |
| 187 &test_installer); | 144 &test_installer); |
| 188 | 145 |
| 189 g_main_loop_run(loop); | 146 g_main_loop_run(loop); |
| 190 g_main_loop_unref(loop); | 147 g_main_loop_unref(loop); |
| 191 | 148 |
| 192 LOG(INFO) << "Done."; | 149 LOG(INFO) << "Done."; |
| 193 return true; | 150 return true; |
| 194 } | 151 } |
| 195 | 152 |
| 196 } // namespace chromeos_update_engine | 153 } // namespace chromeos_update_engine |
| 197 | 154 |
| 198 int main(int argc, char** argv) { | 155 int main(int argc, char** argv) { |
| 199 return chromeos_update_engine::Main(argc, argv) ? 0 : 1; | 156 return chromeos_update_engine::Main(argc, argv) ? 0 : 1; |
| 200 } | 157 } |
| OLD | NEW |