solve a bug when the tmpcfg directory already exists under windows

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@2255 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
joss17 2010-02-09 14:11:03 +00:00
parent 3269dcce0e
commit 5a7fb9a57c

View File

@ -34,6 +34,8 @@
#include <iostream> #include <iostream>
#include <algorithm> #include <algorithm>
#include <stdio.h> #include <stdio.h>
#include <dirent.h>
#if defined(WIN32) || defined(__CYGWIN__) #if defined(WIN32) || defined(__CYGWIN__)
#include "wtypes.h" #include "wtypes.h"
@ -232,9 +234,11 @@ bool RsDirUtil::checkDirectory(std::string dir)
bool RsDirUtil::checkCreateDirectory(std::string dir) bool RsDirUtil::checkCreateDirectory(std::string dir)
{ {
struct stat buf; #ifdef RSDIR_DEBUG
int val = stat(dir.c_str(), &buf); std::cerr << "RsDirUtil::checkCreateDirectory() dir: " << dir << std::endl;
if (val == -1) #endif
DIR *direc = opendir(dir.c_str());
if (!direc)
{ {
// directory don't exist. create. // directory don't exist. create.
/******************************** WINDOWS/UNIX SPECIFIC PART ******************/ /******************************** WINDOWS/UNIX SPECIFIC PART ******************/
@ -247,7 +251,7 @@ bool RsDirUtil::checkCreateDirectory(std::string dir)
{ {
#ifdef RSDIR_DEBUG #ifdef RSDIR_DEBUG
std::cerr << "check_create_directory() Fatal Error --"; std::cerr << "check_create_directory() Fatal Error et oui--";
std::cerr <<std::endl<< "\tcannot create:" <<dir<<std::endl; std::cerr <<std::endl<< "\tcannot create:" <<dir<<std::endl;
#endif #endif
return 0; return 0;
@ -258,15 +262,7 @@ bool RsDirUtil::checkCreateDirectory(std::string dir)
std::cerr <<std::endl<< "\tcreated:" <<dir<<std::endl; std::cerr <<std::endl<< "\tcreated:" <<dir<<std::endl;
#endif #endif
} }
else if (!S_ISDIR(buf.st_mode))
{
// Some other type - error.
#ifdef RSDIR_DEBUG
std::cerr<<"check_create_directory() Fatal Error --";
std::cerr<<std::endl<<"\t"<<dir<<" is nor Directory"<<std::endl;
#endif
return 0;
}
#ifdef RSDIR_DEBUG #ifdef RSDIR_DEBUG
std::cerr << "check_create_directory()"; std::cerr << "check_create_directory()";
std::cerr <<std::endl<< "\tDir Exists:" <<dir<<std::endl; std::cerr <<std::endl<< "\tDir Exists:" <<dir<<std::endl;
@ -274,9 +270,6 @@ bool RsDirUtil::checkCreateDirectory(std::string dir)
return 1; return 1;
} }
#include <dirent.h>
//#include <sys/types.h> //#include <sys/types.h>
//#include <sys/stat.h> //#include <sys/stat.h>
//#include <fcntl.h> //#include <fcntl.h>