Skip to content

Commit 644c2b9

Browse files
committed
Fix FileSystemProvider validation during rename
Because FileSystemProvider allows specifying a file as the library and a different file name as the destination (i.e. rename scenario), it was failing during goal state validation. However, in the FSP case, this is always valid - when a single file is specified, it can be mapped to one output file of any name.
1 parent 86cda61 commit 644c2b9

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/LibraryManager/Helpers/Extensions.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System.Threading;
99
using System.Threading.Tasks;
1010
using Microsoft.Web.LibraryManager.Contracts;
11+
using Microsoft.Web.LibraryManager.Providers.FileSystem;
1112
using Newtonsoft.Json;
1213
using Newtonsoft.Json.Linq;
1314

@@ -108,6 +109,16 @@ public static IReadOnlyList<string> GetInvalidFiles(this ILibrary library, IRead
108109

109110
var invalidFiles = new List<string>();
110111

112+
if (library.ProviderId == FileSystemProvider.IdText
113+
&& library.Files.Count == 1)
114+
{
115+
// Ideally this would be in the FileSystemLibrary, but this is an extension method.
116+
// For FileSystem provider, if a single file is specified, it is always valid.
117+
// It can be mapped to a different file name at the destination.
118+
// This is valid for FileSystem but not for any other provider.
119+
return invalidFiles;
120+
}
121+
111122
if (files == null || !files.Any())
112123
{
113124
return invalidFiles;
@@ -172,5 +183,15 @@ public static string GetJObjectMemberStringValue(this JObject jObject, string pr
172183
return propertyValue;
173184
}
174185

186+
#if NETFRAMEWORK
187+
/// <summary>
188+
/// Destructs the KeyValuePair into separate values for key and value.
189+
/// </summary>
190+
public static void Deconstruct<T1, T2>(this KeyValuePair<T1, T2> pair, out T1 key, out T2 value)
191+
{
192+
key = pair.Key;
193+
value = pair.Value;
194+
}
195+
#endif
175196
}
176197
}

src/LibraryManager/Providers/FileSystem/FileSystemProvider.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ namespace Microsoft.Web.LibraryManager.Providers.FileSystem
1717
/// <summary>Internal use only</summary>
1818
internal sealed class FileSystemProvider : BaseProvider
1919
{
20+
public const string IdText = "filesystem";
2021
private FileSystemCatalog _catalog;
2122

2223
/// <summary>Internal use only</summary>
@@ -28,7 +29,7 @@ public FileSystemProvider(IHostInteraction hostInteraction)
2829
/// <summary>
2930
/// The unique identifier of the provider.
3031
/// </summary>
31-
public override string Id => "filesystem";
32+
public override string Id => IdText;
3233

3334
/// <summary>
3435
/// Hint text for the library id.

0 commit comments

Comments
 (0)