Utils: Make UnixDeviceFileAccess macOS compatible

"stat" on macOS has slightly different formatting options.

Also adds unittests for UnixDeviceFileAccess

Task-number: QTCREATORBUG-28142
Change-Id: Ib42fc1c22ef2771365e915df34f2286e2c705568
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
Marcus Tillmanns
2023-02-23 15:34:05 +01:00
parent a62c5cf89a
commit c41d30711a
10 changed files with 184 additions and 34 deletions

View File

@@ -586,8 +586,7 @@ FilePaths FileUtils::getOpenFilePaths(QWidget *parent,
#endif // QT_WIDGETS_LIB
// Converts a hex string of the st_mode field of a stat structure to FileFlags.
FilePathInfo::FileFlags fileInfoFlagsfromStatRawModeHex(const QString &hexString)
FilePathInfo::FileFlags fileInfoFlagsfromStatMode(const QString &hexString, int modeBase)
{
// Copied from stat.h
enum st_mode {
@@ -617,7 +616,7 @@ FilePathInfo::FileFlags fileInfoFlagsfromStatRawModeHex(const QString &hexString
};
bool ok = false;
uint mode = hexString.toUInt(&ok, 16);
uint mode = hexString.toUInt(&ok, modeBase);
QTC_ASSERT(ok, return {});
@@ -657,13 +656,13 @@ FilePathInfo::FileFlags fileInfoFlagsfromStatRawModeHex(const QString &hexString
return result;
}
FilePathInfo FileUtils::filePathInfoFromTriple(const QString &infos)
FilePathInfo FileUtils::filePathInfoFromTriple(const QString &infos, int modeBase)
{
const QStringList parts = infos.split(' ', Qt::SkipEmptyParts);
if (parts.size() != 3)
return {};
FilePathInfo::FileFlags flags = fileInfoFlagsfromStatRawModeHex(parts[0]);
FilePathInfo::FileFlags flags = fileInfoFlagsfromStatMode(parts[0], modeBase);
const QDateTime dt = QDateTime::fromSecsSinceEpoch(parts[1].toLongLong(), Qt::UTC);
qint64 size = parts[2].toLongLong();