2015-12-10 05:06:13 +02:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
|
|
|
** Copyright (C) 2015 The Qt Company Ltd.
|
2019-12-29 23:21:34 +00:00
|
|
|
** Copyright (C) 2016-2020 Ivailo Monev
|
2015-12-10 05:06:13 +02:00
|
|
|
**
|
2019-07-02 18:13:44 +00:00
|
|
|
** This file is part of the QtCore module of the Katie Toolkit.
|
2015-12-10 05:06:13 +02:00
|
|
|
**
|
|
|
|
** $QT_BEGIN_LICENSE:LGPL$
|
2019-12-29 23:21:34 +00:00
|
|
|
**
|
2015-12-10 05:06:13 +02:00
|
|
|
** GNU Lesser General Public License Usage
|
2019-12-29 23:21:34 +00:00
|
|
|
** This file may be used under the terms of the GNU Lesser
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2015-12-10 05:06:13 +02:00
|
|
|
**
|
|
|
|
** As a special exception, The Qt Company gives you certain additional
|
|
|
|
** rights. These rights are described in The Qt Company LGPL Exception
|
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
**
|
|
|
|
** GNU General Public License Usage
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
** General Public License version 3.0 as published by the Free Software
|
|
|
|
** Foundation and appearing in the file LICENSE.GPL included in the
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
** ensure the GNU General Public License version 3.0 requirements will be
|
|
|
|
** met: http://www.gnu.org/copyleft/gpl.html.
|
|
|
|
**
|
|
|
|
** $QT_END_LICENSE$
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "qfilesystemengine_p.h"
|
2019-07-16 11:25:23 +00:00
|
|
|
#include "qdir.h"
|
|
|
|
#include "qset.h"
|
|
|
|
#include "qabstractfileengine_p.h"
|
2019-11-17 00:24:00 +00:00
|
|
|
|
|
|
|
#ifndef QT_BOOTSTRAPPED
|
|
|
|
# include "qresource_p.h"
|
2015-12-10 05:06:13 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
QT_BEGIN_NAMESPACE
|
|
|
|
|
|
|
|
//these unix functions are in this file, because they are shared by symbian port
|
|
|
|
//for open C file handles.
|
|
|
|
#ifdef Q_OS_UNIX
|
|
|
|
//static
|
|
|
|
bool QFileSystemEngine::fillMetaData(int fd, QFileSystemMetaData &data)
|
|
|
|
{
|
|
|
|
data.entryFlags &= ~QFileSystemMetaData::PosixStatFlags;
|
|
|
|
data.knownFlagsMask |= QFileSystemMetaData::PosixStatFlags;
|
|
|
|
|
|
|
|
QT_STATBUF statBuffer;
|
|
|
|
if (QT_FSTAT(fd, &statBuffer) == 0) {
|
|
|
|
data.fillFromStatBuf(statBuffer);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void QFileSystemMetaData::fillFromStatBuf(const QT_STATBUF &statBuffer)
|
|
|
|
{
|
|
|
|
// Permissions
|
|
|
|
if (statBuffer.st_mode & S_IRUSR)
|
|
|
|
entryFlags |= QFileSystemMetaData::OwnerReadPermission;
|
|
|
|
if (statBuffer.st_mode & S_IWUSR)
|
|
|
|
entryFlags |= QFileSystemMetaData::OwnerWritePermission;
|
|
|
|
if (statBuffer.st_mode & S_IXUSR)
|
|
|
|
entryFlags |= QFileSystemMetaData::OwnerExecutePermission;
|
|
|
|
|
|
|
|
if (statBuffer.st_mode & S_IRGRP)
|
|
|
|
entryFlags |= QFileSystemMetaData::GroupReadPermission;
|
|
|
|
if (statBuffer.st_mode & S_IWGRP)
|
|
|
|
entryFlags |= QFileSystemMetaData::GroupWritePermission;
|
|
|
|
if (statBuffer.st_mode & S_IXGRP)
|
|
|
|
entryFlags |= QFileSystemMetaData::GroupExecutePermission;
|
|
|
|
|
|
|
|
if (statBuffer.st_mode & S_IROTH)
|
|
|
|
entryFlags |= QFileSystemMetaData::OtherReadPermission;
|
|
|
|
if (statBuffer.st_mode & S_IWOTH)
|
|
|
|
entryFlags |= QFileSystemMetaData::OtherWritePermission;
|
|
|
|
if (statBuffer.st_mode & S_IXOTH)
|
|
|
|
entryFlags |= QFileSystemMetaData::OtherExecutePermission;
|
|
|
|
|
|
|
|
// Type
|
|
|
|
if ((statBuffer.st_mode & S_IFMT) == S_IFREG)
|
|
|
|
entryFlags |= QFileSystemMetaData::FileType;
|
|
|
|
else if ((statBuffer.st_mode & S_IFMT) == S_IFDIR)
|
|
|
|
entryFlags |= QFileSystemMetaData::DirectoryType;
|
|
|
|
else
|
|
|
|
entryFlags |= QFileSystemMetaData::SequentialType;
|
|
|
|
|
|
|
|
// Attributes
|
|
|
|
entryFlags |= QFileSystemMetaData::ExistsAttribute;
|
|
|
|
size_ = statBuffer.st_size;
|
|
|
|
|
|
|
|
// Times
|
|
|
|
creationTime_ = statBuffer.st_ctime ? statBuffer.st_ctime : statBuffer.st_mtime;
|
|
|
|
modificationTime_ = statBuffer.st_mtime;
|
|
|
|
accessTime_ = statBuffer.st_atime;
|
|
|
|
userId_ = statBuffer.st_uid;
|
|
|
|
groupId_ = statBuffer.st_gid;
|
|
|
|
}
|
|
|
|
|
|
|
|
void QFileSystemMetaData::fillFromDirEnt(const QT_DIRENT &entry)
|
|
|
|
{
|
2016-10-05 23:33:10 +00:00
|
|
|
#if defined(_DIRENT_HAVE_D_TYPE) || defined(Q_OS_BSD4)
|
2015-12-10 05:06:13 +02:00
|
|
|
// BSD4 includes Mac OS X
|
|
|
|
|
|
|
|
// ### This will clear all entry flags and knownFlagsMask
|
|
|
|
switch (entry.d_type)
|
|
|
|
{
|
|
|
|
case DT_DIR:
|
|
|
|
knownFlagsMask = QFileSystemMetaData::LinkType
|
|
|
|
| QFileSystemMetaData::FileType
|
|
|
|
| QFileSystemMetaData::DirectoryType
|
|
|
|
| QFileSystemMetaData::SequentialType
|
|
|
|
| QFileSystemMetaData::ExistsAttribute;
|
|
|
|
|
|
|
|
entryFlags = QFileSystemMetaData::DirectoryType
|
|
|
|
| QFileSystemMetaData::ExistsAttribute;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DT_BLK:
|
|
|
|
case DT_CHR:
|
|
|
|
case DT_FIFO:
|
|
|
|
case DT_SOCK:
|
|
|
|
// ### System attribute
|
|
|
|
knownFlagsMask = QFileSystemMetaData::LinkType
|
|
|
|
| QFileSystemMetaData::FileType
|
|
|
|
| QFileSystemMetaData::DirectoryType
|
|
|
|
| QFileSystemMetaData::SequentialType
|
|
|
|
| QFileSystemMetaData::ExistsAttribute;
|
|
|
|
|
|
|
|
entryFlags = QFileSystemMetaData::SequentialType
|
|
|
|
| QFileSystemMetaData::ExistsAttribute;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DT_LNK:
|
|
|
|
knownFlagsMask = QFileSystemMetaData::LinkType;
|
|
|
|
entryFlags = QFileSystemMetaData::LinkType;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DT_REG:
|
|
|
|
knownFlagsMask = QFileSystemMetaData::LinkType
|
|
|
|
| QFileSystemMetaData::FileType
|
|
|
|
| QFileSystemMetaData::DirectoryType
|
|
|
|
| QFileSystemMetaData::SequentialType
|
|
|
|
| QFileSystemMetaData::ExistsAttribute;
|
|
|
|
|
|
|
|
entryFlags = QFileSystemMetaData::FileType
|
|
|
|
| QFileSystemMetaData::ExistsAttribute;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DT_UNKNOWN:
|
|
|
|
default:
|
|
|
|
clear();
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
Q_UNUSED(entry)
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
//static
|
|
|
|
QString QFileSystemEngine::resolveUserName(const QFileSystemEntry &entry, QFileSystemMetaData &metaData)
|
|
|
|
{
|
|
|
|
if (!metaData.hasFlags(QFileSystemMetaData::UserId))
|
|
|
|
QFileSystemEngine::fillMetaData(entry, metaData, QFileSystemMetaData::UserId);
|
|
|
|
return resolveUserName(metaData.userId());
|
|
|
|
}
|
|
|
|
|
|
|
|
//static
|
|
|
|
QString QFileSystemEngine::resolveGroupName(const QFileSystemEntry &entry, QFileSystemMetaData &metaData)
|
|
|
|
{
|
|
|
|
if (!metaData.hasFlags(QFileSystemMetaData::GroupId))
|
|
|
|
QFileSystemEngine::fillMetaData(entry, metaData, QFileSystemMetaData::GroupId);
|
|
|
|
return resolveGroupName(metaData.groupId());
|
|
|
|
}
|
|
|
|
|
|
|
|
QT_END_NAMESPACE
|