lmi-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi-commits] [lmi] master a8bd7d2 2/2: Test msw locked-file anomaly on


From: Greg Chicares
Subject: [lmi-commits] [lmi] master a8bd7d2 2/2: Test msw locked-file anomaly on msw only
Date: Wed, 3 May 2017 18:55:07 -0400 (EDT)

branch: master
commit a8bd7d21064dbba175496293ec779c760ab662ab
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>

    Test msw locked-file anomaly on msw only
    
    Incidentally, remove files in reverse creation order: that's more
    logical in general, and made the msw-conditional code simpler.
---
 path_utility.cpp      | 15 ++++++++++-----
 path_utility_test.cpp | 12 ++++++++----
 2 files changed, 18 insertions(+), 9 deletions(-)

diff --git a/path_utility.cpp b/path_utility.cpp
index 6fe2210..2e0e8e5 100644
--- a/path_utility.cpp
+++ b/path_utility.cpp
@@ -231,10 +231,10 @@ fs::path serial_file_path
 /// file 'foo.in', and output is to be saved in a pdf file. A natural
 /// name for the pdf file would be 'foo.pdf'. If a file with that
 /// exact name already exists, it should normally be erased, and its
-/// name reused: that's what an end user would expect. But that's not
-/// possible if 'foo.pdf' is already open in some viewer that locks it
-/// against modification; in that case, a distinct new name must be
-/// devised.
+/// name reused: that's what an end user would expect, and it's how
+/// *nix naturally works. But that's not possible on msw if 'foo.pdf'
+/// is already open in some viewer that locks it against modification;
+/// in that case, a distinct new name must be devised.
 ///
 /// Postcondition: !exists(returned_filepath).
 ///
@@ -246,7 +246,7 @@ fs::path serial_file_path
 /// hardly run illustrations faster than once a second. If even that
 /// fails to establish the postcondition, then throw an exception.
 ///
-/// Implementation note.
+/// Implementation notes.
 ///
 /// A try-block is necessary because fs::remove() can throw. The
 /// postcondition is asserted explicitly at the end of the try-block
@@ -255,6 +255,11 @@ fs::path serial_file_path
 /// apparently it mustn't fail without throwing, yet it doesn't throw
 /// on an operation that must fail, like removing a file that's locked
 /// by another process as in the motivating example above.
+///
+/// For *nix, the catch-clause is not normally expected to be reached,
+/// and the alternative filename it devises might work no better than
+/// the original. However, it doesn't hurt to try it, so there's no
+/// reason to restrict it to msw.
 
 fs::path unique_filepath
     (fs::path    const& original_filepath
diff --git a/path_utility_test.cpp b/path_utility_test.cpp
index 88a64a3..85f5892 100644
--- a/path_utility_test.cpp
+++ b/path_utility_test.cpp
@@ -164,6 +164,9 @@ void test_unique_filepath_with_normal_filenames()
     write_dummy_file(path1);
     BOOST_TEST_EQUAL(0, access(path1.string().c_str(), R_OK));
 
+#if defined LMI_MSW
+    // This conditional block tests an msw "feature".
+
     // Open a file for writing, and leave it open, preventing it from
     // being erased and therefore forcing unique_filepath() to use a
     // different name. This behavior isn't guaranteed on toy OS's.
@@ -212,10 +215,11 @@ void test_unique_filepath_with_normal_filenames()
 
     // Clean up the files created in this function.
 
-    BOOST_TEST(0 == std::remove(p));
-    BOOST_TEST(0 == std::remove(q));
-    BOOST_TEST(0 == std::remove(path2.string().c_str()));
     BOOST_TEST(0 == std::remove(path3.string().c_str()));
+    BOOST_TEST(0 == std::remove(path2.string().c_str()));
+#endif // defined LMI_MSW
+    BOOST_TEST(0 == std::remove(q));
+    BOOST_TEST(0 == std::remove(p));
 }
 
 void test_unique_filepath_with_ludicrous_filenames()
@@ -298,8 +302,8 @@ void test_path_validation()
         );
 
     // Remove file and directory created for this test.
-    fs::remove("path_utility_test_dir");
     fs::remove("path_utility_test_file");
+    fs::remove("path_utility_test_dir");
 }
 
 int test_main(int, char*[])



reply via email to

[Prev in Thread] Current Thread [Next in Thread]