diff --git a/source/graphics/MapWriter.cpp b/source/graphics/MapWriter.cpp index 2072cccbe3..f1015c1044 100644 --- a/source/graphics/MapWriter.cpp +++ b/source/graphics/MapWriter.cpp @@ -30,6 +30,7 @@ #include "maths/MathUtil.h" #include "maths/NUSpline.h" +#include "ps/CLogger.h" #include "ps/Loader.h" #include "ps/Filesystem.h" #include "ps/XML/XMLWriter.h" @@ -63,8 +64,16 @@ void CMapWriter::SaveMap(const VfsPath& pathname, CTerrain* pTerrain, // build necessary data PackMap(packer, pTerrain); - // write it out - packer.Write(pathname); + try + { + // write it out + packer.Write(pathname); + } + catch (PSERROR_File_WriteFailed&) + { + LOGERROR(L"Failed to write map '%ls'", pathname.string().c_str()); + return; + } VfsPath pathnameXML = pathname.ChangeExtension(L".xml"); WriteXML(pathnameXML, pWaterMan, pSkyMan, pLightEnv, pCamera, pCinema, pPostproc, pSimulation2); @@ -170,7 +179,7 @@ void CMapWriter::PackTerrain(CFilePacker& packer, CTerrain* pTerrain) packer.PackString(terrainTextures[i]); // pack tile data - packer.PackRaw(&tiles[0],sizeof(STileDesc)*tiles.size()); + packer.PackRaw(&tiles[0],sizeof(STileDesc)*tiles.size()); } void CMapWriter::WriteXML(const VfsPath& filename, @@ -444,8 +453,8 @@ void CMapWriter::WriteXML(const VfsPath& filename, } } } - if (! XML_StoreVFS(g_VFS, filename)) - DEBUG_WARN_ERR(ERR::LOGIC); // failed to write map XML file + if (!XML_StoreVFS(g_VFS, filename)) + LOGERROR(L"Failed to write map '%ls'", filename.string().c_str()); } /* diff --git a/source/lib/file/io/io.h b/source/lib/file/io/io.h index e0f68a9423..1500c37d7f 100644 --- a/source/lib/file/io/io.h +++ b/source/lib/file/io/io.h @@ -301,7 +301,7 @@ static inline Status Store(const OsPath& pathname, const void* data, size_t size int oflag = O_WRONLY; if(p.queueDepth != 1) oflag |= O_DIRECT; - WARN_RETURN_STATUS_IF_ERR(file.Open(pathname, oflag)); + RETURN_STATUS_IF_ERR(file.Open(pathname, oflag)); io::Operation op(file, (void*)data, size); #if OS_WIN diff --git a/source/lib/file/vfs/vfs.cpp b/source/lib/file/vfs/vfs.cpp index b0551c7a3e..1bb145eca0 100644 --- a/source/lib/file/vfs/vfs.cpp +++ b/source/lib/file/vfs/vfs.cpp @@ -132,7 +132,12 @@ public: { ScopedLock s; VfsDirectory* directory; - WARN_RETURN_STATUS_IF_ERR(vfs_Lookup(pathname, &m_rootDirectory, directory, 0, VFS_LOOKUP_ADD|VFS_LOOKUP_CREATE|VFS_LOOKUP_CREATE_ALWAYS)); + Status st; + st = vfs_Lookup(pathname, &m_rootDirectory, directory, 0, VFS_LOOKUP_ADD|VFS_LOOKUP_CREATE|VFS_LOOKUP_CREATE_ALWAYS); + if (st == ERR::FILE_ACCESS) + return ERR::FILE_ACCESS; + + WARN_RETURN_STATUS_IF_ERR(st); const PRealDirectory& realDirectory = directory->AssociatedDirectory(); const OsPath name = pathname.Filename(); @@ -163,8 +168,8 @@ public: s.~ScopedLock(); return CreateFile(pathname, fileContents, size); } - else - WARN_RETURN_STATUS_IF_ERR(st); + + WARN_RETURN_STATUS_IF_ERR(st); RealDirectory realDirectory(file->Loader()->Path(), file->Priority(), directory->AssociatedDirectory()->Flags()); RETURN_STATUS_IF_ERR(realDirectory.Store(pathname.Filename(), fileContents, size)); diff --git a/source/lib/file/vfs/vfs_lookup.cpp b/source/lib/file/vfs/vfs_lookup.cpp index 5c99ea73e6..35e414942f 100644 --- a/source/lib/file/vfs/vfs_lookup.cpp +++ b/source/lib/file/vfs/vfs_lookup.cpp @@ -30,6 +30,7 @@ #include "lib/external_libraries/suppress_boost_warnings.h" #include "lib/sysdep/filesystem.h" +#include "lib/file/file.h" #include "lib/file/vfs/vfs.h" // error codes #include "lib/file/vfs/vfs_tree.h" #include "lib/file/vfs/vfs_populate.h" @@ -61,6 +62,9 @@ static Status CreateDirectory(const OsPath& path) return INFO::OK; } + if (errno == EACCES) + return ERR::FILE_ACCESS; + // unexpected failure debug_printf(L"wmkdir failed with errno=%d\n", errno); DEBUG_WARN_ERR(ERR::LOGIC); diff --git a/source/ps/FileIo.cpp b/source/ps/FileIo.cpp index 8eb8d1dab7..e06d339863 100644 --- a/source/ps/FileIo.cpp +++ b/source/ps/FileIo.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2009 Wildfire Games. +/* Copyright (C) 2013 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -22,6 +22,7 @@ #include "precompiled.h" #include "FileIo.h" +#include "ps/CLogger.h" #include "ps/Filesystem.h" #include "lib/byte_order.h" @@ -65,8 +66,12 @@ void CFilePacker::Write(const VfsPath& filename) m_writeBuffer.Overwrite(&payloadSize_le, sizeof(payloadSize_le), 0+offsetof(FileHeader, payloadSize_le)); // write out all data (including header) - if(g_VFS->CreateFile(filename, m_writeBuffer.Data(), m_writeBuffer.Size()) < 0) + const Status st = g_VFS->CreateFile(filename, m_writeBuffer.Data(), m_writeBuffer.Size()); + if (st < 0) + { + LOGERROR(L"Failed to write file '%ls' with status '%lld'", filename.string().c_str(), (long long)st); throw PSERROR_File_WriteFailed(); + } } diff --git a/source/ps/XML/XMLWriter.cpp b/source/ps/XML/XMLWriter.cpp index 1a8dd80af1..e77ce171ec 100644 --- a/source/ps/XML/XMLWriter.cpp +++ b/source/ps/XML/XMLWriter.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2011 Wildfire Games. +/* Copyright (C) 2013 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -102,7 +102,7 @@ bool XMLWriter_File::StoreVFS(const PIVFS& vfs, const VfsPath& pathname) Status ret = vfs->CreateFile(pathname, data, size); if (ret < 0) { - LOGERROR(L"Error saving XML data through VFS: %lld", (long long)ret); + LOGERROR(L"Error saving XML data through VFS: %lld '%ls'", (long long)ret, pathname.string().c_str()); return false; } return true;