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

Kai Reinhard
16.25.2018 056160edd629372ff93619be7e130a26e2377f9b
file lists...
9 files modified
93 ■■■■ changed files
borgbutler-core/src/main/java/de/micromata/borgbutler/cache/ArchiveFilelistCache.java 9 ●●●●● patch | view | raw | blame | history
borgbutler-core/src/main/java/de/micromata/borgbutler/cache/ButlerCache.java 33 ●●●●● patch | view | raw | blame | history
borgbutler-core/src/main/java/de/micromata/borgbutler/json/borg/BorgFilesystemItem.java 2 ●●●●● patch | view | raw | blame | history
borgbutler-server/src/main/java/de/micromata/borgbutler/server/Main.java 5 ●●●●● patch | view | raw | blame | history
borgbutler-server/src/main/java/de/micromata/borgbutler/server/rest/ArchivesRest.java 21 ●●●●● patch | view | raw | blame | history
borgbutler-webapp/src/components/views/archives/ArchiveView.jsx 2 ●●● patch | view | raw | blame | history
borgbutler-webapp/src/components/views/archives/FileListEntry.jsx 2 ●●●●● patch | view | raw | blame | history
borgbutler-webapp/src/components/views/archives/FileListPanel.jsx 14 ●●●●● patch | view | raw | blame | history
borgbutler-webapp/src/components/views/archives/FileListTable.jsx 5 ●●●●● patch | view | raw | blame | history
borgbutler-core/src/main/java/de/micromata/borgbutler/cache/ArchiveFilelistCache.java
@@ -58,15 +58,15 @@
     * @param archive
     * @return
     */
    public List<BorgFilesystemItem> load(BorgRepoConfig repoConfig, Archive archive) {
    public List<BorgFilesystemItem> load(BorgRepoConfig repoConfig, Archive archive, int maxSize) {
        File file = getFile(repoConfig, archive);
        if (!file.exists()) {
            return null;
        }
        return load(file);
        return load(file, maxSize);
    }
    public List<BorgFilesystemItem> load(File file) {
    public List<BorgFilesystemItem> load(File file, int maxSize) {
        if (file.exists() == false) {
            log.error("File '" + file.getAbsolutePath() + "' doesn't exist. Can't get archive content files.");
            return null;
@@ -86,6 +86,9 @@
                return null;
            }
            int size = (Integer) obj;
            if (maxSize > 0 && maxSize < size) {
                size = maxSize;
            }
            list = new ArrayList<>();
            for (int i = 0; i < size; i++) {
                obj = inputStream.readObject();
borgbutler-core/src/main/java/de/micromata/borgbutler/cache/ButlerCache.java
@@ -7,6 +7,7 @@
import de.micromata.borgbutler.data.Archive;
import de.micromata.borgbutler.data.Repository;
import de.micromata.borgbutler.json.borg.BorgFilesystemItem;
import de.micromata.borgbutler.utils.DateUtils;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.jcs.JCS;
import org.apache.commons.jcs.access.CacheAccess;
@@ -180,6 +181,10 @@
    }
    public List<BorgFilesystemItem> getArchiveContent(String archiveId) {
        return getArchiveContent(archiveId, -1);
    }
    public List<BorgFilesystemItem> getArchiveContent(String archiveId, int maxSize) {
        Archive archive = null;
        outerLoop:
        for (Repository repository : getAllRepositories()) {
@@ -197,19 +202,41 @@
            return null;
        }
        BorgRepoConfig repoConfig = ConfigurationHandler.getConfiguration().getRepoConfig(archive.getRepoId());
        return getArchiveContent(repoConfig, archive);
        return getArchiveContent(repoConfig, archive, maxSize);
    }
    /**
     *
     * @param repoConfig
     * @param archive
     * @return
     */
    public List<BorgFilesystemItem> getArchiveContent(BorgRepoConfig repoConfig, Archive archive) {
        return getArchiveContent(repoConfig, archive, -1);
    }
    /**
     *
     * @param repoConfig
     * @param archive
     * @param maxSize Max result size (default is -1 meaning all).
     * @return
     */
    public List<BorgFilesystemItem> getArchiveContent(BorgRepoConfig repoConfig, Archive archive, int maxSize) {
        if (archive == null || StringUtils.isBlank(archive.getName())) {
            return null;
        }
        List<BorgFilesystemItem> items = archiveFilelistCache.load(repoConfig, archive);
        List<BorgFilesystemItem> items = archiveFilelistCache.load(repoConfig, archive, maxSize);
        if (items == null) {
            List<BorgFilesystemItem> list = BorgCommands.listArchiveContent(repoConfig, archive.getName());
            if (CollectionUtils.isNotEmpty(list)) {
                archiveFilelistCache.save(repoConfig, archive, list);
                items = new ArrayList<>();
                int i = 0;
                for (BorgFilesystemItem item : list) {
                    if (++i > maxSize) break;
                    items.add(item);
                }
            }
        }
        if (items == null) {
@@ -219,7 +246,7 @@
    }
    public List<BorgFilesystemItem> getArchiveContent(File file) {
        return archiveFilelistCache.load(file);
        return archiveFilelistCache.load(file, -1);
    }
    public void shutdown() {
borgbutler-core/src/main/java/de/micromata/borgbutler/json/borg/BorgFilesystemItem.java
@@ -1,6 +1,7 @@
package de.micromata.borgbutler.json.borg;
import lombok.Getter;
import lombok.Setter;
import java.io.Serializable;
@@ -35,6 +36,7 @@
    @Getter
    private String flags;
    @Getter
    @Setter
    private String mtime;
    @Getter
    private long size;
borgbutler-server/src/main/java/de/micromata/borgbutler/server/Main.java
@@ -17,6 +17,7 @@
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.TimeZone;
public class Main {
@@ -132,9 +133,9 @@
    private static void printArchiveContent(String fileName) {
        File file = new File(fileName);
        BorgFilesystemItem[] fileList = ButlerCache.getInstance().getArchiveContent(file);
        List<BorgFilesystemItem> fileList = ButlerCache.getInstance().getArchiveContent(file);
        boolean parseFormatExceptionPrinted = false;
        if (fileList != null && fileList.length > 0) {
        if (fileList != null && fileList.size() > 0) {
            TimeZone tz = TimeZone.getTimeZone("UTC");
            DateFormat iso = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss'Z'"); // Quoted "Z" to indicate UTC, no timezone offset
            iso.setTimeZone(tz);
borgbutler-server/src/main/java/de/micromata/borgbutler/server/rest/ArchivesRest.java
@@ -4,6 +4,7 @@
import de.micromata.borgbutler.data.Archive;
import de.micromata.borgbutler.data.Repository;
import de.micromata.borgbutler.json.JsonUtils;
import de.micromata.borgbutler.json.borg.BorgFilesystemItem;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -12,6 +13,7 @@
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import java.util.List;
@Path("/archives")
public class ArchivesRest {
@@ -39,16 +41,21 @@
    @Produces(MediaType.APPLICATION_JSON)
    /**
     *
     * @param repo Name of repository ({@link Repository#getName()}.
     * @param archive Id or name of archive.
     * @param archiveId Id or name of archive.
     * @param maxResultSize maximum number of file items to return (default is 50).
     * @param prettyPrinter If true then the json output will be in pretty format.
     * @return Repository (including list of archives) as json string.
     * @see JsonUtils#toJson(Object, boolean)
     */
    public String getArchiveFileLIst(@QueryParam("repo") String repoName,
                             @QueryParam("archive") String archiveIdOrName, @QueryParam("force") boolean force,
                             @QueryParam("prettyPrinter") boolean prettyPrinter) {
        Archive archive = ButlerCache.getInstance().getArchive(repoName, archiveIdOrName, force);
        return JsonUtils.toJson(archive, prettyPrinter);
    public String getArchiveFileLIst(@QueryParam("archiveId") String archiveId,
                                     @QueryParam("maxResultSize") Integer maxResultSize,
                                     @QueryParam("force") boolean force,
                                     @QueryParam("prettyPrinter") boolean prettyPrinter) {
        int maxSize = maxResultSize != null ? maxResultSize : 50;
        List<BorgFilesystemItem> items = ButlerCache.getInstance().getArchiveContent(archiveId, maxSize);
        if (items == null) {
            return "";
        }
        return JsonUtils.toJson(items, prettyPrinter);
    }
}
borgbutler-webapp/src/components/views/archives/ArchiveView.jsx
@@ -131,7 +131,7 @@
                                            <td>{humanFileSize(archive.stats.original_size)}</td>
                                        </tr>
                                        <tr>
                                            <td>Nfiles</td>
                                            <td>Number of files</td>
                                            <td>{Number(archive.stats.nfiles).toLocaleString()}</td>
                                        </tr>
                                        </tbody>
borgbutler-webapp/src/components/views/archives/FileListEntry.jsx
@@ -6,6 +6,8 @@
    return (
        <tr>
            <td className={'tt'}>{entry.mode}</td>
            <td className={'tt'}>{entry.mtime}</td>
            <td className={'tt'}>{entry.size}</td>
            <td className={'tt'}><Highlight search={search}>{entry.path}</Highlight></td>
        </tr>
    );
borgbutler-webapp/src/components/views/archives/FileListPanel.jsx
@@ -1,11 +1,13 @@
import React from 'react'
import {getRestServiceUrl, humanFileSize} from '../../../utilities/global';
import {getRestServiceUrl} from '../../../utilities/global';
import ErrorAlert from '../../general/ErrorAlert';
import FileListTable from "./FileListTable";
class ArchiveView extends React.Component {
    state = {
        isFetching: false, activeTab: '1',
        fileList : undefined
    };
    componentDidMount = () => {
@@ -23,7 +25,7 @@
            failed: false
        });
        fetch(getRestServiceUrl('archives/filelist', {
            archive: this.props.archiveId,
            archiveId: this.props.archiveId,
            force: forceReload
        }), {
            method: 'GET',
@@ -35,7 +37,7 @@
            .then(json => {
                this.setState({
                    isFetching: false,
                    archive: json
                    fileList: json
                })
            })
            .catch(() => this.setState({isFetching: false, failed: true}));
@@ -43,7 +45,6 @@
    render = () => {
        let content = undefined;
        let archive = this.state.archive;
        if (this.state.isFetching) {
            content = <i>Loading...</i>;
@@ -56,9 +57,10 @@
                    title: 'Try again'
                }}
            />;
        } else if (this.state.archive) {
        } else if (this.state.fileList) {
            content = <React.Fragment>
                Hurzel;
                <FileListTable
                entries={this.state.fileList}/>
            </React.Fragment>;
        }
        return <React.Fragment>
borgbutler-webapp/src/components/views/archives/FileListTable.jsx
@@ -10,9 +10,8 @@
            <thead>
            <tr>
                <th>Mode</th>
                <th style={{whiteSpace: 'nowrap'}}>
                    Date
                </th>
                <th>Date</th>
                <th>Size</th>
                <th>Path</th>
            </tr>
            </thead>