|
| 1 | +//===----------------------------------------------------------------------===// |
| 2 | +// |
| 3 | +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | +// See https://llvm.org/LICENSE.txt for license information. |
| 5 | +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | +// |
| 7 | +//===----------------------------------------------------------------------===// |
| 8 | + |
| 9 | +#ifndef LLVM_CAS_BUILTINUNIFIEDCASDATABASES_H |
| 10 | +#define LLVM_CAS_BUILTINUNIFIEDCASDATABASES_H |
| 11 | + |
| 12 | +#include "llvm/Support/Error.h" |
| 13 | + |
| 14 | +namespace llvm::cas { |
| 15 | + |
| 16 | +class ActionCache; |
| 17 | +class ObjectStore; |
| 18 | + |
| 19 | +/// Create on-disk \c ObjectStore and \c ActionCache instances based on |
| 20 | +/// \c ondisk::UnifiedOnDiskCache, with built-in hashing. |
| 21 | +Expected<std::pair<std::unique_ptr<ObjectStore>, std::unique_ptr<ActionCache>>> |
| 22 | +createOnDiskUnifiedCASDatabases(StringRef Path); |
| 23 | + |
| 24 | +/// Represents the result of validating the contents using |
| 25 | +/// \c validateOnDiskUnifiedCASDatabasesIfNeeded. |
| 26 | +/// |
| 27 | +/// Note: invalid results are handled as an \c Error. |
| 28 | +enum class ValidationResult { |
| 29 | + /// The data is already valid. |
| 30 | + Valid, |
| 31 | + /// The data was invalid, but was recovered. |
| 32 | + Recovered, |
| 33 | + /// Validation was skipped, as it was not needed. |
| 34 | + Skipped, |
| 35 | +}; |
| 36 | + |
| 37 | +/// Validate the data in \p Path, if needed to ensure correctness. |
| 38 | +/// |
| 39 | +/// \param Path directory for the on-disk database. |
| 40 | +/// \param CheckHash Whether to validate hashes match the data. |
| 41 | +/// \param AllowRecovery Whether to automatically recover from invalid data by |
| 42 | +/// marking the files for garbage collection. |
| 43 | +/// \param ForceValidation Whether to force validation to occur even if it |
| 44 | +/// should not be necessary. |
| 45 | +/// \param LLVMCasBinaryPath If provided, validation is performed out-of-process |
| 46 | +/// using the given \c llvm-cas executable which protects against crashes |
| 47 | +/// during validation. Otherwise validation is performed in-process. |
| 48 | +/// |
| 49 | +/// \returns \c Valid if the data is already valid, \c Recovered if data |
| 50 | +/// was invalid but has been cleared, \c Skipped if validation is not needed, |
| 51 | +/// or an \c Error if validation cannot be performed or if the data is left |
| 52 | +/// in an invalid state because \p AllowRecovery is false. |
| 53 | +Expected<ValidationResult> validateOnDiskUnifiedCASDatabasesIfNeeded( |
| 54 | + StringRef Path, bool CheckHash, bool AllowRecovery, bool ForceValidation, |
| 55 | + std::optional<StringRef> LLVMCasBinaryPath); |
| 56 | + |
| 57 | +} // namespace llvm::cas |
| 58 | + |
| 59 | +#endif // LLVM_CAS_BUILTINUNIFIEDCASDATABASES_H |
0 commit comments