Skip to content

Commit 8ece0b5

Browse files
committed
Code Quality: Prevent user names and paths from being written to the log file
1 parent 2f62129 commit 8ece0b5

20 files changed

Lines changed: 137 additions & 66 deletions

File tree

src/Files.App/Actions/FileSystem/FlattenFolderAction.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ private void FlattenFolder(string path)
8888
}
8989
catch (Exception ex)
9090
{
91-
App.Logger.LogWarning(ex.Message, $"Folder '{folderName}' already exists in the destination folder.");
91+
App.Logger.LogWarning(ex, $"Folder '{LogPathHelper.GetPathIdentifier(folderName)}' already exists in the destination folder.");
9292
}
9393
}
9494

@@ -106,7 +106,7 @@ private void FlattenFolder(string path)
106106
}
107107
catch (Exception ex)
108108
{
109-
App.Logger.LogWarning(ex.Message, $"Failed to move file '{fileName}'.");
109+
App.Logger.LogWarning(ex, $"Failed to move file '{LogPathHelper.GetPathIdentifier(fileName)}'.");
110110
}
111111
}
112112

@@ -118,7 +118,7 @@ private void FlattenFolder(string path)
118118
}
119119
catch (Exception ex)
120120
{
121-
App.Logger.LogWarning(ex.Message, $"Failed to delete folder '{path}'.");
121+
App.Logger.LogWarning(ex, $"Failed to delete folder '{LogPathHelper.GetPathIdentifier(path)}'.");
122122
}
123123
}
124124
}

src/Files.App/Data/Items/ExpandableSidebarItemBase.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ private void StartWatchingSubfolders()
140140
// FileSystemWatcher ctor throws ArgumentException for invalid paths, UnauthorizedAccessException for protected roots; either way fall back to no live updates for this subtree.
141141
catch (Exception ex)
142142
{
143-
App.Logger?.LogDebug(ex, "Sidebar subfolder watcher start failed for {Path}", ExpansionPath);
143+
App.Logger?.LogDebug(ex, "Sidebar subfolder watcher start failed for {Path}", LogPathHelper.GetPathIdentifier(ExpansionPath));
144144
subfolderWatcher?.Dispose();
145145
subfolderWatcher = null;
146146
}
@@ -214,7 +214,7 @@ private async Task ResyncSubfoldersAsync()
214214
// EnumerateSubfolders can throw UnauthorizedAccessException / IOException if the folder is in a bad state mid-resync; treat as "no change visible right now" rather than tearing down ChildItems.
215215
catch (Exception ex)
216216
{
217-
App.Logger?.LogDebug(ex, "Sidebar subfolder resync enumeration failed for {Path}", ExpansionPath);
217+
App.Logger?.LogDebug(ex, "Sidebar subfolder resync enumeration failed for {Path}", LogPathHelper.GetPathIdentifier(ExpansionPath));
218218
return;
219219
}
220220

src/Files.App/Data/Items/LocationItem.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ await dispatcher.EnqueueOrInvokeAsync(async () =>
140140
// FolderHelpers.EnumerateSubfolders / FileThumbnailHelper can throw UnauthorizedAccessException, IOException, or COMException on inaccessible / missing paths. Still run onLoaded on the dispatcher so the caller can clear HasUnrealizedChildren and mark childrenLoaded — otherwise the chevron stays and every subsequent click replays the failing enumeration.
141141
catch (Exception ex)
142142
{
143-
App.Logger?.LogDebug(ex, "Sidebar subfolder enumeration failed for {Path}", enumerationPath);
143+
App.Logger?.LogDebug(ex, "Sidebar subfolder enumeration failed for {Path}", LogPathHelper.GetPathIdentifier(enumerationPath));
144144
await (MainWindow.Instance?.DispatcherQueue).EnqueueOrInvokeAsync(onLoaded);
145145
}
146146
}
@@ -194,7 +194,7 @@ internal static async Task UpgradeIconsAsync(List<LocationItem> children, byte[]
194194
// FileThumbnailHelper.GetIconAsync can throw COMException / UnauthorizedAccessException on inaccessible paths; keep the shared generic icon.
195195
catch (Exception ex)
196196
{
197-
App.Logger?.LogDebug(ex, "LocationItem: real icon load failed for {Path}", path);
197+
App.Logger?.LogDebug(ex, "LocationItem: real icon load failed for {Path}", LogPathHelper.GetPathIdentifier(path));
198198
continue;
199199
}
200200

@@ -212,7 +212,7 @@ await dispatcher.EnqueueOrInvokeAsync(async () =>
212212
item.Icon = bmp;
213213
}
214214
// BitmapImage.SetSourceAsync throws on corrupt bytes; keep the generic icon.
215-
catch (Exception ex) { App.Logger?.LogDebug(ex, "LocationItem: real icon decode failed for {Path}", path); }
215+
catch (Exception ex) { App.Logger?.LogDebug(ex, "LocationItem: real icon decode failed for {Path}", LogPathHelper.GetPathIdentifier(path)); }
216216
}, Microsoft.UI.Dispatching.DispatcherQueuePriority.Low);
217217
}
218218
}

