Do not remove an empty note file after edit session
Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk> Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
This commit is contained in:
parent
e1b5580bdf
commit
e3dd92ef71
@ -936,7 +936,6 @@ void io_set_lock(void);
|
|||||||
unsigned io_dump_pid(char *);
|
unsigned io_dump_pid(char *);
|
||||||
unsigned io_get_pid(char *);
|
unsigned io_get_pid(char *);
|
||||||
int io_files_equal(const char *, const char *);
|
int io_files_equal(const char *, const char *);
|
||||||
int io_file_is_empty(char *);
|
|
||||||
int io_file_cp(const char *, const char *);
|
int io_file_cp(const char *, const char *);
|
||||||
void io_unset_modified(void);
|
void io_unset_modified(void);
|
||||||
void io_set_modified(void);
|
void io_set_modified(void);
|
||||||
|
@ -213,8 +213,10 @@ static void ical_export_note(FILE *stream, char *name)
|
|||||||
int has_desc, has_prop, i;
|
int has_desc, has_prop, i;
|
||||||
|
|
||||||
asprintf(¬e_file, "%s/%s", path_notes, name);
|
asprintf(¬e_file, "%s/%s", path_notes, name);
|
||||||
if (!(fp = fopen(note_file, "r")))
|
if (!(fp = fopen(note_file, "r")) || ungetc(getc(fp), fp) == EOF) {
|
||||||
|
fclose(fp);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
string_init(¬e);
|
string_init(¬e);
|
||||||
while (fgets(lbuf, BUFSIZ, fp))
|
while (fgets(lbuf, BUFSIZ, fp))
|
||||||
string_catf(¬e, "%s", lbuf);
|
string_catf(¬e, "%s", lbuf);
|
||||||
|
16
src/io.c
16
src/io.c
@ -1578,22 +1578,6 @@ unsigned io_get_pid(char *file)
|
|||||||
return pid;
|
return pid;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Check whether a file is empty.
|
|
||||||
*/
|
|
||||||
int io_file_is_empty(char *file)
|
|
||||||
{
|
|
||||||
FILE *fp;
|
|
||||||
int ret = -1;
|
|
||||||
|
|
||||||
if (file && (fp = fopen(file, "r"))) {
|
|
||||||
ret = (fgetc(fp) == '\n' && fgetc(fp) == EOF) || feof(fp);
|
|
||||||
fclose(fp);
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Check whether two files are equal.
|
* Check whether two files are equal.
|
||||||
*/
|
*/
|
||||||
|
@ -94,9 +94,7 @@ void edit_note(char **note, const char *editor)
|
|||||||
const char *arg[] = { editor, tmppath, NULL };
|
const char *arg[] = { editor, tmppath, NULL };
|
||||||
wins_launch_external(arg);
|
wins_launch_external(arg);
|
||||||
|
|
||||||
if (io_file_is_empty(tmppath) > 0) {
|
if ((fp = fopen(tmppath, "r"))) {
|
||||||
erase_note(note);
|
|
||||||
} else if ((fp = fopen(tmppath, "r"))) {
|
|
||||||
sha1_stream(fp, sha1);
|
sha1_stream(fp, sha1);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
*note = sha1;
|
*note = sha1;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user