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

...
Kai Reinhard
10.01.2018 5c6ef91b43f0b0cc225b1a5b8abdc08b670a9317
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package de.micromata.borgbutler.cache;
 
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import de.micromata.borgbutler.BorgCommands;
import de.micromata.borgbutler.config.BorgRepoConfig;
import de.micromata.borgbutler.json.borg.Archive;
import de.micromata.borgbutler.json.borg.FilesystemItem;
import de.micromata.borgbutler.utils.ReplaceUtils;
import lombok.Getter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
 
import java.io.File;
import java.util.List;
 
class ArchiveFileListCache extends AbstractCache {
    private static Logger log = LoggerFactory.getLogger(ArchiveFileListCache.class);
    public static final String CACHE_ARCHIVE_LISTS_BASENAME = "archive-content-";
 
    @JsonIgnore
    @Getter
    private Archive archive;
    @JsonProperty
    private List<FilesystemItem> content;
 
    public List<FilesystemItem> getContent(BorgRepoConfig repoConfig) {
        if (content == null) {
            read();
        }
        if (content == null) {
            this.content = BorgCommands.list(repoConfig, archive);
            save();
        }
        List<FilesystemItem> result = this.content;
        if (content != null && content.size() > 100000) {
            // Don't waste the memory space...
            this.content = null;
        }
        return result;
    }
 
    protected void update(AbstractCache readCache) {
        this.content = ((ArchiveFileListCache) readCache).content;
    }
 
    /**
     * Needed by jackson for deserialization.
     */
    ArchiveFileListCache() {
    }
 
    ArchiveFileListCache(File cacheDir, BorgRepoConfig repoConfig, Archive archive) {
        super(cacheDir, ReplaceUtils.encodeFilename(CACHE_ARCHIVE_LISTS_BASENAME + repoConfig.getName() + "-" + archive.getArchive(),
                true), true);
        this.archive = archive;
    }
}