超长路径json文件解析适配

Signed-off-by: fangyunzhong <fangyunzhong2@huawei.com>
This commit is contained in:
fangyunzhong
2023-04-20 09:14:22 +00:00
parent d03e8c4932
commit 035a4bac2f
3 changed files with 5 additions and 5 deletions
+1 -1
View File
@@ -57,12 +57,12 @@ public:
static bool CopyFileInner(const std::string &src, const std::string &dst);
static bool IsDirectory(const std::string &path);
static std::string RealPath(const std::string &path);
static std::string AdapateLongPath(const std::string &path);
private:
bool IsIgnore(const std::string &filename) const;
static bool RemoveAllDirInner(const FileEntry &entry);
static bool CreateDirsInner(const std::string &path, std::string::size_type offset);
static std::string AdapateLongPath(const std::string &path);
FilePath filePath_;
bool isFile_;
static const std::string SEPARATE;
+2 -2
View File
@@ -360,15 +360,15 @@ void FileEntry::FilePath::Init()
}
}
#ifdef _WIN32
string FileEntry::AdapateLongPath(const string &path)
{
#ifdef _WIN32
if (path.size() >= MAX_PATH -12) { //the max file path can not exceed 260 - 12
return LONG_PATH_HEAD + path;
}
#endif
return path;
}
#endif
}
}
}
+2 -2
View File
@@ -72,7 +72,7 @@ bool ResourceUtil::RmoveAllDir(const string &path)
bool ResourceUtil::OpenJsonFile(const string &path, Json::Value &root)
{
ifstream ifs(path, ios::binary);
ifstream ifs(FileEntry::AdapateLongPath(path), ios::binary);
if (!ifs.is_open()) {
cerr << "Error: open json failed '" << path << "', reason: " << strerror(errno) << endl;
return false;
@@ -98,7 +98,7 @@ bool ResourceUtil::SaveToJsonFile(const string &path, const Json::Value &root)
writerBuilder["indentation"] = " ";
writerBuilder["emitUTF8"] = true;
unique_ptr<Json::StreamWriter> writer(writerBuilder.newStreamWriter());
ofstream out(path, ofstream::out | ofstream::binary);
ofstream out(FileEntry::AdapateLongPath(path), ofstream::out | ofstream::binary);
if (!out.is_open()) {
cerr << "Error: open failed '" << path <<"', reason: " << strerror(errno) << endl;
return false;