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

Side by Side Diff: src/platform/update_engine/generate_delta_main.cc

Issue 1718001: AU: Class to perform delta updates. (Closed)
Patch Set: fixes for review Created 10 years, 8 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
OLDNEW
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 #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 <unistd.h> 9 #include <unistd.h>
9 #include <set> 10 #include <set>
10 #include <string> 11 #include <string>
12 #include <vector>
11 #include <gflags/gflags.h> 13 #include <gflags/gflags.h>
12 #include <glib.h> 14 #include <glib.h>
13 #include "base/command_line.h" 15 #include "base/command_line.h"
14 #include "chromeos/obsolete_logging.h" 16 #include "chromeos/obsolete_logging.h"
15 #include "update_engine/delta_diff_generator.h" 17 #include "update_engine/delta_diff_generator.h"
18 #include "update_engine/delta_performer.h"
16 #include "update_engine/subprocess.h" 19 #include "update_engine/subprocess.h"
17 #include "update_engine/update_metadata.pb.h" 20 #include "update_engine/update_metadata.pb.h"
18 #include "update_engine/utils.h" 21 #include "update_engine/utils.h"
19 22
20 DEFINE_string(old_dir, "", 23 DEFINE_string(old_dir, "",
21 "Directory where the old rootfs is loop mounted read-only"); 24 "Directory where the old rootfs is loop mounted read-only");
22 DEFINE_string(new_dir, "", 25 DEFINE_string(new_dir, "",
23 "Directory where the new rootfs is loop mounted read-only"); 26 "Directory where the new rootfs is loop mounted read-only");
24 DEFINE_string(old_image, "", "Path to the old rootfs"); 27 DEFINE_string(old_image, "", "Path to the old rootfs");
25 DEFINE_string(new_image, "", "Path to the new rootfs"); 28 DEFINE_string(new_image, "", "Path to the new rootfs");
26 DEFINE_string(out_file, "", "Path to output file"); 29 DEFINE_string(out_file, "", "Path to output file");
30 DEFINE_string(apply_delta, "",
31 "If set, apply delta over old_image. (For debugging.)");
27 32
28 // This file contains a simple program that takes an old path, a new path, 33 // This file contains a simple program that takes an old path, a new path,
29 // and an output file as arguments and the path to an output file and 34 // and an output file as arguments and the path to an output file and
30 // generates a delta that can be sent to Chrome OS clients. 35 // generates a delta that can be sent to Chrome OS clients.
31 36
32 using std::set; 37 using std::set;
33 using std::string; 38 using std::string;
39 using std::vector;
34 40
35 namespace chromeos_update_engine { 41 namespace chromeos_update_engine {
36 42
37 namespace { 43 namespace {
38 44
39 bool IsDir(const char* path) { 45 bool IsDir(const char* path) {
40 struct stat stbuf; 46 struct stat stbuf;
41 TEST_AND_RETURN_FALSE_ERRNO(lstat(path, &stbuf) == 0); 47 TEST_AND_RETURN_FALSE_ERRNO(lstat(path, &stbuf) == 0);
42 return S_ISDIR(stbuf.st_mode); 48 return S_ISDIR(stbuf.st_mode);
43 } 49 }
44 50
45 int Main(int argc, char** argv) { 51 int Main(int argc, char** argv) {
46 g_thread_init(NULL); 52 g_thread_init(NULL);
47 google::ParseCommandLineFlags(&argc, &argv, true); 53 google::ParseCommandLineFlags(&argc, &argv, true);
48 CommandLine::Init(argc, argv); 54 CommandLine::Init(argc, argv);
49 Subprocess::Init(); 55 Subprocess::Init();
50 logging::InitLogging("delta_generator.log", 56 logging::InitLogging("delta_generator.log",
51 logging::LOG_ONLY_TO_SYSTEM_DEBUG_LOG, 57 logging::LOG_ONLY_TO_SYSTEM_DEBUG_LOG,
52 logging::DONT_LOCK_LOG_FILE, 58 logging::DONT_LOCK_LOG_FILE,
53 logging::APPEND_TO_OLD_LOG_FILE); 59 logging::APPEND_TO_OLD_LOG_FILE);
60 if (!FLAGS_apply_delta.empty()) {
61 if (FLAGS_old_image.empty()) {
62 LOG(FATAL) << "Must pass --old_image with --apply_delta.";
63 }
64 DeltaPerformer performer;
65 CHECK_EQ(0, performer.Open(FLAGS_old_image.c_str(), 0, 0));
Daniel Erat 2010/04/23 17:47:25 mind using the more-natural-to-read CHECK_EQ(actua
adlr 2010/04/23 20:50:17 Done.
66 vector<char> buf(1024 * 1024);
67 int fd = open(FLAGS_apply_delta.c_str(), O_RDONLY, 0);
68 CHECK_GE(fd, 0);
69 ScopedFdCloser fd_closer(&fd);
70 for (off_t offset = 0;; offset += buf.size()) {
71 ssize_t bytes_read;
72 CHECK(utils::PReadAll(fd, &buf[0], buf.size(), offset, &bytes_read));
73 if (bytes_read == 0)
74 break;
75 CHECK_EQ(bytes_read, performer.Write(&buf[0], bytes_read));
76 }
77 CHECK_EQ(0, performer.Close());
78 LOG(INFO) << "done applying delta.";
79 return 0;
80 }
54 if (FLAGS_old_dir.empty() || FLAGS_new_dir.empty() || 81 if (FLAGS_old_dir.empty() || FLAGS_new_dir.empty() ||
55 FLAGS_old_image.empty() || FLAGS_new_image.empty() || 82 FLAGS_old_image.empty() || FLAGS_new_image.empty() ||
56 FLAGS_out_file.empty()) { 83 FLAGS_out_file.empty()) {
57 LOG(FATAL) << "Missing required argument(s)"; 84 LOG(FATAL) << "Missing required argument(s)";
58 } 85 }
59 if ((!IsDir(FLAGS_old_dir.c_str())) || (!IsDir(FLAGS_new_dir.c_str()))) { 86 if ((!IsDir(FLAGS_old_dir.c_str())) || (!IsDir(FLAGS_new_dir.c_str()))) {
60 LOG(FATAL) << "old_dir or new_dir not directory"; 87 LOG(FATAL) << "old_dir or new_dir not directory";
61 } 88 }
62 89
63 DeltaDiffGenerator::GenerateDeltaUpdateFile(FLAGS_old_dir, 90 DeltaDiffGenerator::GenerateDeltaUpdateFile(FLAGS_old_dir,
64 FLAGS_old_image, 91 FLAGS_old_image,
65 FLAGS_new_dir, 92 FLAGS_new_dir,
66 FLAGS_new_image, 93 FLAGS_new_image,
67 FLAGS_out_file); 94 FLAGS_out_file);
68 95
69 return 0; 96 return 0;
70 } 97 }
71 98
72 } // namespace {} 99 } // namespace {}
73 100
74 } // namespace chromeos_update_engine 101 } // namespace chromeos_update_engine
75 102
76 int main(int argc, char** argv) { 103 int main(int argc, char** argv) {
77 return chromeos_update_engine::Main(argc, argv); 104 return chromeos_update_engine::Main(argc, argv);
78 } 105 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698