@@ -149,8 +149,9 @@ get_file_count(mportInstance *mport, char *pkg_name, int *file_total)
149149 __block char * err ;
150150
151151 if (mport_db_prepare (mport -> db , & count ,
152- "SELECT COUNT(*) FROM stub.assets WHERE (type=%i or type=%i or type=%i or type=%i) AND pkg=%Q" ,
153- ASSET_FILE , ASSET_SAMPLE , ASSET_SHELL , ASSET_FILE_OWNER_MODE , pkg_name ) != MPORT_OK ) {
152+ "SELECT COUNT(*) FROM stub.assets WHERE (type=%i or type=%i or type=%i or type=%i or type=%i) AND pkg=%Q" ,
153+ ASSET_FILE , ASSET_SAMPLE , ASSET_SHELL , ASSET_FILE_OWNER_MODE , ASSET_SAMPLE_OWNER_MODE ,
154+ pkg_name ) != MPORT_OK ) {
154155 sqlite3_finalize (count );
155156 RETURN_CURRENT_ERROR ;
156157 }
@@ -236,8 +237,10 @@ create_sample_file(mportInstance *mport, char *cwd, const char *file)
236237 char nonSample [FILENAME_MAX * 2 ];
237238 char secondFile [FILENAME_MAX ];
238239
239- strlcpy (nonSample , file , FILENAME_MAX * 2 );
240- (void ) snprintf (nonSample , FILENAME_MAX , "%s%s/%s" , mport -> root , cwd , file );
240+ if (file [0 ] != '/' )
241+ (void ) snprintf (nonSample , FILENAME_MAX , "%s%s/%s" , mport -> root , cwd , file );
242+ else
243+ strlcpy (nonSample , file , FILENAME_MAX * 2 );
241244 char * * fileargv = parse_sample (nonSample );
242245
243246 if (fileargv [1 ] != '\0' ) {
@@ -256,8 +259,9 @@ create_sample_file(mportInstance *mport, char *cwd, const char *file)
256259 if (sptr != NULL ) {
257260 sptr [0 ] = '\0' ; /* hack off .sample */
258261 if (!mport_file_exists (nonSample )) {
259- if (mport_copy_file (file , nonSample ) != MPORT_OK )
262+ if (mport_copy_file (file , nonSample ) != MPORT_OK ) {
260263 RETURN_CURRENT_ERROR ;
264+ }
261265 }
262266 }
263267 }
@@ -494,12 +498,18 @@ do_actual_install(mportInstance *mport, mportBundleRead *bundle, mportPackageMet
494498 case ASSET_SHELL :
495499 /* FALLS THROUGH */
496500 case ASSET_SAMPLE :
501+ /* FALLS THROUGH */
502+ case ASSET_SAMPLE_OWNER_MODE :
497503 if (mport_bundle_read_next_entry (bundle , & entry ) != MPORT_OK )
498504 goto ERROR ;
499505
500- (void ) snprintf (file , FILENAME_MAX , "%s%s/%s" , mport -> root , cwd , e -> data );
506+ if (e -> data [0 ] == '/' ) {
507+ (void ) snprintf (file , FILENAME_MAX , "%s" , e -> data );
508+ } else {
509+ (void ) snprintf (file , FILENAME_MAX , "%s%s/%s" , mport -> root , cwd , e -> data );
510+ }
501511
502- if (e -> type == ASSET_SAMPLE )
512+ if (e -> type == ASSET_SAMPLE || e -> type == ASSET_SAMPLE_OWNER_MODE )
503513 for (int ch = 0 ; ch < FILENAME_MAX ; ch ++ ) {
504514 if (file [ch ] == '\0' )
505515 break ;
@@ -525,7 +535,7 @@ do_actual_install(mportInstance *mport, mportBundleRead *bundle, mportPackageMet
525535 }
526536
527537 if (S_ISREG (sb .st_mode )) {
528- if (e -> type == ASSET_FILE_OWNER_MODE ) {
538+ if (e -> type == ASSET_FILE_OWNER_MODE || e -> type == ASSET_SAMPLE_OWNER_MODE ) {
529539 /* Test for owner and group settings, otherwise roll with our default. */
530540 if (e -> owner != NULL && e -> group != NULL && e -> owner [0 ] != '\0' &&
531541 e -> group [0 ] != '\0' ) {
@@ -575,7 +585,8 @@ do_actual_install(mportInstance *mport, mportBundleRead *bundle, mportPackageMet
575585 SET_ERRORX (MPORT_ERR_FATAL , "Unable to stat file %s" , file );
576586 goto ERROR ;
577587 }
578- if (e -> type == ASSET_FILE_OWNER_MODE && e -> mode != NULL ) {
588+ if ((e -> type == ASSET_SAMPLE_OWNER_MODE ||
589+ e -> type == ASSET_FILE_OWNER_MODE ) && e -> mode != NULL ) {
579590 if ((set = setmode (e -> mode )) == NULL ) {
580591 SET_ERROR (MPORT_ERR_FATAL , "Unable to set mode" );
581592 goto ERROR ;
@@ -598,14 +609,16 @@ do_actual_install(mportInstance *mport, mportBundleRead *bundle, mportPackageMet
598609 if (e -> type == ASSET_SHELL && mport_shell_register (file ) != MPORT_OK ) {
599610 goto ERROR ;
600611 }
612+ }
601613
602614 /* for sample files, if we don't have an existing file, make a new one */
603- if (e -> type == ASSET_SAMPLE && create_sample_file (mport , cwd , e -> data ) != MPORT_OK ) {
615+ if ((e -> type == ASSET_SAMPLE || e -> type == ASSET_SAMPLE_OWNER_MODE ) &&
616+ create_sample_file (mport , cwd , e -> data ) != MPORT_OK ) {
604617 SET_ERRORX (MPORT_ERR_FATAL , "Unable to create sample file from %s" ,
605618 file );
606619 goto ERROR ;
607620 }
608- }
621+
609622
610623 (mport -> progress_step_cb )(++ file_count , file_total , file );
611624
@@ -628,7 +641,7 @@ do_actual_install(mportInstance *mport, mportBundleRead *bundle, mportPackageMet
628641 return ;
629642 }
630643 if (e -> type == ASSET_FILE || e -> type == ASSET_SAMPLE || e -> type == ASSET_SHELL ||
631- e -> type == ASSET_FILE_OWNER_MODE ) {
644+ e -> type == ASSET_FILE_OWNER_MODE || e -> type == ASSET_SAMPLE_OWNER_MODE ) {
632645 /* don't put the root in the database! */
633646 if (sqlite3_bind_text (insert , 2 , filePtr + strlen (mport -> root ), -1 , SQLITE_STATIC ) !=
634647 SQLITE_OK ) {
@@ -758,6 +771,7 @@ do_actual_install(mportInstance *mport, mportBundleRead *bundle, mportPackageMet
758771 return ;
759772 }
760773
774+ sqlite3_clear_bindings (insert );
761775 sqlite3_reset (insert );
762776 });
763777
@@ -946,7 +960,7 @@ display_pkg_msg(mportInstance *mport, mportBundleRead *bundle, mportPackageMeta
946960 /* if we couldn't stat the file, we assume there isn't a pkg-msg */
947961 return MPORT_OK ;
948962
949- if ((file = fopen (filename , "r " )) == NULL )
963+ if ((file = fopen (filename , "re " )) == NULL )
950964 RETURN_ERRORX (MPORT_ERR_FATAL , "Couldn't open %s: %s" , filename , strerror (errno ));
951965
952966 if ((buf = (char * ) calloc ((size_t ) (st .st_size + 1 ), sizeof (char ))) == NULL )
0 commit comments