about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2016-11-25 22:07:31 -0800
committerKartik K. Agaram <vc@akkartik.com>2016-11-25 22:09:44 -0800
commit4beaf39d4ffa1502a1697f831cc5639e38aa7374 (patch)
tree2a0b1948997d27a8e8b8645b4d0fc139e4a82b94
parentf222051e01e05f2e9666235a5664536cb772d230 (diff)
downloadmu-4beaf39d4ffa1502a1697f831cc5639e38aa7374.tar.gz
3690
Attempting to write to a file in a non-existent directory silently
writes to a black hole in Unix. Make that explicit.
-rw-r--r--102persist.cc1
-rw-r--r--html/102persist.cc.html1
2 files changed, 2 insertions, 0 deletions
diff --git a/102persist.cc b/102persist.cc
index abefeda6..642385df 100644
--- a/102persist.cc
+++ b/102persist.cc
@@ -98,6 +98,7 @@ case SAVE: {
     filename = read_mu_text(ingredients.at(0).at(0));
   }
   ofstream fout(("lesson/"+filename).c_str());
+  if (!fout) break;
   string contents = read_mu_text(ingredients.at(1).at(0));
   fout << contents;
   fout.close();
diff --git a/html/102persist.cc.html b/html/102persist.cc.html
index 55961625..863546d2 100644
--- a/html/102persist.cc.html
+++ b/html/102persist.cc.html
@@ -130,6 +130,7 @@ put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span
     filename = read_mu_text<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">));</span>
   <span class="Delimiter">}</span>
   ofstream fout<span class="Delimiter">((</span><span class="Constant">&quot;lesson/&quot;</span>+filename<span class="Delimiter">).</span>c_str<span class="Delimiter">());</span>
+  <span class="Normal">if</span> <span class="Delimiter">(</span>!fout<span class="Delimiter">)</span> <span class="Identifier">break</span><span class="Delimiter">;</span>
   string contents = read_mu_text<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">).</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">));</span>
   fout &lt;&lt; contents<span class="Delimiter">;</span>
   fout<span class="Delimiter">.</span>close<span class="Delimiter">();</span>