blob: 9e7f0606796edad379f2c0faf5a6540361a1dfc9 [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:
35 FilesystemCopierAction()
Andrew de los Reyesc7020782010-04-28 10:46:04 -070036 : src_stream_(NULL),
37 dst_stream_(NULL),
38 canceller_(NULL),
39 read_in_flight_(false),
40 buffer_valid_size_(0) {}
adlr@google.com3defe6a2009-12-04 20:57:17 +000041 typedef ActionTraits<FilesystemCopierAction>::InputObjectType
42 InputObjectType;
43 typedef ActionTraits<FilesystemCopierAction>::OutputObjectType
44 OutputObjectType;
45 void PerformAction();
46 void TerminateProcessing();
47
48 // Used for testing, so we can copy from somewhere other than root
Andrew de los Reyes4fe15d02009-12-10 19:01:36 -080049 void set_copy_source(const std::string& path) {
adlr@google.com3defe6a2009-12-04 20:57:17 +000050 copy_source_ = path;
51 }
adlr@google.com3defe6a2009-12-04 20:57:17 +000052
53 // Debugging/logging
54 static std::string StaticType() { return "FilesystemCopierAction"; }
55 std::string Type() const { return StaticType(); }
56
57 private:
Andrew de los Reyesc7020782010-04-28 10:46:04 -070058 // Callback from glib when the copy operation is done.
59 void AsyncReadyCallback(GObject *source_object, GAsyncResult *res);
60 static void StaticAsyncReadyCallback(GObject *source_object,
61 GAsyncResult *res,
62 gpointer user_data) {
63 reinterpret_cast<FilesystemCopierAction*>(user_data)->AsyncReadyCallback(
64 source_object, res);
adlr@google.com3defe6a2009-12-04 20:57:17 +000065 }
Andrew de los Reyesc7020782010-04-28 10:46:04 -070066
67 // Cleans up all the variables we use for async operations and tells
68 // the ActionProcessor we're done w/ success as passed in.
69 // was_cancelled should be true if TerminateProcessing() was called.
70 void Cleanup(bool success, bool was_cancelled);
71
72 // The path to copy from. If empty (the default), the source is from the
73 // passed in InstallPlan.
Andrew de los Reyes4fe15d02009-12-10 19:01:36 -080074 std::string copy_source_;
adlr@google.com3defe6a2009-12-04 20:57:17 +000075
Andrew de los Reyesc7020782010-04-28 10:46:04 -070076 // If non-NULL, these are GUnixInputStream objects for the opened
77 // source/destination partitions.
78 GInputStream* src_stream_;
79 GOutputStream* dst_stream_;
80
81 // If non-NULL, the cancellable object for the in-flight async call.
82 GCancellable* canceller_;
83
84 // True if we're waiting on a read to complete; false if we're
85 // waiting on a write.
86 bool read_in_flight_;
87
88 // The buffer for storing data we read/write.
89 std::vector<char> buffer_;
90
91 // Number of valid elements in buffer_.
92 std::vector<char>::size_type buffer_valid_size_;
93
adlr@google.com3defe6a2009-12-04 20:57:17 +000094 // The install plan we're passed in via the input pipe.
95 InstallPlan install_plan_;
Andrew de los Reyesc7020782010-04-28 10:46:04 -070096
adlr@google.com3defe6a2009-12-04 20:57:17 +000097 DISALLOW_COPY_AND_ASSIGN(FilesystemCopierAction);
98};
99
100} // namespace chromeos_update_engine
101
102#endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_FILESYSTEM_COPIER_ACTION_H__