Fix missing map_meta.txt error when creating new worlds
authorkwolekr <kwolekr@minetest.net>
Tue, 27 Jan 2015 07:07:41 +0000 (02:07 -0500)
committerkwolekr <kwolekr@minetest.net>
Tue, 27 Jan 2015 07:10:04 +0000 (02:10 -0500)
A missing map_meta.txt should be treated simply as if there were a blank file.

src/map.cpp

index bd3636c7b9e4b0121d4a2ca42eb6176d07c25719..d8f018742c506b670e1fd7c8ad50097d826fbc70 100644 (file)
@@ -3109,7 +3109,7 @@ void ServerMap::saveMapMeta()
 
        createDirs(m_savedir);
 
-       std::string fullpath = m_savedir + DIR_DELIM "map_meta.txt";
+       std::string fullpath = m_savedir + DIR_DELIM "map_meta.txt";
        std::ostringstream ss(std::ios_base::binary);
 
        Settings params;
@@ -3133,19 +3133,21 @@ void ServerMap::loadMapMeta()
 {
        DSTACK(__FUNCTION_NAME);
 
+       Settings params;
        std::string fullpath = m_savedir + DIR_DELIM "map_meta.txt";
-       std::ifstream is(fullpath.c_str(), std::ios_base::binary);
-       if (!is.good()) {
-               errorstream << "ServerMap::loadMapMeta(): "
-                               << "could not open" << fullpath << std::endl;
-               throw FileNotGoodException("Cannot open map metadata");
-       }
 
-       Settings params;
+       if (fs::PathExists(fullpath)) {
+               std::ifstream is(fullpath.c_str(), std::ios_base::binary);
+               if (!is.good()) {
+                       errorstream << "ServerMap::loadMapMeta(): "
+                               "could not open " << fullpath << std::endl;
+                       throw FileNotGoodException("Cannot open map metadata");
+               }
 
-       if (!params.parseConfigLines(is, "[end_of_params]")) {
-               throw SerializationError("ServerMap::loadMapMeta(): "
+               if (!params.parseConfigLines(is, "[end_of_params]")) {
+                       throw SerializationError("ServerMap::loadMapMeta(): "
                                "[end_of_params] not found!");
+               }
        }
 
        m_emerge->loadParamsFromSettings(&params);