diff --git a/doc/tutorial/alignment_file/alignment_file_snippets.cpp b/doc/tutorial/alignment_file/alignment_file_snippets.cpp index 10df04e302..f687ba88ab 100644 --- a/doc/tutorial/alignment_file/alignment_file_snippets.cpp +++ b/doc/tutorial/alignment_file/alignment_file_snippets.cpp @@ -1,4 +1,6 @@ #include + +#include #include //![include_aligned_sequence] @@ -7,6 +9,8 @@ struct write_file_dummy_struct { + std::filesystem::path const file_path = std::filesystem::temp_directory_path()/"example.sam"; + write_file_dummy_struct() { @@ -20,14 +24,18 @@ r003 2064 ref 29 17 5M * 0 0 TAGGC * r001 147 ref 37 30 9M = 7 -39 CAGCGGCAT * NM:i:1 )//![sam_file]"; - std::ofstream file{std::filesystem::temp_directory_path()/"example.sam"}; + std::ofstream file{file_path}; std::string str{file_raw}; file << str.substr(1); // skip first newline } ~write_file_dummy_struct() { - std::filesystem::remove(std::filesystem::temp_directory_path()/"example.sam"); + std::error_code ec{}; + std::filesystem::remove(file_path, ec); + + if (ec) + seqan3::debug_stream << "[WARNING] Could not delete " << file_path << ". " << ec.message() << '\n'; } }; diff --git a/doc/tutorial/alignment_file/alignment_file_solution2.cpp b/doc/tutorial/alignment_file/alignment_file_solution2.cpp index a3a4261ded..8862263eef 100644 --- a/doc/tutorial/alignment_file/alignment_file_solution2.cpp +++ b/doc/tutorial/alignment_file/alignment_file_solution2.cpp @@ -1,11 +1,15 @@ #include +#include #include struct write_file_dummy_struct { + std::filesystem::path const tmp_path = std::filesystem::temp_directory_path(); + write_file_dummy_struct() { + auto fasta_file_raw = R"//![ref_file]( >chr1 ACAGCAGGCATCTATCGGCGGATCGATCAGGCAGGCAGCTACTGG @@ -23,19 +27,30 @@ r004 0 chr2 16 60 6M14N5M * 0 0 ATAGCTTCAGC * r003 2064 chr2 18 10 5M * 0 0 TAGGC * )//![sam_file]"; - std::ofstream file{std::filesystem::temp_directory_path()/"mapping.sam"}; + std::ofstream file{tmp_path/"mapping.sam"}; std::string str{file_raw}; file << str.substr(1); // skip first newline - std::ofstream reffile{std::filesystem::temp_directory_path()/"reference.fasta"}; + std::ofstream reffile{tmp_path/"reference.fasta"}; std::string fasta_file_rawstr{fasta_file_raw}; reffile << fasta_file_rawstr.substr(1); // skip first newline } ~write_file_dummy_struct() { - std::filesystem::remove(std::filesystem::temp_directory_path()/"mapping.sam"); - std::filesystem::remove(std::filesystem::temp_directory_path()/"reference.fasta"); + std::error_code ec{}; + std::filesystem::path file_path{}; + + file_path = tmp_path/"mapping.sam"; + std::filesystem::remove(file_path, ec); + if (ec) + seqan3::debug_stream << "[WARNING] Could not delete " << file_path << ". " << ec.message() << '\n'; + + file_path = tmp_path/"reference.fasta"; + std::filesystem::remove(file_path, ec); + if (ec) + seqan3::debug_stream << "[WARNING] Could not delete " << file_path << ". " << ec.message() << '\n'; + } }; diff --git a/doc/tutorial/sequence_file/sequence_file_snippets.cpp b/doc/tutorial/sequence_file/sequence_file_snippets.cpp index 20dbe2cb83..ce93dde193 100644 --- a/doc/tutorial/sequence_file/sequence_file_snippets.cpp +++ b/doc/tutorial/sequence_file/sequence_file_snippets.cpp @@ -20,6 +20,8 @@ struct write_file_dummy_struct { + std::filesystem::path const tmp_path = std::filesystem::temp_directory_path(); + write_file_dummy_struct() { @@ -38,22 +40,36 @@ AGCGATCGAGGAATATAT IIIIHHGIIIIHHGIIIH )//![fastq_file]"; - std::ofstream file{std::filesystem::temp_directory_path()/"my.fastq"}; + std::ofstream file{tmp_path/"my.fastq"}; std::string str{file_raw}; file << str.substr(1); // skip first newline - std::ofstream file2{std::filesystem::temp_directory_path()/"my.qq"}; + std::ofstream file2{tmp_path/"my.qq"}; file2 << str.substr(1); // skip first newline - std::ofstream file3{std::filesystem::temp_directory_path()/"my.fasta"}; + std::ofstream file3{tmp_path/"my.fasta"}; file3 << ">seq1\nAVAV\n>seq2\nAVAVA\n"; } ~write_file_dummy_struct() { - std::filesystem::remove(std::filesystem::temp_directory_path()/"my.fastq"); - std::filesystem::remove(std::filesystem::temp_directory_path()/"my.qq"); - std::filesystem::remove(std::filesystem::temp_directory_path()/"my.fasta"); + std::error_code ec{}; + std::filesystem::path file_path{}; + + file_path = tmp_path/"my.fastq"; + std::filesystem::remove(file_path, ec); + if (ec) + seqan3::debug_stream << "[WARNING] Could not delete " << file_path << ". " << ec.message() << '\n'; + + file_path = tmp_path/"my.qq"; + std::filesystem::remove(file_path, ec); + if (ec) + seqan3::debug_stream << "[WARNING] Could not delete " << file_path << ". " << ec.message() << '\n'; + + file_path = tmp_path/"my.fasta"; + std::filesystem::remove(file_path, ec); + if (ec) + seqan3::debug_stream << "[WARNING] Could not delete " << file_path << ". " << ec.message() << '\n'; } }; @@ -178,5 +194,4 @@ sequence_file_output{tmp_dir/"output.fasta"} = sequence_file_input{tmp_dir/"my.f std::filesystem::remove(std::filesystem::temp_directory_path()/"output.fasta"); std::filesystem::remove(std::filesystem::temp_directory_path()/"output.fastq"); - } diff --git a/doc/tutorial/sequence_file/sequence_file_solution1.cpp b/doc/tutorial/sequence_file/sequence_file_solution1.cpp index 719bef6c9b..255ac8ff68 100644 --- a/doc/tutorial/sequence_file/sequence_file_solution1.cpp +++ b/doc/tutorial/sequence_file/sequence_file_solution1.cpp @@ -1,9 +1,12 @@ #include +#include #include struct write_file_dummy_struct { + std::filesystem::path const file_path = std::filesystem::temp_directory_path()/"my.fastq"; + write_file_dummy_struct() { @@ -22,14 +25,18 @@ AGCGATCGAGGAATATAT IIIIHHGIIIIHHGIIIH )//![fastq_file]"; - std::ofstream file{std::filesystem::temp_directory_path()/"my.fastq"}; + std::ofstream file{file_path}; std::string str{file_raw}; file << str.substr(1); // skip first newline } ~write_file_dummy_struct() { - std::filesystem::remove(std::filesystem::temp_directory_path()/"my.fastq"); + std::error_code ec{}; + std::filesystem::remove(file_path, ec); + + if (ec) + seqan3::debug_stream << "[WARNING] Could not delete " << file_path << ". " << ec.message() << '\n'; } }; diff --git a/doc/tutorial/sequence_file/sequence_file_solution2.cpp b/doc/tutorial/sequence_file/sequence_file_solution2.cpp index 8b292991e1..6e64bc014b 100644 --- a/doc/tutorial/sequence_file/sequence_file_solution2.cpp +++ b/doc/tutorial/sequence_file/sequence_file_solution2.cpp @@ -1,9 +1,12 @@ #include +#include #include struct write_file_dummy_struct { + std::filesystem::path const file_path = std::filesystem::temp_directory_path()/"my.fasta"; + write_file_dummy_struct() { @@ -14,14 +17,18 @@ AGCT CGATCGA )//![fasta_file]"; - std::ofstream file{std::filesystem::temp_directory_path()/"my.fasta"}; + std::ofstream file{file_path}; std::string str{file_raw}; file << str.substr(1); // skip first newline } ~write_file_dummy_struct() { - std::filesystem::remove(std::filesystem::temp_directory_path()/"my.fastq"); + std::error_code ec{}; + std::filesystem::remove(file_path, ec); + + if (ec) + seqan3::debug_stream << "[WARNING] Could not delete " << file_path << ". " << ec.message() << '\n'; } }; diff --git a/doc/tutorial/sequence_file/sequence_file_solution3.cpp b/doc/tutorial/sequence_file/sequence_file_solution3.cpp index 7ec12a81bd..87abe59dab 100644 --- a/doc/tutorial/sequence_file/sequence_file_solution3.cpp +++ b/doc/tutorial/sequence_file/sequence_file_solution3.cpp @@ -1,9 +1,12 @@ #include +#include #include struct write_file_dummy_struct { + std::filesystem::path const file_path = std::filesystem::temp_directory_path()/"my.fastq"; + write_file_dummy_struct() { @@ -30,14 +33,18 @@ AGCTAGCAGCGATCG IIIIIHIIJJIIIII )//![fastq_file]"; - std::ofstream file{std::filesystem::temp_directory_path()/"my.fastq"}; + std::ofstream file{file_path}; std::string str{file_raw}; file << str.substr(1); // skip first newline } ~write_file_dummy_struct() { - std::filesystem::remove(std::filesystem::temp_directory_path()/"my.fastq"); + std::error_code ec{}; + std::filesystem::remove(file_path, ec); + + if (ec) + seqan3::debug_stream << "[WARNING] Could not delete " << file_path << ". " << ec.message() << '\n'; } }; diff --git a/doc/tutorial/sequence_file/sequence_file_solution4.cpp b/doc/tutorial/sequence_file/sequence_file_solution4.cpp index dcc5932dbd..e8a2d40d69 100644 --- a/doc/tutorial/sequence_file/sequence_file_solution4.cpp +++ b/doc/tutorial/sequence_file/sequence_file_solution4.cpp @@ -1,9 +1,12 @@ #include +#include #include struct write_file_dummy_struct { + std::filesystem::path const tmp_path = std::filesystem::temp_directory_path(); + write_file_dummy_struct() { @@ -30,14 +33,26 @@ AGCTAGCAGCGATCG IIIIIHIIJJIIIII )//![fastq_file]"; - std::ofstream file{std::filesystem::temp_directory_path()/"my.fastq"}; + std::ofstream file{tmp_path/"my.fastq"}; std::string str{file_raw}; file << str.substr(1); // skip first newline } ~write_file_dummy_struct() { - std::filesystem::remove(std::filesystem::temp_directory_path()/"my.fastq"); + std::error_code ec{}; + std::filesystem::path file_path{}; + + file_path = tmp_path/"my.fastq"; + std::filesystem::remove(file_path, ec); + if (ec) + seqan3::debug_stream << "[WARNING] Could not delete " << file_path << ". " << ec.message() << '\n'; + + file_path = tmp_path/"output.fastq"; + std::filesystem::remove(file_path, ec); + if (ec) + seqan3::debug_stream << "[WARNING] Could not delete " << file_path << ". " << ec.message() << '\n'; + } }; diff --git a/doc/tutorial/sequence_file/sequence_file_solution5.cpp b/doc/tutorial/sequence_file/sequence_file_solution5.cpp index a24b6168a0..13ea322782 100644 --- a/doc/tutorial/sequence_file/sequence_file_solution5.cpp +++ b/doc/tutorial/sequence_file/sequence_file_solution5.cpp @@ -1,9 +1,12 @@ #include +#include #include struct write_file_dummy_struct { + std::filesystem::path const tmp_path = std::filesystem::temp_directory_path(); + write_file_dummy_struct() { @@ -30,14 +33,26 @@ AGCTAGCAGCGATCG IIIIIHIIJJIIIII )//![fastq_file]"; - std::ofstream file{std::filesystem::temp_directory_path()/"my.fastq"}; + std::ofstream file{tmp_path/"my.fastq"}; std::string str{file_raw}; file << str.substr(1); // skip first newline } ~write_file_dummy_struct() { - std::filesystem::remove(std::filesystem::temp_directory_path()/"my.fastq"); + std::error_code ec{}; + std::filesystem::path file_path{}; + + file_path = tmp_path/"my.fastq"; + std::filesystem::remove(file_path, ec); + if (ec) + seqan3::debug_stream << "[WARNING] Could not delete " << file_path << ". " << ec.message() << '\n'; + + file_path = tmp_path/"output.fastq"; + std::filesystem::remove(file_path, ec); + if (ec) + seqan3::debug_stream << "[WARNING] Could not delete " << file_path << ". " << ec.message() << '\n'; + } }; diff --git a/test/include/seqan3/test/tmp_filename.hpp b/test/include/seqan3/test/tmp_filename.hpp index 3506869494..dd84f097f7 100644 --- a/test/include/seqan3/test/tmp_filename.hpp +++ b/test/include/seqan3/test/tmp_filename.hpp @@ -118,6 +118,9 @@ class tmp_filename } /*!\brief Destructs the temporary directory path. + * + * \details + * * Removes the temporary directory and all its subdirectories and files contained. */ ~tmp_filename()