1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-01-03 05:18:29 +03:00

export: limit generation of comment strings

Generate comment string only for formatter with comments.
This commit is contained in:
Zdenek Kabelac 2024-10-20 01:56:23 +02:00
parent 0179f00e0c
commit b4156bb4de

View File

@ -71,6 +71,7 @@ struct formatter {
int indent; /* current level of indentation */ int indent; /* current level of indentation */
int error; int error;
int header; /* 1 => comments at start; 0 => end */ int header; /* 1 => comments at start; 0 => end */
int with_comment; /* 1 => prepare comment sting */
}; };
static struct utsname _utsname; static struct utsname _utsname;
@ -273,8 +274,11 @@ int out_size(struct formatter *f, uint64_t size, const char *fmt, ...)
va_list ap; va_list ap;
int r; int r;
if (!_sectors_to_units(size, buffer, sizeof(buffer))) if (f->with_comment) {
return 0; if (!_sectors_to_units(size, buffer, sizeof(buffer)))
return 0;
} else
buffer[0] = 0;
_out_with_comment(f, buffer, fmt, ap); _out_with_comment(f, buffer, fmt, ap);
@ -696,10 +700,14 @@ static int _print_timestamp(struct formatter *f,
struct tm *local_tm; struct tm *local_tm;
if (ts) { if (ts) {
strncpy(buf, "# ", buf_size); if (f->with_comment) {
if (!(local_tm = localtime(&ts)) || /* generate timestamp only for commented output */
!strftime(buf + 2, buf_size - 2, strncpy(buf, "# ", buf_size);
"%Y-%m-%d %T %z", local_tm)) if (!(local_tm = localtime(&ts)) ||
!strftime(buf + 2, buf_size - 2,
"%Y-%m-%d %T %z", local_tm))
buf[0] = 0;
} else
buf[0] = 0; buf[0] = 0;
outfc(f, buf, "%s = " FMTu64, name, (uint64_t) ts); outfc(f, buf, "%s = " FMTu64, name, (uint64_t) ts);
@ -1049,6 +1057,7 @@ int text_vg_export_file(struct volume_group *vg, const char *desc, FILE *fp)
.indent = 0, .indent = 0,
.header = 1, .header = 1,
.out_with_comment = &_out_with_comment_file, .out_with_comment = &_out_with_comment_file,
.with_comment = 1,
.nl = &_nl_file, .nl = &_nl_file,
.data.fp = fp, .data.fp = fp,
}; };