diff --git a/src/File/FileSpec.cs b/src/File/FileSpec.cs index 924596b..57862ce 100644 --- a/src/File/FileSpec.cs +++ b/src/File/FileSpec.cs @@ -1,8 +1,10 @@ using System; +using System.Diagnostics; using System.Linq; namespace Devlooped { + [DebuggerDisplay("{Path}")] public class FileSpec { public static FileSpec WithPath(string path, Uri uri) diff --git a/src/File/SyncCommand.cs b/src/File/SyncCommand.cs index e66dadc..a383cbb 100644 --- a/src/File/SyncCommand.cs +++ b/src/File/SyncCommand.cs @@ -1,4 +1,5 @@ -using System.IO; +using System; +using System.IO; using System.Linq; using DotNetConfig; @@ -16,12 +17,21 @@ protected override bool OnRemoteUrlMissing(FileSpec spec) // Clear empty directories var dir = new FileInfo(spec.Path).DirectoryName; - if (dir != null && !Directory.EnumerateFiles(dir).Any()) - Directory.Delete(dir); + DeleteEmptyDirectories(dir); Configuration.RemoveSection("file", spec.Path); return true; } + + void DeleteEmptyDirectories(string? dir) + { + if (dir != null && !Directory.EnumerateFiles(dir).Any() && !Directory.EnumerateDirectories(dir).Any()) + { + var parent = new DirectoryInfo(dir).Parent?.FullName; + Directory.Delete(dir); + DeleteEmptyDirectories(parent); + } + } } }