void UploadToMegaDialog::on_bOK_clicked() { MegaNode *node = megaApi->getNodeByPath(ui->eFolderPath->text().toUtf8().constData()); if (node && node->isFolder()) { selectedHandle = node->getHandle(); delete node; accept(); return; } delete node; if (!ui->eFolderPath->text().compare(QString::fromUtf8("/MEGAsync Uploads"))) { ui->bChange->setEnabled(false); ui->bOK->setEnabled(false); MegaNode *rootNode = megaApi->getRootNode(); if (!rootNode) { return; } megaApi->createFolder(tr("MEGAsync Uploads").toUtf8().constData(), rootNode, delegateListener); delete rootNode; return; } MegaApi::log(MegaApi::LOG_LEVEL_ERROR, QString::fromUtf8("Folder not found: %1").arg(ui->eFolderPath->text()).toUtf8().constData()); ui->eFolderPath->setText(QString::fromUtf8("/MEGAsync Uploads")); return; }
static int MEGAunlink(const char *p) { string path = megaBasePath + p; MegaApi::log(MegaApi::LOG_LEVEL_DEBUG, "Deleting file:"); MegaApi::log(MegaApi::LOG_LEVEL_DEBUG, path.c_str()); MegaNode *n = megaApi->getNodeByPath(path.c_str()); if (!n) { MegaApi::log(MegaApi::LOG_LEVEL_WARNING, "File not found"); return -ENOENT; } if (!n->isFile()) { delete n; MegaApi::log(MegaApi::LOG_LEVEL_WARNING, "The path isn't a file"); return -EISDIR; } SynchronousRequestListenerFuse listener; megaApi->remove(n, &listener); listener.wait(); delete n; if (listener.getError()->getErrorCode() != MegaError::API_OK) { MegaApi::log(MegaApi::LOG_LEVEL_ERROR, "Error deleting file"); return -EIO; } MegaApi::log(MegaApi::LOG_LEVEL_DEBUG, "File deleted OK"); return 0; }
static int MEGAreaddir(const char *p, void *buf, fuse_fill_dir_t filler, off_t offset, struct fuse_file_info *fi) { string path = megaBasePath + p; MegaApi::log(MegaApi::LOG_LEVEL_DEBUG, "Listing folder:"); MegaApi::log(MegaApi::LOG_LEVEL_DEBUG, path.c_str()); MegaNode *node = megaApi->getNodeByPath(path.c_str()); if (!node) { MegaApi::log(MegaApi::LOG_LEVEL_DEBUG, "Folder not found"); return -ENOENT; } filler(buf, ".", NULL, 0); filler(buf, "..", NULL, 0); MegaNodeList *children = megaApi->getChildren(node); for (int i=0; i<children->size(); i++) { MegaNode *n = children->get(i); filler(buf, n->getName(), NULL, 0); MegaApi::log(MegaApi::LOG_LEVEL_DEBUG, n->getName()); } delete node; delete children; MegaApi::log(MegaApi::LOG_LEVEL_DEBUG, "Folder listed OK"); return 0; }
void SdkTest::purgeTree(MegaNode *p) { MegaNodeList *children; children = megaApi->getChildren(p); for (int i = 0; i < children->size(); i++) { MegaNode *n = children->get(i); if (n->isFolder()) purgeTree(n); megaApi->remove(n); } }
void NodeSelector::on_bOk_clicked() { MegaNode *node = megaApi->getNodeByHandle(selectedFolder); if (!node) { reject(); return; } int access = megaApi->getAccess(node); if ((selectMode == NodeSelector::UPLOAD_SELECT) && ((access < MegaShare::ACCESS_READWRITE))) { QMessageBox::warning(this, tr("Error"), tr("You need Read & Write or Full access rights to be able to upload to the selected folder."), QMessageBox::Ok); delete node; return; } else if ((selectMode == NodeSelector::SYNC_SELECT) && (access < MegaShare::ACCESS_FULL)) { QMessageBox::warning(this, tr("Error"), tr("You need Full access right to be able to sync the selected folder."), QMessageBox::Ok); delete node; return; } else if ((selectMode == NodeSelector::STREAM_SELECT) && node->isFolder()) { QMessageBox::warning(this, tr("Error"), tr("Only files can be used for streaming."), QMessageBox::Ok); delete node; return; } if (selectMode == NodeSelector::SYNC_SELECT) { const char* path = megaApi->getNodePath(node); MegaNode *check = megaApi->getNodeByPath(path); delete [] path; if (!check) { QMessageBox::warning(this, tr("Warning"), tr("Invalid folder for synchronization.\n" "Please, ensure that you don't use characters like '\\' '/' or ':' in your folder names."), QMessageBox::Ok); delete node; return; } delete check; } delete node; accept(); }
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; }
static int MEGAmkdir(const char *p, mode_t mode) { string path = megaBasePath + p; MegaApi::log(MegaApi::LOG_LEVEL_DEBUG, "Creating folder:"); MegaApi::log(MegaApi::LOG_LEVEL_DEBUG, path.c_str()); MegaNode *n = megaApi->getNodeByPath(path.c_str()); if (n) { MegaApi::log(MegaApi::LOG_LEVEL_WARNING, "Path already exists"); delete n; return -EEXIST; } string spath = path; size_t index = spath.find_last_of('/'); if (index == string::npos) { MegaApi::log(MegaApi::LOG_LEVEL_ERROR, "Invalid path"); return -ENOENT; } spath.resize(index + 1); n = megaApi->getNodeByPath(spath.c_str()); if (!n || n->isFile()) { MegaApi::log(MegaApi::LOG_LEVEL_WARNING, "Parent folder not found"); delete n; return -ENOTDIR; } SynchronousRequestListenerFuse listener; megaApi->createFolder(path.c_str() + index + 1, n, &listener); listener.wait(); delete n; if (listener.getError()->getErrorCode() != MegaError::API_OK) { MegaApi::log(MegaApi::LOG_LEVEL_ERROR, "Error creating folder"); return -EIO; } MegaApi::log(MegaApi::LOG_LEVEL_DEBUG, "Folder created OK"); return 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; }
virtual void onRequestFinish(MegaApi* api, MegaRequest *request, MegaError* e) { if(e->getErrorCode() != MegaError::API_OK) { finished = true; return; } switch(request->getType()) { case MegaRequest::TYPE_LOGIN: { api->fetchNodes(); break; } case MegaRequest::TYPE_FETCH_NODES: { cout << "***** Showing files/folders in the root folder:" << endl; MegaNode *root = api->getRootNode(); MegaNodeList *list = api->getChildren(root); for(int i=0; i < list->size(); i++) { MegaNode *node = list->get(i); if(node->isFile()) cout << "***** File: "; else cout << "***** Folder: "; cout << node->getName() << endl; } cout << "***** Done" << endl; delete list; cout << "***** Uploading the image MEGA.png" << endl; api->startUpload("MEGA.png", root); delete root; break; } default: break; } }
void NodeSelector::onRequestFinish(MegaApi *, MegaRequest *request, MegaError *e) { ui->bNewFolder->setEnabled(true); ui->bOk->setEnabled(true); if (e->getErrorCode() != MegaError::API_OK) { QMessageBox::critical(this, QString::fromUtf8("MEGAsync"), tr("Error") + QString::fromUtf8(": ") + QCoreApplication::translate("MegaError", e->getErrorString())); ui->tMegaFolders->setEnabled(true); return; } if(request->getType() == MegaRequest::TYPE_CREATE_FOLDER) { if (e->getErrorCode() == MegaError::API_OK) { MegaNode *node = megaApi->getNodeByHandle(request->getNodeHandle()); if (node) { QModelIndex row = model->insertNode(node, selectedItem); setSelectedFolderHandle(node->getHandle()); ui->tMegaFolders->selectionModel()->select(row, QItemSelectionModel::ClearAndSelect); ui->tMegaFolders->selectionModel()->setCurrentIndex(row, QItemSelectionModel::ClearAndSelect); } } else { QMessageBox::critical(this, QString::fromUtf8("MEGAsync"), tr("Error") + QString::fromUtf8(": ") + QCoreApplication::translate("MegaError", e->getErrorString())); } } else if (request->getType() == MegaRequest::TYPE_REMOVE || request->getType() == MegaRequest::TYPE_MOVE) { if (e->getErrorCode() == MegaError::API_OK) { MegaNode *parent = model->getNode(selectedItem.parent()); if (parent) { model->removeNode(selectedItem); setSelectedFolderHandle(parent->getHandle()); } } } ui->tMegaFolders->setEnabled(true); }
void UploadToMegaDialog::onRequestFinish(MegaApi *, MegaRequest *request, MegaError *e) { ui->bChange->setEnabled(true); ui->bOK->setEnabled(true); MegaNode *node = megaApi->getNodeByHandle(request->getNodeHandle()); if (e->getErrorCode() != MegaError::API_OK || !node) { MegaApi::log(MegaApi::LOG_LEVEL_ERROR, QString::fromAscii("Request error: %1") .arg(QCoreApplication::translate("MegaError", e->getErrorString())).toUtf8().constData()); this->reject(); delete node; return; } selectedHandle = node->getHandle(); delete node; accept(); }
static int MEGArmdir(const char *p) { string path = megaBasePath + p; MegaApi::log(MegaApi::LOG_LEVEL_DEBUG, "Deleting folder:"); MegaApi::log(MegaApi::LOG_LEVEL_DEBUG, path.c_str()); MegaNode *n = megaApi->getNodeByPath(path.c_str()); if (!n) { MegaApi::log(MegaApi::LOG_LEVEL_WARNING, "Folder not found"); return -ENOENT; } if (n->isFile()) { delete n; MegaApi::log(MegaApi::LOG_LEVEL_WARNING, "The path isn't a folder"); return -ENOTDIR; } if (megaApi->getNumChildren(n)) { delete n; MegaApi::log(MegaApi::LOG_LEVEL_WARNING, "Folder not empty"); return -ENOTEMPTY; } SynchronousRequestListenerFuse listener; megaApi->remove(n, &listener); listener.wait(); delete n; if (listener.getError()->getErrorCode() != MegaError::API_OK) { MegaApi::log(MegaApi::LOG_LEVEL_ERROR, "Error deleting folder"); return -EIO; } MegaApi::log(MegaApi::LOG_LEVEL_DEBUG, "Folder deleted OK"); return 0; }
void NodeSelector::onSelectionChanged(QItemSelection, QItemSelection) { if (ui->tMegaFolders->selectionModel()->selectedIndexes().size()) { selectedItem = ui->tMegaFolders->selectionModel()->selectedIndexes().at(0); MegaNode *node = model->getNode(selectedItem); if (node) { selectedFolder = node->getHandle(); } else { selectedFolder = mega::INVALID_HANDLE; } } else { selectedItem = QModelIndex(); selectedFolder = mega::INVALID_HANDLE; } }
void UploadToMegaDialog::on_bChange_clicked() { QPointer<NodeSelector> nodeSelector = new NodeSelector(megaApi, NodeSelector::UPLOAD_SELECT, this); MegaNode *defaultNode = megaApi->getNodeByPath(ui->eFolderPath->text().toUtf8().constData()); if (defaultNode) { nodeSelector->setSelectedFolderHandle(defaultNode->getHandle()); delete defaultNode; } int result = nodeSelector->exec(); if (!nodeSelector || result != QDialog::Accepted) { delete nodeSelector; return; } MegaHandle selectedMegaFolderHandle = nodeSelector->getSelectedFolderHandle(); MegaNode *node = megaApi->getNodeByHandle(selectedMegaFolderHandle); if (!node) { delete nodeSelector; return; } const char *nPath = megaApi->getNodePath(node); if (!nPath) { delete nodeSelector; delete node; return; } ui->eFolderPath->setText(QString::fromUtf8(nPath)); delete nodeSelector; delete [] nPath; delete node; }
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(); }
void NodeSelector::onDeleteClicked() { MegaNode *node = megaApi->getNodeByHandle(selectedFolder); int access = megaApi->getAccess(node); if(!node || access < MegaShare::ACCESS_FULL) { delete node; return; } if(QMessageBox::question(this, QString::fromUtf8("MEGAsync"), tr("Are you sure that you want to delete \"%1\"?") .arg(QString::fromUtf8(node->getName())), QMessageBox::Yes | QMessageBox::No, QMessageBox::No) == QMessageBox::Yes) { ui->tMegaFolders->setEnabled(false); ui->bNewFolder->setEnabled(false); ui->bOk->setEnabled(false); const char *name = node->getName(); if (access == MegaShare::ACCESS_FULL || !strcmp(name, "NO_KEY") || !strcmp(name, "CRYPTO_ERROR") || !strcmp(name, "BLANK")) { megaApi->remove(node, delegateListener); } else { MegaNode *rubbish = megaApi->getRubbishNode(); megaApi->moveNode(node, rubbish, delegateListener); delete rubbish; } } delete node; }
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; }
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); } }
void NodeSelector::setSelectedFolderHandle(long long selectedHandle) { MegaNode *node = megaApi->getNodeByHandle(selectedHandle); if (!node) { return; } QList<MegaNode *> list; while (node) { list.append(node); node = megaApi->getParentNode(node); } if (!list.size()) { return; } int index = list.size() - 1; QModelIndex modelIndex; QModelIndex parentModelIndex; node = list.at(index); for (int i = 0; i < model->rowCount(); i++) { QModelIndex tmp = model->index(i, 0); MegaNode *n = model->getNode(tmp); if (n && n->getHandle() == node->getHandle()) { node = NULL; parentModelIndex = modelIndex; modelIndex = tmp; index--; ui->tMegaFolders->expand(parentModelIndex); break; } } if (node) { for (int k = 0; k < list.size(); k++) { delete list.at(k); } ui->tMegaFolders->collapseAll(); return; } while (index >= 0) { node = list.at(index); for (int j = 0; j < model->rowCount(modelIndex); j++) { QModelIndex tmp = model->index(j, 0, modelIndex); MegaNode *n = model->getNode(tmp); if (n && n->getHandle() == node->getHandle()) { node = NULL; parentModelIndex = modelIndex; modelIndex = tmp; index--; ui->tMegaFolders->expand(parentModelIndex); break; } } if (node) { for (int k = 0; k < list.size(); k++) { delete list.at(k); } ui->tMegaFolders->collapseAll(); return; } } for (int k = 0; k < list.size(); k++) { delete list.at(k); } ui->tMegaFolders->selectionModel()->setCurrentIndex(modelIndex, QItemSelectionModel::ClearAndSelect); ui->tMegaFolders->selectionModel()->select(modelIndex, QItemSelectionModel::ClearAndSelect); }
/** * @brief TEST_F SdkTestShares * * Initialize a test scenario by: * * - Creating/uploading some folders/files to share * - Creating a new contact to share to * * Performs different operations related to sharing: * * - Share a folder with an existing contact * - Check the correctness of the outgoing share * - Check the reception and correctness of the incoming share * - Modify the access level * - Revoke the access to the share * - Share a folder with a non registered email * - Check the correctness of the pending outgoing share * - Create a public link * - Import a public link * - Get a node from public link * - Remove a public link */ TEST_F(SdkTest, SdkTestShares) { MegaShareList *sl; MegaShare *s; MegaNodeList *nl; MegaNode *n; MegaNode *n1; getMegaApiAux(); // login + fetchnodes // Initialize a test scenario : create some folders/files to share // Create some nodes to share // |--Shared-folder // |--subfolder // |--file.txt MegaNode *rootnode = megaApi->getRootNode(); char foldername1[64] = "Shared-folder"; MegaHandle hfolder1; responseReceived = false; megaApi->createFolder(foldername1, rootnode); waitForResponse(&responseReceived); ASSERT_EQ(MegaError::API_OK, lastError) << "Cannot create a folder (error: " << lastError << ")"; hfolder1 = h; // 'h' is set in 'onRequestFinish()' n1 = megaApi->getNodeByHandle(hfolder1); char foldername2[64] = "subfolder"; MegaHandle hfolder2; responseReceived = false; megaApi->createFolder(foldername2, megaApi->getNodeByHandle(hfolder1)); waitForResponse(&responseReceived); ASSERT_EQ(MegaError::API_OK, lastError) << "Cannot create a folder (error: " << lastError << ")"; hfolder2 = h; MegaHandle hfile1; createFile(PUBLICFILE.data(), false); // not a large file since don't need to test transfers here uploadFinished = false; megaApi->startUpload(PUBLICFILE.data(), megaApi->getNodeByHandle(hfolder1)); waitForResponse(&uploadFinished); ASSERT_EQ(MegaError::API_OK, lastError) << "Cannot upload file (error: " << lastError << ")"; hfile1 = h; // Initialize a test scenario: create a new contact to share to string message = "Hi contact. Let's share some stuff"; contactRequestUpdated = false; contactRequestUpdatedAux = false; ASSERT_NO_FATAL_FAILURE( inviteContact(emailaux, message, MegaContactRequest::INVITE_ACTION_ADD) ); waitForResponse(&contactRequestUpdatedAux); // at the target side (auxiliar account) waitForResponse(&contactRequestUpdated); // at the source side (main account) MegaContactRequestList *crlaux = megaApiAux->getIncomingContactRequests(); ASSERT_EQ(1, crlaux->size()) << "Too many incoming contact requests in auxiliar account"; MegaContactRequest *craux = crlaux->get(0); contactRequestUpdated = false; contactRequestUpdatedAux = false; ASSERT_NO_FATAL_FAILURE( replyContact(craux, MegaContactRequest::REPLY_ACTION_ACCEPT) ); waitForResponse(&contactRequestUpdatedAux); // at the target side (auxiliar account) waitForResponse(&contactRequestUpdated); // at the source side (main account) delete crlaux; // --- Create a new outgoing share --- nodeUpdated = false; nodeUpdatedAux = false; ASSERT_NO_FATAL_FAILURE( shareFolder(n1, emailaux.data(), MegaShare::ACCESS_READ) ); waitForResponse(&nodeUpdated); waitForResponse(&nodeUpdatedAux); // --- Check the outgoing share --- sl = megaApi->getOutShares(); ASSERT_EQ(1, sl->size()) << "Outgoing share failed"; s = sl->get(0); ASSERT_EQ(MegaShare::ACCESS_READ, s->getAccess()) << "Wrong access level of outgoing share"; ASSERT_EQ(hfolder1, s->getNodeHandle()) << "Wrong node handle of outgoing share"; ASSERT_STREQ(emailaux.data(), s->getUser()) << "Wrong email address of outgoing share"; ASSERT_TRUE(megaApi->isShared(n1)) << "Wrong sharing information at outgoing share"; ASSERT_TRUE(megaApi->isOutShare(n1)) << "Wrong sharing information at outgoing share"; delete sl; // --- Check the incoming share --- nl = megaApiAux->getInShares(megaApiAux->getContact(email.data())); ASSERT_EQ(1, nl->size()) << "Incoming share not received in auxiliar account"; n = nl->get(0); ASSERT_EQ(hfolder1, n->getHandle()) << "Wrong node handle of incoming share"; ASSERT_STREQ(foldername1, n->getName()) << "Wrong folder name of incoming share"; ASSERT_EQ(MegaError::API_OK, megaApiAux->checkAccess(n, MegaShare::ACCESS_READ).getErrorCode()) << "Wrong access level of incoming share"; ASSERT_TRUE(megaApiAux->isInShare(n)) << "Wrong sharing information at incoming share"; ASSERT_TRUE(megaApiAux->isShared(n)) << "Wrong sharing information at incoming share"; delete nl; // --- Modify the access level of an outgoing share --- nodeUpdated = false; nodeUpdatedAux = false; ASSERT_NO_FATAL_FAILURE( shareFolder(megaApi->getNodeByHandle(hfolder1), emailaux.data(), MegaShare::ACCESS_READWRITE) ); waitForResponse(&nodeUpdated); waitForResponse(&nodeUpdatedAux); nl = megaApiAux->getInShares(megaApiAux->getContact(email.data())); ASSERT_EQ(1, nl->size()) << "Incoming share not received in auxiliar account"; n = nl->get(0); ASSERT_EQ(MegaError::API_OK, megaApiAux->checkAccess(n, MegaShare::ACCESS_READWRITE).getErrorCode()) << "Wrong access level of incoming share"; delete nl; // --- Revoke access to an outgoing share --- nodeUpdated = false; nodeUpdatedAux = false; ASSERT_NO_FATAL_FAILURE( shareFolder(n1, emailaux.data(), MegaShare::ACCESS_UNKNOWN) ); waitForResponse(&nodeUpdated); waitForResponse(&nodeUpdatedAux); sl = megaApi->getOutShares(); ASSERT_EQ(0, sl->size()) << "Outgoing share revocation failed"; delete sl; nl = megaApiAux->getInShares(megaApiAux->getContact(email.data())); ASSERT_EQ(0, nl->size()) << "Incoming share revocation failed"; delete nl; // --- Get pending outgoing shares --- char emailfake[64]; srand (time(NULL)); sprintf(emailfake, "*****@*****.**", rand()%1000000); // carefull, antispam rejects too many tries without response for the same address n = megaApi->getNodeByHandle(hfolder2); nodeUpdated = false; ASSERT_NO_FATAL_FAILURE( shareFolder(n, emailfake, MegaShare::ACCESS_FULL) ); waitForResponse(&nodeUpdated); sl = megaApi->getPendingOutShares(n); delete n; ASSERT_EQ(1, sl->size()) << "Pending outgoing share failed"; s = sl->get(0); n = megaApi->getNodeByHandle(s->getNodeHandle()); // ASSERT_STREQ(emailfake, s->getUser()) << "Wrong email address of outgoing share"; User is not created yet ASSERT_FALSE(megaApi->isShared(n)) << "Node is already shared, must be pending"; ASSERT_FALSE(megaApi->isOutShare(n)) << "Node is already shared, must be pending"; delete sl; delete n; // --- Create a public link --- MegaNode *nfile1 = megaApi->getNodeByHandle(hfile1); ASSERT_NO_FATAL_FAILURE( createPublicLink(nfile1) ); // The created link is stored in this->link at onRequestFinish() // --- Import a public link --- ASSERT_NO_FATAL_FAILURE( importPublicLink(link, rootnode) ); MegaNode *nimported = megaApi->getNodeByHandle(h); ASSERT_STREQ(nfile1->getName(), nimported->getName()) << "Imported file with wrong name"; ASSERT_EQ(rootnode->getHandle(), nimported->getParentHandle()) << "Imported file in wrong path"; // --- Get node from public link --- ASSERT_NO_FATAL_FAILURE( getPublicNode(link) ); ASSERT_TRUE(publicNode->isPublic()) << "Cannot get a node from public link"; // --- Remove a public link --- ASSERT_NO_FATAL_FAILURE( removePublicLink(nfile1) ); delete nfile1; nfile1 = megaApi->getNodeByHandle(h); ASSERT_FALSE(nfile1->isPublic()) << "Public link removal failed (still public)"; delete nimported; }
void NodeSelector::on_bNewFolder_clicked() { QPointer<QInputDialog> id = new QInputDialog(this); id->setWindowTitle(tr("New folder")); id->setLabelText(tr("Enter the new folder name:")); int result = id->exec(); if (!id || !result) { delete id; return; } QString text = id->textValue(); text = text.trimmed(); if (!text.isEmpty()) { MegaNode *parent = megaApi->getNodeByHandle(selectedFolder); if (!parent) { parent = megaApi->getRootNode(); if (!parent) { delete id; return; } selectedFolder = parent->getHandle(); selectedItem = QModelIndex(); } MegaNode *node = megaApi->getNodeByPath(text.toUtf8().constData(), parent); if (!node || node->isFile()) { ui->bNewFolder->setEnabled(false); ui->bOk->setEnabled(false); ui->tMegaFolders->setEnabled(false); megaApi->createFolder(text.toUtf8().constData(), parent, delegateListener); } else { for (int i = 0; i < model->rowCount(selectedItem); i++) { QModelIndex row = model->index(i, 0, selectedItem); MegaNode *node = model->getNode(row); if (node && text.compare(QString::fromUtf8(node->getName())) == 0) { setSelectedFolderHandle(node->getHandle()); ui->tMegaFolders->selectionModel()->select(row, QItemSelectionModel::ClearAndSelect); ui->tMegaFolders->selectionModel()->setCurrentIndex(row, QItemSelectionModel::ClearAndSelect); break; } } } delete parent; delete node; } else { QMessageBox::critical(this, QString::fromUtf8("MEGAsync"), tr("Please enter a valid folder name")); } delete id; }
static int MEGArename(const char *f, const char *t) { string from = megaBasePath + f; string to = megaBasePath + t; MegaApi::log(MegaApi::LOG_LEVEL_DEBUG, "Renaming/moving file/folder"); MegaApi::log(MegaApi::LOG_LEVEL_DEBUG, from.c_str()); MegaApi::log(MegaApi::LOG_LEVEL_DEBUG, to.c_str()); MegaNode *source = megaApi->getNodeByPath(from.c_str()); if (!source) { MegaApi::log(MegaApi::LOG_LEVEL_WARNING, "Source not found"); return -ENOENT; } MegaNode *dest = megaApi->getNodeByPath(to.c_str()); if (dest) { if (dest->isFile()) { delete source; delete dest; MegaApi::log(MegaApi::LOG_LEVEL_WARNING, "The destination is an existing file"); return -ENOTDIR; } else { SynchronousRequestListenerFuse listener; megaApi->moveNode(source, dest, &listener); listener.wait(); delete source; delete dest; if (listener.getError()->getErrorCode() != MegaError::API_OK) { MegaApi::log(MegaApi::LOG_LEVEL_ERROR, "Error moving file/folder"); return -EIO; } MegaApi::log(MegaApi::LOG_LEVEL_DEBUG, "File/folder moved OK"); return 0; } } string destpath = to; size_t index = destpath.find_last_of('/'); if (index == string::npos) { delete source; MegaApi::log(MegaApi::LOG_LEVEL_ERROR, "Invalid path"); return -ENOENT; } string destname = destpath.c_str() + index + 1; destpath.resize(index + 1); dest = megaApi->getNodeByPath(destpath.c_str()); if (!dest) { delete source; MegaApi::log(MegaApi::LOG_LEVEL_WARNING, "Destination folder not found"); return -ENOENT; } if (dest->isFile()) { delete source; delete dest; MegaApi::log(MegaApi::LOG_LEVEL_WARNING, "The destination folder is a file"); return -ENOTDIR; } MegaNode *n = megaApi->getChildNode(dest, destname.c_str()); if(n) { delete n; delete source; delete dest; MegaApi::log(MegaApi::LOG_LEVEL_WARNING, "The destination path already exists"); return -EEXIST; } SynchronousRequestListenerFuse listener; megaApi->moveNode(source, dest, &listener); listener.wait(); delete dest; if (listener.getError()->getErrorCode() != MegaError::API_OK) { delete source; MegaApi::log(MegaApi::LOG_LEVEL_ERROR, "Error moving file/folder"); return -EIO; } MegaApi::log(MegaApi::LOG_LEVEL_DEBUG, "File/folder moved OK"); if (strcmp(source->getName(), destname.c_str())) { listener.reset(); megaApi->renameNode(source, destname.c_str(), &listener); listener.wait(); if(listener.getError()->getErrorCode() != MegaError::API_OK) { delete source; MegaApi::log(MegaApi::LOG_LEVEL_ERROR, "Error renaming file/folder"); return -EIO; } MegaApi::log(MegaApi::LOG_LEVEL_DEBUG, "File/folder renamed OK"); } delete source; return 0; }