diff --git a/eden/fs/config/CheckoutConfig.cpp b/eden/fs/config/CheckoutConfig.cpp index fa1c4f4653..e71ea1ebf7 100644 --- a/eden/fs/config/CheckoutConfig.cpp +++ b/eden/fs/config/CheckoutConfig.cpp @@ -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(); diff --git a/eden/fs/config/test/CheckoutConfigTest.cpp b/eden/fs/config/test/CheckoutConfigTest.cpp index e86027ff51..5f6947ca36 100644 --- a/eden/fs/config/test/CheckoutConfigTest.cpp +++ b/eden/fs/config/test/CheckoutConfigTest.cpp @@ -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("ede", "incorrect data size for Hash"); - testBadSnapshot( + 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"); } diff --git a/eden/fs/testharness/TestMount.cpp b/eden/fs/testharness/TestMount.cpp index a0d9bbc4e9..a0a1ad2cd7 100644 --- a/eden/fs/testharness/TestMount.cpp +++ b/eden/fs/testharness/TestMount.cpp @@ -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) {