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