blob: 786c2ab083c3653c928e7685463cc6262343c7b6 [file] [log] [blame]
Andrew de los Reyesc7020782010-04-28 10:46:04 -07001// Copyright (c) 2010 The Chromium Authors. All rights reserved.
adlr@google.com3defe6a2009-12-04 20:57:17 +00002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_FILESYSTEM_COPIER_ACTION_H__
6#define CHROMEOS_PLATFORM_UPDATE_ENGINE_FILESYSTEM_COPIER_ACTION_H__
7
8#include <sys/stat.h>
9#include <sys/types.h>
10#include <string>
Andrew de los Reyesc7020782010-04-28 10:46:04 -070011#include <vector>
12#include <gio/gio.h>
adlr@google.com3defe6a2009-12-04 20:57:17 +000013#include <glib.h>
14#include "update_engine/action.h"
15#include "update_engine/install_plan.h"
16
17// This action will only do real work if it's a delta update. It will
Andrew de los Reyesc7020782010-04-28 10:46:04 -070018// copy the root partition to install partition, and then terminate.
adlr@google.com3defe6a2009-12-04 20:57:17 +000019
20namespace chromeos_update_engine {
21
22class FilesystemCopierAction;
23
24template<>
25class ActionTraits<FilesystemCopierAction> {
26 public:
27 // Takes the install plan as input
28 typedef InstallPlan InputObjectType;
29 // Passes the install plan as output
30 typedef InstallPlan OutputObjectType;
31};
32
33class FilesystemCopierAction : public Action<FilesystemCopierAction> {
34 public:
Andrew de los Reyesf9185172010-05-03 11:07:05 -070035 explicit FilesystemCopierAction(bool copying_kernel_install_path)
36 : copying_kernel_install_path_(copying_kernel_install_path),
37 src_stream_(NULL),
Andrew de los Reyesc7020782010-04-28 10:46:04 -070038 dst_stream_(NULL),
39 canceller_(NULL),
40 read_in_flight_(false),
41 buffer_valid_size_(0) {}
adlr@google.com3defe6a2009-12-04 20:57:17 +000042 typedef ActionTraits<FilesystemCopierAction>::InputObjectType
43 InputObjectType;
44 typedef ActionTraits<FilesystemCopierAction>::OutputObjectType
45 OutputObjectType;
46 void PerformAction();
47 void TerminateProcessing();
48
49 // Used for testing, so we can copy from somewhere other than root
Andrew de los Reyes4fe15d02009-12-10 19:01:36 -080050 void set_copy_source(const std::string& path) {
adlr@google.com3defe6a2009-12-04 20:57:17 +000051 copy_source_ = path;
52 }
adlr@google.com3defe6a2009-12-04 20:57:17 +000053
54 // Debugging/logging
55 static std::string StaticType() { return "FilesystemCopierAction"; }
56 std::string Type() const { return StaticType(); }
57
58 private:
Andrew de los Reyesc7020782010-04-28 10:46:04 -070059 // Callback from glib when the copy operation is done.
60 void AsyncReadyCallback(GObject *source_object, GAsyncResult *res);
61 static void StaticAsyncReadyCallback(GObject *source_object,
62 GAsyncResult *res,
63 gpointer user_data) {
64 reinterpret_cast<FilesystemCopierAction*>(user_data)->AsyncReadyCallback(
65 source_object, res);
adlr@google.com3defe6a2009-12-04 20:57:17 +000066 }
Andrew de los Reyesc7020782010-04-28 10:46:04 -070067
68 // Cleans up all the variables we use for async operations and tells
69 // the ActionProcessor we're done w/ success as passed in.
70 // was_cancelled should be true if TerminateProcessing() was called.
71 void Cleanup(bool success, bool was_cancelled);
72
Andrew de los Reyesf9185172010-05-03 11:07:05 -070073 // If true, this action is copying to the kernel_install_path from
74 // the install plan, otherwise it's copying just to the install_path.
75 const bool copying_kernel_install_path_;
76
Andrew de los Reyesc7020782010-04-28 10:46:04 -070077 // The path to copy from. If empty (the default), the source is from the
78 // passed in InstallPlan.
Andrew de los Reyes4fe15d02009-12-10 19:01:36 -080079 std::string copy_source_;
adlr@google.com3defe6a2009-12-04 20:57:17 +000080
Andrew de los Reyesc7020782010-04-28 10:46:04 -070081 // If non-NULL, these are GUnixInputStream objects for the opened
82 // source/destination partitions.
83 GInputStream* src_stream_;
84 GOutputStream* dst_stream_;
85
86 // If non-NULL, the cancellable object for the in-flight async call.
87 GCancellable* canceller_;
88
89 // True if we're waiting on a read to complete; false if we're
90 // waiting on a write.
91 bool read_in_flight_;
92
93 // The buffer for storing data we read/write.
94 std::vector<char> buffer_;
95
96 // Number of valid elements in buffer_.
97 std::vector<char>::size_type buffer_valid_size_;
98
adlr@google.com3defe6a2009-12-04 20:57:17 +000099 // The install plan we're passed in via the input pipe.
100 InstallPlan install_plan_;
Andrew de los Reyesc7020782010-04-28 10:46:04 -0700101
adlr@google.com3defe6a2009-12-04 20:57:17 +0000102 DISALLOW_COPY_AND_ASSIGN(FilesystemCopierAction);
103};
104
105} // namespace chromeos_update_engine
106
107#endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_FILESYSTEM_COPIER_ACTION_H__