aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2020-01-22 01:37:38 -0500
committerJoseph Hunkeler <jhunkeler@gmail.com>2020-01-22 01:37:38 -0500
commit444ccb0a7c5f88f408bee91db052d00794791ccc (patch)
tree542eb4129ad07ef71dac601e7ca199607681054a
parent1a427e0e5e16bc75d05a961a4001923b26b7b2f8 (diff)
downloadspmc-444ccb0a7c5f88f408bee91db052d00794791ccc.tar.gz
Groundhog day 2
-rw-r--r--include/spm.h2
-rw-r--r--src/fs.c1
-rw-r--r--src/internal_cmd.c53
-rw-r--r--src/manifest.c17
-rw-r--r--src/spm.c2
5 files changed, 71 insertions, 4 deletions
diff --git a/include/spm.h b/include/spm.h
index 4107a03..bf04fd3 100644
--- a/include/spm.h
+++ b/include/spm.h
@@ -283,7 +283,7 @@ void dep_show(Dependencies **deps);
// manifest.c
Manifest *manifest_from(const char *package_dir);
Manifest *manifest_read(char *file_or_url);
-int manifest_write(Manifest *info);
+int manifest_write(Manifest *info, const char *dest);
void manifest_free(Manifest *info);
ManifestPackage *manifest_search(Manifest *info, const char *package);
diff --git a/src/fs.c b/src/fs.c
index e3f4d1f..42172f9 100644
--- a/src/fs.c
+++ b/src/fs.c
@@ -9,6 +9,7 @@
* @return
*/
FSTree *fstree(const char *_path) {
+ // TODO: Add an argument to filter FSTree content... probably a callback function
FTS *parent = NULL;
FTSENT *node = NULL;
FSTree *fsdata = NULL;
diff --git a/src/internal_cmd.c b/src/internal_cmd.c
index 7b46e2c..2390671 100644
--- a/src/internal_cmd.c
+++ b/src/internal_cmd.c
@@ -9,6 +9,7 @@
static char *internal_commands[] = {
"mkprefixbin", "generate prefix manifest (binary)",
"mkprefixtext", "generate prefix manifest (text)",
+ "mkmanifest", "generate package repository manifest",
"rpath_set", "modify binary RPATH",
"rpath_autoset", "determine nearest lib directory and set RPATH",
NULL, NULL,
@@ -83,6 +84,55 @@ int mkprefix_interface(int argc, char **argv) {
/**
*
*/
+void mkmanifest_interface_usage(void) {
+ printf("usage: mkmanifest [package_dir] [output_dir]");
+}
+
+/**
+ * Generate a named package manifest
+ * @param argc
+ * @param argv
+ * @return value of `manifest_write`
+ */
+int mkmanifest_interface(int argc, char **argv) {
+ if (argc < 1) {
+ mkmanifest_interface_usage();
+ return -1;
+ }
+ Manifest *manifest = NULL;
+ char *pkgdir = NULL;
+ char path[PATH_MAX];
+ memset(path, '\0', PATH_MAX);
+
+ if (argc == 2) {
+ pkgdir = argv[1];
+ }
+ else {
+ pkgdir = SPM_GLOBAL.package_dir;
+ }
+
+ if (argc > 2) {
+ strcpy(path, argv[2]);
+ }
+ else {
+ strcpy(path, SPM_MANIFEST_FILENAME);
+ }
+
+ if (exists(pkgdir) != 0) {
+ return -1;
+ }
+
+ manifest = manifest_from(pkgdir);
+ if (manifest == NULL) {
+ return -2;
+ }
+
+ return manifest_write(manifest, path);
+}
+
+/**
+ *
+ */
void rpath_set_interface_usage(void) {
printf("usage: rpath_set {file} {rpath}\n");
}
@@ -178,6 +228,9 @@ int internal_cmd(int argc, char **argv) {
if (strcmp(command, "mkprefixbin") == 0 || strcmp(command, "mkprefixtext") == 0) {
return mkprefix_interface(arg_count, arg_array);
}
+ else if (strcmp(command, "mkmanifest") == 0) {
+ return mkmanifest_interface(arg_count, arg_array);
+ }
else if (strcmp(command, "rpath_set") == 0) {
return rpath_set_interface(arg_count, arg_array);
}
diff --git a/src/manifest.c b/src/manifest.c
index 5ed3bab..c401cb2 100644
--- a/src/manifest.c
+++ b/src/manifest.c
@@ -14,6 +14,7 @@
Manifest *manifest_from(const char *package_dir) {
FSTree *fsdata = NULL;
fsdata = fstree(package_dir);
+
Manifest *info = (Manifest *)calloc(1, sizeof(Manifest));
info->records = fsdata->files_length;
info->packages = (ManifestPackage **) calloc(info->records + 1, sizeof(ManifestPackage *));
@@ -98,13 +99,25 @@ void manifest_free(Manifest *info) {
/**
* Write a `Manifest` to the configuration directory
* @param info
+ * @param outfile
* @return
*/
-int manifest_write(Manifest *info) {
+int manifest_write(Manifest *info, const char *outfile) {
char *reqs = NULL;
char path[PATH_MAX];
memset(path, '\0', sizeof(path));
- strcpy(path, SPM_GLOBAL.package_manifest);
+
+ if (outfile == NULL) {
+ strcpy(path, SPM_GLOBAL.package_manifest);
+ }
+ else {
+ strcpy(path, outfile);
+ }
+
+ if (endswith(path, SPM_MANIFEST_FILENAME) != 0) {
+ strcat(path, DIRSEPS);
+ strcat(path, SPM_MANIFEST_FILENAME);
+ }
FILE *fp = fopen(path, "w+");
#ifdef _DEBUG
diff --git a/src/spm.c b/src/spm.c
index 4cfffd9..0e2a725 100644
--- a/src/spm.c
+++ b/src/spm.c
@@ -72,7 +72,7 @@ int main(int argc, char *argv[], char *arge[]) {
}
else if (strcmp(arg, "--reindex") == 0) {
Manifest *info = manifest_from(SPM_GLOBAL.package_dir);
- manifest_write(info);
+ manifest_write(info, SPM_GLOBAL.package_manifest);
manifest_free(info);
exit(0);
}