| | |
| | | import de.micromata.borgbutler.data.Archive; |
| | | import de.micromata.borgbutler.data.FileSystemFilter; |
| | | import de.micromata.borgbutler.data.Repository; |
| | | import de.micromata.borgbutler.json.borg.BorgFilesystemItem; |
| | | import de.micromata.borgbutler.utils.ReplaceUtils; |
| | | import lombok.Getter; |
| | | import org.apache.commons.collections4.CollectionUtils; |
| | | import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream; |
| | | import org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream; |
| | |
| | | private int cacheArchiveContentMaxDiscSizeMB; |
| | | private long FILES_EXPIRE_TIME = 7 * 24 * 3660 * 1000; // Expires after 7 days. |
| | | |
| | | public void save(BorgRepoConfig repoConfig, Archive archive, List<BorgFilesystemItem> filesystemItems) { |
| | | public void save(BorgRepoConfig repoConfig, Archive archive, List<FilesystemItem> filesystemItems) { |
| | | if (CollectionUtils.isEmpty(filesystemItems)) { |
| | | return; |
| | | } |
| | |
| | | log.info("Saving archive content as file list: " + file.getAbsolutePath()); |
| | | try (ObjectOutputStream outputStream = new ObjectOutputStream(new BufferedOutputStream(new GzipCompressorOutputStream(new FileOutputStream(file))))) { |
| | | outputStream.writeObject(filesystemItems.size()); |
| | | for (BorgFilesystemItem item : filesystemItems) { |
| | | for (FilesystemItem item : filesystemItems) { |
| | | outputStream.writeObject(item); |
| | | } |
| | | outputStream.writeObject("EOF"); |
| | |
| | | * @param archive |
| | | * @return |
| | | */ |
| | | public List<BorgFilesystemItem> load(BorgRepoConfig repoConfig, Archive archive) { |
| | | public List<FilesystemItem> load(BorgRepoConfig repoConfig, Archive archive) { |
| | | return load(repoConfig, archive, null); |
| | | } |
| | | |
| | |
| | | * @param filter If given, only file items matching this filter are returned. |
| | | * @return |
| | | */ |
| | | public List<BorgFilesystemItem> load(BorgRepoConfig repoConfig, Archive archive, FileSystemFilter filter) { |
| | | public List<FilesystemItem> load(BorgRepoConfig repoConfig, Archive archive, FileSystemFilter filter) { |
| | | File file = getFile(repoConfig, archive); |
| | | if (!file.exists()) { |
| | | return null; |
| | |
| | | * @param filter If given, only file items matching this filter are returned. |
| | | * @return |
| | | */ |
| | | public List<BorgFilesystemItem> load(File file, FileSystemFilter filter) { |
| | | public List<FilesystemItem> load(File file, FileSystemFilter filter) { |
| | | if (!file.exists()) { |
| | | log.error("File '" + file.getAbsolutePath() + "' doesn't exist. Can't get archive content files."); |
| | | return null; |
| | | } |
| | | log.info("Loading archive content as file list from: " + file.getAbsolutePath()); |
| | | List<BorgFilesystemItem> list = null; |
| | | List<FilesystemItem> list = null; |
| | | try { |
| | | // Set last modified time of file: |
| | | Files.setAttribute(file.toPath(), "lastModifiedTime", FileTime.fromMillis(System.currentTimeMillis())); |
| | |
| | | for (int i = 0; i < size; i++) { |
| | | ++fileNumber; |
| | | obj = inputStream.readObject(); |
| | | if (obj instanceof BorgFilesystemItem) { |
| | | BorgFilesystemItem item = (BorgFilesystemItem) obj; |
| | | item.setFileNumber(fileNumber); |
| | | if (obj instanceof FilesystemItem) { |
| | | FilesystemItem item = (FilesystemItem) obj; |
| | | // item.setFileNumber(fileNumber); |
| | | if (filter == null || filter.matches(item)) { |
| | | list.add(item); |
| | | if (filter != null && filter.isFinished()) break; |
| | |
| | | Collections.sort(list); // Sort by path (if archive list order wasn't correct). |
| | | log.info("Loading done."); |
| | | if (filter != null) { |
| | | return filter.reduce(list); |
| | | // return filter.reduce(list); |
| | | } |
| | | return list; |
| | | } |