8 SplitFile::SplitFile() : m_file(NULL), m_count(0), m_shflag(_SH_DENYNO), m_toggle_readonly(false), m_current_bytes(0), m_mode(
IFile::ReadOnly)
32 Poco::Path p(file_name);
35 f.createDirectories();
38 RetryWIN32APIBOOL(boost::bind(SetFileAttributes, file_name.c_str(), FILE_ATTRIBUTE_NORMAL), 10);
40 std::string fmode =
openMode(file_name);
41 for(
int nretry = 10; ((
m_file = _fsopen(file_name.c_str(), fmode.c_str(),
m_shflag)) == NULL) && (nretry > 0); --nretry)
43 LOGSTR_ERROR(file_name +
" in mode " + fmode +
": " + strerror(errno));
60 return static_cast<size_t>(-1);
66 return fwrite(data, element_size, nelement,
m_file);
69 if (fwrite(data, element_size, n1,
m_file) != n1)
71 return static_cast<size_t>(-1);
74 n =
write((
const char*)data + n1 * element_size, element_size, nelement - n1);
81 return static_cast<size_t>(-1);
89 return static_cast<size_t>(-1);
99 return fread(data, element_size, nelement,
m_file);
102 if ( (n = fread(data, element_size, n1,
m_file)) != n1 )
104 if (n != static_cast<size_t>(-1))
111 n =
read((
char*)data + n1 * element_size, element_size, nelement - n1);
112 if ( n != static_cast<size_t>(-1) )
118 return static_cast<size_t>(-1);
126 throw std::runtime_error(
"close");
131 throw std::runtime_error(
"open");
142 throw std::runtime_error(
"flush");
156 if (whence != SEEK_SET)
158 throw std::runtime_error(
"SplitFile::seek");
165 throw std::runtime_error(
"close");
170 throw std::runtime_error(
"open");
183 throw std::runtime_error(
"ftell");
190 std::set<std::string> files;
193 BOOST_FOREACH(
const std::string& s, files)
195 if (s != current_file)
197 RetryWIN32APIBOOL(boost::bind(SetFileAttributes, s.c_str(), FILE_ATTRIBUTE_NORMAL), 10);
198 std::remove(s.c_str());
203 return _chsize(fileno(
m_file), 0);
207 std::remove(current_file.c_str());
214 std::set<std::string> files;
215 findFiles(Poco::Path::forDirectory(path), files);
216 BOOST_FOREACH(
const std::string& s, files)
218 RetryWIN32APIBOOL(boost::bind(SetFileAttributes, s.c_str(), FILE_ATTRIBUTE_NORMAL), 10);
219 std::remove(s.c_str());
227 catch(
const std::exception& )
263 p.pushDirectory(Poco::format(
"D%lu", (
unsigned long)(count / m_files_per_sub_dir)));
275 std::string file_expr(
"F[0-9]*.tmp");
276 Poco::Path search_expr(path, file_expr);
277 search_expr.pushDirectory(
"D[0-9]*");
278 Poco::Glob::glob(search_expr, files, Poco::Glob::GLOB_CASELESS);
292 if (_access(path.c_str(), 0) == 0)
int tell(int64_t &offset)
int seek(int64_t offset, int whence)
size_t write(const void *data, size_t element_size, size_t nelement)
size_t countFromOffset(int64_t offset) const
Poco::Path m_top_directory
static void RetryWIN32APIBOOL(boost::function< BOOL()> func, int nretry)
std::string fileNamefromCount(size_t count) const
static const size_t m_files_per_sub_dir
size_t read(void *data, size_t element_size, size_t nelement)
void findFiles(std::set< std::string > &files) const
std::string openMode(const std::string &path) const
determine flags to use for fopen/fsopen
#define LOGSTR_ERROR(__arg)
static void removeFile(const std::string &path)
void setLoggerName(const std::string &logger_name)
static const size_t m_bytes_per_file
std::string getFileName() const