arrow-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From w...@apache.org
Subject arrow git commit: ARROW-1500: [C++] Do not ignore return value from truncate in MemoryMa…
Date Thu, 21 Sep 2017 00:51:34 GMT
Repository: arrow
Updated Branches:
  refs/heads/master 975f32b1e -> 203fb6355


ARROW-1500: [C++] Do not ignore return value from truncate in MemoryMa…

…ppedFile::Create

Author: Amir Malekpour <a.malekpour@gmail.com>

Author: Amir Malekpour <a.malekpour@gmail.com>

Closes #1116 from amirma/arrow-1500 and squashes the following commits:

689aaa9 [Amir Malekpour]  RROW-1500: [C++] Do not ignore return value from truncate in MemoryMappedFile::Create


Project: http://git-wip-us.apache.org/repos/asf/arrow/repo
Commit: http://git-wip-us.apache.org/repos/asf/arrow/commit/203fb635
Tree: http://git-wip-us.apache.org/repos/asf/arrow/tree/203fb635
Diff: http://git-wip-us.apache.org/repos/asf/arrow/diff/203fb635

Branch: refs/heads/master
Commit: 203fb635505ad9ffe6a205f9473cfc6e6f47e500
Parents: 975f32b
Author: Amir Malekpour <a.malekpour@gmail.com>
Authored: Wed Sep 20 20:51:29 2017 -0400
Committer: Wes McKinney <wes.mckinney@twosigma.com>
Committed: Wed Sep 20 20:51:29 2017 -0400

----------------------------------------------------------------------
 cpp/src/arrow/io/file.cc | 25 +++++++++++++++++--------
 1 file changed, 17 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/arrow/blob/203fb635/cpp/src/arrow/io/file.cc
----------------------------------------------------------------------
diff --git a/cpp/src/arrow/io/file.cc b/cpp/src/arrow/io/file.cc
index 843cfe8..ca53632 100644
--- a/cpp/src/arrow/io/file.cc
+++ b/cpp/src/arrow/io/file.cc
@@ -134,12 +134,13 @@ struct PlatformFilename {
 };
 #endif
 
-static inline Status CheckOpenResult(int ret, int errno_actual,
-                                     const PlatformFilename& file_name) {
+static inline Status CheckFileOpResult(int ret, int errno_actual,
+                                       const PlatformFilename& file_name,
+                                       const std::string& opname) {
   if (ret == -1) {
-    // TODO: errno codes to strings
     std::stringstream ss;
-    ss << "Failed to open local file: " << file_name.string();
+    ss << "Failed to " << opname << " file: " << file_name.string();
+    ss << " , error: " << std::strerror(errno_actual);
     return Status::IOError(ss.str());
   }
   return Status::OK();
@@ -168,7 +169,7 @@ static inline Status FileOpenReadable(const PlatformFilename& file_name,
int* fd
   errno_actual = errno;
 #endif
 
-  return CheckOpenResult(ret, errno_actual, file_name);
+  return CheckFileOpResult(ret, errno_actual, file_name, "open local");
 }
 
 static inline Status FileOpenWriteable(const PlatformFilename& file_name, bool write_only,
@@ -211,7 +212,7 @@ static inline Status FileOpenWriteable(const PlatformFilename& file_name,
bool w
 
   ret = *fd = open(file_name.c_str(), oflag, ARROW_WRITE_SHMODE);
 #endif
-  return CheckOpenResult(ret, errno_actual, file_name);
+  return CheckFileOpResult(ret, errno_actual, file_name, "open local");
 }
 
 static inline Status FileTell(int fd, int64_t* pos) {
@@ -599,13 +600,21 @@ MemoryMappedFile::~MemoryMappedFile() {}
 
 Status MemoryMappedFile::Create(const std::string& path, int64_t size,
                                 std::shared_ptr<MemoryMappedFile>* out) {
+  int ret;
+  errno_t errno_actual;
   std::shared_ptr<FileOutputStream> file;
   RETURN_NOT_OK(FileOutputStream::Open(path, &file));
+
 #ifdef _MSC_VER
-  _chsize_s(file->file_descriptor(), static_cast<size_t>(size));
+  errno_actual = _chsize_s(file->file_descriptor(), static_cast<size_t>(size));
+  ret = errno_actual == 0 ? 0 : -1;
 #else
-  ftruncate(file->file_descriptor(), static_cast<size_t>(size));
+  ret = ftruncate(file->file_descriptor(), static_cast<size_t>(size));
+  errno_actual = errno;
 #endif
+
+  RETURN_NOT_OK(CheckFileOpResult(ret, errno_actual, PlatformFilename(path), "truncate"));
+
   RETURN_NOT_OK(file->Close());
   return MemoryMappedFile::Open(path, FileMode::READWRITE, out);
 }


Mime
View raw message