Skip to content

Conversation

@QuintenQVD0
Copy link
Contributor

@QuintenQVD0 QuintenQVD0 commented Jan 22, 2026

Changes

  • Added logic to detect and handle hard links to avoid size duplication.

See: pterodactyl/wings#181

Summary by CodeRabbit

Release Notes

  • Bug Fixes
    • Improved disk space calculation accuracy by preventing hard-linked files from being counted multiple times when determining directory sizes.

✏️ Tip: You can customize this high-level summary in your review settings.

Added logic to detect and handle hard links to avoid size duplication.
@QuintenQVD0 QuintenQVD0 requested a review from a team as a code owner January 22, 2026 15:29
@coderabbitai
Copy link

coderabbitai bot commented Jan 22, 2026

📝 Walkthrough

Walkthrough

The 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

Cohort / File(s)
Hard-link De-duplication Logic
server/filesystem/disk_space.go

The file adds imports for unix and slices packages, introduces an inode tracking mechanism, and implements logic to detect when a regular file is part of a hard-link group (Nlink > 1). For each encountered inode, the function checks if it has already been processed—if so, the file's size is skipped; if not, the inode is recorded and the size is accumulated.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 A rabbit's hop through linked delights,
Where inodes dance and duplicates take flight,
No more counting what's already been seen,
Hard links now handled—clean and keen!
A TODO solved with whisker-thin precision. ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: implementing hard link detection in directory size calculation, which matches the core functionality added in the changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between eb6db92 and 958af85.

📒 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 is 1.24.0 (from go.mod), which fully supports the slices package (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.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a 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: Guard Sys() type assertion and use composite (Dev, Ino) key for hard-link dedup.

The unsafe type assertion info.Sys().(*unix.Stat_t) will panic if Sys() returns nil or a different type (compare with the ok-checked pattern in stat_linux.go). Additionally, inode numbers are per-device scoped—using only Ino causes 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

📥 Commits

Reviewing files that changed from the base of the PR and between eb6db92 and 958af85.

📒 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 is 1.24.0 (from go.mod), which fully supports the slices package (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.

@parkervcp parkervcp merged commit 6e20c4d into pelican-dev:main Jan 23, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants