"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.RepoCacheLocal = void 0;
const tslib_1 = require("tslib");
const upath_1 = tslib_1.__importDefault(require("upath"));
const logger_1 = require("../../../../logger");
const fs_1 = require("../../../fs");
const base_1 = require("./base");
class RepoCacheLocal extends base_1.RepoCacheBase {
    constructor(repository, fingerprint) {
        super(repository, fingerprint);
    }
    async read() {
        const cacheFileName = this.getCacheFileName();
        try {
            // suppress debug logs with errros
            if (!(await (0, fs_1.cachePathExists)(cacheFileName))) {
                return null;
            }
            return await (0, fs_1.readCacheFile)(cacheFileName, 'utf8');
        }
        catch (err) {
            logger_1.logger.debug({ err, cacheFileName }, 'Repository local cache not found');
        }
        return null;
    }
    async write(data) {
        const cacheFileName = this.getCacheFileName();
        await (0, fs_1.outputCacheFile)(cacheFileName, JSON.stringify(data));
    }
    getCacheFileName() {
        const repoCachePath = 'renovate/repository/';
        const platform = this.platform;
        const fileName = `${this.repository}.json`;
        return upath_1.default.join(repoCachePath, platform, fileName);
    }
}
exports.RepoCacheLocal = RepoCacheLocal;
//# sourceMappingURL=local.js.map