Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(16)

Side by Side Diff: filesystem_copier_action.cc

Issue 3022008: For actions, switch bool success into an exit code. (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/update_engine.git
Patch Set: switch to all positive error codes. Created 10 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « download_action_unittest.cc ('k') | filesystem_copier_action_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "update_engine/filesystem_copier_action.h" 5 #include "update_engine/filesystem_copier_action.h"
6 #include <sys/stat.h> 6 #include <sys/stat.h>
7 #include <sys/types.h> 7 #include <sys/types.h>
8 #include <errno.h> 8 #include <errno.h>
9 #include <fcntl.h> 9 #include <fcntl.h>
10 #include <stdlib.h> 10 #include <stdlib.h>
(...skipping 27 matching lines...) Expand all
38 if (!HasInputObject()) { 38 if (!HasInputObject()) {
39 LOG(ERROR) << "FilesystemCopierAction missing input object."; 39 LOG(ERROR) << "FilesystemCopierAction missing input object.";
40 return; 40 return;
41 } 41 }
42 install_plan_ = GetInputObject(); 42 install_plan_ = GetInputObject();
43 43
44 if (install_plan_.is_full_update) { 44 if (install_plan_.is_full_update) {
45 // No copy needed. Done! 45 // No copy needed. Done!
46 if (HasOutputPipe()) 46 if (HasOutputPipe())
47 SetOutputObject(install_plan_); 47 SetOutputObject(install_plan_);
48 abort_action_completer.set_success(true); 48 abort_action_completer.set_code(kActionCodeSuccess);
49 return; 49 return;
50 } 50 }
51 51
52 string source = copy_source_; 52 string source = copy_source_;
53 if (source.empty()) { 53 if (source.empty()) {
54 source = copying_kernel_install_path_ ? 54 source = copying_kernel_install_path_ ?
55 utils::BootKernelDevice(utils::BootDevice()) : 55 utils::BootKernelDevice(utils::BootDevice()) :
56 utils::BootDevice(); 56 utils::BootDevice();
57 } 57 }
58 58
59 const string destination = copying_kernel_install_path_ ? 59 const string destination = copying_kernel_install_path_ ?
60 install_plan_.kernel_install_path : 60 install_plan_.kernel_install_path :
61 install_plan_.install_path; 61 install_plan_.install_path;
62 62
63 int src_fd = open(source.c_str(), O_RDONLY); 63 int src_fd = open(source.c_str(), O_RDONLY);
64 if (src_fd < 0) { 64 if (src_fd < 0) {
65 PLOG(ERROR) << "Unable to open " << source << " for reading:"; 65 PLOG(ERROR) << "Unable to open " << source << " for reading:";
66 return; 66 return;
67 } 67 }
68 int dst_fd = open(destination.c_str(), 68 int dst_fd = open(destination.c_str(),
69 O_WRONLY | O_TRUNC | O_CREAT, 69 O_WRONLY | O_TRUNC | O_CREAT,
70 0644); 70 0644);
71 if (dst_fd < 0) { 71 if (dst_fd < 0) {
72 close(src_fd); 72 close(src_fd);
(...skipping 30 matching lines...) Expand all
103 103
104 void FilesystemCopierAction::Cleanup(bool success, bool was_cancelled) { 104 void FilesystemCopierAction::Cleanup(bool success, bool was_cancelled) {
105 g_object_unref(src_stream_); 105 g_object_unref(src_stream_);
106 src_stream_ = NULL; 106 src_stream_ = NULL;
107 g_object_unref(dst_stream_); 107 g_object_unref(dst_stream_);
108 dst_stream_ = NULL; 108 dst_stream_ = NULL;
109 if (was_cancelled) 109 if (was_cancelled)
110 return; 110 return;
111 if (success && HasOutputPipe()) 111 if (success && HasOutputPipe())
112 SetOutputObject(install_plan_); 112 SetOutputObject(install_plan_);
113 processor_->ActionComplete(this, success); 113 processor_->ActionComplete(
114 this,
115 success ? kActionCodeSuccess : kActionCodeError);
114 } 116 }
115 117
116 void FilesystemCopierAction::AsyncReadyCallback(GObject *source_object, 118 void FilesystemCopierAction::AsyncReadyCallback(GObject *source_object,
117 GAsyncResult *res) { 119 GAsyncResult *res) {
118 GError* error = NULL; 120 GError* error = NULL;
119 CHECK(canceller_); 121 CHECK(canceller_);
120 bool was_cancelled = g_cancellable_is_cancelled(canceller_) == TRUE; 122 bool was_cancelled = g_cancellable_is_cancelled(canceller_) == TRUE;
121 g_object_unref(canceller_); 123 g_object_unref(canceller_);
122 canceller_ = NULL; 124 canceller_ = NULL;
123 125
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 src_stream_, 172 src_stream_,
171 &buffer_[0], 173 &buffer_[0],
172 buffer_.size(), 174 buffer_.size(),
173 G_PRIORITY_DEFAULT, 175 G_PRIORITY_DEFAULT,
174 canceller_, 176 canceller_,
175 &FilesystemCopierAction::StaticAsyncReadyCallback, 177 &FilesystemCopierAction::StaticAsyncReadyCallback,
176 this); 178 this);
177 } 179 }
178 180
179 } // namespace chromeos_update_engine 181 } // namespace chromeos_update_engine
OLDNEW
« no previous file with comments | « download_action_unittest.cc ('k') | filesystem_copier_action_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698