Пример #1
0
int LocalPackage::get_xml()
{
	legacyPackage=false;
	_parseOk=false;
	//mDebug("get_xml start");
	string tmp_xml=get_tmp_file();
	//mDebug("Extracting XML");
	extractFromTgz(filename, "install/data.xml", tmp_xml);

	if (!FileNotEmpty(tmp_xml))
	{
		//mDebug("XML empty, parsing as legacy");
		say(_("%s: No XML, converting from legacy\n"), filename.c_str());
		legacyPackage=true;
		
		FILE *legacy = fopen("/var/log/mpkg-legacy.log", "a");
		if (legacy)
		{
			fprintf(legacy, "%s\n", filename.c_str());
			fclose(legacy);
		}
		// In most cases it means that we have legacy Slackware package.
		// Trying to convert:
		//mDebug("Converting from legacy to XML");
		if (slack2xml(filename, tmp_xml) != 0)
		{
			mError("Infernally invalid package! Cannot work with it at all");
			unlink(tmp_xml.c_str());
			delete_tmp_files();
			return -1;
		}
		//mDebug("Converted");
	}
	//mDebug("Parsing XML");
	PackageConfig p(tmp_xml);
	unlink(tmp_xml.c_str());
	if (!p.parseOk)
	{
		//mDebug("Error parsing XML");
		delete_tmp_files();
		return -100;
	}

	int bufsize;
	xmlChar * membuff = p.getXMLNodeXPtr(&bufsize);
	__doc = xmlParseMemory((const char *) membuff, bufsize);
	xmlFree(membuff);
	_packageXMLNode = xmlDocGetRootElement(__doc);

	xml2package(p.getXMLDoc(), p.getXMLNode(), &data);
	//mDebug("get_xml end");
	delete_tmp_files();
	_parseOk=true;
	return 0;
}
Пример #2
0
/**
 * \brief Callback when the menu item is clicked.
 */
