Esempio n. 1
0
static int MEGAread(const char *p, char *buf, size_t size, off_t offset,
                      struct fuse_file_info *fi)
{
	string path = megaBasePath + p;
	MegaApi::log(MegaApi::LOG_LEVEL_DEBUG, "Reading file:");
	MegaApi::log(MegaApi::LOG_LEVEL_DEBUG, path.c_str());
        	
	MegaNode *node = megaApi->getNodeByPath(path.c_str());
	if (!node)
	{
		MegaApi::log(MegaApi::LOG_LEVEL_DEBUG, "File not found");
		return -ENOENT;
	}	
	
	if (offset >= node->getSize())
	{
		delete node;
		return 0;
	}
	
	if (offset + size > node->getSize())
	{
		size = node->getSize() - offset;
	}
	
	SynchronousTransferListenerFuse listener;
	megaApi->startStreaming(node, offset, size, &listener);
	listener.wait();
	delete node;
	if (listener.getError()->getErrorCode() != MegaError::API_OK)
	{
		MegaApi::log(MegaApi::LOG_LEVEL_ERROR, "Transfer error");
		return -EIO;
	}
	
	if (listener.getDataSize() != size)
	{
		MegaApi::log(MegaApi::LOG_LEVEL_ERROR, "Internal error");
		return -EIO;
	}
	
