fix Stat::recheck(), seems like noone ever tested it...
authorGerd von Egidy <gerd.von.egidy@intra2net.com>
Tue, 9 Mar 2010 18:01:25 +0000 (19:01 +0100)
committerGerd von Egidy <gerd.von.egidy@intra2net.com>
Tue, 9 Mar 2010 18:01:25 +0000 (19:01 +0100)
src/filefunc.cpp
test/test_filefunc.cpp

index 469b2b3..c0995e6 100644 (file)
@@ -63,7 +63,8 @@ void Stat::recheck()
 {
     if (! Path.empty())
     {
-        stat(Path, FollowLinks);
+        // pass a copy of Path: otherwise clear() would leave an empty reference
+        stat(string(Path), FollowLinks);
     }
 } // eo Stat::recheck()
 
index 2ca37b0..f00e0f5 100644 (file)
@@ -95,6 +95,23 @@ BOOST_AUTO_TEST_CASE(StatTest1)
     BOOST_CHECK_EQUAL( false, stat.is_block_device() );
 } // eo StatTest1
 
+BOOST_AUTO_TEST_CASE(StatRecheck)
+{
+    // just to be sure
+    unlink(".foobar");
+
+    I2n::Stat stat(".foobar");
+    BOOST_CHECK_EQUAL( false, (bool)stat );
+
+    write_file(".foobar","hello world");
+
+    stat.recheck();
+
+    BOOST_CHECK_EQUAL( true, (bool)stat );
+    BOOST_CHECK_EQUAL( true, stat.size() > 0 );
+
+    unlink(".foobar");
+}
 
 BOOST_AUTO_TEST_CASE(DirTest1)
 {