From 570369ad9cceb8cc073dc15c6ad39c544a86d95d Mon Sep 17 00:00:00 2001 From: csoler Date: Mon, 6 Aug 2012 17:04:43 +0000 Subject: [PATCH] fixed re-copy of dht bootstrap file when the file is empty git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@5385 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/rsserver/rsinit.cc | 2 +- libretroshare/src/util/rsdir.cc | 10 +++++++--- libretroshare/src/util/rsdir.h | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/libretroshare/src/rsserver/rsinit.cc b/libretroshare/src/rsserver/rsinit.cc index bc5bded62..6b3227fa4 100644 --- a/libretroshare/src/rsserver/rsinit.cc +++ b/libretroshare/src/rsserver/rsinit.cc @@ -2013,7 +2013,7 @@ int RsServer::StartupRetroShare() * if not... copy from dataDirectory */ - if (!RsDirUtil::checkFile(bootstrapfile)) + if (!RsDirUtil::checkFile(bootstrapfile,true)) { std::cerr << "DHT bootstrap file not in ConfigDir: " << bootstrapfile << std::endl; std::string installfile = RsInit::getRetroshareDataDirectory(); diff --git a/libretroshare/src/util/rsdir.cc b/libretroshare/src/util/rsdir.cc index ef166eab0..47251f704 100644 --- a/libretroshare/src/util/rsdir.cc +++ b/libretroshare/src/util/rsdir.cc @@ -351,7 +351,7 @@ bool RsDirUtil::copyFile(const std::string& source,const std::string& dest) } -bool RsDirUtil::checkFile(const std::string& filename) +bool RsDirUtil::checkFile(const std::string& filename,bool disallow_empty_file) { int val; mode_t st_mode; @@ -362,8 +362,8 @@ bool RsDirUtil::checkFile(const std::string& filename) val = _wstat(wfilename.c_str(), &buf); st_mode = buf.st_mode; #else - struct stat buf; - val = stat(filename.c_str(), &buf); + struct stat64 buf; + val = stat64(filename.c_str(), &buf); st_mode = buf.st_mode; #endif if (val == -1) @@ -383,6 +383,10 @@ bool RsDirUtil::checkFile(const std::string& filename) #endif return false; } + + if(disallow_empty_file && buf.st_size == 0) + return false ; + return true; } diff --git a/libretroshare/src/util/rsdir.h b/libretroshare/src/util/rsdir.h index ffcd9c4ca..543973637 100644 --- a/libretroshare/src/util/rsdir.h +++ b/libretroshare/src/util/rsdir.h @@ -81,7 +81,7 @@ bool crc32File(FILE *f,uint64_t file_size,uint32_t chunk_size,CRC32Map& map) ; int breakupDirList(const std::string& path, std::list &subdirs); bool copyFile(const std::string& source,const std::string& dest); -bool checkFile(const std::string& filename); +bool checkFile(const std::string& filename,bool disallow_empty_file = false); bool checkDirectory(const std::string& dir); bool checkCreateDirectory(const std::string& dir); bool cleanupDirectory(const std::string& dir, const std::list &keepFiles);