inline void create_tmp_and_clean_old(std::string &tmp_name)
{
   //First get the temp directory
   std::string root_tmp_name;
   get_tmp_base_dir(root_tmp_name);

   //If fails, check that it's because already exists
   if(!create_directory(root_tmp_name.c_str())){
      error_info info(system_error_code());
      if(info.get_error_code() != already_exists_error){
         throw interprocess_exception(info);
      }
   }

   #if defined(BOOST_INTERPROCESS_HAS_KERNEL_BOOTTIME)
      tmp_folder(tmp_name);

      //If fails, check that it's because already exists
      if(!create_directory(tmp_name.c_str())){
         error_info info(system_error_code());
         if(info.get_error_code() != already_exists_error){
            throw interprocess_exception(info);
         }
      }
      //Now erase all old directories created in the previous boot sessions
      std::string subdir = tmp_name;
      subdir.erase(0, root_tmp_name.size()+1);
      delete_subdirectories(root_tmp_name, subdir.c_str());
   #else
      tmp_name = root_tmp_name;
   #endif
}
Beispiel #2
0
inline void tmp_folder(std::string &tmp_name)
{
   get_tmp_base_dir(tmp_name);
   #ifdef BOOST_INTERPROCESS_HAS_KERNEL_BOOTTIME
   tmp_name += "/";
   get_bootstamp(tmp_name, true);
   #endif
}
inline void tmp_filename(const char *filename, std::string &tmp_name)
{
   get_tmp_base_dir(tmp_name);
   //Remove final null.
   tmp_name += "/";
   #ifdef BOOST_INTERPROCESS_HAS_KERNEL_BOOTTIME
   get_bootstamp(tmp_name, true);
   tmp_name += '/';
   #endif
   tmp_name += filename;
}
inline void create_tmp_dir_and_get_filename(const char *filename, std::string &tmp_name)
{
   //First get the temp directory
   get_tmp_base_dir(tmp_name);

   //If fails, check that it's because already exists
   if(!create_directory(tmp_name.c_str())){
      error_info info(system_error_code());
      if(info.get_error_code() != already_exists_error){
         throw interprocess_exception(info);
      }
   }

   #ifdef BOOST_INTERPROCESS_HAS_KERNEL_BOOTTIME
   //Create a new subdirectory with the bootstamp
   std::string root_tmp_name = tmp_name;
   tmp_name += '/';
   //Obtain bootstamp string
   std::string bootstamp;
   get_bootstamp(bootstamp);
   tmp_name += bootstamp; 

   //If fails, check that it's because already exists
   if(!create_directory(tmp_name.c_str())){
      error_info info(system_error_code());
      if(info.get_error_code() != already_exists_error){
         throw interprocess_exception(info);
      }
   }
   //Now erase all old directories created in the previous boot sessions
   delete_subdirectories(root_tmp_name, bootstamp.c_str());
   #endif

   //Add filename
   tmp_name += '/';
   tmp_name += filename;
}