void RsyncDirListerOperation::procFinished() { QTextCodec *codec = QTextCodec::codecForName("UTF-8"); QTextStream outputStream (new QString(codec->toUnicode(d->syncProcess -> readAllStandardOutput()))); QString line; QList<RsyncEntry*> parentEntries; do { line =outputStream.readLine(); QStringList data= line.split(" ",QString::SkipEmptyParts); if (data.isEmpty()) continue; bool isDir=false; bool isFile=false; bool isLink=false; bool isExec=false; QString d1=data[0]; //in data list 0: permisions, 1: size, 2: date, 3: hour, 4: name if (d1.at(0)=='d'){ isExec=true; isDir=true; } else if(d1.at(0)=='l') isLink=true; else if(d1.at(0)=='-') isFile=true; else continue; d1=data[4]; for (int i=5;i<data.size();i++) d1+=" "+data[i]; if (d1[0]=='.') continue; if (d->parentEntry){ d->parentEntry->addUrlInfo(QUrlInfo(d1,777,"root","root",data[1].toLong(), QDateTime::fromString(data[2]+" "+data[3],"yyyy/MM/dd HH:mm:ss"), QDateTime::fromString(data[2]+" "+data[3],"yyyy/MM/dd HH:mm:ss"), isDir,isFile,isLink,false,true,isExec)); }else{ parentEntries.append(new RsyncEntry(QUrlInfo(d1,777,"root","root",data[1].toLong(), QDateTime::fromString(data[2]+" "+data[3],"yyyy/MM/dd HH:mm:ss"), QDateTime::fromString(data[2]+" "+data[3],"yyyy/MM/dd HH:mm:ss"), isDir,isFile,isLink,false,true,isExec))); } }while (!line.isNull()); d->executing = false; d->finished = true; d->success = true; if (d->parentEntry) d->parent->setChildrenFetched(d->parentEntry); else d->parent->setTopLevelEntries(parentEntries); }
void SFtpFileEngine::readDir(const QString &dir) { QString cacheDir(getCachePath(dir, true)); _fileInfoCache->removeDirInfo(cacheDir); // add an empty entry to distinguish a empty directory from // a non-existent directory _fileInfoCache->addFileInfo(cacheDir, QUrlInfo()); LIBSSH2_SFTP_HANDLE* dir_handle; dir_handle = libssh2_sftp_opendir(_sftp_session, _textCodec->fromUnicode(dir).data()); if (dir_handle) { QByteArray entry(512, 0); QByteArray longEntry(512, 0); LIBSSH2_SFTP_ATTRIBUTES attr; while (libssh2_sftp_readdir_ex(dir_handle, entry.data(), entry.capacity(), longEntry.data(), longEntry.capacity(), &attr) > 0) { QString entryUni(_textCodec->toUnicode(entry.data())); QUrlInfo urlInfo; attr2urlinfo(&urlInfo, entryUni, &attr); _fileInfoCache->addFileInfo(cacheDir, urlInfo); } libssh2_sftp_closedir(dir_handle); } }
void RsyncEntry::setFetching(bool val) { d->fetching = val; // Add a dummy URL info, until // children are fetched. addUrlInfo(QUrlInfo()); }
void QLocalFs::operationListChildren( QNetworkOperation *op ) { #ifdef QLOCALFS_DEBUG qDebug( "QLocalFs: operationListChildren" ); #endif op->setState( StInProgress ); dir = QDir( url()->path() ); dir.setNameFilter( url()->nameFilter() ); dir.setMatchAllDirs( TRUE ); if ( !dir.isReadable() ) { QString msg = tr( "Could not read directory\n%1" ).arg( url()->path() ); op->setState( StFailed ); op->setProtocolDetail( msg ); op->setErrorCode( (int)ErrListChildren ); emit finished( op ); return; } const QFileInfoList *filist = dir.entryInfoList( QDir::All | QDir::Hidden | QDir::System ); if ( !filist ) { QString msg = tr( "Could not read directory\n%1" ).arg( url()->path() ); op->setState( StFailed ); op->setProtocolDetail( msg ); op->setErrorCode( (int)ErrListChildren ); emit finished( op ); return; } emit start( op ); QFileInfoListIterator it( *filist ); QFileInfo *fi; QValueList<QUrlInfo> infos; while ( ( fi = it.current() ) != 0 ) { ++it; infos << QUrlInfo( fi->fileName(), convertPermissions(fi), fi->owner(), fi->group(), fi->size(), fi->lastModified(), fi->lastRead(), fi->isDir(), fi->isFile(), fi->isSymLink(), fi->isWritable(), fi->isReadable(), fi->isExecutable() ); } emit newChildren( infos, op ); op->setState( StDone ); emit finished( op ); }
void Q3LocalFs::operationListChildren( Q3NetworkOperation *op ) { #ifdef QLOCALFS_DEBUG qDebug( "Q3LocalFs: operationListChildren" ); #endif op->setState( StInProgress ); dir = QDir( url()->path() ); dir.setNameFilter( url()->nameFilter() ); dir.setMatchAllDirs( true ); if ( !dir.isReadable() ) { QString msg = tr( "Could not read directory\n%1" ).arg( url()->path() ); op->setState( StFailed ); op->setProtocolDetail( msg ); op->setErrorCode( (int)ErrListChildren ); emit finished( op ); return; } QFileInfoList filist = dir.entryInfoList(QDir::All | QDir::Hidden | QDir::System); if ( filist.isEmpty() ) { QString msg = tr( "Could not read directory\n%1" ).arg( url()->path() ); op->setState( StFailed ); op->setProtocolDetail( msg ); op->setErrorCode( (int)ErrListChildren ); emit finished( op ); return; } emit start( op ); Q3ValueList<QUrlInfo> infos; for (int i = 0; i < filist.size(); ++i) { QFileInfo fi = filist.at(i); infos << QUrlInfo( fi.fileName(), convertPermissions(&fi), fi.owner(), fi.group(), fi.size(), fi.lastModified(), fi.lastRead(), fi.isDir(), fi.isFile(), fi.isSymLink(), fi.isWritable(), fi.isReadable(), fi.isExecutable() ); } emit newChildren( infos, op ); op->setState( StDone ); emit finished( op ); }
void SFtpFileEngine::refreshFileInfoCache() { // sftp: case ? if (_url.host().isEmpty()) { qDebug() << "refreshFileInfoCache()" << "host empty" << _path; // accepts / only if (_path != "/") { _fileFlags = QAbstractFileEngine::FileType; return; } QAbstractFileEngine::FileFlags permissions = QAbstractFileEngine::ReadOwnerPerm | QAbstractFileEngine::ReadUserPerm | QAbstractFileEngine::ReadGroupPerm | QAbstractFileEngine::ReadOtherPerm; _fileFlags = QAbstractFileEngine::RootFlag | QAbstractFileEngine::ExistsFlag | QAbstractFileEngine::DirectoryType | permissions; _urlInfo.setName(_path); _urlInfo.setDir(true); _urlInfo.setPermissions(permissions); QString cacheDir(getCachePath(_path, true)); _fileInfoCache->addFileInfo(cacheDir, _urlInfo); // insert a invalid entry to avoid cache failure in beginEntryList() _fileInfoCache->addFileInfo(cacheDir, QUrlInfo()); return; } // failed to connect or to login ? if (!sftpConnect()) { // Do not cache. // It is possbiel that a server was down and it will be up later. // and caching a wrong account is useless _fileFlags = QAbstractFileEngine::FileType; return; } if (_path == "/") { QAbstractFileEngine::FileFlags permissions = QAbstractFileEngine::ReadOwnerPerm | QAbstractFileEngine::ReadUserPerm | QAbstractFileEngine::ReadGroupPerm | QAbstractFileEngine::ReadOtherPerm; _fileFlags = QAbstractFileEngine::RootFlag | QAbstractFileEngine::ExistsFlag | QAbstractFileEngine::DirectoryType | permissions; _urlInfo.setName(_path); _urlInfo.setDir(true); _urlInfo.setPermissions(permissions); _fileInfoCache->addFileInfo(getCachePath(_path, true), _urlInfo); } else { QString dir(PathComp(_path).dir()); QString name(PathComp(_path).fileName()); readDir(dir); _urlInfo = _fileInfoCache->findFileInfo(getCachePath(_path)); _fileFlags = 0; if (_urlInfo.isValid()) { _fileFlags = QAbstractFileEngine::ExistsFlag; _fileFlags |= _urlInfo.isDir() ? QAbstractFileEngine::DirectoryType : QAbstractFileEngine::FileType; if (_path == "/") _fileFlags |= QAbstractFileEngine::RootFlag; _fileFlags |= QAbstractFileEngine::FileFlag(_urlInfo.permissions()); } else if (name != ":refresh:") // do not cache a refresh signal { // add a non-existent entry as well not to read a directory // to retrive its information and to test its existence again // later _fileFlags |= QAbstractFileEngine::FileType; _urlInfo.setName(name); _urlInfo.setPermissions(0); _fileInfoCache->addFileInfo(getCachePath(dir, true), _urlInfo); } } sftpDisconnect(); }