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>
This commit is contained in:
parent
2fe7a36aab
commit
5c6a00ee93
42
src/note.c
42
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);
|
||||
}
|
||||
(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);
|
||||
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);
|
||||
}
|
||||
|
||||
unlink (tmppath);
|
||||
}
|
||||
|
||||
/* View a note in an external pager. */
|
||||
|
Loading…
x
Reference in New Issue
Block a user