diff -Nru envstore-2.0.3/Changelog envstore-2.0.4/Changelog --- envstore-2.0.3/Changelog 2009-12-11 17:46:21.000000000 +0000 +++ envstore-2.0.4/Changelog 2010-01-23 15:33:02.000000000 +0000 @@ -1,3 +1,8 @@ +envstore 2.0.4 - Sat Jan 23 2010 + + * Preserve leading space in saved variables + * Improved some error messages + envstore 2.0.3 - Fri Dec 11 2009 * Fix a bug in the Makefile (the test script was still run with zsh) diff -Nru envstore-2.0.3/debian/changelog envstore-2.0.4/debian/changelog --- envstore-2.0.3/debian/changelog 2010-05-09 16:13:20.000000000 +0100 +++ envstore-2.0.4/debian/changelog 2010-05-09 16:13:21.000000000 +0100 @@ -1,3 +1,10 @@ +envstore (2.0.4-1) unstable; urgency=low + + * New upstrem release + * Bump Standards-Version to 3.8.4 (no changes necessary) + + -- Maximilian Gass Sat, 30 Jan 2010 13:10:44 +0100 + envstore (2.0.3-1) unstable; urgency=low * New upstream release: remove build-dependency on zsh diff -Nru envstore-2.0.3/debian/control envstore-2.0.4/debian/control --- envstore-2.0.3/debian/control 2010-05-09 16:13:20.000000000 +0100 +++ envstore-2.0.4/debian/control 2010-05-09 16:13:21.000000000 +0100 @@ -3,7 +3,7 @@ Priority: optional Maintainer: Maximilian Gass Build-Depends: debhelper (>= 7.0.50~) -Standards-Version: 3.8.3 +Standards-Version: 3.8.4 Homepage: https://derf.homelinux.org/~derf/projects/envstore Vcs-Git: git://git.debian.org/collab-maint/envstore.git Vcs-Browser: http://git.debian.org/?p=collab-maint/envstore.git diff -Nru envstore-2.0.3/Makefile envstore-2.0.4/Makefile --- envstore-2.0.3/Makefile 2009-12-11 17:46:21.000000000 +0000 +++ envstore-2.0.4/Makefile 2010-01-23 15:33:02.000000000 +0000 @@ -23,7 +23,7 @@ rm -f $(prefix)/share/man/man1/envstore.1 test: - test/main --extended + test/main clean: rm -f bin/envstore diff -Nru envstore-2.0.3/man/1/envstore envstore-2.0.4/man/1/envstore --- envstore-2.0.3/man/1/envstore 2009-12-11 17:46:21.000000000 +0000 +++ envstore-2.0.4/man/1/envstore 2010-01-23 15:33:02.000000000 +0000 @@ -56,6 +56,13 @@ .Sh LIMITATIONS Variable names or values must not contain null bytes or newlines. .Pp +Due to limitations imposed by most shells, it is not possible to save +parameters containing more than one consecutive whitespace. +.Nm +will save and display them correctly, but unless you do +.Ev IFS +trickery, your shell will not be able to load them. +.Pp The current maximum length (in bytes) is 255 bytes for the variable name and 1023 bytes for its content. .Sh AUTHOR diff -Nru envstore-2.0.3/src/envstore.c envstore-2.0.4/src/envstore.c --- envstore-2.0.3/src/envstore.c 2009-12-11 17:46:21.000000000 +0000 +++ envstore-2.0.4/src/envstore.c 2010-01-23 15:33:02.000000000 +0000 @@ -1,5 +1,5 @@ /* - * Copyright © 2009 by Daniel Friesel + * Copyright © 2009,2010 by Daniel Friesel * License: WTFPL * * Function policy: Fail early (use err/errx if something goes wrong) @@ -20,7 +20,7 @@ #define PARAM_LENGTH 256 #define VALUE_LENGTH 1024 -#define SCAN_FORMAT "%255s %1023[^\n]\n" +#define SCAN_FORMAT "%255s%*1[ ]%1023[^\n]\n" static FILE * store_open(char *file) { struct stat finfo; @@ -35,13 +35,13 @@ return NULL; if (fstat(fileno(fp), &finfo) != 0) - err(EXIT_FAILURE, "Unable to verify store file permissions (%s)", file); + err(EXIT_FAILURE, "%s: Unable to check file mode", file); if (finfo.st_uid != self_uid) - errx(EXIT_FAILURE, "Store file '%s' is insecure (must be owned by you, not uid %d)", file, finfo.st_uid); + errx(EXIT_FAILURE, "%s: File is insecure (must be owned by you, not uid %d)", file, finfo.st_uid); if ((finfo.st_mode & 077) > 0) - errx(EXIT_FAILURE, "Store file '%s' has insecure permissions %04o (recommended: 0600)", file, finfo.st_mode & 07777); + errx(EXIT_FAILURE, "%s: File is insecure (should have mode 0600, not %04o)", file, finfo.st_mode & 07777); return fp; } @@ -65,7 +65,7 @@ fp = fopen(file, "w"); if (fp == NULL) - err(EXIT_FAILURE, "fopen %s", file); + err(EXIT_FAILURE, "%s: Unable to open", file); return fp; } @@ -107,17 +107,17 @@ while ((read_items = fscanf(fp, SCAN_FORMAT, vname, vcontent)) != EOF) { if (read_items == 0) - errx(EXIT_FAILURE, "Unable to read items, store file '%s' corrupt?", file); - else if (read_items == 1) - vcontent[0] = '\0'; + errx(EXIT_FAILURE, "%s: Cannot read items, file corrupt?", file); if (command == CMD_LIST) printf("%-15s = %s\n", vname, vcontent); else print_escaped(vname, vcontent); + vname[0] = '\0'; + vcontent[0] = '\0'; } if (fclose(fp) != 0) - err(EXIT_FAILURE, "fclose %s", file); + err(EXIT_FAILURE, "%s: Unable to close", file); } static void command_rm_save(char *old_file, char *param, char *value, int argc, int mode) { @@ -132,10 +132,10 @@ while (fscanf(old_fp, SCAN_FORMAT, curparam, curvalue) != EOF) { if (strcmp(curparam, param) != 0) if (fprintf(new_fp, "%s %s\n", curparam, curvalue) <= 0) - err(EXIT_FAILURE, "fprintf %s", new_file); + err(EXIT_FAILURE, "%s: Unable to write (fprintf)", new_file); } if (fclose(old_fp) != 0) - err(EXIT_FAILURE, "fclose %s", old_file); + err(EXIT_FAILURE, "%s: Unable to close", old_file); } if (mode == CMD_SAVE) { @@ -151,14 +151,14 @@ errx(EXIT_FAILURE, "parameter or value too long (see man envstore -> LIMITATIONS)"); if (fprintf(new_fp, "%s %s\n", param, newvalue) <= 0) - err(EXIT_FAILURE, "fprintf %s", new_file); + err(EXIT_FAILURE, "%s: Unable to write (fprintf)", new_file); } if (fclose(new_fp) != 0) - err(EXIT_FAILURE, "fclose %s", new_file); + err(EXIT_FAILURE, "%s: Unable to close", new_file); if (rename(new_file, old_file) != 0) - err(EXIT_FAILURE, "Unable to rename '%s' to '%s'", new_file, old_file); + err(EXIT_FAILURE, "%s: Unable to rename to %s", new_file, old_file); } diff -Nru envstore-2.0.3/test/main envstore-2.0.4/test/main --- envstore-2.0.3/test/main 2009-12-11 17:46:21.000000000 +0000 +++ envstore-2.0.4/test/main 2010-01-23 15:33:02.000000000 +0000 @@ -73,6 +73,18 @@ test "$hello" = 'your mom' unset hello +echo "# envstore save (leading space in value)" +envstore save hello ' world' +eval $(envstore eval) +test "$hello" = ' world' +unset hello + +echo "# envstore save (trailing space in value)" +envstore save hello 'world ' +eval $(envstore eval) +test "$hello" = 'world ' +unset hello + echo "# envstore save (overwrite)" envstore save hello world eval $(envstore eval)