| // MD5All reads all the files in the file tree rooted at root and returns a map |
| // from file path to the MD5 sum of the file's contents. If the directory walk |
| // fails or any read operation fails, MD5All returns an error. |
| func MD5All(root string) (map[string][md5.Size]byte, error) { |
| m := make(map[string][md5.Size]byte) |
| err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error { // HL |
| if !info.Mode().IsRegular() { |
| data, err := ioutil.ReadFile(path) // HL |
| m[path] = md5.Sum(data) // HL |
| // Calculate the MD5 sum of all files under the specified directory, |
| // then print the results sorted by path name. |
| m, err := MD5All(os.Args[1]) // HL |
| paths = append(paths, path) |
| sort.Strings(paths) // HL |
| for _, path := range paths { |
| fmt.Printf("%x %s\n", m[path], path) |