projects
/
oweals
/
minetest.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Node highlighting.
[oweals/minetest.git]
/
src
/
filesys.cpp
diff --git
a/src/filesys.cpp
b/src/filesys.cpp
index eda36c83307a39e93392e52048933b5185091f13..b95986a92bcc9f880a412d1703441ea8549d85b8 100644
(file)
--- a/
src/filesys.cpp
+++ b/
src/filesys.cpp
@@
-25,6
+25,7
@@
with this program; if not, write to the Free Software Foundation, Inc.,
#include <errno.h>
#include <fstream>
#include "log.h"
#include <errno.h>
#include <fstream>
#include "log.h"
+#include "config.h"
namespace fs
{
namespace fs
{
@@
-34,8
+35,8
@@
namespace fs
#define _WIN32_WINNT 0x0501
#include <windows.h>
#include <malloc.h>
#define _WIN32_WINNT 0x0501
#include <windows.h>
#include <malloc.h>
-#include <tchar.h>
-#include <wchar.h>
+#include <tchar.h>
+#include <wchar.h>
#define BUFSIZE MAX_PATH
#define BUFSIZE MAX_PATH
@@
-73,12
+74,12
@@
std::vector<DirListNode> GetDirListing(std::string pathstring)
// Find the first file in the directory.
hFind = FindFirstFile(DirSpec, &FindFileData);
// Find the first file in the directory.
hFind = FindFirstFile(DirSpec, &FindFileData);
- if (hFind == INVALID_HANDLE_VALUE)
+ if (hFind == INVALID_HANDLE_VALUE)
{
retval = (-1);
goto Cleanup;
{
retval = (-1);
goto Cleanup;
- }
- else
+ }
+ else
{
// NOTE:
// Be very sure to not include '..' in the results, it will
{
// NOTE:
// Be very sure to not include '..' in the results, it will
@@
-91,7
+92,7
@@
std::vector<DirListNode> GetDirListing(std::string pathstring)
listing.push_back(node);
// List all the other files in the directory.
listing.push_back(node);
// List all the other files in the directory.
- while (FindNextFile(hFind, &FindFileData) != 0)
+ while (FindNextFile(hFind, &FindFileData) != 0)
{
DirListNode node;
node.name = FindFileData.cFileName;
{
DirListNode node;
node.name = FindFileData.cFileName;
@@
-102,7
+103,7
@@
std::vector<DirListNode> GetDirListing(std::string pathstring)
dwError = GetLastError();
FindClose(hFind);
dwError = GetLastError();
FindClose(hFind);
- if (dwError != ERROR_NO_MORE_FILES)
+ if (dwError != ERROR_NO_MORE_FILES)
{
errorstream<<"GetDirListing: FindNextFile error. Error is "
<<dwError<<std::endl;
{
errorstream<<"GetDirListing: FindNextFile error. Error is "
<<dwError<<std::endl;
@@
-401,7
+402,11
@@
std::string TempPath()
compatible with lua's os.tmpname which under the default
configuration hardcodes mkstemp("/tmp/lua_XXXXXX").
*/
compatible with lua's os.tmpname which under the default
configuration hardcodes mkstemp("/tmp/lua_XXXXXX").
*/
- return std::string(DIR_DELIM) + "tmp";
+#ifdef __ANDROID__
+ return DIR_DELIM "sdcard" DIR_DELIM PROJECT_NAME DIR_DELIM "tmp";
+#else
+ return DIR_DELIM "tmp";
+#endif
}
#endif
}
#endif
@@
-696,16
+701,19
@@
bool safeWriteToFile(const std::string &path, const std::string &content)
os << content;
os.flush();
os.close();
os << content;
os.flush();
os.close();
- if (os.fail())
+ if (os.fail()) {
+ remove(tmp_file.c_str());
return false;
return false;
+ }
// Copy file
// Copy file
-#ifdef _WIN32
remove(path.c_str());
remove(path.c_str());
- return (rename(tmp_file.c_str(), path.c_str()) == 0);
-#else
- return (rename(tmp_file.c_str(), path.c_str()) == 0);
-#endif
+ if(rename(tmp_file.c_str(), path.c_str())) {
+ remove(tmp_file.c_str());
+ return false;
+ } else {
+ return true;
+ }
}
} // namespace fs
}
} // namespace fs