Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 17 additions & 8 deletions cpp/src/arrow/io/file.cc
Expand Up @@ -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();
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}
Expand Down