blob: b64533b72afe4b448dedbd71e0f3ecf3d4da6404 [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>
adlr@google.com3defe6a2009-12-04 20:57:17 +000011#include <glib.h>
adlr@google.com3defe6a2009-12-04 20:57:17 +000012#include "chromeos/obsolete_logging.h"
Andrew de los Reyes4fe15d02009-12-10 19:01:36 -080013#include "update_engine/delta_diff_generator.h"
adlr@google.com3defe6a2009-12-04 20:57:17 +000014#include "update_engine/subprocess.h"
15#include "update_engine/update_metadata.pb.h"
Andrew de los Reyes4fe15d02009-12-10 19:01:36 -080016#include "update_engine/utils.h"
adlr@google.com3defe6a2009-12-04 20:57:17 +000017
18// This file contains a simple program that takes an old path, a new path,
19// and an output file as arguments and the path to an output file and
20// generates a delta that can be sent to Chrome OS clients.
21
Andrew de los Reyes4fe15d02009-12-10 19:01:36 -080022using std::set;
23using std::string;
24
adlr@google.com3defe6a2009-12-04 20:57:17 +000025namespace chromeos_update_engine {
26
Andrew de los Reyes4fe15d02009-12-10 19:01:36 -080027namespace {
28// These paths should never be delta diffed. They should always be transmitted
29// in full in the update.
30const char* kNonDiffPaths[] = {
31 "/boot/extlinux.conf"
32};
33
34void usage(const char* argv0) {
35 printf("usage: %s old_dir new_dir out_file\n", argv0);
36 exit(1);
37}
38
39bool 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);
47 Subprocess::Init();
48 if (argc != 4) {
49 usage(argv[0]);
50 }
Andrew de los Reyes4fe15d02009-12-10 19:01:36 -080051 logging::InitLogging("",
52 logging::LOG_ONLY_TO_SYSTEM_DEBUG_LOG,
53 logging::DONT_LOCK_LOG_FILE,
54 logging::APPEND_TO_OLD_LOG_FILE);
adlr@google.com3defe6a2009-12-04 20:57:17 +000055 const char* old_dir = argv[1];
56 const char* new_dir = argv[2];
57 if ((!IsDir(old_dir)) || (!IsDir(new_dir))) {
58 usage(argv[0]);
59 }
Andrew de los Reyes4fe15d02009-12-10 19:01:36 -080060
61 set<string> non_diff_paths;
62 for (size_t i = 0; i < arraysize(kNonDiffPaths); i++)
63 non_diff_paths.insert(kNonDiffPaths[i]);
64
65 DeltaArchiveManifest* manifest =
66 DeltaDiffGenerator::EncodeMetadataToProtoBuffer(new_dir);
67 CHECK(manifest);
68 CHECK(DeltaDiffGenerator::EncodeDataToDeltaFile(manifest,
69 old_dir,
70 new_dir,
71 argv[3],
72 non_diff_paths,
73 ""));
adlr@google.com3defe6a2009-12-04 20:57:17 +000074 return 0;
Andrew de los Reyes4fe15d02009-12-10 19:01:36 -080075}
76
77} // namespace {}
78
79} // namespace chromeos_update_engine
80
81int main(int argc, char** argv) {
82 return chromeos_update_engine::Main(argc, argv);
83}