From cf024f1c4ccddf03f371f09d5951d9e57caad754 Mon Sep 17 00:00:00 2001 From: bronku Date: Fri, 14 Nov 2025 00:20:58 +0100 Subject: [PATCH] ensure path exists --- main.cpp | 3 +++ makefile | 10 ++-------- sort.cpp | 4 ++++ 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/main.cpp b/main.cpp index 1861b9c..34a7764 100644 --- a/main.cpp +++ b/main.cpp @@ -9,6 +9,9 @@ void generate_file(int N, const std::string& filename) { + std::filesystem::path dirPath = std::filesystem::path(filename).parent_path(); + std::filesystem::create_directories(dirPath); + std::ofstream out_stream(filename); Writer output(out_stream); diff --git a/makefile b/makefile index 83535d7..4545a71 100644 --- a/makefile +++ b/makefile @@ -6,22 +6,16 @@ build/main: main.cpp sort.cpp config.hpp buffer.hpp reader.hpp writer.hpp build build: mkdir -p build -build/run: - mkdir -p build/run - -build/run/tmp: - mkdir -p build/run/tmp - clean: rm -rf build generate: build/run/1.in # actually should depend on build/main and build/run, but that will trigger it every recompile, and i don't need that -build/run/1.in: build/run/tmp +build/run/1.in: build/main -g -o build/run/1.in -run: build/main build/run/1.in build/run/tmp +run: build/main build/run/1.in build/main -i build/run/1.in -d build/run/tmp debug: build/main tests/1.in diff --git a/sort.cpp b/sort.cpp index 0e77808..8e78ce2 100644 --- a/sort.cpp +++ b/sort.cpp @@ -20,6 +20,9 @@ size_t read_chunk(Reader& reader, SubBuffer& buff) void write_to_file(const std::string& filename, SubBuffer& buff, size_t n) { + std::filesystem::path dirPath = std::filesystem::path(filename).parent_path(); + std::filesystem::create_directories(dirPath); + std::ofstream out_stream(filename); Writer output_writer(out_stream); for (size_t j = 0; j < n; j++) { @@ -46,6 +49,7 @@ void create_initial_runs(const std::string& input_filename, const std::string& d int sort_file(const Configuration& opts) { Buffer main_buffer(opts.n * opts.b); + create_initial_runs(opts.input_file, opts.directory, main_buffer); return 0;