408 emptyCount = len(sc.files) |
408 emptyCount = len(sc.files) |
409 delete(data.sizeGroups, 0) |
409 delete(data.sizeGroups, 0) |
410 return |
410 return |
411 } |
411 } |
412 |
412 |
413 func (data *dataT) createSizeHash() (hardLinkCount, uniqueSizeCount int) { |
413 // initialCleanup() removes files with unique size as well as hard links |
|
414 func (data *dataT) initialCleanup() (hardLinkCount, uniqueSizeCount int) { |
414 for s, sizeGroup := range data.sizeGroups { |
415 for s, sizeGroup := range data.sizeGroups { |
415 if len(sizeGroup.files) < 2 { |
416 if len(sizeGroup.files) < 2 { |
416 delete(data.sizeGroups, s) |
417 delete(data.sizeGroups, s) |
417 uniqueSizeCount++ |
418 uniqueSizeCount++ |
418 continue |
419 continue |
419 } |
420 } |
420 |
421 |
421 var hardlinksFound bool |
422 var hardlinksFound bool |
422 |
423 |
423 // Check for hardlinks |
424 // Check for hardlinks |
424 // TODO: what about symlinks? |
|
425 // Remove unique dev/inodes |
425 // Remove unique dev/inodes |
426 // Instead of this loop, another way would be to use the field |
426 // Instead of this loop, another way would be to use the field |
427 // "Unique" of the fileObj to mark them to be discarded |
427 // "Unique" of the fileObj to mark them to be discarded |
428 // and remove them all at the end. |
428 // and remove them all at the end. |
|
429 // TODO: what about symlinks? |
429 for { |
430 for { |
430 if !OSHasInodes() { |
431 if !OSHasInodes() { |
431 break |
432 break |
432 } |
433 } |
433 var hardLinkIndex int |
434 var hardLinkIndex int |
560 myLog.Println(3, "* Number of size groups:", len(data.sizeGroups)) |
561 myLog.Println(3, "* Number of size groups:", len(data.sizeGroups)) |
561 } |
562 } |
562 |
563 |
563 // Remove unique sizes |
564 // Remove unique sizes |
564 myLog.Println(1, "* Removing files with unique size, sorting file lists...") |
565 myLog.Println(1, "* Removing files with unique size, sorting file lists...") |
565 hardLinkCount, uniqueSizeCount := data.createSizeHash() |
566 hardLinkCount, uniqueSizeCount := data.initialCleanup() |
566 if verbose { |
567 if verbose { |
567 myLog.Printf(2, " Dropped %d files with unique size\n", |
568 myLog.Printf(2, " Dropped %d files with unique size\n", |
568 uniqueSizeCount) |
569 uniqueSizeCount) |
569 myLog.Printf(2, " Dropped %d hard links\n", hardLinkCount) |
570 myLog.Printf(2, " Dropped %d hard links\n", hardLinkCount) |
570 myLog.Println(3, "* Number of size groups:", len(data.sizeGroups)) |
571 myLog.Println(3, "* Number of size groups:", len(data.sizeGroups)) |