adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 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> |
Andrew de los Reyes | 4fe15d0 | 2009-12-10 19:01:36 -0800 | [diff] [blame] | 7 | #include <errno.h> |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 8 | #include <unistd.h> |
Andrew de los Reyes | 4fe15d0 | 2009-12-10 19:01:36 -0800 | [diff] [blame] | 9 | #include <set> |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 10 | #include <string> |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 11 | #include <gflags/gflags.h> |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 12 | #include <glib.h> |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 13 | #include "base/command_line.h" |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 14 | #include "chromeos/obsolete_logging.h" |
Andrew de los Reyes | 4fe15d0 | 2009-12-10 19:01:36 -0800 | [diff] [blame] | 15 | #include "update_engine/delta_diff_generator.h" |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 16 | #include "update_engine/subprocess.h" |
| 17 | #include "update_engine/update_metadata.pb.h" |
Andrew de los Reyes | 4fe15d0 | 2009-12-10 19:01:36 -0800 | [diff] [blame] | 18 | #include "update_engine/utils.h" |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 19 | |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 20 | DEFINE_string(old_dir, "", |
| 21 | "Directory where the old rootfs is loop mounted read-only"); |
| 22 | DEFINE_string(new_dir, "", |
| 23 | "Directory where the new rootfs is loop mounted read-only"); |
| 24 | DEFINE_string(old_image, "", "Path to the old rootfs"); |
| 25 | DEFINE_string(new_image, "", "Path to the new rootfs"); |
| 26 | DEFINE_string(out_file, "", "Path to output file"); |
| 27 | |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 28 | // 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 |
| 30 | // generates a delta that can be sent to Chrome OS clients. |
| 31 | |
Andrew de los Reyes | 4fe15d0 | 2009-12-10 19:01:36 -0800 | [diff] [blame] | 32 | using std::set; |
| 33 | using std::string; |
| 34 | |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 35 | namespace chromeos_update_engine { |
| 36 | |
Andrew de los Reyes | 4fe15d0 | 2009-12-10 19:01:36 -0800 | [diff] [blame] | 37 | namespace { |
Andrew de los Reyes | 4fe15d0 | 2009-12-10 19:01:36 -0800 | [diff] [blame] | 38 | |
Andrew de los Reyes | 4fe15d0 | 2009-12-10 19:01:36 -0800 | [diff] [blame] | 39 | bool IsDir(const char* path) { |
| 40 | struct stat stbuf; |
| 41 | TEST_AND_RETURN_FALSE_ERRNO(lstat(path, &stbuf) == 0); |
| 42 | return S_ISDIR(stbuf.st_mode); |
| 43 | } |
| 44 | |
| 45 | int Main(int argc, char** argv) { |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 46 | g_thread_init(NULL); |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 47 | google::ParseCommandLineFlags(&argc, &argv, true); |
| 48 | CommandLine::Init(argc, argv); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 49 | Subprocess::Init(); |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 50 | logging::InitLogging("delta_generator.log", |
Andrew de los Reyes | 4fe15d0 | 2009-12-10 19:01:36 -0800 | [diff] [blame] | 51 | logging::LOG_ONLY_TO_SYSTEM_DEBUG_LOG, |
| 52 | logging::DONT_LOCK_LOG_FILE, |
| 53 | logging::APPEND_TO_OLD_LOG_FILE); |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 54 | if (FLAGS_old_dir.empty() || FLAGS_new_dir.empty() || |
| 55 | FLAGS_old_image.empty() || FLAGS_new_image.empty() || |
| 56 | FLAGS_out_file.empty()) { |
| 57 | LOG(FATAL) << "Missing required argument(s)"; |
| 58 | } |
| 59 | if ((!IsDir(FLAGS_old_dir.c_str())) || (!IsDir(FLAGS_new_dir.c_str()))) { |
| 60 | LOG(FATAL) << "old_dir or new_dir not directory"; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 61 | } |
Andrew de los Reyes | 4fe15d0 | 2009-12-10 19:01:36 -0800 | [diff] [blame] | 62 | |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 63 | DeltaDiffGenerator::GenerateDeltaUpdateFile(FLAGS_old_dir, |
| 64 | FLAGS_old_image, |
| 65 | FLAGS_new_dir, |
| 66 | FLAGS_new_image, |
| 67 | FLAGS_out_file); |
Andrew de los Reyes | 1e338b8 | 2010-01-22 14:57:27 -0800 | [diff] [blame] | 68 | |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 69 | return 0; |
Andrew de los Reyes | 4fe15d0 | 2009-12-10 19:01:36 -0800 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | } // namespace {} |
| 73 | |
| 74 | } // namespace chromeos_update_engine |
| 75 | |
| 76 | int main(int argc, char** argv) { |
| 77 | return chromeos_update_engine::Main(argc, argv); |
| 78 | } |