Ejemplo n.º 1
0
void DownloadOperation::tryCalcInputFilesSize()
{
  FileInfoList *fil = m_toCopy;

  while (fil != NULL) {
    if (fil->getFileInfo()->isDirectory()) {
      StringStorage pathNoRoot;
      StringStorage pathToFile;

      fil->getAbsolutePath(&pathNoRoot, _T('/'));

      pathToFile.setString(m_pathToSourceRoot.getString());
      if (!pathToFile.endsWith(_T('/'))) {
        pathToFile.appendString(_T("/"));
      }
      pathToFile.appendString(pathNoRoot.getString());

      m_foldersToCalcSizeLeft++;
      m_sender->sendFolderSizeRequest(pathToFile.getString());
    } else {
      m_totalBytesToCopy += fil->getFileInfo()->getSize();
    }
    fil = fil->getNext();
  }
}
Ejemplo n.º 2
0
void DownloadOperation::gotoNext()
{
  FileInfoList *current = m_toCopy;

  bool hasChild = current->getChild() != NULL;
  bool hasNext = current->getNext() != NULL;
  bool hasParent = current->getFirst()->getParent() != NULL;

  if (hasChild) {
    changeFileToDownload(current->getChild());
    startDownload();
  } else if (hasNext) {
    changeFileToDownload(current->getNext());
    startDownload();
  } else {

    FileInfoList *first = current->getFirst();
    if (hasParent) {
      changeFileToDownload(first->getParent());
      m_toCopy->setChild(NULL, 0);

      gotoNext();
    } else {
      killOp();
    } 
  } 
} 
Ejemplo n.º 3
0
void DownloadOperation::gotoNext()
{
  FileInfoList *current = m_toCopy;

  bool hasChild = current->getChild() != NULL;
  bool hasNext = current->getNext() != NULL;
  bool hasParent = current->getFirst()->getParent() != NULL;

  if (hasChild) {
    // If it has child, we must download child file list first
    changeFileToDownload(current->getChild());
    startDownload();
  } else if (hasNext) {
    // If it has no child, but has next file, we must download next file
    changeFileToDownload(current->getNext());
    startDownload();
  } else {

    //
    // If it has no child and not next, but has parent file,
    // we must go to parent file (folder i mean), set childs to NULL
    // cause we already download child files and go to next file.
    //

    FileInfoList *first = current->getFirst();
    if (hasParent) {
      changeFileToDownload(first->getParent());
      m_toCopy->setChild(NULL, 0);

      gotoNext();
    } else {
      killOp();
    } // if / else
  } // if / else
} // void
Ejemplo n.º 4
0
FileInfoList Dir::entryInfoList(QFlags<Filters> filters,
                           QFlags<SortFlags> sortFlags)
{
    if(filters == NoFilter)
        filters = m_filters;
    if(sortFlags == NoSort)
        sortFlags == m_sort_flags;

    FileInfoList ret;

    // use our internal method to get an unsorted list, then sort it
    foreach(QString entry, m_entry_list())
    {
        // this list contains absolute URIs
        FileInfo i(entry);

        // apply the filters //

        // is this a hidden file ?
        if(i.fileName().startsWith('.') && !filters.testFlag(Hidden))
            continue; // yes, don't include it unless Hidden flag is set

        // check permissions
        if(!i.isReadable() && filters.testFlag(Readable))
            continue; // non readable, and we must ony include readable
        // as above, for +w and +x
        if(!i.isWritable() && filters.testFlag(Writeable))
            continue;
        if(!i.isExecutable() && filters.testFlag(Executable))
            continue;

        // is it a symlink ?
        if(i.isSymlink())
        {
            // can we include it ?
            if(!filters.testFlag(NoSymlinks))
                ret.append(i);
        }

        // is it a dir ?
        else if(i.isDir())
        {
            if(filters.testFlag(AllDirs))
                ret.append(i); // yes, but flag AllDirs tells we should include it even he does not match name filters
            else if(filters.testFlag(Dirs) || filters.testFlag(AllEntries)/* && TODO: add nameFilters */)
                ret.append(i); // yes, but he must match the name filters to be included
        }

        // is it a file ?
        else if(i.isFile())
        {
            if(filters.testFlag(Files) || filters.testFlag(AllEntries))
                ret.append(i);
        }
    }
Ejemplo n.º 5
0
    //-----------------------------------------------------------------------
    FileInfoListPtr ZipArchive::listFileInfo(bool recursive, bool dirs) const
    {
        OGRE_LOCK_AUTO_MUTEX;
        FileInfoList* fil = OGRE_NEW_T(FileInfoList, MEMCATEGORY_GENERAL)();
        FileInfoList::const_iterator i, iend;
        iend = mFileList.end();
        for (i = mFileList.begin(); i != iend; ++i)
            if ((dirs == (i->compressedSize == size_t (-1))) &&
                (recursive || i->path.empty()))
                fil->push_back(*i);

        return FileInfoListPtr(fil, SPFM_DELETE_T);
    }
Ejemplo n.º 6
0
 //-----------------------------------------------------------------------
 FileInfoListPtr ZipArchive::listFileInfo(bool recursive)
 {
     FileInfoList* fil = new FileInfoList();
     FileInfoList::const_iterator i, iend;
     iend = mFileList.end();
     for (i = mFileList.begin(); i != iend; ++i)
     {
         if (recursive || i->path.empty())
         {
             fil->push_back(*i);
         }
     }
     return FileInfoListPtr(fil);
 }
Ejemplo n.º 7
0
FileInfoList Manifest::diff(const FileInfoList& in) const
{
    FileInfoList out;
    for (const auto& f : in)
    {
        auto matches([&f](const FileInfo& x) { return f.path() == x.path(); });

        if (std::none_of(m_fileInfo.begin(), m_fileInfo.end(), matches))
        {
            out.emplace_back(f);
        }
    }

    return out;
}
Ejemplo n.º 8
0
void scanDirectory(FileInfoList &fileEntries, const QString &name, const QString &strDir)
{
   QDir dir(strDir);
   if (!dir.exists()) return;

   QFileInfoList *newEntries = (QFileInfoList *) dir.entryInfoList();

   if (!newEntries) return; // Directory not accessible ??

   for(QFileInfo *qFileInfo = newEntries->first();
       qFileInfo;
       qFileInfo = newEntries->next())
   {
       if (qFileInfo->isFile())
       {
          FileInfo *fileInfo = readEntry( strDir + "/" + qFileInfo->fileName());
          if (fileInfo)
          {
             fileInfo->name = name + "/" + qFileInfo->fileName();
             fileInfo->size = (qFileInfo->size() + 1023) / 1024;
             fileEntries.append(fileInfo);
          }
       }
   }
}
Ejemplo n.º 9
0
void ChatControler::_getFileList(service::ErrorInfo &info, std::vector<FileInfo> files)
{
    FileInfoList msgList;
    MsgFileInfo fileInfo;
    for(auto msg:files)
    {
        fileInfo.fileid = QString::number(msg.fileid);
        fileInfo.userid = QString::number(msg.userid);
        fileInfo.targetid = QString::number(msg.targetid);
        fileInfo.size = msg.size;
        fileInfo.time = msg.time;
        fileInfo.path = QString::fromStdString(msg.path);
        fileInfo.name = QString::fromStdString(msg.name);
        fileInfo.url = QString::fromStdString(msg.url);
        fileInfo.encrypt_key = QString::fromStdString(msg.encrypt_key);
        msgList.push_back(fileInfo);
    }
    emit getFileListBack(info.code(), msgList);
}
Ejemplo n.º 10
0
void LinkDoodService::onChatGetFileList(service::ErrorInfo &info, std::vector<FileInfo> files)
{
    qDebug() << Q_FUNC_INFO;
    FileInfoList msgList;
    MsgFileInfo fileInfo;
    for(auto msg:files)
    {
        fileInfo.fileid = QString::number(msg.fileid);
        fileInfo.userid = QString::number(msg.userid);
        fileInfo.targetid = QString::number(msg.targetid);
        fileInfo.size = msg.size;
        fileInfo.time = msg.time;
        fileInfo.path = QString::fromStdString(msg.path);
        fileInfo.name = QString::fromStdString(msg.name);
        fileInfo.url = QString::fromStdString(msg.url);
        fileInfo.encrypt_key = QString::fromStdString(msg.encrypt_key);
        msgList.push_back(fileInfo);
    }

    emit getFileListResult(info.code(), msgList);
}
Ejemplo n.º 11
0
void GroupControler::_getGroupFileList(service::ErrorInfo &info, std::vector<FileInfo> fileInfos)
{
    FileInfoList fileInfoList;
    if(info.code()==0){
        for(auto i: fileInfos){
            MsgFileInfo msgFileInfo;
            msgFileInfo.encrypt_key=QString::fromStdString(i.encrypt_key);
            msgFileInfo.fileid=QString::number(i.fileid);
            msgFileInfo.name=QString::fromStdString(i.name);
            msgFileInfo.path=QString::fromStdString(i.path);
            msgFileInfo.size=QString::number(i.size);
            msgFileInfo.targetid=QString::number(i.targetid);
            msgFileInfo.url=QString::fromStdString(i.url);
            msgFileInfo.userid=QString::number(i.userid);
            QDateTime DateTime;
            DateTime.setMSecsSinceEpoch(i.time);
            msgFileInfo.time=DateTime.toString("MM月dd日");
            fileInfoList.push_back(msgFileInfo);
        }
    }
    emit getGroupFileListResult(fileInfoList);
}
Ejemplo n.º 12
0
UINT64 UploadOperation::getInputFilesSize()
{
    UINT64 totalFilesSize = 0;

    FileInfoList *fil = m_toCopy;
    while (fil != NULL) {
        StringStorage pathNoRoot;
        StringStorage pathToFile;

        fil->getAbsolutePath(&pathNoRoot, _T('\\'));

        pathToFile.setString(m_pathToSourceRoot.getString());
        pathToFile.appendString(_T("\\"));
        pathToFile.appendString(pathNoRoot.getString());

        totalFilesSize += getFileSize(pathToFile.getString());

        fil = fil->getNext();
    }

    return totalFilesSize;
}
Ejemplo n.º 13
0
void FileSystemChangeNotifier::internalNotifyDirChanged( const Path &dir )
{
   DirMap::Iterator itr = mDirMap.find( dir );
   if ( itr == mDirMap.end() )
      return;

   // Gather the changed file info.
   FileInfoList changedList;
   FileInfoList &fileList = itr->value;
   for ( U32 i = 0; i < fileList.getSize(); i++ )
   {
      FileInfo &fInfo = fileList[i];

      FileNode::Attributes attr;
      bool success = GetFileAttributes(fInfo.filePath, &attr);

      // Ignore the file if we couldn't get the attributes (it must have 
      // been deleted) or the last modification time isn't newer.
      if ( !success || attr.mtime <= fInfo.savedLastModTime )       
         continue;

      // Store the new mod time.
      fInfo.savedLastModTime = attr.mtime;

      // We're taking a copy of the FileInfo struct here so that the
      // callback can safely remove the notification without crashing.
      changedList.pushBack( fInfo );
   }

   // Now signal all the changed files.
   for ( U32 i = 0; i < changedList.getSize(); i++ )
   {
      FileInfo &fInfo = changedList[i];

      Con::warnf( "    : file changed [%s]", fInfo.filePath.getFullPath().c_str() );
      fInfo.signal.trigger( fInfo.filePath );
   }
}
Ejemplo n.º 14
0
void RemoteFilesDeleteOperation::gotoNext()
{
  FileInfoList *current = m_toDelete;

  bool hasChild = current->getChild() != NULL;
  bool hasNext = current->getNext() != NULL;
  bool hasParent = current->getFirst()->getParent() != NULL;

  if (hasChild) {
    // If it has child, we must remove child file list first
    m_toDelete = current->getChild();
    remove(false);
  } else if (hasNext) {
    // If it has no child, but has next file, we must remove next file
    m_toDelete = current->getNext();
    remove(false);
  } else {

    //
    // If it has no child and not next, but has parent file,
    // we must go to parent file (folder i mean) and forced remove it
    //

    FileInfoList *first = current->getFirst();
    if (hasParent) {
      m_toDelete = first->getParent();
      remove(true);
    } else {
      //
      // If no files to delete, than clear memory and
      // operation is finished
      //
      killOp();
    } // if / else
  } // if / else
} // void
Ejemplo n.º 15
0
bool FileSystemChangeNotifier::addNotification( const Path &path, ChangeDelegate callback )
{
   // Notifications are for files... if the path is empty 
   // then there is nothing to do. 
   if ( path.isEmpty() )
      return false;

   // strip the filename and extension - we notify on dirs
   Path dir(cleanPath(path));
   if (dir.isEmpty())
      return false;

   dir.setFileName( String() );
   dir.setExtension( String () );
   
   // first lookup the dir to see if we already have an entry for it...
   DirMap::Iterator   itr = mDirMap.find( dir );

   FileInfoList   *fileList = NULL;
   bool           addedDir = false;

   // Note that GetFileAttributes can fail here if the file doesn't 
   // exist, but thats ok and expected.  You can have notifications 
   // on files that don't exist yet.
   FileNode::Attributes attr;
   GetFileAttributes(path, &attr);

   if ( itr != mDirMap.end() )
   {
      fileList = &(itr->value);

      // look for the file and return if we find it
      for ( U32 i = 0; i < fileList->getSize(); i++ )
      {
         FileInfo &fInfo = (*fileList)[i];
         if ( fInfo.filePath == path )
         {
            // NOTE: This is bad... we should store the mod
            // time for each callback seperately in the future.
            //
            fInfo.savedLastModTime = attr.mtime;
            fInfo.signal.notify(callback);
            return true;
         }
      }
   }
   else
   {
      // otherwise we need to add the dir to our map and let the inherited class add it
      itr = mDirMap.insert( dir, FileInfoList() );

      fileList = &(itr->value);

      addedDir = true;
   }

   FileInfo newInfo;
   newInfo.signal.notify(callback);
   newInfo.filePath = path;
   newInfo.savedLastModTime = attr.mtime;

   fileList->pushBack( newInfo );

   return addedDir ? internalAddNotification( dir ) : true;
}
Ejemplo n.º 16
0
extern "C" KDE_EXPORT int kdemain(int argc, char **argv)
{
   KLocale::setMainCatalogue("kdelibs");
   KCmdLineArgs::init( argc, argv, appName,
		       I18N_NOOP("KDE HTTP cache maintenance tool"),
		       description, version, true);

   KCmdLineArgs::addCmdLineOptions( options );

   KCmdLineArgs *args = KCmdLineArgs::parsedArgs();

   bool deleteAll = args->isSet("clear-all");

   KInstance ins( appName );

   if (!deleteAll)
   {
      DCOPClient *dcop = new DCOPClient();
      QCString name = dcop->registerAs(appName, false);
      if (!name.isEmpty() && (name != appName))
      {
         fprintf(stderr, "%s: Already running! (%s)\n", appName, name.data());
         return 0;
      }
   }

   currentDate = time(0);
   m_maxCacheAge = KProtocolManager::maxCacheAge();
   m_maxCacheSize = KProtocolManager::maxCacheSize();

   if (deleteAll)
      m_maxCacheSize = -1;

   QString strCacheDir = KGlobal::dirs()->saveLocation("cache", "http");

   QDir cacheDir( strCacheDir );
   if (!cacheDir.exists())
   {
      fprintf(stderr, "%s: '%s' does not exist.\n", appName, strCacheDir.ascii());
      return 0;
   }

   QStringList dirs = cacheDir.entryList( );

   FileInfoList cachedEntries;

   for(QStringList::Iterator it = dirs.begin();
       it != dirs.end();
       it++)
   {
      if ((*it)[0] != '.')
      {
         scanDirectory( cachedEntries, *it, strCacheDir + "/" + *it);
      }
   }

   cachedEntries.sort();

   int maxCachedSize = m_maxCacheSize / 2;

   for(FileInfo *fileInfo = cachedEntries.first();
       fileInfo;
       fileInfo = cachedEntries.next())
   {
      if (fileInfo->size > maxCachedSize)
      {
         QCString filename = QFile::encodeName( strCacheDir + "/" + fileInfo->name);
         unlink(filename.data());
//         kdDebug () << appName << ": Object too big, deleting '" << filename.data() << "' (" << result<< ")" << endl;
      }
   }

   int totalSize = 0;

   for(FileInfo *fileInfo = cachedEntries.first();
       fileInfo;
       fileInfo = cachedEntries.next())
   {
      if ((totalSize + fileInfo->size) > m_maxCacheSize)
      {
         QCString filename = QFile::encodeName( strCacheDir + "/" + fileInfo->name);
         unlink(filename.data());
//         kdDebug () << appName << ": Cache too big, deleting '" << filename.data() << "' (" << fileInfo->size << ")" << endl;
      }
      else
      {
         totalSize += fileInfo->size;
// fprintf(stderr, "Keep in cache: %s %d %d total = %d\n", fileInfo->name.ascii(), fileInfo->size, fileInfo->age, totalSize);
      }
   }
   kdDebug () << appName << ": Current size of cache = " << totalSize << " kB." << endl;
   return 0;
}
Ejemplo n.º 17
0
void ConfigParser::normalizeInput(
        Json::Value& json,
        const arbiter::Arbiter& arbiter)
{
    Json::Value& input(json["input"]);
    const bool verbose(json["verbose"].asBool());

    const std::string extension(
            input.isString() ?
                arbiter::Arbiter::getExtension(input.asString()) : "");

    const bool isInferencePath(extension == "entwine-inference");

    if (!isInferencePath)
    {
        // The input source is a path or array of paths.  First, we possibly
        // need to expand out directories into their containing files.
        FileInfoList fileInfo;

        auto insert([&fileInfo, &arbiter, verbose](std::string in)
        {
            Paths current(arbiter.resolve(in, verbose));
            for (const auto& c : current) fileInfo.emplace_back(c);
        });

        if (input.isArray())
        {
            for (const auto& entry : input)
            {
                if (entry.isString())
                {
                    insert(directorify(entry.asString()));
                }
                else
                {
                    fileInfo.emplace_back(entry);
                }
            }
        }
        else if (input.isString())
        {
            insert(directorify(input.asString()));
        }
        else return;

        // Now, we have an array of files (no directories).
        //
        // Reset our input with our resolved paths.  config.input.fileInfo will
        // be an array of strings, containing only paths with no associated
        // information.
        input = Json::Value();
        input.resize(fileInfo.size());
        for (std::size_t i(0); i < fileInfo.size(); ++i)
        {
            input[Json::ArrayIndex(i)] = fileInfo[i].toJson();
        }
    }
    else if (isInferencePath)
    {
        const std::string path(input.asString());
        const Json::Value inference(parse(arbiter.get(path)));

        input = inference["fileInfo"];

        if (!json.isMember("schema")) json["schema"] = inference["schema"];
        if (!json.isMember("bounds")) json["bounds"] = inference["bounds"];
        if (!json.isMember("numPointsHint"))
        {
            json["numPointsHint"] = inference["numPoints"];
        }

        if (inference.isMember("reprojection"))
        {
            json["reprojection"] = inference["reprojection"];
        }

        if (Delta::existsIn(inference))
        {
            if (!json.isMember("scale")) json["scale"] = inference["scale"];
            if (!json.isMember("offset")) json["offset"] = inference["offset"];
        }
    }
}
Ejemplo n.º 18
0
void UploadOperation::gotoNext(bool fake)
{
    FileInfoList *current = m_toCopy;

    bool hasChild = current->getChild() != NULL;
    bool hasNext = current->getNext() != NULL;
    bool hasParent = current->getFirst()->getParent() != NULL;

    if (hasChild) {
        if (fake) {
            m_gotoChild = true;

            m_sender->sendFileListRequest(m_pathToTargetFile.getString(),
                                          m_replyBuffer->isCompressionSupported());
            return ;
        } else {
            // If it has child, we must upload child file list first
            changeFileToUpload(current->getChild());
            startUpload();
        }
    } else if (hasNext) {
        // If it has no child, but has next file, we must upload next file
        changeFileToUpload(current->getNext());
        startUpload();
    } else {

        //
        // If it has no child and not next, but has parent file,
        // we must go to parent file (folder i mean), set childs to NULL
        // cause we already upload child files and go to next file.
        //

        FileInfoList *first = current->getFirst();
        if (hasParent) {
            if (fake) {
                m_gotoParent = true;

                StringStorage pathToRemoteFolder(m_pathToTargetRoot.getString());

                FileInfoList *parentOfCurrent = m_toCopy->getFirst()->getParent();
                FileInfoList *parentOfParent = NULL;

                if (parentOfCurrent != NULL) {
                    parentOfParent = parentOfCurrent->getFirst()->getParent();
                }

                if (parentOfParent != NULL) {
                    getRemotePath(parentOfParent, m_pathToTargetRoot.getString(), &pathToRemoteFolder);
                }

                m_sender->sendFileListRequest(pathToRemoteFolder.getString(),
                                              m_replyBuffer->isCompressionSupported());
                return ;
            } else {
                changeFileToUpload(first->getParent());
                m_toCopy->setChild(NULL, 0);
                gotoNext();
            }
        } else {
            killOp();
        } // if / else
    } // if / else
} // void