bool SFtpFileEngine::rename(const QString &newName) { qDebug() << "rename()" << _fileName << _path << newName; if (!sftpConnect()) return false; PathComp fixedNewName(newName); QString newPath(QUrl(fixedNewName.path()).path()); bool result = !libssh2_sftp_rename(_sftp_session, _textCodec->fromUnicode(_path).data(), _textCodec->fromUnicode(newPath).data()); if (result) { _fileInfoCache->renameFileInfo(getCachePath(_path), getCachePath(newPath)); _urlInfo.setName(fixedNewName.fileName()); } sftpDisconnect(); return result; }
QString Cache::get(const QString &strChannel, const QString &strUrl) { QString strFileName = QString(QCryptographicHash::hash(strUrl.toLatin1(), QCryptographicHash::Md5).toHex())+"."+QFileInfo(strUrl).suffix(); QString strPathPlusFileName = getCachePath(strFileName); bool bDownloadFile = true; if (QFile::exists(strPathPlusFileName)) { QList<QString> lSupportedImages; lSupportedImages << "jpg" << "jpeg" << "png" << "bmp"; if (lSupportedImages.contains(QFileInfo(strFileName).suffix().toLower())) { QPixmap pixmap; if (!pixmap.load(strPathPlusFileName)) bDownloadFile = true; else bDownloadFile = false; } else bDownloadFile = false; } else bDownloadFile = true; if (bDownloadFile) { QNetworkReply *reply = accessManager->get(QNetworkRequest(strUrl)); reply->setProperty("file", strPathPlusFileName); reply->setProperty("channel", strChannel); } return strPathPlusFileName; }
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 SFtpFileEngine::initSFtp() { _fileInfoCache = FtpFileInfoCache::getInstance(); QString cacheEntry(getCachePath(_path)); QUrlInfo urlInfo = _fileInfoCache->findFileInfo(cacheEntry); if (urlInfo.isValid()) { // non-existent file ? if (urlInfo.permissions() == 0) { _fileFlags = QAbstractFileEngine::FileType; return; } _fileFlags = QAbstractFileEngine::ExistsFlag; _fileFlags |= urlInfo.isDir() ? QAbstractFileEngine::DirectoryType : QAbstractFileEngine::FileType; if (_path == "/") _fileFlags |= QAbstractFileEngine::RootFlag; _fileFlags |= QAbstractFileEngine::FileFlag(urlInfo.permissions()); _urlInfo = urlInfo; return; } refreshFileInfoCache(); }
void UninstallAllThread::removeDesuraCache() { gcString logStr("{0}\n", Managers::GetString("#DUN_THREAD_CACHE")); onLogEvent(logStr); m_iTotalPos++; std::pair<uint32,uint32> pair(m_iTotalPos*100/m_iTotal, 0); onProgressEvent(pair); UTIL::FS::Path path(getCachePath(), "", false); std::vector<std::string> extList; extList.push_back("mcf"); for (size_t x=0; x<20; x++) extList.push_back(gcString("part_{0}", x)); UTIL::FS::Path dbDir(UTIL::OS::getAppDataPath(), L"", false); delLeftOverMcf(path, extList); delLeftOverMcf(dbDir, extList); UTIL::FS::Path mcfUploads = dbDir; UTIL::FS::Path mcfStore = dbDir; mcfUploads += UTIL::FS::File("mcf_uploads.sqlite"); mcfStore += UTIL::FS::File("mcfstoreb.sqlite"); UTIL::FS::delFile(mcfUploads); UTIL::FS::delFile(mcfStore); }
bool Device::loadFromCache() { std::string sDevicePath = getCachePath() + getConfigRom().getGuidString(); char* configId; asprintf(&configId, "%016"PRIx64"", getConfigurationId() ); if ( !configId ) { debugError( "could not create id string\n" ); return false; } std::string sFileName = sDevicePath + "/" + configId + ".xml"; free( configId ); debugOutput( DEBUG_LEVEL_NORMAL, "filename %s\n", sFileName.c_str() ); struct stat buf; if ( stat( sFileName.c_str(), &buf ) != 0 ) { debugOutput( DEBUG_LEVEL_NORMAL, "\"%s\" does not exist\n", sFileName.c_str() ); return false; } else { if ( !S_ISREG( buf.st_mode ) ) { debugOutput( DEBUG_LEVEL_NORMAL, "\"%s\" is not a regular file\n", sFileName.c_str() ); return false; } } Util::XMLDeserialize deser( sFileName, getDebugLevel() ); if (!deser.isValid()) { debugOutput( DEBUG_LEVEL_NORMAL, "cache not valid: %s\n", sFileName.c_str() ); return false; } bool result = deserialize( "", deser ); if ( result ) { debugOutput( DEBUG_LEVEL_NORMAL, "could create valid bebob driver from %s\n", sFileName.c_str() ); } if(result) { buildMixer(); } return result; }
bool Device::saveCache() { // the path looks like this: // PATH_TO_CACHE + GUID + CONFIGURATION_ID string tmp_path = getCachePath() + getConfigRom().getGuidString(); // the following piece should do something like // 'mkdir -p some/path/with/some/dirs/which/do/not/exist' vector<string> tokens; tokenize( tmp_path, tokens, "/" ); string path; for ( vector<string>::const_iterator it = tokens.begin(); it != tokens.end(); ++it ) { path += "/" + *it; struct stat buf; if ( stat( path.c_str(), &buf ) == 0 ) { if ( !S_ISDIR( buf.st_mode ) ) { debugError( "\"%s\" is not a directory\n", path.c_str() ); return false; } } else { if ( mkdir( path.c_str(), S_IRWXU | S_IRWXG ) != 0 ) { debugError( "Could not create \"%s\" directory\n", path.c_str() ); return false; } } } // come up with an unique file name for the current settings char* configId; asprintf(&configId, "%016"PRIx64"", BeBoB::Device::getConfigurationId() ); if ( !configId ) { debugError( "Could not create id string\n" ); return false; } string filename = path + "/" + configId + ".xml"; free( configId ); debugOutput( DEBUG_LEVEL_NORMAL, "filename %s\n", filename.c_str() ); Util::XMLSerialize ser( filename ); return serialize( "", ser ); }
/** * symlinking new icon to actual.gif in .cache/weather/ */ void symlinking_image(char *image) { char *filename_new = SHARED_FOLDER; char *filename_old = 0; getCachePath(&filename_old, APP_NAME); strmcat(&filename_old, "actual.gif"); strmcat(&filename_new, "/%1.gif"); strmreplace(&filename_new, "%1", image); unlink(filename_old); if(symlink(filename_new, filename_old) == -1) outerr("Error symlinking"); freeChar(&filename_new); freeChar(&filename_old); }
MC2String ModuleMap::getCacheFilename( uint32 mapID, uint32 loadMapRequestType, byte zoomlevel ) { char fileName[1024]; MC2String path = getCachePath(); if ( path.length() == 0 ) { return ""; } sprintf(fileName, "%s%09x_z%04u_%04u%s", path.c_str(), mapID, zoomlevel, loadMapRequestType, ".cached"); return MC2String(fileName); }
bool SFtpFileEngine::remove() { qDebug() << "remove()" << _fileName; if (!sftpConnect()) return false; bool result = !libssh2_sftp_unlink(_sftp_session, _textCodec->fromUnicode(_path).data()); if (result) { // remove cache entry _fileInfoCache->removeFileInfo(getCachePath(_path)); _fileFlags = QAbstractFileEngine::FileType; } sftpDisconnect(); return result; }
QAbstractFileEngine::Iterator* SFtpFileEngine::beginEntryList(QDir::Filters filters, const QStringList &filterNames) { qDebug() << "beginEntryList() : " << _fileName << _fileFlags; QString cachePath(getCachePath(_path, true)); FtpFileInfoCache::QUrlInfoList list = _fileInfoCache->findDirInfo(cachePath); if (list.size() == 0 && (_fileFlags & QAbstractFileEngine::DirectoryType) && sftpConnect()) { readDir(_path); sftpDisconnect(); } QMap<QString, QUrlInfo> entriesMap; list = _fileInfoCache->findDirInfo(cachePath); if (list.size() > 0) { FtpFileInfoCache::QUrlInfoListIterator it(list); while (it.hasNext()) { QUrlInfo urlInfo = it.next(); // exclude an empty entry inserted by us and a non-existent entry if (urlInfo.isValid() && urlInfo.permissions()) entriesMap.insert(urlInfo.name(), urlInfo); } } return new FtpFileEngineIterator(filters, filterNames, filterEntries(filters, filterNames, entriesMap)); }
VString VDirAdapter::getAppPath() const { return getCachePath(); }
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(); }
QString DFMStandardPaths::location(DFMStandardPaths::StandardLocation type) { switch (type) { case TrashPath: return QDir::homePath() + "/.local/share/Trash"; case TrashFilesPath: return QDir::homePath() + "/.local/share/Trash/files"; case TrashInfosPath: return QDir::homePath() + "/.local/share/Trash/info"; #ifdef APPSHAREDIR case TranslationPath: { QString path = APPSHAREDIR"/translations"; if (!QDir(path).exists()) { path = qApp->applicationDirPath() + "/translations"; } return path; } case TemplatesPath: { QString path = APPSHAREDIR"/templates"; if (!QDir(path).exists()) { path = qApp->applicationDirPath() + "/templates"; } return path; } case MimeTypePath: { QString path = APPSHAREDIR"/mimetypes"; if (!QDir(path).exists()) { path = qApp->applicationDirPath() + "/mimetypes"; } return path; } #endif #ifdef PLUGINDIR case PluginsPath: { QString path = PLUGINDIR; if (!QDir(path).exists()) { path = QString::fromLocal8Bit(PLUGINDIR).split(':').last(); } return path; } #endif #ifdef QMAKE_TARGET case ApplicationConfigPath: return getConfigPath(); #endif case ThumbnailPath: return QDir::homePath() + "/.cache/thumbnails"; case ThumbnailFailPath: return location(ThumbnailPath) + "/fail"; case ThumbnailLargePath: return location(ThumbnailPath) + "/large"; case ThumbnailNormalPath: return location(ThumbnailPath) + "/normal"; case ThumbnailSmallPath: return location(ThumbnailPath) + "/small"; #ifdef APPSHAREDIR case ApplicationSharePath: return APPSHAREDIR; #endif case RecentPath: return "recent:///"; case HomePath: return QStandardPaths::standardLocations(QStandardPaths::HomeLocation).first(); case DesktopPath: return QStandardPaths::standardLocations(QStandardPaths::DesktopLocation).first(); case VideosPath: return QStandardPaths::standardLocations(QStandardPaths::MoviesLocation).first(); case MusicPath: return QStandardPaths::standardLocations(QStandardPaths::MusicLocation).first(); case PicturesPath: return QStandardPaths::standardLocations(QStandardPaths::PicturesLocation).first(); case DocumentsPath: return QStandardPaths::standardLocations(QStandardPaths::DocumentsLocation).first(); case DownloadsPath: return QStandardPaths::standardLocations(QStandardPaths::DownloadLocation).first(); case CachePath: return getCachePath(); case DiskPath: return QDir::rootPath(); #ifdef NETWORK_ROOT case NetworkRootPath: return NETWORK_ROOT; #endif #ifdef USERSHARE_ROOT case UserShareRootPath: return USERSHARE_ROOT; #endif #ifdef COMPUTER_ROOT case ComputerRootPath: return COMPUTER_ROOT; #endif case Root: return "/"; default: return QStringLiteral("bug://dde-file-manager-lib/interface/dfmstandardpaths.cpp#") + QT_STRINGIFY(type); } return QString(); }