diff -u -r epm/aix.c epm-4.2/aix.c --- epm/aix.c 2007-12-12 11:12:06.000000000 +0100 +++ epm-4.2/aix.c 2007-12-11 15:31:05.000000000 +0100 @@ -46,8 +46,7 @@ * Local functions... */ -static int aix_addfile(int type, const char *src, const char *dst, - int num_dirs, aixdir_t **dirs); +static int aix_addfile(file_t *file, int num_dirs, aixdir_t **dirs); static void aix_fileset(FILE *fp, const char *prodname, dist_t *dist, const char *subpackage); static char *aix_version(const char *version); @@ -201,7 +200,8 @@ printf("%s -> %s...\n", file->src, filename); if (copy_file(filename, file->src, file->mode, pwd ? pwd->pw_uid : 0, - grp ? grp->gr_gid : 0)) + grp ? grp->gr_gid : 0, + strstr(file->options, "expand(")!=NULL, &file->size)) return (1); break; case 'i' : @@ -218,7 +218,8 @@ printf("%s -> %s...\n", file->src, filename); if (copy_file(filename, file->src, file->mode, - pwd ? pwd->pw_uid : 0, grp ? grp->gr_gid : 0)) + pwd ? pwd->pw_uid : 0, grp ? grp->gr_gid : 0, + strstr(file->options, "expand(")!=NULL, &file->size)) return (1); snprintf(filename, sizeof(filename), @@ -230,7 +231,8 @@ printf("%s -> %s...\n", file->src, filename); if (copy_file(filename, file->src, file->mode, - pwd ? pwd->pw_uid : 0, grp ? grp->gr_gid : 0)) + pwd ? pwd->pw_uid : 0, grp ? grp->gr_gid : 0, + strstr(file->options, "expand(")!=NULL, &file->size)) return (1); } break; @@ -312,25 +314,24 @@ */ static int /* O - New number dirs */ -aix_addfile(int type, /* I - Filetype */ - const char *src, /* I - Source path */ - const char *dst, /* I - Destination path */ +aix_addfile(file_t *file, /* IO - File structure */ int num_dirs, /* I - Number of directories */ aixdir_t **dirs) /* IO - Directories */ { int i, j; /* Looping vars */ int blocks; /* Blocks to add... */ - struct stat fileinfo; /* File information */ aixdir_t *temp; /* Temporary pointer */ char dstpath[1024], /* Destination path */ *dstptr; /* Pointer into destination */ + int type; /* file type converted to lower case */ + type = tolower(file->type); /* * Determine the destination path and block size... */ - strlcpy(dstpath, dst, sizeof(dstpath)); + strlcpy(dstpath, file->dst, sizeof(dstpath)); if (type == 'd') { @@ -343,10 +344,11 @@ if (type == 'l') blocks = 1; - else if (!stat(src, &fileinfo)) - blocks = (fileinfo.st_size + 511) / 512; else - blocks = 0; + { + sizeof_file(file); + blocks = (file->size + 511) / 512; + } } if (dstptr && *dstptr == '/' && dstptr > dstpath) @@ -456,8 +458,7 @@ for (i = dist->num_files, file = dist->files; i > 0; i --, file ++) if (file->subpackage == subpackage) - num_dirs = aix_addfile(tolower(file->type), file->src, file->dst, - num_dirs, &dirs); + num_dirs = aix_addfile(file, num_dirs, &dirs); for (i = 0; i < num_dirs; i ++) fprintf(fp, "%s %d\n", dirs[i].dst, dirs[i].blocks); @@ -524,7 +525,6 @@ FILE *fp; /* Control file */ char filename[1024], /* Destination filename */ prodfull[1024]; /* Full product name */ - struct stat fileinfo; /* File information */ command_t *c; /* Current command */ file_t *file; /* Current distribution file */ int configcount; /* Number of config files */ @@ -832,8 +832,8 @@ fprintf(fp, " class=apply,inventory,%s\n", prodfull); fputs(" type=FILE\n", fp); - if (!stat(file->src, &fileinfo)) - fprintf(fp, " size=%d\n", (int)fileinfo.st_size); + sizeof_file(file); + fprintf(fp, " size=%d\n", (int)file->size); fprintf(fp, " owner=%s\n", file->user); fprintf(fp, " group=%s\n", file->group); @@ -860,8 +860,8 @@ break; default : fputs(" type=FILE\n", fp); - if (!stat(file->src, &fileinfo)) - fprintf(fp, " size=%ld\n", (long)fileinfo.st_size); + sizeof_file(file); + fprintf(fp, " size=%ld\n", (long)file->size); break; } @@ -882,9 +882,9 @@ snprintf(filename, sizeof(filename), "%s/lpp.README", directory); if (dist->license[0]) - copy_file(filename, dist->license, 0644, 0, 0); + copy_file(filename, dist->license, 0644, 0, 0, 0, NULL); else if (dist->readme[0]) - copy_file(filename, dist->readme, 0644, 0, 0); + copy_file(filename, dist->readme, 0644, 0, 0, 0, NULL); else if ((fp = fopen(filename, "w")) != NULL) fclose(fp); else diff -u -r epm/bsd.c epm-4.2/bsd.c --- epm/bsd.c 2007-12-12 11:12:06.000000000 +0100 +++ epm-4.2/bsd.c 2007-12-11 15:32:29.000000000 +0100 @@ -354,7 +354,8 @@ printf("%s -> %s...\n", file->src, filename); if (copy_file(filename, file->src, file->mode, pwd ? pwd->pw_uid : 0, - grp ? grp->gr_gid : 0)) + grp ? grp->gr_gid : 0, + strstr(file->options, "expand(")!=NULL, &file->size)) return (1); break; case 'i' : @@ -365,7 +366,8 @@ printf("%s -> %s...\n", file->src, filename); if (copy_file(filename, file->src, file->mode, pwd ? pwd->pw_uid : 0, - grp ? grp->gr_gid : 0)) + grp ? grp->gr_gid : 0, + strstr(file->options, "expand(")!=NULL, &file->size)) return (1); break; case 'd' : diff -u -r epm/deb.c epm-4.2/deb.c --- epm/deb.c 2007-12-12 11:12:06.000000000 +0100 +++ epm-4.2/deb.c 2007-12-11 15:33:33.000000000 +0100 @@ -534,7 +534,8 @@ printf("%s -> %s...\n", file->src, filename); if (copy_file(filename, file->src, file->mode, pwd ? pwd->pw_uid : 0, - grp ? grp->gr_gid : 0)) + grp ? grp->gr_gid : 0, + strstr(file->options, "expand(")!=NULL, &file->size)) return (1); break; case 'i' : @@ -545,7 +546,8 @@ printf("%s -> %s...\n", file->src, filename); if (copy_file(filename, file->src, file->mode, pwd ? pwd->pw_uid : 0, - grp ? grp->gr_gid : 0)) + grp ? grp->gr_gid : 0, + strstr(file->options, "expand(")!=NULL, &file->size)) return (1); break; case 'd' : diff -u -r epm/dist.c epm-4.2/dist.c --- epm/dist.c 2007-12-12 11:12:06.000000000 +0100 +++ epm-4.2/dist.c 2007-12-11 16:45:01.000000000 +0100 @@ -65,7 +65,7 @@ */ static int compare_files(const file_t *f0, const file_t *f1); -static void expand_name(char *buffer, char *name, size_t bufsize); +static int expand_name(char *buffer, char *name, size_t bufsize); static char *get_file(const char *filename, char *buffer, size_t size); static char *get_inline(const char *term, FILE *fp, char *buffer, size_t size); @@ -88,6 +88,24 @@ #define SKIP_IFSAT 16 /* Set if an #if statement has been satisfied */ #define SKIP_MASK 7 /* Bits to look at */ +/* + * exported function to expand variables in a buffer + * similar to static function expand_name() + */ +int expand_variables(char *buffer, size_t bufsize) +{ + char *expand; + int rc = 0; + + expand = strdup(buffer); + rc = expand_name(buffer, expand, bufsize); + + free(expand); + + return rc; +} + + /* * 'add_command()' - Add a command to the distribution... @@ -829,7 +847,13 @@ */ line[0] = buf[0]; /* Don't expand initial $ */ - expand_name(line + 1, buf + 1, sizeof(line) - 1); + if(expand_name(line + 1, buf + 1, sizeof(line) - 1) != 0) + { + fprintf(stderr, + "epm: Variable expansion in list file failed for line\n" + " %s\n",buf); + return (NULL); + } /* * Check line for config stuff... @@ -1135,6 +1159,7 @@ file = add_file(dist, subpkg); + file->size = 0; file->type = type; file->mode = mode; strcpy(file->src, src); @@ -1156,6 +1181,7 @@ file = add_file(dist, subpkg); + file->size = 0; file->type = type; file->mode = mode; strcpy(file->src, src); @@ -1436,7 +1462,7 @@ * 'expand_name()' - Expand a filename with environment variables. */ -static void +static int expand_name(char *buffer, /* O - Output string */ char *name, /* I - Input string */ size_t bufsize) /* I - Size of output string */ @@ -1492,13 +1518,18 @@ buffer += strlen(buffer); } else + { fprintf(stderr, "epm: Variable \"%s\" undefined!\n", var); + return -1; + } } else *buffer++ = *name++; } *buffer = '\0'; + + return 0; } @@ -1514,7 +1545,7 @@ FILE *fp; /* File buffer */ struct stat info; /* File information */ char *expand; /* Expansion buffer */ - + int rc; /* Expansion return code */ if (stat(filename, &info)) { @@ -1561,9 +1592,18 @@ expand = strdup(buffer); - expand_name(buffer, expand, size); + rc = expand_name(buffer, expand, size); free(expand); + + if(rc != 0) + { + fprintf(stderr, + "epm: Variable expansion failed while reading File \"%s\"\n", + filename); + return (NULL); + } + } return (buffer); diff -u -r epm/epm.h epm-4.2/epm.h --- epm/epm.h 2007-12-12 11:12:06.000000000 +0100 +++ epm-4.2/epm.h 2007-12-11 16:38:33.000000000 +0100 @@ -174,6 +174,7 @@ { int type; /* Type of file */ mode_t mode; /* Permissions of file */ + size_t size; /* file size */ char user[32], /* Owner of file */ group[32], /* Group of file */ src[512], /* Source path */ @@ -254,8 +255,11 @@ const char *subpkg); extern file_t *add_file(dist_t *dist, const char *subpkg); extern char *add_subpackage(dist_t *dist, const char *subpkg); -extern int copy_file(const char *dst, const char *src, - mode_t mode, uid_t owner, gid_t group); +extern int copy_file(const char *dst, const char *src, mode_t mode, + uid_t owner, gid_t group, int expand, + size_t *sizePtr); +extern int sizeof_file(file_t *file); +extern int expand_variables(char *buffer, size_t bufsize); extern char *find_subpackage(dist_t *dist, const char *subpkg); extern void free_dist(dist_t *dist); extern const char *get_option(file_t *file, const char *name, const char *defval); @@ -316,7 +320,7 @@ extern int tar_close(tarf_t *tar); extern int tar_directory(tarf_t *tar, const char *srcpath, const char *dstpath); -extern int tar_file(tarf_t *tar, const char *filename); +extern int tar_file(tarf_t *tar, const char *filename, int expand); extern int tar_header(tarf_t *tar, int type, mode_t mode, off_t size, time_t mtime, const char *user, const char *group, const char *pathname, const char *linkname); diff -u -r epm/epminstall.c epm-4.2/epminstall.c --- epm/epminstall.c 2007-12-12 11:12:06.000000000 +0100 +++ epm-4.2/epminstall.c 2007-12-11 15:46:18.000000000 +0100 @@ -170,6 +170,7 @@ if ((file = find_file(dist, files[i])) == NULL) file = add_file(dist, NULL); + file->size = 0; file->type = 'd'; file->mode = mode & 07777; strlcpy(file->user, user, sizeof(file->user)); @@ -192,7 +193,10 @@ if (file == NULL || file->type != 'd') { if (!file) + { file = add_file(dist, NULL); + file->size = 0; + } if (stat(files[0], &fileinfo)) { @@ -249,6 +253,7 @@ file = add_file(dist, NULL); + file->size = 0; file->type = 'd'; file->mode = 0755; strlcpy(file->user, user, sizeof(file->user)); @@ -277,7 +282,10 @@ snprintf(dst, sizeof(dst), "%s/%s", files[num_files], src); if ((file = find_file(dist, dst)) == NULL) + { file = add_file(dist, NULL); + file->size = 0; + } if (stat(files[i], &fileinfo)) { diff -u -r epm/file.c epm-4.2/file.c --- epm/file.c 2007-12-12 11:12:06.000000000 +0100 +++ epm-4.2/file.c 2007-12-11 16:37:58.000000000 +0100 @@ -34,6 +34,8 @@ /* * 'copy_file()' - Copy a file... + * Can be used to compute the size of a modified file without actually + * creating it by calling with dst = NULL. */ int /* O - 0 on success, -1 on failure */ @@ -41,55 +43,94 @@ const char *src, /* I - Source file */ mode_t mode, /* I - Permissions */ uid_t owner, /* I - Owner ID */ - gid_t group) /* I - Group ID */ + gid_t group, /* I - Group ID */ + int expand, /* I - expand environment variables */ + size_t *sizePtr) /* O - return file size if != NULL */ { - FILE *dstfile, /* Destination file */ + FILE *dstfile = NULL, /* Destination file */ *srcfile; /* Source file */ char buffer[8192]; /* Copy buffer */ char *slash; /* Pointer to trailing slash */ size_t bytes; /* Number of bytes read/written */ - + size_t size = 0; /* counter for file size */ /* * Check that the destination directory exists... */ - strcpy(buffer, dst); - if ((slash = strrchr(buffer, '/')) != NULL) - *slash = '\0'; + if(dst != NULL) + { + strcpy(buffer, dst); + if ((slash = strrchr(buffer, '/')) != NULL) + *slash = '\0'; - if (access(buffer, F_OK)) - make_directory(buffer, 0755, owner, group); + if (access(buffer, F_OK)) + make_directory(buffer, 0755, owner, group); + } /* * Open files... */ - unlink(dst); - - if ((dstfile = fopen(dst, "wb")) == NULL) + if ((srcfile = fopen(src, "rb")) == NULL) { - fprintf(stderr, "epm: Unable to create \"%s\" -\n %s\n", dst, + fprintf(stderr, "epm: Unable to open \"%s\" -\n %s\n", src, strerror(errno)); return (-1); } - if ((srcfile = fopen(src, "rb")) == NULL) + if(dst != NULL) { - fclose(dstfile); unlink(dst); - fprintf(stderr, "epm: Unable to open \"%s\" -\n %s\n", src, - strerror(errno)); - return (-1); + if ((dstfile = fopen(dst, "wb")) == NULL) + { + fclose(srcfile); + fprintf(stderr, "epm: Unable to create \"%s\" -\n %s\n", dst, + strerror(errno)); + return (-1); + } } /* * Copy from src to dst... */ - while ((bytes = fread(buffer, 1, sizeof(buffer), srcfile)) > 0) - if (fwrite(buffer, 1, bytes, dstfile) < bytes) + if(expand) + { + int lineno = 0; + while(fgets(buffer, sizeof(buffer), srcfile) != NULL) + { + lineno++; + if(expand_variables(buffer, sizeof(buffer)) < 0) + { + fprintf(stderr, + "epm: Variable expansion failed at line %d while processing file\n" + " \"%s\"\n", + lineno, src); + + fclose(srcfile); + if(dst != NULL) + { + fclose(dstfile); + unlink(dst); + } + + return (-1); + } + if ((dst != NULL) && (fputs(buffer, dstfile) < 0)) + { + fprintf(stderr, "epm: Unable to write to \"%s\" -\n %s\n", dst, + strerror(errno)); + return (-1); + } + size += strlen(buffer); + } + } + else + { + while ((bytes = fread(buffer, 1, sizeof(buffer), srcfile)) > 0) + if ((dst != NULL) && (fwrite(buffer, 1, bytes, dstfile) < bytes)) { fprintf(stderr, "epm: Unable to write to \"%s\" -\n %s\n", dst, strerror(errno)); @@ -100,22 +141,54 @@ return (-1); } + size += bytes; + } /* * Close files, change permissions, and return... */ fclose(srcfile); - fclose(dstfile); + if(dst != NULL) + { + fclose(dstfile); + chmod(dst, mode); + chown(dst, owner, group); + } - chmod(dst, mode); - chown(dst, owner, group); + /* return file size */ + if(sizePtr != NULL) *sizePtr = size; return (0); } /* + * 'sizeof_file()' - Compute the size of a file + */ + +int /* O - 0 on success, -1 on failure */ +sizeof_file(file_t *file) /* IO - file structure */ +{ + struct stat fileinfo; + + if(file->size != 0) + { + if(strstr(file->options, "expand(")!=NULL) + return copy_file(NULL, file->src, 0, 0, 0, 1, &file->size); + else if (!stat(file->src, &fileinfo)) + { + file->size = fileinfo.st_size; + return 0; + } + else + return -1; + } + return 0; +} + + +/* * 'make_directory()' - Make a directory. */ diff -u -r epm/inst.c epm-4.2/inst.c --- epm/inst.c 2007-12-12 11:12:06.000000000 +0100 +++ epm-4.2/inst.c 2007-12-11 15:59:29.000000000 +0100 @@ -154,6 +154,7 @@ runlevels ++) { file = add_file(dist, dist->files[i].subpackage); + file->size = 0; file->type = 'l'; file->mode = 0; strcpy(file->user, "root"); @@ -195,6 +196,7 @@ */ file = add_file(dist, NULL); + file->size = 0; file->type = '1'; file->mode = 0555; strcpy(file->user, "root"); @@ -249,6 +251,7 @@ */ file = add_file(dist, NULL); + file->size = 0; file->type = '2'; file->mode = 0555; strcpy(file->user, "root"); @@ -303,6 +306,7 @@ */ file = add_file(dist, NULL); + file->size = 0; file->type = '3'; file->mode = 0555; strcpy(file->user, "root"); @@ -359,6 +363,7 @@ */ file = add_file(dist, NULL); + file->size = 0; file->type = '4'; file->mode = 0555; strcpy(file->user, "root"); @@ -532,7 +537,7 @@ return (-1); } - if (tar_file(tarfile, srcname) < 0) + if (tar_file(tarfile, srcname, 0) < 0) { if (Verbosity) puts(""); diff -u -r epm/osx.c epm-4.2/osx.c --- epm/osx.c 2007-12-12 11:12:06.000000000 +0100 +++ epm-4.2/osx.c 2007-12-11 16:00:59.000000000 +0100 @@ -117,7 +117,7 @@ snprintf(filename, sizeof(filename), "%s/MetaResources/License%s", directory, ext); - copy_file(filename, dist->license, 0644, 0, 0); + copy_file(filename, dist->license, 0644, 0, 0, 0, NULL); } if (dist->readme[0]) @@ -127,7 +127,7 @@ snprintf(filename, sizeof(filename), "%s/MetaResources/ReadMe%s", directory, ext); - copy_file(filename, dist->readme, 0644, 0, 0); + copy_file(filename, dist->readme, 0644, 0, 0, 0, NULL); } if (setup && (ext = strrchr(setup, '.')) != NULL && @@ -135,7 +135,7 @@ { snprintf(filename, sizeof(filename), "%s/MetaResources/background%s", directory, ext); - copy_file(filename, setup, 0644, 0, 0); + copy_file(filename, setup, 0644, 0, 0, 0, NULL); } snprintf(filename, sizeof(filename), "%s/MetaResources/Welcome.rtf", @@ -405,7 +405,7 @@ snprintf(filename, sizeof(filename), "%s/%s/Resources/License%s", directory, prodfull, ext); - copy_file(filename, dist->license, 0644, 0, 0); + copy_file(filename, dist->license, 0644, 0, 0, 0, NULL); } if (dist->readme[0]) @@ -415,7 +415,7 @@ snprintf(filename, sizeof(filename), "%s/%s/Resources/ReadMe%s", directory, prodfull, ext); - copy_file(filename, dist->readme, 0644, 0, 0); + copy_file(filename, dist->readme, 0644, 0, 0, 0, NULL); } if (setup && (ext = strrchr(setup, '.')) != NULL && @@ -423,7 +423,7 @@ { snprintf(filename, sizeof(filename), "%s/%s/Resources/background%s", directory, prodfull, ext); - copy_file(filename, setup, 0644, 0, 0); + copy_file(filename, setup, 0644, 0, 0, 0, NULL); } snprintf(filename, sizeof(filename), "%s/%s/Resources/Welcome.rtf", @@ -616,7 +616,8 @@ printf("%s -> %s...\n", file->src, filename); if (copy_file(filename, file->src, file->mode, pwd ? pwd->pw_uid : 0, - grp ? grp->gr_gid : 0)) + grp ? grp->gr_gid : 0, + strstr(file->options, "expand(")!=NULL, &file->size)) return (1); break; case 'i' : @@ -628,7 +629,8 @@ printf("%s -> %s...\n", file->src, filename); if (copy_file(filename, file->src, file->mode, pwd ? pwd->pw_uid : 0, - grp ? grp->gr_gid : 0)) + grp ? grp->gr_gid : 0, + strstr(file->options, "expand(")!=NULL, &file->size)) return (1); snprintf(filename, sizeof(filename), diff -u -r epm/pkg.c epm-4.2/pkg.c --- epm/pkg.c 2007-12-12 11:12:06.000000000 +0100 +++ epm-4.2/pkg.c 2007-12-11 16:41:48.000000000 +0100 @@ -27,13 +27,16 @@ #include "epm.h" +const char *expandedDir = "expanded"; /* * Local functions... */ static const char *pkg_path(const char *filename, const char *dirname); - +static const char *pkg_path_expand(file_t *file, + const char *dirname, + const char *outputDir); /* * 'make_pkg()' - Make an AT&T software distribution package. @@ -348,6 +351,7 @@ runlevels ++) { file = add_file(dist, dist->files[i].subpackage); + file->size = 0; file->type = 'l'; file->mode = 0; strcpy(file->user, "root"); @@ -374,6 +378,13 @@ strcpy(file->dst, filename); } + /* + * create temporary directory for files with variable expansion + */ + + snprintf(filename, sizeof(filename), "%s/%s", directory, expandedDir); + make_directory(filename, 0777, getuid(), getgid()); + /* * Write the prototype file for pkgmk... */ @@ -415,7 +426,7 @@ case 'c' : qprintf(fp, "e %s %s=%s %04o %s %s\n", file->subpackage ? file->subpackage : "none", - file->dst, pkg_path(file->src, current), + file->dst, pkg_path_expand(file, current, directory), file->mode, file->user, file->group); break; case 'd' : @@ -427,7 +438,7 @@ case 'i' : qprintf(fp, "f %s %s=%s %04o %s %s\n", file->subpackage ? file->subpackage : "none", - file->dst, pkg_path(file->src, current), + file->dst, pkg_path_expand(file, current, directory), file->mode, file->user, file->group); break; case 'l' : @@ -515,11 +526,51 @@ unlink(postremove); } + /* + * Remove temporary files... + */ + + if (!KeepFiles) + { + if (Verbosity) + puts("Removing temporary distribution files..."); + + run_command(NULL, "/bin/rm -rf %s/%s", directory, expandedDir); + + } + return (0); } /* + * 'pkg_path_expand()' - Expand variables if "expand()" option specified + * and return an absolute path of original or expanded file + */ + +static const char * /* O - Absolute filename */ +pkg_path_expand(file_t *file, /* IO - Source file structure */ + const char *dirname, /* I - Source directory */ + const char *outputDir) /* I - Output directory */ +{ + static char expandedName[1024]; /* name of expanded source file */ + const char *basename; /* pointer to source file's base name*/ + + if (strstr(file->options, "expand(")!=NULL) + { + basename = strrchr(file->src, '/'); + if(!basename) basename = file->src; + sprintf(expandedName, "%s/%s/%s", pkg_path(outputDir, dirname), + expandedDir, basename); + copy_file(expandedName, file->src, 0644, 0, 0, 1, &file->size); + return expandedName; + } + + return pkg_path(file->src, dirname); +} + + +/* * 'pkg_path()' - Return an absolute path for the prototype file. */ diff -u -r epm/portable.c epm-4.2/portable.c --- epm/portable.c 2007-12-12 11:12:06.000000000 +0100 +++ epm-4.2/portable.c 2007-12-11 16:21:04.000000000 +0100 @@ -370,7 +370,7 @@ return (-1); } - if (tar_file(tarfile, filename) < 0) + if (tar_file(tarfile, filename, 0) < 0) { fprintf(stderr, "epm: Error writing file data for setup.icns -\n %s\n", strerror(errno)); @@ -394,7 +394,7 @@ return (-1); } - if (tar_file(tarfile, filename) < 0) + if (tar_file(tarfile, filename, 0) < 0) { fprintf(stderr, "epm: Error writing file data for PkgInfo -\n %s\n", strerror(errno)); @@ -465,7 +465,7 @@ return (-1); } - if (tar_file(tarfile, filename) < 0) + if (tar_file(tarfile, filename, 0) < 0) { fprintf(stderr, "epm: Error writing file data for Info.plist -\n %s\n", strerror(errno)); @@ -535,7 +535,7 @@ return (-1); } - if (tar_file(tarfile, SetupProgram) < 0) + if (tar_file(tarfile, SetupProgram, 0) < 0) { fprintf(stderr, "epm: Error writing file data for setup -\n %s\n", strerror(errno)); @@ -568,7 +568,7 @@ return (-1); } - if (tar_file(tarfile, setup) < 0) + if (tar_file(tarfile, setup, 0) < 0) { fprintf(stderr, "epm: Error writing file data for %s -\n %s\n", setup_img, strerror(errno)); @@ -597,7 +597,7 @@ return (-1); } - if (tar_file(tarfile, types) < 0) + if (tar_file(tarfile, types, 0) < 0) { fprintf(stderr, "epm: Error writing file data for setup.types -\n %s\n", strerror(errno)); @@ -667,7 +667,7 @@ return (-1); } - if (tar_file(tarfile, filename) < 0) + if (tar_file(tarfile, filename, 0) < 0) { fprintf(stderr, "epm: Error writing file data for uninst.icns -\n %s\n", strerror(errno)); @@ -691,7 +691,7 @@ return (-1); } - if (tar_file(tarfile, filename) < 0) + if (tar_file(tarfile, filename, 0) < 0) { fprintf(stderr, "epm: Error writing file data for PkgInfo -\n %s\n", strerror(errno)); @@ -762,7 +762,7 @@ return (-1); } - if (tar_file(tarfile, filename) < 0) + if (tar_file(tarfile, filename, 0) < 0) { tar_close(tarfile); fprintf(stderr, "epm: Error writing file data for Info.plist -\n %s\n", @@ -804,7 +804,7 @@ return (-1); } - if (tar_file(tarfile, UninstProgram) < 0) + if (tar_file(tarfile, UninstProgram, 0) < 0) { fprintf(stderr, "epm: Error writing file data for uninst -\n %s\n", strerror(errno)); @@ -834,7 +834,7 @@ return (-1); } - if (tar_file(tarfile, setup) < 0) + if (tar_file(tarfile, setup, 0) < 0) { fprintf(stderr, "epm: Error writing file data for %s -\n %s\n", setup_img, strerror(errno)); @@ -1433,14 +1433,16 @@ if (dist->license[0]) { snprintf(filename, sizeof(filename), "%s/%s.license", directory, prodfull); - if (copy_file(filename, dist->license, 0444, getuid(), getgid())) + if (copy_file(filename, dist->license, 0444, getuid(), getgid(), + strstr(file->options, "expand(")!=NULL, &file->size)) return (1); } if (dist->readme[0]) { snprintf(filename, sizeof(filename), "%s/%s.readme", directory, prodfull); - if (copy_file(filename, dist->readme, 0444, getuid(), getgid())) + if (copy_file(filename, dist->readme, 0444, getuid(), getgid(), + strstr(file->options, "expand(")!=NULL, &file->size)) return (1); } @@ -1478,11 +1480,12 @@ tar_close(tarfile); return (1); } + sizeof_file(file); - rootsize += (srcstat.st_size + 1023) / 1024; + rootsize += (file->size + 1023) / 1024; if (isupper(file->type & 255)) - prootsize += (srcstat.st_size + 1023) / 1024; + prootsize += (file->size + 1023) / 1024; /* * Configuration files are extracted to the config file name with @@ -1502,7 +1505,7 @@ if (Verbosity > 1) printf("%s -> %s...\n", file->src, filename); - if (tar_header(tarfile, TAR_NORMAL, file->mode, srcstat.st_size, + if (tar_header(tarfile, TAR_NORMAL, file->mode, file->size, srcstat.st_mtime, file->user, file->group, filename, NULL) < 0) { @@ -1512,7 +1515,8 @@ return (1); } - if (tar_file(tarfile, file->src) < 0) + if (tar_file(tarfile, file->src, + strstr(file->options, "expand(")!=NULL) < 0) { fprintf(stderr, "epm: Error writing file data - %s\n", strerror(errno)); @@ -1588,10 +1592,17 @@ return (1); } - usrsize += (srcstat.st_size + 1023) / 1024; + if (sizeof_file(file)) + { + fprintf(stderr, "epm: Cannot compute size of %s\n", file->src); + tar_close(tarfile); + return (1); + } + + usrsize += (file->size + 1023) / 1024; if (isupper(file->type & 255)) - pusrsize += (srcstat.st_size + 1023) / 1024; + pusrsize += (file->size + 1023) / 1024; /* * Configuration files are extracted to the config file name with @@ -1611,7 +1622,8 @@ if (Verbosity > 1) printf("%s -> %s...\n", file->src, filename); - if (tar_header(tarfile, TAR_NORMAL, file->mode, srcstat.st_size, + if (tar_header(tarfile, TAR_NORMAL, file->mode, file->size, + srcstat.st_mtime, file->user, file->group, filename, NULL) < 0) { @@ -1621,7 +1633,8 @@ return (1); } - if (tar_file(tarfile, file->src) < 0) + if (tar_file(tarfile, file->src, + strstr(file->options, "expand(")!=NULL) < 0) { fprintf(stderr, "epm: Error writing file data - %s\n", strerror(errno)); @@ -1697,6 +1710,14 @@ return (1); } + if (sizeof_file(file)) + { + fprintf(stderr, "epm: Cannot compute size of %s\n", file->src); + tar_close(tarfile); + return (1); + } + + /* * Configuration files are extracted to the config file name with * .N appended; add a bit of script magic to check if the config @@ -1715,7 +1736,7 @@ if (Verbosity > 1) printf("%s -> %s...\n", file->src, filename); - if (tar_header(tarfile, TAR_NORMAL, file->mode, srcstat.st_size, + if (tar_header(tarfile, TAR_NORMAL, file->mode, file->size, srcstat.st_mtime, file->user, file->group, filename, NULL) < 0) { @@ -1725,7 +1746,8 @@ return (1); } - if (tar_file(tarfile, file->src) < 0) + if (tar_file(tarfile, file->src, + strstr(file->options, "expand(")!=NULL) < 0) { fprintf(stderr, "epm: Error writing file data - %s\n", strerror(errno)); @@ -1803,7 +1825,7 @@ if (Verbosity > 1) printf("%s -> %s...\n", file->src, filename); - if (tar_header(tarfile, TAR_NORMAL, file->mode, srcstat.st_size, + if (tar_header(tarfile, TAR_NORMAL, file->mode, file->size, srcstat.st_mtime, file->user, file->group, filename, NULL) < 0) { @@ -1813,7 +1835,8 @@ return (1); } - if (tar_file(tarfile, file->src) < 0) + if (tar_file(tarfile, file->src, + strstr(file->options, "expand(")!=NULL) < 0) { fprintf(stderr, "epm: Error writing file data - %s\n", strerror(errno)); @@ -2278,7 +2301,7 @@ return (-1); } - if (tar_file(tarfile, srcname) < 0) + if (tar_file(tarfile, srcname, 0) < 0) { fprintf(stderr, "epm: Error writing file data for %s -\n %s\n", dstname, strerror(errno)); diff -u -r epm/rpm.c epm-4.2/rpm.c --- epm/rpm.c 2007-12-12 11:12:06.000000000 +0100 +++ epm-4.2/rpm.c 2007-12-11 16:23:08.000000000 +0100 @@ -201,7 +201,8 @@ printf("%s -> %s...\n", file->src, filename); if (copy_file(filename, file->src, file->mode, pwd ? pwd->pw_uid : 0, - grp ? grp->gr_gid : 0)) + grp ? grp->gr_gid : 0, + strstr(file->options, "expand(")!=NULL, &file->size)) return (1); break; case 'i' : @@ -216,7 +217,8 @@ printf("%s -> %s...\n", file->src, filename); if (copy_file(filename, file->src, file->mode, pwd ? pwd->pw_uid : 0, - grp ? grp->gr_gid : 0)) + grp ? grp->gr_gid : 0, + strstr(file->options, "expand(")!=NULL, &file->size)) return (1); break; case 'd' : @@ -336,7 +338,7 @@ return (-1); } - if (tar_file(tarfile, SetupProgram) < 0) + if (tar_file(tarfile, SetupProgram, 0) < 0) { fprintf(stderr, "epm: Error writing file data for setup -\n %s\n", strerror(errno)); @@ -367,7 +369,7 @@ return (-1); } - if (tar_file(tarfile, setup) < 0) + if (tar_file(tarfile, setup, 0) < 0) { fprintf(stderr, "epm: Error writing file data for %s -\n %s\n", setup_img, strerror(errno)); @@ -395,7 +397,7 @@ return (-1); } - if (tar_file(tarfile, types) < 0) + if (tar_file(tarfile, types, 0) < 0) { fprintf(stderr, "epm: Error writing file data for setup.types -\n %s\n", strerror(errno)); @@ -428,7 +430,7 @@ return (-1); } - if (tar_file(tarfile, UninstProgram) < 0) + if (tar_file(tarfile, UninstProgram, 0) < 0) { fprintf(stderr, "epm: Error writing file data for uninst -\n %s\n", strerror(errno)); diff -u -r epm/setld.c epm-4.2/setld.c --- epm/setld.c 2007-12-12 11:12:06.000000000 +0100 +++ epm-4.2/setld.c 2007-12-11 16:24:45.000000000 +0100 @@ -144,6 +144,7 @@ runlevels ++) { file = add_file(dist, dist->files[i].subpackage); + file->size = 0; file->type = 'l'; file->mode = 0; strcpy(file->user, "root"); @@ -380,7 +381,8 @@ printf("%s -> %s...\n", file->src, filename); if (copy_file(filename, file->src, file->mode, pwd ? pwd->pw_uid : 0, - grp ? grp->gr_gid : 0)) + grp ? grp->gr_gid : 0, + strstr(file->options, "expand(")!=NULL, &file->size)) return (1); break; diff -u -r epm/slackware.c epm-4.2/slackware.c --- epm/slackware.c 2007-12-12 11:12:06.000000000 +0100 +++ epm-4.2/slackware.c 2007-12-11 16:26:05.000000000 +0100 @@ -173,7 +173,8 @@ printf("F %s -> %s...\n", file->src, filename); if (copy_file(filename, file->src, file->mode, pwd ? pwd->pw_uid : 0, - grp ? grp->gr_gid : 0)) + grp ? grp->gr_gid : 0, + strstr(file->options, "expand(")!=NULL, &file->size)) return (1); break; @@ -185,7 +186,8 @@ printf("I %s -> %s...\n", file->src, filename); if (copy_file(filename, file->src, file->mode, pwd ? pwd->pw_uid : 0, - grp ? grp->gr_gid : 0)) + grp ? grp->gr_gid : 0, + strstr(file->options, "expand(")!=NULL, &file->size)) return (1); break; diff -u -r epm/swinstall.c epm-4.2/swinstall.c --- epm/swinstall.c 2007-12-12 11:12:06.000000000 +0100 +++ epm-4.2/swinstall.c 2007-12-11 16:26:38.000000000 +0100 @@ -283,6 +283,7 @@ runlevels ++) { file = add_file(dist, dist->files[i].subpackage); + file->size = 0; file->type = 'l'; file->mode = 0; strcpy(file->user, "root"); diff -u -r epm/tar.c epm-4.2/tar.c --- epm/tar.c 2007-12-12 11:12:06.000000000 +0100 +++ epm-4.2/tar.c 2007-12-11 16:40:08.000000000 +0100 @@ -217,7 +217,7 @@ srcinfo.st_mtime, "root", "sys", dst, NULL)) return (-1); - if (tar_file(tar, src)) + if (tar_file(tar, src, 0)) return (-1); } } @@ -233,7 +233,8 @@ int /* O - 0 on success, -1 on error */ tar_file(tarf_t *fp, /* I - Tar file to write to */ - const char *filename) /* I - File to write */ + const char *filename, /* I - File to write */ + int expand) /* I - Flag for variable expansion */ { FILE *file; /* File to write */ size_t nbytes, /* Number of bytes read */ @@ -255,35 +256,84 @@ tbytes = 0; - while ((nbytes = fread(buffer, 1, sizeof(buffer), file)) > 0) + if(expand) { - /* - * Zero fill the file to a 512 byte record as needed. - */ - - if (nbytes < sizeof(buffer)) + int lineno = 0; + while(fgets(buffer, sizeof(buffer), file) != NULL) { - fill = TAR_BLOCK - (nbytes & (TAR_BLOCK - 1)); + lineno++; + if(expand_variables(buffer, sizeof(buffer)) < 0) + { + fprintf(stderr, + "epm: Variable expansion failed at line %d while " + "processing file\n \"%s\"\n", + lineno, filename); + + fclose(file); + + return (-1); + } + + nbytes = strlen(buffer); - if (fill < TAR_BLOCK) + if (fwrite(buffer, 1, nbytes, fp->file) < nbytes) { - memset(buffer + nbytes, 0, fill); - nbytes += fill; + fprintf(stderr, "epm: Unable to archive file \"%s\" -\n %s\n", + filename, strerror(errno)); + fclose(file); + return (-1); } + tbytes += nbytes; } - /* - * Write the buffer to the file... - */ - - if (fwrite(buffer, 1, nbytes, fp->file) < nbytes) + fill = tbytes % TAR_BLOCK; + if(fill != 0) { - fclose(file); - return (-1); + fill = TAR_BLOCK - fill; + memset(buffer, 0, fill); + if (fwrite(buffer, 1, fill, fp->file) < fill) + { + fprintf(stderr, "epm: Unable to archive file \"%s\" -\n %s\n", + filename, strerror(errno)); + fclose(file); + return (-1); + } } + tbytes += fill; + fp->blocks += tbytes / TAR_BLOCK; + } + else + { + while ((nbytes = fread(buffer, 1, sizeof(buffer), file)) > 0) + { + /* + * Zero fill the file to a 512 byte record as needed. + */ + + if (nbytes < sizeof(buffer)) + { + fill = TAR_BLOCK - (nbytes & (TAR_BLOCK - 1)); + + if (fill < TAR_BLOCK) + { + memset(buffer + nbytes, 0, fill); + nbytes += fill; + } + } - tbytes += nbytes; - fp->blocks += nbytes / TAR_BLOCK; + /* + * Write the buffer to the file... + */ + + if (fwrite(buffer, 1, nbytes, fp->file) < nbytes) + { + fclose(file); + return (-1); + } + + tbytes += nbytes; + fp->blocks += nbytes / TAR_BLOCK; + } } /* @@ -549,7 +599,7 @@ filestat.st_mtime, "root", "root", name, NULL)) return (-1); - return (tar_file(tar, filename)); + return (tar_file(tar, filename, 0)); } Nur in epm-4.2: tar.o.