Skip to content

fix: ignore empty directories in device clean scan - #13442

Merged
ssongliu merged 2 commits into
dev-v2from
fix/device-clean-empty-directory-scan
Aug 3, 2026
Merged

fix: ignore empty directories in device clean scan#13442
ssongliu merged 2 commits into
dev-v2from
fix/device-clean-empty-directory-scan

Conversation

@ssongliu

@ssongliu ssongliu commented Aug 3, 2026

Copy link
Copy Markdown
Member

Refs #13435

Copilot AI review requested due to automatic review settings August 3, 2026 05:53

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the agent’s device cleanup scan logic to avoid surfacing empty directories by computing directory trees and sizes in a single recursive traversal, primarily for rollback/upload/download-related cleanup items.

Changes:

  • Refactors rollback scan to no longer require fileOp and instead build rollback trees via the updated helper.
  • Replaces loadTreeWithCheck’s size-gating (previously based on GetDirSize) with a new recursive walker that returns both a file tree and aggregated size.
  • Introduces loadTreeWithFileSize to skip empty directories while building dto.CleanTree results.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread agent/app/service/device_clean.go
Copilot AI review requested due to automatic review settings August 3, 2026 06:06
@ssongliu
ssongliu merged commit d018799 into dev-v2 Aug 3, 2026
4 checks passed
@ssongliu
ssongliu deleted the fix/device-clean-empty-directory-scan branch August 3, 2026 06:06

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

Suppressed comments (2)

agent/app/service/device_clean.go:869

  • loadTreeWithFileSize currently skips any entry whose computed item.Size is 0, which also filters out 0-byte files. The PR title/intent is to ignore empty directories; silently hiding 0-byte files is an additional behavior change and may prevent users from cleaning placeholder/empty files inside otherwise non-empty trees.
		if item.Size == 0 {
			continue
		}

agent/app/service/device_clean.go:828

  • loadTreeWithCheck now derives Size by summing os.DirEntry.Info().Size() via loadTreeWithFileSize, while most other scan sections use fileOp.GetDirSize() (which uses du and reflects disk usage). This makes the reported sizes inconsistent across cleanup categories and can under-report reclaimable space (e.g., filesystem blocks, sparse files), which may confuse users.

This issue also appears on line 867 of the same file.

func loadTreeWithCheck(treeData []dto.CleanTree, pathItem, treeType string) []dto.CleanTree {
	list, size := loadTreeWithFileSize(true, pathItem, treeType, pathItem)
	if len(list) == 0 || size == 0 {
		return treeData
	}
	treeData = append(treeData, dto.CleanTree{ID: uuid.NewString(), Label: treeType, Size: size, IsCheck: size > 0, Children: list, Type: treeType, IsRecommend: true, CanDelete: false})

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