void* pakfire_free(void* mem);
char* pakfire_strdup(const char* s);
+int pakfire_string_startswith(const char* s, const char* prefix);
char* pakfire_format_size(double size);
char* pakfire_format_date(time_t t);
pakfire_pool_has_changed(repo->pakfire);
}
+// Returns a default priority based on the repository configuration
+static int pakfire_repo_auto_priority(PakfireRepo repo) {
+ // The @system repository has a priority of zero
+ if (pakfire_repo_is_installed_repo(repo) == 0)
+ return 0;
+
+ if (repo->appdata->baseurl) {
+ // HTTPS
+ if (pakfire_string_startswith(repo->appdata->baseurl, "https://"))
+ return 75;
+
+ // HTTP
+ if (pakfire_string_startswith(repo->appdata->baseurl, "http://"))
+ return 75;
+
+ // Local path
+ if (pakfire_string_startswith(repo->appdata->baseurl, "dir://"))
+ return 50;
+ }
+
+ // Default to 100
+ return 100;
+}
+
PAKFIRE_EXPORT int pakfire_repo_get_priority(PakfireRepo repo) {
- return repo->repo->priority;
+ if (repo->repo->priority > 0)
+ return repo->repo->priority;
+
+ return pakfire_repo_auto_priority(repo);
}
PAKFIRE_EXPORT void pakfire_repo_set_priority(PakfireRepo repo, int priority) {
return r;
}
+int pakfire_string_startswith(const char* s, const char* prefix) {
+ return strncmp(s, prefix, strlen(prefix));
+}
+
char* pakfire_format_size(double size) {
char string[STRING_SIZE];
const char* units[] = {" ", "k", "M", "G", "T", NULL};
return keyfile
- @property
- def priority(self):
- priority = self.settings.get("priority", None)
- if not priority is None:
- # Try to concert the given input to an integer
- # and return the value if possible.
- try:
- priority = int(priority)
- return priority
-
- except ValueError:
- pass
-
- # The default priority is 100.
- priority = 100
-
- url2priority = {
- "file://" : 50,
- "http://" : 75,
- }
-
- for url, prio in list(url2priority.items()):
- if self.baseurl.startswith(url):
- priority = prio
- break
-
- return priority
-
def make_downloader(self):
"""
Creates a downloader that can be used to download