mirror of
https://github.com/LostRuins/koboldcpp.git
synced 2026-08-31 17:40:52 +02:00
quantize: prevent input/output file collision (#18451)
Check Pre-Tokenizer Hashes / pre-tokenizer-hashes (push) Failing after 9s
Python check requirements.txt / check-requirements (push) Failing after 8s
Python Type-Check / pyright type-check (push) Failing after 7s
Update Operations Documentation / update-ops-docs (push) Failing after 7s
Check Pre-Tokenizer Hashes / pre-tokenizer-hashes (push) Failing after 9s
Python check requirements.txt / check-requirements (push) Failing after 8s
Python Type-Check / pyright type-check (push) Failing after 7s
Update Operations Documentation / update-ops-docs (push) Failing after 7s
Check if input and output files are the same before quantizing to prevent file corruption when mmap reads from a file being written to. Fixes #12753
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
#include <cmath>
|
||||
#include <cctype>
|
||||
#include <algorithm>
|
||||
#include <filesystem>
|
||||
|
||||
struct quant_option {
|
||||
std::string name;
|
||||
@@ -643,6 +644,11 @@ int main(int argc, char ** argv) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (std::error_code ec; std::filesystem::equivalent(fname_inp, fname_out, ec)) {
|
||||
fprintf(stderr, "%s: error: input and output files are the same: '%s'\n", __func__, fname_inp.c_str());
|
||||
return 1;
|
||||
}
|
||||
|
||||
print_build_info();
|
||||
|
||||
fprintf(stderr, "%s: quantizing '%s' to '%s' as %s", __func__, fname_inp.c_str(), fname_out.c_str(), ftype_str.c_str());
|
||||
|
||||
Reference in New Issue
Block a user