diff --git a/edit/ChangeLog b/edit/ChangeLog index 982e76ea1..44edb2b16 100644 --- a/edit/ChangeLog +++ b/edit/ChangeLog @@ -1,7 +1,16 @@ +2002-06-24 Pavel Roskin + + * edit.c (check_file_access): Return 1 on all errors, document + this behavior. Set edit->delete_file to 1 for newly created + files. + (edit_open_file): Don't set edit->delete_file, it's now done in + check_file_access(). + Reported by Saso + 2002-05-13 Andrew V. Samoilov - * editcmd.c (edit_save_file): Call mc_chown () and mc_chmod () - before mc_open () to prevent hangs over ftpfs. + * editcmd.c (edit_save_file): Call mc_chown() and mc_chmod() + before mc_open() to prevent hangs over ftpfs. * edit.h: Remove open, close, write, read and mkdir definitions. * edit.c: Use mc_open, mc_close, mc_write, mc_read, mc_rename, diff --git a/edit/edit.c b/edit/edit.c index 041374a0f..9a89a4d9e 100644 --- a/edit/edit.c +++ b/edit/edit.c @@ -398,6 +398,7 @@ int edit_insert_file (WEdit * edit, const char *filename) return 1; } +/* Open file and create it if necessary. Return 0 for success, 1 for error. */ static int check_file_access (WEdit *edit, const char *filename, struct stat *st) { int file; @@ -417,7 +418,7 @@ static int check_file_access (WEdit *edit, const char *filename, struct stat *st /* Open the file, create it if needed */ if ((file = mc_open (filename, O_RDONLY | O_CREAT, 0666)) < 0) { edit_error_dialog (_ (" Error "), get_sys_error (catstrs (_ (" Failed trying to open file for reading: "), filename, " ", 0))); - return 2; + return 1; } /* If the file has just been created, we don't have valid stat yet, so do it now */ @@ -428,6 +429,11 @@ static int check_file_access (WEdit *edit, const char *filename, struct stat *st } mc_close (file); + /* If it's a new file, delete it if it's not modified or saved */ + if (!stat_ok && st->st_size == 0) { + edit->delete_file = 1; + } + if (st->st_size >= SIZE_LIMIT) { /* The file-name is printed after the ':' */ edit_error_dialog (_ (" Error "), catstrs (_ (" File is too large: "), \ @@ -447,8 +453,6 @@ int edit_open_file (WEdit * edit, const char *filename, const char *text, unsign } else { int r; r = check_file_access (edit, filename, &st); - if (r == 2) - return edit->delete_file = 1; if (r) return 1; edit->stat1 = st;