From 03a9cf7c21a4cc40322c9eec9cc3dbde6559d9aa Mon Sep 17 00:00:00 2001 From: Artyom Beilis Date: Tue, 22 Dec 2015 22:03:53 +0000 Subject: [PATCH] Fixed issue with temporary file removal --- private/http_file_buffer.h | 9 ++++++++- src/http_file.cpp | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/private/http_file_buffer.h b/private/http_file_buffer.h index b19ca83..3b58251 100644 --- a/private/http_file_buffer.h +++ b/private/http_file_buffer.h @@ -49,7 +49,8 @@ public: f_(0), limit_(mlimit), file_size_(0), - read_offset_(0) + read_offset_(0), + closed_(false) { setp(0,0); setg(0,0,0); @@ -93,6 +94,8 @@ public: int close() { + if(closed_) + return 0; if(sync() < 0) return -1; if(f_) { @@ -107,6 +110,7 @@ public: clear(input_); clear(output_); clear(data_); + closed_ = true; return 0; } #ifdef DEBUG_FILE_BUFFER @@ -304,6 +308,8 @@ protected: } int write_buffer() { + if(closed_) + return -1; if(!f_) { get_name(); f_ = booster::nowide::fopen(name_.c_str(),"w+b"); @@ -335,6 +341,7 @@ private: std::vector data_; std::string temp_dir_; std::string name_; + bool closed_; }; } // impl diff --git a/src/http_file.cpp b/src/http_file.cpp index 3bd990b..9dfce30 100644 --- a/src/http_file.cpp +++ b/src/http_file.cpp @@ -159,6 +159,7 @@ int file::close() int r = d->fb.close(); if(file_temporary_ && !d->fb.name().empty()) { booster::nowide::remove(d->fb.name().c_str()); + removed_ = 1; } return r; }