-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathFileSystem.qll
93 lines (73 loc) · 2.54 KB
/
FileSystem.qll
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/** Provides classes for working with files and folders. */
import Location
private import codeql.util.FileSystem
private module Input implements InputSig {
abstract class ContainerBase extends @container {
abstract string getAbsolutePath();
ContainerBase getParentContainer() { containerparent(result, this) }
string toString() { result = this.getAbsolutePath() }
}
class FolderBase extends ContainerBase, @folder {
override string getAbsolutePath() { folders(this, result) }
}
class FileBase extends ContainerBase, @file {
override string getAbsolutePath() { files(this, result) }
}
predicate hasSourceLocationPrefix = sourceLocationPrefix/1;
}
private module Impl = Make<Input>;
/** A file or folder. */
class Container extends Impl::Container, Top {
override string toString() { result = Impl::Container.super.toString() }
}
/** A folder. */
class Folder extends Container, Impl::Folder {
override string getAPrimaryQlClass() { result = "Folder" }
}
/**
* A file.
*
* Note that `File` extends `Container` as it may be a `jar` file.
*/
class File extends Container, Impl::File {
override string getAPrimaryQlClass() { result = "File" }
/** Holds if this is a (Java or Kotlin) source file. */
predicate isSourceFile() { this.isJavaSourceFile() or this.isKotlinSourceFile() }
/** Holds if this is a Java source file. */
predicate isJavaSourceFile() { this.getExtension() = "java" }
/** Holds if this is a Kotlin source file. */
predicate isKotlinSourceFile() { this.getExtension() = "kt" }
}
/**
* A Java archive file with a ".jar" extension.
*/
class JarFile extends File {
JarFile() { this.getExtension() = "jar" }
/**
* Gets the main attribute with the specified `key`
* from this JAR file's manifest.
*/
string getManifestMainAttribute(string key) { jarManifestMain(this, key, result) }
/**
* Gets the "Specification-Version" main attribute
* from this JAR file's manifest.
*/
string getSpecificationVersion() {
result = this.getManifestMainAttribute("Specification-Version")
}
/**
* Gets the "Implementation-Version" main attribute
* from this JAR file's manifest.
*/
string getImplementationVersion() {
result = this.getManifestMainAttribute("Implementation-Version")
}
/**
* Gets the per-entry attribute for the specified `entry` and `key`
* from this JAR file's manifest.
*/
string getManifestEntryAttribute(string entry, string key) {
jarManifestEntries(this, entry, key, result)
}
override string getAPrimaryQlClass() { result = "JarFile" }
}