mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-31 23:13:25 +00:00
Make special backup when switching XML versions
Since the last few dozen commits change the format in irreversible ways and could therefore be destructive and lose data for testers of the development version, let's try to be extra careful and create "special" backup files that aren't overwritten by subsequent backups. At least this way people can go back to the previous state. Of course people using the git backend don't have to worry about this as they always can go back to any earlier save. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
ae49a8a4f7
commit
d4f2b72148
3 changed files with 15 additions and 1 deletions
2
dive.h
2
dive.h
|
@ -48,6 +48,8 @@ extern "C" {
|
|||
#include <stdbool.h>
|
||||
#endif
|
||||
|
||||
extern int last_xml_version;
|
||||
|
||||
enum dive_comp_type {OC, CCR, PSCR, FREEDIVE, NUM_DC_TYPE}; // Flags (Open-circuit and Closed-circuit-rebreather) for setting dive computer type
|
||||
enum cylinderuse {OC_GAS, DILUENT, OXYGEN, NUM_GAS_USE}; // The different uses for cylinders
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
|
||||
int verbose, quit;
|
||||
int metric = 1;
|
||||
int last_xml_version = -1;
|
||||
|
||||
static xmlDoc *test_xslt_transforms(xmlDoc *doc, const char **params);
|
||||
|
||||
|
@ -1644,6 +1645,9 @@ static void userid_stop(void)
|
|||
|
||||
static void entry(const char *name, char *buf)
|
||||
{
|
||||
if (!strncmp(name, "version.program", sizeof("version.program") - 1) ||
|
||||
!strncmp(name, "version.divelog", sizeof("version.divelog") - 1))
|
||||
last_xml_version = atoi(buf);
|
||||
if (in_userid) {
|
||||
try_to_fill_userid(name, buf);
|
||||
return;
|
||||
|
|
10
save-xml.c
10
save-xml.c
|
@ -591,7 +591,15 @@ static void try_to_backup(const char *filename)
|
|||
while (extension[i][0] != '\0') {
|
||||
int elen = strlen(extension[i]);
|
||||
if (strcasecmp(filename + flen - elen, extension[i]) == 0) {
|
||||
save_backup(filename, extension[i], "bak");
|
||||
if (last_xml_version < VERSION) {
|
||||
int se_len = strlen(extension[i]) + 5;
|
||||
char *special_ext = malloc(se_len);
|
||||
snprintf(special_ext, se_len, "%s.v%d", extension[i], last_xml_version);
|
||||
save_backup(filename, extension[i], special_ext);
|
||||
free(special_ext);
|
||||
} else {
|
||||
save_backup(filename, extension[i], "bak");
|
||||
}
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
|
|
Loading…
Add table
Reference in a new issue