src/Files.App/Data/Models/CompressArchiveModel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ await Task.Run(() =>
239239
if (skippedItems.Count > 0)
240240
{
241241
var logger = Ioc.Default.GetRequiredService<ILogger<App>>();
242-
logger?.LogWarning($"Skipped {skippedItems.Count} item(s) that could not be archived to {ArchivePath}: {string.Join(", ", skippedItems)}");
242+
logger?.LogWarning($"Skipped {skippedItems.Count} item(s) that could not be archived to {LogPathHelper.GetPathIdentifier(ArchivePath)}: {string.Join(", ", skippedItems.Select(LogPathHelper.GetPathIdentifier))}");
243243

244244
// Ask the user whether to skip the items or cancel the operation, see #16240
245245
var dialogService = Ioc.Default.GetRequiredService<IDialogService>();
@@ -324,7 +324,7 @@ static void AddArchiveEntry(IDictionary<string, string> entries, string name, st
324324
catch (Exception ex)
325325
{
326326
var logger = Ioc.Default.GetRequiredService<ILogger<App>>();
327-
logger?.LogWarning(ex, $"Error compressing folder: {ArchivePath}");
327+
logger?.LogWarning(ex, $"Error compressing folder: {LogPathHelper.GetPathIdentifier(ArchivePath)}");
328328

329329
cts.Cancel();
330330

src/Files.App/Helpers/LogPathHelper.cs

Lines changed: 0 additions & 34 deletions
This file was deleted.

src/Files.App/Helpers/PathNormalization.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public static string GetPathRoot(string? path)
5555
}
5656
catch (Exception ex) when (ex is UriFormatException || ex is ArgumentException)
5757
{
58-
App.Logger.LogDebug(ex, path);
58+
App.Logger.LogDebug(ex, LogPathHelper.GetPathIdentifier(path));
5959
return path;
6060
}
6161
}

src/Files.App/Services/Git/LibGit2Service.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ await DoGitOperationAsync<GitOperationResult>(() =>
408408
catch (Exception ex)
409409
{
410410
// An unreachable remote (e.g. a deleted fork answering 401) must not prevent fetching the remaining remotes
411-
_logger.LogWarning(ex, "Failed to fetch remote {RemoteName} in {RepositoryPath}", remote.Name, repositoryPath);
411+
_logger.LogWarning(ex, "Failed to fetch remote {RemoteName} in {RepositoryPath}", remote.Name, LogPathHelper.GetPathIdentifier(repositoryPath));
412412

413413
if (IsAuthorizationException(ex))
414414
result = GitOperationResult.AuthorizationError;

src/Files.App/Services/Windows/WindowsDialogService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public unsafe bool Open_FileOpenDialog(nint hWnd, bool pickFoldersOnly, string[]
5757
// Handle shell item creation failure gracefully
5858
if (hr.Failed)
5959
{
60-
App.Logger.LogWarning("Failed to create shell item for default folder '{0}'. HRESULT: 0x{1:X8}. Dialog will open without default folder.", Environment.GetFolderPath(defaultFolder), hr.Value);
60+
App.Logger.LogWarning("Failed to create shell item for default folder '{0}'. HRESULT: 0x{1:X8}. Dialog will open without default folder.", defaultFolder, hr.Value);
6161
// Continue without setting default folder rather than failing completely
6262
}
6363
else
@@ -159,7 +159,7 @@ public unsafe bool Open_FileSaveDialog(nint hWnd, bool pickFoldersOnly, string[]
159159
// Handle shell item creation failure gracefully
160160
if (hr.Failed)
161161
{
162-
App.Logger.LogWarning("Failed to create shell item for default folder '{0}'. HRESULT: 0x{1:X8}. Dialog will open without default folder.", Environment.GetFolderPath(defaultFolder), hr.Value);
162+
App.Logger.LogWarning("Failed to create shell item for default folder '{0}'. HRESULT: 0x{1:X8}. Dialog will open without default folder.", defaultFolder, hr.Value);
163163
// Continue without setting default folder rather than failing completely
164164
}
165165
else

src/Files.App/Utils/Cloud/CloudDrivesManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public static async Task UpdateDrivesAsync()
3434

3535
foreach (var provider in providers)
3636
{
37-
_logger?.LogInformation($"Adding cloud provider \"{provider.Name}\" mapped to {provider.SyncFolder}");
37+
_logger?.LogInformation($"Adding cloud provider {provider.ID} mapped to {LogPathHelper.GetPathIdentifier(provider.SyncFolder)}");
3838

3939
var cloudProviderItem = new DriveItem()
4040
{

src/Files.App/Utils/Cloud/Detector/DropBoxCloudDetector.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ protected override async IAsyncEnumerable<ICloudProvider> GetProviders()
2121
if (File.Exists(websiteJsonPath))
2222
{
2323
infoJsonPath = websiteJsonPath;
24-
App.Logger.LogInformation("Dropbox: Found website version at {Path}", websiteJsonPath);
24+
App.Logger.LogInformation("Dropbox: Found website version at {Path}", LogPathHelper.GetPathIdentifier(websiteJsonPath));
2525
}
2626
else
2727
{
@@ -51,7 +51,7 @@ protected override async IAsyncEnumerable<ICloudProvider> GetProviders()
5151
if (newestInfoJsonPath is not null)
5252
{
5353
infoJsonPath = newestInfoJsonPath;
54-
App.Logger.LogInformation("Dropbox: Found Store version at {Path} (last modified: {Timestamp})", newestInfoJsonPath, newestTimestamp);
54+
App.Logger.LogInformation("Dropbox: Found Store version at {Path} (last modified: {Timestamp})", LogPathHelper.GetPathIdentifier(newestInfoJsonPath), newestTimestamp);
5555
}
5656
}
5757
}

0 commit comments

Comments
 (0)