Skip to content

[Bug]: Cleanup — the "can be freed" figure stops counting at the first protected folder and follows junctions #2098

Description

@laurentiu021

Problem

CleanupPreScanService sizes both temp folders with Directory.EnumerateFiles(path, "*", SearchOption.AllDirectories). Three defects follow from that one call, and the codebase already diagnosed and fixed all three elsewhere:

  1. It aborts at the first unreadable subfolder. AllDirectories throws UnauthorizedAccessException out of MoveNext(), and the try sits outside the foreach — so the whole remaining walk for that path is abandoned and the headline reports whatever had been summed so far. Silently low, with no indication anything was skipped.
  2. It follows reparse points. A junction inside %TEMP% is walked as if it were a real folder, so bytes living outside temp are counted as freeable. MeasureRecycleBin has the same call and the same exposure, where it is worse: deleting a junction puts a reparse point in the Recycle Bin, so the bin can size at tens of GB of live data.
  3. It counts bytes the cleanup refuses to delete. Since [Bug]: Quick Cleanup - The temp sweep can delete the .NET extraction root of every running single-file app, and overcounts what it freed #2094 the temp sweep skips SystemPaths.BundleExtractionRoot and SystemPaths.OwnExtractionDirectory. The pre-scan does not, so the headline promises space that Clean TEMP will correctly leave alone.

TuneUpService.EnumerateFilesSkippingReparsePoints exists precisely for this and solves all three: per-directory try/catch that continues, reparse-point skip at the root and every child, and exclusion subtrees.

Expected behavior

The pre-scan measures what the cleanup would actually delete, using the same walker and the same two exclusions. An unreadable subfolder is skipped, not treated as the end of the tree.

Evidence

  • SysManager/SysManager/Services/CleanupPreScanService.csMeasureTemp and MeasureRecycleBin
  • SysManager/SysManager/Services/TuneUpService.csEnumerateFilesSkippingReparsePoints
  • ArchitectureTests.EveryTempTreeWalkerCall_PassesBothExtractionExclusions cannot see this: its walker-argument half is scoped to a hardcoded ["TuneUpService.cs", "DeepCleanupService.cs"], the same hardcoded-list weakness that let the third sweeper hide in CleanupViewModel for months.

Also in the same file: ICleanupPreScanService's doc offers "Unable to scan" as a possible TempLabel, which MeasureTemp cannot return — it catches per-path and always ends at Describe.

Affected tab

Cleanup

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions