Skip to content
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

Fix: Fixed folder size calculation #12207

Merged
merged 1 commit into from
Apr 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 9 additions & 15 deletions src/Files.App/ViewModels/Properties/Items/BaseProperties.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
using CommunityToolkit.Mvvm.DependencyInjection;
using CommunityToolkit.WinUI;
using Files.App.Extensions;
using Files.Backend.Extensions;
using Files.Shared.Services.DateTimeFormatter;
using Microsoft.UI.Dispatching;
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using Windows.Storage.FileProperties;
using static Files.Backend.Helpers.NativeFindStorageItemHelper;
using FileAttributes = System.IO.FileAttributes;
Expand Down Expand Up @@ -72,22 +65,23 @@ public async Task<long> CalculateFolderSizeAsync(string path, CancellationToken
{
do
{
if (((FileAttributes)findData.dwFileAttributes & FileAttributes.ReparsePoint) == FileAttributes.ReparsePoint)
// Skip symbolic links and junctions
continue;

if (((FileAttributes)findData.dwFileAttributes & FileAttributes.Directory) != FileAttributes.Directory)
{
size += findData.GetSize();
++count;
ViewModel.FilesCount++;
}
else if (((FileAttributes)findData.dwFileAttributes & FileAttributes.Directory) == FileAttributes.Directory)
else if (findData.cFileName != "." && findData.cFileName != "..")
{
if (findData.cFileName != "." && findData.cFileName != "..")
{
var itemPath = Path.Combine(path, findData.cFileName);
var itemPath = Path.Combine(path, findData.cFileName);

size += await CalculateFolderSizeAsync(itemPath, token);
++count;
ViewModel.FoldersCount++;
}
size += await CalculateFolderSizeAsync(itemPath, token);
++count;
ViewModel.FoldersCount++;
}

if (size > ViewModel.ItemSizeBytes)
Expand Down
4 changes: 4 additions & 0 deletions src/Files.Backend/Services/SizeProvider/CachedSizeProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ async Task<ulong> Calculate(string path, int level = 0)
{
do
{
if (((FileAttributes)findData.dwFileAttributes & FileAttributes.ReparsePoint) == FileAttributes.ReparsePoint)
// Skip symbolic links and junctions
continue;

bool isDirectory = ((FileAttributes)findData.dwFileAttributes & FileAttributes.Directory) is FileAttributes.Directory;
if (!isDirectory)
{
Expand Down