Merge pull request #6722 from sfc-gh-satherton/fix-backup-backward-compatibility

Fixed Codec<Reference<IBackupContainer>> backward compatibility bug from #6705
This commit is contained in:
Xiaoxi Wang 2022-03-30 08:38:48 -07:00 committed by GitHub
commit e2c66de28f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -727,30 +727,36 @@ template <>
inline Tuple Codec<Reference<IBackupContainer>>::pack(Reference<IBackupContainer> const& bc) {
Tuple tuple;
tuple.append(StringRef(bc->getURL()));
if (bc->getProxy().present()) {
tuple.append(StringRef(bc->getProxy().get()));
} else {
tuple.append(StringRef());
}
if (bc->getEncryptionKeyFileName().present()) {
tuple.append(bc->getEncryptionKeyFileName().get());
} else {
tuple.append(StringRef());
}
if (bc->getProxy().present()) {
tuple.append(StringRef(bc->getProxy().get()));
} else {
tuple.append(StringRef());
}
return tuple;
}
template <>
inline Reference<IBackupContainer> Codec<Reference<IBackupContainer>>::unpack(Tuple const& val) {
ASSERT(val.size() == 3);
ASSERT(val.size() >= 1);
auto url = val.getString(0).toString();
Optional<std::string> proxy;
if (!val.getString(1).empty()) {
proxy = val.getString(1).toString();
}
Optional<std::string> encryptionKeyFileName;
if (!val.getString(2).empty()) {
encryptionKeyFileName = val.getString(2).toString();
if (val.size() > 1 && !val.getString(1).empty()) {
encryptionKeyFileName = val.getString(1).toString();
}
Optional<std::string> proxy;
if (val.size() > 2 && !val.getString(2).empty()) {
proxy = val.getString(2).toString();
}
return IBackupContainer::openContainer(url, proxy, encryptionKeyFileName);
}