mirror of https://github.com/micromata/borgbackup-butler.git

Kai Reinhard
08.03.2019 26f572a3cbdde9855563b5b6ca575e95bc6cb57d
Deletes now single cache files on demand.
4 files modified
80 ■■■■ changed files
borgbutler-core/src/main/java/de/micromata/borgbutler/cache/ArchiveFilelistCache.java 10 ●●●●● patch | view | raw | blame | history
borgbutler-core/src/main/java/de/micromata/borgbutler/cache/ButlerCache.java 18 ●●●● patch | view | raw | blame | history
borgbutler-server/src/main/java/de/micromata/borgbutler/server/rest/ArchivesRest.java 3 ●●●●● patch | view | raw | blame | history
borgbutler-webapp/src/components/views/archives/ArchiveView.jsx 49 ●●●●● patch | view | raw | blame | history
borgbutler-core/src/main/java/de/micromata/borgbutler/cache/ArchiveFilelistCache.java
@@ -256,6 +256,16 @@
        }
    }
    public void deleteCachFile(Repository repository, Archive archive) {
        File file = getFile(repository, archive);
        if (file.exists()) {
            log.info("Deleting cache file: " + file.getAbsolutePath());
            file.delete();
        } else {
            log.info("Can't delete requested file because it doesn't exist (anymore): " + file.getAbsolutePath());
        }
    }
    File getFile(Repository repository, Archive archive) {
        return getFile(repository.getName(), archive);
    }
borgbutler-core/src/main/java/de/micromata/borgbutler/cache/ButlerCache.java
@@ -195,10 +195,6 @@
        return archive;
    }
    public List<BorgFilesystemItem> getArchiveContent(String archiveId) {
        return getArchiveContent(archiveId, true, null);
    }
    public Archive getArchive(String archiveId) {
        for (Repository repository : getAllRepositories()) {
            if (repository.getArchives() != null) {
@@ -304,6 +300,20 @@
        return archiveFilelistCache.load(file, null);
    }
    public void deleteCachedArchiveContent(String repoIdOrName, String archiveIdOrName) {
        Repository repository = getRepository(repoIdOrName);
        if (repository == null) {
            log.warn("Can't delete archive content cache file, repository not found: " + repoIdOrName);
            return;
        }
        Archive archive = getArchive(repoIdOrName, archiveIdOrName);
        if (archive == null) {
            log.warn("Can't delete archive content cache file, archive not found: " + repoIdOrName);
            return;
        }
        archiveFilelistCache.deleteCachFile(repository, archive);
    }
    public void shutdown() {
        JCS.shutdown();
    }
borgbutler-server/src/main/java/de/micromata/borgbutler/server/rest/ArchivesRest.java
@@ -47,6 +47,9 @@
                             @QueryParam("archiveId") String archiveId, @QueryParam("force") boolean force,
                             @QueryParam("prettyPrinter") boolean prettyPrinter) {
        Archive archive = ButlerCache.getInstance().getArchive(repoName, archiveId, force);
        if (force) {
            ButlerCache.getInstance().deleteCachedArchiveContent(repoName, archiveId);
        }
        return JsonUtils.toJson(archive, prettyPrinter);
    }
borgbutler-webapp/src/components/views/archives/ArchiveView.jsx
@@ -1,5 +1,5 @@
import React from 'react'
import {CardBody, Nav, NavLink, TabContent, Table, TabPane} from 'reactstrap';
import {Nav, NavLink, TabContent, Table, TabPane} from 'reactstrap';
import {PageHeader} from '../../general/BootstrapComponents';
import {getRestServiceUrl, humanFileSize, humanSeconds} from '../../../utilities/global';
import ErrorAlert from '../../general/ErrorAlert';
@@ -7,26 +7,17 @@
import classNames from 'classnames';
import FileListPanel from './FileListPanel';
import JobMonitorPanel from '../jobs/JobMonitorPanel';
import {Link} from "react-router-dom";
import ConfirmModal from '../../general/modal/ConfirmModal';
class ArchiveView extends React.Component {
    state = {
        repoId: this.props.match.params.repoId,
        archiveId: this.props.match.params.archiveId,
        isFetching: false,
        activeTab: '1'
    };
    componentDidMount = () => {
        this.fetchArchive();
    };
    fetchArchive = (force) => {
        let forceReload = false;
        if (force && window.confirm('Are you sure you want to reload the archive info? This may take some time...')) {
            forceReload = true;
        }
        this.setState({
            isFetching: true,
            failed: false
@@ -34,7 +25,7 @@
        fetch(getRestServiceUrl('archives', {
            repo: this.state.repoId,
            archiveId: this.state.archiveId,
            force: forceReload
            force: force
        }), {
            method: 'GET',
            headers: {
@@ -57,13 +48,19 @@
        })
    };
    toggleModal() {
        this.setState({
            confirmModal: !this.state.confirmModal
        })
    }
    render = () => {
        let content = undefined;
        let archive = this.state.archive;
        let pageHeader = '';
        if (this.state.isFetching) {
            content = <JobMonitorPanel repo={this.state.repoId} />;
            content = <JobMonitorPanel repo={this.state.repoId}/>;
        } else if (this.state.failed) {
            content = <ErrorAlert
                title={'Cannot load Repositories'}
@@ -75,10 +72,10 @@
            />;
        } else if (this.state.archive) {
            pageHeader = <React.Fragment>
                {archive.repoDisplayName}
                <Link to={`/repoArchives/${this.state.repoId}`}> {archive.repoDisplayName}</Link> - {archive.name}
                <div
                    className={'btn btn-outline-primary refresh-button-right'}
                    onClick={this.fetchArchive.bind(this, true)}
                    onClick={this.toggleModal}
                >
                    <IconRefresh/>
                </div>
@@ -183,6 +180,16 @@
                        </Table>
                    </TabPane>
                </TabContent>
                <ConfirmModal
                    onConfirm={() => this.fetchArchive(true)}
                    title={'Are you sure?'}
                    toggle={this.toggleModal}
                    open={this.state.confirmModal}
                >
                    Are you sure you want to reload the archive info and the file system list (if already cached)?
                    <br/>
                    This is a safe option but it may take some time to re-fill the caches (on demand) again.
                </ConfirmModal>
            </React.Fragment>;
        }
@@ -197,7 +204,17 @@
    constructor(props) {
        super(props);
        this.state = {
            repoId: this.props.match.params.repoId,
            archiveId: this.props.match.params.archiveId,
            isFetching: false,
            activeTab: '1',
            confirmModal: false
        };
        this.fetchArchive = this.fetchArchive.bind(this);
        this.toggleModal = this.toggleModal.bind(this);
    }
}