blob: 2f21b2a561a756bd37496290b7ce480997ae49c6 [file] [log] [blame]
adlr@google.com3defe6a2009-12-04 20:57:17 +00001// 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 Reyes4fe15d02009-12-10 19:01:36 -08007#include <errno.h>
adlr@google.com3defe6a2009-12-04 20:57:17 +00008#include <unistd.h>
Andrew de los Reyes4fe15d02009-12-10 19:01:36 -08009#include <set>
adlr@google.com3defe6a2009-12-04 20:57:17 +000010#include <string>
Andrew de los Reyesb10320d2010-03-31 16:44:44 -070011#include <gflags/gflags.h>
adlr@google.com3defe6a2009-12-04 20:57:17 +000012#include <glib.h>
Andrew de los Reyesb10320d2010-03-31 16:44:44 -070013#include "base/command_line.h"
adlr@google.com3defe6a2009-12-04 20:57:17 +000014#include "chromeos/obsolete_logging.h"
Andrew de los Reyes4fe15d02009-12-10 19:01:36 -080015#include "update_engine/delta_diff_generator.h"
adlr@google.com3defe6a2009-12-04 20:57:17 +000016#include "update_engine/subprocess.h"
17#include "update_engine/update_metadata.pb.h"
Andrew de los Reyes4fe15d02009-12-10 19:01:36 -080018#include "update_engine/utils.h"
adlr@google.com3defe6a2009-12-04 20:57:17 +000019
Andrew de los Reyesb10320d2010-03-31 16:44:44 -070020DEFINE_string(old_dir, "",
21 "Directory where the old rootfs is loop mounted read-only");
22DEFINE_string(new_dir, "",
23 "Directory where the new rootfs is loop mounted read-only");
24DEFINE_string(old_image, "", "Path to the old rootfs");
25DEFINE_string(new_image, "", "Path to the new rootfs");
26DEFINE_string(out_file, "", "Path to output file");
27
adlr@google.com3defe6a2009-12-04 20:57:17 +000028// 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 Reyes4fe15d02009-12-10 19:01:36 -080032using std::set;
33using std::string;
34
adlr@google.com3defe6a2009-12-04 20:57:17 +000035namespace chromeos_update_engine {
36
Andrew de los Reyes4fe15d02009-12-10 19:01:36 -080037namespace {
Andrew de los Reyes4fe15d02009-12-10 19:01:36 -080038
Andrew de los Reyes4fe15d02009-12-10 19:01:36 -080039bool 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
45int Main(int argc, char** argv) {
adlr@google.com3defe6a2009-12-04 20:57:17 +000046 g_thread_init(NULL);
Andrew de los Reyesb10320d2010-03-31 16:44:44 -070047 google::ParseCommandLineFlags(&argc, &argv, true);
48 CommandLine::Init(argc, argv);
adlr@google.com3defe6a2009-12-04 20:57:17 +000049 Subprocess::Init();
Andrew de los Reyesb10320d2010-03-31 16:44:44 -070050 logging::InitLogging("delta_generator.log",
Andrew de los Reyes4fe15d02009-12-10 19:01:36 -080051 logging::LOG_ONLY_TO_SYSTEM_DEBUG_LOG,
52 logging::DONT_LOCK_LOG_FILE,
53 logging::APPEND_TO_OLD_LOG_FILE);
Andrew de los Reyesb10320d2010-03-31 16:44:44 -070054 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.com3defe6a2009-12-04 20:57:17 +000061 }
Andrew de los Reyes4fe15d02009-12-10 19:01:36 -080062
Andrew de los Reyesb10320d2010-03-31 16:44:44 -070063 DeltaDiffGenerator::GenerateDeltaUpdateFile(FLAGS_old_dir,
64 FLAGS_old_image,
65 FLAGS_new_dir,
66 FLAGS_new_image,
67 FLAGS_out_file);
Andrew de los Reyes1e338b82010-01-22 14:57:27 -080068
adlr@google.com3defe6a2009-12-04 20:57:17 +000069 return 0;
Andrew de los Reyes4fe15d02009-12-10 19:01:36 -080070}
71
72} // namespace {}
73
74} // namespace chromeos_update_engine
75
76int main(int argc, char** argv) {
77 return chromeos_update_engine::Main(argc, argv);
78}