提交 1c83ea8c 编写于 作者: C chengtbf 提交者: Will Zhang

fix Windows for DeleteFile macro and Socket lib (#359)



Former-commit-id: a07174d7
上级 fbcd7d5a
...@@ -40,6 +40,7 @@ set(oneflow_third_party_libs ...@@ -40,6 +40,7 @@ set(oneflow_third_party_libs
if(WIN32) if(WIN32)
# static gflags lib requires "PathMatchSpecA" defined in "ShLwApi.Lib" # static gflags lib requires "PathMatchSpecA" defined in "ShLwApi.Lib"
list(APPEND oneflow_third_party_libs "ShLwApi.Lib") list(APPEND oneflow_third_party_libs "ShLwApi.Lib")
list(APPEND oneflow_third_party_libs "Ws2_32.lib")
endif() endif()
set(oneflow_third_party_dependencies set(oneflow_third_party_dependencies
......
...@@ -45,7 +45,7 @@ void FileSystem::RecursivelyDeleteDir(const std::string& dirname) { ...@@ -45,7 +45,7 @@ void FileSystem::RecursivelyDeleteDir(const std::string& dirname) {
} else { } else {
// Delete file might fail because of permissions issues or might be // Delete file might fail because of permissions issues or might be
// unimplemented. // unimplemented.
DeleteFile(child_path); DelFile(child_path);
} }
} }
} }
......
...@@ -4,10 +4,6 @@ ...@@ -4,10 +4,6 @@
#include "oneflow/core/common/util.h" #include "oneflow/core/common/util.h"
#include "oneflow/core/persistence/platform.h" #include "oneflow/core/persistence/platform.h"
#if defined(_WIN32)
#undef DeleteFile
#endif
namespace oneflow { namespace oneflow {
namespace fs { namespace fs {
...@@ -114,7 +110,8 @@ class FileSystem { ...@@ -114,7 +110,8 @@ class FileSystem {
virtual std::vector<std::string> ListDir(const std::string& dir) = 0; virtual std::vector<std::string> ListDir(const std::string& dir) = 0;
// Deletes the named file. // Deletes the named file.
virtual void DeleteFile(const std::string& fname) = 0; // Using DelFile to avoid Windows macro
virtual void DelFile(const std::string& fname) = 0;
// Creates the specified directory. // Creates the specified directory.
virtual void CreateDir(const std::string& dirname) = 0; virtual void CreateDir(const std::string& dirname) = 0;
......
...@@ -330,7 +330,7 @@ std::vector<std::string> HadoopFileSystem::ListDir(const std::string& dir) { ...@@ -330,7 +330,7 @@ std::vector<std::string> HadoopFileSystem::ListDir(const std::string& dir) {
return result; return result;
} }
void HadoopFileSystem::DeleteFile(const std::string& fname) { void HadoopFileSystem::DelFile(const std::string& fname) {
hdfsFS fs = nullptr; hdfsFS fs = nullptr;
CHECK(Connect(&fs)); CHECK(Connect(&fs));
PCHECK(hdfs_->hdfsDelete(fs, TranslateName(fname).c_str(), /*recursive=*/0) PCHECK(hdfs_->hdfsDelete(fs, TranslateName(fname).c_str(), /*recursive=*/0)
......
...@@ -78,7 +78,7 @@ class HadoopFileSystem final : public FileSystem { ...@@ -78,7 +78,7 @@ class HadoopFileSystem final : public FileSystem {
std::vector<std::string> ListDir(const std::string& dir) override; std::vector<std::string> ListDir(const std::string& dir) override;
void DeleteFile(const std::string& fname) override; void DelFile(const std::string& fname) override;
void CreateDir(const std::string& dirname) override; void CreateDir(const std::string& dirname) override;
......
...@@ -125,7 +125,7 @@ std::vector<std::string> PosixFileSystem::ListDir(const std::string& dir) { ...@@ -125,7 +125,7 @@ std::vector<std::string> PosixFileSystem::ListDir(const std::string& dir) {
return result; return result;
} }
void PosixFileSystem::DeleteFile(const std::string& fname) { void PosixFileSystem::DelFile(const std::string& fname) {
PCHECK(unlink(TranslateName(fname).c_str()) == 0) PCHECK(unlink(TranslateName(fname).c_str()) == 0)
<< "Fail to delete file " << fname; << "Fail to delete file " << fname;
} }
......
...@@ -28,7 +28,7 @@ class PosixFileSystem final : public FileSystem { ...@@ -28,7 +28,7 @@ class PosixFileSystem final : public FileSystem {
std::vector<std::string> ListDir(const std::string& dir) override; std::vector<std::string> ListDir(const std::string& dir) override;
void DeleteFile(const std::string& fname) override; void DelFile(const std::string& fname) override;
void CreateDir(const std::string& dirname) override; void CreateDir(const std::string& dirname) override;
......
...@@ -70,7 +70,7 @@ void Snapshot::ConcatLbnFile(const std::string& lbn, int32_t part_num, ...@@ -70,7 +70,7 @@ void Snapshot::ConcatLbnFile(const std::string& lbn, int32_t part_num,
out_stream.Write(buffer, n); out_stream.Write(buffer, n);
offset += n; offset += n;
} }
GlobalFS()->DeleteFile(part_file_path); GlobalFS()->DelFile(part_file_path);
} }
} }
GlobalFS()->DeleteDir(part_dir); GlobalFS()->DeleteDir(part_dir);
......
...@@ -222,7 +222,7 @@ std::vector<std::string> WindowsFileSystem::ListDir(const std::string& dir) { ...@@ -222,7 +222,7 @@ std::vector<std::string> WindowsFileSystem::ListDir(const std::string& dir) {
return result; return result;
} }
void WindowsFileSystem::DeleteFile(const std::string& fname) { void WindowsFileSystem::DelFile(const std::string& fname) {
std::wstring file_name = Utf8ToWideChar(fname); std::wstring file_name = Utf8ToWideChar(fname);
PCHECK(_wunlink(file_name.c_str()) == 0) PCHECK(_wunlink(file_name.c_str()) == 0)
<< "Failed to delete a file: " + fname; << "Failed to delete a file: " + fname;
......
...@@ -7,8 +7,6 @@ ...@@ -7,8 +7,6 @@
#include <Windows.h> #include <Windows.h>
#undef DeleteFile
namespace oneflow { namespace oneflow {
namespace fs { namespace fs {
...@@ -32,7 +30,7 @@ class WindowsFileSystem final : public FileSystem { ...@@ -32,7 +30,7 @@ class WindowsFileSystem final : public FileSystem {
std::vector<std::string> ListDir(const std::string& dir) override; std::vector<std::string> ListDir(const std::string& dir) override;
void DeleteFile(const std::string& fname) override; void DelFile(const std::string& fname) override;
void CreateDir(const std::string& dirname) override; void CreateDir(const std::string& dirname) override;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册