mirror of https://github.com/MidnightCommander/mc
The file's mtime is checked before saving.
This commit is contained in:
parent
7a9daa86b0
commit
45bb7dbe50
|
@ -1,3 +1,11 @@
|
|||
2006-11-17 Roland Illig <roland.illig@gmx.de>
|
||||
|
||||
* edit_cmd.c (edit_save_file): The file's modification time is
|
||||
recorded and compared to the one of the file on disk. If it
|
||||
differs, the user is asked whether the file should really be
|
||||
overwritten.
|
||||
* edit.c (edit_init): Likewise.
|
||||
|
||||
2006-08-02 Leonard den Ottolander <leonard den ottolander nl>
|
||||
|
||||
* syntax.c (edit_read_syntax_file): Set NENTRIES to 30.
|
||||
|
|
|
@ -529,6 +529,7 @@ edit_init (WEdit *edit, int lines, int columns, const char *filename,
|
|||
edit->stat1.st_mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
|
||||
edit->stat1.st_uid = getuid ();
|
||||
edit->stat1.st_gid = getgid ();
|
||||
edit->stat1.st_mtime = 0;
|
||||
edit->bracket = -1;
|
||||
edit->force |= REDRAW_PAGE;
|
||||
edit_set_filename (edit, filename);
|
||||
|
@ -690,6 +691,7 @@ void edit_push_action (WEdit * edit, long c,...)
|
|||
unsigned long sp = edit->stack_pointer;
|
||||
unsigned long spm1;
|
||||
long *t;
|
||||
|
||||
/* first enlarge the stack if necessary */
|
||||
if (sp > edit->stack_size - 10) { /* say */
|
||||
if (option_max_undo < 256)
|
||||
|
|
|
@ -276,6 +276,21 @@ edit_save_file (WEdit *edit, const char *filename)
|
|||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/* Prevent overwriting changes from other editor sessions. */
|
||||
if (rv == 0 && edit->stat1.st_mtime != 0 && edit->stat1.st_mtime != sb.st_mtime) {
|
||||
|
||||
/* The default action is "Cancel". */
|
||||
query_set_sel(1);
|
||||
|
||||
rv = edit_query_dialog2 (
|
||||
_("Warning"),
|
||||
_("The file has been modified in the meantime. Save anyway?"),
|
||||
_("&Yes"),
|
||||
_("&Cancel"));
|
||||
if (rv != 0)
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (this_save_mode != EDIT_QUICK_SAVE) {
|
||||
|
@ -381,6 +396,10 @@ edit_save_file (WEdit *edit, const char *filename)
|
|||
}
|
||||
if (mc_close (fd))
|
||||
goto error_save;
|
||||
|
||||
/* Update the file information, especially the mtime. */
|
||||
if (mc_stat (savename, &edit->stat1) == -1)
|
||||
goto error_save;
|
||||
}
|
||||
|
||||
if (filelen != edit->last_byte)
|
||||
|
|
Loading…
Reference in New Issue