Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(592)

Side by Side Diff: generate_delta_main.cc

Issue 3521016: AU: Start checkpointing update progress. (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/update_engine.git
Patch Set: address review comments Created 10 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « download_action_unittest.cc ('k') | omaha_hash_calculator.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium OS 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 #include <sys/types.h> 5 #include <sys/types.h>
6 #include <sys/stat.h> 6 #include <sys/stat.h>
7 #include <errno.h> 7 #include <errno.h>
8 #include <fcntl.h> 8 #include <fcntl.h>
9 #include <unistd.h> 9 #include <unistd.h>
10
10 #include <set> 11 #include <set>
11 #include <string> 12 #include <string>
12 #include <vector> 13 #include <vector>
14
15 #include <base/command_line.h>
16 #include <base/logging.h>
13 #include <gflags/gflags.h> 17 #include <gflags/gflags.h>
14 #include <glib.h> 18 #include <glib.h>
15 #include "base/command_line.h" 19
16 #include "base/logging.h"
17 #include "update_engine/delta_diff_generator.h" 20 #include "update_engine/delta_diff_generator.h"
18 #include "update_engine/delta_performer.h" 21 #include "update_engine/delta_performer.h"
22 #include "update_engine/prefs.h"
19 #include "update_engine/subprocess.h" 23 #include "update_engine/subprocess.h"
20 #include "update_engine/update_metadata.pb.h" 24 #include "update_engine/update_metadata.pb.h"
21 #include "update_engine/utils.h" 25 #include "update_engine/utils.h"
22 26
23 DEFINE_string(old_dir, "", 27 DEFINE_string(old_dir, "",
24 "Directory where the old rootfs is loop mounted read-only"); 28 "Directory where the old rootfs is loop mounted read-only");
25 DEFINE_string(new_dir, "", 29 DEFINE_string(new_dir, "",
26 "Directory where the new rootfs is loop mounted read-only"); 30 "Directory where the new rootfs is loop mounted read-only");
27 DEFINE_string(old_image, "", "Path to the old rootfs"); 31 DEFINE_string(old_image, "", "Path to the old rootfs");
28 DEFINE_string(new_image, "", "Path to the new rootfs"); 32 DEFINE_string(new_image, "", "Path to the new rootfs");
29 DEFINE_string(out_file, "", "Path to output file"); 33 DEFINE_string(out_file, "", "Path to output file");
30 DEFINE_string(old_kernel, "", "Path to the old kernel partition image"); 34 DEFINE_string(old_kernel, "", "Path to the old kernel partition image");
31 DEFINE_string(new_kernel, "", "Path to the new kernel partition image"); 35 DEFINE_string(new_kernel, "", "Path to the new kernel partition image");
32 DEFINE_string(private_key, "", "Path to private key in .pem format"); 36 DEFINE_string(private_key, "", "Path to private key in .pem format");
33 DEFINE_string(apply_delta, "", 37 DEFINE_string(apply_delta, "",
34 "If set, apply delta over old_image. (For debugging.)"); 38 "If set, apply delta over old_image. (For debugging.)");
39 DEFINE_string(prefs_dir, "/tmp/update_engine_prefs",
40 "Preferences directory, used with apply_delta.");
35 41
36 // This file contains a simple program that takes an old path, a new path, 42 // This file contains a simple program that takes an old path, a new path,
37 // and an output file as arguments and the path to an output file and 43 // and an output file as arguments and the path to an output file and
38 // generates a delta that can be sent to Chrome OS clients. 44 // generates a delta that can be sent to Chrome OS clients.
39 45
40 using std::set; 46 using std::set;
41 using std::string; 47 using std::string;
42 using std::vector; 48 using std::vector;
43 49
44 namespace chromeos_update_engine { 50 namespace chromeos_update_engine {
(...skipping 12 matching lines...) Expand all
57 CommandLine::Init(argc, argv); 63 CommandLine::Init(argc, argv);
58 Subprocess::Init(); 64 Subprocess::Init();
59 logging::InitLogging("delta_generator.log", 65 logging::InitLogging("delta_generator.log",
60 logging::LOG_ONLY_TO_SYSTEM_DEBUG_LOG, 66 logging::LOG_ONLY_TO_SYSTEM_DEBUG_LOG,
61 logging::DONT_LOCK_LOG_FILE, 67 logging::DONT_LOCK_LOG_FILE,
62 logging::APPEND_TO_OLD_LOG_FILE); 68 logging::APPEND_TO_OLD_LOG_FILE);
63 if (!FLAGS_apply_delta.empty()) { 69 if (!FLAGS_apply_delta.empty()) {
64 if (FLAGS_old_image.empty()) { 70 if (FLAGS_old_image.empty()) {
65 LOG(FATAL) << "Must pass --old_image with --apply_delta."; 71 LOG(FATAL) << "Must pass --old_image with --apply_delta.";
66 } 72 }
67 DeltaPerformer performer; 73 Prefs prefs;
74 LOG(INFO) << "Setting up preferences under: " << FLAGS_prefs_dir;
75 LOG_IF(ERROR, !prefs.Init(FilePath(FLAGS_prefs_dir)))
76 << "Failed to initialize preferences.";
77 DeltaPerformer performer(&prefs);
68 CHECK_EQ(performer.Open(FLAGS_old_image.c_str(), 0, 0), 0); 78 CHECK_EQ(performer.Open(FLAGS_old_image.c_str(), 0, 0), 0);
69 CHECK(performer.OpenKernel(FLAGS_old_kernel.c_str())); 79 CHECK(performer.OpenKernel(FLAGS_old_kernel.c_str()));
70 vector<char> buf(1024 * 1024); 80 vector<char> buf(1024 * 1024);
71 int fd = open(FLAGS_apply_delta.c_str(), O_RDONLY, 0); 81 int fd = open(FLAGS_apply_delta.c_str(), O_RDONLY, 0);
72 CHECK_GE(fd, 0); 82 CHECK_GE(fd, 0);
73 ScopedFdCloser fd_closer(&fd); 83 ScopedFdCloser fd_closer(&fd);
74 for (off_t offset = 0;; offset += buf.size()) { 84 for (off_t offset = 0;; offset += buf.size()) {
75 ssize_t bytes_read; 85 ssize_t bytes_read;
76 CHECK(utils::PReadAll(fd, &buf[0], buf.size(), offset, &bytes_read)); 86 CHECK(utils::PReadAll(fd, &buf[0], buf.size(), offset, &bytes_read));
77 if (bytes_read == 0) 87 if (bytes_read == 0)
78 break; 88 break;
79 CHECK_EQ(performer.Write(&buf[0], bytes_read), bytes_read); 89 CHECK_EQ(performer.Write(&buf[0], bytes_read), bytes_read);
80 } 90 }
81 CHECK_EQ(performer.Close(), 0); 91 CHECK_EQ(performer.Close(), 0);
82 LOG(INFO) << "done applying delta."; 92 LOG(INFO) << "done applying delta.";
83 return 0; 93 return 0;
84 } 94 }
85 CHECK(!FLAGS_old_dir.empty()); 95 CHECK(!FLAGS_old_dir.empty());
86 CHECK(!FLAGS_new_dir.empty()); 96 CHECK(!FLAGS_new_dir.empty());
87 CHECK(!FLAGS_old_image.empty()); 97 CHECK(!FLAGS_old_image.empty());
88 CHECK(!FLAGS_new_image.empty()); 98 CHECK(!FLAGS_new_image.empty());
89 CHECK(!FLAGS_out_file.empty()); 99 CHECK(!FLAGS_out_file.empty());
90 CHECK(!FLAGS_old_kernel.empty()); 100 CHECK(!FLAGS_old_kernel.empty());
91 CHECK(!FLAGS_new_kernel.empty()); 101 CHECK(!FLAGS_new_kernel.empty());
92 if ((!IsDir(FLAGS_old_dir.c_str())) || (!IsDir(FLAGS_new_dir.c_str()))) { 102 if ((!IsDir(FLAGS_old_dir.c_str())) || (!IsDir(FLAGS_new_dir.c_str()))) {
93 LOG(FATAL) << "old_dir or new_dir not directory"; 103 LOG(FATAL) << "old_dir or new_dir not directory";
94 } 104 }
95 105
96 DeltaDiffGenerator::GenerateDeltaUpdateFile(FLAGS_old_dir, 106 DeltaDiffGenerator::GenerateDeltaUpdateFile(FLAGS_old_dir,
97 FLAGS_old_image, 107 FLAGS_old_image,
98 FLAGS_new_dir, 108 FLAGS_new_dir,
99 FLAGS_new_image, 109 FLAGS_new_image,
100 FLAGS_old_kernel, 110 FLAGS_old_kernel,
101 FLAGS_new_kernel, 111 FLAGS_new_kernel,
102 FLAGS_out_file, 112 FLAGS_out_file,
103 FLAGS_private_key); 113 FLAGS_private_key);
104 114
105 return 0; 115 return 0;
106 } 116 }
107 117
108 } // namespace {} 118 } // namespace {}
109 119
110 } // namespace chromeos_update_engine 120 } // namespace chromeos_update_engine
111 121
112 int main(int argc, char** argv) { 122 int main(int argc, char** argv) {
113 return chromeos_update_engine::Main(argc, argv); 123 return chromeos_update_engine::Main(argc, argv);
114 } 124 }
OLDNEW
« no previous file with comments | « download_action_unittest.cc ('k') | omaha_hash_calculator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698