| | |
| | | * @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; |
| | |
| | | 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(); |
| | |
| | | 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; |
| | |
| | | } |
| | | |
| | | 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()) { |
| | |
| | | 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) { |
| | |
| | | } |
| | | |
| | | public List<BorgFilesystemItem> getArchiveContent(File file) { |
| | | return archiveFilelistCache.load(file); |
| | | return archiveFilelistCache.load(file, -1); |
| | | } |
| | | |
| | | public void shutdown() { |
| | |
| | | package de.micromata.borgbutler.json.borg; |
| | | |
| | | import lombok.Getter; |
| | | import lombok.Setter; |
| | | |
| | | import java.io.Serializable; |
| | | |
| | |
| | | @Getter |
| | | private String flags; |
| | | @Getter |
| | | @Setter |
| | | private String mtime; |
| | | @Getter |
| | | private long size; |
| | |
| | | import java.text.DateFormat; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.TimeZone; |
| | | |
| | | public class Main { |
| | |
| | | |
| | | 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); |
| | |
| | | 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; |
| | | |
| | |
| | | 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 { |
| | |
| | | @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, |
| | | public String getArchiveFileLIst(@QueryParam("archiveId") String archiveId, |
| | | @QueryParam("maxResultSize") Integer maxResultSize, |
| | | @QueryParam("force") boolean force, |
| | | @QueryParam("prettyPrinter") boolean prettyPrinter) { |
| | | Archive archive = ButlerCache.getInstance().getArchive(repoName, archiveIdOrName, force); |
| | | return JsonUtils.toJson(archive, prettyPrinter); |
| | | int maxSize = maxResultSize != null ? maxResultSize : 50; |
| | | List<BorgFilesystemItem> items = ButlerCache.getInstance().getArchiveContent(archiveId, maxSize); |
| | | if (items == null) { |
| | | return ""; |
| | | } |
| | | return JsonUtils.toJson(items, prettyPrinter); |
| | | } |
| | | } |
| | |
| | | <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> |
| | |
| | | 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> |
| | | ); |
| | |
| | | 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 = () => { |
| | |
| | | failed: false |
| | | }); |
| | | fetch(getRestServiceUrl('archives/filelist', { |
| | | archive: this.props.archiveId, |
| | | archiveId: this.props.archiveId, |
| | | force: forceReload |
| | | }), { |
| | | method: 'GET', |
| | |
| | | .then(json => { |
| | | this.setState({ |
| | | isFetching: false, |
| | | archive: json |
| | | fileList: json |
| | | }) |
| | | }) |
| | | .catch(() => this.setState({isFetching: false, failed: true})); |
| | |
| | | |
| | | render = () => { |
| | | let content = undefined; |
| | | let archive = this.state.archive; |
| | | |
| | | if (this.state.isFetching) { |
| | | content = <i>Loading...</i>; |
| | |
| | | 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> |
| | |
| | | <thead> |
| | | <tr> |
| | | <th>Mode</th> |
| | | <th style={{whiteSpace: 'nowrap'}}> |
| | | Date |
| | | </th> |
| | | <th>Date</th> |
| | | <th>Size</th> |
| | | <th>Path</th> |
| | | </tr> |
| | | </thead> |