14 #include "../clib/clib_endian.h" 15 #include "../clib/fileutil.h" 16 #include "../clib/iohelp.h" 17 #include "../clib/logfacility.h" 18 #include "../clib/rawtypes.h" 19 #include "../clib/streamsaver.h" 20 #include "../clib/strutil.h" 21 #include "../clib/timer.h" 22 #include "../plib/systemstate.h" 71 for ( StorageArea::Cont::const_iterator item_itr = area->
_items.begin();
72 item_itr != area->
_items.end(); ++item_itr )
103 bool& has_nonsaved_owner )
111 has_nonsaved_owner =
true;
116 if ( has_nonsaved_owner )
119 if ( owner->
dirty() )
139 for ( ; citr != end; ++citr )
145 if ( !
id.save_on_exit )
154 bool has_nonsaved_owner =
false;
156 if ( has_nonsaved_owner )
174 for ( ; deleted_citr != deleted_end; ++deleted_citr )
176 u32 serial = ( *deleted_citr );
189 ofs <<
"}" << pf_endl <<
pf_endl;
191 ofs <<
"Deleted" << pf_endl <<
"{" <<
pf_endl;
196 ofs <<
"}" << pf_endl <<
pf_endl;
209 if ( unlink( datfile.c_str() ) )
212 POLLOG_ERROR.Format(
"Unable to delete {}: {} ({})\n" ) << datfile << strerror( err ) << err;
218 if ( rename( ndtfile.c_str(), datfile.c_str() ) )
221 POLLOG_ERROR.Format(
"Unable to rename {} to {}: {} ({})\n" )
222 << ndtfile << datfile << strerror( err ) << err;
239 throw std::runtime_error(
240 "Incremental saves are disabled until the next full save, due to a previous incremental " 241 "save failure (dirty flags are inconsistent)" );
251 std::ofstream ofs_data;
252 std::ofstream ofs_index;
254 ofs_data.exceptions( std::ios_base::failbit | std::ios_base::badbit );
255 ofs_index.exceptions( std::ios_base::failbit | std::ios_base::badbit );
258 std::string data_basename =
"incr-data-" +
Clib::decint( save_index );
259 std::string index_basename =
"incr-index-" +
Clib::decint( save_index );
293 catch ( std::exception& ex )
295 POLLOG_ERROR.Format(
"Exception during incremental save: {}\n" ) << ex.what();
304 for (
unsigned save_index = 1;; ++save_index )
306 std::string data_basename =
"incr-data-" +
Clib::decint( save_index );
307 std::string index_basename =
"incr-index-" +
Clib::decint( save_index );
309 bool res1 =
commit( data_basename );
310 bool res2 =
commit( index_basename );
void write_dirty_storage(Clib::StreamWriter &sw_data)
std::string world_data_path
void write_system_data(Clib::StreamWriter &sw)
void open_file(std::fstream &ofs, std::string &filename, std::ios::openmode mode)
std::string decint(unsigned short v)
hs::const_iterator begin() const
void write_dirty_data(Clib::StreamWriter &sw_data)
virtual UObject * owner()
unsigned int clean_objects
unsigned int dirty_objects
const ItemDesc & find_itemdesc(unsigned int objtype)
bool incremental_saves_disabled
ds::const_iterator dirty_deleted_end() const
virtual void printSelfOn(Clib::StreamWriter &sw) const
unsigned incremental_save_count
std::vector< u32 > deleted_serials
void commit_incremental_saves()
bool commit_incremental(const std::string &basename)
std::vector< u32 > modified_serials
void write_global_properties(Clib::StreamWriter &sw)
int save_incremental(unsigned int &dirty, unsigned int &clean, long long &elapsed_ms)
ObjectStorageManager objStorageManager
hs::const_iterator end() const
ds::const_iterator dirty_deleted_begin() const
bool FileExists(const char *filename)
void write_index(std::ostream &ofs)
void write_object_dirty_owners(Clib::StreamWriter &sw_data, const UObject *obj, bool &has_nonsaved_owner)
bool commit(const std::string &basename)