"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.checkDirectoryIsEmpty = exports.checkTmpIsEmpty = void 0;
const tslib_1 = require("tslib");
const chai_1 = require("chai");
const fs_extra_1 = require("fs-extra");
function checkTmpIsEmpty(server) {
    return tslib_1.__awaiter(this, void 0, void 0, function* () {
        yield checkDirectoryIsEmpty(server, 'tmp', ['plugins-global.css', 'hls', 'resumable-uploads']);
        if (yield (0, fs_extra_1.pathExists)(server.getDirectoryPath('tmp/hls'))) {
            yield checkDirectoryIsEmpty(server, 'tmp/hls');
        }
    });
}
exports.checkTmpIsEmpty = checkTmpIsEmpty;
function checkDirectoryIsEmpty(server, directory, exceptions = []) {
    return tslib_1.__awaiter(this, void 0, void 0, function* () {
        const directoryPath = server.getDirectoryPath(directory);
        const directoryExists = yield (0, fs_extra_1.pathExists)(directoryPath);
        (0, chai_1.expect)(directoryExists).to.be.true;
        const files = yield (0, fs_extra_1.readdir)(directoryPath);
        const filtered = files.filter(f => exceptions.includes(f) === false);
        (0, chai_1.expect)(filtered).to.have.lengthOf(0);
    });
}
exports.checkDirectoryIsEmpty = checkDirectoryIsEmpty;
//# sourceMappingURL=directories.js.map