Documentation ¶
Overview ¶
Package tree implements functions to hash directory trees.
To calculate the hash of a directory tree (a tree hash) a list of all files in the directory root (a tree list) is created as follows.
All the files below the root of the directory tree are traversed in lexical order (with filepath.Walk) and printed in this format:
m xxx filename
Where:
m is the mode ('f' or 'x') xxx is the SHA256 hash for the file in hex notation filename is the file name with directory prefix starting at root
Example list:
f 7d865e959b2466918c9863afca942d0fb89d7c9ac0c99bafc3749504ded97730 bar/baz.txt x b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c foo.txt
The fields are separated with single white space characters and the lines are separated with single newline characters.
Directories are only implicitly listed (i.e., if they contain files). Entries start with 'f' if it is a regular file (read and write permission for user) and with 'x' if it is an executable (read, write, and executable for user).
The directory tree must only contain directories, regular files, or executables.
The deterministic tree list serves as the basis for a hash of a directory tree (the tree hash), which is the SHA256 hash of the tree list in hex notation.
Index ¶
Constants ¶
const EmptyHash = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
EmptyHash is the hash of an empty directory tree (in hex notation).
Variables ¶
This section is empty.
Functions ¶
func Hash ¶
Hash returns a SHA256 hash of all files and directories in the file tree rooted at root, except for the paths in excludePaths (the tree hash).
func HashList ¶
HashList returns the SHA256 hash of a list of entries.
This is a convience function to calculate a tree hash out of entries without having to print them first in the canonical format.
func ListBytes ¶
ListBytes returns a list in lexical order of newline separated hashes of all files in the file tree rooted at root in the canonical format, except for the paths in excludePaths (the tree list).
Types ¶
type ListEntry ¶
type ListEntry struct { Mode rune // 'f' (regular) or 'x' (binary) Filename string // Including directory path starting from root Hash [32]byte // SHA256 hash }
ListEntry describes a directory tree entry.