From 692d54b21cec60dd61c51c95bea75c1e017ce78c Mon Sep 17 00:00:00 2001 From: Jason Yellick Date: Fri, 23 Feb 2018 10:56:05 -0500 Subject: [PATCH] [FAB-8473] Make configtxlator truncate output file The new configtxlator CLI mode allows specifying an output file. If the file already exists, the output is appended. This is fairly unintuitive behavior or a CLI and it should truncate the file instead. This CR simply adds the truncate flag to the file opens in the flag options. Change-Id: I5ea14170da1dc93f4f5c5b9aa555080311f71e9e Signed-off-by: Jason Yellick --- common/tools/configtxlator/main.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/common/tools/configtxlator/main.go b/common/tools/configtxlator/main.go index 343836f5e7..6fad70cf10 100644 --- a/common/tools/configtxlator/main.go +++ b/common/tools/configtxlator/main.go @@ -48,18 +48,18 @@ var ( protoEncode = app.Command("proto_encode", "Converts a JSON document to protobuf.") protoEncodeType = protoEncode.Flag("type", "The type of protobuf structure to encode to. For example, 'common.Config'.").Required().String() protoEncodeSource = protoEncode.Flag("input", "A file containing the JSON document.").Default(os.Stdin.Name()).File() - protoEncodeDest = protoEncode.Flag("output", "A file to write the output to.").Default(os.Stdout.Name()).OpenFile(os.O_RDWR|os.O_CREATE, 0600) + protoEncodeDest = protoEncode.Flag("output", "A file to write the output to.").Default(os.Stdout.Name()).OpenFile(os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0600) protoDecode = app.Command("proto_decode", "Converts a proto message to JSON.") protoDecodeType = protoDecode.Flag("type", "The type of protobuf structure to decode from. For example, 'common.Config'.").Required().String() protoDecodeSource = protoDecode.Flag("input", "A file containing the proto message.").Default(os.Stdin.Name()).File() - protoDecodeDest = protoDecode.Flag("output", "A file to write the JSON document to.").Default(os.Stdout.Name()).OpenFile(os.O_RDWR|os.O_CREATE, 0600) + protoDecodeDest = protoDecode.Flag("output", "A file to write the JSON document to.").Default(os.Stdout.Name()).OpenFile(os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0600) computeUpdate = app.Command("compute_update", "Takes two marshaled common.Config messages and computes the config update which transitions between the two.") computeUpdateOriginal = computeUpdate.Flag("original", "The original config message.").File() computeUpdateUpdated = computeUpdate.Flag("updated", "The updated config message.").File() computeUpdateChannelID = computeUpdate.Flag("channel_id", "The name of the channel for this update.").Required().String() - computeUpdateDest = computeUpdate.Flag("output", "A file to write the JSON document to.").Default(os.Stdout.Name()).OpenFile(os.O_RDWR|os.O_CREATE, 0600) + computeUpdateDest = computeUpdate.Flag("output", "A file to write the JSON document to.").Default(os.Stdout.Name()).OpenFile(os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0600) version = app.Command("version", "Show version information") )