goduf.go
changeset 42 3fa13770e970
parent 41 bce80b708ddb
child 43 95d940f9598e
equal deleted inserted replaced
41:bce80b708ddb 42:3fa13770e970
    59 	IgnoreEmpty bool
    59 	IgnoreEmpty bool
    60 }
    60 }
    61 
    61 
    62 // Results contains the results of the duplicates search
    62 // Results contains the results of the duplicates search
    63 type Results struct {
    63 type Results struct {
    64 	Groups             []ResultSet `json:"groups"`                // List of duplicate sets
    64 	Groups                 []ResultSet `json:"groups"`                    // List of duplicate sets
    65 	Duplicates         uint        `json:"duplicates"`            // Number of duplicates
    65 	Duplicates             uint        `json:"duplicates"`                // Number of duplicates
    66 	NumberOfSets       uint        `json:"number_of_sets"`        // Number of duplicate sets
    66 	NumberOfSets           uint        `json:"number_of_sets"`            // Number of duplicate sets
    67 	RedundantDataSize  uint64      `json:"redundant_data_size"`   // Redundant data size
    67 	RedundantDataSizeBytes uint64      `json:"redundant_data_size_bytes"` // Redundant data size
    68 	RedundantDataSizeH string      `json:"redundant_data_size_h"` // Same, human-readable
    68 	RedundantDataSizeHuman string      `json:"redundant_data_size_human"` // Same, human-readable
    69 	TotalFileCount     uint        `json:"total_file_count"`      // Total number of checked files
    69 	TotalFileCount         uint        `json:"total_file_count"`          // Total number of checked files
    70 	TotalSize          uint64      `json:"total_size"`            // Total size for checked files
    70 	TotalSizeBytes         uint64      `json:"total_size_bytes"`          // Total size for checked files
    71 	TotalSizeH         string      `json:"total_size_h"`          // Same, human-readable
    71 	TotalSizeHuman         string      `json:"total_size_human"`          // Same, human-readable
    72 }
    72 }
    73 
    73 
    74 // ResultSet contains a group of identical duplicate files
    74 // ResultSet contains a group of identical duplicate files
    75 type ResultSet struct {
    75 type ResultSet struct {
    76 	Size  uint64   `json:"size"`  // Size of each item
    76 	FileSize uint64   `json:"file_size"` // Size of each item
    77 	Paths []string `json:"paths"` // List of file paths
    77 	Paths    []string `json:"paths"`     // List of file paths
    78 }
    78 }
    79 
    79 
    80 type fileObj struct {
    80 type fileObj struct {
    81 	//Unique   bool
    81 	//Unique   bool
    82 	FilePath string
    82 	FilePath string
   521 
   521 
   522 	for _, l := range result {
   522 	for _, l := range result {
   523 		size := uint64(l[0].Size())
   523 		size := uint64(l[0].Size())
   524 		// We do not count the size of the 1st item
   524 		// We do not count the size of the 1st item
   525 		// so we get only duplicate size.
   525 		// so we get only duplicate size.
   526 		results.RedundantDataSize += size * uint64(len(l)-1)
   526 		results.RedundantDataSizeBytes += size * uint64(len(l)-1)
   527 		newSet := ResultSet{Size: size}
   527 		newSet := ResultSet{FileSize: size}
   528 		for _, f := range l {
   528 		for _, f := range l {
   529 			newSet.Paths = append(newSet.Paths, f.FilePath)
   529 			newSet.Paths = append(newSet.Paths, f.FilePath)
   530 			results.Duplicates++
   530 			results.Duplicates++
   531 		}
   531 		}
   532 		results.Groups = append(results.Groups, newSet)
   532 		results.Groups = append(results.Groups, newSet)
   533 	}
   533 	}
   534 	results.NumberOfSets = uint(len(results.Groups))
   534 	results.NumberOfSets = uint(len(results.Groups))
   535 	results.RedundantDataSizeH = formatSize(results.RedundantDataSize, true)
   535 	results.RedundantDataSizeHuman = formatSize(results.RedundantDataSizeBytes, true)
   536 	results.TotalFileCount = data.cmpt
   536 	results.TotalFileCount = data.cmpt
   537 	results.TotalSize = data.totalSize
   537 	results.TotalSizeBytes = data.totalSize
   538 	results.TotalSizeH = formatSize(data.totalSize, true)
   538 	results.TotalSizeHuman = formatSize(data.totalSize, true)
   539 
   539 
   540 	return results, nil
   540 	return results, nil
   541 }
   541 }
   542 
   542 
   543 // It all starts here.
   543 // It all starts here.