Skip to content

Commit 4bfd6fd

Browse files
committed
PS: Revert psmodule path file extraction.
1 parent 1978e10 commit 4bfd6fd

File tree

6 files changed

+7
-72
lines changed

6 files changed

+7
-72
lines changed

powershell/extractor/Semmle.Extraction.PowerShell.Standalone/Options.cs

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ public override bool HandleFlag(string key, bool value)
2424
case "dry-run":
2525
SkipExtraction = value;
2626
return true;
27-
case "skip-psmodulepath-files":
28-
SkipPSModulePathFiles = value;
29-
return true;
3027
default:
3128
return base.HandleFlag(key, value);
3229
}
@@ -77,7 +74,7 @@ public override void InvalidArgument(string argument)
7774
/// <summary>
7875
/// List of extensions to include.
7976
/// </summary>
80-
public IList<string> Extensions { get; } = new List<string>() { ".ps1", ".psd1" };
77+
public IList<string> Extensions { get; } = new List<string>() { ".ps1" };
8178

8279
/// <summary>
8380
/// Files/patterns to exclude.
@@ -130,12 +127,6 @@ private static FileInfo[] GetDefaultFiles()
130127
/// </summary>
131128
public bool SkipExtraction { get; private set; } = false;
132129

133-
/// <summary>
134-
/// Whether to extract files in the paths found in the `PSModulePath`
135-
/// environment variable.
136-
/// </summary>
137-
public bool SkipPSModulePathFiles { get; private set; } = false;
138-
139130
/// <summary>
140131
/// Whether errors were encountered parsing the arguments.
141132
/// </summary>
@@ -167,14 +158,13 @@ public static void ShowHelp(System.IO.TextWriter output)
167158
"PowerShell# standalone extractor\n\nExtracts PowerShell scripts in the current directory.\n"
168159
);
169160
output.WriteLine("Additional options:\n");
170-
output.WriteLine(" <path> Use the provided path instead.");
161+
output.WriteLine(" <path> Use the provided path instead.");
171162
output.WriteLine(
172-
" --exclude:xxx Exclude a file or directory (can be specified multiple times)"
163+
" --exclude:xxx Exclude a file or directory (can be specified multiple times)"
173164
);
174-
output.WriteLine(" --dry-run Stop before extraction");
175-
output.WriteLine(" --threads:nnn Specify number of threads (default=CPU cores)");
176-
output.WriteLine(" --verbose Produce more output");
177-
output.WriteLine(" --skip-psmodulepath-files Avoid extracting source files in paths specified by the PSModulePath environment variable.");
165+
output.WriteLine(" --dry-run Stop before extraction");
166+
output.WriteLine(" --threads:nnn Specify number of threads (default=CPU cores)");
167+
output.WriteLine(" --verbose Produce more output");
178168
}
179169

180170
private Options() { }

powershell/extractor/Semmle.Extraction.PowerShell.Standalone/Program.cs

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ public static int Main(string[] args)
4545

4646
output.Log(Severity.Info, "Running PowerShell standalone extractor");
4747
var sourceFiles = options
48-
.Files.Concat(GetPSModuleFiles(options))
49-
.Where(d =>
48+
.Files.Where(d =>
5049
options.Extensions.Contains(
5150
d.Extension,
5251
StringComparer.InvariantCultureIgnoreCase
@@ -88,30 +87,6 @@ public static int Main(string[] args)
8887
return 0;
8988
}
9089

91-
private static String[] GetPSModulePaths()
92-
{
93-
return Environment.GetEnvironmentVariable("PSModulePath")?.Split(Path.PathSeparator)
94-
?? Array.Empty<string>();
95-
}
96-
97-
private static IEnumerable<FileInfo> GetPSModuleFiles(Options options)
98-
{
99-
if(options.SkipPSModulePathFiles)
100-
{
101-
return Array.Empty<FileInfo>();
102-
}
103-
104-
return GetPSModulePaths()
105-
.Where(d => Directory.Exists(d))
106-
.SelectMany(d =>
107-
{
108-
var di = new DirectoryInfo(d);
109-
return di.Exists
110-
? di.GetFiles("*.*", SearchOption.AllDirectories)
111-
: new FileInfo[] { new(d) };
112-
});
113-
}
114-
11590
private class ExtractionProgress : IProgressMonitor
11691
{
11792
public ExtractionProgress(ILogger output)

powershell/extractor/Semmle.Extraction.PowerShell/Entities/Base/File.cs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using System;
33
using System.Collections.Generic;
44
using System.IO;
5-
using System.Linq;
65

76
namespace Semmle.Extraction.PowerShell.Entities
87
{
@@ -15,18 +14,6 @@ protected File(PowerShellContext cx, string path)
1514
{
1615
}
1716

18-
private static string[] GetPSModulePaths()
19-
{
20-
return Environment.GetEnvironmentVariable("PSModulePath")?.Split(Path.PathSeparator)
21-
?? Array.Empty<string>();
22-
}
23-
24-
private bool PathIsInPSModulePath()
25-
{
26-
// Check if f's path is inside one of the paths in $Env:PSModulePath
27-
return GetPSModulePaths().Any(originalPath.StartsWith);
28-
}
29-
3017
public override void Populate(TextWriter trapFile)
3118
{
3219
trapFile.files(this, TransformedPath.Value);
@@ -36,11 +23,6 @@ public override void Populate(TextWriter trapFile)
3623
trapFile.containerparent(Extraction.Entities.Folder.Create(PowerShellContext, dir), this);
3724
}
3825

39-
if(PathIsInPSModulePath())
40-
{
41-
trapFile.is_in_psmodule_path(this);
42-
}
43-
4426
try
4527
{
4628
System.Text.Encoding encoding;

powershell/extractor/Semmle.Extraction/Tuples.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,5 @@ public static void locations_default(this System.IO.TextWriter trapFile, SourceL
3232
{
3333
trapFile.WriteTuple("locations_default", label, file, startLine, startCol, endLine, endCol);
3434
}
35-
36-
public static void is_in_psmodule_path(this System.IO.TextWriter trapFile, Entities.File file) {
37-
trapFile.WriteTuple("is_in_psmodule_path", file);
38-
}
3935
}
4036
}

powershell/ql/lib/semmle/code/powershell/File.qll

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,6 @@ class File extends Container, @file {
209209
not this.isStub()
210210
}
211211

212-
predicate isInPSModulePath() {
213-
is_in_psmodule_path(this)
214-
}
215-
216212
/** Holds if this file is a library. */
217213
predicate fromLibrary() {
218214
not this.getBaseName() = "" and

powershell/ql/lib/semmlecode.powershell.dbscheme

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,6 @@ containerparent(
4141
unique int child: @container ref
4242
);
4343

44-
is_in_psmodule_path(
45-
int file: @file ref
46-
);
47-
4844
/* Comments */
4945
comment_entity(
5046
unique int id: @comment_entity,

0 commit comments

Comments
 (0)