static void item_activate(GtkMenuItem *menuitem, gpointer gdata)
{
    GeanyDocument   *doc = document_get_current();
    ScintillaObject *sci = doc->editor->sci ;
    if ( gms_hnd  == NULL )
        return ;

    if ( gms_dlg( gms_hnd ) == 0 )
        return ;

    gms_create_filter_file( gms_hnd ) ;

    switch ( gms_get_input_mode(gms_hnd) )
    {
        case IN_CURRENT_DOC :
            select_entirely_doc(  sci  ) ;
            create_selection_2_input_file(sci) ;
            run_filter( sci ) ;
            delete_tmp_files() ;
            break;
        case IN_SELECTION :
            create_selection_2_input_file(sci) ;
            run_filter( sci ) ;
            delete_tmp_files() ;
            break;
        case IN_DOCS_SESSION :
            {
                guint nb_doc = 0  , i=0;

				/* find the opened document in the geany session */
                while ( (doc = document_get_from_page(nb_doc))!=NULL ) nb_doc++;

                /* For each document */
                for( i=0; i<nb_doc;i++)
                {
                    doc = document_get_from_page(i) ;
                    sci = doc->editor->sci ;
                    select_entirely_doc(  sci  ) ;
                    create_selection_2_input_file(sci) ;
                    if ( run_filter( sci ) )
						break ; /* if error then stop the loop */
                }
            }
            delete_tmp_files() ;
            break;
        default:
            delete_tmp_files() ;
            return ;
    }

}
Пример #3
0
int convert_package(const string& filename, const string& output_dir)
{
//	char tmp[1000];
	say("converting package %s\n", filename.c_str());
	int name_start=0;
	for (int i=filename.length()-1; filename[i]!='/' && i>=0; i--)
	{
		name_start=i;
	}
	string real_filename;
	for (unsigned int i=name_start; i<filename.length(); i++)
	{
		real_filename+=filename[i];
	}
	string ext_outdir = filename.substr(0,filename.find_last_of("/"));
	string tmp_dir=get_tmp_file();
	string xml_output=tmp_dir+"/install/data.xml";
	string reasm="rm "+tmp_dir+" && mkdir -p "+tmp_dir+"/install >/dev/null && cp "+filename+" "+tmp_dir+"/ && cd "+tmp_dir+" &&  tar xf "+real_filename+" > /dev/null";
	system(reasm.c_str());	
	slack_convert(filename, xml_output);
	system("mkdir -p " + output_dir+"/"+ext_outdir);
	reasm="cd "+tmp_dir+" && rm "+real_filename+" && " + MAKEPKG_CMD +" "+output_dir+"/"+ext_outdir + "/" + real_filename+" 2>/dev/null >/dev/null && rm -rf "+tmp_dir;

	int ret = system(reasm.c_str());
	if (ret) say("An error occured while converting package %s\n", filename.c_str());
	else say("%s: OK\n", filename.c_str());
	delete_tmp_files();
	return 0;
}
Пример #4
0
static rc_t merge_pool_files( const sorter_params * params )
{
    rc_t rc;
    merge_sorter_params msp;
    struct merge_sorter * ms;
    
    msp.dir = params->dir;
    msp.output_filename = params->output_filename;
    msp.index_filename = params->index_filename;
    msp.count = params->num_threads;
    msp.buf_size = params->buf_size;

    rc = make_merge_sorter( &ms, &msp );
    if ( rc == 0 )
    {
        uint32_t i;
        for ( i = 0; rc == 0 && i < params->num_threads; ++i )
        {
            char buffer[ 4096 ];
            rc = make_pool_src_filename( params, i + 1, buffer, sizeof buffer );
            if ( rc == 0 )
                rc = add_merge_sorter_src( ms, buffer, i );
        }
        if ( rc == 0 )
            rc = run_merge_sorter( ms );
        
        release_merge_sorter( ms );
    }

    if ( rc == 0 ) 
       rc = delete_tmp_files( params, params->num_threads );

    return rc;
}
Пример #5
0
bool core::archive::image_cache::update_file_from_tmp_files()
{
    const bool to_add_exists = tools::system::is_exist(tmp_to_add_storage_->get_file_name());
    if (to_add_exists)
    {
        images_map_t to_add;
        if (!read_file(*tmp_to_add_storage_, to_add))
            return false;

        add_images_to_tree(to_add);

        if (!append_to_file(*storage_, to_add))
            return false;
    }

    const bool to_delete_exists = tools::system::is_exist(tmp_to_delete_storage_->get_file_name());
    if (to_delete_exists)
    {
        bool need_to_save_all = false;
        if (!process_deleted(need_to_save_all))
            return false;

        if (need_to_save_all && !save_all())
            return false;
    }

    delete_tmp_files();

    return true;
}
Пример #6
0
mpkg::~mpkg()
{
	if (DepTracker!=NULL) delete DepTracker;
	if (db!=NULL) delete db;
	delete_tmp_files();
	mpkgSys::clean_cache(true);

}
Пример #7
0
int LocalPackage::fill_filelist(PACKAGE *package, bool)
{
	if (!package) package=&data;
	//mDebug("fill_filelist start");
	// Retrieving regular files
	// For setup mode, we can try to enable cached filelists
	vector<string> file_names;
	string fname;
	bool fname_temp = false;
	if (setupMode && FileExists(getAbsolutePath(getDirectory(filename))+"/.fcache/" + getFilename(filename) + "/flist")) {
		fname = getAbsolutePath(getDirectory(filename))+"/.fcache/" + getFilename(filename) + "/flist";
	}
	else {
		fname = get_tmp_file();
		fname_temp = true;
		system("tar tf "+filename+" --exclude install " +" > "+fname + " 2>/dev/null");
	}
	// Parsing file list
	file_names=ReadFileStrings(fname);
	if (fname_temp) unlink(fname.c_str());
	if (file_names.size()>2) file_names.erase(file_names.begin(), file_names.begin()+2);
	else {
		mWarning("Empty file list in package " + package->get_name());
		file_names.clear();
	}
	package->set_files(file_names);
	// Retrieving symlinks (from doinst.sh).
	string dt;
	bool dt_temp=false;
	// Extracting file to the temp dir
	if (setupMode && FileExists(getAbsolutePath(getDirectory(filename))+"/.fcache/" + getFilename(filename) + "/doinst.sh")) {
		dt = getAbsolutePath(getDirectory(filename))+"/.fcache/" + getFilename(filename) + "/doinst.sh";
	}
	else if (!setupMode || !FileExists(getAbsolutePath(getDirectory(filename))+"/.fcache/" + getFilename(filename) + "/flist")) { // Assuming that doinst.sh isn't present if flist is cached
		dt = get_tmp_file();
		extractFromTgz(filename, "install/doinst.sh", dt);
		dt_temp = true;
	}

	
	if (!dt.empty() && FileExists(dt)) {
		string lnfname=get_tmp_file();
		string sed_cmd = "sed -n 's,^( *cd \\([^ ;][^ ;]*\\) *; *rm -rf \\([^ )][^ )]*\\) *) *$,\\1/\\2,p' < ";
		sed_cmd += dt + " > " + lnfname;
		system(sed_cmd);
		vector<string>link_names=ReadFileStrings(lnfname);
		for (size_t i=0; i<link_names.size(); ++i) {
			if (!link_names[i].empty()) package->get_files_ptr()->push_back(link_names[i]);
		}
		if (dt_temp) unlink(dt.c_str());
		unlink(lnfname.c_str());
	}

	delete_tmp_files();
	return 0;
}
Пример #8
0
int LocalPackage::injectFile()
{
	if (!dialogMode && verbose) say(string(_("Injecting file") + filename + "\n").c_str());

	internal=true;
	// Injecting data from file!
	// If any of functions fails (e.g. return!=0) - break process and return failure code (!=0);
	//int ret=0;
	//mDebug("local_package.cpp: injectFile(): start");
	//mDebug("get_xml");
	if (get_xml()!=0)
	{
		//mDebug("local_package.cpp: injectFile(): get_xml FAILED");
		return -3;
	}
	if (getExtension(filename)=="spkg") {
		//printf("Source package detected, adding to XML\n");
		xmlNewTextChild(_packageXMLNode, NULL, (const xmlChar *)"type", (const xmlChar *)"source");
		data.set_type(PKGTYPE_SOURCE);
	}
	if (getExtension(filename)=="tgz" || getExtension(filename) == "txz" || getExtension(filename) == "tlz" ||getExtension(filename) == "tbz" ) {
		xmlNewTextChild(_packageXMLNode, NULL, (const xmlChar *)"type", (const xmlChar *)"binary");
		data.set_type(PKGTYPE_BINARY);
	}

	


	//mDebug("get_size()\n");
	if (get_size()!=0)
	{
		mDebug("local_package.cpp: injectFile(): get_size() FAILED");
		return -1;
	}
	//mDebug("create_md5\n");
	if (create_md5()!=0)
	{
		mDebug("local_package.cpp: injectFile(): create_md5 FAILED");
		return -2;
	}
	//mDebug("set_additional_data\n");
	//mDebug("local_packaige.cpp: injectFile(): filename is "+ filename);
	data.set_filename(filename);
	
	if (set_additional_data()!=0)
	{
		mDebug("local_package.cpp: injectFile(): set_additional_data FAILED");
		return -6;
	}
	delete_tmp_files();	
	//mDebug("local_package.cpp: injectFile(): end");
	return 0;
}
Пример #9
0
bool core::archive::image_cache::build(const contact_archive& _archive)
{
    cancel_build_.clear();

    tree_is_consistent_ = false;
    building_in_progress_ = true;

    image_by_msgid_.clear();

    history_block messages;

    int64_t from = -1;
    while (true)
    {
        if (cancel_build_.test_and_set())
        {
            return false;
        }

        cancel_build_.clear();

        _archive.get_messages(from, fetch_size, -1, messages, contact_archive::get_message_policy::skip_patches_and_deleted);
        if (messages.empty())
        {
            building_in_progress_ = false;
            tree_is_consistent_ = true;

            update_tree_from_tmp_files();

            data_ready_.notify_all();

            if (save_all())
            {
                delete_tmp_files();
                return true;
            }

            return false;
        }

        from = (*messages.begin())->get_msgid();

        const auto images = extract_images(messages);
        if (!images.empty())
        {
            {
                std::lock_guard<std::mutex> lock(mutex_);
                add_images_to_tree(images);
            }
            data_ready_.notify_all();
        }
    }
}
Пример #10
0
int slack_convert(const string& filename, string& xml_output)
{
	mDebug("Preparing to convert " + filename);
	PACKAGE package;
	package.set_filename(filename);
	// Resolving name, version, arch and build
	string tmp;
	string tmp_xml = get_tmp_file();
	extractFromTgz(filename, "install/data.xml", tmp_xml);
	if (FileNotEmpty(tmp_xml))
	{
		WriteFile(xml_output, ReadFile(tmp_xml));
		delete_tmp_files();
		return 0;
	}
	string ptrstr;
	// Guessing type
	string pkgType = getExtension(filename);
	if (pkgType!="tgz" && pkgType!="txz" && pkgType!="tlz" && pkgType!="tbz") {
		mError(_("Unknown package type ") + pkgType);
		return 1;
	}
	// Name-ver-arch-build parsing
	string name_tmp=filename.substr(0,filename.find("." + pkgType));
	name_tmp = name_tmp.substr(name_tmp.find_last_of("/")+1);
	ptrstr = name_tmp.substr(name_tmp.find_last_of("-")+1);
	package.set_build(ptrstr);
	name_tmp = name_tmp.substr(0,name_tmp.find_last_of("-"));
	ptrstr = name_tmp.substr(name_tmp.find_last_of("-")+1);
	package.set_arch(ptrstr);
	name_tmp = name_tmp.substr(0,name_tmp.find_last_of("-"));
	ptrstr=name_tmp.substr(name_tmp.find_last_of("-")+1);
	package.set_version(ptrstr);
	name_tmp = name_tmp.substr(0,name_tmp.find_last_of("-"));
	package.set_name(name_tmp);
	name_tmp.clear();


#define DESCRIPTION_PROCESS
#ifdef DESCRIPTION_PROCESS	
	//DESCRIPTION
	mDebug("Processing description");
	string desc_file= filename.substr(0,filename.length()-3)+"txt";
	bool can_read=false;
#ifdef GET_TXT_DESC
	if (access(desc_file.c_str(), R_OK)==0)
	{
		mDebug("Retrieving from txt");
		can_read=true;
	}
	else 
	{
#endif
		desc_file=get_tmp_file();
		string desc="tar xf "+filename+" install/slack-desc --to-stdout > "+desc_file;
		if (system(desc.c_str())==0)
		{

			mDebug("Retrieving from slack-desc");
			can_read=true;
		}
		else mDebug("Cannot find any description");
#ifdef GET_TXT_DESC
	}
#endif
	if (can_read)
	{
		string description=ReadFile(desc_file);
		delete_tmp_files();
		// Step 1. Skip comments
		unsigned int dpos=0;
		//unsigned int strLen=0;
		string comment;
		string head;
		string short_description;
		//bool str1=true;
		if (!description.empty())
		{
			// Cleaning out comments
			for (unsigned int i=0; i<description.length(); i++)
			{
				if (description[i]=='#')
				{
					while (description[i]!='\n') i++;
				}
				if (i<description.length()) tmp+=description[i];
			}
			description=tmp;
			tmp.clear();
			string pHead=package.get_name()+":";
			int spos=description.find(pHead,0);
			// Removing package: headers
			for (unsigned int i=spos; i<description.length(); i++)
			{
				//head+=description[i];
				if (i==0 || description[i-1]=='\n')
				{
					i=i+package.get_name().length()+1;
					//if (description[i-1]=='\n') i=i+package.get_name().length()+2;
					//head.clear();
				}
				if (i<description.length()) tmp+=description[i];
			}
			description=tmp;
			tmp.clear();
	
			// Splitting short and long descriptions
			for (unsigned int i=0; i<description.length() && description[i]!='\n'; i++)
			{
				tmp+=description[i];
				dpos=i+1;
			}
			short_description=tmp;
			tmp.clear();
			for (unsigned int i=dpos; i<description.length(); i++)
			{
				if (i==dpos && description[i]=='\n')
				{
					while (description[i]=='\n' || description[i]==' ') i++;
					if (i>=description.length()) break;
				}
				if (i<description.length()) tmp+=description[i];
			}
			description=tmp;
			tmp.clear();
			package.set_short_description(short_description);
			package.set_description(description);
			mDebug("Description: " + description);
		}
	}
#endif
	XMLNode pkg=XMLNode::createXMLTopNode("package");
	pkg.addChild("name");
	pkg.getChildNode("name").addText(package.get_name().c_str());
	pkg.addChild("version");
	pkg.getChildNode("version").addText(package.get_version().c_str());
	pkg.addChild("arch");
	pkg.getChildNode("arch").addText(package.get_arch().c_str());
	pkg.addChild("build");
	pkg.getChildNode("build").addText(package.get_build().c_str());
#ifdef DESCRIPTION_PROCESS
	mDebug("Adding description to XML node");
	pkg.addChild("short_description");
	pkg.getChildNode("short_description").addText(package.get_short_description().c_str());
	pkg.addChild("description");
	pkg.getChildNode("description").addText(package.get_description().c_str());
#endif
#ifdef TAG_CONVERTED
	pkg.addChild("tags");
	pkg.getChildNode("tags").addChild("tag");
	pkg.getChildNode("tags").getChildNode("tag").addText("slackware");
#endif
	// Get maintainer name and email
	string mName = mConfig.getValue("maintainer_name");
	string mEmail = mConfig.getValue("maintainer_email");
	if (mName.empty()) mName = "Converted by anonymous maintainer";
	if (mEmail.empty()) mEmail = "No email specified";
	pkg.addChild("maintainer");
	pkg.getChildNode("maintainer").addChild("name");
	pkg.getChildNode("maintainer").getChildNode("name").addText(mName.c_str());
	pkg.getChildNode("maintainer").addChild("email");
	pkg.getChildNode("maintainer").getChildNode("email").addText(mEmail.c_str());
	pkg.writeToFile(xml_output.c_str(), "utf-8");
	return 0;
}
Пример #11
0
void generateDeps(string tgz_filename, bool updateOnly)
{
	if (mConfig.getValue("add_deps_in_build")=="yes") updateOnly=false;
	if (tgz_filename.empty()) {
		mError("No filename specified");
		return;
	}
	say("Generating dependencies for %s\n",tgz_filename.c_str());
	string current_dir = (string) get_current_dir_name();
	// Create a temporary directory
	string tmpdir = get_tmp_file();
	string dep_out = get_tmp_file();
	unlink(tmpdir.c_str());
	system("mkdir -p " + tmpdir);
	say("Extracting\n");
	system("tar zxf " + tgz_filename + " -C " + tmpdir);
	PackageConfig *p = new PackageConfig(tmpdir+"/install/data.xml");
	PACKAGE pkg;
	if (p->parseOk) xml2package(p->getXMLNode(), &pkg);
	delete p;
	say("Building dependencies\n");
	
	system("env LC_ALL=C requiredbuilder -n -v " + tgz_filename + " > "+ dep_out);
	vector<string> data = ReadFileStrings(dep_out);
	
	string tmp;
	string tail;
	DEPENDENCY d;
	//pkg.get_dependencies()->clear();
	string condptr;
	for (unsigned int i=0; i<data.size(); i++)
	{
		tmp = data[i].substr(0,data[i].find_first_of(" "));
		tail = data[i].substr(tmp.length()+1);
		d.set_package_name(&tmp);

		tmp = tail.substr(0, tail.find_first_of(" "));
		tail = tail.substr(tmp.length()+1);
		condptr=IntToStr(condition2int(hcondition2xml(tmp)));
		d.set_condition(&condptr);

		tmp = tail.substr(0,tail.find_first_of("-"));
		d.set_package_version(&tmp);
		if (*d.get_package_name()!=*pkg.get_name()) {
			// Checking existing dependencies
			bool added=false;
			for (unsigned int t=0; t<pkg.get_dependencies()->size(); t++) {
				if (*d.get_package_name()==*pkg.get_dependencies()->at(t).get_package_name()) {
					pkg.get_dependencies()->at(t) = d;
					added=true;
				}
			}
			if (!added) {
				if (updateOnly) mWarning("Found (possible) missing dependencies: " + d.getDepInfo());
				else pkg.get_dependencies()->push_back(d);
			}
		}
	}
	say(_("Got %d dependencies\n"), pkg.get_dependencies()->size());
	p = new PackageConfig(tmpdir+"/install/data.xml");
	dumpPackage(&pkg, p, tmpdir+"/install/data.xml");
	delete p;
	if (tgz_filename[0]!='/') tgz_filename = current_dir + "/"+getDirectory(tgz_filename);
	system ("cd " + tmpdir + "; buildpkg " + tgz_filename );
	system("rm -rf " + tmpdir);
	delete_tmp_files();
}