OmniSciDB  a5dc49c757
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
File.cpp File Reference

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

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

Go to the source code of this file.

Namespaces

 File_Namespace
 

Functions

std::string File_Namespace::get_data_file_path (const std::string &base_path, int file_id, size_t page_size)
 
std::string File_Namespace::get_legacy_data_file_path (const std::string &new_data_file_path)
 
std::pair< FILE *, std::string > 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 &full_path, const size_t requested_file_size)
 Opens/creates a file with the given path and file size. Fatal crash if file can not be created to required size. More...
 
FILE * File_Namespace::open (int file_id)
 Opens the file with the given id; fatal crash 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, const std::string &file_path)
 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, const 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, const 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, const std::string &file_path)
 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, const std::string &file_path)
 
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.

Definition in file File.cpp.

Function Documentation

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

Definition at line 272 of file File.cpp.

References gpu_enabled::copy(), logger::ERROR, report::error_code(), logger::INFO, and LOG.

Referenced by startHeavyDBServer().

274  {
275  const auto wait_duration = std::chrono::seconds(wait_interval_seconds);
276  const boost::filesystem::path path(base_path);
277  while (program_is_running) {
278  using vec = std::vector<boost::filesystem::path>; // store paths,
279  vec v;
281 
282  // copy vector from iterator as was getting weird random errors if
283  // removed direct from iterator
284  copy(boost::filesystem::directory_iterator(path),
285  boost::filesystem::directory_iterator(),
286  back_inserter(v));
287  for (vec::const_iterator it(v.begin()); it != v.end(); ++it) {
288  std::string object_name(it->string());
289 
290  if (boost::algorithm::ends_with(object_name, "DELETE_ME")) {
291  LOG(INFO) << " removing object " << object_name;
292  boost::filesystem::remove_all(*it, ec);
293  if (ec.value() != boost::system::errc::success) {
294  LOG(ERROR) << "Failed to remove object " << object_name << " error was " << ec;
295  }
296  }
297  }
298 
299  std::this_thread::sleep_for(wait_duration);
300  }
301 }
#define LOG(tag)
Definition: Logger.h:285
DEVICE auto copy(ARGS &&...args)
Definition: gpu_enabled.h:51
def error_code
Definition: report.py:234

+ Here is the call graph for this function:

+ Here is the caller graph for this function: