Skip to content

Commit

Permalink
Fix globbing (#86)
Browse files Browse the repository at this point in the history
* fix globbing

* fix globbing 2
  • Loading branch information
mariuszkochanowski authored and madskristensen committed Apr 11, 2018
1 parent 6eaca9d commit 5f211d3
Showing 1 changed file with 30 additions and 15 deletions.
45 changes: 30 additions & 15 deletions src/WebOptimizer.Core/Asset.cs
Expand Up @@ -94,27 +94,42 @@ public static IEnumerable<string> ExpandGlobs(IAsset asset, IHostingEnvironment
string outSourceFile;
var provider = asset.GetFileProvider(env, sourceFile, out outSourceFile);

var fileInfo = provider.GetFileInfo("/");
string root = fileInfo.PhysicalPath;
if (root != null)
if (provider.GetFileInfo(outSourceFile).Exists)
{
var dir = new DirectoryInfoWrapper(new DirectoryInfo(root));
var matcher = new Matcher();
matcher.AddInclude(outSourceFile);
PatternMatchingResult globbingResult = matcher.Execute(dir);
IEnumerable<string> fileMatches = globbingResult.Files.Select(f => f.Path.Replace(root, string.Empty));

if (!fileMatches.Any())
if (!files.Contains(sourceFile))
{
throw new FileNotFoundException($"No files found matching \"{sourceFile}\" exist in \"{dir.FullName}\"");
files.Add(sourceFile);
}
}

if (!files.Contains(sourceFile))
else
{
files.Add(sourceFile);
}
var fileInfo = provider.GetFileInfo("/");
string root = fileInfo.PhysicalPath;

if (root != null)
{
var dir = new DirectoryInfoWrapper(new DirectoryInfo(root));
var matcher = new Matcher();
matcher.AddInclude(outSourceFile);
PatternMatchingResult globbingResult = matcher.Execute(dir);
IEnumerable<string> fileMatches = globbingResult.Files.Select(f => f.Path.Replace(root, string.Empty));

if (!fileMatches.Any())
{
throw new FileNotFoundException($"No files found matching \"{sourceFile}\" exist in \"{dir.FullName}\"");
}

files.AddRange(fileMatches.Where(f => !files.Contains(f)));

}
else
{
if (!files.Contains(sourceFile))
{
files.Add(sourceFile);
}
}
}
}

asset.Items[PhysicalFilesKey] = files;
Expand Down

0 comments on commit 5f211d3

Please sign in to comment.