Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/Cake.Core/IO/Directory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,5 +121,12 @@ public IDirectory SetUnixFileMode(UnixFileMode unixFileMode)
_directory.Refresh();
return this;
}

public IEnumerable<IFileSystemInfo> GetFileSystemInfos(string filter, SearchScope scope)
{
var directories = GetDirectories(filter, scope).Cast<IFileSystemInfo>();
var files = GetFiles(filter, scope).Cast<IFileSystemInfo>();
return directories.Concat(files);
}
}
}
17 changes: 17 additions & 0 deletions src/Cake.Core/IO/FileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;

namespace Cake.Core.IO
{
/// <summary>
Expand All @@ -20,5 +22,20 @@ public IDirectory GetDirectory(DirectoryPath path)
{
return new Directory(path);
}

/// <inheritdoc/>
public IFileSystemInfo GetFileSystemInfo(DirectoryPath path)
{
if (path == null)
{
throw new ArgumentNullException(nameof(path));
}
var directory = GetDirectory(path);
if (directory.Exists)
{
return directory;
}
return GetFile(path.FullPath);
}
}
}
18 changes: 18 additions & 0 deletions src/Cake.Core/IO/Globber.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public sealed class Globber : IGlobber
private readonly GlobVisitor _visitor;
private readonly PathComparer _comparer;
private readonly ICakeEnvironment _environment;
private readonly IFileSystem _fileSystem;

/// <summary>
/// Initializes a new instance of the <see cref="Globber"/> class.
Expand All @@ -33,6 +34,7 @@ public Globber(IFileSystem fileSystem, ICakeEnvironment environment)
_parser = new GlobParser(environment);
_visitor = new GlobVisitor(fileSystem, environment);
_comparer = new PathComparer(environment.Platform.IsUnix());
_fileSystem = fileSystem;
}

/// <inheritdoc/>
Expand All @@ -52,5 +54,21 @@ public IEnumerable<Path> Match(GlobPattern pattern, GlobberSettings settings)
.Select(x => x.Path)
.Distinct(_comparer);
}

/// <inheritdoc/>
public IEnumerable<IFileSystemInfo> GetFileSystemInfos(string pattern)
{
if (pattern is null)
{
throw new ArgumentNullException(nameof(pattern));
}

var glob = _parser.Parse(pattern, new GlobberSettings
{
IsCaseSensitive = !_comparer.IsCaseSensitive
});
var settings = new GlobberSettings { IsCaseSensitive = !_comparer.IsCaseSensitive };
return _visitor.Walk(glob, settings);
}
}
}
8 changes: 8 additions & 0 deletions src/Cake.Core/IO/IDirectory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,13 @@ public interface IDirectory : IFileSystemInfo
/// <param name="unixFileMode">The <see cref="UnixFileMode"/> to set.</param>
/// <returns>The <see cref="IDirectory"/> instance representing the specified path.</returns>
IDirectory SetUnixFileMode(UnixFileMode unixFileMode) => this;

/// <summary>
/// Gets all file system entries in the directory.
/// </summary>
/// <param name="filter">The filter.</param>
/// <param name="scope">The search scope.</param>
/// <returns>The file system entries.</returns>
IEnumerable<IFileSystemInfo> GetFileSystemInfos(string filter, SearchScope scope);
}
}
7 changes: 7 additions & 0 deletions src/Cake.Core/IO/IFileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,12 @@ public interface IFileSystem
/// <param name="path">The path.</param>
/// <returns>A <see cref="IDirectory"/> instance representing the specified path.</returns>
IDirectory GetDirectory(DirectoryPath path);

/// <summary>
/// Gets a <see cref="IFileSystemInfo"/> for the specified path.
/// </summary>
/// <param name="path">The path.</param>
/// <returns>A <see cref="IFileSystemInfo"/> for the specified path.</returns>
IFileSystemInfo GetFileSystemInfo(DirectoryPath path);
}
}
7 changes: 7 additions & 0 deletions src/Cake.Core/IO/IGlobber.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,12 @@ public interface IGlobber
/// <see cref="Path" /> instances matching the specified pattern.
/// </returns>
IEnumerable<Path> Match(GlobPattern pattern, GlobberSettings settings);

/// <summary>
/// Returns a list of <see cref="IFileSystemInfo"/> matching the specified pattern.
/// </summary>
/// <param name="pattern">The pattern to match.</param>
/// <returns>A list of <see cref="IFileSystemInfo"/>.</returns>
IEnumerable<IFileSystemInfo> GetFileSystemInfos(string pattern);
}
}
11 changes: 11 additions & 0 deletions src/Cake.Testing/FakeDirectory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text.RegularExpressions;
using Cake.Core.IO;

Expand Down Expand Up @@ -276,5 +277,15 @@ private static Regex CreateRegex(string pattern)
pattern = pattern.Replace(".", "\\.").Replace("*", ".*").Replace("?", ".{1}");
return new Regex(pattern, RegexOptions.Singleline | RegexOptions.Compiled);
}

/// <inheritdoc/>
public IEnumerable<IFileSystemInfo> GetFileSystemInfos(string filter, SearchScope scope)
{
// بنجمع المجلدات والملفات الوهمية
var directories = GetDirectories(filter, scope).Cast<IFileSystemInfo>();
var files = GetFiles(filter, scope).Cast<IFileSystemInfo>();

return directories.Concat(files);
}
}
}
15 changes: 15 additions & 0 deletions src/Cake.Testing/FakeFileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,20 @@ IFile IFileSystem.GetFile(FilePath path)
{
return GetFile(path);
}

/// <inheritdoc/>
public IFileSystemInfo GetFileSystemInfo(DirectoryPath path)
{
if (path == null)
{
throw new ArgumentNullException(nameof(path));
}
var directory = GetDirectory(path);
if (directory.Exists)
{
return directory;
}
return GetFile(path.FullPath);
}
}
}