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
44
src/note.c
44
src/note.c
@ -37,26 +37,46 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "calcurse.h"
|
#include "calcurse.h"
|
||||||
|
#include "sha1.h"
|
||||||
|
|
||||||
/* Edit a note with an external editor. */
|
/* Edit a note with an external editor. */
|
||||||
void
|
void
|
||||||
edit_note (char **note, char *editor)
|
edit_note (char **note, char *editor)
|
||||||
{
|
{
|
||||||
char fullname[BUFSIZ];
|
char tmppath[BUFSIZ];
|
||||||
char *filename;
|
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 ((filename = new_tempfile (path_notes, NOTESIZ)) != NULL)
|
if ((tmpext = new_tempfile (tmppath, TMPEXTSIZ)) == NULL)
|
||||||
*note = filename;
|
|
||||||
else
|
|
||||||
return;
|
return;
|
||||||
}
|
strncat (tmppath, tmpext, BUFSIZ);
|
||||||
(void)snprintf (fullname, BUFSIZ, "%s%s", path_notes, *note);
|
mem_free (tmpext);
|
||||||
wins_launch_external (fullname, editor);
|
|
||||||
|
|
||||||
if (io_file_is_empty (fullname) > 0)
|
if (*note != NULL)
|
||||||
erase_note (note, ERASE_FORCE);
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
unlink (tmppath);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* View a note in an external pager. */
|
/* View a note in an external pager. */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user