Esempio n. 1
0
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;
}
Esempio n. 2
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. 3
0
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;
}
Esempio n. 4
0
File: main.cpp Progetto: tagyro/sdk
	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;
		}
	}
Esempio n. 5
0
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;
}
Esempio n. 6
0
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;	
}
Esempio n. 7
0
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;
}