mirror of
https://github.com/sheumann/hush.git
synced 2024-12-22 14:30:31 +00:00
It now correctly backs up the (still corrupt) status file
This commit is contained in:
parent
0e757a2f3f
commit
13e9c7ad82
@ -478,7 +478,6 @@ static int status_merge(void *status, package_t *pkgs)
|
|||||||
char *line = NULL;
|
char *line = NULL;
|
||||||
package_t *pkg = 0, *statpkg = 0;
|
package_t *pkg = 0, *statpkg = 0;
|
||||||
package_t locpkg;
|
package_t locpkg;
|
||||||
int r = 0;
|
|
||||||
|
|
||||||
if ((fout = wfopen(new_statusfile, "w")) == NULL) {
|
if ((fout = wfopen(new_statusfile, "w")) == NULL) {
|
||||||
return 0;
|
return 0;
|
||||||
@ -486,7 +485,10 @@ static int status_merge(void *status, package_t *pkgs)
|
|||||||
if (getenv(udpkg_quiet) == NULL) {
|
if (getenv(udpkg_quiet) == NULL) {
|
||||||
printf("(Updating database...)\n");
|
printf("(Updating database...)\n");
|
||||||
}
|
}
|
||||||
if ((fin = wfopen(statusfile, "r")) != NULL) {
|
/*
|
||||||
|
* Dont use wfopen here, handle errors ourself
|
||||||
|
*/
|
||||||
|
if ((fin = fopen(statusfile, "r")) != NULL) {
|
||||||
while (((line = get_line_from_file(fin)) != NULL) && !feof(fin)) {
|
while (((line = get_line_from_file(fin)) != NULL) && !feof(fin)) {
|
||||||
line[strlen(line) - 1] = '\0'; /* trim newline */
|
line[strlen(line) - 1] = '\0'; /* trim newline */
|
||||||
/* If we see a package header, find out if it's a package
|
/* If we see a package header, find out if it's a package
|
||||||
@ -495,14 +497,14 @@ static int status_merge(void *status, package_t *pkgs)
|
|||||||
*
|
*
|
||||||
* we also look at packages in the status cache and update
|
* we also look at packages in the status cache and update
|
||||||
* their status fields
|
* their status fields
|
||||||
*/
|
*/
|
||||||
if (strstr(line, "Package: ") == line) {
|
if (strstr(line, "Package: ") == line) {
|
||||||
for (pkg = pkgs; pkg != 0 && strcmp(line + 9,
|
for (pkg = pkgs; pkg != 0 && strcmp(line + 9,
|
||||||
pkg->package) != 0; pkg = pkg->next) ;
|
pkg->package) != 0; pkg = pkg->next) ;
|
||||||
|
|
||||||
locpkg.package = line + 9;
|
locpkg.package = line + 9;
|
||||||
statpkg = tfind(&locpkg, &status, package_compare);
|
statpkg = tfind(&locpkg, &status, package_compare);
|
||||||
|
|
||||||
/* note: statpkg should be non-zero, unless the status
|
/* note: statpkg should be non-zero, unless the status
|
||||||
* file was changed while we are processing (no locking
|
* file was changed while we are processing (no locking
|
||||||
* is currently done...
|
* is currently done...
|
||||||
@ -521,6 +523,7 @@ static int status_merge(void *status, package_t *pkgs)
|
|||||||
fputs(line, fout);
|
fputs(line, fout);
|
||||||
fputc('\n', fout);
|
fputc('\n', fout);
|
||||||
}
|
}
|
||||||
|
fclose(fin);
|
||||||
}
|
}
|
||||||
free(line);
|
free(line);
|
||||||
|
|
||||||
@ -538,16 +541,24 @@ static int status_merge(void *status, package_t *pkgs)
|
|||||||
fprintf(fout, "Description: %s\n", pkg->description);
|
fprintf(fout, "Description: %s\n", pkg->description);
|
||||||
fputc('\n', fout);
|
fputc('\n', fout);
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose(fin);
|
|
||||||
fclose(fout);
|
fclose(fout);
|
||||||
|
|
||||||
r = rename(statusfile, bak_statusfile);
|
/*
|
||||||
if (r == 0) {
|
* Its ok if renaming statusfile fails becasue it doesnt exist
|
||||||
r = rename(new_statusfile, statusfile);
|
*/
|
||||||
|
if (rename(statusfile, bak_statusfile) == -1) {
|
||||||
|
struct stat stat_buf;
|
||||||
|
error_msg("Couldnt create backup status file");
|
||||||
|
if (stat(statusfile, &stat_buf) == 0) {
|
||||||
|
return(EXIT_FAILURE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
if (rename(new_statusfile, statusfile) == -1) {
|
||||||
|
error_msg("Couldnt create status file");
|
||||||
|
return(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
return(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int is_file(const char *fn)
|
static int is_file(const char *fn)
|
||||||
|
31
dpkg.c
31
dpkg.c
@ -478,7 +478,6 @@ static int status_merge(void *status, package_t *pkgs)
|
|||||||
char *line = NULL;
|
char *line = NULL;
|
||||||
package_t *pkg = 0, *statpkg = 0;
|
package_t *pkg = 0, *statpkg = 0;
|
||||||
package_t locpkg;
|
package_t locpkg;
|
||||||
int r = 0;
|
|
||||||
|
|
||||||
if ((fout = wfopen(new_statusfile, "w")) == NULL) {
|
if ((fout = wfopen(new_statusfile, "w")) == NULL) {
|
||||||
return 0;
|
return 0;
|
||||||
@ -486,7 +485,10 @@ static int status_merge(void *status, package_t *pkgs)
|
|||||||
if (getenv(udpkg_quiet) == NULL) {
|
if (getenv(udpkg_quiet) == NULL) {
|
||||||
printf("(Updating database...)\n");
|
printf("(Updating database...)\n");
|
||||||
}
|
}
|
||||||
if ((fin = wfopen(statusfile, "r")) != NULL) {
|
/*
|
||||||
|
* Dont use wfopen here, handle errors ourself
|
||||||
|
*/
|
||||||
|
if ((fin = fopen(statusfile, "r")) != NULL) {
|
||||||
while (((line = get_line_from_file(fin)) != NULL) && !feof(fin)) {
|
while (((line = get_line_from_file(fin)) != NULL) && !feof(fin)) {
|
||||||
line[strlen(line) - 1] = '\0'; /* trim newline */
|
line[strlen(line) - 1] = '\0'; /* trim newline */
|
||||||
/* If we see a package header, find out if it's a package
|
/* If we see a package header, find out if it's a package
|
||||||
@ -495,14 +497,14 @@ static int status_merge(void *status, package_t *pkgs)
|
|||||||
*
|
*
|
||||||
* we also look at packages in the status cache and update
|
* we also look at packages in the status cache and update
|
||||||
* their status fields
|
* their status fields
|
||||||
*/
|
*/
|
||||||
if (strstr(line, "Package: ") == line) {
|
if (strstr(line, "Package: ") == line) {
|
||||||
for (pkg = pkgs; pkg != 0 && strcmp(line + 9,
|
for (pkg = pkgs; pkg != 0 && strcmp(line + 9,
|
||||||
pkg->package) != 0; pkg = pkg->next) ;
|
pkg->package) != 0; pkg = pkg->next) ;
|
||||||
|
|
||||||
locpkg.package = line + 9;
|
locpkg.package = line + 9;
|
||||||
statpkg = tfind(&locpkg, &status, package_compare);
|
statpkg = tfind(&locpkg, &status, package_compare);
|
||||||
|
|
||||||
/* note: statpkg should be non-zero, unless the status
|
/* note: statpkg should be non-zero, unless the status
|
||||||
* file was changed while we are processing (no locking
|
* file was changed while we are processing (no locking
|
||||||
* is currently done...
|
* is currently done...
|
||||||
@ -521,6 +523,7 @@ static int status_merge(void *status, package_t *pkgs)
|
|||||||
fputs(line, fout);
|
fputs(line, fout);
|
||||||
fputc('\n', fout);
|
fputc('\n', fout);
|
||||||
}
|
}
|
||||||
|
fclose(fin);
|
||||||
}
|
}
|
||||||
free(line);
|
free(line);
|
||||||
|
|
||||||
@ -538,16 +541,24 @@ static int status_merge(void *status, package_t *pkgs)
|
|||||||
fprintf(fout, "Description: %s\n", pkg->description);
|
fprintf(fout, "Description: %s\n", pkg->description);
|
||||||
fputc('\n', fout);
|
fputc('\n', fout);
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose(fin);
|
|
||||||
fclose(fout);
|
fclose(fout);
|
||||||
|
|
||||||
r = rename(statusfile, bak_statusfile);
|
/*
|
||||||
if (r == 0) {
|
* Its ok if renaming statusfile fails becasue it doesnt exist
|
||||||
r = rename(new_statusfile, statusfile);
|
*/
|
||||||
|
if (rename(statusfile, bak_statusfile) == -1) {
|
||||||
|
struct stat stat_buf;
|
||||||
|
error_msg("Couldnt create backup status file");
|
||||||
|
if (stat(statusfile, &stat_buf) == 0) {
|
||||||
|
return(EXIT_FAILURE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
if (rename(new_statusfile, statusfile) == -1) {
|
||||||
|
error_msg("Couldnt create status file");
|
||||||
|
return(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
return(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int is_file(const char *fn)
|
static int is_file(const char *fn)
|
||||||
|
Loading…
Reference in New Issue
Block a user