OmniSciDB  29e35f4d58
File.cpp File Reference

Implementation of helper methods for File I/O. More...

#include "File.h"
#include <boost/filesystem.hpp>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <stdexcept>
#include <string>
#include "Logger.h"
#include <atomic>
#include <boost/algorithm/string/predicate.hpp>
#include <chrono>
#include <thread>
+ Include dependency graph for File.cpp:

Go to the source code of this file.

Namespaces

 File_Namespace
 

Functions

FILE * File_Namespace::create (const std::string &basePath, const int fileId, const size_t pageSize, const size_t numPages)
 
FILE * File_Namespace::create (const std::string &fullPath, const size_t requestedFileSize)
 
FILE * File_Namespace::open (int fileId)
 Opens/creates the file with the given id; returns NULL on error. More...
 
FILE * File_Namespace::open (const std::string &path)
 
void File_Namespace::close (FILE *f)
 Closes the file pointed to by the FILE pointer. More...
 
bool File_Namespace::removeFile (const std::string basePath, const std::string filename)
 Deletes the file pointed to by the FILE pointer. More...
 
size_t File_Namespace::read (FILE *f, const size_t offset, const size_t size, int8_t *buf)
 Reads the specified number of bytes from the offset position in file f into buf. More...
 
size_t File_Namespace::write (FILE *f, const size_t offset, const size_t size, int8_t *buf)
 Writes the specified number of bytes to the offset position in file f from buf. More...
 
size_t File_Namespace::append (FILE *f, const size_t size, int8_t *buf)
 Appends the specified number of bytes to the end of the file f from buf. More...
 
size_t File_Namespace::readPage (FILE *f, const size_t pageSize, const size_t pageNum, int8_t *buf)
 Reads the specified page from the file f into buf. More...
 
size_t File_Namespace::readPartialPage (FILE *f, const size_t pageSize, const size_t offset, const size_t readSize, const size_t pageNum, int8_t *buf)
 
size_t File_Namespace::writePage (FILE *f, const size_t pageSize, const size_t pageNum, int8_t *buf)
 Writes a page from buf to the file. More...
 
size_t File_Namespace::writePartialPage (FILE *f, const size_t pageSize, const size_t offset, const size_t writeSize, const size_t pageNum, int8_t *buf)
 
size_t File_Namespace::appendPage (FILE *f, const size_t pageSize, int8_t *buf)
 Appends a page from buf to the file. More...
 
size_t File_Namespace::fileSize (FILE *f)
 Returns the size of the specified file. More...
 
void File_Namespace::renameForDelete (const std::string directoryName)
 Renames a directory to DELETE_ME_<EPOCH>_<oldname>. More...
 
void file_delete (std::atomic< bool > &program_is_running, const unsigned int wait_interval_seconds, const std::string base_path)
 

Detailed Description

Implementation of helper methods for File I/O.

Author
Steven Stewart steve.nosp@m.@map.nosp@m.-d.co.nosp@m.m

Definition in file File.cpp.

Function Documentation

◆ file_delete()

void file_delete ( std::atomic< bool > &  program_is_running,
const unsigned int  wait_interval_seconds,
const std::string  base_path 
)

Definition at line 227 of file File.cpp.

References logger::ERROR, error_code, logger::INFO, and LOG.

Referenced by startMapdServer().

229  {
230  const auto wait_duration = std::chrono::seconds(wait_interval_seconds);
231  const boost::filesystem::path path(base_path);
232  while (program_is_running) {
233  using vec = std::vector<boost::filesystem::path>; // store paths,
234  vec v;
236 
237  // copy vector from iterator as was getting weird random errors if
238  // removed direct from iterator
239  copy(boost::filesystem::directory_iterator(path),
240  boost::filesystem::directory_iterator(),
241  back_inserter(v));
242  for (vec::const_iterator it(v.begin()); it != v.end(); ++it) {
243  std::string object_name(it->string());
244 
245  if (boost::algorithm::ends_with(object_name, "DELETE_ME")) {
246  LOG(INFO) << " removing object " << object_name;
247  boost::filesystem::remove_all(*it, ec);
248  if (ec.value() != boost::system::errc::success) {
249  LOG(ERROR) << "Failed to remove object " << object_name << " error was " << ec;
250  }
251  }
252  }
253 
254  std::this_thread::sleep_for(wait_duration);
255  }
256 }
#define LOG(tag)
Definition: Logger.h:188
const int8_t const int64_t const uint64_t const int32_t const int64_t int64_t uint32_t const int64_t int32_t * error_code
+ Here is the caller graph for this function: