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

Unified Diff: delta_performer.cc

Issue 3591019: AU: Delta Performer: properly detect idempotent operations (Closed) Base URL: ssh://git@chromiumos-git/update_engine.git
Patch Set: Created 10 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « delta_performer.h ('k') | delta_performer_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: delta_performer.cc
diff --git a/delta_performer.cc b/delta_performer.cc
index 10031eb8f8d5225ee4719d6a3ad648cf275676d6..58afe53cf690f9898910c8d1ead7dfb2dc051f02 100644
--- a/delta_performer.cc
+++ b/delta_performer.cc
@@ -18,6 +18,7 @@
#include "update_engine/bzip_extent_writer.h"
#include "update_engine/delta_diff_generator.h"
+#include "update_engine/extent_ranges.h"
#include "update_engine/extent_writer.h"
#include "update_engine/graph_types.h"
#include "update_engine/payload_signer.h"
@@ -40,17 +41,6 @@ const char kUpdatePayloadPublicKeyPath[] =
"/usr/share/update_engine/update-payload-key.pub.pem";
const int kUpdateStateOperationInvalid = -1;
-// Returns true if |op| is idempotent -- i.e., if we can interrupt it and repeat
-// it safely. Returns false otherwise.
-bool IsIdempotentOperation(const DeltaArchiveManifest_InstallOperation& op) {
- if (op.src_extents_size() == 0) {
- return true;
- }
- // TODO(petkov): Cover the case where the source and target extents don't
- // intersect.
- return false;
-}
-
// Converts extents to a human-readable string, for use by DumpUpdateProto().
string ExtentsToString(const RepeatedPtrField<Extent>& extents) {
string ret;
@@ -121,6 +111,24 @@ bool OpenFile(const char* path, int* fd, int* err) {
} // namespace {}
+// Returns true if |op| is idempotent -- i.e., if we can interrupt it and repeat
+// it safely. Returns false otherwise.
+bool DeltaPerformer::IsIdempotentOperation(
+ const DeltaArchiveManifest_InstallOperation& op) {
+ if (op.src_extents_size() == 0) {
+ return true;
+ }
+ // TODO(adlr): detect other types of idempotent operations. For example,
+ // a MOVE may move a block onto itself.
+
+ // When in doubt, it's safe to declare an op non-idempotent.
+ ExtentRanges src_ranges;
+ src_ranges.AddRepeatedExtents(op.src_extents());
+ const uint64_t block_count = src_ranges.blocks();
+ src_ranges.SubtractRepeatedExtents(op.dst_extents());
+ return block_count == src_ranges.blocks();
+}
+
int DeltaPerformer::Open(const char* path, int flags, mode_t mode) {
int err;
if (OpenFile(path, &fd_, &err))
« no previous file with comments | « delta_performer.h ('k') | delta_performer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698