Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixing Files matching on Windows-style filesystems

  • Loading branch information...
commit 8b13a54a1e12291282dadf61d053a336073fefa4 1 parent ee77780
Louis DeJardin lodejard authored

Showing 1 changed file with 27 additions and 15 deletions. Show diff stats Hide diff stats

  1. +27 15 src/Sake.Library/Shared/Files.shade
42 src/Sake.Library/Shared/Files.shade
@@ -6,10 +6,14 @@ functions
6 6 @{
7 7 _Files Files {get {return new _Files(Log);}}
8 8
  9 + static string ReplaceDirectorySeparatorChar(string path)
  10 + {
  11 + return path.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar);
  12 + }
9 13
10 14 class _Files : IEnumerable<string>
11 15 {
12   - string _basePath;
  16 + string _basePath;
13 17 IList<string> _include = new List<string>();
14 18 IList<string> _exclude = new List<string>();
15 19
@@ -23,7 +27,9 @@ functions
23 27
24 28 public _Files BasePath(string basePath)
25 29 {
26   - _basePath = Path.Combine(Directory.GetCurrentDirectory(), basePath);
  30 + _basePath = Path.Combine(
  31 + Directory.GetCurrentDirectory(),
  32 + ReplaceDirectorySeparatorChar(basePath));
27 33 return this;
28 34 }
29 35
@@ -31,7 +37,7 @@ functions
31 37 {
32 38 foreach(var pattern in patterns)
33 39 {
34   - _include.Add(pattern);
  40 + _include.Add(ReplaceDirectorySeparatorChar(pattern));
35 41 }
36 42 return this;
37 43 }
@@ -40,7 +46,7 @@ functions
40 46 {
41 47 foreach(var pattern in patterns)
42 48 {
43   - _exclude.Add(pattern);
  49 + _exclude.Add(ReplaceDirectorySeparatorChar(pattern));
44 50 }
45 51 return this;
46 52 }
@@ -57,19 +63,25 @@ functions
57 63
58 64 IEnumerable<string> Scan()
59 65 {
60   - var exclude = _exclude
61   - .SelectMany(pattern => PathResolver.PerformWildcardSearch(_basePath, pattern))
62   - .Distinct()
63   - .ToList();
  66 + var exclude = _exclude
  67 + .SelectMany(pattern => PathResolver.PerformWildcardSearch(_basePath, pattern))
  68 + .Distinct()
  69 + .ToList();
  70 +
  71 + var include = _include;
  72 + if (!include.Any())
  73 + {
  74 + include = new[]{ReplaceDirectorySeparatorChar("**/*")};
  75 + }
64 76
65   - var files = _include
66   - .SelectMany(pattern => PathResolver.PerformWildcardSearch(_basePath, pattern))
67   - .Distinct()
68   - .Where(path => !exclude.Contains(path))
69   - .Select(path => {if (path.StartsWith(_basePath)) {return path.Substring(_basePath.Length + 1);} return path;})
70   - .ToList();
  77 + var files = include
  78 + .SelectMany(pattern => PathResolver.PerformWildcardSearch(_basePath, pattern))
  79 + .Distinct()
  80 + .Where(path => !exclude.Contains(path))
  81 + .Select(path => {if (path.StartsWith(_basePath)) {return path.Substring(_basePath.Length + 1);} return path;})
  82 + .ToList();
71 83
72   - return files;
  84 + return files;
73 85 }
74 86 }
75 87 }

0 comments on commit 8b13a54

Please sign in to comment.
Something went wrong with that request. Please try again.