-
Notifications
You must be signed in to change notification settings - Fork 59
Implement hard link detection in directory size calculation #163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Added logic to detect and handle hard links to avoid size duplication.
📝 WalkthroughWalkthroughThe changes implement hard-link de-duplication in the DirectorySize function by tracking inode numbers and skipping size accumulation for previously-encountered hard-linked files, replacing a TODO placeholder with actual logic. Changes
The file adds imports for Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
📜 Recent review detailsConfiguration used: Organization UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
🔇 Additional comments (1)
✏️ Tip: You can disable this entire section by setting Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
server/filesystem/disk_space.go (1)
168-195: GuardSys()type assertion and use composite (Dev, Ino) key for hard-link dedup.The unsafe type assertion
info.Sys().(*unix.Stat_t)will panic ifSys()returns nil or a different type (compare with the ok-checked pattern instat_linux.go). Additionally, inode numbers are per-device scoped—using onlyInocauses undercounting when the walk crosses mount points. Use a composite(Dev, Ino)key in a map and add the ok-check.🔧 Proposed fix (device+inode key + safe assertion)
- var hardLinks []uint64 + type inodeKey struct { + dev uint64 + ino uint64 + } + hardLinks := make(map[inodeKey]struct{}) ... - var sysFileInfo = info.Sys().(*unix.Stat_t) - if sysFileInfo.Nlink > 1 { - // Hard links have the same inode number - if slices.Contains(hardLinks, sysFileInfo.Ino) { - // Don't add hard links size twice - return nil - } else { - hardLinks = append(hardLinks, sysFileInfo.Ino) - } - } + if sysFileInfo, ok := info.Sys().(*unix.Stat_t); ok && sysFileInfo != nil && sysFileInfo.Nlink > 1 { + key := inodeKey{dev: uint64(sysFileInfo.Dev), ino: sysFileInfo.Ino} + if _, seen := hardLinks[key]; seen { + return nil + } + hardLinks[key] = struct{}{} + }
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
server/filesystem/disk_space.go
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
- GitHub Check: Build and Test (ubuntu-22.04, 1.25.1, linux, amd64)
- GitHub Check: Analyze (go)
- GitHub Check: Build and Test (ubuntu-22.04, 1.24.7, linux, amd64)
🔇 Additional comments (1)
server/filesystem/disk_space.go (1)
4-5: No action needed. The project's Go version is1.24.0(fromgo.mod), which fully supports theslicespackage (available since Go 1.21). The import is compatible and will compile correctly.Likely an incorrect or invalid review comment.
✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.
Changes
See: pterodactyl/wings#181
Summary by CodeRabbit
Release Notes
✏️ Tip: You can customize this high-level summary in your review settings.