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