aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLukas Fleischer <calcurse@cryptocrack.de>2011-08-02 13:49:05 +0200
committerLukas Fleischer <calcurse@cryptocrack.de>2011-10-05 12:25:47 +0200
commit5c6a00ee93e54cc044aee5146e9fcfbcb732a2ee (patch)
treef7df475374daa504f75a2291ff9c242f7c7efe70 /src
parent2fe7a36aab8c6c934550b2b8dc2074c1af23859a (diff)
downloadcalcurse-5c6a00ee93e54cc044aee5146e9fcfbcb732a2ee.tar.gz
calcurse-5c6a00ee93e54cc044aee5146e9fcfbcb732a2ee.zip
Use hash-bashed file names in edit_note()
Note file names are now generated based on their content. Items using the same note will share a single note file. Please note that this implies a few changes: * Both random-style and hash-style note files need to be handled to ensure we do not break backwards compatibility. * Note files may not be moved or deleted if a note is changed or removed since the original note file might be used by another item as well. * A garbage collector to remove unreferenced note files needs to be implemented. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
Diffstat (limited to 'src')
-rw-r--r--src/note.c42
1 files changed, 31 insertions, 11 deletions
diff --git a/src/note.c b/src/note.c
index c8aa1ec..36c2c0f 100644
--- a/src/note.c
+++ b/src/note.c
@@ -37,26 +37,46 @@
#include <unistd.h>
#include "calcurse.h"
+#include "sha1.h"
/* Edit a note with an external editor. */
void
edit_note (char **note, char *editor)
{
- char fullname[BUFSIZ];
- char *filename;
+ char tmppath[BUFSIZ];
+ char *tmpext;
+ char notepath[BUFSIZ];
+ char *sha1 = mem_malloc (SHA1_DIGESTLEN * 2 + 1);
+ FILE *fp;
- if (*note == NULL)
+ strncpy (tmppath, get_tempdir (), BUFSIZ);
+ strncat (tmppath, "/calcurse-note.", BUFSIZ);
+ if ((tmpext = new_tempfile (tmppath, TMPEXTSIZ)) == NULL)
+ return;
+ strncat (tmppath, tmpext, BUFSIZ);
+ mem_free (tmpext);
+
+ if (*note != NULL)
{
- if ((filename = new_tempfile (path_notes, NOTESIZ)) != NULL)
- *note = filename;
- else
- return;
+ snprintf (notepath, BUFSIZ, "%s%s", path_notes, *note);
+ io_file_cp (notepath, tmppath);
+ }
+
+ wins_launch_external (tmppath, editor);
+
+ if (io_file_is_empty (tmppath) > 0)
+ erase_note (note, ERASE_FORCE_KEEP_NOTE);
+ else if ((fp = fopen (tmppath, "r")))
+ {
+ sha1_stream (fp, sha1);
+ fclose (fp);
+ *note = sha1;
+
+ snprintf (notepath, BUFSIZ, "%s%s", path_notes, *note);
+ io_file_cp (tmppath, notepath);
}
- (void)snprintf (fullname, BUFSIZ, "%s%s", path_notes, *note);
- wins_launch_external (fullname, editor);
- if (io_file_is_empty (fullname) > 0)
- erase_note (note, ERASE_FORCE);
+ unlink (tmppath);
}
/* View a note in an external pager. */