|
|
@@ -261,7 +261,7 @@ private int uininstall() {
|
|
|
|
|
|
// Do files and symlinks first
|
|
|
foreach (var resource in manifest.provides.where(r => r.value.file_type != Usm.ManifestFileType.DIRECTORY)) {
|
|
|
- var path = paths.get_suggested_path(resource.key);
|
|
|
+ var path = paths.get_suggested_path_for_resource(resource.key);
|
|
|
printerr(@"Deleting resource $(resource.key) from $path...");
|
|
|
try {
|
|
|
var file = File.new_for_path(path);
|
|
|
@@ -281,7 +281,7 @@ private int uininstall() {
|
|
|
|
|
|
// Do directories last
|
|
|
foreach (var resource in manifest.provides.where(r => r.value.file_type == Usm.ManifestFileType.DIRECTORY)) {
|
|
|
- var path = paths.get_suggested_path(resource.key);
|
|
|
+ var path = paths.get_suggested_path_for_resource(resource.key);
|
|
|
printerr(@"Deleting resource $(resource.key) from $path...");
|
|
|
try {
|
|
|
var file = File.new_for_path(path);
|
|
|
@@ -437,6 +437,10 @@ public static Invercargill.DataStructures.Vector<string> autoprovides_scan_tree(
|
|
|
var true_path = file.get_path().substring(install_root.length);
|
|
|
var type = get_local_resource_type(true_path);
|
|
|
var relative_path = get_relative_path_for_type(true_path, type);
|
|
|
+ // Remove leading slash from relative_path if present
|
|
|
+ if (relative_path.has_prefix("/")) {
|
|
|
+ relative_path = relative_path.substring(1);
|
|
|
+ }
|
|
|
provides.add(@"$type:$relative_path");
|
|
|
|
|
|
}
|
|
|
@@ -454,80 +458,52 @@ private static string get_local_resource_type(string path) {
|
|
|
// Remove leading slash if present
|
|
|
string clean_path = path.has_prefix("/") ? path.substring(1) : path;
|
|
|
|
|
|
- // Define all resource types with their path patterns
|
|
|
- var resource_patterns = new Invercargill.DataStructures.Dictionary<string, Invercargill.DataStructures.Vector<string>>();
|
|
|
-
|
|
|
- // Helper function to create a Vector from a string array
|
|
|
- Invercargill.DataStructures.Vector<string> create_vector(string[] patterns) {
|
|
|
- var vector = new Invercargill.DataStructures.Vector<string>();
|
|
|
- foreach (var pattern in patterns) {
|
|
|
- vector.add(pattern);
|
|
|
- }
|
|
|
- return vector;
|
|
|
- }
|
|
|
-
|
|
|
- // Binary executables
|
|
|
- resource_patterns.set("bin", create_vector(new string[] {"usr/bin/"}));
|
|
|
- resource_patterns.set("sbin", create_vector(new string[] {"usr/sbin/"}));
|
|
|
-
|
|
|
- // Libraries
|
|
|
- resource_patterns.set("lib", create_vector(new string[] {"usr/lib/", "usr/lib64/", "lib/", "lib64/"}));
|
|
|
- resource_patterns.set("libexec", create_vector(new string[] {"usr/libexec/"}));
|
|
|
-
|
|
|
- // Headers
|
|
|
- resource_patterns.set("inc", create_vector(new string[] {"usr/include/"}));
|
|
|
-
|
|
|
- // Share resources
|
|
|
- resource_patterns.set("app", create_vector(new string[] {"usr/share/applications/"}));
|
|
|
- resource_patterns.set("info", create_vector(new string[] {"usr/share/info/"}));
|
|
|
- resource_patterns.set("man", create_vector(new string[] {"usr/share/man/"}));
|
|
|
- resource_patterns.set("locale", create_vector(new string[] {"usr/share/locale/"}));
|
|
|
- resource_patterns.set("vapi", create_vector(new string[] {"usr/share/vala/vapi/", "usr/share/vala-0.56/vapi/"}));
|
|
|
- resource_patterns.set("gir", create_vector(new string[] {"usr/share/gir-1.0/"}));
|
|
|
- resource_patterns.set("tag", create_vector(new string[] {"usr/share/usm-tags/"}));
|
|
|
- resource_patterns.set("res", create_vector(new string[] {"usr/share/"}));
|
|
|
-
|
|
|
- // Package config and typelib (more specific types)
|
|
|
- resource_patterns.set("pc", create_vector(new string[] {"usr/lib/pkgconfig/", "usr/lib64/pkgconfig/", "usr/share/pkgconfig/"}));
|
|
|
- resource_patterns.set("typelib", create_vector(new string[] {"usr/lib64/girepository-1.0/", "usr/lib/girepository-1.0/", "lib64/girepository-1.0/", "lib/girepository-1.0/"}));
|
|
|
-
|
|
|
- // Configuration and optional
|
|
|
- resource_patterns.set("cfg", create_vector(new string[] {"etc/"}));
|
|
|
- resource_patterns.set("opt", create_vector(new string[] {"opt/"}));
|
|
|
+ // Create a temporary Paths object to get the default paths
|
|
|
+ var default_paths = new Usm.Paths.defaults();
|
|
|
|
|
|
// Find all matching resource types and calculate directory traversals
|
|
|
var matching_types = new Invercargill.DataStructures.Vector<string>();
|
|
|
var traversal_counts = new Invercargill.DataStructures.Vector<int>();
|
|
|
|
|
|
// Define all resource types to check
|
|
|
- string[] types_to_check = {
|
|
|
- "bin", "sbin", "lib", "libexec", "inc", "app", "info", "man",
|
|
|
- "locale", "vapi", "gir", "tag", "res", "pc", "typelib", "cfg", "opt"
|
|
|
+ Usm.ResourceType[] types_to_check = {
|
|
|
+ Usm.ResourceType.BINARY,
|
|
|
+ Usm.ResourceType.SUPER_BINARY,
|
|
|
+ Usm.ResourceType.LIBRARY,
|
|
|
+ Usm.ResourceType.LIBRARY_EXECUTABLE,
|
|
|
+ Usm.ResourceType.INCLUDE,
|
|
|
+ Usm.ResourceType.APPLICATION,
|
|
|
+ Usm.ResourceType.INFO_PAGE,
|
|
|
+ Usm.ResourceType.MANUAL_PAGE,
|
|
|
+ Usm.ResourceType.LOCALE,
|
|
|
+ Usm.ResourceType.VALA_API,
|
|
|
+ Usm.ResourceType.GOBJECT_IR,
|
|
|
+ Usm.ResourceType.TAG,
|
|
|
+ Usm.ResourceType.RESOURCE,
|
|
|
+ Usm.ResourceType.PKG_CONFIG,
|
|
|
+ Usm.ResourceType.TYPELIB,
|
|
|
+ Usm.ResourceType.CONFIGURATION,
|
|
|
+ Usm.ResourceType.OPTIONAL
|
|
|
};
|
|
|
|
|
|
foreach (var type in types_to_check) {
|
|
|
- try {
|
|
|
- var patterns = resource_patterns.get(type);
|
|
|
-
|
|
|
- for (int i = 0; i < patterns.peek_count(); i++) {
|
|
|
- var pattern = patterns[i];
|
|
|
- if (clean_path.has_prefix(pattern)) {
|
|
|
- var relative_path = clean_path.substring(pattern.length);
|
|
|
- // Count slashes (directory traversals) in the relative path
|
|
|
- int traversal_count = 0;
|
|
|
- for (int j = 0; j < relative_path.length; j++) {
|
|
|
- if (relative_path[j] == '/') {
|
|
|
- traversal_count++;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- matching_types.add(type);
|
|
|
- traversal_counts.add(traversal_count);
|
|
|
- break; // Found a matching pattern for this type, move to next type
|
|
|
+ var suggested_path = default_paths.get_suggested_base_path_for_type(type);
|
|
|
+ // Remove the destination prefix (usually "/") to get the relative path
|
|
|
+ var relative_suggested_path = suggested_path.has_prefix("/") ?
|
|
|
+ suggested_path.substring(1) : suggested_path;
|
|
|
+
|
|
|
+ if (clean_path.has_prefix(relative_suggested_path)) {
|
|
|
+ var relative_path = clean_path.substring(relative_suggested_path.length);
|
|
|
+ // Count slashes (directory traversals) in the relative path
|
|
|
+ int traversal_count = 0;
|
|
|
+ for (int j = 0; j < relative_path.length; j++) {
|
|
|
+ if (relative_path[j] == '/') {
|
|
|
+ traversal_count++;
|
|
|
}
|
|
|
}
|
|
|
- } catch (Error e) {
|
|
|
- // Type not found, continue to next type
|
|
|
+
|
|
|
+ matching_types.add(type.to_string());
|
|
|
+ traversal_counts.add(traversal_count);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -554,58 +530,22 @@ private static string get_relative_path_for_type(string path, string type) {
|
|
|
// Remove leading slash if present
|
|
|
string clean_path = path.has_prefix("/") ? path.substring(1) : path;
|
|
|
|
|
|
- // Helper function to create a Vector from a string array
|
|
|
- Invercargill.DataStructures.Vector<string> create_vector(string[] patterns) {
|
|
|
- var vector = new Invercargill.DataStructures.Vector<string>();
|
|
|
- foreach (var pattern in patterns) {
|
|
|
- vector.add(pattern);
|
|
|
- }
|
|
|
- return vector;
|
|
|
- }
|
|
|
-
|
|
|
- // Define all resource types with their path patterns (same as in get_local_resource_type)
|
|
|
- var resource_patterns = new Invercargill.DataStructures.Dictionary<string, Invercargill.DataStructures.Vector<string>>();
|
|
|
-
|
|
|
- // Binary executables
|
|
|
- resource_patterns.set("bin", create_vector(new string[] {"usr/bin/"}));
|
|
|
- resource_patterns.set("sbin", create_vector(new string[] {"usr/sbin/"}));
|
|
|
-
|
|
|
- // Libraries
|
|
|
- resource_patterns.set("lib", create_vector(new string[] {"usr/lib/", "usr/lib64/", "lib/", "lib64/"}));
|
|
|
- resource_patterns.set("libexec", create_vector(new string[] {"usr/libexec/"}));
|
|
|
+ // Create a temporary Paths object to get the default paths
|
|
|
+ var default_paths = new Usm.Paths.defaults();
|
|
|
|
|
|
- // Headers
|
|
|
- resource_patterns.set("inc", create_vector(new string[] {"usr/include/"}));
|
|
|
-
|
|
|
- // Share resources
|
|
|
- resource_patterns.set("app", create_vector(new string[] {"usr/share/applications/"}));
|
|
|
- resource_patterns.set("info", create_vector(new string[] {"usr/share/info/"}));
|
|
|
- resource_patterns.set("man", create_vector(new string[] {"usr/share/man/"}));
|
|
|
- resource_patterns.set("locale", create_vector(new string[] {"usr/share/locale/"}));
|
|
|
- resource_patterns.set("vapi", create_vector(new string[] {"usr/share/vala/vapi/", "usr/share/vala-0.56/vapi/"}));
|
|
|
- resource_patterns.set("gir", create_vector(new string[] {"usr/share/gir-1.0/"}));
|
|
|
- resource_patterns.set("tag", create_vector(new string[] {"usr/share/usm-tags/"}));
|
|
|
- resource_patterns.set("res", create_vector(new string[] {"usr/share/"}));
|
|
|
-
|
|
|
- // Package config and typelib (more specific types)
|
|
|
- resource_patterns.set("pc", create_vector(new string[] {"usr/lib/pkgconfig/", "usr/lib64/pkgconfig/", "usr/share/pkgconfig/"}));
|
|
|
- resource_patterns.set("typelib", create_vector(new string[] {"usr/lib64/girepository-1.0/", "usr/lib/girepository-1.0/", "lib64/girepository-1.0/", "lib/girepository-1.0/"}));
|
|
|
-
|
|
|
- // Configuration and optional
|
|
|
- resource_patterns.set("cfg", create_vector(new string[] {"etc/"}));
|
|
|
- resource_patterns.set("opt", create_vector(new string[] {"opt/"}));
|
|
|
-
|
|
|
- // Find the matching pattern for the given type and extract relative path
|
|
|
try {
|
|
|
- var patterns = resource_patterns.get(type);
|
|
|
- for (int i = 0; i < patterns.peek_count(); i++) {
|
|
|
- var pattern = patterns[i];
|
|
|
- if (clean_path.has_prefix(pattern)) {
|
|
|
- return clean_path.substring(pattern.length);
|
|
|
- }
|
|
|
+ // Convert string type to ResourceType enum
|
|
|
+ var resource_type = Usm.ResourceType.from_string(type);
|
|
|
+ var suggested_path = default_paths.get_suggested_base_path_for_type(resource_type);
|
|
|
+ // Remove the destination prefix (usually "/") to get the relative path
|
|
|
+ var relative_suggested_path = suggested_path.has_prefix("/") ?
|
|
|
+ suggested_path.substring(1) : suggested_path;
|
|
|
+
|
|
|
+ if (clean_path.has_prefix(relative_suggested_path)) {
|
|
|
+ return clean_path.substring(relative_suggested_path.length);
|
|
|
}
|
|
|
} catch (Error e) {
|
|
|
- // Type not found in dictionary, fall through to default case
|
|
|
+ // Type not found, fall through to default case
|
|
|
}
|
|
|
|
|
|
// Default case - return the path as-is
|