Replace file reading code in wxTextFile with wxFile::ReadAll()
There is nothing special about wxTextFile justifying having code for
dealing with non-seekable files in it, so put this code into wxFile
itself and just call its ReadAll() method from here.
This is a better fix than 41f6f17d01
originally applied (and which is going to be reverted next) as it
doesn't break wxFile::Length() for these files and also avoids
triggering an assert if the file we're trying to read was truncated by
another process in the meanwhile -- which can happen and doesn't
indicate a programming error and so shouldn't result in an assert.
Also add a unit test checking that this really works.
See #3802, #8354, #9965.
This commit is contained in:
@@ -338,5 +338,29 @@ void TextFileTestCase::ReadBig()
|
||||
f[NUM_LINES - 1] );
|
||||
}
|
||||
|
||||
#endif // wxUSE_TEXTFILE
|
||||
#ifdef __LINUX__
|
||||
|
||||
// Check if using wxTextFile with special files, whose reported size doesn't
|
||||
// correspond to the real amount of data in them, works.
|
||||
TEST_CASE("wxTextFile::Special", "[textfile][linux][special-file]")
|
||||
{
|
||||
SECTION("/proc")
|
||||
{
|
||||
wxTextFile f;
|
||||
CHECK( f.Open("/proc/diskstats") );
|
||||
CHECK( f.GetLineCount() > 1 );
|
||||
}
|
||||
|
||||
SECTION("/sys")
|
||||
{
|
||||
wxTextFile f;
|
||||
CHECK( f.Open("/sys/power/state") );
|
||||
REQUIRE( f.GetLineCount() == 1 );
|
||||
INFO( "/sys/power/state contains \"" << f[0] << "\"" );
|
||||
CHECK( f[0].find("mem") != wxString::npos );
|
||||
}
|
||||
}
|
||||
|
||||
#endif // __LINUX__
|
||||
|
||||
#endif // wxUSE_TEXTFILE
|
||||
|
Reference in New Issue
Block a user