diff options
author | Chris Wilson <chris+github@qwirx.com> | 2008-05-28 12:36:53 +0000 |
---|---|---|
committer | Chris Wilson <chris+github@qwirx.com> | 2008-05-28 12:36:53 +0000 |
commit | 0ed03aa198fedb15283018dff384dfad0dc97c79 (patch) | |
tree | 0e9b814ae64af6f8cbd13f43b272d79b0a16bd8b /lib | |
parent | c13d500d013c8eac0502a319941a9548206aaa82 (diff) |
Separate checks for file existing and file not empty.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/common/Test.cpp | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/lib/common/Test.cpp b/lib/common/Test.cpp index 563c2e36..92793c1b 100644 --- a/lib/common/Test.cpp +++ b/lib/common/Test.cpp @@ -25,6 +25,12 @@ bool TestFileExists(const char *Filename) { struct stat st; + return ::stat(Filename, &st) == 0 && (st.st_mode & S_IFDIR) == 0; +} + +bool TestFileNotEmpty(const char *Filename) +{ + struct stat st; return ::stat(Filename, &st) == 0 && (st.st_mode & S_IFDIR) == 0 && st.st_size > 0; } @@ -102,7 +108,7 @@ bool ServerIsAlive(int pid) int ReadPidFile(const char *pidFile) { - if(!TestFileExists(pidFile)) + if(!TestFileNotEmpty(pidFile)) { TEST_FAIL_WITH_MESSAGE("Server didn't save PID file " "(perhaps one was already running?)"); @@ -194,7 +200,7 @@ int LaunchServer(const std::string& rCommandLine, const char *pidFile) for (int i = 0; i < 15; i++) { - if (TestFileExists(pidFile)) + if (TestFileNotEmpty(pidFile)) { break; } @@ -223,7 +229,7 @@ int LaunchServer(const std::string& rCommandLine, const char *pidFile) } #endif - if (!TestFileExists(pidFile)) + if (!TestFileNotEmpty(pidFile)) { ::fprintf(stdout, " timed out!\n"); TEST_FAIL_WITH_MESSAGE("Server didn't save PID file"); |