[Midnightbsd-cvs] src [9629] trunk/lib/libmport: Add partial support for multi argument sample syntax.

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Fri Oct 6 17:10:30 EDT 2017


Revision: 9629
          http://svnweb.midnightbsd.org/src/?rev=9629
Author:   laffer1
Date:     2017-10-06 17:10:30 -0400 (Fri, 06 Oct 2017)
Log Message:
-----------
Add partial support for multi argument sample syntax. @sample src dest.  Does not remove the created file on uninstall.

Modified Paths:
--------------
    trunk/lib/libmport/bundle_read_install_pkg.c
    trunk/lib/libmport/create_primative.c

Modified: trunk/lib/libmport/bundle_read_install_pkg.c
===================================================================
--- trunk/lib/libmport/bundle_read_install_pkg.c	2017-10-06 18:31:33 UTC (rev 9628)
+++ trunk/lib/libmport/bundle_read_install_pkg.c	2017-10-06 21:10:30 UTC (rev 9629)
@@ -55,7 +55,8 @@
 static int create_package_row(mportInstance *, mportPackageMeta *);
 static int create_categories(mportInstance *mport, mportPackageMeta *pkg);
 static int create_depends(mportInstance *mport, mportPackageMeta *pkg);
-static int create_sample_file(const char *file);
+static int create_sample_file(mportInstance *mport, char *cwd, const char *file);
+static char** parse_sample(char *input);
 static int mark_complete(mportInstance *, mportPackageMeta *);
 static int mport_bundle_read_get_assetlist(mportInstance *mport, mportPackageMeta *pkg, mportAssetList **alist_p, enum phase);
 
@@ -210,20 +211,59 @@
 	return MPORT_OK;
 }
 
+static char**
+parse_sample(char *input)
+{
+	char **ap, **argv;
+	argv = calloc(3, sizeof(char *));
+
+	if (argv == NULL)
+		return NULL;
+
+	for (ap = argv; (*ap = strsep(&input, " \t")) != NULL;) {
+		if (**ap != '\0') {
+			if (++ap >= &argv[3])
+				break;
+		}
+	}
+
+	return argv;
+}
+
 static int
-create_sample_file(const char *file)
+create_sample_file(mportInstance *mport, char *cwd, const char *file)
 {
-	char nonSample[FILENAME_MAX];
-	strlcpy(nonSample, file, FILENAME_MAX);
-	char *sptr = strcasestr(nonSample, ".sample");
-	if (sptr != NULL) {
-		sptr[0] = '\0'; /* hack off .sample */
-		if (!mport_file_exists(nonSample)) {
-			if (mport_copy_file(file, nonSample) != MPORT_OK)
+	char nonSample[FILENAME_MAX * 2];
+	char secondFile[FILENAME_MAX];
+
+ 	strlcpy(nonSample, file, FILENAME_MAX * 2);
+	(void) snprintf(nonSample, FILENAME_MAX, "%s%s/%s", mport->root, cwd, file);
+	char** fileargv = parse_sample(nonSample);
+
+	if (fileargv[1] != '\0') {
+		if (fileargv[1][0] == '/')
+			strlcpy(secondFile, fileargv[1], FILENAME_MAX);
+		else
+			(void) snprintf(secondFile, FILENAME_MAX, "%s%s/%s", mport->root, cwd, fileargv[1]);
+
+		if (!mport_file_exists(secondFile)) {
+			if (mport_copy_file(fileargv[0], secondFile) != MPORT_OK)
 				RETURN_CURRENT_ERROR;
 		}
+	} else {
+		/* single file */
+		char *sptr = strcasestr(nonSample, ".sample");
+		if (sptr != NULL) {
+			sptr[0] = '\0'; /* hack off .sample */
+			if (!mport_file_exists(nonSample)) {
+				if (mport_copy_file(file, nonSample) != MPORT_OK)
+					RETURN_CURRENT_ERROR;
+			}
+		}
 	}
 
+	free(fileargv);
+
 	return MPORT_OK;
 }
 
@@ -458,6 +498,17 @@
 					goto ERROR;
 
 				(void) snprintf(file, FILENAME_MAX, "%s%s/%s", mport->root, cwd, e->data);
+
+				if (e->type == ASSET_SAMPLE)
+					for (int ch = 0; ch < FILENAME_MAX; ch++) {
+						if (file[ch] == '\0')
+							break;
+						if (file[ch] == ' ' || file[ch] == '\t') {
+							file[ch] = '\0';
+							break;
+						}
+					}
+						
 				if (entry == NULL) {
 					SET_ERROR(MPORT_ERR_FATAL, "Unexpected EOF with archive file");
 					goto ERROR;
@@ -549,7 +600,7 @@
 					}
 
 					/* for sample files, if we don't have an existing file, make a new one */
-					if (e->type == ASSET_SAMPLE && create_sample_file(file) != MPORT_OK) {
+					if (e->type == ASSET_SAMPLE && create_sample_file(mport, cwd, e->data) != MPORT_OK) {
 						SET_ERRORX(MPORT_ERR_FATAL, "Unable to create sample file from %s",
 						           file);
 						goto ERROR;

Modified: trunk/lib/libmport/create_primative.c
===================================================================
--- trunk/lib/libmport/create_primative.c	2017-10-06 18:31:33 UTC (rev 9628)
+++ trunk/lib/libmport/create_primative.c	2017-10-06 21:10:30 UTC (rev 9629)
@@ -176,6 +176,15 @@
         (void)snprintf(file, FILENAME_MAX, "%s/%s", cwd, e->data);
       }
 
+      if (e->type == ASSET_SAMPLE) {
+          for (int ch = 0; ch < FILENAME_MAX; ch++) {
+		if (file[ch] == '\0')
+			break;
+		if (file[ch] == ' ' || file[ch] == '\t')
+			file[ch] = '\0';
+	  } 
+      }
+
       if (lstat(file, &st) != 0) {
         sqlite3_finalize(stmnt);
         RETURN_ERRORX(MPORT_ERR_FATAL, "Could not stat %s: %s", file, strerror(errno));
@@ -558,6 +567,18 @@
 			(void) snprintf(filename, FILENAME_MAX, "%s/%s/%s", extra->sourcedir, cwd, e->data);
 		}
 
+		if (e->type == ASSET_SAMPLE) {
+			// eat the second filename if it exists.
+			for (int ch = 0; ch < FILENAME_MAX; ch++) {
+				if (filename[ch] == '\0')
+					break;
+				if (filename[ch] == ' ' || filename[ch] == '\t') {
+					filename[ch] = '\0';
+					break;
+				}
+			}
+		}
+
 		if (mport_bundle_write_add_file(bundle, filename, e->data) != MPORT_OK)
 			RETURN_CURRENT_ERROR;
 	}



More information about the Midnightbsd-cvs mailing list