Skip to content

Commit

Permalink
Added Filter and Filter Regexpes to spec and code.
Browse files Browse the repository at this point in the history
They don't do anything yet.
For KSP-CKAN#129.
  • Loading branch information
pjf committed Oct 31, 2014
1 parent 72bdd02 commit 30c6044
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 8 deletions.
19 changes: 19 additions & 0 deletions CKAN.schema
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,14 @@
"description" : "Where file should be installed to",
"$ref" : "#/definitions/install_to"
},
"filter" : {
"description" : "List of files and directories that should be filtered from the install",
"$ref" : "#/definitions/one_or_more_strings"
},
"filter_regexp" : {
"description" : "List of regexps that should filter files from this install",
"$ref" : "#/definitions/one_or_more_strings"
},
"requires" : {
"description" : "A required mod for this install part",
"$ref" : "#/definitions/identifier"
Expand Down Expand Up @@ -303,6 +311,17 @@
"uniqueItems" : true
}
]
},
"one_or_more_strings" : {
"description" : "One or more strings",
"oneOf" : [
{ "type" : "string" },
{
"type" : "array",
"items" : { "type" : "string" },
"uniqueItems" : true
}
]
}
}
}
15 changes: 11 additions & 4 deletions CKAN/CKAN/Module.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,19 @@ public class ResourcesDescriptor
public KerbalStuffResourceDescriptor kerbalstuff;
}

// [JsonObject(MemberSerialization.OptIn)]
public class ModuleInstallDescriptor : InstallableDescriptor
{
public string description;
public bool optional;
public bool overwrite;
public string requires;
public string description; // Discouraged, maybe...
public bool optional; // Discouraged GH #113
public bool overwrite; // Discouraged GH #113
public string requires; // Discouraged GH #113

[JsonConverter(typeof (JsonSingleOrArrayConverter<string>))]
public List<string> filter;

[JsonConverter(typeof (JsonSingleOrArrayConverter<string>))]
public List<string> filter_regexp;
}

public enum License
Expand Down
4 changes: 2 additions & 2 deletions CKAN/CKAN/ModuleInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -610,15 +610,15 @@ internal static List<InstallableFile> FindInstallableFiles(InstallableDescriptor
}

// Is there a better way to extract a tree?
string filter = "^" + stanza.file + "(/|$)";
string wanted_filter = "^" + stanza.file + "(/|$)";

// O(N^2) solution, as we're walking the zipfile for each stanza.
// Surely there's a better way, although this is fast enough we may not care.

foreach (ZipEntry entry in zipfile)
{
// Skip things we don't want.
if (!Regex.IsMatch(entry.Name, filter))
if (!Regex.IsMatch(entry.Name, wanted_filter))
{
continue;
}
Expand Down
12 changes: 12 additions & 0 deletions CKAN/Tests/CKAN/Module.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@ public void MetaData()
Assert.AreEqual("https://github.com/KSP-KOS/KOS/issues", module.resources.bugtracker.ToString());
}

[Test]
public void FilterRead()
{
CkanModule module = CkanModule.FromJson(TestData.DogeCoinFlag_101());

// Assert known things about this mod.
Assert.IsNotNull(module.install[0].filter);
Assert.IsNotNull(module.install[0].filter_regexp);

Assert.AreEqual(2, module.install[0].filter.Count);
}

}
}

4 changes: 3 additions & 1 deletion CKAN/Tests/TestData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ public static string DogeCoinFlag_101()
""install"": [
{
""file"": ""DogeCoinFlag-1.01/GameData/DogeCoinFlag"",
""install_to"": ""GameData""
""install_to"": ""GameData"",
""filter"" : [ ""Thumbs.db"", ""INSTALL.md"" ],
""filter_regexp"" : ""\\.bak$""
}
],
""resources"": {
Expand Down
15 changes: 14 additions & 1 deletion Spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,20 @@ mandatory directives:
Paths will be preserved, but directories will *only*
be created when installing to `GameData` or `Tutorial`.

An install directive may also include the following optional fields:
Optionally, an install directive may filter the files to install using:

- `filter` : A string, or list of strings, of file parts that should not
be installed. These are treated as literal things which must match a
file name or directory. Examples of filters may be `Thumbs.db`,
or `Source`. Filters are considered case-insensitive.
- `filter_regexp` : A string, or list of strings, which are treated as
case-sensitive C# regular expressions whch are matched against the
full paths from the installing zip-file. If a file matches the regular
expression, it is not installed.

An install directive may also include the following optional fields.
Use of these fields are *discouraged*, and they may become deprecated
in the future.

- `depends`: Indicates this install directive should only be triggered
if the required mod has already been installed.
Expand Down

0 comments on commit 30c6044

Please sign in to comment.