Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Add PLIST_MD5 type in compat Add writting of new +MANIFEST after the conversion Now test presence of +MANIFEST before falling back to pkg_compat Need refactoring, full conversion should goes to pkg_compat
Baptiste Daroussin committed 15 years ago
commit 1f0cdafeb3f07ae6c11e7068c0ee2e1aac518896
parent 1f042be
3 files changed +68 -23
modified libpkg/pkg_compat.c
@@ -64,6 +64,9 @@ pkg_compat_plist_cmd(char *s, char **arg)
		} else if (!strncmp(*arg, "DEPORIGIN:", 10)) {
			*arg += 10;
			return PLIST_DEPORIGIN;
+
		} else if (!strncmp(*arg, "MD5:", 4)) {
+
			*arg += 4;
+
			return PLIST_MD5;
		}
		return PLIST_COMMENT;
	} else if (!strcmp(cmd, "ignore"))
modified libpkg/pkg_compat.h
@@ -11,7 +11,7 @@ enum plist_t {
	PLIST_NAME, PLIST_UNEXEC, PLIST_SRC, PLIST_DISPLAY,
	PLIST_PKGDEP, PLIST_CONFLICTS, PLIST_MTREE, PLIST_DIR_RM,
	PLIST_IGNORE_INST, PLIST_OPTION, PLIST_ORIGIN, PLIST_DEPORIGIN,
-
	PLIST_NOINST
+
	PLIST_NOINST, PLIST_MD5
};


modified libpkg/pkgdb_cache.c
@@ -25,14 +25,16 @@ pkgdb_cache_rebuild(const char *pkg_dbdir, const char *cache_path)
	char *value;
	char tmppath[MAXPATHLEN];
	char contentpath[MAXPATHLEN];
+
	char manifestpath[MAXPATHLEN];
	struct cdb_make cdb_make;
	DIR *dir;
	struct dirent *portsdir;
	struct stat st;
-
	FILE *content;
-
	char *content_buffer;
+
	FILE *content, *manifest;
+
	char *content_buffer = NULL;
	cJSON *manifest_json;
	int nb_packages = 0;
+
	char *manifest_out;


	strlcpy(tmppath, pkg_dbdir, MAXPATHLEN);
@@ -49,31 +51,67 @@ pkgdb_cache_rebuild(const char *pkg_dbdir, const char *cache_path)
		while ((portsdir = readdir(dir)) != NULL) {
			if (strcmp(portsdir->d_name, ".") != 0 &&
					strcmp(portsdir->d_name, "..") !=0) {
-
				strlcpy(contentpath, pkg_dbdir, MAXPATHLEN);
-
				strlcat(contentpath, "/", MAXPATHLEN);
-
				strlcat(contentpath, portsdir->d_name, MAXPATHLEN);
-
				strlcat(contentpath, "/+CONTENTS", MAXPATHLEN);

-
				if (stat(contentpath, &st) == -1) {
-
					warn("Unable to read %s informations, skipping:", portsdir->d_name);
+
				if (portsdir->d_type != DT_DIR)
					continue;
-
				}
-

-
				if ((content = fopen(contentpath, "r")) == NULL) {
-
					warn("Unable to read %s file, skipping", contentpath);
-
					continue;
-
				}

-
				content_buffer = malloc(st.st_size + 1);
-
				fread(content_buffer, st.st_size, 1, content);
-
				fclose(content);
+
				strlcpy(manifestpath, pkg_dbdir, MAXPATHLEN);
+
				strlcat(manifestpath, "/", MAXPATHLEN);
+
				strlcat(manifestpath, portsdir->d_name, MAXPATHLEN);
+
				strlcat(manifestpath, "/+MANIFEST", MAXPATHLEN);
+

+
				if (stat(manifestpath, &st) == -1) {
+
					warnx("No manifest for %s trying old format", portsdir->d_name);
+
					strlcpy(contentpath, pkg_dbdir, MAXPATHLEN);
+
					strlcat(contentpath, "/", MAXPATHLEN);
+
					strlcat(contentpath, portsdir->d_name, MAXPATHLEN);
+
					strlcat(contentpath, "/+CONTENTS", MAXPATHLEN);
+
					if (stat(contentpath, &st) == -1 ) {
+
						warn("No content for %s, should be corrupted, skipping", portsdir->d_name);
+
						continue;
+
					}
+

+
					if ((content = fopen(contentpath, "r")) == NULL) {
+
						warn("Unable to read %s file, skipping", contentpath);
+
						continue;
+
					}
+
					
+
					content_buffer = malloc(st.st_size + 1);
+
					fread(content_buffer, st.st_size, 1, content);
+
					fclose(content);

-
				manifest_json = cJSON_Parse(content_buffer);
-
				if (manifest_json == 0)
					manifest_json = pkg_compat_converter(content_buffer);
-

-
				if (manifest_json == 0)
-
					continue; /* skipping */
+
					
+
					if (manifest_json == 0) {
+
						warnx("%s: Manifest corrupted, skipping", portsdir->d_name);
+
						continue;
+
					}
+

+
					/* writing the manifest to end
+
					 * conversion */
+
					manifest_out = cJSON_Print(manifest_json);
+
					manifest = fopen(manifestpath, "w+");
+
					fprintf(manifest, "%s", manifest_out);
+
					fclose(manifest);
+

+
				} else {
+

+
					if ((content = fopen(manifestpath, "r")) == NULL) {
+
						warn("Unable to read %s file, skipping", manifestpath);
+
						continue;
+
					}
+

+
					content_buffer = malloc(st.st_size + 1);
+
					fread(content_buffer, st.st_size, 1, content);
+
					fclose(content);
+

+
					manifest_json = cJSON_Parse(content_buffer);
+

+
					if (manifest_json == 0) {
+
						warnx("%s: Manifest corrputed, skipping", portsdir->d_name);
+
						continue;
+
					}
+
				}

				nb_packages++;
				snprintf(key, BUFSIZ, "%d_name",nb_packages);
@@ -82,7 +120,11 @@ pkgdb_cache_rebuild(const char *pkg_dbdir, const char *cache_path)
				snprintf(key, BUFSIZ, "%d_version", nb_packages);
				value = cJSON_GetObjectItem(manifest_json, "version")->valuestring;
				cdb_make_add(&cdb_make, key, strlen(key), value, strlen(value));
+

				cJSON_Delete(manifest_json);
+

+
				if (content_buffer != NULL)
+
					free(content_buffer);
			}
		}
	}