Andrew de los Reyes | c702078 | 2010-04-28 10:46:04 -0700 | [diff] [blame^] | 1 | // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 2 | // 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 Reyes | c702078 | 2010-04-28 10:46:04 -0700 | [diff] [blame^] | 11 | #include <vector> |
| 12 | #include <gio/gio.h> |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 13 | #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 Reyes | c702078 | 2010-04-28 10:46:04 -0700 | [diff] [blame^] | 18 | // copy the root partition to install partition, and then terminate. |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 19 | |
| 20 | namespace chromeos_update_engine { |
| 21 | |
| 22 | class FilesystemCopierAction; |
| 23 | |
| 24 | template<> |
| 25 | class 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 | |
| 33 | class FilesystemCopierAction : public Action<FilesystemCopierAction> { |
| 34 | public: |
| 35 | FilesystemCopierAction() |
Andrew de los Reyes | c702078 | 2010-04-28 10:46:04 -0700 | [diff] [blame^] | 36 | : src_stream_(NULL), |
| 37 | dst_stream_(NULL), |
| 38 | canceller_(NULL), |
| 39 | read_in_flight_(false), |
| 40 | buffer_valid_size_(0) {} |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 41 | 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 Reyes | 4fe15d0 | 2009-12-10 19:01:36 -0800 | [diff] [blame] | 49 | void set_copy_source(const std::string& path) { |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 50 | copy_source_ = path; |
| 51 | } |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 52 | |
| 53 | // Debugging/logging |
| 54 | static std::string StaticType() { return "FilesystemCopierAction"; } |
| 55 | std::string Type() const { return StaticType(); } |
| 56 | |
| 57 | private: |
Andrew de los Reyes | c702078 | 2010-04-28 10:46:04 -0700 | [diff] [blame^] | 58 | // 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.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 65 | } |
Andrew de los Reyes | c702078 | 2010-04-28 10:46:04 -0700 | [diff] [blame^] | 66 | |
| 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 Reyes | 4fe15d0 | 2009-12-10 19:01:36 -0800 | [diff] [blame] | 74 | std::string copy_source_; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 75 | |
Andrew de los Reyes | c702078 | 2010-04-28 10:46:04 -0700 | [diff] [blame^] | 76 | // 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.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 94 | // The install plan we're passed in via the input pipe. |
| 95 | InstallPlan install_plan_; |
Andrew de los Reyes | c702078 | 2010-04-28 10:46:04 -0700 | [diff] [blame^] | 96 | |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 97 | DISALLOW_COPY_AND_ASSIGN(FilesystemCopierAction); |
| 98 | }; |
| 99 | |
| 100 | } // namespace chromeos_update_engine |
| 101 | |
| 102 | #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_FILESYSTEM_COPIER_ACTION_H__ |