void restart() { namespace fs = boost::filesystem; if ( m_flags.initial_erase()) { for ( unsigned idx = 0; idx < m_flags.file_count(); ++idx) { boost::system::error_code ec; if ( fs::exists( file_name(idx), ec) && !ec) fs::remove( file_name(idx) ); } } // see what file to start from if ( m_flags.start_where_size_not_exceeded() ) { for ( m_cur_idx = 0; m_cur_idx < m_flags.file_count(); ++m_cur_idx ) { boost::system::error_code ec; if ( fs::exists( file_name(m_cur_idx), ec) && !ec) { if ( fs::file_size( file_name(m_cur_idx)) < m_flags.max_size_bytes() ) // file hasn't reached max size break; } else // file not found, we'll create it now break; } if ( m_cur_idx >= m_flags.file_count()) // all files are too full (we'll overwrite the first one) m_cur_idx = 0; } recreate_file(); }
void rolling_file_writer::check_renew_file_pre_log(const tm* cur_tm) { if ( settinges_.new_file_by_date ) { const tm* new_tm; if ( cur_tm ) { new_tm = cur_tm; } else { time_t val = ::time(0); new_tm = localtime( &val); } if ( new_tm->tm_year > last_tm_.tm_year || new_tm->tm_year == last_tm_.tm_year && new_tm->tm_mon > last_tm_.tm_mon || new_tm->tm_year == last_tm_.tm_year && new_tm->tm_mon == last_tm_.tm_mon && new_tm->tm_mday > last_tm_.tm_mday ) { out_file_->close(); rename_file_with_retry(date_tmp_file_, date_file_); last_tm_ = *new_tm; recreate_file(); } } }
rolling_file_info (const std::string& name_prefix, rolling_file_settings flags ) // many thanks to Martin Bauer : m_name_prefix(name_prefix), m_flags(flags), m_cur_idx(0) { namespace fs = boost::filesystem; if ( m_flags.initial_erase()) { for ( int idx = 0; idx < m_flags.file_count(); ++idx) if ( fs::exists( file_name(idx) )) fs::remove( file_name(idx) ); } // see what file to start from if ( m_flags.start_where_size_not_exceeded() ) { for ( m_cur_idx = 0; m_cur_idx < m_flags.file_count(); ++m_cur_idx ) if ( fs::exists( file_name(m_cur_idx) )) { if ( fs::file_size( file_name(m_cur_idx)) < m_flags.max_size_bytes() ) // file hasn't reached max size break; } else // file not found, we'll create it now break; } recreate_file(); }
template<class msg_type> void write( const msg_type& msg) { convert_dest::write(msg, (*m_out) ); if ( m_out->tellp() > m_flags.max_size_bytes()) { m_cur_idx = (m_cur_idx + 1) % m_flags.file_count(); recreate_file(); } }
void compress(char * source, char * destination) { int freq_array[128]= {0}; FILE * fp_source; FILE * fp_compressed; fp_source = fopen(source,"r"); fp_compressed = fopen("compressed.txt", "wb"); fp_source = frequency_finder(fp_source, freq_array); // display_frequency(freq_array); list_t * head =make_tree(freq_array); // inorder(head->link_node); make_compressed_file(head, fp_compressed, fp_source); fclose(fp_source); fclose(fp_compressed); FILE * fp_recreate = fopen(destination, "wb"); FILE * fp_compressed_read = fopen("compressed.txt", "r"); recreate_file(head->link_node, fp_compressed_read, fp_recreate); printf("\nA compressed file named \"compressed.txt\" is created.\n"); fclose(fp_compressed_read); fclose(fp_recreate); }
void rolling_file_writer::ensure_out_file() { if (!out_file_) { time_t cur_time = ::time(0); last_tm_ = *localtime( &cur_time ); recreate_file(); } }
void rolling_file_writer::check_renew_file_post_log(const tm* cur_tm) { if ( !settinges_.new_file_by_date ) { if ( out_file_->tellp() > settinges_.max_size_bytes) { out_file_->close(); recreate_file(); } } }
void create_if_needed() { if ( !m_out) recreate_file(); }