本文整理汇总了C++中QFileInfo::symLinkTarget方法的典型用法代码示例。如果您正苦于以下问题:C++ QFileInfo::symLinkTarget方法的具体用法?C++ QFileInfo::symLinkTarget怎么用?C++ QFileInfo::symLinkTarget使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QFileInfo
的用法示例。
在下文中一共展示了QFileInfo::symLinkTarget方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: runningUnderDebugger
QT_BEGIN_NAMESPACE
// Find out if our parent process is gdb by looking at the 'exe' symlink under /proc,.
// or, for older Linuxes, read out 'cmdline'.
static bool runningUnderDebugger()
{
#if defined(QT_DEBUG) && defined(Q_OS_LINUX)
const QString parentProc = QLatin1String("/proc/") + QString::number(getppid());
const QFileInfo parentProcExe(parentProc + QLatin1String("/exe"));
if (parentProcExe.isSymLink())
return parentProcExe.symLinkTarget().endsWith(QLatin1String("/gdb"));
QFile f(parentProc + QLatin1String("/cmdline"));
if (!f.open(QIODevice::ReadOnly))
return false;
QByteArray s;
char c;
while (f.getChar(&c) && c) {
if (c == '/')
s.clear();
else
s += c;
}
return s == "gdb";
#else
return false;
#endif
}
示例2: listOpenedFd
void listOpenedFd()
{
qDebug() << Q_FUNC_INFO;
pid_t pid = getpid();
qDebug() << Q_FUNC_INFO << pid;
QString path("/proc/");
path.append(QString::number(pid));
path.append("/fd");
QDir pidDir(path);
qDebug() << Q_FUNC_INFO << path;
QStringList list = pidDir.entryList();
QStringList::const_iterator it = list.begin();
QStringList::const_iterator itEnd = list.end();
QFileInfo fi;
for(; it != itEnd; ++it)
{
QString file_path = pidDir.filePath(*it);
fi.setFile(file_path);
qDebug() << Q_FUNC_INFO << fi.isSymLink() << fi.symLinkTarget();
}
}
示例3: getPid
int QBookDevel::getPid(const char *exe) {
static struct dirent *ent;
DIR *dir = opendir("/proc");
if (!dir)
return 0;
while( (ent = readdir(dir)) ) {
if(!ent || !ent->d_name) {
closedir(dir);
return 0;
}
if(*ent->d_name < '0' || *ent->d_name > '9')
continue;
QString *path = new QString();
path->append("/proc/");
path->append(ent->d_name);
path->append("/exe");
qDebug () << *path;
QFileInfo f = QFileInfo(*path);
if (f.isSymLink()) {
QFileInfo l = QFileInfo (f.symLinkTarget());
if (l.completeBaseName() == exe) {
closedir(dir);
return atoi(ent->d_name);
}
}
// We need to check also cmdline as a lot of binaries are links to busybox
path = new QString();
path->append("/proc/");
path->append(ent->d_name);
path->append("/cmdline");
QFile *file = new QFile(*path);
delete path;
if (!file->open(QIODevice::ReadOnly))
continue;
QTextStream stream(file);
QString line = stream.readLine();
file->close();
delete file;
QStringList args = line.split((QChar)0); // cmdline is separated with NULLs!
if (args.size() > 0) {
f = QFileInfo (args.at(0));
if (f.completeBaseName() == exe) {
closedir(dir);
return atoi(ent->d_name);
}
}
}
closedir(dir);
return 0;
}
示例4: canonicalized
/*!
\internal
Returns the canonicalized form of \a path (i.e., with all symlinks
resolved, and all redundant path elements removed.
*/
QString QFSFileEnginePrivate::canonicalized(const QString &path)
{
if (path.isEmpty())
return path;
QFileInfo fi;
const QChar slash(QLatin1Char('/'));
QString tmpPath = path;
int separatorPos = 0;
QSet<QString> nonSymlinks;
QSet<QString> known;
known.insert(path);
do {
#ifdef Q_OS_WIN
// UNC, skip past the first two elements
if (separatorPos == 0 && tmpPath.startsWith(QLatin1String("//")))
separatorPos = tmpPath.indexOf(slash, 2);
if (separatorPos != -1)
#endif
separatorPos = tmpPath.indexOf(slash, separatorPos + 1);
QString prefix = separatorPos == -1 ? tmpPath : tmpPath.left(separatorPos);
if (
#ifdef Q_OS_SYMBIAN
// Symbian doesn't support directory symlinks, so do not check for link unless we
// are handling the last path element. This not only slightly improves performance,
// but also saves us from lot of unnecessary platform security check failures
// when dealing with files under *:/private directories.
separatorPos == -1 &&
#endif
!nonSymlinks.contains(prefix)) {
fi.setFile(prefix);
if (fi.isSymLink()) {
QString target = fi.symLinkTarget();
if (separatorPos != -1) {
if (fi.isDir() && !target.endsWith(slash))
target.append(slash);
target.append(tmpPath.mid(separatorPos));
}
tmpPath = QDir::cleanPath(target);
separatorPos = 0;
if (known.contains(tmpPath))
return QString();
known.insert(tmpPath);
} else {
nonSymlinks.insert(prefix);
}
}
} while (separatorPos != -1);
return QDir::cleanPath(tmpPath);
}
示例5: disablePtrace
static void disablePtrace()
{
#if HAVE_PR_SET_DUMPABLE
// Allow ptrace when running inside gdb
const qint64 pid = QCoreApplication::applicationPid();
const QFileInfo process(QStringLiteral("/proc/%1/exe").arg(pid));
if (process.isSymLink() && process.symLinkTarget().endsWith(QLatin1String("/gdb")))
return;
::prctl(PR_SET_DUMPABLE, 0);
#endif
}
示例6: isValid
/**
* Returns if a file is supported by nomacs or not.
* Note: this function only checks for a valid extension.
* @param fileInfo the file info of the file to be validated.
* @return bool true if the file format is supported.
**/
bool DkUtils::isValid(const QFileInfo& fileInfo) {
printf("accepting file...\n");
QFileInfo fInfo = fileInfo;
if (fInfo.isSymLink())
fInfo = fileInfo.symLinkTarget();
if (!fInfo.exists())
return false;
QString fileName = fInfo.fileName();
return hasValidSuffix(fileName);
}
示例7: canonicalized
/*!
\internal
Returns the canonicalized form of \a path (i.e., with all symlinks
resolved, and all redundant path elements removed.
*/
QString QFSFileEnginePrivate::canonicalized(const QString &path)
{
if (path.isEmpty())
return path;
QFileInfo fi;
const QChar slash(QLatin1Char('/'));
QString tmpPath = path;
int separatorPos = 0;
QSet<QString> nonSymlinks;
QSet<QString> known;
do {
#ifdef Q_OS_WIN
// UNC, skip past the first two elements
if (separatorPos == 0 && tmpPath.startsWith(QLatin1String("//")))
separatorPos = tmpPath.indexOf(slash, 2);
if (separatorPos != -1)
#endif
separatorPos = tmpPath.indexOf(slash, separatorPos + 1);
QString prefix = separatorPos == -1 ? tmpPath : tmpPath.left(separatorPos);
if (!nonSymlinks.contains(prefix)) {
if (known.contains(prefix))
return QString();
known.insert(prefix);
fi.setFile(prefix);
if (fi.isSymLink()) {
QString target = fi.symLinkTarget();
if (separatorPos != -1) {
if (fi.isDir() && !target.endsWith(slash))
target.append(slash);
target.append(tmpPath.mid(separatorPos));
}
tmpPath = target;
separatorPos = 0;
} else {
nonSymlinks.insert(prefix);
}
}
} while (separatorPos != -1);
return QDir::cleanPath(tmpPath);
}
示例8: FormatResponse
bool ServiceHost::FormatResponse( HTTPRequest *pRequest, QFileInfo oInfo )
{
QString sName = oInfo.absoluteFilePath();
if (oInfo.exists())
{
if (oInfo.isSymLink())
pRequest->FormatFileResponse( oInfo.symLinkTarget() );
else
pRequest->FormatFileResponse( oInfo.absoluteFilePath() );
}
else
{
// force return as a 404...
pRequest->FormatFileResponse( "" );
}
return true;
}
示例9: file
QSharedPointer<QByteArray> DkImageContainer::loadFileToBuffer(const QFileInfo fileInfo) {
QFileInfo fInfo = fileInfo.isSymLink() ? fileInfo.symLinkTarget() : fileInfo;
#ifdef WITH_QUAZIP
if (isFromZip())
return zipData->extractImage(zipData->getZipFileInfo(), zipData->getImageFileInfo());
#endif
if (fInfo.suffix().contains("psd")) { // for now just psd's are not cached because their file might be way larger than the part we need to read
return QSharedPointer<QByteArray>(new QByteArray());
}
QFile file(fInfo.absoluteFilePath());
file.open(QIODevice::ReadOnly);
QSharedPointer<QByteArray> ba(new QByteArray(file.readAll()));
file.close();
return ba;
}
示例10: di
FileTreeItem::FileTreeItem(const QFileInfo & fileInfo,const FileTreeItem * parentItem,
bool scan_subdirs,bool encripted) {
m_path = (parentItem->rootItem?"":parentItem->archivePath()) + fileInfo.fileName();
if (fileInfo.isDir()) m_path += "/";
m_perms = permissions(fileInfo);
m_user = fileInfo.owner();
m_group = fileInfo.group();
m_link_to = fileInfo.symLinkTarget();
m_file_size = fileInfo.size();
m_date = fileInfo.lastModified();
m_parentItem = (FileTreeItem *)parentItem;
m_encripted = encripted;
rootItem = false;
if (is_dir()) {
if (scan_subdirs) {
QDirIterator di(fileInfo.filePath(),QDir::AllEntries | QDir::Hidden | QDir::System | QDir::NoDotAndDotDot);
while (di.hasNext()) {
di.next();
appendChild(new FileTreeItem(QFileInfo(di.filePath()),this,true,encripted));
}
}
}
}
示例11: slowCanonicalized
QT_BEGIN_NAMESPACE
/*!
\internal
Returns the canonicalized form of \a path (i.e., with all symlinks
resolved, and all redundant path elements removed.
*/
QString QFileSystemEngine::slowCanonicalized(const QString &path)
{
if (path.isEmpty())
return path;
QFileInfo fi;
const QChar slash(QLatin1Char('/'));
QString tmpPath = path;
int separatorPos = 0;
QSet<QString> nonSymlinks;
QSet<QString> known;
known.insert(path);
do {
#ifdef Q_OS_WIN
if (separatorPos == 0) {
if (tmpPath.size() >= 2 && tmpPath.at(0) == slash && tmpPath.at(1) == slash) {
// UNC, skip past the first two elements
separatorPos = tmpPath.indexOf(slash, 2);
} else if (tmpPath.size() >= 3 && tmpPath.at(1) == QLatin1Char(':') && tmpPath.at(2) == slash) {
// volume root, skip since it can not be a symlink
separatorPos = 2;
}
}
if (separatorPos != -1)
#endif
separatorPos = tmpPath.indexOf(slash, separatorPos + 1);
QString prefix = separatorPos == -1 ? tmpPath : tmpPath.left(separatorPos);
if (!nonSymlinks.contains(prefix)) {
fi.setFile(prefix);
if (fi.isSymLink()) {
QString target = fi.symLinkTarget();
if(QFileInfo(target).isRelative())
target = fi.absolutePath() + slash + target;
if (separatorPos != -1) {
if (fi.isDir() && !target.endsWith(slash))
target.append(slash);
target.append(tmpPath.mid(separatorPos));
}
tmpPath = QDir::cleanPath(target);
separatorPos = 0;
if (known.contains(tmpPath))
return QString();
known.insert(tmpPath);
} else {
nonSymlinks.insert(prefix);
}
}
} while (separatorPos != -1);
return QDir::cleanPath(tmpPath);
}
示例12: slowCanonicalized
QT_BEGIN_NAMESPACE
/*!
\internal
Returns the canonicalized form of \a path (i.e., with all symlinks
resolved, and all redundant path elements removed.
*/
QString QFileSystemEngine::slowCanonicalized(const QString &path)
{
if (path.isEmpty())
return path;
QFileInfo fi;
const QChar slash(QLatin1Char('/'));
QString tmpPath = path;
int separatorPos = 0;
QSet<QString> nonSymlinks;
QSet<QString> known;
known.insert(path);
do {
#ifdef Q_OS_WIN
if (separatorPos == 0) {
if (tmpPath.size() >= 2 && tmpPath.at(0) == slash && tmpPath.at(1) == slash) {
// UNC, skip past the first two elements
separatorPos = tmpPath.indexOf(slash, 2);
} else if (tmpPath.size() >= 3 && tmpPath.at(1) == QLatin1Char(':') && tmpPath.at(2) == slash) {
// volume root, skip since it can not be a symlink
separatorPos = 2;
}
}
if (separatorPos != -1)
#endif
separatorPos = tmpPath.indexOf(slash, separatorPos + 1);
QString prefix = separatorPos == -1 ? tmpPath : tmpPath.left(separatorPos);
if (
#ifdef Q_OS_SYMBIAN
// Symbian doesn't support directory symlinks, so do not check for link unless we
// are handling the last path element. This not only slightly improves performance,
// but also saves us from lot of unnecessary platform security check failures
// when dealing with files under *:/private directories.
separatorPos == -1 &&
#endif
!nonSymlinks.contains(prefix)) {
fi.setFile(prefix);
if (fi.isSymLink()) {
QString target = fi.symLinkTarget();
if(QFileInfo(target).isRelative())
target = fi.absolutePath() + slash + target;
if (separatorPos != -1) {
if (fi.isDir() && !target.endsWith(slash))
target.append(slash);
target.append(tmpPath.mid(separatorPos));
}
tmpPath = QDir::cleanPath(target);
separatorPos = 0;
if (known.contains(tmpPath))
return QString();
known.insert(tmpPath);
} else {
nonSymlinks.insert(prefix);
}
}
} while (separatorPos != -1);
return QDir::cleanPath(tmpPath);
}
示例13: canonicalized
/*!
\internal
Returns the canonicalized form of \a path (i.e., with all symlinks
resolved, and all redundant path elements removed.
*/
QString QFSFileEnginePrivate::canonicalized(const QString &path)
{
if (path.isEmpty())
return path;
// FIXME let's see if this stuff works, then we might be able to remove some of the other code.
#if defined(Q_OS_UNIX) && !defined(Q_OS_SYMBIAN)
if (path.size() == 1 && path.at(0) == QLatin1Char('/'))
return path;
#endif
#if defined(Q_OS_LINUX) || defined(Q_OS_SYMBIAN) || defined(Q_OS_MAC)
// ... but Linux with uClibc does not have it
#if !defined(__UCLIBC__)
char *ret = 0;
#if defined(Q_OS_MAC) && !defined(Q_OS_IPHONE)
// Mac OS X 10.5.x doesn't support the realpath(X,0) extension we use here.
if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_6) {
ret = realpath(path.toLocal8Bit().constData(), (char*)0);
} else {
// on 10.5 we can use FSRef to resolve the file path.
FSRef fsref;
if (FSPathMakeRef((const UInt8 *)QDir::cleanPath(path).toUtf8().data(), &fsref, 0) == noErr) {
CFURLRef urlref = CFURLCreateFromFSRef(NULL, &fsref);
CFStringRef canonicalPath = CFURLCopyFileSystemPath(urlref, kCFURLPOSIXPathStyle);
QString ret = QCFString::toQString(canonicalPath);
CFRelease(canonicalPath);
CFRelease(urlref);
return ret;
}
}
#else
ret = realpath(path.toLocal8Bit().constData(), (char*)0);
#endif
if (ret) {
QString canonicalPath = QDir::cleanPath(QString::fromLocal8Bit(ret));
free(ret);
return canonicalPath;
}
#endif
#endif
QFileInfo fi;
const QChar slash(QLatin1Char('/'));
QString tmpPath = path;
int separatorPos = 0;
QSet<QString> nonSymlinks;
QSet<QString> known;
known.insert(path);
do {
#ifdef Q_OS_WIN
// UNC, skip past the first two elements
if (separatorPos == 0 && tmpPath.startsWith(QLatin1String("//")))
separatorPos = tmpPath.indexOf(slash, 2);
if (separatorPos != -1)
#endif
separatorPos = tmpPath.indexOf(slash, separatorPos + 1);
QString prefix = separatorPos == -1 ? tmpPath : tmpPath.left(separatorPos);
if (
#ifdef Q_OS_SYMBIAN
// Symbian doesn't support directory symlinks, so do not check for link unless we
// are handling the last path element. This not only slightly improves performance,
// but also saves us from lot of unnecessary platform security check failures
// when dealing with files under *:/private directories.
separatorPos == -1 &&
#endif
!nonSymlinks.contains(prefix)) {
fi.setFile(prefix);
if (fi.isSymLink()) {
QString target = fi.symLinkTarget();
if (separatorPos != -1) {
if (fi.isDir() && !target.endsWith(slash))
target.append(slash);
target.append(tmpPath.mid(separatorPos));
}
tmpPath = QDir::cleanPath(target);
separatorPos = 0;
if (known.contains(tmpPath))
return QString();
known.insert(tmpPath);
} else {
nonSymlinks.insert(prefix);
}
}
} while (separatorPos != -1);
return QDir::cleanPath(tmpPath);
}
示例14: addFile
void FileOrganiserWidget::addFile(const QString &pFileName,
QStandardItem *pDropItem,
const QAbstractItemView::DropIndicatorPosition &pDropPosition)
{
if (!pDropItem)
// pDropItem is not valid, so...
return;
// Check that we are indeed dealing with a file
QFileInfo fileInfo = pFileName;
if (!fileInfo.isFile())
// We are not dealing with a file, so...
return;
// Check whether we are dropping a symbolic link
QString fileName = pFileName;
if (fileInfo.isSymLink())
// We are dropping a symbolic link, so retrieve its target
fileName = fileInfo.symLinkTarget();
// Check whether the file exists
if (QFileInfo(fileName).exists()) {
// The target file exists, so add it above/on/below pDropItem, depending
// on the drop position and only if the file isn't already present
// First, determine the item that will own the file
QStandardItem *newParentItem = parentItem(pDropItem, pDropPosition);
// Second, if the file is not already owned, then add it to
// newParentItem and this to the right place, depending on the value of
// pDropPosition
if (!ownedBy(fileName, newParentItem)) {
QStandardItem *newFileItem = new QStandardItem(QIcon(FileIcon),
QFileInfo(fileName).fileName());
newFileItem->setData(fileName, Item::Path);
dropItem(pDropItem, pDropPosition, newParentItem, newFileItem);
// Add the file to our file manager
// Note: it doesn't matter whether or not the file is already being
// monitored, since if that's the case then the current
// instance will be ignored
mFileManager->manage(fileName);
// Resize the widget, just in case the new file takes more space
// than is visible
resizeToContents();
} else {
// The file is already owned by newParentItem, so just repaint the
// widget to make sure that the dragging & dropping overlay
// disappears
repaint();
}
}
}
示例15: performOperation
bool CopyDirectoryOperation::performOperation()
{
const QStringList args = arguments();
if (args.count() != 2) {
setError(InvalidArguments);
setErrorString(tr("Invalid arguments in %0: %1 arguments given, 2 expected.").arg(name())
.arg(args.count()));
return false;
}
const QString sourcePath = args.at(0);
const QString targetPath = args.at(1);
const QFileInfo sourceInfo(sourcePath);
const QFileInfo targetInfo(targetPath);
if (!sourceInfo.exists() || !sourceInfo.isDir() || !targetInfo.exists() || !targetInfo.isDir()) {
setError(InvalidArguments);
setErrorString(tr("Invalid arguments in %0: Directories are invalid: %1 %2").arg(name())
.arg(sourcePath).arg(targetPath));
return false;
}
const QDir sourceDir = sourceInfo.absoluteDir();
const QDir targetDir = targetInfo.absoluteDir();
AutoPush autoPush(this);
QDirIterator it(sourceInfo.absoluteFilePath(), QDir::NoDotAndDotDot | QDir::AllEntries | QDir::Hidden,
QDirIterator::Subdirectories);
while (it.hasNext()) {
const QString itemName = it.next();
const QFileInfo itemInfo(sourceDir.absoluteFilePath(itemName));
const QString relativePath = sourceDir.relativeFilePath(itemName);
if (itemInfo.isSymLink()) {
// Check if symlink target is inside copied directory
const QString linkTarget = itemInfo.symLinkTarget();
if (linkTarget.startsWith(sourceDir.absolutePath())) {
// create symlink to copied location
const QString linkTargetRelative = sourceDir.relativeFilePath(linkTarget);
QFile(targetDir.absoluteFilePath(linkTargetRelative))
.link(targetDir.absoluteFilePath(relativePath));
} else {
// create symlink pointing to original location
QFile(linkTarget).link(targetDir.absoluteFilePath(relativePath));
}
// add file entry
autoPush.m_files.prepend(targetDir.absoluteFilePath(relativePath));
emit outputTextChanged(autoPush.m_files.first());
} else if (itemInfo.isDir()) {
if (!targetDir.mkpath(targetDir.absoluteFilePath(relativePath))) {
setError(InvalidArguments);
setErrorString(tr("Could not create %0").arg(targetDir.absoluteFilePath(relativePath)));
return false;
}
} else {
if (!QFile::copy(sourceDir.absoluteFilePath(itemName), targetDir.absoluteFilePath(relativePath))) {
setError(InvalidArguments);
setErrorString(tr("Could not copy %0 to %1").arg(sourceDir.absoluteFilePath(itemName))
.arg(targetDir.absoluteFilePath(relativePath)));
return false;
}
autoPush.m_files.prepend(targetDir.absoluteFilePath(relativePath));
emit outputTextChanged(autoPush.m_files.first());
}
}
return true;
}