From c77d1a573fc9c9d27ccc8c80a5a67245a3cf0e1b Mon Sep 17 00:00:00 2001 From: Lukas Fleischer Date: Tue, 2 Aug 2011 21:49:49 +0200 Subject: Use hash-based file names in ical_read_note() Signed-off-by: Lukas Fleischer --- src/io.c | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) (limited to 'src/io.c') diff --git a/src/io.c b/src/io.c index feaeb0a..20dab48 100644 --- a/src/io.c +++ b/src/io.c @@ -45,6 +45,7 @@ #include #include "calcurse.h" +#include "sha1.h" #define ICALDATEFMT "%Y%m%d" #define ICALDATETIMEFMT "%Y%m%dT%H%M%S" @@ -2308,43 +2309,37 @@ static char * ical_read_note (char *line, unsigned *noskipped, ical_vevent_e item_type, const int itemline, FILE *log) { - char *p, *notestr, *notename, fullnotename[BUFSIZ]; + char *sha1 = mem_malloc (SHA1_DIGESTLEN * 2 + 1); + char *p, *notestr, fullnotename[BUFSIZ]; FILE *fdo; if ((p = strchr (line, ':')) != NULL) { - notename = new_tempfile (path_notes, TMPEXTSIZ); - EXIT_IF (notename == NULL, - _("Warning: could not create new note file to store " - "description. Aborting...\n")); - (void)snprintf (fullnotename, BUFSIZ, "%s%s", path_notes, notename); - fdo = fopen (fullnotename, "w"); - EXIT_IF (fdo == NULL, _("Warning: could not open %s, Aborting..."), - fullnotename); p++; notestr = ical_unformat_line (p); if (notestr == NULL) { ical_log (log, item_type, itemline, _("could not get entire item description.")); - file_close (fdo, __FILE_POS__); - erase_note (¬ename, ERASE_FORCE); (*noskipped)++; return NULL; } else if (strlen (notestr) == 0) { - file_close (fdo, __FILE_POS__); - erase_note (¬ename, ERASE_FORCE); mem_free (notestr); return NULL; } else { + sha1_digest (notestr, sha1); + (void)snprintf (fullnotename, BUFSIZ, "%s%s", path_notes, sha1); + fdo = fopen (fullnotename, "w"); + EXIT_IF (fdo == NULL, _("Warning: could not open %s, Aborting..."), + fullnotename); (void)fprintf (fdo, "%s", notestr); file_close (fdo, __FILE_POS__); mem_free (notestr); - return notename; + return sha1; } } else -- cgit v1.2.3-54-g00ecf