Matthias Andreas Benkard | b5d657a | 2022-02-03 21:14:30 +0100 | [diff] [blame^] | 1 | // SPDX-FileCopyrightText: © 2021 Matthias Andreas Benkard <code@mail.matthias.benkard.de> |
| 2 | // |
| 3 | // SPDX-License-Identifier: LGPL-3.0-or-later |
| 4 | |
Matthias Andreas Benkard | 4e8423d | 2021-12-19 22:56:09 +0100 | [diff] [blame] | 5 | package eu.mulk.jgvariant.ostree; |
| 6 | |
| 7 | import eu.mulk.jgvariant.core.Decoder; |
| 8 | import java.nio.charset.StandardCharsets; |
| 9 | import java.util.List; |
| 10 | |
| 11 | /** |
| 12 | * Metadata describing files and directories of a file tree. |
| 13 | * |
Matthias Andreas Benkard | 0511464 | 2021-12-29 21:51:29 +0100 | [diff] [blame] | 14 | * <p>Often comes in a pair with {@link DirMeta}. |
| 15 | * |
Matthias Andreas Benkard | 4e8423d | 2021-12-19 22:56:09 +0100 | [diff] [blame] | 16 | * <p>Referenced by {@link Commit#rootDirTreeChecksum()} and recursively by {@link |
| 17 | * Directory#treeChecksum()}. |
| 18 | * |
| 19 | * <p>Reference: {@code ostree-core.h#OSTREE_TREE_GVARIANT_STRING} |
Matthias Andreas Benkard | 0511464 | 2021-12-29 21:51:29 +0100 | [diff] [blame] | 20 | * |
| 21 | * @param files a list of files in the directory. |
| 22 | * @param directories a list of subdirectories of the directory. |
| 23 | * @see DirMeta |
| 24 | * @see ObjectType#DIR_TREE |
Matthias Andreas Benkard | 4e8423d | 2021-12-19 22:56:09 +0100 | [diff] [blame] | 25 | */ |
| 26 | public record DirTree(List<File> files, List<Directory> directories) { |
| 27 | |
Matthias Andreas Benkard | 0511464 | 2021-12-29 21:51:29 +0100 | [diff] [blame] | 28 | /** |
| 29 | * A file in a file tree. |
| 30 | * |
| 31 | * @param name the file name. |
| 32 | * @param checksum the checksum of the {@link ObjectType#FILE} object. |
| 33 | */ |
Matthias Andreas Benkard | 4e8423d | 2021-12-19 22:56:09 +0100 | [diff] [blame] | 34 | public record File(String name, Checksum checksum) { |
| 35 | |
| 36 | private static final Decoder<File> DECODER = |
| 37 | Decoder.ofStructure( |
| 38 | File.class, Decoder.ofString(StandardCharsets.UTF_8), Checksum.decoder()); |
| 39 | |
Matthias Andreas Benkard | 0511464 | 2021-12-29 21:51:29 +0100 | [diff] [blame] | 40 | /** |
| 41 | * Acquires a {@link Decoder} for the enclosing type. |
| 42 | * |
| 43 | * @return a possibly shared {@link Decoder}. |
| 44 | */ |
Matthias Andreas Benkard | 4e8423d | 2021-12-19 22:56:09 +0100 | [diff] [blame] | 45 | public static Decoder<File> decoder() { |
| 46 | return DECODER; |
| 47 | } |
| 48 | } |
| 49 | |
Matthias Andreas Benkard | 0511464 | 2021-12-29 21:51:29 +0100 | [diff] [blame] | 50 | /** |
| 51 | * A subdirectory in a file tree. |
| 52 | * |
| 53 | * @param name the name of the subdirectory. |
| 54 | * @param treeChecksum the checksum of the {@link DirTree} object. |
| 55 | * @param dirChecksum the checksum of the {@link DirMeta} object. |
| 56 | */ |
Matthias Andreas Benkard | 4e8423d | 2021-12-19 22:56:09 +0100 | [diff] [blame] | 57 | public record Directory(String name, Checksum treeChecksum, Checksum dirChecksum) { |
| 58 | |
| 59 | private static final Decoder<Directory> DECODER = |
| 60 | Decoder.ofStructure( |
| 61 | Directory.class, |
| 62 | Decoder.ofString(StandardCharsets.UTF_8), |
| 63 | Checksum.decoder(), |
| 64 | Checksum.decoder()); |
| 65 | |
Matthias Andreas Benkard | 0511464 | 2021-12-29 21:51:29 +0100 | [diff] [blame] | 66 | /** |
| 67 | * Acquires a {@link Decoder} for the enclosing type. |
| 68 | * |
| 69 | * @return a possibly shared {@link Decoder}. |
| 70 | */ |
Matthias Andreas Benkard | 4e8423d | 2021-12-19 22:56:09 +0100 | [diff] [blame] | 71 | public static Decoder<Directory> decoder() { |
| 72 | return DECODER; |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | private static final Decoder<DirTree> DECODER = |
| 77 | Decoder.ofStructure( |
| 78 | DirTree.class, Decoder.ofArray(File.decoder()), Decoder.ofArray(Directory.decoder())); |
| 79 | |
Matthias Andreas Benkard | 0511464 | 2021-12-29 21:51:29 +0100 | [diff] [blame] | 80 | /** |
| 81 | * Acquires a {@link Decoder} for the enclosing type. |
| 82 | * |
| 83 | * @return a possibly shared {@link Decoder}. |
| 84 | */ |
Matthias Andreas Benkard | 4e8423d | 2021-12-19 22:56:09 +0100 | [diff] [blame] | 85 | public static Decoder<DirTree> decoder() { |
| 86 | return DECODER; |
| 87 | } |
| 88 | } |