2016-04-01 10:46:28 +03:00
|
|
|
// Copyright 2016-present Facebook. All Rights Reserved.
|
|
|
|
//
|
|
|
|
// checksum.c: implementation for recalculating the checksums for
|
|
|
|
// intermediate nodes in a tree.
|
2016-04-01 21:19:53 +03:00
|
|
|
//
|
|
|
|
// no-check-code
|
2016-04-01 10:46:28 +03:00
|
|
|
|
2017-05-23 21:57:32 +03:00
|
|
|
#include "sha1/sha1.h"
|
2016-04-01 10:46:28 +03:00
|
|
|
|
|
|
|
#include "node.h"
|
|
|
|
#include "tree.h"
|
|
|
|
|
2016-04-09 08:33:07 +03:00
|
|
|
static void update_checksum(node_t *node) {
|
sha1: switch to new implementation
Summary:
This diff changes our code to use the new SHA1 library. See the previous diff
for why we do this.
Test Plan:
Run related tests manually:
```
$ make local PYTHON=python2
$ rt test-remotefilelog-*.t
.........................
# Ran 25 tests, 0 skipped, 0 warned, 0 failed.
$ rt test-treemanifest*.t
........
# Ran 8 tests, 0 skipped, 0 warned, 0 failed.
$ rt test-fastmanifest*.t
.........
# Ran 9 tests, 0 skipped, 0 warned, 0 failed.
```
Reviewers: #sourcecontrol, durham
Reviewed By: durham
Subscribers: mjpieters
Differential Revision: https://phabricator.intern.facebook.com/D4945025
Signature: t1:4945025:1493154873:844e55a51ab250354fc08163e0949eed47b0a861
2017-04-26 00:53:32 +03:00
|
|
|
SHA1_CTX ctx;
|
|
|
|
SHA1DCInit(&ctx);
|
2016-04-01 10:46:28 +03:00
|
|
|
|
|
|
|
// find all the children and make sure their checksums are up-to-date.
|
2016-04-25 21:58:38 +03:00
|
|
|
for (child_num_t ix = 0; ix < node->num_children; ix++) {
|
2016-04-18 21:34:01 +03:00
|
|
|
node_t* child = get_child_by_index(node, ix);
|
2016-04-01 10:46:28 +03:00
|
|
|
if (child->checksum_valid == false) {
|
|
|
|
update_checksum(child);
|
|
|
|
}
|
|
|
|
|
sha1: switch to new implementation
Summary:
This diff changes our code to use the new SHA1 library. See the previous diff
for why we do this.
Test Plan:
Run related tests manually:
```
$ make local PYTHON=python2
$ rt test-remotefilelog-*.t
.........................
# Ran 25 tests, 0 skipped, 0 warned, 0 failed.
$ rt test-treemanifest*.t
........
# Ran 8 tests, 0 skipped, 0 warned, 0 failed.
$ rt test-fastmanifest*.t
.........
# Ran 9 tests, 0 skipped, 0 warned, 0 failed.
```
Reviewers: #sourcecontrol, durham
Reviewed By: durham
Subscribers: mjpieters
Differential Revision: https://phabricator.intern.facebook.com/D4945025
Signature: t1:4945025:1493154873:844e55a51ab250354fc08163e0949eed47b0a861
2017-04-26 00:53:32 +03:00
|
|
|
SHA1DCUpdate(&ctx, (const unsigned char*) child->name, child->name_sz);
|
|
|
|
SHA1DCUpdate(&ctx, child->checksum, child->checksum_sz);
|
|
|
|
SHA1DCUpdate(&ctx, &child->flags, 1);
|
2016-04-01 10:46:28 +03:00
|
|
|
}
|
|
|
|
|
sha1: switch to new implementation
Summary:
This diff changes our code to use the new SHA1 library. See the previous diff
for why we do this.
Test Plan:
Run related tests manually:
```
$ make local PYTHON=python2
$ rt test-remotefilelog-*.t
.........................
# Ran 25 tests, 0 skipped, 0 warned, 0 failed.
$ rt test-treemanifest*.t
........
# Ran 8 tests, 0 skipped, 0 warned, 0 failed.
$ rt test-fastmanifest*.t
.........
# Ran 9 tests, 0 skipped, 0 warned, 0 failed.
```
Reviewers: #sourcecontrol, durham
Reviewed By: durham
Subscribers: mjpieters
Differential Revision: https://phabricator.intern.facebook.com/D4945025
Signature: t1:4945025:1493154873:844e55a51ab250354fc08163e0949eed47b0a861
2017-04-26 00:53:32 +03:00
|
|
|
SHA1DCFinal(node->checksum, &ctx);
|
2016-04-01 10:46:28 +03:00
|
|
|
node->checksum_sz = SHA1_BYTES;
|
|
|
|
node->checksum_valid = true;
|
|
|
|
}
|
|
|
|
|
2016-04-09 08:33:07 +03:00
|
|
|
void update_checksums(tree_t *tree) {
|
2016-04-01 10:46:28 +03:00
|
|
|
update_checksum(tree->shadow_root);
|
|
|
|
}
|