Throw a transport exception if fstat fails.
authorDavid Reiss <dreiss@apache.org>
Thu, 1 May 2008 06:21:04 +0000 (06:21 +0000)
committerDavid Reiss <dreiss@apache.org>
Thu, 1 May 2008 06:21:04 +0000 (06:21 +0000)
This was failing on an NFS mount that was dying.
Better to fail hard then return uninitialized data.

git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665677 13f79535-47bb-0310-9956-ffa450edef68

lib/cpp/src/transport/TFileTransport.cpp

index 6c4920f..d376795 100644 (file)
@@ -734,8 +734,17 @@ uint32_t TFileTransport::getNumChunks() {
   if (fd_ <= 0) {
     return 0;
   }
+
   struct stat f_info;
-  fstat(fd_, &f_info);
+  int rv = fstat(fd_, &f_info);
+
+  if (rv < 0) {
+    int errno_copy = errno;
+    throw TTransportException(TTransportException::UNKNOWN,
+                              "TFileTransport::getNumChunks() (fstat)",
+                              errno_copy);
+  }
+
   if (f_info.st_size > 0) {
     return ((f_info.st_size)/chunkSize_) + 1;
   }