	memcpy(buf, listener.getData(), size);
	MegaApi::log(MegaApi::LOG_LEVEL_DEBUG, "File read OK");
    return size;
}
Esempio n. 2
0
void ImportMegaLinksDialog::onLinkInfoAvailable(int id)
{
    ImportListWidgetItem *item = (ImportListWidgetItem *)ui->linkList->itemWidget(ui->linkList->item(id));
    MegaNode *node = linkProcessor->getNode(id);

    int e = linkProcessor->getError(id);
    if (node && (e == MegaError::API_OK))
    {
        QString name = QString::fromUtf8(node->getName());
        if (!name.compare(QString::fromAscii("NO_KEY")) || !name.compare(QString::fromAscii("CRYPTO_ERROR")))
        {
            item->setData(tr("Decryption error"), ImportListWidgetItem::WARNING, node->getSize());
        }
        else
        {
            item->setData(name, ImportListWidgetItem::CORRECT, node->getSize());
        }
    }
    else
    {
        if ((e != MegaError::API_OK) && (e != MegaError::API_ETOOMANY))
        {
            ImportListWidgetItem::linkstatus status = ImportListWidgetItem::FAILED;
            if (e == MegaError::API_ETEMPUNAVAIL)
            {
                status = ImportListWidgetItem::WARNING;
            }
            item->setData(QCoreApplication::translate("MegaError", MegaError::getErrorString(e)), status);
        }
        else
        {
            item->setData(tr("Not found"), ImportListWidgetItem::FAILED);
        }
    }
    item->updateGui();
}
Esempio n. 3
0
void LinkProcessor::importLinks(MegaNode *node)
{
    if (!node)
    {
        return;
    }

    MegaNodeList *children = megaApi->getChildren(node);
    importParentFolder = node->getHandle();

    for (int i = 0; i < linkList.size(); i++)
    {
        if (!linkNode[i])
        {
            MegaApi::log(MegaApi::LOG_LEVEL_ERROR, "Trying to import a NULL node");
        }

        if (linkNode[i] && linkSelected[i] && !linkError[i])
        {
            bool dupplicate = false;
            long long dupplicateHandle;
            const char* name = linkNode[i]->getName();
            long long size = linkNode[i]->getSize();

            for (int j = 0; j < children->size(); j++)
            {
                MegaNode *child = children->get(j);
                if (!strcmp(name, child->getName()) && (size == child->getSize()))
                {
                    dupplicate = true;
                    dupplicateHandle = child->getHandle();
                }
            }

            if (!dupplicate)
            {
                remainingNodes++;
                megaApi->copyNode(linkNode[i], node, delegateListener);
            }
            else
            {
                emit onDupplicateLink(linkList[i], QString::fromUtf8(name), dupplicateHandle);
            }
        }
    }
    delete children;
}
Esempio n. 4
0
static int MEGAgetattr(const char *p, struct stat *stbuf)
{
	string path = megaBasePath + p;
	MegaApi::log(MegaApi::LOG_LEVEL_DEBUG, "Getting attributes:");
	MegaApi::log(MegaApi::LOG_LEVEL_DEBUG, path.c_str());

	MegaNode *n = megaApi->getNodeByPath(path.c_str());
	if (!n)
	{
		MegaApi::log(MegaApi::LOG_LEVEL_DEBUG, "Node not found");
		return -ENOENT;
	}
	
	stbuf->st_uid = getuid();
	stbuf->st_gid = getgid();
	stbuf->st_mode = n->isFile() ? S_IFREG | 0444 : S_IFDIR | 0755;
	stbuf->st_nlink = 1;
	stbuf->st_size = n->isFile() ? n->getSize() : 4096;
	stbuf->st_mtime = n->isFile() ? n->getModificationTime() : n->getCreationTime();
		
	delete n;
	MegaApi::log(MegaApi::LOG_LEVEL_DEBUG, "Attributes read OK");
	return 0;
}
Esempio n. 5
0
void MegaUploader::upload(QFileInfo info, MegaNode *parent)
{
    QApplication::processEvents();

    MegaNodeList *children =  megaApi->getChildren(parent);
    QByteArray utf8name = info.fileName().toUtf8();
    QString currentPath = QDir::toNativeSeparators(info.absoluteFilePath());
    MegaNode *dupplicate = NULL;
    for (int i = 0; i < children->size(); i++)
    {
        MegaNode *child = children->get(i);
        if (!strcmp(utf8name.constData(), child->getName())
                && ((info.isDir() && (child->getType() == MegaNode::TYPE_FOLDER))
                    || (info.isFile() && (child->getType() == MegaNode::TYPE_FILE)
                        && (info.size() == child->getSize()))))
        {
            dupplicate = child->copy();
            break;
        }
    }
    delete children;

    if (dupplicate)
    {
        if (dupplicate->getType() == MegaNode::TYPE_FILE)
        {
            emit dupplicateUpload(info.absoluteFilePath(), info.fileName(), dupplicate->getHandle());
        }

        if (dupplicate->getType() == MegaNode::TYPE_FOLDER)
        {
            QDir dir(info.absoluteFilePath());
            QFileInfoList entries = dir.entryInfoList(QDir::AllEntries | QDir::NoDotAndDotDot);
            for (int i = 0; i < entries.size(); i++)
            {
                upload(entries[i], dupplicate);
            }
        }
        delete dupplicate;
        return;
    }

    string localPath = megaApi->getLocalPath(parent);
    if (localPath.size() && megaApi->isSyncable(info.fileName().toUtf8().constData()))
    {
#ifdef WIN32
        QString destPath = QDir::toNativeSeparators(QString::fromWCharArray((const wchar_t *)localPath.data()) + QDir::separator() + info.fileName());
        if (destPath.startsWith(QString::fromAscii("\\\\?\\")))
        {
            destPath = destPath.mid(4);
        }
#else
        QString destPath = QDir::toNativeSeparators(QString::fromUtf8(localPath.data()) + QDir::separator() + info.fileName());
#endif
        megaApi->moveToLocalDebris(destPath.toUtf8().constData());
        QtConcurrent::run(Utilities::copyRecursively, currentPath, destPath);
    }
    else if (info.isFile())
    {
        megaApi->startUpload(currentPath.toUtf8().constData(), parent);
    }
    else if (info.isDir())
    {
        folders.enqueue(info);
        megaApi->createFolder(info.fileName().toUtf8().constData(), parent, delegateListener);
    }
}