remove support for legacy SNAPSHOT files

Summary: The legacy format was last written in 2017, so we can remove it now.

Reviewed By: xavierd

Differential Revision: D28524663

fbshipit-source-id: 59ed437b0e5ef2e5ee3e3e9944d1049a13d64d9e
This commit is contained in:
Chad Austin 2021-05-21 10:52:13 -07:00 committed by Facebook GitHub Bot
parent df90f5626e
commit 48dcaf8cb2
3 changed files with 9 additions and 17 deletions

View File

@ -85,16 +85,6 @@ Hash CheckoutConfig::getParentCommit() const {
auto snapshotFileContents = readFile(snapshotFile).value();
StringPiece contents{snapshotFileContents};
if (!contents.startsWith(kSnapshotFileMagic)) {
// Try reading an old-style SNAPSHOT file that just contains a single
// commit ID, as an ASCII hexadecimal string.
//
// TODO: In the not-to-distant future we can remove support for this old
// format, and simply throw an exception here if the snapshot file does not
// start with the correct identifier bytes.
auto snapshotID = folly::trimWhitespace(contents);
return Hash{snapshotID};
}
if (contents.size() < kSnapshotHeaderSize) {
throw std::runtime_error(folly::sformat(
@ -103,6 +93,11 @@ Hash CheckoutConfig::getParentCommit() const {
snapshotFile));
}
if (!contents.startsWith(kSnapshotFileMagic)) {
throw std::runtime_error(
folly::sformat("unsupported legacy SNAPSHOT file"));
}
IOBuf buf(IOBuf::WRAP_BUFFER, ByteRange{contents});
folly::io::Cursor cursor(&buf);
cursor += kSnapshotFileMagic.size();

View File

@ -149,6 +149,7 @@ void CheckoutConfigTest::testBadSnapshot(
}
TEST_F(CheckoutConfigTest, testBadSnapshot) {
testBadSnapshot("ede", "SNAPSHOT file is too short");
testBadSnapshot("eden", "SNAPSHOT file is too short");
testBadSnapshot(StringPiece{"eden\0\0\0", 7}, "SNAPSHOT file is too short");
testBadSnapshot(
@ -179,8 +180,7 @@ TEST_F(CheckoutConfigTest, testBadSnapshot) {
// The error type and message for this will probably change in the future
// when we drop support for the legacy SNAPSHOT file format (of a 40-byte
// ASCII string containing the snapshot hash).
testBadSnapshot<std::invalid_argument>("ede", "incorrect data size for Hash");
testBadSnapshot<std::invalid_argument>(
testBadSnapshot(
StringPiece{
"xden\00\00\00\01"
"\x99\x88\x77\x66\x55\x44\x33\x22\x11\x00"
@ -188,5 +188,5 @@ TEST_F(CheckoutConfigTest, testBadSnapshot) {
"\xab\xcd\xef\x98\x76\x54\x32\x10\x01\x23"
"\x45\x67\x89\xab\xcd\xef\x00\x11\x22\x33",
48},
"incorrect data size for Hash");
"unsupported legacy SNAPSHOT file");
}

View File

@ -424,10 +424,7 @@ size_t TestMount::drainServerExecutor() {
void TestMount::setInitialCommit(Hash commitHash) {
// Write the commit hash to the snapshot file
auto snapshotPath = config_->getSnapshotPath();
writeFileAtomic(
snapshotPath, folly::StringPiece(commitHash.toString() + "\n"))
.value();
config_->setParentCommit(commitHash);
}
void TestMount::setInitialCommit(Hash commitHash, Hash rootTreeHash) {