浏览代码

put: Check if file exists correctly

Jonas Pflanzer 5 年之前
父节点
当前提交
be459b066f
共有 1 个文件被更改,包括 8 次插入6 次删除
  1. 8 6
      daemon/src/FileManager.cpp

+ 8 - 6
daemon/src/FileManager.cpp

@@ -18,15 +18,17 @@ bool FileManager::openPutFile(const std::string &filename) {
   this->putFileName = this->fileDirectory;
   this->putFileName.append(filename);
 
-  // open file and test if it already exists
-  this->putFile.open(this->putFileName, std::ios::app | std::ios::binary);
-  if (this->putFile.tellp() != std::ios::beg) {
-    // file already exists
+  std::ifstream ifile(this->putFileName);
+  if (ifile.is_open()) {
+    // file alread exists
+    ifile.close();
     closePutFile();
     return false;
-  } else {
-    return true;
   }
+
+  // open file and test if it already exists
+  this->putFile.open(this->putFileName, std::ios::app | std::ios::binary);
+  return true;
 }
 
 bool FileManager::openGetFile(const std::string &filename, int &chunks) {