MINGW-packages/mingw-w64-highlight/002-fix-data-dir-stat.patch
2023-07-12 09:38:11 +05:30

114 lines
3.3 KiB
Diff
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

diff --git a/src/cli/main.cpp b/src/cli/main.cpp
index 2d9ca92..9779cae 100644
--- a/src/cli/main.cpp
+++ b/src/cli/main.cpp
@@ -343,7 +343,7 @@ int HLCmdLineApp::run ( const int argc, const char*argv[] )
CmdLineOptions options ( argc, argv );
// set data directory path, where /langDefs and /themes reside
- string dataDirPath = ( options.getDataDir().empty() ) ? Platform::getAppPath() :options.getDataDir();
+ string dataDirPath = options.getDataDir();
if ( options.printVersion() ) {
printVersionInfo(options.quietMode());
diff --git a/src/core/datadir.cpp b/src/core/datadir.cpp
index 558b66f..0841557 100644
--- a/src/core/datadir.cpp
+++ b/src/core/datadir.cpp
@@ -67,7 +67,13 @@ void DataDir::initSearchDirectories ( const string &userDefinedDir )
#endif
#else
+#ifndef __MINGW32__
possibleDirs.push_back(Platform::getAppPath()); //not needed because of fallback in searchFile
+#else
+ possibleDirs.emplace_back(getSystemDataPath());
+ const std::string prefix = Platform::getPrefixPath();
+ possibleDirs.push_back(prefix + "etc\\highlight\\");
+#endif
#endif
}
@@ -138,8 +144,10 @@ const string DataDir::getSystemDataPath ( )
#else
return LSB_DATA_DIR;
#endif
-#else
+#elif !defined(__MINGW32__)
return Platform::getAppPath();
+#else
+ return Platform::getPrefixPath() + "share\\highlight\\";
#endif
}
@@ -155,7 +163,11 @@ const string DataDir::getExtDir()
const string DataDir::getDocDir()
{
+#ifndef __MINGW32__
return getSystemDataPath();
+#else
+ return getSystemDataPath() + "share\\doc\\highlight\\";
+#endif
}
const string DataDir::getEncodingHint (const string &syntax) {
diff --git a/src/core/platform_fs.cpp b/src/core/platform_fs.cpp
index f2abf35..d66f800 100644
--- a/src/core/platform_fs.cpp
+++ b/src/core/platform_fs.cpp
@@ -61,6 +61,15 @@ std::string getAppPath()
}
#endif
+std::string getPrefixPath()
+{
+ std::string prefix = getAppPath();
+ prefix.pop_back();
+ while (!prefix.empty() && (prefix.back() != '\\'))
+ prefix.pop_back();
+ return prefix;
+}
+
std::string getHomePath()
{
return "";
@@ -368,7 +377,12 @@ int wildcmp ( const char *wild, const char *data )
bool fileExists(const string &fName)
{
struct stat fileInfo;
- return !stat(fName.c_str(),&fileInfo);
+ // MinGWs stat() doesnt work on paths with
+ // - trailing separator (https://sourceforge.net/p/mingw-w64/bugs/810/)
+ // - mix of forward (/) and back slashes (\\)
+ const string path = (fName.back() != pathSeparator) ?
+ fName : fName.substr(0, fName.size() - 1);
+ return stat(path.c_str(), &fileInfo) == 0;
}
//-D_FILE_OFFSET_BITS=64
@@ -376,7 +390,9 @@ bool fileExists(const string &fName)
off_t fileSize(const string& fName) {
struct stat fileInfo;
- if(stat(fName.c_str(), &fileInfo) != 0) {
+ const string path = (fName.back() != pathSeparator) ?
+ fName : fName.substr(0, fName.size() - 1);
+ if (stat(path.c_str(), &fileInfo) != 0) {
return 0;
}
return fileInfo.st_size;
diff --git a/src/include/platform_fs.h b/src/include/platform_fs.h
index 1ebc010..7120c03 100644
--- a/src/include/platform_fs.h
+++ b/src/include/platform_fs.h
@@ -29,6 +29,8 @@ extern const char pathSeparator;
std::string getAppPath();
+std::string getPrefixPath();
+
std::string getHomePath();
std::string getTempFilePath();