Skip to content

Commit e6deac3

Browse files
authored
gguf-split : add basic checks (#9499)
* gguf-split : do not overwrite existing files when merging * gguf-split : error when too many arguments are passed
1 parent 6988da9 commit e6deac3

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

examples/gguf-split/gguf-split.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ static void split_params_parse_ex(int argc, const char ** argv, split_params & p
152152
throw std::invalid_argument("error: invalid parameter for argument: " + arg);
153153
}
154154

155-
if (argc - arg_idx < 2) {
155+
if (argc - arg_idx != 2) {
156156
throw std::invalid_argument("error: bad arguments");
157157
}
158158

@@ -389,10 +389,17 @@ static void gguf_merge(const split_params & split_params) {
389389
int n_split = 1;
390390
int total_tensors = 0;
391391

392-
auto * ctx_out = gguf_init_empty();
392+
// avoid overwriting existing output file
393+
if (std::ifstream(split_params.output.c_str())) {
394+
fprintf(stderr, "%s: output file %s already exists\n", __func__, split_params.output.c_str());
395+
exit(EXIT_FAILURE);
396+
}
397+
393398
std::ofstream fout(split_params.output.c_str(), std::ios::binary);
394399
fout.exceptions(std::ofstream::failbit); // fail fast on write errors
395400

401+
auto * ctx_out = gguf_init_empty();
402+
396403
std::vector<uint8_t> read_data;
397404
std::vector<ggml_context *> ctx_metas;
398405
std::vector<gguf_context *> ctx_ggufs;

0 commit comments

Comments
 (0)