-
Notifications
You must be signed in to change notification settings - Fork 89
Expand file tree
/
Copy pathFileAnalyzer.cs
More file actions
129 lines (113 loc) · 3.92 KB
/
FileAnalyzer.cs
File metadata and controls
129 lines (113 loc) · 3.92 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
using Packaging.Targets.IO;
using System;
using System.Collections.ObjectModel;
using System.IO;
namespace Packaging.Targets.Rpm
{
/// <summary>
/// Provides a very basic implementation of the <see cref="IFileAnalyzer"/> class. To get the details that are consistent
/// with those found in real-world RPM packages, more complete parsing of ELF files is required to get the full list of
/// dependencies, as well as the class (description).
/// </summary>
internal class FileAnalyzer : IFileAnalyzer
{
/// <inheritdoc/>
public virtual Collection<PackageDependency> DetermineRequires(ArchiveEntry entry)
{
// For now, report no dependencies at all. Could be enhanced if ELF parsing is available.
var dependencies = new Collection<PackageDependency>();
return dependencies;
}
/// <inheritdoc/>
public virtual Collection<PackageDependency> DetermineProvides(ArchiveEntry entry)
{
// For now, report no provides at all. Could be enhanced if ELF parsing is available.
var dependencies = new Collection<PackageDependency>();
return dependencies;
}
/// <inheritdoc/>
public virtual RpmFileFlags DetermineFlags(ArchiveEntry entry)
{
if (entry.Type == ArchiveEntryType.Doc)
{
return RpmFileFlags.RPMFILE_DOC;
}
else
{
return RpmFileFlags.None;
}
}
/// <inheritdoc/>
public virtual RpmFileColor DetermineColor(ArchiveEntry entry)
{
// Only support ELF32 and ELF64
switch (entry.Type)
{
case ArchiveEntryType.Executable32:
return RpmFileColor.RPMFC_ELF32;
case ArchiveEntryType.Executable64:
return RpmFileColor.RPMFC_ELF64;
case ArchiveEntryType.NetAssembly:
return RpmFileColor.RPMFC_INCLUDE;
default:
return RpmFileColor.RPMFC_BLACK;
}
}
/// <inheritdoc/>
public virtual bool IsExecutable(ArchiveEntry entry)
{
throw new NotSupportedException();
}
/// <inheritdoc/>
public virtual string DetermineClass(ArchiveEntry entry)
{
// Very simplistic implementation - non-executable files are considered to be tet files.
if (entry.Mode.HasFlag(LinuxFileMode.S_IFDIR))
{
return "directory";
}
if (entry.Mode.HasFlag(LinuxFileMode.S_IFLNK))
{
return string.Empty;
}
if (entry.Type == ArchiveEntryType.NetAssembly)
{
return "mono";
}
if (entry.TargetPath.EndsWith(".svg"))
{
return "SVG Scalable Vector Graphics image";
}
else if (entry.TargetPath.EndsWith(".ttf"))
{
return "TrueType font data";
}
else if (entry.TargetPath.EndsWith(".woff"))
{
return string.Empty;
}
else if (entry.TargetPath.EndsWith(".woff2"))
{
return string.Empty;
}
else if (entry.TargetPath.EndsWith(".eot"))
{
return string.Empty;
}
if (!entry.Mode.HasFlag(LinuxFileMode.S_IXGRP)
&& !entry.Mode.HasFlag(LinuxFileMode.S_IXOTH)
&& !entry.Mode.HasFlag(LinuxFileMode.S_IXUSR))
{
if (entry.IsAscii)
{
return "ASCII text";
}
else
{
return "UTF-8 Unicode text";
}
}
return string.Empty;
}
}
}