FileInfo toFileInfo(const QFileInfo &info) { FileInfo fi; fi.m_valid = true; fi.m_exists = info.exists(); fi.m_permissions = info.permissions(); fi.m_isSymlink = info.isSymLink(); fi.m_type = FileInfo::System; fi.m_hidden = info.isHidden(); fi.m_size = -1; fi.m_lastModified = info.lastModified(); if (info.isDir()) fi.m_type = FileInfo::Dir; else if (info.isFile()) fi.m_type = FileInfo::File; else if (!info.exists() && info.isSymLink()) fi.m_type = FileInfo::System; if (fi.type() == FileInfo::Dir) fi.m_size = 0; else if (fi.type() == FileInfo::File) fi.m_size = info.size(); if (!info.exists() && !info.isSymLink()) fi.m_size = -1; return fi; }
/*! \internal */ void QDirIteratorPrivate::advance() { // Store the current entry if (!fileEngineIterators.isEmpty()) currentFilePath = fileEngineIterators.top()->currentFilePath(); // Advance to the next entry if (followNextDir) { // Start by navigating into the current directory. followNextDir = false; QAbstractFileEngineIterator *it = fileEngineIterators.top(); QString subDir = it->currentFilePath(); #ifdef Q_OS_WIN if (currentFileInfo.isSymLink()) subDir = currentFileInfo.canonicalFilePath(); #endif pushSubDirectory(subDir, it->nameFilters(), it->filters()); } while (!fileEngineIterators.isEmpty()) { QAbstractFileEngineIterator *it = fileEngineIterators.top(); // Find the next valid iterator that matches the filters. bool foundDirectory = false; while (it->hasNext()) { it->next(); if (matchesFilters(it)) { currentFileInfo = nextFileInfo; nextFileInfo = it->currentFileInfo(); // Signal that we want to follow this entry. followNextDir = shouldFollowDirectory(nextFileInfo); //We found a matching entry. return; } else if (iteratorFlags & QDirIterator::Subdirectories) { QFileInfo fileInfo = it->currentFileInfo(); if (!shouldFollowDirectory(fileInfo)) continue; QString subDir = it->currentFilePath(); #ifdef Q_OS_WIN if (fileInfo.isSymLink()) subDir = fileInfo.canonicalFilePath(); #endif pushSubDirectory(subDir, it->nameFilters(), it->filters()); foundDirectory = true; break; } } if (!foundDirectory) delete fileEngineIterators.pop(); } currentFileInfo = nextFileInfo; done = true; }
QString KStandardDirs::findExe( const QString& appname, const QString& pstr, bool ignore) { #ifdef Q_WS_WIN QString real_appname = appname + ".exe"; #else QString real_appname = appname; #endif QFileInfo info; // absolute or relative path given if (real_appname.find(QDir::separator()) >= 0) { info.setFile( real_appname ); if( info.exists() && ( ignore || info.isExecutable() ) && info.isFile() ) { return info.absFilePath(); } return QString::null; } QString p = QString("%1/%2").arg(kfsstnd_defaultbindir()).arg(real_appname); info.setFile( p ); if( info.exists() && ( ignore || info.isExecutable() ) && ( info.isFile() || info.isSymLink() ) ) { return p; } QStringList exePaths = systemPaths( pstr ); for (QStringList::ConstIterator it = exePaths.begin(); it != exePaths.end(); ++it) { p = (*it) + "/"; p += real_appname; // Check for executable in this tokenized path info.setFile( p ); if( info.exists() && ( ignore || info.isExecutable() ) && ( info.isFile() || info.isSymLink() ) ) { return p; } } // If we reach here, the executable wasn't found. // So return empty string. return QString::null; }
QString QFileIconProvider::type(const QFileInfo &info) const { if (info.isRoot()) return QApplication::translate("QFileDialog", "Drive"); if (info.isFile()) { if (!info.suffix().isEmpty()) return info.suffix() + QLatin1Char(' ') + QApplication::translate("QFileDialog", "File"); return QApplication::translate("QFileDialog", "File"); } if (info.isDir()) #ifdef Q_WS_WIN return QApplication::translate("QFileDialog", "File Folder", "Match Windows Explorer"); #else return QApplication::translate("QFileDialog", "Folder", "All other platforms"); #endif // Windows - "File Folder" // OS X - "Folder" // Konqueror - "Folder" // Nautilus - "folder" if (info.isSymLink()) #ifdef Q_OS_MAC return QApplication::translate("QFileDialog", "Alias", "Mac OS X Finder"); #else return QApplication::translate("QFileDialog", "Shortcut", "All other platforms"); #endif // OS X - "Alias" // Windows - "Shortcut" // Konqueror - "Folder" or "TXT File" i.e. what it is pointing to // Nautilus - "link to folder" or "link to object file", same as Konqueror return QApplication::translate("QFileDialog", "Unknown"); }
QIcon TIconProvider::icon(const QFileInfo& fi) const { if (fi.isSymLink()) { if (fi.isDir() || extensions.isPlaylist(fi)) { return folderLinkIcon; } return fileLinkIcon; } if (fi.isDir() || extensions.isPlaylist(fi)) { return folderIcon; } if (fi.filePath().startsWith("dvd://") || fi.filePath().startsWith("dvdnav://") || fi.filePath().startsWith("br://")) { return driveDVDIcon; } if (fi.filePath().startsWith("vcd://") || fi.filePath().startsWith("cdda://")) { return driveCDIcon; } QIcon i = QFileIconProvider::icon(fi); if (i.isNull()) { return fileIcon; } return i; }
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(); } }
/*! \internal */ bool QDirIteratorPrivate::shouldFollowDirectory(const QFileInfo &fileInfo) { // If we're doing flat iteration, we're done. if (!(iteratorFlags & QDirIterator::Subdirectories)) return false; // Never follow non-directory entries if (!fileInfo.isDir()) return false; // Never follow . and .. if (fileInfo.fileName() == QLatin1String(".") || fileInfo.fileName() == QLatin1String("..")) return false; // Check symlinks if (fileInfo.isSymLink() && !(iteratorFlags & QDirIterator::FollowSymlinks)) { // Follow symlinks only if FollowSymlinks was passed return false; } // Stop link loops if (visitedLinks.contains(fileInfo.canonicalFilePath())) return false; return true; }
/*! \internal */ void QDirIteratorPrivate::checkAndPushDirectory(const QFileInfo &fileInfo) { // If we're doing flat iteration, we're done. if (!(iteratorFlags & QDirIterator::Subdirectories)) return; // Never follow non-directory entries if (!fileInfo.isDir()) return; // Follow symlinks only when asked if (!(iteratorFlags & QDirIterator::FollowSymlinks) && fileInfo.isSymLink()) return; // Never follow . and .. QString fileName = fileInfo.fileName(); if (QLatin1String(".") == fileName || QLatin1String("..") == fileName) return; // No hidden directories unless requested if (!(filters & QDir::AllDirs) && !(filters & QDir::Hidden) && fileInfo.isHidden()) return; // Stop link loops if (!visitedLinks.isEmpty() && visitedLinks.contains(fileInfo.canonicalFilePath())) return; pushDirectory(fileInfo); }
QSet<MacBinaryInfo> MacReplaceInstallNamesOperation::collectPatchableBinaries(const QString &searchDir) { QSet<MacBinaryInfo> patchableBinaries; QDirIterator dirIterator(searchDir, QDirIterator::Subdirectories); while (dirIterator.hasNext()) { const QString fileName = dirIterator.next(); const QFileInfo fileInfo = dirIterator.fileInfo(); if (fileInfo.isDir() || fileInfo.isSymLink()) continue; MacBinaryInfo binaryInfo; binaryInfo.fileName = fileName; // try to find libraries in frameworks if (fileName.contains(QLatin1String(".framework/")) && !fileName.contains(QLatin1String("/Headers/")) && updateExecutableInfo(&binaryInfo) == 0) { patchableBinaries.insert(binaryInfo); } else if (fileName.endsWith(QLatin1String(".dylib")) && updateExecutableInfo(&binaryInfo) == 0) { patchableBinaries.insert(binaryInfo); } // the endsWith checks are here because there might be wrongly committed files in the repositories else if (dirIterator.fileInfo().isExecutable() && !fileName.endsWith(QLatin1String(".h")) && !fileName.endsWith(QLatin1String(".cpp")) && !fileName.endsWith(QLatin1String(".pro")) && !fileName.endsWith(QLatin1String(".pri")) && updateExecutableInfo(&binaryInfo) == 0) { patchableBinaries.insert(binaryInfo); } } return patchableBinaries; }
QString forPermissions(const QFileInfo &info) { mode_t p = 0; if (info.isDir()) p |= S_IFDIR; if (info.isSymLink()) p |= S_IFLNK; if (info.permission(QFile::ReadUser)) p |= S_IRWXU & S_IRUSR; if (info.permission(QFile::WriteUser)) p |= S_IRWXU & S_IWUSR; if (info.permission(QFile::ExeUser)) p |= S_IRWXU & S_IXUSR; if (info.permission(QFile::ReadGroup)) p |= S_IRWXG & S_IRGRP; if (info.permission(QFile::WriteGroup)) p |= S_IRWXG & S_IWGRP; if (info.permission(QFile::ExeGroup)) p |= S_IRWXG & S_IXGRP; if (info.permission(QFile::ReadOther)) p |= S_IRWXO & S_IROTH; if (info.permission(QFile::WriteOther)) p |= S_IRWXO & S_IWOTH; if (info.permission(QFile::ExeOther)) p |= S_IRWXO & S_IXOTH; return forPermissions(p); }
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 }
void QucsSettingsDialog::slotAddPathWithSubFolders() { // open a file dialog to select the top level directory QFileDialog fileDialog( this, tr("Select a directory"), QucsSettings.QucsWorkDir.canonicalPath()); fileDialog.setAcceptMode(QFileDialog::AcceptOpen); fileDialog.setFileMode(QFileDialog::DirectoryOnly); QString path; QFileInfo pathfinfo; if (fileDialog.exec()) { // Iterate through the directories QDirIterator pathIter(fileDialog.selectedFile(), QDirIterator::Subdirectories); while (pathIter.hasNext()) { path = pathIter.next(); pathfinfo = pathIter.fileInfo(); if (pathfinfo.isDir() && !pathfinfo.isSymLink() && !path.endsWith(".")) { QDir thispath(path); currentPaths.append(thispath.canonicalPath()); } } makePathTable(); } else { // user cancelled } }
/* private slots */ qint64 ShredThread::getDirSize(QString &dir) { uint _size = 0; QDir::Filters flags = QDir::AllEntries | QDir::NoDotAndDotDot | QDir::Hidden | QDir::System | QDir::AllDirs; QDir d; d.setPath(dir); QList<QFileInfo> entry = d.entryInfoList(flags); if ( !entry.isEmpty() ) { QList<QFileInfo>::const_iterator i; for ( i=entry.constBegin(); i<entry.constEnd(); i++ ) { QFileInfo item = *i; if ( !item.exists() ) continue; QString path = item.canonicalFilePath(); if ( path==d.absoluteFilePath(dir) || item.isSymLink() ) continue; if ( item.isDir() ) { _size += getDirSize(path); } else { _size += item.size(); }; }; }; return _size; }
bool SyncAction::deleteFileOrFolder(SyncFile * sf, FolderActionGroup * f*g) { QFileInfo fi; for (int i = 0; i < f*g->count(); ++i) { MTFile file(QDir(f*g->at(i)).absoluteFilePath(sf->getName())); fi.setFile(file); if (fi.isDir() && !fi.isSymLink()) { if (removeFolder(fi)) { sf->setFileStatusInFolder(f*g->idAt(i), SyncFile::Deleted); emit this->syncOutMessage(new SyncOutMessage(SyncOutMessage::FolderDeleted, new FolderActionGroup(f*g->idAt(i), fi.absoluteFilePath()))); } else emit this->syncOutMessage(new SyncOutMessage(SyncOutMessage::FolderDeleted, new FolderActionGroup(f*g->idAt(i), fi.absoluteFilePath()), true)); } else { if (!backup_action->backupFile(&file)) { continue; } if (file.remove()) { sf->setFileStatusInFolder(f*g->idAt(i), SyncFile::Deleted); emit this->syncOutMessage(new SyncOutMessage(SyncOutMessage::FileDeleted, new FolderActionGroup(f*g->idAt(i), fi.absoluteFilePath()))); } else emit this->syncOutMessage(new SyncOutMessage(SyncOutMessage::FileDeleted, new FolderActionGroup(f*g->idAt(i), fi.absoluteFilePath()), true, file.errorString())); } } sf->setModified(true); return true; }
void FileBrowserWindow::itemDoubleClicked(const QModelIndex &) { // Check what kind of item has been double clicked and if it is a file, then // let people know about it being double clicked QString fileName = mFileBrowserWidget->currentPath(); QFileInfo fileInfo = fileName; if (fileInfo.isFile()) { // We are dealing with a file (as opposed to a folder), so let's see // whether we can let people know about it having been double clicked if (fileInfo.isSymLink()) { // The file is actually a symbolic link, so retrieve its target and // check that it exists, and if it does then let people know about // it having been double clicked fileName = fileInfo.symLinkTarget(); if (QFileInfo(fileName).exists()) emit filesOpened(QStringList() << fileName); } else { // This is a 'normal' file, so just go ahead and let people know // about it having been double clicked emit filesOpened(QStringList() << fileName); } } }
/*! \internal */ void QDirIteratorPrivate::pushDirectory(const QFileInfo &fileInfo) { QString path = fileInfo.filePath(); #ifdef Q_OS_WIN if (fileInfo.isSymLink()) path = fileInfo.canonicalFilePath(); #endif if (iteratorFlags & QDirIterator::FollowSymlinks) visitedLinks << fileInfo.canonicalFilePath(); if (engine) { engine->setFileName(path); QAbstractFileEngineIterator *it = engine->beginEntryList(filters, nameFilters); if (it) { it->setPath(path); fileEngineIterators << it; } else { // No iterator; no entry list. } } else { #ifndef QT_NO_FILESYSTEMITERATOR QFileSystemIterator *it = new QFileSystemIterator(fileInfo.d_ptr->fileEntry, filters, nameFilters, iteratorFlags); nativeIterators << it; #endif } }
// We could port this to KTempDir::removeDir but then we wouldn't be able to tell the user // where exactly the deletion failed, in case of errors. bool FileProtocol::deleteRecursive(const QString& path) { //kDebug() << path; QDirIterator it(path, QDir::AllEntries | QDir::NoDotAndDotDot | QDir::System | QDir::Hidden, QDirIterator::Subdirectories); QStringList dirsToDelete; while ( it.hasNext() ) { const QString itemPath = it.next(); //kDebug() << "itemPath=" << itemPath; const QFileInfo info = it.fileInfo(); if (info.isDir() && !info.isSymLink()) dirsToDelete.prepend(itemPath); else { //kDebug() << "QFile::remove" << itemPath; if (!QFile::remove(itemPath)) { error(KIO::ERR_CANNOT_DELETE, itemPath); return false; } } } QDir dir; Q_FOREACH(const QString& itemPath, dirsToDelete) { //kDebug() << "QDir::rmdir" << itemPath; if (!dir.rmdir(itemPath)) { error(KIO::ERR_CANNOT_DELETE, itemPath); return false; } } return true; }
tlp::node addFileNode(const QFileInfo &infos, tlp::Graph *g) { tlp::node n = g->addNode(); _absolutePaths->setNodeValue(n,tlp::QStringToTlpString(infos.absoluteFilePath())); _baseNames->setNodeValue(n,tlp::QStringToTlpString(infos.baseName())); _createdDates->setNodeValue(n,tlp::QStringToTlpString(infos.created().toString())); _fileNames->setNodeValue(n,tlp::QStringToTlpString(infos.fileName())); _isDir->setNodeValue(n,infos.isDir()); _isExecutable->setNodeValue(n,infos.isExecutable()); _isReadable->setNodeValue(n,infos.isReadable()); _isSymlink->setNodeValue(n,infos.isSymLink()); _isWritable->setNodeValue(n,infos.isWritable()); _lastModifiedDates->setNodeValue(n,tlp::QStringToTlpString(infos.lastModified().toString())); _lastReadDates->setNodeValue(n,tlp::QStringToTlpString(infos.lastRead().toString())); _owners->setNodeValue(n,tlp::QStringToTlpString(infos.owner())); _permissions->setNodeValue(n,(int)(infos.permissions())); _suffixes->setNodeValue(n,tlp::QStringToTlpString(infos.suffix())); _sizes->setNodeValue(n,infos.size()); if (_useIcons) { std::string extension = infos.suffix().toStdString(); if (infos.isDir()) { _fontAwesomeIcon->setNodeValue(n, tlp::TulipFontAwesome::FolderO); tlp::ColorProperty *viewColor = graph->getProperty<tlp::ColorProperty>("viewColor"); viewColor->setNodeValue(n, dirColor); } else if (std::find(commonTextFilesExt.begin(), commonTextFilesExt.end(), extension) != commonTextFilesExt.end()) { _fontAwesomeIcon->setNodeValue(n, tlp::TulipFontAwesome::FileTextO); } else if (std::find(commonArchiveFilesExt.begin(), commonArchiveFilesExt.end(), extension) != commonArchiveFilesExt.end()) { _fontAwesomeIcon->setNodeValue(n, tlp::TulipFontAwesome::FileArchiveO); } else if (std::find(commonAudioFilesExt.begin(), commonAudioFilesExt.end(), extension) != commonAudioFilesExt.end()) { _fontAwesomeIcon->setNodeValue(n, tlp::TulipFontAwesome::FileAudioO); } else if (std::find(commonImageFilesExt.begin(), commonImageFilesExt.end(), extension) != commonImageFilesExt.end()) { _fontAwesomeIcon->setNodeValue(n, tlp::TulipFontAwesome::FileImageO); } else if (std::find(commonVideoFilesExt.begin(), commonVideoFilesExt.end(), extension) != commonVideoFilesExt.end()) { _fontAwesomeIcon->setNodeValue(n, tlp::TulipFontAwesome::FileVideoO); } else if (std::find(commonDevFilesExt.begin(), commonDevFilesExt.end(), extension) != commonDevFilesExt.end()) { _fontAwesomeIcon->setNodeValue(n, tlp::TulipFontAwesome::FileCodeO); } else if (extension == "pdf") { _fontAwesomeIcon->setNodeValue(n, tlp::TulipFontAwesome::FilePdfO); } else if (extension == "doc" || extension == "docx") { _fontAwesomeIcon->setNodeValue(n, tlp::TulipFontAwesome::FileWordO); } else if (extension == "xls" || extension == "xlsx") { _fontAwesomeIcon->setNodeValue(n, tlp::TulipFontAwesome::FileExcelO); } else if (extension == "ppt" || extension == "pptx") { _fontAwesomeIcon->setNodeValue(n, tlp::TulipFontAwesome::FilePowerpointO); } } return n; }
static inline std::string permissions(const QFileInfo &fi) { std::string result = permissions(fi.permissions()); if (fi.isSymLink()) result[0] = 'l'; else if (fi.isDir()) result[0] = 'd'; return result; }
qulonglong TrashSizeCache::calculateSize() { // First read the directorysizes cache into memory QFile file( mTrashSizeCachePath ); typedef QHash<QByteArray, CacheData> DirCacheHash; DirCacheHash dirCache; if (file.open(QIODevice::ReadOnly)) { while (!file.atEnd()) { const QByteArray line = file.readLine(); const int firstSpace = line.indexOf(' '); const int secondSpace = line.indexOf(' ', firstSpace + 1); CacheData data; data.mtime = line.left(firstSpace).toLongLong(); // "012 4567 name" -> firstSpace=3, secondSpace=8, we want mid(4,4) data.size = line.mid(firstSpace + 1, secondSpace - firstSpace - 1).toULongLong(); dirCache.insert(line.mid(secondSpace + 1), data); } } // Iterate over the actual trashed files. // Orphan items (no .fileinfo) still take space. QDirIterator it( mTrashPath + QString::fromLatin1( "/files/" ), QDirIterator::NoIteratorFlags ); qulonglong sum = 0; while ( it.hasNext() ) { const QFileInfo file = it.next(); if (file.fileName() == QLatin1String(".") || file.fileName() == QLatin1String("..")) { continue; } if ( file.isSymLink() ) { // QFileInfo::size does not return the actual size of a symlink. #253776 KDE_struct_stat buff; return static_cast<qulonglong>(KDE::lstat(file.absoluteFilePath(), &buff) == 0 ? buff.st_size : 0); } else if (file.isFile()) { sum += file.size(); } else { bool usableCache = false; const QString fileId = file.fileName(); DirCacheHash::const_iterator it = dirCache.constFind(QFile::encodeName(fileId)); if (it != dirCache.constEnd()) { const CacheData &data = *it; const QString fileInfoPath = mTrashPath + "/info/" + fileId + ".trashinfo"; if (QFileInfo(fileInfoPath).lastModified().toMSecsSinceEpoch() == data.mtime) { sum += data.size; usableCache = true; } } if (!usableCache) { const qulonglong size = DiscSpaceUtil::sizeOfPath(file.absoluteFilePath()); sum += size; add(fileId, size); } } } return sum; }
void WebApplication::sendWebUIFile() { const QStringList pathItems {request().path.split('/', QString::SkipEmptyParts)}; if (pathItems.contains(".") || pathItems.contains("..")) throw InternalServerErrorHTTPError(); if (!m_isAltUIUsed) { if (request().path.startsWith(PATH_PREFIX_IMAGES)) { const QString imageFilename {request().path.mid(PATH_PREFIX_IMAGES.size())}; sendFile(QLatin1String(":/icons/") + imageFilename); return; } } const QString path { (request().path != QLatin1String("/") ? request().path : (session() ? QLatin1String("/index.html") : QLatin1String("/login.html"))) }; QString localPath { m_rootFolder + (session() ? PRIVATE_FOLDER : PUBLIC_FOLDER) + path }; QFileInfo fileInfo {localPath}; if (!fileInfo.exists() && session()) { // try to send public file if there is no private one localPath = m_rootFolder + PUBLIC_FOLDER + path; fileInfo.setFile(localPath); } if (m_isAltUIUsed) { #ifdef Q_OS_UNIX if (!Utils::Fs::isRegularFile(localPath)) { status(500, "Internal Server Error"); print(tr("Unacceptable file type, only regular file is allowed."), Http::CONTENT_TYPE_TXT); return; } #endif while (fileInfo.filePath() != m_rootFolder) { if (fileInfo.isSymLink()) throw InternalServerErrorHTTPError(tr("Symlinks inside alternative UI folder are forbidden.")); fileInfo.setFile(fileInfo.path()); } } sendFile(localPath); }
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; }
/*! \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); }
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 }
foreach (QFileInfo f, files){ if (f.isDir()&&!f.isSymLink()&&f.isReadable()){ ++count_dirs; dirRound(f.absoluteFilePath()); } else { ++count_files; total_size+=f.size(); } }
void parseFile(const QFileInfo& file, bool force_update=false) { if(!file.exists())return; if(file.isSymLink())return; //skip files in skiplist if(skip_paths.contains(file.fileName()))return; //force update on our files if(!force_update)force_update=our_paths.contains(file.filePath()); if(file.isDir()) { QString name=file.baseName(); //ignore system dirs if(name.length()==0 || name.at(0)==QChar('.'))return; QDir dir(file.absoluteFilePath()); QFileInfoList list = dir.entryInfoList( QDir::NoDotAndDotDot|QDir::Readable|QDir::Dirs|QDir::Files, QDir::DirsFirst|QDir::Name); QFileInfoList::const_iterator iter=list.constBegin(); for(;iter!=list.constEnd(); ++iter) { qDebug()<<"... "<<iter->filePath(); parseFile(*iter,force_update); } return; } if(file.isFile()) { filereported=false;//reset flag QStringList exts; exts<<"cpp"<<"c"<<"hpp"<<"h"<<"java"<<"qml"; QString ext=file.completeSuffix().toLower(); if(exts.contains(ext)) { qDebug()<<"Parsing "<<file.baseName(); processCXXFile(file.absoluteFilePath(),force_update); removeExtraLines(file.absoluteFilePath()); } else if(file.baseName().toLower()=="makefile") { qDebug()<<"Parsing "<<file.baseName(); processMakeFile(file.absoluteFilePath(),force_update); removeExtraLines(file.absoluteFilePath()); } } }
quint64 RecursiveDirJobHelper::calculateDirSize(const QString & dir) { QDir currentDir(dir); if ( !currentDir.exists() ) { emit errorOccured(Error(Error::NoSuchFileOrDirectory, dir)); return 0; } QFileInfoList currentList = currentDir.entryInfoList(dirFilters); QFileInfo currentItem; QStack<QFileInfoList> stack; quint64 totalSize = 0; int refreshCounter = 0; if ( m_reportProgress ) { //show busy waiting indicator emit setMaximum(0); emit setValue(0); } while(1){ if ( !currentList.isEmpty() ){ currentItem = currentList.takeFirst(); totalSize += stat_size(currentItem.absoluteFilePath()); if ( currentItem.isDir() && !currentItem.isSymLink() ) { if ( !currentDir.cd(currentItem.fileName()) ) { emit errorOccured(Error(Error::AccessDenied, currentItem.absoluteFilePath())); } else { stack.push(currentList); currentList = currentDir.entryInfoList(dirFilters); } } if ( m_reportProgress && (++refreshCounter % 100 == 0) ) emit setLabelText( tr("Calculating the size of \"%1\"... %2") .arg(dir).arg(DirOperations::bytesToString(totalSize)) ); } else { // list is empty if ( !stack.isEmpty() ){ currentList = stack.pop(); currentDir.cdUp(); } else break; } } totalSize += stat_size(dir); qDebug() << "calculateDirSize" << dir << totalSize; return totalSize; }
/** * \brief Lookup some settings, and do OS-specific stuff in sub-classes * * \bug If the user changes the MonitorDrives or IgnoreDevices settings, * it will have no effect until the frontend is restarted. */ MediaMonitor::MediaMonitor(QObject* par, unsigned long interval, bool allowEject) : QObject(par), m_Active(false), m_Thread(NULL), m_MonitorPollingInterval(interval), m_AllowEject(allowEject) { // MediaMonitor object is always created, // but the user can elect not to actually do monitoring: m_StartThread = gCoreContext->GetNumSetting("MonitorDrives"); // User can specify that some devices are not monitored QString ignore = gCoreContext->GetSetting("IgnoreDevices", ""); if (ignore.length()) m_IgnoreList = ignore.split(',', QString::SkipEmptyParts); else m_IgnoreList = QStringList(); // Force empty list if (m_StartThread) LOG(VB_MEDIA, LOG_NOTICE, "Creating MediaMonitor"); else #ifdef USING_DARWIN_DA LOG(VB_MEDIA, LOG_INFO, "MediaMonitor is disabled. Eject will not work"); #else LOG(VB_MEDIA, LOG_INFO, "Creating inactive MediaMonitor and static device list"); #endif LOG(VB_MEDIA, LOG_INFO, "IgnoreDevices=" + ignore); // If any of IgnoreDevices are symlinks, also add the real device QStringList::Iterator dev; for (dev = m_IgnoreList.begin(); dev != m_IgnoreList.end(); ++dev) { QFileInfo *fi = new QFileInfo(*dev); if (fi && fi->isSymLink()) { QString target = getSymlinkTarget(*dev); if (m_IgnoreList.filter(target).isEmpty()) { LOG(VB_MEDIA, LOG_INFO, "Also ignoring " + target + " (symlinked from " + *dev + ")."); m_IgnoreList += target; } } delete fi; } }
/** * 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); }
static bool isCacheable(const QFileInfo &fi) { if (!fi.isFile()) return false; #ifdef Q_OS_WIN // On windows it's faster to just look at the file extensions. QTBUG-13182 const QString fileExtension = fi.suffix(); // Will return false for .exe, .lnk and .ico extensions return fileExtension.compare(QLatin1String("exe"), Qt::CaseInsensitive) && fileExtension.compare(QLatin1String("lnk"), Qt::CaseInsensitive) && fileExtension.compare(QLatin1String("ico"), Qt::CaseInsensitive); #else return !fi.isExecutable() && !fi.isSymLink(); #endif }