-
Notifications
You must be signed in to change notification settings - Fork 212
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed the file system changes watching and cache invalidation
- Loading branch information
1 parent
5aa01ae
commit 301069e
Showing
5 changed files
with
102 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using Microsoft.Extensions.Primitives; | ||
|
||
namespace VirtoCommerce.Storefront.Model.Common | ||
{ | ||
public static class PathUtils | ||
{ | ||
private static readonly char[] _invalidFileNameChars = Path.GetInvalidFileNameChars().Where(c => c != Path.DirectorySeparatorChar && c != Path.AltDirectorySeparatorChar).ToArray(); | ||
|
||
private static readonly char[] _invalidFilterChars = _invalidFileNameChars.Where(c => c != '*' && c != '|' && c != '?').ToArray(); | ||
|
||
private static readonly char[] _pathSeparators = new[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar }; | ||
|
||
public static bool HasInvalidPathChars(string path) | ||
{ | ||
return path.IndexOfAny(_invalidFileNameChars) != -1; | ||
} | ||
|
||
public static bool HasInvalidFilterChars(string path) | ||
{ | ||
return path.IndexOfAny(_invalidFilterChars) != -1; | ||
} | ||
|
||
public static string EnsureTrailingSlash(string path) | ||
{ | ||
if (!string.IsNullOrEmpty(path) && | ||
path[path.Length - 1] != Path.DirectorySeparatorChar) | ||
{ | ||
return path + Path.DirectorySeparatorChar; | ||
} | ||
|
||
return path; | ||
} | ||
|
||
public static bool PathNavigatesAboveRoot(string path) | ||
{ | ||
var tokenizer = new StringTokenizer(path, _pathSeparators); | ||
var depth = 0; | ||
|
||
foreach (var segment in tokenizer) | ||
{ | ||
if (segment.Equals(".") || segment.Equals("")) | ||
{ | ||
continue; | ||
} | ||
else if (segment.Equals("..")) | ||
{ | ||
depth--; | ||
|
||
if (depth == -1) | ||
{ | ||
return true; | ||
} | ||
} | ||
else | ||
{ | ||
depth++; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters