001-ipkg.patch 423 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715
  1. diff -Nur busybox-1.19.4.orig/Makefile busybox-1.19.4/Makefile
  2. --- busybox-1.19.4.orig/Makefile 2012-02-04 20:34:24.000000000 +0100
  3. +++ busybox-1.19.4/Makefile 2012-03-17 00:58:08.189100677 +0100
  4. @@ -465,6 +465,7 @@
  5. libs-y := \
  6. archival/ \
  7. archival/libarchive/ \
  8. + archival/libipkg/ \
  9. console-tools/ \
  10. coreutils/ \
  11. coreutils/libcoreutils/ \
  12. diff -Nur busybox-1.19.4.orig/archival/Config.src busybox-1.19.4/archival/Config.src
  13. --- busybox-1.19.4.orig/archival/Config.src 2012-02-04 20:34:24.000000000 +0100
  14. +++ busybox-1.19.4/archival/Config.src 2012-03-17 00:58:08.189100677 +0100
  15. @@ -202,6 +202,12 @@
  16. are actually slower than gzip at equivalent compression ratios
  17. and take up 3.2K of code.
  18. +config IPKG
  19. + bool "ipkg"
  20. + default n
  21. + help
  22. + ipkg is the itsy package management system.
  23. +
  24. config RPM2CPIO
  25. bool "rpm2cpio"
  26. default y
  27. diff -Nur busybox-1.19.4.orig/archival/Kbuild.src busybox-1.19.4/archival/Kbuild.src
  28. --- busybox-1.19.4.orig/archival/Kbuild.src 2012-02-04 20:24:55.000000000 +0100
  29. +++ busybox-1.19.4/archival/Kbuild.src 2012-03-17 00:58:08.189100677 +0100
  30. @@ -22,6 +22,7 @@
  31. lib-$(CONFIG_LZOP) += lzop.o bbunzip.o
  32. lib-$(CONFIG_GZIP) += gzip.o bbunzip.o
  33. lib-$(CONFIG_BZIP2) += bzip2.o bbunzip.o
  34. +lib-$(CONFIG_IPKG) += ipkg.o
  35. lib-$(CONFIG_UNXZ) += bbunzip.o
  36. lib-$(CONFIG_UNLZMA) += bbunzip.o
  37. diff -Nur busybox-1.19.4.orig/archival/ipkg.c busybox-1.19.4/archival/ipkg.c
  38. --- busybox-1.19.4.orig/archival/ipkg.c 1970-01-01 01:00:00.000000000 +0100
  39. +++ busybox-1.19.4/archival/ipkg.c 2012-03-17 00:58:08.189100677 +0100
  40. @@ -0,0 +1,28 @@
  41. +/* ipkg.c - the itsy package management system
  42. +
  43. + Florina Boor
  44. +
  45. + Copyright (C) 2003 kernel concepts
  46. +
  47. + This program is free software; you can redistribute it and/or
  48. + modify it under the terms of the GNU General Public License as
  49. + published by the Free Software Foundation; either version 2, or (at
  50. + your option) any later version.
  51. +
  52. + This program is distributed in the hope that it will be useful, but
  53. + WITHOUT ANY WARRANTY; without even the implied warranty of
  54. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  55. + General Public License for more details.
  56. +
  57. + ipkg command line frontend using libipkg
  58. +
  59. +*/
  60. +
  61. +#include "libbb.h"
  62. +#include "libipkg/libipkg.h"
  63. +
  64. +int ipkg_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  65. +int ipkg_main(int argc, char **argv)
  66. +{
  67. + return ipkg_op(argc, argv);
  68. +}
  69. diff -Nur busybox-1.19.4.orig/archival/libipkg/Kbuild busybox-1.19.4/archival/libipkg/Kbuild
  70. --- busybox-1.19.4.orig/archival/libipkg/Kbuild 1970-01-01 01:00:00.000000000 +0100
  71. +++ busybox-1.19.4/archival/libipkg/Kbuild 2012-03-17 00:58:08.189100677 +0100
  72. @@ -0,0 +1,60 @@
  73. +# Makefile for busybox
  74. +#
  75. +# Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
  76. +# Copyright (C) 2006 OpenWrt.org
  77. +#
  78. +# Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
  79. +
  80. +LIBIPKG_CORE_OBJS:= \
  81. + args.o \
  82. + libipkg.o \
  83. + user.o \
  84. +
  85. +LIBIPKG_CMD_OBJS:= \
  86. + ipkg_cmd.o \
  87. + ipkg_configure.o \
  88. + ipkg_download.o \
  89. + ipkg_install.o \
  90. + ipkg_remove.o \
  91. + ipkg_upgrade.o \
  92. +
  93. +LIBIPKG_DB_OBJS:= \
  94. + hash_table.o \
  95. + ipkg_conf.o \
  96. + ipkg_utils.o \
  97. + pkg.o \
  98. + pkg_depends.o \
  99. + pkg_extract.o \
  100. + pkg_hash.o \
  101. + pkg_parse.o \
  102. + pkg_vec.o \
  103. +
  104. +LIBIPKG_LIST_OBJS:= \
  105. + conffile.o \
  106. + conffile_list.o \
  107. + nv_pair.o \
  108. + nv_pair_list.o \
  109. + pkg_dest.o \
  110. + pkg_dest_list.o \
  111. + pkg_src.o \
  112. + pkg_src_list.o \
  113. + str_list.o \
  114. + void_list.o \
  115. +
  116. +LIBIPKG_UTIL_OBJS:= \
  117. + file_util.o \
  118. + ipkg_message.o \
  119. + str_util.o \
  120. + xsystem.o \
  121. +
  122. +lib-y :=
  123. +lib-$(CONFIG_IPKG) += $(LIBIPKG_CORE_OBJS)
  124. +lib-$(CONFIG_IPKG) += $(LIBIPKG_CMD_OBJS)
  125. +lib-$(CONFIG_IPKG) += $(LIBIPKG_DB_OBJS)
  126. +lib-$(CONFIG_IPKG) += $(LIBIPKG_LIST_OBJS)
  127. +lib-$(CONFIG_IPKG) += $(LIBIPKG_UTIL_OBJS)
  128. +
  129. +ifeq ($(strip $(IPKG_ARCH)),)
  130. +IPKG_ARCH:=$(TARGET_ARCH)
  131. +endif
  132. +CFLAGS += -DIPKGLIBDIR="\"/usr/lib\"" -DHOST_CPU_STR="\"$(IPKG_ARCH)\""
  133. diff -Nur busybox-1.19.4.orig/archival/libipkg/args.c busybox-1.19.4/archival/libipkg/args.c
  134. --- busybox-1.19.4.orig/archival/libipkg/args.c 1970-01-01 01:00:00.000000000 +0100
  135. +++ busybox-1.19.4/archival/libipkg/args.c 2012-03-17 00:58:08.189100677 +0100
  136. @@ -0,0 +1,242 @@
  137. +/* args.c - parse command-line args
  138. +
  139. + Carl D. Worth
  140. +
  141. + Copyright 2001 University of Southern California
  142. +
  143. + This program is free software; you can redistribute it and/or modify
  144. + it under the terms of the GNU General Public License as published by
  145. + the Free Software Foundation; either version 2, or (at your option)
  146. + any later version.
  147. +
  148. + This program is distributed in the hope that it will be useful,
  149. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  150. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  151. + GNU General Public License for more details.
  152. + */
  153. +
  154. +#include <getopt.h>
  155. +#include <stdlib.h>
  156. +#include <string.h>
  157. +#include <unistd.h>
  158. +
  159. +#include "ipkg.h"
  160. +#include "ipkg_message.h"
  161. +
  162. +#include "args.h"
  163. +#include "sprintf_alloc.h"
  164. +
  165. +#include "libbb.h"
  166. +
  167. +
  168. +static void print_version(void);
  169. +
  170. +enum long_args_opt
  171. +{
  172. + ARGS_OPT_FORCE_DEFAULTS = 129,
  173. + ARGS_OPT_FORCE_DEPENDS,
  174. + ARGS_OPT_FORCE_OVERWRITE,
  175. + ARGS_OPT_FORCE_DOWNGRADE,
  176. + ARGS_OPT_FORCE_REINSTALL,
  177. + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES,
  178. + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES,
  179. + ARGS_OPT_FORCE_SPACE,
  180. + ARGS_OPT_NOACTION,
  181. + ARGS_OPT_NODEPS,
  182. + ARGS_OPT_VERBOSE_WGET,
  183. + ARGS_OPT_VERBOSITY,
  184. + ARGS_OPT_MULTIPLE_PROVIDERS
  185. +};
  186. +
  187. +int args_init(args_t *args)
  188. +{
  189. + const char *conf_file_dir;
  190. +
  191. + memset(args, 0, sizeof(args_t));
  192. +
  193. + args->dest = ARGS_DEFAULT_DEST;
  194. +
  195. + conf_file_dir = getenv("IPKG_CONF_DIR");
  196. + if (conf_file_dir == NULL || conf_file_dir[0] == '\0') {
  197. + conf_file_dir = ARGS_DEFAULT_CONF_FILE_DIR;
  198. + }
  199. + sprintf_alloc(&args->conf_file, "%s/%s", conf_file_dir,
  200. + ARGS_DEFAULT_CONF_FILE_NAME);
  201. +
  202. + args->force_defaults = ARGS_DEFAULT_FORCE_DEFAULTS;
  203. + args->force_depends = ARGS_DEFAULT_FORCE_DEPENDS;
  204. + args->force_overwrite = ARGS_DEFAULT_FORCE_OVERWRITE;
  205. + args->force_downgrade = ARGS_DEFAULT_FORCE_DOWNGRADE;
  206. + args->force_reinstall = ARGS_DEFAULT_FORCE_REINSTALL;
  207. + args->force_removal_of_dependent_packages = ARGS_DEFAULT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES;
  208. + args->force_removal_of_essential_packages = ARGS_DEFAULT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES;
  209. + args->noaction = ARGS_DEFAULT_NOACTION;
  210. + args->nodeps = ARGS_DEFAULT_NODEPS;
  211. + args->verbose_wget = ARGS_DEFAULT_VERBOSE_WGET;
  212. + args->verbosity = ARGS_DEFAULT_VERBOSITY;
  213. + args->offline_root = ARGS_DEFAULT_OFFLINE_ROOT;
  214. + args->offline_root_pre_script_cmd = ARGS_DEFAULT_OFFLINE_ROOT_PRE_SCRIPT_CMD;
  215. + args->offline_root_post_script_cmd = ARGS_DEFAULT_OFFLINE_ROOT_POST_SCRIPT_CMD;
  216. + args->multiple_providers = 0;
  217. + args->nocheckfordirorfile = 0;
  218. + args->noreadfeedsfile = 0;
  219. +
  220. + return 1;
  221. +}
  222. +
  223. +void args_deinit(args_t *args)
  224. +{
  225. + free(args->conf_file);
  226. + args->conf_file = NULL;
  227. +}
  228. +
  229. +int args_parse(args_t *args, int argc, char *argv[])
  230. +{
  231. + int c;
  232. + int option_index = 0;
  233. + int parse_err = 0;
  234. + static struct option long_options[] = {
  235. + {"query-all", 0, 0, 'A'},
  236. + {"conf-file", 1, 0, 'f'},
  237. + {"conf", 1, 0, 'f'},
  238. + {"dest", 1, 0, 'd'},
  239. + {"force-defaults", 0, 0, ARGS_OPT_FORCE_DEFAULTS},
  240. + {"force_defaults", 0, 0, ARGS_OPT_FORCE_DEFAULTS},
  241. + {"force-depends", 0, 0, ARGS_OPT_FORCE_DEPENDS},
  242. + {"force_depends", 0, 0, ARGS_OPT_FORCE_DEPENDS},
  243. + {"force-overwrite", 0, 0, ARGS_OPT_FORCE_OVERWRITE},
  244. + {"force_overwrite", 0, 0, ARGS_OPT_FORCE_OVERWRITE},
  245. + {"force_downgrade", 0, 0, ARGS_OPT_FORCE_DOWNGRADE},
  246. + {"force-downgrade", 0, 0, ARGS_OPT_FORCE_DOWNGRADE},
  247. + {"force-reinstall", 0, 0, ARGS_OPT_FORCE_REINSTALL},
  248. + {"force_reinstall", 0, 0, ARGS_OPT_FORCE_REINSTALL},
  249. + {"force-space", 0, 0, ARGS_OPT_FORCE_SPACE},
  250. + {"force_space", 0, 0, ARGS_OPT_FORCE_SPACE},
  251. + {"recursive", 0, 0,
  252. + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
  253. + {"force-removal-of-dependent-packages", 0, 0,
  254. + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
  255. + {"force_removal_of_dependent_packages", 0, 0,
  256. + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
  257. + {"force-removal-of-essential-packages", 0, 0,
  258. + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES},
  259. + {"force_removal_of_essential_packages", 0, 0,
  260. + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES},
  261. + {"multiple-providers", 0, 0, ARGS_OPT_MULTIPLE_PROVIDERS},
  262. + {"multiple_providers", 0, 0, ARGS_OPT_MULTIPLE_PROVIDERS},
  263. + {"noaction", 0, 0, ARGS_OPT_NOACTION},
  264. + {"nodeps", 0, 0, ARGS_OPT_NODEPS},
  265. + {"offline", 1, 0, 'o'},
  266. + {"offline-root", 1, 0, 'o'},
  267. + {"test", 0, 0, ARGS_OPT_NOACTION},
  268. + {"tmp-dir", 1, 0, 't'},
  269. + {"verbose-wget", 0, 0, ARGS_OPT_VERBOSE_WGET},
  270. + {"verbose_wget", 0, 0, ARGS_OPT_VERBOSE_WGET},
  271. + {"verbosity", 2, 0, 'V'},
  272. + {"version", 0, 0, 'v'},
  273. + {0, 0, 0, 0}
  274. + };
  275. +
  276. + while (1) {
  277. + c = getopt_long_only(argc, argv, "Ad:f:no:t:vV:", long_options, &option_index);
  278. + if (c == -1)
  279. + break;
  280. +
  281. + switch (c) {
  282. + case 'A':
  283. + args->query_all = 1;
  284. + break;
  285. + case 'd':
  286. + args->dest = optarg;
  287. + break;
  288. + case 'f':
  289. + free(args->conf_file);
  290. + args->conf_file = strdup(optarg);
  291. + break;
  292. + case 'o':
  293. + args->offline_root = optarg;
  294. + break;
  295. + case 'n':
  296. + args->noaction = 1;
  297. + break;
  298. + case 't':
  299. + args->tmp_dir = strdup(optarg);
  300. + break;
  301. + case 'v':
  302. + print_version();
  303. + exit(0);
  304. + case 'V':
  305. + case ARGS_OPT_VERBOSITY:
  306. + if (optarg)
  307. + args->verbosity = atoi(optarg);
  308. + else
  309. + args->verbosity += 1;
  310. + break;
  311. + case ARGS_OPT_FORCE_DEFAULTS:
  312. + args->force_defaults = 1;
  313. + break;
  314. + case ARGS_OPT_FORCE_DEPENDS:
  315. + args->force_depends = 1;
  316. + break;
  317. + case ARGS_OPT_FORCE_OVERWRITE:
  318. + args->force_overwrite = 1;
  319. + break;
  320. + case ARGS_OPT_FORCE_DOWNGRADE:
  321. + args->force_downgrade = 1;
  322. + break;
  323. + case ARGS_OPT_FORCE_REINSTALL:
  324. + args->force_reinstall = 1;
  325. + break;
  326. + case ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES:
  327. + args->force_removal_of_essential_packages = 1;
  328. + break;
  329. + case ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES:
  330. + args->force_removal_of_dependent_packages = 1;
  331. + break;
  332. + case ARGS_OPT_FORCE_SPACE:
  333. + args->force_space = 1;
  334. + break;
  335. + case ARGS_OPT_VERBOSE_WGET:
  336. + args->verbose_wget = 1;
  337. + break;
  338. + case ARGS_OPT_MULTIPLE_PROVIDERS:
  339. + args->multiple_providers = 1;
  340. + break;
  341. + case ARGS_OPT_NODEPS:
  342. + args->nodeps = 1;
  343. + break;
  344. + case ARGS_OPT_NOACTION:
  345. + args->noaction = 1;
  346. + break;
  347. + case ':':
  348. + parse_err++;
  349. + break;
  350. + case '?':
  351. + parse_err++;
  352. + break;
  353. + default:
  354. + bb_error_msg("Confusion: getopt_long returned %d\n", c);
  355. + }
  356. + }
  357. +
  358. + if (parse_err) {
  359. + return -parse_err;
  360. + } else {
  361. + return optind;
  362. + }
  363. +}
  364. +
  365. +void args_usage(const char *complaint)
  366. +{
  367. + if (complaint) {
  368. + bb_error_msg("%s\n", complaint);
  369. + }
  370. + print_version();
  371. + bb_show_usage();
  372. + exit(1);
  373. +}
  374. +
  375. +static void print_version(void)
  376. +{
  377. + bb_error_msg("version %s\n", IPKG_VERSION);
  378. +}
  379. diff -Nur busybox-1.19.4.orig/archival/libipkg/args.h busybox-1.19.4/archival/libipkg/args.h
  380. --- busybox-1.19.4.orig/archival/libipkg/args.h 1970-01-01 01:00:00.000000000 +0100
  381. +++ busybox-1.19.4/archival/libipkg/args.h 2012-03-17 00:58:08.189100677 +0100
  382. @@ -0,0 +1,72 @@
  383. +/* args.h - parse command-line args
  384. +
  385. + Carl D. Worth
  386. +
  387. + Copyright 2001 University of Southern California
  388. +
  389. + This program is free software; you can redistribute it and/or modify
  390. + it under the terms of the GNU General Public License as published by
  391. + the Free Software Foundation; either version 2, or (at your option)
  392. + any later version.
  393. +
  394. + This program is distributed in the hope that it will be useful,
  395. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  396. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  397. + GNU General Public License for more details.
  398. +*/
  399. +
  400. +#ifndef ARGS_H
  401. +#define ARGS_H
  402. +
  403. +struct args
  404. +{
  405. + char *conf_file;
  406. + char *dest;
  407. + char *tmp_dir;
  408. + int force_defaults;
  409. + int force_depends;
  410. + int force_overwrite;
  411. + int force_downgrade;
  412. + int force_reinstall;
  413. + int force_removal_of_essential_packages;
  414. + int force_removal_of_dependent_packages;
  415. + int force_space;
  416. + int noaction;
  417. + int nodeps;
  418. + int multiple_providers;
  419. + int query_all;
  420. + int verbose_wget;
  421. + int verbosity;
  422. + int nocheckfordirorfile;
  423. + int noreadfeedsfile;
  424. + char *offline_root;
  425. + char *offline_root_pre_script_cmd;
  426. + char *offline_root_post_script_cmd;
  427. +};
  428. +typedef struct args args_t;
  429. +
  430. +#define ARGS_DEFAULT_CONF_FILE_DIR "/etc"
  431. +#define ARGS_DEFAULT_CONF_FILE_NAME "ipkg.conf"
  432. +#define ARGS_DEFAULT_DEST NULL
  433. +#define ARGS_DEFAULT_FORCE_DEFAULTS 0
  434. +#define ARGS_DEFAULT_FORCE_DEPENDS 0
  435. +#define ARGS_DEFAULT_FORCE_OVERWRITE 0
  436. +#define ARGS_DEFAULT_FORCE_DOWNGRADE 0
  437. +#define ARGS_DEFAULT_FORCE_REINSTALL 0
  438. +#define ARGS_DEFAULT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES 0
  439. +#define ARGS_DEFAULT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES 0
  440. +#define ARGS_DEFAULT_FORCE_SPACE 0
  441. +#define ARGS_DEFAULT_OFFLINE_ROOT NULL
  442. +#define ARGS_DEFAULT_OFFLINE_ROOT_PRE_SCRIPT_CMD NULL
  443. +#define ARGS_DEFAULT_OFFLINE_ROOT_POST_SCRIPT_CMD NULL
  444. +#define ARGS_DEFAULT_NOACTION 0
  445. +#define ARGS_DEFAULT_NODEPS 0
  446. +#define ARGS_DEFAULT_VERBOSE_WGET 0
  447. +#define ARGS_DEFAULT_VERBOSITY 1
  448. +
  449. +int args_init(args_t *args);
  450. +void args_deinit(args_t *args);
  451. +int args_parse(args_t *args, int argc, char *argv[]);
  452. +void args_usage(const char *complaint);
  453. +
  454. +#endif
  455. diff -Nur busybox-1.19.4.orig/archival/libipkg/conffile.c busybox-1.19.4/archival/libipkg/conffile.c
  456. --- busybox-1.19.4.orig/archival/libipkg/conffile.c 1970-01-01 01:00:00.000000000 +0100
  457. +++ busybox-1.19.4/archival/libipkg/conffile.c 2012-03-17 00:58:08.189100677 +0100
  458. @@ -0,0 +1,65 @@
  459. +/* conffile.c - the itsy package management system
  460. +
  461. + Carl D. Worth
  462. +
  463. + Copyright (C) 2001 University of Southern California
  464. +
  465. + This program is free software; you can redistribute it and/or
  466. + modify it under the terms of the GNU General Public License as
  467. + published by the Free Software Foundation; either version 2, or (at
  468. + your option) any later version.
  469. +
  470. + This program is distributed in the hope that it will be useful, but
  471. + WITHOUT ANY WARRANTY; without even the implied warranty of
  472. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  473. + General Public License for more details.
  474. +*/
  475. +
  476. +#include <string.h>
  477. +#include <stdlib.h>
  478. +
  479. +#include "libbb.h"
  480. +#include "ipkg.h"
  481. +#include "ipkg_message.h"
  482. +
  483. +#include "conffile.h"
  484. +#include "file_util.h"
  485. +#include "sprintf_alloc.h"
  486. +
  487. +int conffile_init(conffile_t *conffile, const char *file_name, const uint8_t *md5sum)
  488. +{
  489. + return nv_pair_init(conffile, file_name, (char *)md5sum);
  490. +}
  491. +
  492. +void conffile_deinit(conffile_t *conffile)
  493. +{
  494. + nv_pair_deinit(conffile);
  495. +}
  496. +
  497. +int conffile_has_been_modified(ipkg_conf_t *conf, conffile_t *conffile)
  498. +{
  499. + uint8_t *md5sum;
  500. + char *filename = conffile->name;
  501. + char *root_filename;
  502. + int ret;
  503. +
  504. + if (conffile->value == NULL) {
  505. + ipkg_message(conf, IPKG_NOTICE, "%s: conffile %s has no md5sum\n", __FUNCTION__, conffile->name);
  506. + return 1;
  507. + }
  508. +
  509. + root_filename = root_filename_alloc(conf, filename);
  510. +
  511. + md5sum = file_md5sum_alloc(root_filename);
  512. +
  513. + ret = strcmp((char *)md5sum, conffile->value);
  514. + if (ret) {
  515. + ipkg_message(conf, IPKG_NOTICE, "%s: conffile %s: \t\nold md5=%s \t\nnew md5=%s\n", __FUNCTION__,
  516. + conffile->name, md5sum, conffile->value);
  517. + }
  518. +
  519. + free(root_filename);
  520. + free(md5sum);
  521. +
  522. + return ret;
  523. +}
  524. diff -Nur busybox-1.19.4.orig/archival/libipkg/conffile.h busybox-1.19.4/archival/libipkg/conffile.h
  525. --- busybox-1.19.4.orig/archival/libipkg/conffile.h 1970-01-01 01:00:00.000000000 +0100
  526. +++ busybox-1.19.4/archival/libipkg/conffile.h 2012-03-17 00:58:08.189100677 +0100
  527. @@ -0,0 +1,30 @@
  528. +/* conffile.h - the itsy package management system
  529. +
  530. + Carl D. Worth
  531. +
  532. + Copyright (C) 2001 University of Southern California
  533. +
  534. + This program is free software; you can redistribute it and/or
  535. + modify it under the terms of the GNU General Public License as
  536. + published by the Free Software Foundation; either version 2, or (at
  537. + your option) any later version.
  538. +
  539. + This program is distributed in the hope that it will be useful, but
  540. + WITHOUT ANY WARRANTY; without even the implied warranty of
  541. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  542. + General Public License for more details.
  543. +*/
  544. +
  545. +#ifndef CONFFILE_H
  546. +#define CONFFILE_H
  547. +
  548. +#include "nv_pair.h"
  549. +
  550. +typedef struct nv_pair conffile_t;
  551. +
  552. +int conffile_init(conffile_t *conffile, const char *file_name, const uint8_t *md5sum);
  553. +void conffile_deinit(conffile_t *conffile);
  554. +int conffile_has_been_modified(struct ipkg_conf *conf, conffile_t *conffile);
  555. +
  556. +#endif
  557. +
  558. diff -Nur busybox-1.19.4.orig/archival/libipkg/conffile_list.c busybox-1.19.4/archival/libipkg/conffile_list.c
  559. --- busybox-1.19.4.orig/archival/libipkg/conffile_list.c 1970-01-01 01:00:00.000000000 +0100
  560. +++ busybox-1.19.4/archival/libipkg/conffile_list.c 2012-03-17 00:58:08.189100677 +0100
  561. @@ -0,0 +1,47 @@
  562. +/* conffile_list.c - the itsy package management system
  563. +
  564. + Carl D. Worth
  565. +
  566. + Copyright (C) 2001 University of Southern California
  567. +
  568. + This program is free software; you can redistribute it and/or
  569. + modify it under the terms of the GNU General Public License as
  570. + published by the Free Software Foundation; either version 2, or (at
  571. + your option) any later version.
  572. +
  573. + This program is distributed in the hope that it will be useful, but
  574. + WITHOUT ANY WARRANTY; without even the implied warranty of
  575. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  576. + General Public License for more details.
  577. +*/
  578. +
  579. +#include "ipkg.h"
  580. +
  581. +#include "conffile_list.h"
  582. +
  583. +int conffile_list_init(conffile_list_t *list)
  584. +{
  585. + return nv_pair_list_init(list);
  586. +}
  587. +
  588. +void conffile_list_deinit(conffile_list_t *list)
  589. +{
  590. + nv_pair_list_deinit(list);
  591. +}
  592. +
  593. +conffile_t *conffile_list_append(conffile_list_t *list, const char *file_name,
  594. + const char *md5sum)
  595. +{
  596. + return nv_pair_list_append(list, file_name, md5sum);
  597. +}
  598. +
  599. +int conffile_list_push(conffile_list_t *list, conffile_t *data)
  600. +{
  601. + return nv_pair_list_push(list, data);
  602. +}
  603. +
  604. +conffile_list_elt_t *conffile_list_pop(conffile_list_t *list)
  605. +{
  606. + return nv_pair_list_pop(list);
  607. +}
  608. +
  609. diff -Nur busybox-1.19.4.orig/archival/libipkg/conffile_list.h busybox-1.19.4/archival/libipkg/conffile_list.h
  610. --- busybox-1.19.4.orig/archival/libipkg/conffile_list.h 1970-01-01 01:00:00.000000000 +0100
  611. +++ busybox-1.19.4/archival/libipkg/conffile_list.h 2012-03-17 00:58:08.189100677 +0100
  612. @@ -0,0 +1,36 @@
  613. +/* conffile_list.h - the itsy package management system
  614. +
  615. + Carl D. Worth
  616. +
  617. + Copyright (C) 2001 University of Southern California
  618. +
  619. + This program is free software; you can redistribute it and/or
  620. + modify it under the terms of the GNU General Public License as
  621. + published by the Free Software Foundation; either version 2, or (at
  622. + your option) any later version.
  623. +
  624. + This program is distributed in the hope that it will be useful, but
  625. + WITHOUT ANY WARRANTY; without even the implied warranty of
  626. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  627. + General Public License for more details.
  628. +*/
  629. +
  630. +#ifndef CONFFILE_LIST_H
  631. +#define CONFFILE_LIST_H
  632. +
  633. +#include "conffile.h"
  634. +#include "nv_pair_list.h"
  635. +
  636. +typedef struct nv_pair_list_elt conffile_list_elt_t;
  637. +typedef struct nv_pair_list conffile_list_t;
  638. +
  639. +int conffile_list_init(conffile_list_t *list);
  640. +void conffile_list_deinit(conffile_list_t *list);
  641. +
  642. +conffile_t *conffile_list_append(conffile_list_t *list, const char *name,
  643. + const char *root_dir);
  644. +int conffile_list_push(conffile_list_t *list, conffile_t *data);
  645. +conffile_list_elt_t *conffile_list_pop(conffile_list_t *list);
  646. +
  647. +#endif
  648. +
  649. diff -Nur busybox-1.19.4.orig/archival/libipkg/file_util.c busybox-1.19.4/archival/libipkg/file_util.c
  650. --- busybox-1.19.4.orig/archival/libipkg/file_util.c 1970-01-01 01:00:00.000000000 +0100
  651. +++ busybox-1.19.4/archival/libipkg/file_util.c 2012-03-17 00:58:08.189100677 +0100
  652. @@ -0,0 +1,186 @@
  653. +/* file_util.c - convenience routines for common stat operations
  654. +
  655. + Carl D. Worth
  656. +
  657. + Copyright (C) 2001 University of Southern California
  658. +
  659. + This program is free software; you can redistribute it and/or
  660. + modify it under the terms of the GNU General Public License as
  661. + published by the Free Software Foundation; either version 2, or (at
  662. + your option) any later version.
  663. +
  664. + This program is distributed in the hope that it will be useful, but
  665. + WITHOUT ANY WARRANTY; without even the implied warranty of
  666. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  667. + General Public License for more details.
  668. +*/
  669. +
  670. +#include "ipkg.h"
  671. +#include <sys/types.h>
  672. +#include <sys/stat.h>
  673. +
  674. +#include "sprintf_alloc.h"
  675. +#include "file_util.h"
  676. +#include "libbb.h"
  677. +#undef strlen
  678. +
  679. +int file_exists(const char *file_name)
  680. +{
  681. + int err;
  682. + struct stat stat_buf;
  683. +
  684. + err = stat(file_name, &stat_buf);
  685. + if (err == 0) {
  686. + return 1;
  687. + } else {
  688. + return 0;
  689. + }
  690. +}
  691. +
  692. +int file_is_dir(const char *file_name)
  693. +{
  694. + int err;
  695. + struct stat stat_buf;
  696. +
  697. + err = stat(file_name, &stat_buf);
  698. + if (err) {
  699. + return 0;
  700. + }
  701. +
  702. + return S_ISDIR(stat_buf.st_mode);
  703. +}
  704. +
  705. +/* read a single line from a file, stopping at a newline or EOF.
  706. + If a newline is read, it will appear in the resulting string.
  707. + Return value is a malloc'ed char * which should be freed at
  708. + some point by the caller.
  709. +
  710. + Return value is NULL if the file is at EOF when called.
  711. +*/
  712. +#define FILE_READ_LINE_BUF_SIZE 1024
  713. +char *file_read_line_alloc(FILE *file)
  714. +{
  715. + char buf[FILE_READ_LINE_BUF_SIZE];
  716. + int buf_len;
  717. + char *line = NULL;
  718. + int line_size = 0;
  719. +
  720. + memset(buf, 0, FILE_READ_LINE_BUF_SIZE);
  721. + while (fgets(buf, FILE_READ_LINE_BUF_SIZE, file)) {
  722. + buf_len = strlen(buf);
  723. + if (line) {
  724. + line_size += buf_len;
  725. + line = realloc(line, line_size);
  726. + if (line == NULL) {
  727. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  728. + break;
  729. + }
  730. + strcat(line, buf);
  731. + } else {
  732. + line_size = buf_len + 1;
  733. + line = strdup(buf);
  734. + }
  735. + if (buf[buf_len - 1] == '\n') {
  736. + break;
  737. + }
  738. + }
  739. +
  740. + return line;
  741. +}
  742. +
  743. +int file_move(const char *src, const char *dest)
  744. +{
  745. + int err;
  746. +
  747. + err = rename(src, dest);
  748. +
  749. + if (err && errno == EXDEV) {
  750. + err = file_copy(src, dest);
  751. + unlink(src);
  752. + } else if (err) {
  753. + fprintf(stderr, "%s: ERROR: failed to rename %s to %s: %s\n",
  754. + __FUNCTION__, src, dest, strerror(errno));
  755. + }
  756. +
  757. + return err;
  758. +}
  759. +
  760. +/* I put these here to keep libbb dependencies from creeping all over
  761. + the ipkg code */
  762. +int file_copy(const char *src, const char *dest)
  763. +{
  764. + int err;
  765. +
  766. + err = copy_file(src, dest, FILEUTILS_FORCE | FILEUTILS_PRESERVE_STATUS);
  767. + if (err) {
  768. + fprintf(stderr, "%s: ERROR: failed to copy %s to %s\n",
  769. + __FUNCTION__, src, dest);
  770. + }
  771. +
  772. + return err;
  773. +}
  774. +
  775. +int file_mkdir_hier(char *path, long mode)
  776. +{
  777. + return bb_make_directory(path, mode, FILEUTILS_RECUR);
  778. +}
  779. +
  780. +static unsigned char *hash_bin_to_hex(unsigned char *hash_value,
  781. + unsigned hash_length)
  782. +{
  783. + /* xzalloc zero-terminates */
  784. + char *hex_value = xzalloc((hash_length * 2) + 1);
  785. + bin2hex(hex_value, (char*)hash_value, hash_length);
  786. + return (unsigned char *)hex_value;
  787. +}
  788. +
  789. +static uint8_t *hash_file(const char *filename, hash_algo_t hash_algo)
  790. +{
  791. + int src_fd, hash_len, count;
  792. + union _ctx_ {
  793. + sha1_ctx_t sha1;
  794. + md5_ctx_t md5;
  795. + } context;
  796. + uint8_t *hash_value = NULL;
  797. + RESERVE_CONFIG_UBUFFER(in_buf, 4096);
  798. + void FAST_FUNC (*update)(void*, const void*, size_t);
  799. + void FAST_FUNC (*final)(void*, void*);
  800. +
  801. + src_fd = open_or_warn_stdin(filename);
  802. + if (src_fd < 0) {
  803. + return NULL;
  804. + }
  805. +
  806. + /* figure specific hash algorithims */
  807. + if (ENABLE_MD5SUM && hash_algo == HASH_MD5) {
  808. + md5_begin(&context.md5);
  809. + update = (void*)md5_hash;
  810. + final = (void*)md5_end;
  811. + hash_len = 16;
  812. + } else {
  813. + bb_error_msg_and_die("algorithm not supported");
  814. + }
  815. +
  816. + while ((count = safe_read(src_fd, in_buf, 4096)) > 0) {
  817. + update(&context, in_buf, count);
  818. + }
  819. +
  820. + if (count == 0) {
  821. + final(&context, in_buf);
  822. + hash_value = hash_bin_to_hex(in_buf, hash_len);
  823. + }
  824. +
  825. + RELEASE_CONFIG_BUFFER(in_buf);
  826. +
  827. + if (src_fd != STDIN_FILENO) {
  828. + close(src_fd);
  829. + }
  830. +
  831. + return hash_value;
  832. +}
  833. +
  834. +uint8_t *file_md5sum_alloc(const char *file_name)
  835. +{
  836. + return hash_file(file_name, HASH_MD5);
  837. +}
  838. +
  839. diff -Nur busybox-1.19.4.orig/archival/libipkg/file_util.h busybox-1.19.4/archival/libipkg/file_util.h
  840. --- busybox-1.19.4.orig/archival/libipkg/file_util.h 1970-01-01 01:00:00.000000000 +0100
  841. +++ busybox-1.19.4/archival/libipkg/file_util.h 2012-03-17 00:58:08.189100677 +0100
  842. @@ -0,0 +1,29 @@
  843. +/* file_util.h - convenience routines for common file operations
  844. +
  845. + Carl D. Worth
  846. +
  847. + Copyright (C) 2001 University of Southern California
  848. +
  849. + This program is free software; you can redistribute it and/or
  850. + modify it under the terms of the GNU General Public License as
  851. + published by the Free Software Foundation; either version 2, or (at
  852. + your option) any later version.
  853. +
  854. + This program is distributed in the hope that it will be useful, but
  855. + WITHOUT ANY WARRANTY; without even the implied warranty of
  856. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  857. + General Public License for more details.
  858. +*/
  859. +
  860. +#ifndef FILE_UTIL_H
  861. +#define FILE_UTIL_H
  862. +
  863. +int file_exists(const char *file_name);
  864. +int file_is_dir(const char *file_name);
  865. +char *file_read_line_alloc(FILE *file);
  866. +int file_move(const char *src, const char *dest);
  867. +int file_copy(const char *src, const char *dest);
  868. +int file_mkdir_hier(char *path, long mode);
  869. +uint8_t *file_md5sum_alloc(const char *file_name);
  870. +
  871. +#endif
  872. diff -Nur busybox-1.19.4.orig/archival/libipkg/hash_table.c busybox-1.19.4/archival/libipkg/hash_table.c
  873. --- busybox-1.19.4.orig/archival/libipkg/hash_table.c 1970-01-01 01:00:00.000000000 +0100
  874. +++ busybox-1.19.4/archival/libipkg/hash_table.c 2012-03-17 00:58:08.189100677 +0100
  875. @@ -0,0 +1,155 @@
  876. +/* hash.c - hash tables for ipkg
  877. +
  878. + Steven M. Ayer, Jamey Hicks
  879. +
  880. + Copyright (C) 2002 Compaq Computer Corporation
  881. +
  882. + This program is free software; you can redistribute it and/or
  883. + modify it under the terms of the GNU General Public License as
  884. + published by the Free Software Foundation; either version 2, or (at
  885. + your option) any later version.
  886. +
  887. + This program is distributed in the hope that it will be useful, but
  888. + WITHOUT ANY WARRANTY; without even the implied warranty of
  889. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  890. + General Public License for more details.
  891. +*/
  892. +
  893. +#include <errno.h>
  894. +#include <stdio.h>
  895. +#include <stdlib.h>
  896. +#include <string.h>
  897. +#include "hash_table.h"
  898. +#include "ipkg_message.h"
  899. +
  900. +
  901. +static int hash_index(hash_table_t *hash, const char *pkg_name);
  902. +static int rotating(const char *key, int len, int prime);
  903. +
  904. +static int hash_index(hash_table_t *hash, const char *pkg_name)
  905. +{
  906. + return rotating(pkg_name, strlen(pkg_name), hash->n_entries);
  907. +}
  908. +
  909. +static int rotating(const char *key, int len, int prime)
  910. +{
  911. + unsigned int hash, i;
  912. + for (hash=len, i=0; i<len; ++i)
  913. + hash = (hash<<4)^(hash>>28)^key[i];
  914. + return (hash % prime);
  915. +}
  916. +
  917. +
  918. +/*
  919. + * this is an open table keyed by strings
  920. + */
  921. +int hash_table_init(const char *name, hash_table_t *hash, int len)
  922. +{
  923. + static int primes_table[] = {
  924. + 379, 761, 983, 1423, 2711, 3361, 3931, 4679, 5519, 6701, 9587,
  925. + 19471, 23143, 33961, 46499, 49727, 99529, 0
  926. + };
  927. + int *picker;
  928. +
  929. + if (hash->entries != NULL) {
  930. + /* we have been here already */
  931. + return 0;
  932. + }
  933. +
  934. + hash->name = name;
  935. + hash->entries = NULL;
  936. + hash->n_entries = 0;
  937. + hash->hash_entry_key = NULL;
  938. +
  939. + picker = primes_table;
  940. + while(*picker && (*picker++ < len));
  941. + if(!*picker)
  942. + fprintf(stderr, "%s: primes table might not be big enough (! << %d)\n", __FUNCTION__, len);
  943. + --picker;
  944. +
  945. + hash->n_entries = *picker;
  946. + hash->entries = (hash_entry_t *)calloc(hash->n_entries, sizeof(hash_entry_t));
  947. + if (hash->entries == NULL) {
  948. + fprintf(stderr, "%s: Out of memory.\n", __FUNCTION__);
  949. + return ENOMEM;
  950. + }
  951. + return 0;
  952. +}
  953. +
  954. +void hash_table_deinit(hash_table_t *hash)
  955. +{
  956. + free(hash->entries);
  957. + hash->entries = NULL;
  958. + hash->n_entries = 0;
  959. +}
  960. +
  961. +void *hash_table_get(hash_table_t *hash, const char *key)
  962. +{
  963. + int ndx= hash_index(hash, key);
  964. + hash_entry_t *hash_entry = hash->entries + ndx;
  965. + while (hash_entry)
  966. + {
  967. + if (hash_entry->key)
  968. + {
  969. + if (strcmp(key, hash_entry->key) == 0) {
  970. + // ipkg_message(NULL, IPKG_DEBUG, "Function: %s. Key found for '%s' \n", __FUNCTION__, key);
  971. + return hash_entry->data;
  972. + }
  973. + }
  974. + hash_entry = hash_entry->next;
  975. + }
  976. + return NULL;
  977. +}
  978. +
  979. +int hash_table_insert(hash_table_t *hash, const char *key, void *value)
  980. +{
  981. + int ndx= hash_index(hash, key);
  982. + hash_entry_t *hash_entry = hash->entries + ndx;
  983. + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Inserting in hash for '%s' \n", __FUNCTION__, key);
  984. + if (hash_entry->key) {
  985. + if (strcmp(hash_entry->key, key) == 0) {
  986. + /* alread in table, update the value */
  987. + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Value already in hash for '%s' \n", __FUNCTION__, key);
  988. + hash_entry->data = value;
  989. + return 0;
  990. + } else {
  991. + /*
  992. + * if this is a collision, we have to go to the end of the ll,
  993. + * then add a new entry
  994. + * before we can hook up the value
  995. + */
  996. + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Value already in hash by collision for '%s' \n", __FUNCTION__, key);
  997. + while (hash_entry->next)
  998. + hash_entry = hash_entry->next;
  999. + hash_entry->next = (hash_entry_t *)malloc(sizeof(hash_entry_t));
  1000. + if (!hash_entry->next) {
  1001. + return -ENOMEM;
  1002. + }
  1003. + hash_entry = hash_entry->next;
  1004. + hash_entry->next = NULL;
  1005. + }
  1006. + }
  1007. + hash->n_elements++;
  1008. + hash_entry->key = strdup(key);
  1009. + hash_entry->data = value;
  1010. +
  1011. + return 0;
  1012. +}
  1013. +
  1014. +
  1015. +void hash_table_foreach(hash_table_t *hash, void (*f)(const char *key, void *entry, void *data), void *data)
  1016. +{
  1017. + int i;
  1018. + if (!hash || !f)
  1019. + return;
  1020. +
  1021. + for (i = 0; i < hash->n_entries; i++) {
  1022. + hash_entry_t *hash_entry = (hash->entries + i);
  1023. + do {
  1024. + if(hash_entry->key) {
  1025. + f(hash_entry->key, hash_entry->data, data);
  1026. + }
  1027. + } while((hash_entry = hash_entry->next));
  1028. + }
  1029. +}
  1030. +
  1031. diff -Nur busybox-1.19.4.orig/archival/libipkg/hash_table.h busybox-1.19.4/archival/libipkg/hash_table.h
  1032. --- busybox-1.19.4.orig/archival/libipkg/hash_table.h 1970-01-01 01:00:00.000000000 +0100
  1033. +++ busybox-1.19.4/archival/libipkg/hash_table.h 2012-03-17 00:58:08.189100677 +0100
  1034. @@ -0,0 +1,44 @@
  1035. +/* hash.h - hash tables for ipkg
  1036. +
  1037. + Steven M. Ayer, Jamey Hicks
  1038. +
  1039. + Copyright (C) 2002 Compaq Computer Corporation
  1040. +
  1041. + This program is free software; you can redistribute it and/or
  1042. + modify it under the terms of the GNU General Public License as
  1043. + published by the Free Software Foundation; either version 2, or (at
  1044. + your option) any later version.
  1045. +
  1046. + This program is distributed in the hope that it will be useful, but
  1047. + WITHOUT ANY WARRANTY; without even the implied warranty of
  1048. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  1049. + General Public License for more details.
  1050. +*/
  1051. +
  1052. +#ifndef _HASH_TABLE_H_
  1053. +#define _HASH_TABLE_H_
  1054. +
  1055. +typedef struct hash_entry hash_entry_t;
  1056. +typedef struct hash_table hash_table_t;
  1057. +
  1058. +struct hash_entry {
  1059. + const char * key;
  1060. + void * data;
  1061. + struct hash_entry * next;
  1062. +};
  1063. +
  1064. +struct hash_table {
  1065. + const char *name;
  1066. + hash_entry_t * entries;
  1067. + int n_entries; /* number of buckets */
  1068. + int n_elements;
  1069. + const char * (*hash_entry_key)(void * data);
  1070. +};
  1071. +
  1072. +int hash_table_init(const char *name, hash_table_t *hash, int len);
  1073. +void hash_table_deinit(hash_table_t *hash);
  1074. +void *hash_table_get(hash_table_t *hash, const char *key);
  1075. +int hash_table_insert(hash_table_t *hash, const char *key, void *value);
  1076. +void hash_table_foreach(hash_table_t *hash, void (*f)(const char *key, void *entry, void *data), void *data);
  1077. +
  1078. +#endif /* _HASH_TABLE_H_ */
  1079. diff -Nur busybox-1.19.4.orig/archival/libipkg/ipkg.h busybox-1.19.4/archival/libipkg/ipkg.h
  1080. --- busybox-1.19.4.orig/archival/libipkg/ipkg.h 1970-01-01 01:00:00.000000000 +0100
  1081. +++ busybox-1.19.4/archival/libipkg/ipkg.h 2012-03-17 00:58:08.189100677 +0100
  1082. @@ -0,0 +1,68 @@
  1083. +/* ipkg.h - the itsy package management system
  1084. +
  1085. + Carl D. Worth
  1086. +
  1087. + Copyright (C) 2001 University of Southern California
  1088. +
  1089. + This program is free software; you can redistribute it and/or
  1090. + modify it under the terms of the GNU General Public License as
  1091. + published by the Free Software Foundation; either version 2, or (at
  1092. + your option) any later version.
  1093. +
  1094. + This program is distributed in the hope that it will be useful, but
  1095. + WITHOUT ANY WARRANTY; without even the implied warranty of
  1096. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  1097. + General Public License for more details.
  1098. +*/
  1099. +
  1100. +#ifndef IPKG_H
  1101. +#define IPKG_H
  1102. +
  1103. +#include "libbb.h"
  1104. +
  1105. +#include "ipkg_includes.h"
  1106. +#include "ipkg_conf.h"
  1107. +#include "ipkg_message.h"
  1108. +
  1109. +#define IPKG_PKG_EXTENSION ".ipk"
  1110. +#define DPKG_PKG_EXTENSION ".deb"
  1111. +
  1112. +#define IPKG_LEGAL_PKG_NAME_CHARS "abcdefghijklmnopqrstuvwxyz0123456789.+-"
  1113. +#define IPKG_PKG_VERSION_SEP_CHAR '_'
  1114. +
  1115. +#define IPKG_STATE_DIR_PREFIX IPKGLIBDIR"/ipkg"
  1116. +#define IPKG_LISTS_DIR_SUFFIX "lists"
  1117. +#define IPKG_INFO_DIR_SUFFIX "info"
  1118. +#define IPKG_STATUS_FILE_SUFFIX "status"
  1119. +
  1120. +#define IPKG_BACKUP_SUFFIX "-ipkg.backup"
  1121. +
  1122. +#define IPKG_LIST_DESCRIPTION_LENGTH 128
  1123. +
  1124. +#define IPKG_VERSION "1.00"
  1125. +
  1126. +
  1127. +enum ipkg_error {
  1128. + IPKG_SUCCESS = 0,
  1129. + IPKG_PKG_DEPS_UNSATISFIED,
  1130. + IPKG_PKG_IS_ESSENTIAL,
  1131. + IPKG_PKG_HAS_DEPENDENTS,
  1132. + IPKG_PKG_HAS_NO_CANDIDATE
  1133. +};
  1134. +typedef enum ipkg_error ipkg_error_t;
  1135. +
  1136. +extern int ipkg_state_changed;
  1137. +
  1138. +
  1139. +struct errlist {
  1140. + char * errmsg;
  1141. + struct errlist * next;
  1142. +} ;
  1143. +
  1144. +extern struct errlist* error_list;
  1145. +
  1146. +extern ipkg_conf_t *global_conf;
  1147. +
  1148. +typedef enum { HASH_SHA1, HASH_MD5 } hash_algo_t;
  1149. +
  1150. +#endif
  1151. diff -Nur busybox-1.19.4.orig/archival/libipkg/ipkg_cmd.c busybox-1.19.4/archival/libipkg/ipkg_cmd.c
  1152. --- busybox-1.19.4.orig/archival/libipkg/ipkg_cmd.c 1970-01-01 01:00:00.000000000 +0100
  1153. +++ busybox-1.19.4/archival/libipkg/ipkg_cmd.c 2012-03-17 00:58:08.193100680 +0100
  1154. @@ -0,0 +1,1366 @@
  1155. +/* ipkg_cmd.c - the itsy package management system
  1156. +
  1157. + Carl D. Worth
  1158. +
  1159. + Copyright (C) 2001 University of Southern California
  1160. +
  1161. + This program is free software; you can redistribute it and/or
  1162. + modify it under the terms of the GNU General Public License as
  1163. + published by the Free Software Foundation; either version 2, or (at
  1164. + your option) any later version.
  1165. +
  1166. + This program is distributed in the hope that it will be useful, but
  1167. + WITHOUT ANY WARRANTY; without even the implied warranty of
  1168. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  1169. + General Public License for more details.
  1170. +*/
  1171. +
  1172. +#include <string.h>
  1173. +
  1174. +#include "ipkg.h"
  1175. +#include <libgen.h>
  1176. +#include <glob.h>
  1177. +#include <errno.h>
  1178. +#include <stdlib.h>
  1179. +#include <unistd.h>
  1180. +#include <signal.h>
  1181. +#include <stdio.h>
  1182. +#include <dirent.h>
  1183. +
  1184. +#include "ipkg_conf.h"
  1185. +#include "ipkg_cmd.h"
  1186. +#include "ipkg_message.h"
  1187. +#include "pkg.h"
  1188. +#include "pkg_dest.h"
  1189. +#include "pkg_parse.h"
  1190. +#include "sprintf_alloc.h"
  1191. +#include "pkg.h"
  1192. +#include "file_util.h"
  1193. +#include "str_util.h"
  1194. +#include "archive.h"
  1195. +
  1196. +#include <fnmatch.h>
  1197. +
  1198. +
  1199. +#include "ipkg_download.h"
  1200. +#include "ipkg_install.h"
  1201. +#include "ipkg_upgrade.h"
  1202. +#include "ipkg_remove.h"
  1203. +#include "ipkg_configure.h"
  1204. +#include "ipkg_message.h"
  1205. +
  1206. +#include "libipkg.h"
  1207. +static void *p_userdata = NULL;
  1208. +
  1209. +static int ipkg_update_cmd(ipkg_conf_t *conf);
  1210. +static int ipkg_upgrade_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1211. +static int ipkg_list_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1212. +static int ipkg_info_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1213. +static int ipkg_status_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1214. +static int ipkg_install_pending_cmd(ipkg_conf_t *conf);
  1215. +static int ipkg_install_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1216. +static int ipkg_list_installed_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1217. +static int ipkg_remove_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1218. +static int ipkg_purge_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1219. +static int ipkg_flag_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1220. +static int ipkg_files_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1221. +static int ipkg_search_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1222. +static int ipkg_download_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1223. +static int ipkg_depends_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1224. +static int ipkg_whatdepends_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1225. +static int ipkg_whatdepends_recursively_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1226. +static int ipkg_whatsuggests_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1227. +static int ipkg_whatrecommends_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1228. +static int ipkg_whatprovides_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1229. +static int ipkg_whatconflicts_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1230. +static int ipkg_whatreplaces_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1231. +static int ipkg_compare_versions_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1232. +static int ipkg_print_architecture_cmd(ipkg_conf_t *conf);
  1233. +static int ipkg_configure_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1234. +
  1235. +/* XXX: CLEANUP: The usage strings should be incorporated into this
  1236. + array for easier maintenance */
  1237. +static ipkg_cmd_t cmds[] = {
  1238. + {"update", 0, (ipkg_cmd_fun_t)ipkg_update_cmd},
  1239. + {"upgrade", 0, (ipkg_cmd_fun_t)ipkg_upgrade_cmd},
  1240. + {"list", 0, (ipkg_cmd_fun_t)ipkg_list_cmd},
  1241. + {"list_installed", 0, (ipkg_cmd_fun_t)ipkg_list_installed_cmd},
  1242. + {"info", 0, (ipkg_cmd_fun_t)ipkg_info_cmd},
  1243. + {"flag", 1, (ipkg_cmd_fun_t)ipkg_flag_cmd},
  1244. + {"status", 0, (ipkg_cmd_fun_t)ipkg_status_cmd},
  1245. + {"install_pending", 0, (ipkg_cmd_fun_t)ipkg_install_pending_cmd},
  1246. + {"install", 1, (ipkg_cmd_fun_t)ipkg_install_cmd},
  1247. + {"remove", 1, (ipkg_cmd_fun_t)ipkg_remove_cmd},
  1248. + {"purge", 1, (ipkg_cmd_fun_t)ipkg_purge_cmd},
  1249. + {"configure", 0, (ipkg_cmd_fun_t)ipkg_configure_cmd},
  1250. + {"files", 1, (ipkg_cmd_fun_t)ipkg_files_cmd},
  1251. + {"search", 1, (ipkg_cmd_fun_t)ipkg_search_cmd},
  1252. + {"download", 1, (ipkg_cmd_fun_t)ipkg_download_cmd},
  1253. + {"compare_versions", 1, (ipkg_cmd_fun_t)ipkg_compare_versions_cmd},
  1254. + {"compare-versions", 1, (ipkg_cmd_fun_t)ipkg_compare_versions_cmd},
  1255. + {"print-architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
  1256. + {"print_architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
  1257. + {"print-installation-architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
  1258. + {"print_installation_architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
  1259. + {"depends", 1, (ipkg_cmd_fun_t)ipkg_depends_cmd},
  1260. + {"whatdepends", 1, (ipkg_cmd_fun_t)ipkg_whatdepends_cmd},
  1261. + {"whatdependsrec", 1, (ipkg_cmd_fun_t)ipkg_whatdepends_recursively_cmd},
  1262. + {"whatrecommends", 1, (ipkg_cmd_fun_t)ipkg_whatrecommends_cmd},
  1263. + {"whatsuggests", 1, (ipkg_cmd_fun_t)ipkg_whatsuggests_cmd},
  1264. + {"whatprovides", 1, (ipkg_cmd_fun_t)ipkg_whatprovides_cmd},
  1265. + {"whatreplaces", 1, (ipkg_cmd_fun_t)ipkg_whatreplaces_cmd},
  1266. + {"whatconflicts", 1, (ipkg_cmd_fun_t)ipkg_whatconflicts_cmd},
  1267. +};
  1268. +
  1269. +int ipkg_state_changed;
  1270. +static void write_status_files_if_changed(ipkg_conf_t *conf)
  1271. +{
  1272. + if (ipkg_state_changed && !conf->noaction) {
  1273. + ipkg_message(conf, IPKG_INFO,
  1274. + " writing status file\n");
  1275. + ipkg_conf_write_status_files(conf);
  1276. + pkg_write_changed_filelists(conf);
  1277. + } else {
  1278. + ipkg_message(conf, IPKG_NOTICE, "Nothing to be done\n");
  1279. + }
  1280. +}
  1281. +
  1282. +
  1283. +static int num_cmds = sizeof(cmds) / sizeof(ipkg_cmd_t);
  1284. +
  1285. +ipkg_cmd_t *ipkg_cmd_find(const char *name)
  1286. +{
  1287. + int i;
  1288. + ipkg_cmd_t *cmd;
  1289. +
  1290. + for (i=0; i < num_cmds; i++) {
  1291. + cmd = &cmds[i];
  1292. + if (strcmp(name, cmd->name) == 0) {
  1293. + return cmd;
  1294. + }
  1295. + }
  1296. +
  1297. + return NULL;
  1298. +}
  1299. +
  1300. +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc, const char **argv, void *userdata)
  1301. +{
  1302. + int result;
  1303. + p_userdata = userdata;
  1304. +
  1305. +
  1306. + result = (cmd->fun)(conf, argc, argv);
  1307. + if ( result == 0 ) {
  1308. + ipkg_message(conf, IPKG_NOTICE, "Done.\n");
  1309. + } else {
  1310. + ipkg_message(conf, IPKG_NOTICE, "An error ocurred, return value: %d.\n", result);
  1311. +
  1312. + }
  1313. + if ( error_list ) {
  1314. + reverse_error_list(&error_list);
  1315. +
  1316. + ipkg_message(conf, IPKG_NOTICE, "Collected errors:\n");
  1317. + /* Here we print the errors collected and free the list */
  1318. + while (error_list != NULL) {
  1319. + ipkg_message(conf, IPKG_NOTICE, "%s",error_list->errmsg);
  1320. + error_list = error_list->next;
  1321. +
  1322. + }
  1323. + free_error_list(&error_list);
  1324. +
  1325. + }
  1326. +
  1327. + p_userdata = NULL;
  1328. + return result;
  1329. +}
  1330. +
  1331. +static int ipkg_update_cmd(ipkg_conf_t *conf)
  1332. +{
  1333. + int err;
  1334. + int failures;
  1335. + char *lists_dir;
  1336. + pkg_src_list_elt_t *iter;
  1337. + pkg_src_t *src;
  1338. +
  1339. +
  1340. + sprintf_alloc(&lists_dir, "%s", conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir);
  1341. +
  1342. + if (! file_is_dir(lists_dir)) {
  1343. + if (file_exists(lists_dir)) {
  1344. + ipkg_message(conf, IPKG_ERROR,
  1345. + "%s: ERROR: %s exists, but is not a directory\n",
  1346. + __FUNCTION__, lists_dir);
  1347. + free(lists_dir);
  1348. + return EINVAL;
  1349. + }
  1350. + err = file_mkdir_hier(lists_dir, 0755);
  1351. + if (err) {
  1352. + ipkg_message(conf, IPKG_ERROR,
  1353. + "%s: ERROR: failed to make directory %s: %s\n",
  1354. + __FUNCTION__, lists_dir, strerror(errno));
  1355. + free(lists_dir);
  1356. + return EINVAL;
  1357. + }
  1358. + }
  1359. +
  1360. + failures = 0;
  1361. + for (iter = conf->pkg_src_list.head; iter; iter = iter->next) {
  1362. + char *url, *list_file_name;
  1363. +
  1364. + src = iter->data;
  1365. +
  1366. + if (src->extra_data) /* debian style? */
  1367. + sprintf_alloc(&url, "%s/%s/%s", src->value, src->extra_data,
  1368. + src->gzip ? "Packages.gz" : "Packages");
  1369. + else
  1370. + sprintf_alloc(&url, "%s/%s", src->value, src->gzip ? "Packages.gz" : "Packages");
  1371. +
  1372. + sprintf_alloc(&list_file_name, "%s/%s", lists_dir, src->name);
  1373. + if (src->gzip) {
  1374. + char *tmp;
  1375. + char *tmp_file_name;
  1376. + FILE *in, *out;
  1377. +
  1378. + tmp = strdup ("/tmp/ipkg.XXXXXX");
  1379. +
  1380. + if (mkdtemp (tmp) == NULL) {
  1381. + perror ("mkdtemp");
  1382. + failures++;
  1383. + continue;
  1384. + }
  1385. +
  1386. + sprintf_alloc (&tmp_file_name, "%s/%s.gz", tmp, src->name);
  1387. + err = ipkg_download(conf, url, tmp_file_name);
  1388. + if (err == 0) {
  1389. + ipkg_message (conf, IPKG_NOTICE, "Inflating %s\n", url);
  1390. + in = fopen (tmp_file_name, "r");
  1391. + out = fopen (list_file_name, "w");
  1392. + if (in && out) {
  1393. + inflate_unzip_result res;
  1394. + inflate_unzip (&res, 0x8000, fileno(in), fileno(out));
  1395. + } else
  1396. + err = 1;
  1397. + if (in)
  1398. + fclose (in);
  1399. + if (out)
  1400. + fclose (out);
  1401. + unlink (tmp_file_name);
  1402. + rmdir (tmp);
  1403. + free (tmp);
  1404. + }
  1405. + } else
  1406. + err = ipkg_download(conf, url, list_file_name);
  1407. + if (err) {
  1408. + failures++;
  1409. + } else {
  1410. + ipkg_message(conf, IPKG_NOTICE,
  1411. + "Updated list of available packages in %s\n",
  1412. + list_file_name);
  1413. + }
  1414. + free(url);
  1415. + free(list_file_name);
  1416. + }
  1417. + free(lists_dir);
  1418. +
  1419. +#ifdef CONFIG_CLEAR_SW_INSTALL_FLAG
  1420. +#warning here
  1421. + /* clear SW_INSTALL on any package where state is SS_NOT_INSTALLED.
  1422. + * this is a hack to work around poor bookkeeping in old ipkg upgrade code
  1423. + * -Jamey 3/1/03
  1424. + */
  1425. + {
  1426. + int i;
  1427. + int changed = 0;
  1428. + pkg_vec_t *available = pkg_vec_alloc();
  1429. + pkg_hash_fetch_available(&conf->pkg_hash, available);
  1430. + ipkg_message(conf, IPKG_DEBUG, "Clearing SW_INSTALL for SS_NOT_INSTALLED packages.\n");
  1431. + for (i = 0; i < available->len; i++) {
  1432. + pkg_t *pkg = available->pkgs[i];
  1433. + if (pkg->state_want == SW_INSTALL && pkg->state_status == SS_NOT_INSTALLED) {
  1434. + ipkg_message(conf, IPKG_DEBUG, "Clearing SW_INSTALL on package %s.\n", pkg->name);
  1435. + pkg->state_want = SW_UNKNOWN;
  1436. + changed = 1;
  1437. + }
  1438. + }
  1439. + pkg_vec_free(available);
  1440. + if (changed) {
  1441. + write_status_files_if_changed(conf);
  1442. + }
  1443. + }
  1444. +#endif
  1445. +
  1446. + return failures;
  1447. +}
  1448. +
  1449. +
  1450. +/* scan the args passed and cache the local filenames of the packages */
  1451. +int ipkg_multiple_files_scan(ipkg_conf_t *conf, int argc, char **argv)
  1452. +{
  1453. + int i;
  1454. + int err;
  1455. +
  1456. + /*
  1457. + * First scan through package names/urls
  1458. + * For any urls, download the packages and install in database.
  1459. + * For any files, install package info in database.
  1460. + */
  1461. + for (i = 0; i < argc; i ++) {
  1462. + char *filename = argv [i];
  1463. + //char *tmp = basename (tmp);
  1464. + //int tmplen = strlen (tmp);
  1465. +
  1466. + //if (strcmp (tmp + (tmplen - strlen (IPKG_PKG_EXTENSION)), IPKG_PKG_EXTENSION) != 0)
  1467. + // continue;
  1468. + //if (strcmp (tmp + (tmplen - strlen (DPKG_PKG_EXTENSION)), DPKG_PKG_EXTENSION) != 0)
  1469. + // continue;
  1470. +
  1471. + ipkg_message(conf, IPKG_DEBUG2, "Debug mfs: %s \n",filename );
  1472. +
  1473. + err = ipkg_prepare_url_for_install(conf, filename, &argv[i]);
  1474. + if (err)
  1475. + return err;
  1476. + }
  1477. + return 0;
  1478. +}
  1479. +
  1480. +struct ipkg_intercept
  1481. +{
  1482. + char *oldpath;
  1483. + char *statedir;
  1484. +};
  1485. +
  1486. +typedef struct ipkg_intercept *ipkg_intercept_t;
  1487. +ipkg_intercept_t ipkg_prep_intercepts(void);
  1488. +
  1489. +ipkg_intercept_t ipkg_prep_intercepts(void)
  1490. +{
  1491. + ipkg_intercept_t ctx;
  1492. + char *newpath;
  1493. + int gen;
  1494. +
  1495. + ctx = malloc (sizeof (*ctx));
  1496. + ctx->oldpath = strdup (getenv ("PATH"));
  1497. +
  1498. + sprintf_alloc (&newpath, "%s/ipkg/intercept:%s", IPKGLIBDIR, ctx->oldpath);
  1499. + setenv ("PATH", newpath, 1);
  1500. + free (newpath);
  1501. +
  1502. + gen = 0;
  1503. + retry:
  1504. + sprintf_alloc (&ctx->statedir, "/tmp/ipkg-intercept-%d-%d", getpid (), gen);
  1505. + if (mkdir (ctx->statedir, 0770) < 0) {
  1506. + if (errno == EEXIST) {
  1507. + free (ctx->statedir);
  1508. + gen++;
  1509. + goto retry;
  1510. + }
  1511. + perror (ctx->statedir);
  1512. + return NULL;
  1513. + }
  1514. + setenv ("IPKG_INTERCEPT_DIR", ctx->statedir, 1);
  1515. + return ctx;
  1516. +}
  1517. +
  1518. +int ipkg_finalize_intercepts(ipkg_intercept_t ctx);
  1519. +
  1520. +int ipkg_finalize_intercepts(ipkg_intercept_t ctx)
  1521. +{
  1522. + char *cmd;
  1523. + DIR *dir;
  1524. + int err = 0;
  1525. +
  1526. + setenv ("PATH", ctx->oldpath, 1);
  1527. + free (ctx->oldpath);
  1528. +
  1529. + dir = opendir (ctx->statedir);
  1530. + if (dir) {
  1531. + struct dirent *de;
  1532. + while (de = readdir (dir), de != NULL) {
  1533. + char *path;
  1534. +
  1535. + if (de->d_name[0] == '.')
  1536. + continue;
  1537. +
  1538. + sprintf_alloc (&path, "%s/%s", ctx->statedir, de->d_name);
  1539. + if (access (path, X_OK) == 0) {
  1540. + if (system (path)) {
  1541. + err = errno;
  1542. + perror (de->d_name);
  1543. + }
  1544. + }
  1545. + free (path);
  1546. + }
  1547. + } else
  1548. + perror (ctx->statedir);
  1549. +
  1550. + sprintf_alloc (&cmd, "rm -rf %s", ctx->statedir);
  1551. + system (cmd);
  1552. + free (cmd);
  1553. +
  1554. + free (ctx->statedir);
  1555. + free (ctx);
  1556. +
  1557. + return err;
  1558. +}
  1559. +
  1560. +int ipkg_configure_packages(ipkg_conf_t *conf, char *pkg_name)
  1561. +{
  1562. + pkg_vec_t *all;
  1563. + int i;
  1564. + pkg_t *pkg;
  1565. + ipkg_intercept_t ic;
  1566. + int r, err = 0;
  1567. +
  1568. + ipkg_message(conf, IPKG_INFO,
  1569. + "Configuring unpacked packages\n");
  1570. + fflush( stdout );
  1571. +
  1572. + all = pkg_vec_alloc();
  1573. + pkg_hash_fetch_available(&conf->pkg_hash, all);
  1574. +
  1575. + ic = ipkg_prep_intercepts();
  1576. +
  1577. + for(i = 0; i < all->len; i++) {
  1578. + pkg = all->pkgs[i];
  1579. +
  1580. + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
  1581. + continue;
  1582. +
  1583. + if (pkg->state_status == SS_UNPACKED) {
  1584. + ipkg_message(conf, IPKG_NOTICE,
  1585. + "Configuring %s\n", pkg->name);
  1586. + fflush( stdout );
  1587. + r = ipkg_configure(conf, pkg);
  1588. + if (r == 0) {
  1589. + pkg->state_status = SS_INSTALLED;
  1590. + pkg->parent->state_status = SS_INSTALLED;
  1591. + pkg->state_flag &= ~SF_PREFER;
  1592. + } else {
  1593. + if (!err)
  1594. + err = r;
  1595. + }
  1596. + }
  1597. + }
  1598. +
  1599. + r = ipkg_finalize_intercepts (ic);
  1600. + if (r && !err)
  1601. + err = r;
  1602. +
  1603. + pkg_vec_free(all);
  1604. + return err;
  1605. +}
  1606. +
  1607. +static void sigint_handler(int sig)
  1608. +{
  1609. + signal(sig, SIG_DFL);
  1610. + ipkg_message(NULL, IPKG_NOTICE,
  1611. + "ipkg: interrupted. writing out status database\n");
  1612. + write_status_files_if_changed(global_conf);
  1613. + exit(128 + sig);
  1614. +}
  1615. +
  1616. +static int ipkg_install_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1617. +{
  1618. + int i;
  1619. + char *arg;
  1620. + int err=0;
  1621. +
  1622. + global_conf = conf;
  1623. + signal(SIGINT, sigint_handler);
  1624. +
  1625. + /*
  1626. + * Now scan through package names and install
  1627. + */
  1628. + for (i=0; i < argc; i++) {
  1629. + arg = argv[i];
  1630. +
  1631. + ipkg_message(conf, IPKG_DEBUG2, "Debug install_cmd: %s \n",arg );
  1632. + err = ipkg_prepare_url_for_install(conf, arg, &argv[i]);
  1633. + if (err != EINVAL && err != 0)
  1634. + return err;
  1635. + }
  1636. + pkg_info_preinstall_check(conf);
  1637. +
  1638. + for (i=0; i < argc; i++) {
  1639. + arg = argv[i];
  1640. + if (conf->multiple_providers)
  1641. + err = ipkg_install_multi_by_name(conf, arg);
  1642. + else{
  1643. + err = ipkg_install_by_name(conf, arg);
  1644. + }
  1645. + if (err == IPKG_PKG_HAS_NO_CANDIDATE) {
  1646. + ipkg_message(conf, IPKG_ERROR,
  1647. + "Cannot find package %s.\n"
  1648. + "Check the spelling or perhaps run 'ipkg update'\n",
  1649. + arg);
  1650. + }
  1651. + }
  1652. +
  1653. + /* recheck to verify that all dependences are satisfied */
  1654. + if (0) ipkg_satisfy_all_dependences(conf);
  1655. +
  1656. + ipkg_configure_packages(conf, NULL);
  1657. +
  1658. + write_status_files_if_changed(conf);
  1659. +
  1660. + return err;
  1661. +}
  1662. +
  1663. +static int ipkg_upgrade_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1664. +{
  1665. + int i;
  1666. + pkg_t *pkg;
  1667. + int err;
  1668. +
  1669. + global_conf = conf;
  1670. + signal(SIGINT, sigint_handler);
  1671. +
  1672. + if (argc) {
  1673. + for (i=0; i < argc; i++) {
  1674. + char *arg = argv[i];
  1675. +
  1676. + err = ipkg_prepare_url_for_install(conf, arg, &arg);
  1677. + if (err != EINVAL && err != 0)
  1678. + return err;
  1679. + }
  1680. + pkg_info_preinstall_check(conf);
  1681. +
  1682. + for (i=0; i < argc; i++) {
  1683. + char *arg = argv[i];
  1684. + if (conf->restrict_to_default_dest) {
  1685. + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
  1686. + argv[i],
  1687. + conf->default_dest);
  1688. + if (pkg == NULL) {
  1689. + ipkg_message(conf, IPKG_NOTICE,
  1690. + "Package %s not installed in %s\n",
  1691. + argv[i], conf->default_dest->name);
  1692. + continue;
  1693. + }
  1694. + } else {
  1695. + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash,
  1696. + argv[i]);
  1697. + }
  1698. + if (pkg)
  1699. + ipkg_upgrade_pkg(conf, pkg);
  1700. + else {
  1701. + ipkg_install_by_name(conf, arg);
  1702. + }
  1703. + }
  1704. + } else {
  1705. + pkg_vec_t *installed = pkg_vec_alloc();
  1706. +
  1707. + pkg_info_preinstall_check(conf);
  1708. +
  1709. + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
  1710. + for (i = 0; i < installed->len; i++) {
  1711. + pkg = installed->pkgs[i];
  1712. + ipkg_upgrade_pkg(conf, pkg);
  1713. + }
  1714. + pkg_vec_free(installed);
  1715. + }
  1716. +
  1717. + /* recheck to verify that all dependences are satisfied */
  1718. + if (0) ipkg_satisfy_all_dependences(conf);
  1719. +
  1720. + ipkg_configure_packages(conf, NULL);
  1721. +
  1722. + write_status_files_if_changed(conf);
  1723. +
  1724. + return 0;
  1725. +}
  1726. +
  1727. +static int ipkg_download_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1728. +{
  1729. + int i, err;
  1730. + char *arg;
  1731. + pkg_t *pkg;
  1732. +
  1733. + pkg_info_preinstall_check(conf);
  1734. + for (i = 0; i < argc; i++) {
  1735. + arg = argv[i];
  1736. +
  1737. + pkg = pkg_hash_fetch_best_installation_candidate_by_name(conf, arg);
  1738. + if (pkg == NULL) {
  1739. + ipkg_message(conf, IPKG_ERROR,
  1740. + "Cannot find package %s.\n"
  1741. + "Check the spelling or perhaps run 'ipkg update'\n",
  1742. + arg);
  1743. + continue;
  1744. + }
  1745. +
  1746. + err = ipkg_download_pkg(conf, pkg, ".");
  1747. +
  1748. + if (err) {
  1749. + ipkg_message(conf, IPKG_ERROR,
  1750. + "Failed to download %s\n", pkg->name);
  1751. + } else {
  1752. + ipkg_message(conf, IPKG_NOTICE,
  1753. + "Downloaded %s as %s\n",
  1754. + pkg->name, pkg->local_filename);
  1755. + }
  1756. + }
  1757. +
  1758. + return 0;
  1759. +}
  1760. +
  1761. +
  1762. +static int ipkg_list_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1763. +{
  1764. + int i ;
  1765. + pkg_vec_t *available;
  1766. + pkg_t *pkg;
  1767. + char desc_short[IPKG_LIST_DESCRIPTION_LENGTH];
  1768. + char *newline;
  1769. + char *pkg_name = NULL;
  1770. + char *version_str;
  1771. +
  1772. + if (argc > 0) {
  1773. + pkg_name = argv[0];
  1774. + }
  1775. + available = pkg_vec_alloc();
  1776. + pkg_hash_fetch_available(&conf->pkg_hash, available);
  1777. + for (i=0; i < available->len; i++) {
  1778. + pkg = available->pkgs[i];
  1779. + /* if we have package name or pattern and pkg does not match, then skip it */
  1780. + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
  1781. + continue;
  1782. + if (pkg->description) {
  1783. + strncpy(desc_short, pkg->description, IPKG_LIST_DESCRIPTION_LENGTH);
  1784. + } else {
  1785. + desc_short[0] = '\0';
  1786. + }
  1787. + desc_short[IPKG_LIST_DESCRIPTION_LENGTH - 1] = '\0';
  1788. + newline = strchr(desc_short, '\n');
  1789. + if (newline) {
  1790. + *newline = '\0';
  1791. + }
  1792. + if (ipkg_cb_list) {
  1793. + version_str = pkg_version_str_alloc(pkg);
  1794. + ipkg_cb_list(pkg->name,desc_short,
  1795. + version_str,
  1796. + pkg->state_status,
  1797. + p_userdata);
  1798. + free(version_str);
  1799. + }
  1800. + }
  1801. + pkg_vec_free(available);
  1802. +
  1803. + return 0;
  1804. +}
  1805. +
  1806. +
  1807. +static int ipkg_list_installed_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1808. +{
  1809. + int i ;
  1810. + pkg_vec_t *available;
  1811. + pkg_t *pkg;
  1812. + char desc_short[IPKG_LIST_DESCRIPTION_LENGTH];
  1813. + char *newline;
  1814. + char *pkg_name = NULL;
  1815. + char *version_str;
  1816. +
  1817. + if (argc > 0) {
  1818. + pkg_name = argv[0];
  1819. + }
  1820. + available = pkg_vec_alloc();
  1821. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
  1822. + for (i=0; i < available->len; i++) {
  1823. + pkg = available->pkgs[i];
  1824. + /* if we have package name or pattern and pkg does not match, then skip it */
  1825. + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
  1826. + continue;
  1827. + if (pkg->description) {
  1828. + strncpy(desc_short, pkg->description, IPKG_LIST_DESCRIPTION_LENGTH);
  1829. + } else {
  1830. + desc_short[0] = '\0';
  1831. + }
  1832. + desc_short[IPKG_LIST_DESCRIPTION_LENGTH - 1] = '\0';
  1833. + newline = strchr(desc_short, '\n');
  1834. + if (newline) {
  1835. + *newline = '\0';
  1836. + }
  1837. + if (ipkg_cb_list) {
  1838. + version_str = pkg_version_str_alloc(pkg);
  1839. + ipkg_cb_list(pkg->name,desc_short,
  1840. + version_str,
  1841. + pkg->state_status,
  1842. + p_userdata);
  1843. + free(version_str);
  1844. + }
  1845. + }
  1846. +
  1847. + return 0;
  1848. +}
  1849. +
  1850. +static int ipkg_info_status_cmd(ipkg_conf_t *conf, int argc, char **argv, int installed_only)
  1851. +{
  1852. + int i;
  1853. + pkg_vec_t *available;
  1854. + pkg_t *pkg;
  1855. + char *pkg_name = NULL;
  1856. + char **pkg_fields = NULL;
  1857. + int n_fields = 0;
  1858. + char *buff ; // = (char *)malloc(1);
  1859. +
  1860. + if (argc > 0) {
  1861. + pkg_name = argv[0];
  1862. + }
  1863. + if (argc > 1) {
  1864. + pkg_fields = &argv[1];
  1865. + n_fields = argc - 1;
  1866. + }
  1867. +
  1868. + available = pkg_vec_alloc();
  1869. + if (installed_only)
  1870. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
  1871. + else
  1872. + pkg_hash_fetch_available(&conf->pkg_hash, available);
  1873. + for (i=0; i < available->len; i++) {
  1874. + pkg = available->pkgs[i];
  1875. + if (pkg_name && fnmatch(pkg_name, pkg->name, 0)) {
  1876. + continue;
  1877. + }
  1878. + buff = pkg_formatted_info(pkg);
  1879. + if ( buff ) {
  1880. + if (ipkg_cb_status) ipkg_cb_status(pkg->name,
  1881. + pkg->state_status,
  1882. + buff,
  1883. + p_userdata);
  1884. + free(buff);
  1885. + }
  1886. + if (conf->verbosity > 1) {
  1887. + conffile_list_elt_t *iter;
  1888. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  1889. + conffile_t *cf = iter->data;
  1890. + int modified = conffile_has_been_modified(conf, cf);
  1891. + ipkg_message(conf, IPKG_NOTICE, "conffile=%s md5sum=%s modified=%d\n",
  1892. + cf->name, cf->value, modified);
  1893. + }
  1894. + }
  1895. + }
  1896. + pkg_vec_free(available);
  1897. +
  1898. + return 0;
  1899. +}
  1900. +
  1901. +static int ipkg_info_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1902. +{
  1903. + return ipkg_info_status_cmd(conf, argc, argv, 0);
  1904. +}
  1905. +
  1906. +static int ipkg_status_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1907. +{
  1908. + return ipkg_info_status_cmd(conf, argc, argv, 1);
  1909. +}
  1910. +
  1911. +static int ipkg_configure_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1912. +{
  1913. +
  1914. + int err;
  1915. + if (argc > 0) {
  1916. + char *pkg_name = NULL;
  1917. +
  1918. + pkg_name = argv[0];
  1919. +
  1920. + err = ipkg_configure_packages (conf, pkg_name);
  1921. +
  1922. + } else {
  1923. + err = ipkg_configure_packages (conf, NULL);
  1924. + }
  1925. +
  1926. + write_status_files_if_changed(conf);
  1927. +
  1928. + return err;
  1929. +}
  1930. +
  1931. +static int ipkg_install_pending_cmd(ipkg_conf_t *conf)
  1932. +{
  1933. + int i, err;
  1934. + char *globpattern;
  1935. + glob_t globbuf;
  1936. +
  1937. + sprintf_alloc(&globpattern, "%s/*" IPKG_PKG_EXTENSION, conf->pending_dir);
  1938. + err = glob(globpattern, 0, NULL, &globbuf);
  1939. + free(globpattern);
  1940. + if (err) {
  1941. + return 0;
  1942. + }
  1943. +
  1944. + ipkg_message(conf, IPKG_NOTICE,
  1945. + "The following packages in %s will now be installed.\n",
  1946. + conf->pending_dir);
  1947. + for (i = 0; i < globbuf.gl_pathc; i++) {
  1948. + ipkg_message(conf, IPKG_NOTICE,
  1949. + "%s%s", i == 0 ? "" : " ", globbuf.gl_pathv[i]);
  1950. + }
  1951. + ipkg_message(conf, IPKG_NOTICE, "\n");
  1952. + for (i = 0; i < globbuf.gl_pathc; i++) {
  1953. + err = ipkg_install_from_file(conf, globbuf.gl_pathv[i]);
  1954. + if (err == 0) {
  1955. + err = unlink(globbuf.gl_pathv[i]);
  1956. + if (err) {
  1957. + ipkg_message(conf, IPKG_ERROR,
  1958. + "%s: ERROR: failed to unlink %s: %s\n",
  1959. + __FUNCTION__, globbuf.gl_pathv[i], strerror(err));
  1960. + return err;
  1961. + }
  1962. + }
  1963. + }
  1964. + globfree(&globbuf);
  1965. +
  1966. + return err;
  1967. +}
  1968. +
  1969. +static int ipkg_remove_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1970. +{
  1971. + int i,a,done;
  1972. + pkg_t *pkg;
  1973. + pkg_t *pkg_to_remove;
  1974. + pkg_vec_t *available;
  1975. + char *pkg_name = NULL;
  1976. + global_conf = conf;
  1977. + signal(SIGINT, sigint_handler);
  1978. +
  1979. +// ENH: Add the "no pkg removed" just in case.
  1980. +
  1981. + done = 0;
  1982. +
  1983. + available = pkg_vec_alloc();
  1984. + pkg_info_preinstall_check(conf);
  1985. + if ( argc > 0 ) {
  1986. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
  1987. + for (i=0; i < argc; i++) {
  1988. + pkg_name = malloc(strlen(argv[i])+2);
  1989. + strcpy(pkg_name,argv[i]);
  1990. + for (a=0; a < available->len; a++) {
  1991. + pkg = available->pkgs[a];
  1992. + if (pkg_name && fnmatch(pkg_name, pkg->name, 0)) {
  1993. + continue;
  1994. + }
  1995. + if (conf->restrict_to_default_dest) {
  1996. + pkg_to_remove = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
  1997. + pkg->name,
  1998. + conf->default_dest);
  1999. + } else {
  2000. + pkg_to_remove = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name );
  2001. + }
  2002. +
  2003. + if (pkg == NULL) {
  2004. + ipkg_message(conf, IPKG_ERROR, "Package %s is not installed.\n", pkg->name);
  2005. + continue;
  2006. + }
  2007. + if (pkg->state_status == SS_NOT_INSTALLED) { // Added the control, so every already removed package could be skipped
  2008. + ipkg_message(conf, IPKG_ERROR, "Package seems to be %s not installed (STATUS = NOT_INSTALLED).\n", pkg->name);
  2009. + continue;
  2010. + }
  2011. + ipkg_remove_pkg(conf, pkg_to_remove,0);
  2012. + done = 1;
  2013. + }
  2014. + free (pkg_name);
  2015. + }
  2016. + pkg_vec_free(available);
  2017. + } else {
  2018. + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
  2019. + int flagged_pkg_count = 0;
  2020. + int removed;
  2021. +
  2022. + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed_pkgs);
  2023. +
  2024. + for (i = 0; i < installed_pkgs->len; i++) {
  2025. + pkg = installed_pkgs->pkgs[i];
  2026. + if (pkg->state_flag & SF_USER) {
  2027. + flagged_pkg_count++;
  2028. + } else {
  2029. + if (!pkg_has_installed_dependents(pkg, NULL))
  2030. + ipkg_message(conf, IPKG_NOTICE, "Non-user leaf package: %s\n", pkg->name);
  2031. + }
  2032. + }
  2033. + if (!flagged_pkg_count) {
  2034. + ipkg_message(conf, IPKG_NOTICE, "No packages flagged as installed by user, \n"
  2035. + "so refusing to uninstall unflagged non-leaf packages\n");
  2036. + return 0;
  2037. + }
  2038. +
  2039. + /* find packages not flagged SF_USER (i.e., installed to
  2040. + * satisfy a dependence) and not having any dependents, and
  2041. + * remove them */
  2042. + do {
  2043. + removed = 0;
  2044. + for (i = 0; i < installed_pkgs->len; i++) {
  2045. + pkg = installed_pkgs->pkgs[i];
  2046. + if (!(pkg->state_flag & SF_USER)
  2047. + && !pkg_has_installed_dependents(pkg, NULL)) {
  2048. + removed++;
  2049. + ipkg_message(conf, IPKG_NOTICE, "Removing non-user leaf package %s\n");
  2050. + ipkg_remove_pkg(conf, pkg,0);
  2051. + done = 1;
  2052. + }
  2053. + }
  2054. + } while (removed);
  2055. + pkg_vec_free(installed_pkgs);
  2056. + }
  2057. +
  2058. + if ( done == 0 )
  2059. + ipkg_message(conf, IPKG_NOTICE, "No packages removed.\n");
  2060. +
  2061. + write_status_files_if_changed(conf);
  2062. + return 0;
  2063. +}
  2064. +
  2065. +static int ipkg_purge_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2066. +{
  2067. + int i;
  2068. + pkg_t *pkg;
  2069. +
  2070. + global_conf = conf;
  2071. + signal(SIGINT, sigint_handler);
  2072. +
  2073. + pkg_info_preinstall_check(conf);
  2074. +
  2075. + for (i=0; i < argc; i++) {
  2076. + if (conf->restrict_to_default_dest) {
  2077. + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
  2078. + argv[i],
  2079. + conf->default_dest);
  2080. + } else {
  2081. + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, argv[i]);
  2082. + }
  2083. +
  2084. + if (pkg == NULL) {
  2085. + ipkg_message(conf, IPKG_ERROR,
  2086. + "Package %s is not installed.\n", argv[i]);
  2087. + continue;
  2088. + }
  2089. + ipkg_purge_pkg(conf, pkg);
  2090. + }
  2091. +
  2092. + write_status_files_if_changed(conf);
  2093. + return 0;
  2094. +}
  2095. +
  2096. +static int ipkg_flag_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2097. +{
  2098. + int i;
  2099. + pkg_t *pkg;
  2100. + char *flags = argv[0];
  2101. +
  2102. + global_conf = conf;
  2103. + signal(SIGINT, sigint_handler);
  2104. +
  2105. + for (i=1; i < argc; i++) {
  2106. + if (conf->restrict_to_default_dest) {
  2107. + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
  2108. + argv[i],
  2109. + conf->default_dest);
  2110. + } else {
  2111. + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, argv[i]);
  2112. + }
  2113. +
  2114. + if (pkg == NULL) {
  2115. + ipkg_message(conf, IPKG_ERROR,
  2116. + "Package %s is not installed.\n", argv[i]);
  2117. + continue;
  2118. + }
  2119. + if (( strcmp(flags,"hold")==0)||( strcmp(flags,"noprune")==0)||
  2120. + ( strcmp(flags,"user")==0)||( strcmp(flags,"ok")==0)) {
  2121. + pkg->state_flag = pkg_state_flag_from_str(flags);
  2122. + }
  2123. +/* pb_ asked this feature 03292004 */
  2124. +/* Actually I will use only this two, but this is an open for various status */
  2125. + if (( strcmp(flags,"installed")==0)||( strcmp(flags,"unpacked")==0)){
  2126. + pkg->state_status = pkg_state_status_from_str(flags);
  2127. + }
  2128. + ipkg_state_changed++;
  2129. + ipkg_message(conf, IPKG_NOTICE,
  2130. + "Setting flags for package %s to %s\n",
  2131. + pkg->name, flags);
  2132. + }
  2133. +
  2134. + write_status_files_if_changed(conf);
  2135. + return 0;
  2136. +}
  2137. +
  2138. +static int ipkg_files_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2139. +{
  2140. + pkg_t *pkg;
  2141. + str_list_t *installed_files;
  2142. + str_list_elt_t *iter;
  2143. + char *pkg_version;
  2144. + size_t buff_len = 8192;
  2145. + size_t used_len;
  2146. + char *buff ;
  2147. +
  2148. + buff = (char *)malloc(buff_len);
  2149. + if ( buff == NULL ) {
  2150. + fprintf( stderr,"%s: Unable to allocate memory \n",__FUNCTION__);
  2151. + return ENOMEM;
  2152. + }
  2153. +
  2154. + if (argc < 1) {
  2155. + return EINVAL;
  2156. + }
  2157. +
  2158. + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash,
  2159. + argv[0]);
  2160. + if (pkg == NULL) {
  2161. + ipkg_message(conf, IPKG_ERROR,
  2162. + "Package %s not installed.\n", argv[0]);
  2163. + return 0;
  2164. + }
  2165. +
  2166. + installed_files = pkg_get_installed_files(pkg);
  2167. + pkg_version = pkg_version_str_alloc(pkg);
  2168. +
  2169. + printf("Package %s (%s) is installed on %s and has the following files:\n",
  2170. + pkg->name, pkg_version, pkg->dest->name);
  2171. + for (iter = installed_files->head; iter; iter = iter->next) {
  2172. + puts(iter->data);
  2173. + }
  2174. +
  2175. + free(pkg_version);
  2176. + pkg_free_installed_files(pkg);
  2177. +
  2178. + return 0;
  2179. +}
  2180. +
  2181. +static int ipkg_depends_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2182. +{
  2183. +
  2184. + if (argc > 0) {
  2185. + pkg_vec_t *available_pkgs = pkg_vec_alloc();
  2186. + const char *rel_str = "depends on";
  2187. + int i;
  2188. +
  2189. + pkg_info_preinstall_check(conf);
  2190. +
  2191. + if (conf->query_all)
  2192. + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
  2193. + else
  2194. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
  2195. + for (i = 0; i < argc; i++) {
  2196. + const char *target = argv[i];
  2197. + int j;
  2198. +
  2199. + ipkg_message(conf, IPKG_ERROR, "target=%s\n", target);
  2200. +
  2201. + for (j = 0; j < available_pkgs->len; j++) {
  2202. + pkg_t *pkg = available_pkgs->pkgs[j];
  2203. + if (fnmatch(target, pkg->name, 0) == 0) {
  2204. + int k;
  2205. + int count = pkg->depends_count + pkg->pre_depends_count;
  2206. + ipkg_message(conf, IPKG_ERROR, "What %s (arch=%s) %s\n",
  2207. + target, pkg->architecture, rel_str);
  2208. + for (k = 0; k < count; k++) {
  2209. + compound_depend_t *cdepend = &pkg->depends[k];
  2210. + int l;
  2211. + for (l = 0; l < cdepend->possibility_count; l++) {
  2212. + depend_t *possibility = cdepend->possibilities[l];
  2213. + ipkg_message(conf, IPKG_ERROR, " %s", possibility->pkg->name);
  2214. + if (conf->verbosity > 0) {
  2215. + // char *ver = abstract_pkg_version_str_alloc(possibility->pkg);
  2216. + ipkg_message(conf, IPKG_NOTICE, " %s", possibility->version);
  2217. + if (possibility->version) {
  2218. + const char *typestr = NULL;
  2219. + switch (possibility->constraint) {
  2220. + case NONE: typestr = "none"; break;
  2221. + case EARLIER: typestr = "<"; break;
  2222. + case EARLIER_EQUAL: typestr = "<="; break;
  2223. + case EQUAL: typestr = "="; break;
  2224. + case LATER_EQUAL: typestr = ">="; break;
  2225. + case LATER: typestr = ">"; break;
  2226. + }
  2227. + ipkg_message(conf, IPKG_NOTICE, " (%s %s)", typestr, possibility->version);
  2228. + }
  2229. + // free(ver);
  2230. + }
  2231. + ipkg_message(conf, IPKG_ERROR, "\n");
  2232. + }
  2233. + }
  2234. + }
  2235. + }
  2236. + }
  2237. + pkg_vec_free(available_pkgs);
  2238. + }
  2239. + return 0;
  2240. +}
  2241. +
  2242. +enum what_field_type {
  2243. + WHATDEPENDS,
  2244. + WHATCONFLICTS,
  2245. + WHATPROVIDES,
  2246. + WHATREPLACES,
  2247. + WHATRECOMMENDS,
  2248. + WHATSUGGESTS
  2249. +};
  2250. +
  2251. +static int ipkg_what_depends_conflicts_cmd(ipkg_conf_t *conf, enum what_field_type what_field_type, int recursive, int argc, char **argv)
  2252. +{
  2253. +
  2254. + if (argc > 0) {
  2255. + pkg_vec_t *available_pkgs = pkg_vec_alloc();
  2256. + const char *rel_str = NULL;
  2257. + int i;
  2258. + int changed;
  2259. +
  2260. + switch (what_field_type) {
  2261. + case WHATDEPENDS: rel_str = "depends on"; break;
  2262. + case WHATCONFLICTS: rel_str = "conflicts with"; break;
  2263. + case WHATSUGGESTS: rel_str = "suggests"; break;
  2264. + case WHATRECOMMENDS: rel_str = "recommends"; break;
  2265. + case WHATPROVIDES: rel_str = "provides"; break;
  2266. + case WHATREPLACES: rel_str = "replaces"; break;
  2267. + }
  2268. +
  2269. + if (conf->query_all)
  2270. + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
  2271. + else
  2272. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
  2273. +
  2274. + /* mark the root set */
  2275. + pkg_vec_clear_marks(available_pkgs);
  2276. + ipkg_message(conf, IPKG_NOTICE, "Root set:\n");
  2277. + for (i = 0; i < argc; i++) {
  2278. + const char *dependee_pattern = argv[i];
  2279. + pkg_vec_mark_if_matches(available_pkgs, dependee_pattern);
  2280. + }
  2281. + for (i = 0; i < available_pkgs->len; i++) {
  2282. + pkg_t *pkg = available_pkgs->pkgs[i];
  2283. + if (pkg->state_flag & SF_MARKED) {
  2284. + /* mark the parent (abstract) package */
  2285. + pkg_mark_provides(pkg);
  2286. + ipkg_message(conf, IPKG_NOTICE, " %s\n", pkg->name);
  2287. + }
  2288. + }
  2289. +
  2290. + ipkg_message(conf, IPKG_NOTICE, "What %s root set\n", rel_str);
  2291. + do {
  2292. + int j;
  2293. + changed = 0;
  2294. +
  2295. + for (j = 0; j < available_pkgs->len; j++) {
  2296. + pkg_t *pkg = available_pkgs->pkgs[j];
  2297. + int k;
  2298. + int count = ((what_field_type == WHATCONFLICTS)
  2299. + ? pkg->conflicts_count
  2300. + : pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count);
  2301. + /* skip this package if it is already marked */
  2302. + if (pkg->parent->state_flag & SF_MARKED) {
  2303. + continue;
  2304. + }
  2305. + for (k = 0; k < count; k++) {
  2306. + compound_depend_t *cdepend =
  2307. + (what_field_type == WHATCONFLICTS) ? &pkg->conflicts[k] : &pkg->depends[k];
  2308. + int l;
  2309. + for (l = 0; l < cdepend->possibility_count; l++) {
  2310. + depend_t *possibility = cdepend->possibilities[l];
  2311. + if (possibility->pkg->state_flag & SF_MARKED) {
  2312. + /* mark the depending package so we won't visit it again */
  2313. + pkg->state_flag |= SF_MARKED;
  2314. + pkg_mark_provides(pkg);
  2315. + changed++;
  2316. +
  2317. + ipkg_message(conf, IPKG_NOTICE, " %s", pkg->name);
  2318. + if (conf->verbosity > 0) {
  2319. + char *ver = pkg_version_str_alloc(pkg);
  2320. + ipkg_message(conf, IPKG_NOTICE, " %s", ver);
  2321. + ipkg_message(conf, IPKG_NOTICE, "\t%s %s", rel_str, possibility->pkg->name);
  2322. + if (possibility->version) {
  2323. + const char *typestr = NULL;
  2324. + switch (possibility->constraint) {
  2325. + case NONE: typestr = "none"; break;
  2326. + case EARLIER: typestr = "<"; break;
  2327. + case EARLIER_EQUAL: typestr = "<="; break;
  2328. + case EQUAL: typestr = "="; break;
  2329. + case LATER_EQUAL: typestr = ">="; break;
  2330. + case LATER: typestr = ">"; break;
  2331. + }
  2332. + ipkg_message(conf, IPKG_NOTICE, " (%s %s)", typestr, possibility->version);
  2333. + }
  2334. + free(ver);
  2335. + if (!pkg_dependence_satisfiable(possibility))
  2336. + ipkg_message(conf, IPKG_NOTICE, " unsatisfiable");
  2337. + }
  2338. + ipkg_message(conf, IPKG_NOTICE, "\n");
  2339. + goto next_package;
  2340. + }
  2341. + }
  2342. + }
  2343. + next_package:
  2344. + ;
  2345. + }
  2346. + } while (changed && recursive);
  2347. + pkg_vec_free(available_pkgs);
  2348. + }
  2349. +
  2350. + return 0;
  2351. +}
  2352. +
  2353. +int pkg_mark_provides(pkg_t *pkg)
  2354. +{
  2355. + int provides_count = pkg->provides_count;
  2356. + abstract_pkg_t **provides = pkg->provides;
  2357. + int i;
  2358. + pkg->parent->state_flag |= SF_MARKED;
  2359. + for (i = 0; i < provides_count; i++) {
  2360. + provides[i]->state_flag |= SF_MARKED;
  2361. + }
  2362. + return 0;
  2363. +}
  2364. +
  2365. +static int ipkg_whatdepends_recursively_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2366. +{
  2367. + return ipkg_what_depends_conflicts_cmd(conf, WHATDEPENDS, 1, argc, argv);
  2368. +}
  2369. +static int ipkg_whatdepends_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2370. +{
  2371. + return ipkg_what_depends_conflicts_cmd(conf, WHATDEPENDS, 0, argc, argv);
  2372. +}
  2373. +
  2374. +static int ipkg_whatsuggests_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2375. +{
  2376. + return ipkg_what_depends_conflicts_cmd(conf, WHATSUGGESTS, 0, argc, argv);
  2377. +}
  2378. +
  2379. +static int ipkg_whatrecommends_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2380. +{
  2381. + return ipkg_what_depends_conflicts_cmd(conf, WHATRECOMMENDS, 0, argc, argv);
  2382. +}
  2383. +
  2384. +static int ipkg_whatconflicts_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2385. +{
  2386. + return ipkg_what_depends_conflicts_cmd(conf, WHATCONFLICTS, 0, argc, argv);
  2387. +}
  2388. +
  2389. +static int ipkg_what_provides_replaces_cmd(ipkg_conf_t *conf, enum what_field_type what_field_type, int argc, char **argv)
  2390. +{
  2391. +
  2392. + if (argc > 0) {
  2393. + pkg_vec_t *available_pkgs = pkg_vec_alloc();
  2394. + const char *rel_str = (what_field_type == WHATPROVIDES ? "provides" : "replaces");
  2395. + int i;
  2396. +
  2397. + pkg_info_preinstall_check(conf);
  2398. +
  2399. + if (conf->query_all)
  2400. + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
  2401. + else
  2402. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
  2403. + for (i = 0; i < argc; i++) {
  2404. + const char *target = argv[i];
  2405. + int j;
  2406. +
  2407. + ipkg_message(conf, IPKG_ERROR, "What %s %s\n",
  2408. + rel_str, target);
  2409. + for (j = 0; j < available_pkgs->len; j++) {
  2410. + pkg_t *pkg = available_pkgs->pkgs[j];
  2411. + int k;
  2412. + int count = (what_field_type == WHATPROVIDES) ? pkg->provides_count : pkg->replaces_count;
  2413. + for (k = 0; k < count; k++) {
  2414. + abstract_pkg_t *apkg =
  2415. + ((what_field_type == WHATPROVIDES)
  2416. + ? pkg->provides[k]
  2417. + : pkg->replaces[k]);
  2418. + if (fnmatch(target, apkg->name, 0) == 0) {
  2419. + ipkg_message(conf, IPKG_ERROR, " %s", pkg->name);
  2420. + if (strcmp(target, apkg->name) != 0)
  2421. + ipkg_message(conf, IPKG_ERROR, "\t%s %s\n", rel_str, apkg->name);
  2422. + ipkg_message(conf, IPKG_ERROR, "\n");
  2423. + }
  2424. + }
  2425. + }
  2426. + }
  2427. + pkg_vec_free(available_pkgs);
  2428. + }
  2429. + return 0;
  2430. +}
  2431. +
  2432. +static int ipkg_whatprovides_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2433. +{
  2434. + return ipkg_what_provides_replaces_cmd(conf, WHATPROVIDES, argc, argv);
  2435. +}
  2436. +
  2437. +static int ipkg_whatreplaces_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2438. +{
  2439. + return ipkg_what_provides_replaces_cmd(conf, WHATREPLACES, argc, argv);
  2440. +}
  2441. +
  2442. +static int ipkg_search_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2443. +{
  2444. + int i;
  2445. +
  2446. + pkg_vec_t *installed;
  2447. + pkg_t *pkg;
  2448. + str_list_t *installed_files;
  2449. + str_list_elt_t *iter;
  2450. + char *installed_file;
  2451. +
  2452. + if (argc < 1) {
  2453. + return EINVAL;
  2454. + }
  2455. +
  2456. + installed = pkg_vec_alloc();
  2457. + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
  2458. +
  2459. + for (i=0; i < installed->len; i++) {
  2460. + pkg = installed->pkgs[i];
  2461. +
  2462. + installed_files = pkg_get_installed_files(pkg);
  2463. +
  2464. + for (iter = installed_files->head; iter; iter = iter->next) {
  2465. + installed_file = iter->data;
  2466. + if (fnmatch(argv[0], installed_file, 0)==0) {
  2467. + if (ipkg_cb_list) ipkg_cb_list(pkg->name,
  2468. + installed_file,
  2469. + pkg_version_str_alloc(pkg),
  2470. + pkg->state_status, p_userdata);
  2471. + }
  2472. + }
  2473. +
  2474. + pkg_free_installed_files(pkg);
  2475. + }
  2476. +
  2477. + /* XXX: CLEANUP: It's not obvious from the name of
  2478. + pkg_hash_fetch_all_installed that we need to call
  2479. + pkg_vec_free to avoid a memory leak. */
  2480. + pkg_vec_free(installed);
  2481. +
  2482. + return 0;
  2483. +}
  2484. +
  2485. +static int ipkg_compare_versions_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2486. +{
  2487. + if (argc == 3) {
  2488. + /* this is a bit gross */
  2489. + struct pkg p1, p2;
  2490. + parseVersion(&p1, argv[0]);
  2491. + parseVersion(&p2, argv[2]);
  2492. + return pkg_version_satisfied(&p1, &p2, argv[1]);
  2493. + } else {
  2494. + ipkg_message(conf, IPKG_ERROR,
  2495. + "ipkg compare_versions <v1> <op> <v2>\n"
  2496. + "<op> is one of <= >= << >> =\n");
  2497. + return -1;
  2498. + }
  2499. +}
  2500. +
  2501. +#ifndef HOST_CPU_STR
  2502. +#define HOST_CPU_STR__(X) #X
  2503. +#define HOST_CPU_STR_(X) HOST_CPU_STR__(X)
  2504. +#define HOST_CPU_STR HOST_CPU_STR_(HOST_CPU_FOO)
  2505. +#endif
  2506. +
  2507. +static int ipkg_print_architecture_cmd(ipkg_conf_t *conf)
  2508. +{
  2509. + nv_pair_list_elt_t *l;
  2510. +
  2511. + l = conf->arch_list.head;
  2512. + while (l) {
  2513. + nv_pair_t *nv = l->data;
  2514. + printf("arch %s %s\n", nv->name, nv->value);
  2515. + l = l->next;
  2516. + }
  2517. + return 0;
  2518. +}
  2519. +
  2520. +
  2521. diff -Nur busybox-1.19.4.orig/archival/libipkg/ipkg_cmd.h busybox-1.19.4/archival/libipkg/ipkg_cmd.h
  2522. --- busybox-1.19.4.orig/archival/libipkg/ipkg_cmd.h 1970-01-01 01:00:00.000000000 +0100
  2523. +++ busybox-1.19.4/archival/libipkg/ipkg_cmd.h 2012-03-17 00:58:08.193100680 +0100
  2524. @@ -0,0 +1,41 @@
  2525. +/* ipkg_cmd.h - the itsy package management system
  2526. +
  2527. + Carl D. Worth
  2528. +
  2529. + Copyright (C) 2001 University of Southern California
  2530. +
  2531. + This program is free software; you can redistribute it and/or
  2532. + modify it under the terms of the GNU General Public License as
  2533. + published by the Free Software Foundation; either version 2, or (at
  2534. + your option) any later version.
  2535. +
  2536. + This program is distributed in the hope that it will be useful, but
  2537. + WITHOUT ANY WARRANTY; without even the implied warranty of
  2538. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  2539. + General Public License for more details.
  2540. +*/
  2541. +
  2542. +#ifndef IPKG_CMD_H
  2543. +#define IPKG_CMD_H
  2544. +
  2545. +typedef int (*ipkg_cmd_fun_t)(ipkg_conf_t *conf, int argc, const char **argv);
  2546. +
  2547. +struct ipkg_cmd
  2548. +{
  2549. + const char *name;
  2550. + int requires_args;
  2551. + ipkg_cmd_fun_t fun;
  2552. +};
  2553. +typedef struct ipkg_cmd ipkg_cmd_t;
  2554. +
  2555. +ipkg_cmd_t *ipkg_cmd_find(const char *name);
  2556. +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc,
  2557. + const char **argv, void *userdata);
  2558. +int ipkg_multiple_files_scan (ipkg_conf_t *conf, int argc, char *argv[]);
  2559. +/* install any packges with state_want == SW_INSTALL */
  2560. +int ipkg_install_wanted_packages(ipkg_conf_t *conf);
  2561. +/* ensure that all dependences are satisfied */
  2562. +int ipkg_configure_packages(ipkg_conf_t *conf, char *pkg_name);
  2563. +int pkg_mark_provides(pkg_t *pkg);
  2564. +
  2565. +#endif
  2566. diff -Nur busybox-1.19.4.orig/archival/libipkg/ipkg_conf.c busybox-1.19.4/archival/libipkg/ipkg_conf.c
  2567. --- busybox-1.19.4.orig/archival/libipkg/ipkg_conf.c 1970-01-01 01:00:00.000000000 +0100
  2568. +++ busybox-1.19.4/archival/libipkg/ipkg_conf.c 2012-03-17 00:58:08.193100680 +0100
  2569. @@ -0,0 +1,711 @@
  2570. +/* ipkg_conf.c - the itsy package management system
  2571. +
  2572. + Carl D. Worth
  2573. +
  2574. + Copyright (C) 2001 University of Southern California
  2575. +
  2576. + This program is free software; you can redistribute it and/or
  2577. + modify it under the terms of the GNU General Public License as
  2578. + published by the Free Software Foundation; either version 2, or (at
  2579. + your option) any later version.
  2580. +
  2581. + This program is distributed in the hope that it will be useful, but
  2582. + WITHOUT ANY WARRANTY; without even the implied warranty of
  2583. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  2584. + General Public License for more details.
  2585. +*/
  2586. +
  2587. +#include <glob.h>
  2588. +
  2589. +#include "ipkg.h"
  2590. +#include "ipkg_conf.h"
  2591. +
  2592. +#include "xregex.h"
  2593. +#include "sprintf_alloc.h"
  2594. +#include "ipkg_conf.h"
  2595. +#include "ipkg_message.h"
  2596. +#include "file_util.h"
  2597. +#include "str_util.h"
  2598. +#include "xsystem.h"
  2599. +
  2600. +
  2601. +ipkg_conf_t *global_conf;
  2602. +
  2603. +static int ipkg_conf_parse_file(ipkg_conf_t *conf, const char *filename,
  2604. + pkg_src_list_t *pkg_src_list,
  2605. + nv_pair_list_t *tmp_dest_nv_pair_list,
  2606. + char **tmp_lists_dir);
  2607. +static int ipkg_init_options_array(const ipkg_conf_t *conf, ipkg_option_t **options);
  2608. +static int ipkg_conf_set_option(const ipkg_option_t *options,
  2609. + const char *name, const char *value);
  2610. +static int ipkg_conf_set_default_dest(ipkg_conf_t *conf,
  2611. + const char *default_dest_name);
  2612. +static int set_and_load_pkg_src_list(ipkg_conf_t *conf,
  2613. + pkg_src_list_t *nv_pair_list);
  2614. +static int set_and_load_pkg_dest_list(ipkg_conf_t *conf,
  2615. + nv_pair_list_t *nv_pair_list, char * lists_dir);
  2616. +
  2617. +int ipkg_init_options_array(const ipkg_conf_t *conf, ipkg_option_t **options)
  2618. +{
  2619. + ipkg_option_t tmp[] = {
  2620. + { "force_defaults", IPKG_OPT_TYPE_BOOL, &conf->force_defaults },
  2621. + { "force_depends", IPKG_OPT_TYPE_BOOL, &conf->force_depends },
  2622. + { "force_overwrite", IPKG_OPT_TYPE_BOOL, &conf->force_overwrite },
  2623. + { "force_downgrade", IPKG_OPT_TYPE_BOOL, &conf->force_downgrade },
  2624. + { "force_reinstall", IPKG_OPT_TYPE_BOOL, &conf->force_reinstall },
  2625. + { "force_space", IPKG_OPT_TYPE_BOOL, &conf->force_space },
  2626. + { "ftp_proxy", IPKG_OPT_TYPE_STRING, &conf->ftp_proxy },
  2627. + { "http_proxy", IPKG_OPT_TYPE_STRING, &conf->http_proxy },
  2628. + { "multiple_providers", IPKG_OPT_TYPE_BOOL, &conf->multiple_providers },
  2629. + { "no_proxy", IPKG_OPT_TYPE_STRING, &conf->no_proxy },
  2630. + { "test", IPKG_OPT_TYPE_INT, &conf->noaction },
  2631. + { "noaction", IPKG_OPT_TYPE_INT, &conf->noaction },
  2632. + { "nodeps", IPKG_OPT_TYPE_BOOL, &conf->nodeps },
  2633. + { "offline_root", IPKG_OPT_TYPE_STRING, &conf->offline_root },
  2634. + { "offline_root_post_script_cmd", IPKG_OPT_TYPE_STRING, &conf->offline_root_post_script_cmd },
  2635. + { "offline_root_pre_script_cmd", IPKG_OPT_TYPE_STRING, &conf->offline_root_pre_script_cmd },
  2636. + { "proxy_passwd", IPKG_OPT_TYPE_STRING, &conf->proxy_passwd },
  2637. + { "proxy_user", IPKG_OPT_TYPE_STRING, &conf->proxy_user },
  2638. + { "query-all", IPKG_OPT_TYPE_BOOL, &conf->query_all },
  2639. + { "verbose-wget", IPKG_OPT_TYPE_BOOL, &conf->verbose_wget },
  2640. + { "verbosity", IPKG_OPT_TYPE_BOOL, &conf->verbosity },
  2641. + { NULL }
  2642. + };
  2643. +
  2644. + *options = (ipkg_option_t *)malloc(sizeof(tmp));
  2645. + if ( options == NULL ){
  2646. + fprintf(stderr,"%s: Unable to allocate memory\n",__FUNCTION__);
  2647. + return -1;
  2648. + }
  2649. +
  2650. + memcpy(*options, tmp, sizeof(tmp));
  2651. + return 0;
  2652. +};
  2653. +
  2654. +static void ipkg_conf_override_string(char **conf_str, char *arg_str)
  2655. +{
  2656. + if (arg_str) {
  2657. + if (*conf_str) {
  2658. + free(*conf_str);
  2659. + }
  2660. + *conf_str = strdup(arg_str);
  2661. + }
  2662. +}
  2663. +
  2664. +static void ipkg_conf_free_string(char **conf_str)
  2665. +{
  2666. + if (*conf_str) {
  2667. + free(*conf_str);
  2668. + *conf_str = NULL;
  2669. + }
  2670. +}
  2671. +
  2672. +int ipkg_conf_init(ipkg_conf_t *conf, const args_t *args)
  2673. +{
  2674. + int err;
  2675. + char *tmp_dir_base;
  2676. + nv_pair_list_t tmp_dest_nv_pair_list;
  2677. + char * lists_dir =NULL;
  2678. + glob_t globbuf;
  2679. + const char *etc_ipkg_conf_pattern = "/etc/ipkg/*.conf";
  2680. + char *pending_dir =NULL;
  2681. +
  2682. + memset(conf, 0, sizeof(ipkg_conf_t));
  2683. +
  2684. + pkg_src_list_init(&conf->pkg_src_list);
  2685. +
  2686. + nv_pair_list_init(&tmp_dest_nv_pair_list);
  2687. + pkg_dest_list_init(&conf->pkg_dest_list);
  2688. +
  2689. + nv_pair_list_init(&conf->arch_list);
  2690. +
  2691. + conf->restrict_to_default_dest = 0;
  2692. + conf->default_dest = NULL;
  2693. +
  2694. +
  2695. + if (args->tmp_dir)
  2696. + tmp_dir_base = args->tmp_dir;
  2697. + else
  2698. + tmp_dir_base = getenv("TMPDIR");
  2699. + sprintf_alloc(&conf->tmp_dir, "%s/%s",
  2700. + tmp_dir_base ? tmp_dir_base : IPKG_CONF_DEFAULT_TMP_DIR_BASE,
  2701. + IPKG_CONF_TMP_DIR_SUFFIX);
  2702. + conf->tmp_dir = mkdtemp(conf->tmp_dir);
  2703. + if (conf->tmp_dir == NULL) {
  2704. + fprintf(stderr, "%s: Failed to create temporary directory `%s': %s\n",
  2705. + __FUNCTION__, conf->tmp_dir, strerror(errno));
  2706. + return errno;
  2707. + }
  2708. +
  2709. + conf->force_depends = 0;
  2710. + conf->force_defaults = 0;
  2711. + conf->force_overwrite = 0;
  2712. + conf->force_downgrade = 0;
  2713. + conf->force_reinstall = 0;
  2714. + conf->force_space = 0;
  2715. + conf->force_removal_of_essential_packages = 0;
  2716. + conf->force_removal_of_dependent_packages = 0;
  2717. + conf->nodeps = 0;
  2718. + conf->verbose_wget = 0;
  2719. + conf->offline_root = NULL;
  2720. + conf->offline_root_pre_script_cmd = NULL;
  2721. + conf->offline_root_post_script_cmd = NULL;
  2722. + conf->multiple_providers = 0;
  2723. + conf->verbosity = 1;
  2724. + conf->noaction = 0;
  2725. +
  2726. + conf->http_proxy = NULL;
  2727. + conf->ftp_proxy = NULL;
  2728. + conf->no_proxy = NULL;
  2729. + conf->proxy_user = NULL;
  2730. + conf->proxy_passwd = NULL;
  2731. +
  2732. + pkg_hash_init("pkg-hash", &conf->pkg_hash, IPKG_CONF_DEFAULT_HASH_LEN);
  2733. + hash_table_init("file-hash", &conf->file_hash, IPKG_CONF_DEFAULT_HASH_LEN);
  2734. + hash_table_init("obs-file-hash", &conf->obs_file_hash, IPKG_CONF_DEFAULT_HASH_LEN);
  2735. + lists_dir=(char *)malloc(1);
  2736. + lists_dir[0]='\0';
  2737. + if (args->conf_file) {
  2738. + struct stat stat_buf;
  2739. + err = stat(args->conf_file, &stat_buf);
  2740. + if (err == 0)
  2741. + if (ipkg_conf_parse_file(conf, args->conf_file,
  2742. + &conf->pkg_src_list, &tmp_dest_nv_pair_list,&lists_dir)<0) {
  2743. + /* Memory leakage from ipkg_conf_parse-file */
  2744. + return -1;
  2745. + }
  2746. +
  2747. + }
  2748. +
  2749. + /* if (!lists_dir ){*/
  2750. + if (strlen(lists_dir)<=1 ){
  2751. + lists_dir = realloc(lists_dir,strlen(IPKG_CONF_LISTS_DIR)+2);
  2752. + sprintf (lists_dir,"%s",IPKG_CONF_LISTS_DIR);
  2753. + }
  2754. +
  2755. + if (args->offline_root) {
  2756. + char *tmp = malloc(strlen(lists_dir) + strlen(args->offline_root) + 1);
  2757. + sprintf_alloc(&tmp, "%s/%s",args->offline_root,lists_dir);
  2758. + free(lists_dir);
  2759. + lists_dir = tmp;
  2760. + }
  2761. +
  2762. + pending_dir = malloc(strlen(lists_dir)+strlen("/pending")+5);
  2763. + snprintf(pending_dir,strlen(lists_dir)+strlen("/pending") ,"%s%s",lists_dir,"/pending");
  2764. +
  2765. + conf->lists_dir = strdup(lists_dir);
  2766. + conf->pending_dir = strdup(pending_dir);
  2767. +
  2768. + if (args->offline_root)
  2769. + sprintf_alloc(&etc_ipkg_conf_pattern, "%s/etc/ipkg/*.conf", args->offline_root);
  2770. + memset(&globbuf, 0, sizeof(globbuf));
  2771. + err = glob(etc_ipkg_conf_pattern, 0, NULL, &globbuf);
  2772. + if (!err) {
  2773. + int i;
  2774. + for (i = 0; i < globbuf.gl_pathc; i++) {
  2775. + if (globbuf.gl_pathv[i])
  2776. + if ( ipkg_conf_parse_file(conf, globbuf.gl_pathv[i],
  2777. + &conf->pkg_src_list, &tmp_dest_nv_pair_list,&lists_dir)<0) {
  2778. + /* Memory leakage from ipkg_conf_parse-file */
  2779. + return -1;
  2780. + }
  2781. + }
  2782. + }
  2783. + globfree(&globbuf);
  2784. +
  2785. + /* if no architectures were defined, then default all, noarch, and host architecture */
  2786. + if (nv_pair_list_empty(&conf->arch_list)) {
  2787. + nv_pair_list_append(&conf->arch_list, "all", "1");
  2788. + nv_pair_list_append(&conf->arch_list, "noarch", "1");
  2789. + nv_pair_list_append(&conf->arch_list, HOST_CPU_STR, "10");
  2790. + }
  2791. +
  2792. + /* Even if there is no conf file, we'll need at least one dest. */
  2793. + if (tmp_dest_nv_pair_list.head == NULL) {
  2794. + nv_pair_list_append(&tmp_dest_nv_pair_list,
  2795. + IPKG_CONF_DEFAULT_DEST_NAME,
  2796. + IPKG_CONF_DEFAULT_DEST_ROOT_DIR);
  2797. + }
  2798. +
  2799. + /* After parsing the file, set options from command-line, (so that
  2800. + command-line arguments take precedence) */
  2801. + /* XXX: CLEANUP: The interaction between args.c and ipkg_conf.c
  2802. + really needs to be cleaned up. There is so much duplication
  2803. + right now it is ridiculous. Maybe ipkg_conf_t should just save
  2804. + a pointer to args_t (which could then not be freed), rather
  2805. + than duplicating every field here? */
  2806. + if (args->force_depends) {
  2807. + conf->force_depends = 1;
  2808. + }
  2809. + if (args->force_defaults) {
  2810. + conf->force_defaults = 1;
  2811. + }
  2812. + if (args->force_overwrite) {
  2813. + conf->force_overwrite = 1;
  2814. + }
  2815. + if (args->force_downgrade) {
  2816. + conf->force_downgrade = 1;
  2817. + }
  2818. + if (args->force_reinstall) {
  2819. + conf->force_reinstall = 1;
  2820. + }
  2821. + if (args->force_removal_of_dependent_packages) {
  2822. + conf->force_removal_of_dependent_packages = 1;
  2823. + }
  2824. + if (args->force_removal_of_essential_packages) {
  2825. + conf->force_removal_of_essential_packages = 1;
  2826. + }
  2827. + if (args->nodeps) {
  2828. + conf->nodeps = 1;
  2829. + }
  2830. + if (args->noaction) {
  2831. + conf->noaction = 1;
  2832. + }
  2833. + if (args->query_all) {
  2834. + conf->query_all = 1;
  2835. + }
  2836. + if (args->verbose_wget) {
  2837. + conf->verbose_wget = 1;
  2838. + }
  2839. + if (args->multiple_providers) {
  2840. + conf->multiple_providers = 1;
  2841. + }
  2842. + if (args->verbosity != conf->verbosity) {
  2843. + conf->verbosity = args->verbosity;
  2844. + }
  2845. +
  2846. + ipkg_conf_override_string(&conf->offline_root,
  2847. + args->offline_root);
  2848. + ipkg_conf_override_string(&conf->offline_root_pre_script_cmd,
  2849. + args->offline_root_pre_script_cmd);
  2850. + ipkg_conf_override_string(&conf->offline_root_post_script_cmd,
  2851. + args->offline_root_post_script_cmd);
  2852. +
  2853. +/* Pigi: added a flag to disable the checking of structures if the command does not need to
  2854. + read anything from there.
  2855. +*/
  2856. + if ( !(args->nocheckfordirorfile)){
  2857. + /* need to run load the source list before dest list -Jamey */
  2858. + if ( !(args->noreadfeedsfile))
  2859. + set_and_load_pkg_src_list(conf, &conf->pkg_src_list);
  2860. +
  2861. + /* Now that we have resolved conf->offline_root, we can commit to
  2862. + the directory names for the dests and load in all the package
  2863. + lists. */
  2864. + set_and_load_pkg_dest_list(conf, &tmp_dest_nv_pair_list,lists_dir);
  2865. +
  2866. + if (args->dest) {
  2867. + err = ipkg_conf_set_default_dest(conf, args->dest);
  2868. + if (err) {
  2869. + return err;
  2870. + }
  2871. + }
  2872. + }
  2873. + nv_pair_list_deinit(&tmp_dest_nv_pair_list);
  2874. + free(lists_dir);
  2875. + free(pending_dir);
  2876. +
  2877. + return 0;
  2878. +}
  2879. +
  2880. +void ipkg_conf_deinit(ipkg_conf_t *conf)
  2881. +{
  2882. +#ifdef IPKG_DEBUG_NO_TMP_CLEANUP
  2883. +#error
  2884. + fprintf(stderr, "%s: Not cleaning up %s since ipkg compiled "
  2885. + "with IPKG_DEBUG_NO_TMP_CLEANUP\n",
  2886. + __FUNCTION__, conf->tmp_dir);
  2887. +#else
  2888. + int err;
  2889. +
  2890. + err = rmdir(conf->tmp_dir);
  2891. + if (err) {
  2892. + if (errno == ENOTEMPTY) {
  2893. + char *cmd;
  2894. + sprintf_alloc(&cmd, "rm -fr %s\n", conf->tmp_dir);
  2895. + err = xsystem(cmd);
  2896. + free(cmd);
  2897. + }
  2898. + if (err)
  2899. + fprintf(stderr, "WARNING: Unable to remove temporary directory: %s: %s\n", conf->tmp_dir, strerror(errno));
  2900. + }
  2901. +#endif /* IPKG_DEBUG_NO_TMP_CLEANUP */
  2902. +
  2903. + free(conf->tmp_dir); /*XXX*/
  2904. +
  2905. + pkg_src_list_deinit(&conf->pkg_src_list);
  2906. + pkg_dest_list_deinit(&conf->pkg_dest_list);
  2907. + nv_pair_list_deinit(&conf->arch_list);
  2908. + if (&conf->pkg_hash)
  2909. + pkg_hash_deinit(&conf->pkg_hash);
  2910. + if (&conf->file_hash)
  2911. + hash_table_deinit(&conf->file_hash);
  2912. + if (&conf->obs_file_hash)
  2913. + hash_table_deinit(&conf->obs_file_hash);
  2914. +
  2915. + ipkg_conf_free_string(&conf->offline_root);
  2916. + ipkg_conf_free_string(&conf->offline_root_pre_script_cmd);
  2917. + ipkg_conf_free_string(&conf->offline_root_post_script_cmd);
  2918. +
  2919. + if (conf->verbosity > 1) {
  2920. + int i;
  2921. + hash_table_t *hashes[] = {
  2922. + &conf->pkg_hash,
  2923. + &conf->file_hash,
  2924. + &conf->obs_file_hash };
  2925. + for (i = 0; i < 3; i++) {
  2926. + hash_table_t *hash = hashes[i];
  2927. + int c = 0;
  2928. + int n_conflicts = 0;
  2929. + int j;
  2930. + for (j = 0; j < hash->n_entries; j++) {
  2931. + int len = 0;
  2932. + hash_entry_t *e = &hash->entries[j];
  2933. + if (e->next)
  2934. + n_conflicts++;
  2935. + while (e && e->key) {
  2936. + len++;
  2937. + e = e->next;
  2938. + }
  2939. + if (len > c)
  2940. + c = len;
  2941. + }
  2942. + ipkg_message(conf, IPKG_DEBUG, "hash_table[%s] n_buckets=%d n_elements=%d max_conflicts=%d n_conflicts=%d\n",
  2943. + hash->name, hash->n_entries, hash->n_elements, c, n_conflicts);
  2944. + hash_table_deinit(hash);
  2945. + }
  2946. + }
  2947. +}
  2948. +
  2949. +static int ipkg_conf_set_default_dest(ipkg_conf_t *conf,
  2950. + const char *default_dest_name)
  2951. +{
  2952. + pkg_dest_list_elt_t *iter;
  2953. + pkg_dest_t *dest;
  2954. +
  2955. + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
  2956. + dest = iter->data;
  2957. + if (strcmp(dest->name, default_dest_name) == 0) {
  2958. + conf->default_dest = dest;
  2959. + conf->restrict_to_default_dest = 1;
  2960. + return 0;
  2961. + }
  2962. + }
  2963. +
  2964. + fprintf(stderr, "ERROR: Unknown dest name: `%s'\n", default_dest_name);
  2965. +
  2966. + return 1;
  2967. +}
  2968. +
  2969. +static int set_and_load_pkg_src_list(ipkg_conf_t *conf, pkg_src_list_t *pkg_src_list)
  2970. +{
  2971. + pkg_src_list_elt_t *iter;
  2972. + pkg_src_t *src;
  2973. + char *list_file;
  2974. +
  2975. + for (iter = pkg_src_list->head; iter; iter = iter->next) {
  2976. + src = iter->data;
  2977. + if (src == NULL) {
  2978. + continue;
  2979. + }
  2980. +
  2981. + sprintf_alloc(&list_file, "%s/%s",
  2982. + conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir,
  2983. + src->name);
  2984. +
  2985. + if (file_exists(list_file)) {
  2986. + pkg_hash_add_from_file(conf, list_file, src, NULL, 0);
  2987. + }
  2988. + free(list_file);
  2989. + }
  2990. +
  2991. + return 0;
  2992. +}
  2993. +
  2994. +static int set_and_load_pkg_dest_list(ipkg_conf_t *conf, nv_pair_list_t *nv_pair_list, char *lists_dir )
  2995. +{
  2996. + nv_pair_list_elt_t *iter;
  2997. + nv_pair_t *nv_pair;
  2998. + pkg_dest_t *dest;
  2999. + char *root_dir;
  3000. +
  3001. + for (iter = nv_pair_list->head; iter; iter = iter->next) {
  3002. + nv_pair = iter->data;
  3003. +
  3004. + if (conf->offline_root) {
  3005. + sprintf_alloc(&root_dir, "%s%s", conf->offline_root, nv_pair->value);
  3006. + } else {
  3007. + root_dir = strdup(nv_pair->value);
  3008. + }
  3009. + dest = pkg_dest_list_append(&conf->pkg_dest_list, nv_pair->name, root_dir, lists_dir);
  3010. + free(root_dir);
  3011. + if (dest == NULL) {
  3012. + continue;
  3013. + }
  3014. + if (conf->default_dest == NULL) {
  3015. + conf->default_dest = dest;
  3016. + }
  3017. + if (file_exists(dest->status_file_name)) {
  3018. + pkg_hash_add_from_file(conf, dest->status_file_name,
  3019. + NULL, dest, 1);
  3020. + }
  3021. + }
  3022. +
  3023. + return 0;
  3024. +}
  3025. +
  3026. +static int ipkg_conf_parse_file(ipkg_conf_t *conf, const char *filename,
  3027. + pkg_src_list_t *pkg_src_list,
  3028. + nv_pair_list_t *tmp_dest_nv_pair_list,
  3029. + char **lists_dir)
  3030. +{
  3031. + ipkg_option_t * options;
  3032. + FILE *file = fopen(filename, "r");
  3033. + regex_t valid_line_re, comment_re;
  3034. +#define regmatch_size 12
  3035. + regmatch_t regmatch[regmatch_size];
  3036. +
  3037. + if (ipkg_init_options_array(conf, &options)<0)
  3038. + return ENOMEM;
  3039. +
  3040. + if (file == NULL) {
  3041. + fprintf(stderr, "%s: failed to open %s: %s\n",
  3042. + __FUNCTION__, filename, strerror(errno));
  3043. + free(options);
  3044. + return errno;
  3045. + }
  3046. + ipkg_message(conf, IPKG_NOTICE, "loading conf file %s\n", filename);
  3047. +
  3048. + xregcomp(&comment_re,
  3049. + "^[[:space:]]*(#.*|[[:space:]]*)$",
  3050. + REG_EXTENDED);
  3051. + xregcomp(&valid_line_re, "^[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))([[:space:]]+([^[:space:]]+))?[[:space:]]*$", REG_EXTENDED);
  3052. +
  3053. + while(1) {
  3054. + int line_num = 0;
  3055. + char *line;
  3056. + char *type, *name, *value, *extra;
  3057. +
  3058. + line = file_read_line_alloc(file);
  3059. + line_num++;
  3060. + if (line == NULL) {
  3061. + break;
  3062. + }
  3063. +
  3064. + str_chomp(line);
  3065. +
  3066. + if (regexec(&comment_re, line, 0, 0, 0) == 0) {
  3067. + goto NEXT_LINE;
  3068. + }
  3069. +
  3070. + if (regexec(&valid_line_re, line, regmatch_size, regmatch, 0) == REG_NOMATCH) {
  3071. + str_chomp(line);
  3072. + fprintf(stderr, "%s:%d: Ignoring invalid line: `%s'\n",
  3073. + filename, line_num, line);
  3074. + goto NEXT_LINE;
  3075. + }
  3076. +
  3077. + /* This has to be so ugly to deal with optional quotation marks */
  3078. + if (regmatch[2].rm_so > 0) {
  3079. + type = strndup(line + regmatch[2].rm_so,
  3080. + regmatch[2].rm_eo - regmatch[2].rm_so);
  3081. + } else {
  3082. + type = strndup(line + regmatch[3].rm_so,
  3083. + regmatch[3].rm_eo - regmatch[3].rm_so);
  3084. + }
  3085. + if (regmatch[5].rm_so > 0) {
  3086. + name = strndup(line + regmatch[5].rm_so,
  3087. + regmatch[5].rm_eo - regmatch[5].rm_so);
  3088. + } else {
  3089. + name = strndup(line + regmatch[6].rm_so,
  3090. + regmatch[6].rm_eo - regmatch[6].rm_so);
  3091. + }
  3092. + if (regmatch[8].rm_so > 0) {
  3093. + value = strndup(line + regmatch[8].rm_so,
  3094. + regmatch[8].rm_eo - regmatch[8].rm_so);
  3095. + } else {
  3096. + value = strndup(line + regmatch[9].rm_so,
  3097. + regmatch[9].rm_eo - regmatch[9].rm_so);
  3098. + }
  3099. + extra = NULL;
  3100. + if (regmatch[11].rm_so > 0) {
  3101. + extra = strndup (line + regmatch[11].rm_so,
  3102. + regmatch[11].rm_eo - regmatch[11].rm_so);
  3103. + }
  3104. +
  3105. + /* We use the tmp_dest_nv_pair_list below instead of
  3106. + conf->pkg_dest_list because we might encounter an
  3107. + offline_root option later and that would invalidate the
  3108. + directories we would have computed in
  3109. + pkg_dest_list_init. (We do a similar thing with
  3110. + tmp_src_nv_pair_list for sake of symmetry.) */
  3111. + if (strcmp(type, "option") == 0) {
  3112. + ipkg_conf_set_option(options, name, value);
  3113. + } else if (strcmp(type, "src") == 0) {
  3114. + if (!nv_pair_list_find((nv_pair_list_t *)pkg_src_list, name)) {
  3115. + pkg_src_list_append (pkg_src_list, name, value, extra, 0);
  3116. + } else {
  3117. + ipkg_message(conf, IPKG_ERROR, "ERROR: duplicate src declaration. Skipping:\n\t src %s %s\n",
  3118. + name, value);
  3119. + }
  3120. + } else if (strcmp(type, "src/gz") == 0) {
  3121. + if (!nv_pair_list_find((nv_pair_list_t *)pkg_src_list, name)) {
  3122. + pkg_src_list_append (pkg_src_list, name, value, extra, 1);
  3123. + } else {
  3124. + ipkg_message(conf, IPKG_ERROR, "ERROR: duplicate src declaration. Skipping:\n\t src %s %s\n",
  3125. + name, value);
  3126. + }
  3127. + } else if (strcmp(type, "dest") == 0) {
  3128. + nv_pair_list_append(tmp_dest_nv_pair_list, name, value);
  3129. + } else if (strcmp(type, "lists_dir") == 0) {
  3130. + *lists_dir = realloc(*lists_dir,strlen(value)+1);
  3131. + if (*lists_dir == NULL) {
  3132. + ipkg_message(conf, IPKG_ERROR, "ERROR: Not enough memory\n");
  3133. + free(options);
  3134. + return EINVAL;
  3135. + }
  3136. + sprintf (*lists_dir,"%s",value);
  3137. + } else if (strcmp(type, "arch") == 0) {
  3138. + ipkg_message(conf, IPKG_INFO, "supported arch %s priority (%s)\n", name, value);
  3139. + if (!value) {
  3140. + ipkg_message(conf, IPKG_NOTICE, "defaulting architecture %s priority to 10\n", name);
  3141. + value = strdup("10");
  3142. + }
  3143. + nv_pair_list_append(&conf->arch_list, strdup(name), strdup(value));
  3144. + } else {
  3145. + fprintf(stderr, "WARNING: Ignoring unknown configuration "
  3146. + "parameter: %s %s %s\n", type, name, value);
  3147. + free(options);
  3148. + return EINVAL;
  3149. + }
  3150. +
  3151. + free(type);
  3152. + free(name);
  3153. + free(value);
  3154. + if (extra)
  3155. + free (extra);
  3156. +
  3157. + NEXT_LINE:
  3158. + free(line);
  3159. + }
  3160. +
  3161. + free(options);
  3162. + regfree(&comment_re);
  3163. + regfree(&valid_line_re);
  3164. + fclose(file);
  3165. +
  3166. + return 0;
  3167. +}
  3168. +
  3169. +static int ipkg_conf_set_option(const ipkg_option_t *options,
  3170. + const char *name, const char *value)
  3171. +{
  3172. + int i = 0;
  3173. + while (options[i].name) {
  3174. + if (strcmp(options[i].name, name) == 0) {
  3175. + switch (options[i].type) {
  3176. + case IPKG_OPT_TYPE_BOOL:
  3177. + *((int *)options[i].value) = 1;
  3178. + return 0;
  3179. + case IPKG_OPT_TYPE_INT:
  3180. + if (value) {
  3181. + *((int *)options[i].value) = atoi(value);
  3182. + return 0;
  3183. + } else {
  3184. + printf("%s: Option %s need an argument\n",
  3185. + __FUNCTION__, name);
  3186. + return EINVAL;
  3187. + }
  3188. + case IPKG_OPT_TYPE_STRING:
  3189. + if (value) {
  3190. + *((char **)options[i].value) = strdup(value);
  3191. + return 0;
  3192. + } else {
  3193. + printf("%s: Option %s need an argument\n",
  3194. + __FUNCTION__, name);
  3195. + return EINVAL;
  3196. + }
  3197. + }
  3198. + }
  3199. + i++;
  3200. + }
  3201. +
  3202. + fprintf(stderr, "%s: Unrecognized option: %s=%s\n",
  3203. + __FUNCTION__, name, value);
  3204. + return EINVAL;
  3205. +}
  3206. +
  3207. +int ipkg_conf_write_status_files(ipkg_conf_t *conf)
  3208. +{
  3209. + pkg_dest_list_elt_t *iter;
  3210. + pkg_dest_t *dest;
  3211. + pkg_vec_t *all;
  3212. + pkg_t *pkg;
  3213. + register int i;
  3214. + int err;
  3215. +
  3216. + if (conf->noaction)
  3217. + return 0;
  3218. + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
  3219. + dest = iter->data;
  3220. + dest->status_file = fopen(dest->status_file_tmp_name, "w");
  3221. + if (dest->status_file == NULL) {
  3222. + fprintf(stderr, "%s: Can't open status file: %s for writing: %s\n",
  3223. + __FUNCTION__, dest->status_file_name, strerror(errno));
  3224. + }
  3225. + }
  3226. +
  3227. + all = pkg_vec_alloc();
  3228. + pkg_hash_fetch_available(&conf->pkg_hash, all);
  3229. +
  3230. + for(i = 0; i < all->len; i++) {
  3231. + pkg = all->pkgs[i];
  3232. + /* We don't need most uninstalled packages in the status file */
  3233. + if (pkg->state_status == SS_NOT_INSTALLED
  3234. + && (pkg->state_want == SW_UNKNOWN
  3235. + || pkg->state_want == SW_DEINSTALL
  3236. + || pkg->state_want == SW_PURGE)) {
  3237. + continue;
  3238. + }
  3239. + if (!pkg) {
  3240. + fprintf(stderr, "Null package\n");
  3241. + }
  3242. + if (pkg->dest == NULL) {
  3243. + fprintf(stderr, "%s: ERROR: Can't write status for "
  3244. + "package %s since it has a NULL dest\n",
  3245. + __FUNCTION__, pkg->name);
  3246. + continue;
  3247. + }
  3248. + if (pkg->dest->status_file) {
  3249. + pkg_print_status(pkg, pkg->dest->status_file);
  3250. + }
  3251. + }
  3252. +
  3253. + pkg_vec_free(all);
  3254. +
  3255. + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
  3256. + dest = iter->data;
  3257. + if (dest->status_file) {
  3258. + err = ferror(dest->status_file);
  3259. + fclose(dest->status_file);
  3260. + dest->status_file = NULL;
  3261. + if (!err) {
  3262. + file_move(dest->status_file_tmp_name, dest->status_file_name);
  3263. + } else {
  3264. + fprintf(stderr, "%s: ERROR: An error has occurred writing %s, "
  3265. + "retaining old %s\n", __FUNCTION__,
  3266. + dest->status_file_tmp_name, dest->status_file_name);
  3267. + }
  3268. + }
  3269. + }
  3270. +
  3271. + return 0;
  3272. +}
  3273. +
  3274. +
  3275. +char *root_filename_alloc(ipkg_conf_t *conf, char *filename)
  3276. +{
  3277. + char *root_filename;
  3278. + sprintf_alloc(&root_filename, "%s%s", (conf->offline_root ? conf->offline_root : ""), filename);
  3279. + return root_filename;
  3280. +}
  3281. diff -Nur busybox-1.19.4.orig/archival/libipkg/ipkg_conf.h busybox-1.19.4/archival/libipkg/ipkg_conf.h
  3282. --- busybox-1.19.4.orig/archival/libipkg/ipkg_conf.h 1970-01-01 01:00:00.000000000 +0100
  3283. +++ busybox-1.19.4/archival/libipkg/ipkg_conf.h 2012-03-17 00:58:08.193100680 +0100
  3284. @@ -0,0 +1,107 @@
  3285. +/* ipkg_conf.h - the itsy package management system
  3286. +
  3287. + Carl D. Worth
  3288. +
  3289. + Copyright (C) 2001 University of Southern California
  3290. +
  3291. + This program is free software; you can redistribute it and/or
  3292. + modify it under the terms of the GNU General Public License as
  3293. + published by the Free Software Foundation; either version 2, or (at
  3294. + your option) any later version.
  3295. +
  3296. + This program is distributed in the hope that it will be useful, but
  3297. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3298. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3299. + General Public License for more details.
  3300. +*/
  3301. +
  3302. +#ifndef IPKG_CONF_H
  3303. +#define IPKG_CONF_H
  3304. +
  3305. +typedef struct ipkg_conf ipkg_conf_t;
  3306. +
  3307. +#include "hash_table.h"
  3308. +#include "ipkg.h"
  3309. +#include "args.h"
  3310. +#include "pkg.h"
  3311. +#include "pkg_hash.h"
  3312. +#include "pkg_src_list.h"
  3313. +#include "pkg_dest_list.h"
  3314. +#include "nv_pair_list.h"
  3315. +
  3316. +#define IPKG_CONF_DEFAULT_TMP_DIR_BASE "/tmp"
  3317. +#define IPKG_CONF_TMP_DIR_SUFFIX "ipkg-XXXXXX"
  3318. +#define IPKG_CONF_LISTS_DIR IPKG_STATE_DIR_PREFIX "/lists"
  3319. +#define IPKG_CONF_PENDING_DIR IPKG_STATE_DIR_PREFIX "/pending"
  3320. +
  3321. +/* In case the config file defines no dest */
  3322. +#define IPKG_CONF_DEFAULT_DEST_NAME "root"
  3323. +#define IPKG_CONF_DEFAULT_DEST_ROOT_DIR "/"
  3324. +
  3325. +#define IPKG_CONF_DEFAULT_HASH_LEN 1024
  3326. +
  3327. +struct ipkg_conf
  3328. +{
  3329. + pkg_src_list_t pkg_src_list;
  3330. + pkg_dest_list_t pkg_dest_list;
  3331. + nv_pair_list_t arch_list;
  3332. +
  3333. + int restrict_to_default_dest;
  3334. + pkg_dest_t *default_dest;
  3335. +
  3336. + char *tmp_dir;
  3337. + char *lists_dir;
  3338. + char *pending_dir;
  3339. +
  3340. + /* options */
  3341. + int force_depends;
  3342. + int force_defaults;
  3343. + int force_overwrite;
  3344. + int force_downgrade;
  3345. + int force_reinstall;
  3346. + int force_space;
  3347. + int force_removal_of_dependent_packages;
  3348. + int force_removal_of_essential_packages;
  3349. + int nodeps; /* do not follow dependences */
  3350. + int verbose_wget;
  3351. + int multiple_providers;
  3352. + char *offline_root;
  3353. + char *offline_root_pre_script_cmd;
  3354. + char *offline_root_post_script_cmd;
  3355. + int query_all;
  3356. + int verbosity;
  3357. + int noaction;
  3358. +
  3359. + /* proxy options */
  3360. + char *http_proxy;
  3361. + char *ftp_proxy;
  3362. + char *no_proxy;
  3363. + char *proxy_user;
  3364. + char *proxy_passwd;
  3365. +
  3366. + hash_table_t pkg_hash;
  3367. + hash_table_t file_hash;
  3368. + hash_table_t obs_file_hash;
  3369. +};
  3370. +
  3371. +enum ipkg_option_type {
  3372. + IPKG_OPT_TYPE_BOOL,
  3373. + IPKG_OPT_TYPE_INT,
  3374. + IPKG_OPT_TYPE_STRING
  3375. +};
  3376. +typedef enum ipkg_option_type ipkg_option_type_t;
  3377. +
  3378. +typedef struct ipkg_option ipkg_option_t;
  3379. +struct ipkg_option {
  3380. + const char *name;
  3381. + const ipkg_option_type_t type;
  3382. + const void *value;
  3383. +};
  3384. +
  3385. +int ipkg_conf_init(ipkg_conf_t *conf, const args_t *args);
  3386. +void ipkg_conf_deinit(ipkg_conf_t *conf);
  3387. +
  3388. +int ipkg_conf_write_status_files(ipkg_conf_t *conf);
  3389. +char *root_filename_alloc(ipkg_conf_t *conf, char *filename);
  3390. +
  3391. +#endif
  3392. diff -Nur busybox-1.19.4.orig/archival/libipkg/ipkg_configure.c busybox-1.19.4/archival/libipkg/ipkg_configure.c
  3393. --- busybox-1.19.4.orig/archival/libipkg/ipkg_configure.c 1970-01-01 01:00:00.000000000 +0100
  3394. +++ busybox-1.19.4/archival/libipkg/ipkg_configure.c 2012-03-17 00:58:08.193100680 +0100
  3395. @@ -0,0 +1,40 @@
  3396. +/* ipkg_configure.c - the itsy package management system
  3397. +
  3398. + Carl D. Worth
  3399. +
  3400. + Copyright (C) 2001 University of Southern California
  3401. +
  3402. + This program is free software; you can redistribute it and/or
  3403. + modify it under the terms of the GNU General Public License as
  3404. + published by the Free Software Foundation; either version 2, or (at
  3405. + your option) any later version.
  3406. +
  3407. + This program is distributed in the hope that it will be useful, but
  3408. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3409. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3410. + General Public License for more details.
  3411. +*/
  3412. +
  3413. +#include "ipkg.h"
  3414. +
  3415. +#include "ipkg_configure.h"
  3416. +
  3417. +int ipkg_configure(ipkg_conf_t *conf, pkg_t *pkg)
  3418. +{
  3419. + int err;
  3420. +
  3421. + /* DPKG_INCOMPATIBILITY:
  3422. + dpkg actually does some conffile handling here, rather than at the
  3423. + end of ipkg_install(). Do we care? */
  3424. + /* DPKG_INCOMPATIBILITY:
  3425. + dpkg actually includes a version number to this script call */
  3426. + err = pkg_run_script(conf, pkg, "postinst", "configure");
  3427. + if (err) {
  3428. + printf("ERROR: %s.postinst returned %d\n", pkg->name, err);
  3429. + return err;
  3430. + }
  3431. +
  3432. + ipkg_state_changed++;
  3433. + return 0;
  3434. +}
  3435. +
  3436. diff -Nur busybox-1.19.4.orig/archival/libipkg/ipkg_configure.h busybox-1.19.4/archival/libipkg/ipkg_configure.h
  3437. --- busybox-1.19.4.orig/archival/libipkg/ipkg_configure.h 1970-01-01 01:00:00.000000000 +0100
  3438. +++ busybox-1.19.4/archival/libipkg/ipkg_configure.h 2012-03-17 00:58:08.193100680 +0100
  3439. @@ -0,0 +1,25 @@
  3440. +/* ipkg_configure.h - the itsy package management system
  3441. +
  3442. + Carl D. Worth
  3443. +
  3444. + Copyright (C) 2001 University of Southern California
  3445. +
  3446. + This program is free software; you can redistribute it and/or
  3447. + modify it under the terms of the GNU General Public License as
  3448. + published by the Free Software Foundation; either version 2, or (at
  3449. + your option) any later version.
  3450. +
  3451. + This program is distributed in the hope that it will be useful, but
  3452. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3453. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3454. + General Public License for more details.
  3455. +*/
  3456. +
  3457. +#ifndef IPKG_CONFIGURE_H
  3458. +#define IPKG_CONFIGURE_H
  3459. +
  3460. +#include "ipkg_conf.h"
  3461. +
  3462. +int ipkg_configure(ipkg_conf_t *ipkg_conf, pkg_t *pkg);
  3463. +
  3464. +#endif
  3465. diff -Nur busybox-1.19.4.orig/archival/libipkg/ipkg_download.c busybox-1.19.4/archival/libipkg/ipkg_download.c
  3466. --- busybox-1.19.4.orig/archival/libipkg/ipkg_download.c 1970-01-01 01:00:00.000000000 +0100
  3467. +++ busybox-1.19.4/archival/libipkg/ipkg_download.c 2012-03-17 00:58:08.193100680 +0100
  3468. @@ -0,0 +1,195 @@
  3469. +/* ipkg_download.c - the itsy package management system
  3470. +
  3471. + Carl D. Worth
  3472. +
  3473. + Copyright (C) 2001 University of Southern California
  3474. +
  3475. + This program is free software; you can redistribute it and/or
  3476. + modify it under the terms of the GNU General Public License as
  3477. + published by the Free Software Foundation; either version 2, or (at
  3478. + your option) any later version.
  3479. +
  3480. + This program is distributed in the hope that it will be useful, but
  3481. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3482. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3483. + General Public License for more details.
  3484. +*/
  3485. +
  3486. +#include "ipkg.h"
  3487. +#include "ipkg_download.h"
  3488. +#include "ipkg_message.h"
  3489. +
  3490. +#include "sprintf_alloc.h"
  3491. +#include "xsystem.h"
  3492. +#include "file_util.h"
  3493. +#include "str_util.h"
  3494. +
  3495. +int ipkg_download(ipkg_conf_t *conf, const char *src, const char *dest_file_name)
  3496. +{
  3497. + int err = 0;
  3498. +
  3499. + char *src_basec = strdup(src);
  3500. + char *src_base = basename(src_basec);
  3501. + char *tmp_file_location;
  3502. + char *cmd;
  3503. +
  3504. + ipkg_message(conf,IPKG_NOTICE,"Downloading %s\n", src);
  3505. +
  3506. + fflush(stdout);
  3507. +
  3508. + if (str_starts_with(src, "file:")) {
  3509. + int ret;
  3510. + const char *file_src = src + 5;
  3511. + ipkg_message(conf,IPKG_INFO,"Copying %s to %s...", file_src, dest_file_name);
  3512. + ret = file_copy(src + 5, dest_file_name);
  3513. + ipkg_message(conf,IPKG_INFO,"Done.\n");
  3514. + return ret;
  3515. + }
  3516. +
  3517. + sprintf_alloc(&tmp_file_location, "%s/%s", conf->tmp_dir, src_base);
  3518. + err = unlink(tmp_file_location);
  3519. + if (err && errno != ENOENT) {
  3520. + ipkg_message(conf,IPKG_ERROR, "%s: ERROR: failed to unlink %s: %s\n",
  3521. + __FUNCTION__, tmp_file_location, strerror(errno));
  3522. + free(tmp_file_location);
  3523. + return errno;
  3524. + }
  3525. +
  3526. + if (conf->http_proxy) {
  3527. + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: http_proxy = %s\n", conf->http_proxy);
  3528. + setenv("http_proxy", conf->http_proxy, 1);
  3529. + }
  3530. + if (conf->ftp_proxy) {
  3531. + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: ftp_proxy = %s\n", conf->ftp_proxy);
  3532. + setenv("ftp_proxy", conf->ftp_proxy, 1);
  3533. + }
  3534. + if (conf->no_proxy) {
  3535. + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: no_proxy = %s\n", conf->no_proxy);
  3536. + setenv("no_proxy", conf->no_proxy, 1);
  3537. + }
  3538. +
  3539. + /* XXX: BUG rewrite to use execvp or else busybox's internal wget -Jamey 7/23/2002 */
  3540. + sprintf_alloc(&cmd, "wget %s %s%s %s%s %s -P %s %s",
  3541. + (conf->http_proxy || conf->ftp_proxy) ? "-Y on" : "",
  3542. + conf->proxy_user ? "--proxy-user=" : "",
  3543. + conf->proxy_user ? conf->proxy_user : "",
  3544. + conf->proxy_passwd ? "--proxy-passwd=" : "",
  3545. + conf->proxy_passwd ? conf->proxy_passwd : "",
  3546. + conf->verbose_wget ? "" : "-q",
  3547. + conf->tmp_dir,
  3548. + src);
  3549. + err = xsystem(cmd);
  3550. + if (err) {
  3551. + if (err != -1) {
  3552. + ipkg_message(conf,IPKG_ERROR, "%s: ERROR: Command failed with return value %d: `%s'\n",
  3553. + __FUNCTION__, err, cmd);
  3554. + }
  3555. + unlink(tmp_file_location);
  3556. + free(tmp_file_location);
  3557. + free(src_basec);
  3558. + free(cmd);
  3559. + return EINVAL;
  3560. + }
  3561. + free(cmd);
  3562. +
  3563. + err = file_move(tmp_file_location, dest_file_name);
  3564. +
  3565. + free(tmp_file_location);
  3566. + free(src_basec);
  3567. +
  3568. + if (err) {
  3569. + return err;
  3570. + }
  3571. +
  3572. + return 0;
  3573. +}
  3574. +
  3575. +int ipkg_download_pkg(ipkg_conf_t *conf, pkg_t *pkg, const char *dir)
  3576. +{
  3577. + int err;
  3578. + char *url;
  3579. +
  3580. + if (pkg->src == NULL) {
  3581. + ipkg_message(conf,IPKG_ERROR, "ERROR: Package %s (parent %s) is not available from any configured src.\n",
  3582. + pkg->name, pkg->parent->name);
  3583. + return -1;
  3584. + }
  3585. +
  3586. + sprintf_alloc(&url, "%s/%s", pkg->src->value, pkg->filename);
  3587. +
  3588. + /* XXX: BUG: The pkg->filename might be something like
  3589. + "../../foo.ipk". While this is correct, and exactly what we
  3590. + want to use to construct url above, here we actually need to
  3591. + use just the filename part, without any directory. */
  3592. + sprintf_alloc(&pkg->local_filename, "%s/%s", dir, pkg->filename);
  3593. +
  3594. + err = ipkg_download(conf, url, pkg->local_filename);
  3595. + free(url);
  3596. +
  3597. + return err;
  3598. +}
  3599. +
  3600. +/*
  3601. + * Downloads file from url, installs in package database, return package name.
  3602. + */
  3603. +int ipkg_prepare_url_for_install(ipkg_conf_t *conf, const char *url, char **namep)
  3604. +{
  3605. + int err = 0;
  3606. + pkg_t *pkg;
  3607. + pkg = pkg_new();
  3608. + if (pkg == NULL)
  3609. + return ENOMEM;
  3610. +
  3611. + if (str_starts_with(url, "http://")
  3612. + || str_starts_with(url, "ftp://")) {
  3613. + char *tmp_file;
  3614. + char *file_basec = strdup(url);
  3615. + char *file_base = basename(file_basec);
  3616. +
  3617. + sprintf_alloc(&tmp_file, "%s/%s", conf->tmp_dir, file_base);
  3618. + err = ipkg_download(conf, url, tmp_file);
  3619. + if (err)
  3620. + return err;
  3621. +
  3622. + err = pkg_init_from_file(pkg, tmp_file);
  3623. + if (err)
  3624. + return err;
  3625. + pkg->local_filename = strdup(tmp_file);
  3626. +
  3627. + free(tmp_file);
  3628. + free(file_basec);
  3629. +
  3630. + } else if (strcmp(&url[strlen(url) - 4], IPKG_PKG_EXTENSION) == 0
  3631. + || strcmp(&url[strlen(url) - 4], DPKG_PKG_EXTENSION) == 0) {
  3632. +
  3633. + err = pkg_init_from_file(pkg, url);
  3634. + if (err)
  3635. + return err;
  3636. + pkg->local_filename = strdup(url);
  3637. + ipkg_message(conf, IPKG_DEBUG2, "Package %s provided by hand (%s).\n", pkg->name,pkg->local_filename);
  3638. + pkg->provided_by_hand = 1;
  3639. +
  3640. + } else {
  3641. + pkg_deinit(pkg);
  3642. + free(pkg);
  3643. + return 0;
  3644. + }
  3645. +
  3646. + if (!pkg->architecture) {
  3647. + ipkg_message(conf, IPKG_ERROR, "Package %s has no Architecture defined.\n", pkg->name);
  3648. + return -EINVAL;
  3649. + }
  3650. +
  3651. + pkg->dest = conf->default_dest;
  3652. + pkg->state_want = SW_INSTALL;
  3653. + pkg->state_flag |= SF_PREFER;
  3654. + pkg = hash_insert_pkg(&conf->pkg_hash, pkg, 1,conf);
  3655. + if ( pkg == NULL ){
  3656. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  3657. + return 0;
  3658. + }
  3659. + if (namep) {
  3660. + *namep = strdup(pkg->name);
  3661. + }
  3662. + return 0;
  3663. +}
  3664. diff -Nur busybox-1.19.4.orig/archival/libipkg/ipkg_download.h busybox-1.19.4/archival/libipkg/ipkg_download.h
  3665. --- busybox-1.19.4.orig/archival/libipkg/ipkg_download.h 1970-01-01 01:00:00.000000000 +0100
  3666. +++ busybox-1.19.4/archival/libipkg/ipkg_download.h 2012-03-17 00:58:08.193100680 +0100
  3667. @@ -0,0 +1,30 @@
  3668. +/* ipkg_download.h - the itsy package management system
  3669. +
  3670. + Carl D. Worth
  3671. +
  3672. + Copyright (C) 2001 University of Southern California
  3673. +
  3674. + This program is free software; you can redistribute it and/or
  3675. + modify it under the terms of the GNU General Public License as
  3676. + published by the Free Software Foundation; either version 2, or (at
  3677. + your option) any later version.
  3678. +
  3679. + This program is distributed in the hope that it will be useful, but
  3680. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3681. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3682. + General Public License for more details.
  3683. +*/
  3684. +
  3685. +#ifndef IPKG_DOWNLOAD_H
  3686. +#define IPKG_DOWNLOAD_H
  3687. +
  3688. +#include "ipkg_conf.h"
  3689. +
  3690. +int ipkg_download(ipkg_conf_t *conf, const char *src, const char *dest_file_name);
  3691. +int ipkg_download_pkg(ipkg_conf_t *conf, pkg_t *pkg, const char *dir);
  3692. +/*
  3693. + * Downloads file from url, installs in package database, return package name.
  3694. + */
  3695. +int ipkg_prepare_url_for_install(ipkg_conf_t *conf, const char *url, char **namep);
  3696. +
  3697. +#endif
  3698. diff -Nur busybox-1.19.4.orig/archival/libipkg/ipkg_includes.h busybox-1.19.4/archival/libipkg/ipkg_includes.h
  3699. --- busybox-1.19.4.orig/archival/libipkg/ipkg_includes.h 1970-01-01 01:00:00.000000000 +0100
  3700. +++ busybox-1.19.4/archival/libipkg/ipkg_includes.h 2012-03-17 00:58:08.193100680 +0100
  3701. @@ -0,0 +1,82 @@
  3702. +#ifndef IPKG_INCLUDES_H
  3703. +#define IPKG_INCLUDES_H
  3704. +
  3705. +/* Define to 1 if you have the <memory.h> header file. */
  3706. +#define HAVE_MEMORY_H 1
  3707. +
  3708. +/* Define to 1 if you have the <regex.h> header file. */
  3709. +#define HAVE_REGEX_H 1
  3710. +
  3711. +/* Define to 1 if you have the <stdlib.h> header file. */
  3712. +#define HAVE_STDLIB_H 1
  3713. +
  3714. +/* Define to 1 if you have the <strings.h> header file. */
  3715. +#define HAVE_STRINGS_H 1
  3716. +
  3717. +/* Define to 1 if you have the <string.h> header file. */
  3718. +#define HAVE_STRING_H 1
  3719. +
  3720. +/* Define to 1 if you have the <sys/stat.h> header file. */
  3721. +#define HAVE_SYS_STAT_H 1
  3722. +
  3723. +/* Define to 1 if you have <sys/wait.h> that is POSIX.1 compatible. */
  3724. +#define HAVE_SYS_WAIT_H 1
  3725. +
  3726. +/* Define to 1 if you have the <unistd.h> header file. */
  3727. +#define HAVE_UNISTD_H 1
  3728. +
  3729. +/* Define to 1 if you have the ANSI C header files. */
  3730. +#define STDC_HEADERS 1
  3731. +
  3732. +
  3733. +#include <stdio.h>
  3734. +
  3735. +#if STDC_HEADERS
  3736. +# include <stdlib.h>
  3737. +# include <stdarg.h>
  3738. +# include <stddef.h>
  3739. +# include <ctype.h>
  3740. +# include <errno.h>
  3741. +#else
  3742. +# if HAVE_STDLIB_H
  3743. +# include <stdlib.h>
  3744. +# endif
  3745. +#endif
  3746. +
  3747. +#if HAVE_REGEX_H
  3748. +# include <regex.h>
  3749. +#endif
  3750. +
  3751. +#if HAVE_STRING_H
  3752. +# if !STDC_HEADERS && HAVE_MEMORY_H
  3753. +# include <memory.h>
  3754. +# endif
  3755. +/* XXX: What's the right way to pick up GNU's strndup declaration? */
  3756. +# if __GNUC__
  3757. +# define __USE_GNU 1
  3758. +# endif
  3759. +# include <string.h>
  3760. +# undef __USE_GNU
  3761. +#endif
  3762. +
  3763. +#if HAVE_STRINGS_H
  3764. +# include <strings.h>
  3765. +#endif
  3766. +
  3767. +#if HAVE_SYS_STAT_H
  3768. +# include <sys/stat.h>
  3769. +#endif
  3770. +
  3771. +#if HAVE_SYS_WAIT_H
  3772. +# include <sys/wait.h>
  3773. +#endif
  3774. +
  3775. +#if HAVE_UNISTD_H
  3776. +# include <sys/types.h>
  3777. +# include <unistd.h>
  3778. +#endif
  3779. +
  3780. +#include <sys/mount.h>
  3781. +#include <mntent.h>
  3782. +
  3783. +#endif /* IPKG_INCLUDES_H */
  3784. diff -Nur busybox-1.19.4.orig/archival/libipkg/ipkg_install.c busybox-1.19.4/archival/libipkg/ipkg_install.c
  3785. --- busybox-1.19.4.orig/archival/libipkg/ipkg_install.c 1970-01-01 01:00:00.000000000 +0100
  3786. +++ busybox-1.19.4/archival/libipkg/ipkg_install.c 2012-03-17 00:58:08.193100680 +0100
  3787. @@ -0,0 +1,1982 @@
  3788. +/* ipkg_install.c - the itsy package management system
  3789. +
  3790. + Carl D. Worth
  3791. +
  3792. + Copyright (C) 2001 University of Southern California
  3793. +
  3794. + This program is free software; you can redistribute it and/or
  3795. + modify it under the terms of the GNU General Public License as
  3796. + published by the Free Software Foundation; either version 2, or (at
  3797. + your option) any later version.
  3798. +
  3799. + This program is distributed in the hope that it will be useful, but
  3800. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3801. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3802. + General Public License for more details.
  3803. +*/
  3804. +
  3805. +#include "ipkg.h"
  3806. +#include <errno.h>
  3807. +#include <dirent.h>
  3808. +#include <glob.h>
  3809. +#include <time.h>
  3810. +#include <signal.h>
  3811. +typedef void (*sighandler_t)(int);
  3812. +
  3813. +#include "pkg.h"
  3814. +#include "pkg_hash.h"
  3815. +#include "pkg_extract.h"
  3816. +
  3817. +#include "ipkg_install.h"
  3818. +#include "ipkg_configure.h"
  3819. +#include "ipkg_download.h"
  3820. +#include "ipkg_remove.h"
  3821. +
  3822. +#include "ipkg_utils.h"
  3823. +#include "ipkg_message.h"
  3824. +
  3825. +#include "sprintf_alloc.h"
  3826. +#include "file_util.h"
  3827. +#include "str_util.h"
  3828. +#include "xsystem.h"
  3829. +#include "user.h"
  3830. +
  3831. +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg);
  3832. +static int verify_pkg_installable(ipkg_conf_t *conf, pkg_t *pkg);
  3833. +static int unpack_pkg_control_files(ipkg_conf_t *conf, pkg_t *pkg);
  3834. +
  3835. +/*
  3836. +static int prerm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3837. +static int prerm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3838. +static int prerm_deconfigure_conflictors(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors);
  3839. +static int prerm_deconfigure_conflictors_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors);
  3840. +static int preinst_configure_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3841. +static int check_data_file_clashes_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3842. +static int postrm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3843. +static int remove_disappeared(ipkg_conf_t *conf, pkg_t *pkg);
  3844. +static int postrm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3845. +*/
  3846. +static int preinst_configure(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3847. +static int check_data_file_clashes(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3848. +static int check_data_file_clashes_change(ipkg_conf_t *conf, pkg_t *pkg);
  3849. +static int backup_modified_conffiles(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3850. +static int backup_modified_conffiles_unwind(pkg_t *pkg, pkg_t *old_pkg);
  3851. +
  3852. +static int remove_obsolesced_files(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3853. +static int install_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3854. +static int install_data_files(ipkg_conf_t *conf, pkg_t *pkg);
  3855. +static int resolve_conffiles(ipkg_conf_t *conf, pkg_t *pkg);
  3856. +
  3857. +static int cleanup_temporary_files(ipkg_conf_t *conf, pkg_t *pkg);
  3858. +
  3859. +static int user_prefers_old_conffile(const char *file, const char *backup);
  3860. +
  3861. +static char *backup_filename_alloc(const char *file_name);
  3862. +static int backup_make_backup(ipkg_conf_t *conf, const char *file_name);
  3863. +static int backup_exists_for(const char *file_name);
  3864. +static int backup_remove(const char *file_name);
  3865. +
  3866. +int pkg_get_installed_replacees(pkg_t *pkg, pkg_vec_t *installed_replacees);
  3867. +int pkg_remove_installed_replacees(ipkg_conf_t *conf, pkg_vec_t *replacees);
  3868. +int pkg_remove_installed_replacees_unwind(ipkg_conf_t *conf, pkg_vec_t *replacees);
  3869. +
  3870. +int ipkg_install_from_file(ipkg_conf_t *conf, const char *filename)
  3871. +{
  3872. + int err, cmp;
  3873. + pkg_t *pkg, *old;
  3874. + char *old_version, *new_version;
  3875. +
  3876. + pkg = pkg_new();
  3877. + if (pkg == NULL) {
  3878. + return ENOMEM;
  3879. + }
  3880. +
  3881. + err = pkg_init_from_file(pkg, filename);
  3882. + if (err) {
  3883. + return err;
  3884. + }
  3885. +
  3886. + if (!pkg->architecture) {
  3887. + ipkg_message(conf, IPKG_ERROR, "Package %s has no Architecture defined.\n", pkg->name);
  3888. + return -EINVAL;
  3889. + }
  3890. +
  3891. + /* XXX: CLEANUP: hash_insert_pkg has a nasty side effect of possibly
  3892. + freeing the pkg that we pass in. It might be nice to clean this up
  3893. + if possible. */
  3894. + pkg = hash_insert_pkg(&conf->pkg_hash, pkg, 1,conf);
  3895. + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name);
  3896. +
  3897. + pkg->local_filename = strdup(filename);
  3898. +
  3899. + if (old) {
  3900. + old_version = pkg_version_str_alloc(old);
  3901. + new_version = pkg_version_str_alloc(pkg);
  3902. +
  3903. + cmp = pkg_compare_versions(old, pkg);
  3904. + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
  3905. + cmp = -1 ; /* then we force ipkg to downgrade */
  3906. + /* We need to use a value < 0 because in the 0 case we are asking to */
  3907. + /* reinstall, and some check could fail asking the "force-reinstall" option */
  3908. + }
  3909. + if (cmp > 0) {
  3910. + ipkg_message(conf, IPKG_NOTICE,
  3911. + "Not downgrading package %s on %s from %s to %s.\n",
  3912. + old->name, old->dest->name, old_version, new_version);
  3913. + pkg->state_want = SW_DEINSTALL;
  3914. + pkg->state_flag |= SF_OBSOLETE;
  3915. + free(old_version);
  3916. + free(new_version);
  3917. + return 0;
  3918. + } else {
  3919. + free(old_version);
  3920. + free(new_version);
  3921. + }
  3922. + }
  3923. +
  3924. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
  3925. + return ipkg_install_pkg(conf, pkg,0);
  3926. +}
  3927. +
  3928. +ipkg_error_t ipkg_install_by_name(ipkg_conf_t *conf, const char *pkg_name)
  3929. +{
  3930. + int cmp;
  3931. + pkg_t *old, *new;
  3932. + char *old_version, *new_version;
  3933. +
  3934. + ipkg_message(conf, IPKG_DEBUG2, " Getting old from pkg_hash_fetch \n" );
  3935. + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg_name);
  3936. + if ( old )
  3937. + ipkg_message(conf, IPKG_DEBUG2, " Old versions from pkg_hash_fetch %s \n", old->version );
  3938. +
  3939. + ipkg_message(conf, IPKG_DEBUG2, " Getting new from pkg_hash_fetch \n" );
  3940. + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, pkg_name);
  3941. + if ( new )
  3942. + ipkg_message(conf, IPKG_DEBUG2, " New versions from pkg_hash_fetch %s \n", new->version );
  3943. +
  3944. +/* Pigi Basically here is broken the version stuff.
  3945. + What's happening is that nothing provide the version to differents
  3946. + functions, so the returned struct is always the latest.
  3947. + That's why the install by name don't work.
  3948. +*/
  3949. + ipkg_message(conf, IPKG_DEBUG2, " Versions from pkg_hash_fetch in %s ", __FUNCTION__ );
  3950. +
  3951. + if ( old )
  3952. + ipkg_message(conf, IPKG_DEBUG2, " old %s ", old->version );
  3953. + if ( new )
  3954. + ipkg_message(conf, IPKG_DEBUG2, " new %s ", new->version );
  3955. + ipkg_message(conf, IPKG_DEBUG2, " \n");
  3956. +
  3957. + if (new == NULL) {
  3958. + return IPKG_PKG_HAS_NO_CANDIDATE;
  3959. + }
  3960. +
  3961. + new->state_flag |= SF_USER;
  3962. + if (old) {
  3963. + old_version = pkg_version_str_alloc(old);
  3964. + new_version = pkg_version_str_alloc(new);
  3965. +
  3966. + cmp = pkg_compare_versions(old, new);
  3967. + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
  3968. + ipkg_message(conf, IPKG_DEBUG, " Forcing downgrade \n");
  3969. + cmp = -1 ; /* then we force ipkg to downgrade */
  3970. + /* We need to use a value < 0 because in the 0 case we are asking to */
  3971. + /* reinstall, and some check could fail asking the "force-reinstall" option */
  3972. + }
  3973. + ipkg_message(conf, IPKG_DEBUG,
  3974. + "Comparing visible versions of pkg %s:"
  3975. + "\n\t%s is installed "
  3976. + "\n\t%s is available "
  3977. + "\n\t%d was comparison result\n",
  3978. + pkg_name, old_version, new_version, cmp);
  3979. + if (cmp == 0 && !conf->force_reinstall) {
  3980. + ipkg_message(conf, IPKG_NOTICE,
  3981. + "Package %s (%s) installed in %s is up to date.\n",
  3982. + old->name, old_version, old->dest->name);
  3983. + free(old_version);
  3984. + free(new_version);
  3985. + return 0;
  3986. + } else if (cmp > 0) {
  3987. + ipkg_message(conf, IPKG_NOTICE,
  3988. + "Not downgrading package %s on %s from %s to %s.\n",
  3989. + old->name, old->dest->name, old_version, new_version);
  3990. + free(old_version);
  3991. + free(new_version);
  3992. + return 0;
  3993. + } else if (cmp < 0) {
  3994. + new->dest = old->dest;
  3995. + old->state_want = SW_DEINSTALL; /* Here probably the problem for bug 1277 */
  3996. + }
  3997. + }
  3998. +
  3999. + /* XXX: CLEANUP: The error code of ipkg_install_by_name is really
  4000. + supposed to be an ipkg_error_t, but ipkg_install_pkg could
  4001. + return any kind of integer, (might be errno from a syscall,
  4002. + etc.). This is a real mess and will need to be cleaned up if
  4003. + anyone ever wants to make a nice libipkg. */
  4004. +
  4005. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
  4006. + return ipkg_install_pkg(conf, new,0);
  4007. +}
  4008. +
  4009. +ipkg_error_t ipkg_install_multi_by_name(ipkg_conf_t *conf, const char *pkg_name)
  4010. +{
  4011. + abstract_pkg_vec_t *providers = pkg_hash_fetch_all_installation_candidates (&conf->pkg_hash, pkg_name);
  4012. + int i;
  4013. + ipkg_error_t err;
  4014. + abstract_pkg_t *ppkg ;
  4015. +
  4016. + if (providers == NULL)
  4017. + return IPKG_PKG_HAS_NO_CANDIDATE;
  4018. +
  4019. + for (i = 0; i < providers->len; i++) {
  4020. + ppkg = abstract_pkg_vec_get(providers, i);
  4021. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_by_name %d \n",__FUNCTION__, i);
  4022. + err = ipkg_install_by_name(conf, ppkg->name);
  4023. + if (err)
  4024. + return err;
  4025. +/* XXX Maybe ppkg should be freed ? */
  4026. + }
  4027. + return 0;
  4028. +}
  4029. +
  4030. +/*
  4031. + * Walk dependence graph starting with pkg, collect packages to be
  4032. + * installed into pkgs_needed, in dependence order.
  4033. + */
  4034. +int pkg_mark_dependencies_for_installation(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *pkgs_needed)
  4035. +{
  4036. + int i, err;
  4037. + pkg_vec_t *depends = pkg_vec_alloc();
  4038. + char **unresolved = NULL;
  4039. + int ndepends;
  4040. +
  4041. + ndepends = pkg_hash_fetch_unsatisfied_dependencies(conf,
  4042. + pkg, depends,
  4043. + &unresolved);
  4044. +
  4045. + if (unresolved) {
  4046. + ipkg_message(conf, IPKG_ERROR,
  4047. + "%s: Cannot satisfy the following dependencies for %s:\n\t",
  4048. + conf->force_depends ? "Warning" : "ERROR", pkg->name);
  4049. + while (*unresolved) {
  4050. + ipkg_message(conf, IPKG_ERROR, " %s", *unresolved);
  4051. + unresolved++;
  4052. + }
  4053. + ipkg_message(conf, IPKG_ERROR, "\n");
  4054. + if (! conf->force_depends) {
  4055. + ipkg_message(conf, IPKG_INFO,
  4056. + "This could mean that your package list is out of date or that the packages\n"
  4057. + "mentioned above do not yet exist (try 'ipkg update'). To proceed in spite\n"
  4058. + "of this problem try again with the '-force-depends' option.\n");
  4059. + pkg_vec_free(depends);
  4060. + return IPKG_PKG_DEPS_UNSATISFIED;
  4061. + }
  4062. + }
  4063. +
  4064. + if (ndepends <= 0) {
  4065. + pkg_vec_free(depends);
  4066. + return 0;
  4067. + }
  4068. +
  4069. + for (i = 0; i < depends->len; i++) {
  4070. + pkg_t *dep = depends->pkgs[i];
  4071. + /* The package was uninstalled when we started, but another
  4072. + dep earlier in this loop may have depended on it and pulled
  4073. + it in, so check first. */
  4074. + if ((dep->state_status != SS_INSTALLED)
  4075. + && (dep->state_status != SS_UNPACKED)
  4076. + && (dep->state_want != SW_INSTALL)) {
  4077. +
  4078. + /* Mark packages as to-be-installed */
  4079. + dep->state_want = SW_INSTALL;
  4080. +
  4081. + /* Dependencies should be installed the same place as pkg */
  4082. + if (dep->dest == NULL) {
  4083. + dep->dest = pkg->dest;
  4084. + }
  4085. +
  4086. + err = pkg_mark_dependencies_for_installation(conf, dep, pkgs_needed);
  4087. + if (err) {
  4088. + pkg_vec_free(depends);
  4089. + return err;
  4090. + }
  4091. + }
  4092. + }
  4093. + if (pkgs_needed)
  4094. + pkg_vec_insert(pkgs_needed, pkg);
  4095. +
  4096. + pkg_vec_free(depends);
  4097. +
  4098. + return 0;
  4099. +}
  4100. +
  4101. +int name_mark_dependencies_for_installation(ipkg_conf_t *conf, const char *pkg_name, pkg_vec_t *pkgs_needed)
  4102. +{
  4103. + int cmp;
  4104. + pkg_t *old, *new;
  4105. + char *old_version, *new_version;
  4106. +
  4107. + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg_name);
  4108. +
  4109. + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, pkg_name);
  4110. + if (new == NULL) {
  4111. + return IPKG_PKG_HAS_NO_CANDIDATE;
  4112. + }
  4113. + if (old) {
  4114. + old_version = pkg_version_str_alloc(old);
  4115. + new_version = pkg_version_str_alloc(new);
  4116. +
  4117. + cmp = pkg_compare_versions(old, new);
  4118. + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
  4119. + ipkg_message(conf, IPKG_DEBUG, " Forcing downgrade ");
  4120. + cmp = -1 ; /* then we force ipkg to downgrade */
  4121. + /* We need to use a value < 0 because in the 0 case we are asking to */
  4122. + /* reinstall, and some check could fail asking the "force-reinstall" option */
  4123. + }
  4124. + ipkg_message(conf, IPKG_DEBUG,
  4125. + "comparing visible versions of pkg %s:"
  4126. + "\n\t%s is installed "
  4127. + "\n\t%s is available "
  4128. + "\n\t%d was comparison result\n",
  4129. + pkg_name, old_version, new_version, cmp);
  4130. + if (cmp == 0 && !conf->force_reinstall) {
  4131. + ipkg_message(conf, IPKG_NOTICE,
  4132. + "Package %s (%s) installed in %s is up to date.\n",
  4133. + old->name, old_version, old->dest->name);
  4134. + free(old_version);
  4135. + free(new_version);
  4136. + return 0;
  4137. + } else if (cmp > 0) {
  4138. + ipkg_message(conf, IPKG_NOTICE,
  4139. + "Not downgrading package %s on %s from %s to %s.\n",
  4140. + old->name, old->dest->name, old_version, new_version);
  4141. + free(old_version);
  4142. + free(new_version);
  4143. + return 0;
  4144. + } else if (cmp < 0) {
  4145. + new->dest = old->dest;
  4146. + old->state_want = SW_DEINSTALL;
  4147. + old->state_flag |= SF_OBSOLETE;
  4148. + }
  4149. + }
  4150. + return pkg_mark_dependencies_for_installation(conf, new, pkgs_needed);
  4151. +}
  4152. +
  4153. +
  4154. +
  4155. +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg)
  4156. +{
  4157. + int i, err;
  4158. + pkg_vec_t *depends = pkg_vec_alloc();
  4159. + pkg_t *dep;
  4160. + char **unresolved = NULL;
  4161. + int ndepends;
  4162. +
  4163. + ndepends = pkg_hash_fetch_unsatisfied_dependencies(conf,
  4164. + pkg, depends,
  4165. + &unresolved);
  4166. +
  4167. + if (unresolved) {
  4168. + ipkg_message(conf, IPKG_ERROR,
  4169. + "%s: Cannot satisfy the following dependencies for %s:\n\t",
  4170. + conf->force_depends ? "Warning" : "ERROR", pkg->name);
  4171. + while (*unresolved) {
  4172. + ipkg_message(conf, IPKG_ERROR, " %s", *unresolved);
  4173. + unresolved++;
  4174. + }
  4175. + ipkg_message(conf, IPKG_ERROR, "\n");
  4176. + if (! conf->force_depends) {
  4177. + ipkg_message(conf, IPKG_INFO,
  4178. + "This could mean that your package list is out of date or that the packages\n"
  4179. + "mentioned above do not yet exist (try 'ipkg update'). To proceed in spite\n"
  4180. + "of this problem try again with the '-force-depends' option.\n");
  4181. + pkg_vec_free(depends);
  4182. + return IPKG_PKG_DEPS_UNSATISFIED;
  4183. + }
  4184. + }
  4185. +
  4186. + if (ndepends <= 0) {
  4187. + return 0;
  4188. + }
  4189. +
  4190. + /* Mark packages as to-be-installed */
  4191. + for (i=0; i < depends->len; i++) {
  4192. + /* Dependencies should be installed the same place as pkg */
  4193. + if (depends->pkgs[i]->dest == NULL) {
  4194. + depends->pkgs[i]->dest = pkg->dest;
  4195. + }
  4196. + depends->pkgs[i]->state_want = SW_INSTALL;
  4197. + }
  4198. +
  4199. + for (i = 0; i < depends->len; i++) {
  4200. + dep = depends->pkgs[i];
  4201. + /* The package was uninstalled when we started, but another
  4202. + dep earlier in this loop may have depended on it and pulled
  4203. + it in, so check first. */
  4204. + if ((dep->state_status != SS_INSTALLED)
  4205. + && (dep->state_status != SS_UNPACKED)) {
  4206. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
  4207. + err = ipkg_install_pkg(conf, dep,0);
  4208. + if (err) {
  4209. + pkg_vec_free(depends);
  4210. + return err;
  4211. + }
  4212. + }
  4213. + }
  4214. +
  4215. + pkg_vec_free(depends);
  4216. +
  4217. + return 0;
  4218. +}
  4219. +
  4220. +
  4221. +/* check all packages have their dependences satisfied, e.g., in case an upgraded package split */
  4222. +int ipkg_satisfy_all_dependences(ipkg_conf_t *conf)
  4223. +{
  4224. + if (conf->nodeps == 0) {
  4225. + int i;
  4226. + pkg_vec_t *installed = pkg_vec_alloc();
  4227. + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
  4228. + for (i = 0; i < installed->len; i++) {
  4229. + pkg_t *pkg = installed->pkgs[i];
  4230. + satisfy_dependencies_for(conf, pkg);
  4231. + }
  4232. + pkg_vec_free(installed);
  4233. + }
  4234. + return 0;
  4235. +}
  4236. +
  4237. +
  4238. +
  4239. +static int check_conflicts_for(ipkg_conf_t *conf, pkg_t *pkg)
  4240. +{
  4241. + int i;
  4242. + pkg_vec_t *conflicts = NULL;
  4243. + int level;
  4244. + const char *prefix;
  4245. + if (conf->force_depends) {
  4246. + level = IPKG_NOTICE;
  4247. + prefix = "Warning";
  4248. + } else {
  4249. + level = IPKG_ERROR;
  4250. + prefix = "ERROR";
  4251. + }
  4252. +
  4253. + if (!conf->force_depends)
  4254. + conflicts = (pkg_vec_t *)pkg_hash_fetch_conflicts(pkg);
  4255. +
  4256. + if (conflicts) {
  4257. + ipkg_message(conf, level,
  4258. + "%s: The following packages conflict with %s:\n\t", prefix, pkg->name);
  4259. + i = 0;
  4260. + while (i < conflicts->len)
  4261. + ipkg_message(conf, level, " %s", conflicts->pkgs[i++]->name);
  4262. + ipkg_message(conf, level, "\n");
  4263. + pkg_vec_free(conflicts);
  4264. + return IPKG_PKG_DEPS_UNSATISFIED;
  4265. + }
  4266. + return 0;
  4267. +}
  4268. +
  4269. +static int update_file_ownership(ipkg_conf_t *conf, pkg_t *new_pkg, pkg_t *old_pkg)
  4270. +{
  4271. + str_list_t *new_list = pkg_get_installed_files(new_pkg);
  4272. + str_list_elt_t *iter;
  4273. +
  4274. + for (iter = new_list->head; iter; iter = iter->next) {
  4275. + char *new_file = iter->data;
  4276. + pkg_t *owner = file_hash_get_file_owner(conf, new_file);
  4277. + if (!new_file)
  4278. + ipkg_message(conf, IPKG_ERROR, "Null new_file for new_pkg=%s\n", new_pkg->name);
  4279. + if (!owner || (owner == old_pkg))
  4280. + file_hash_set_file_owner(conf, new_file, new_pkg);
  4281. + }
  4282. + if (old_pkg) {
  4283. + str_list_t *old_list = pkg_get_installed_files(old_pkg);
  4284. + for (iter = old_list->head; iter; iter = iter->next) {
  4285. + char *old_file = iter->data;
  4286. + pkg_t *owner = file_hash_get_file_owner(conf, old_file);
  4287. + if (owner == old_pkg) {
  4288. + /* obsolete */
  4289. + hash_table_insert(&conf->obs_file_hash, old_file, old_pkg);
  4290. + }
  4291. + }
  4292. + }
  4293. + return 0;
  4294. +}
  4295. +
  4296. +static int verify_pkg_installable(ipkg_conf_t *conf, pkg_t *pkg)
  4297. +{
  4298. + /* XXX: FEATURE: Anything else needed here? Maybe a check on free space? */
  4299. +
  4300. + /* sma 6.20.02: yup; here's the first bit */
  4301. + /*
  4302. + * XXX: BUG easy for cworth
  4303. + * 1) please point the call below to the correct current root destination
  4304. + * 2) we need to resolve how to check the required space for a pending pkg,
  4305. + * my diddling with the .ipk file size below isn't going to cut it.
  4306. + * 3) return a proper error code instead of 1
  4307. + */
  4308. + int comp_size, blocks_available;
  4309. +
  4310. + if (!conf->force_space && pkg->installed_size != NULL) {
  4311. + blocks_available = get_available_blocks(conf->default_dest->root_dir);
  4312. +
  4313. + comp_size = strtoul(pkg->installed_size, NULL, 0);
  4314. + /* round up a blocks count without doing fancy-but-slow casting jazz */
  4315. + comp_size = (int)((comp_size + 1023) / 1024);
  4316. +
  4317. + if (comp_size >= blocks_available) {
  4318. + ipkg_message(conf, IPKG_ERROR,
  4319. + "Only have %d available blocks on filesystem %s, pkg %s needs %d\n",
  4320. + blocks_available, conf->default_dest->root_dir, pkg->name, comp_size);
  4321. + return ENOSPC;
  4322. + }
  4323. + }
  4324. + return 0;
  4325. +}
  4326. +
  4327. +static int unpack_pkg_control_files(ipkg_conf_t *conf, pkg_t *pkg)
  4328. +{
  4329. + int err;
  4330. + char *conffiles_file_name;
  4331. + char *root_dir;
  4332. + FILE *conffiles_file;
  4333. +
  4334. + sprintf_alloc(&pkg->tmp_unpack_dir, "%s/%s-XXXXXX", conf->tmp_dir, pkg->name);
  4335. +
  4336. + pkg->tmp_unpack_dir = mkdtemp(pkg->tmp_unpack_dir);
  4337. + if (pkg->tmp_unpack_dir == NULL) {
  4338. + ipkg_message(conf, IPKG_ERROR,
  4339. + "%s: Failed to create temporary directory '%s': %s\n",
  4340. + __FUNCTION__, pkg->tmp_unpack_dir, strerror(errno));
  4341. + return errno;
  4342. + }
  4343. +
  4344. + err = pkg_extract_control_files_to_dir(pkg, pkg->tmp_unpack_dir);
  4345. + if (err) {
  4346. + return err;
  4347. + }
  4348. +
  4349. + /* XXX: CLEANUP: There might be a cleaner place to read in the
  4350. + conffiles. Seems like I should be able to get everything to go
  4351. + through pkg_init_from_file. If so, maybe it would make sense to
  4352. + move all of unpack_pkg_control_files to that function. */
  4353. +
  4354. + /* Don't need to re-read conffiles if we already have it */
  4355. + if (pkg->conffiles.head) {
  4356. + return 0;
  4357. + }
  4358. +
  4359. + sprintf_alloc(&conffiles_file_name, "%s/conffiles", pkg->tmp_unpack_dir);
  4360. + if (! file_exists(conffiles_file_name)) {
  4361. + free(conffiles_file_name);
  4362. + return 0;
  4363. + }
  4364. +
  4365. + conffiles_file = fopen(conffiles_file_name, "r");
  4366. + if (conffiles_file == NULL) {
  4367. + fprintf(stderr, "%s: failed to open %s: %s\n",
  4368. + __FUNCTION__, conffiles_file_name, strerror(errno));
  4369. + free(conffiles_file_name);
  4370. + return errno;
  4371. + }
  4372. + free(conffiles_file_name);
  4373. +
  4374. + while (1) {
  4375. + char *cf_name;
  4376. + char *cf_name_in_dest;
  4377. +
  4378. + cf_name = file_read_line_alloc(conffiles_file);
  4379. + if (cf_name == NULL) {
  4380. + break;
  4381. + }
  4382. + str_chomp(cf_name);
  4383. + if (cf_name[0] == '\0') {
  4384. + continue;
  4385. + }
  4386. +
  4387. + /* Prepend dest->root_dir to conffile name.
  4388. + Take pains to avoid multiple slashes. */
  4389. + root_dir = pkg->dest->root_dir;
  4390. + if (conf->offline_root)
  4391. + /* skip the offline_root prefix */
  4392. + root_dir = pkg->dest->root_dir + strlen(conf->offline_root);
  4393. + sprintf_alloc(&cf_name_in_dest, "%s%s", root_dir,
  4394. + cf_name[0] == '/' ? (cf_name + 1) : cf_name);
  4395. +
  4396. + /* Can't get an md5sum now, (file isn't extracted yet).
  4397. + We'll wait until resolve_conffiles */
  4398. + conffile_list_append(&pkg->conffiles, cf_name_in_dest, NULL);
  4399. +
  4400. + free(cf_name);
  4401. + free(cf_name_in_dest);
  4402. + }
  4403. +
  4404. + fclose(conffiles_file);
  4405. +
  4406. + return 0;
  4407. +}
  4408. +
  4409. +/* returns number of installed replacees */
  4410. +int pkg_get_installed_replacees(pkg_t *pkg, pkg_vec_t *installed_replacees)
  4411. +{
  4412. + abstract_pkg_t **replaces = pkg->replaces;
  4413. + int replaces_count = pkg->replaces_count;
  4414. + int i, j;
  4415. + for (i = 0; i < replaces_count; i++) {
  4416. + abstract_pkg_t *ab_pkg = replaces[i];
  4417. + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
  4418. + if (pkg_vec) {
  4419. + for (j = 0; j < pkg_vec->len; j++) {
  4420. + pkg_t *replacee = pkg_vec->pkgs[j];
  4421. + if (!pkg_conflicts(pkg, replacee))
  4422. + continue;
  4423. + if (replacee->state_status == SS_INSTALLED) {
  4424. + pkg_vec_insert(installed_replacees, replacee);
  4425. + }
  4426. + }
  4427. + }
  4428. + }
  4429. + return installed_replacees->len;
  4430. +}
  4431. +
  4432. +int pkg_remove_installed_replacees(ipkg_conf_t *conf, pkg_vec_t *replacees)
  4433. +{
  4434. + int i;
  4435. + int replaces_count = replacees->len;
  4436. + for (i = 0; i < replaces_count; i++) {
  4437. + pkg_t *replacee = replacees->pkgs[i];
  4438. + int err;
  4439. + replacee->state_flag |= SF_REPLACE; /* flag it so remove won't complain */
  4440. + err = ipkg_remove_pkg(conf, replacee,0);
  4441. + if (err)
  4442. + return err;
  4443. + }
  4444. + return 0;
  4445. +}
  4446. +
  4447. +/* to unwind the removal: make sure they are installed */
  4448. +int pkg_remove_installed_replacees_unwind(ipkg_conf_t *conf, pkg_vec_t *replacees)
  4449. +{
  4450. + int i, err;
  4451. + int replaces_count = replacees->len;
  4452. + for (i = 0; i < replaces_count; i++) {
  4453. + pkg_t *replacee = replacees->pkgs[i];
  4454. + if (replacee->state_status != SS_INSTALLED) {
  4455. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
  4456. + err = ipkg_install_pkg(conf, replacee,0);
  4457. + if (err)
  4458. + return err;
  4459. + }
  4460. + }
  4461. + return 0;
  4462. +}
  4463. +
  4464. +int caught_sigint = 0;
  4465. +static void ipkg_install_pkg_sigint_handler(int sig)
  4466. +{
  4467. + caught_sigint = sig;
  4468. +}
  4469. +
  4470. +/* compares versions of pkg and old_pkg, returns 0 if OK to proceed with installation of pkg, 1 otherwise */
  4471. +static int ipkg_install_check_downgrade(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg, int message)
  4472. +{
  4473. + if (old_pkg) {
  4474. + char message_out[15];
  4475. + char *old_version = pkg_version_str_alloc(old_pkg);
  4476. + char *new_version = pkg_version_str_alloc(pkg);
  4477. + int cmp = pkg_compare_versions(old_pkg, pkg);
  4478. + int rc = 0;
  4479. +
  4480. + memset(message_out,'\x0',15);
  4481. + strncpy (message_out,"Upgrading ",strlen("Upgrading "));
  4482. + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
  4483. + cmp = -1 ; /* then we force ipkg to downgrade */
  4484. + strncpy (message_out,"Downgrading ",strlen("Downgrading ")); /* We need to use a value < 0 because in the 0 case we are asking to */
  4485. + /* reinstall, and some check could fail asking the "force-reinstall" option */
  4486. + }
  4487. +
  4488. + if (cmp > 0) {
  4489. + ipkg_message(conf, IPKG_NOTICE,
  4490. + "Not downgrading package %s on %s from %s to %s.\n",
  4491. + old_pkg->name, old_pkg->dest->name, old_version, new_version);
  4492. + rc = 1;
  4493. + } else if (cmp < 0) {
  4494. + ipkg_message(conf, IPKG_NOTICE,
  4495. + "%s%s on %s from %s to %s...\n",
  4496. + message_out, pkg->name, old_pkg->dest->name, old_version, new_version);
  4497. + pkg->dest = old_pkg->dest;
  4498. + rc = 0;
  4499. + } else /* cmp == 0 */ {
  4500. + if (conf->force_reinstall) {
  4501. + ipkg_message(conf, IPKG_NOTICE,
  4502. + "Reinstalling %s (%s) on %s...\n",
  4503. + pkg->name, new_version, old_pkg->dest->name);
  4504. + pkg->dest = old_pkg->dest;
  4505. + rc = 0;
  4506. + } else {
  4507. + ipkg_message(conf, IPKG_NOTICE,
  4508. + "Not installing %s (%s) on %s -- already installed.\n",
  4509. + pkg->name, new_version, old_pkg->dest->name);
  4510. + rc = 1;
  4511. + }
  4512. + }
  4513. + free(old_version);
  4514. + free(new_version);
  4515. + return rc;
  4516. + } else {
  4517. + char message_out[15], *version ;
  4518. + memset(message_out,'\x0',15);
  4519. + if ( message )
  4520. + strncpy( message_out,"Upgrading ",strlen("Upgrading ") );
  4521. + else
  4522. + strncpy( message_out,"Installing ",strlen("Installing ") );
  4523. + version = pkg_version_str_alloc(pkg);
  4524. +
  4525. + ipkg_message(conf, IPKG_NOTICE,
  4526. + "%s%s (%s) to %s...\n", message_out,
  4527. + pkg->name, version, pkg->dest->name);
  4528. + free(version);
  4529. + return 0;
  4530. + }
  4531. +}
  4532. +
  4533. +/* and now the meat... */
  4534. +int ipkg_install_pkg(ipkg_conf_t *conf, pkg_t *pkg, int from_upgrade)
  4535. +{
  4536. + int err = 0;
  4537. + int message = 0;
  4538. + pkg_t *old_pkg = NULL;
  4539. + pkg_vec_t *replacees;
  4540. + abstract_pkg_t *ab_pkg = NULL;
  4541. + int old_state_flag;
  4542. + uint8_t *file_md5;
  4543. +
  4544. +
  4545. + if ( from_upgrade )
  4546. + message = 1; /* Coming from an upgrade, and should change the output message */
  4547. +
  4548. + if (!pkg) {
  4549. + ipkg_message(conf, IPKG_ERROR,
  4550. + "INTERNAL ERROR: null pkg passed to ipkg_install_pkg\n");
  4551. + return -EINVAL;
  4552. + }
  4553. +
  4554. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s calling pkg_arch_supported %s \n", __FUNCTION__, __FUNCTION__);
  4555. +
  4556. + if (!pkg_arch_supported(conf, pkg)) {
  4557. + ipkg_message(conf, IPKG_ERROR, "INTERNAL ERROR: architecture %s for pkg %s is unsupported.\n",
  4558. + pkg->architecture, pkg->name);
  4559. + return -EINVAL;
  4560. + }
  4561. + if (pkg->state_status == SS_INSTALLED && conf->force_reinstall == 0 && conf->nodeps == 0) {
  4562. + err = satisfy_dependencies_for(conf, pkg);
  4563. + if (err) { return err; }
  4564. +
  4565. + ipkg_message(conf, IPKG_NOTICE,
  4566. + "Package %s is already installed in %s.\n",
  4567. + pkg->name, pkg->dest->name);
  4568. + return 0;
  4569. + }
  4570. +
  4571. + if (pkg->dest == NULL) {
  4572. + pkg->dest = conf->default_dest;
  4573. + }
  4574. +
  4575. + old_pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name);
  4576. +
  4577. + err = ipkg_install_check_downgrade(conf, pkg, old_pkg, message);
  4578. + if (err) { return err; }
  4579. +
  4580. + pkg->state_want = SW_INSTALL;
  4581. + if (old_pkg){
  4582. + old_pkg->state_want = SW_DEINSTALL; /* needed for check_data_file_clashes of dependences */
  4583. + }
  4584. +
  4585. +
  4586. + /* Abhaya: conflicts check */
  4587. + err = check_conflicts_for(conf, pkg);
  4588. + if (err) { return err; }
  4589. +
  4590. + /* this setup is to remove the upgrade scenario in the end when
  4591. + installing pkg A, A deps B & B deps on A. So both B and A are
  4592. + installed. Then A's installation is started resulting in an
  4593. + uncecessary upgrade */
  4594. + if (pkg->state_status == SS_INSTALLED
  4595. + && conf->force_reinstall == 0) return 0;
  4596. +
  4597. + err = verify_pkg_installable(conf, pkg);
  4598. + if (err) { return err; }
  4599. +
  4600. + if (pkg->local_filename == NULL) {
  4601. + err = ipkg_download_pkg(conf, pkg, conf->tmp_dir);
  4602. + if (err) {
  4603. + ipkg_message(conf, IPKG_ERROR,
  4604. + "Failed to download %s. Perhaps you need to run 'ipkg update'?\n",
  4605. + pkg->name);
  4606. + return err;
  4607. + }
  4608. + }
  4609. +
  4610. +/* Check for md5 values */
  4611. + if (pkg->md5sum)
  4612. + {
  4613. + file_md5 = file_md5sum_alloc(pkg->local_filename);
  4614. + if (strcmp((char *)file_md5, pkg->md5sum))
  4615. + {
  4616. + ipkg_message(conf, IPKG_ERROR,
  4617. + "Package %s md5sum mismatch. Either the ipkg or the package index are corrupt. Try 'ipkg update'.\n",
  4618. + pkg->name);
  4619. + free(file_md5);
  4620. + return err;
  4621. + }
  4622. + free(file_md5);
  4623. + }
  4624. +
  4625. + if (pkg->tmp_unpack_dir == NULL) {
  4626. + unpack_pkg_control_files(conf, pkg);
  4627. + }
  4628. +
  4629. + /* We should update the filelist here, so that upgrades of packages that split will not fail. -Jamey 27-MAR-03 */
  4630. +/* Pigi: check if it will pass from here when replacing. It seems to fail */
  4631. +/* That's rather strange that files don't change owner. Investigate !!!!!!*/
  4632. + err = update_file_ownership(conf, pkg, old_pkg);
  4633. + if (err) { return err; }
  4634. +
  4635. + if (conf->nodeps == 0) {
  4636. + err = satisfy_dependencies_for(conf, pkg);
  4637. + if (err) { return err; }
  4638. + }
  4639. +
  4640. + replacees = pkg_vec_alloc();
  4641. + pkg_get_installed_replacees(pkg, replacees);
  4642. +
  4643. + /* this next section we do with SIGINT blocked to prevent inconsistency between ipkg database and filesystem */
  4644. + {
  4645. + sigset_t newset, oldset;
  4646. + sighandler_t old_handler = NULL;
  4647. + int use_signal = 0;
  4648. + caught_sigint = 0;
  4649. + if (use_signal) {
  4650. + old_handler = signal(SIGINT, ipkg_install_pkg_sigint_handler);
  4651. + } else {
  4652. + sigemptyset(&newset);
  4653. + sigaddset(&newset, SIGINT);
  4654. + sigprocmask(SIG_BLOCK, &newset, &oldset);
  4655. + }
  4656. +
  4657. + ipkg_state_changed++;
  4658. + pkg->state_flag |= SF_FILELIST_CHANGED;
  4659. +
  4660. + /* XXX: BUG: we really should treat replacement more like an upgrade
  4661. + * Instead, we're going to remove the replacees
  4662. + */
  4663. + err = pkg_remove_installed_replacees(conf, replacees);
  4664. + if (err) goto UNWIND_REMOVE_INSTALLED_REPLACEES;
  4665. +
  4666. + /*
  4667. + err = prerm_upgrade_old_pkg(conf, pkg, old_pkg);
  4668. + if (err) goto UNWIND_PRERM_UPGRADE_OLD_PKG;
  4669. +
  4670. + err = prerm_deconfigure_conflictors(conf, pkg, replacees);
  4671. + if (err) goto UNWIND_PRERM_DECONFIGURE_CONFLICTORS;
  4672. + */
  4673. +
  4674. + err = preinst_configure(conf, pkg, old_pkg);
  4675. + /*
  4676. + if (err) goto UNWIND_PREINST_CONFIGURE;
  4677. + */
  4678. +
  4679. + err = backup_modified_conffiles(conf, pkg, old_pkg);
  4680. + if (err) goto UNWIND_BACKUP_MODIFIED_CONFFILES;
  4681. +
  4682. + err = check_data_file_clashes(conf, pkg, old_pkg);
  4683. + /*
  4684. + if (err) goto UNWIND_CHECK_DATA_FILE_CLASHES;
  4685. +
  4686. + err = postrm_upgrade_old_pkg(conf, pkg, old_pkg);
  4687. + if (err) goto UNWIND_POSTRM_UPGRADE_OLD_PKG;
  4688. + */
  4689. +
  4690. + if (conf->noaction) return 0;
  4691. +
  4692. + /* point of no return: no unwinding after this */
  4693. + if (old_pkg && !conf->force_reinstall) {
  4694. + old_pkg->state_want = SW_DEINSTALL;
  4695. +
  4696. + if (old_pkg->state_flag & SF_NOPRUNE) {
  4697. + ipkg_message(conf, IPKG_INFO,
  4698. + " not removing obsolesced files because package marked noprune\n");
  4699. + } else {
  4700. + ipkg_message(conf, IPKG_INFO,
  4701. + " removing obsolesced files\n");
  4702. + remove_obsolesced_files(conf, pkg, old_pkg);
  4703. + }
  4704. + /* removing files from old package, to avoid ghost files */
  4705. + remove_data_files_and_list(conf, old_pkg);
  4706. +/* Pigi : It should be better to remove also maintainer and postrem scripts here, just in case*/
  4707. + remove_maintainer_scripts_except_postrm(conf, old_pkg);
  4708. + remove_postrm(conf, old_pkg);
  4709. +/* Pigi */
  4710. +
  4711. + }
  4712. +
  4713. +
  4714. + ipkg_message(conf, IPKG_INFO,
  4715. + " installing maintainer scripts\n");
  4716. + install_maintainer_scripts(conf, pkg, old_pkg);
  4717. +
  4718. + /* the following just returns 0
  4719. + remove_disappeared(conf, pkg);
  4720. + */
  4721. +
  4722. + ipkg_message(conf, IPKG_INFO,
  4723. + " installing data files\n");
  4724. + install_data_files(conf, pkg);
  4725. +
  4726. +/* read comments from function for detail but I will execute this here as all other tests are ok.*/
  4727. + err = check_data_file_clashes_change(conf, pkg);
  4728. +
  4729. + ipkg_message(conf, IPKG_INFO,
  4730. + " resolving conf files\n");
  4731. + resolve_conffiles(conf, pkg);
  4732. +
  4733. + pkg->state_status = SS_UNPACKED;
  4734. + old_state_flag = pkg->state_flag;
  4735. + pkg->state_flag &= ~SF_PREFER;
  4736. + ipkg_message(conf, IPKG_DEBUG, " pkg=%s old_state_flag=%x state_flag=%x\n", pkg->name, old_state_flag, pkg->state_flag);
  4737. +
  4738. + if (old_pkg && !conf->force_reinstall) {
  4739. + old_pkg->state_status = SS_NOT_INSTALLED;
  4740. + }
  4741. +
  4742. + time(&pkg->installed_time);
  4743. +
  4744. + ipkg_message(conf, IPKG_INFO,
  4745. + " cleanup temp files\n");
  4746. + cleanup_temporary_files(conf, pkg);
  4747. +
  4748. + ab_pkg = pkg->parent;
  4749. + if (ab_pkg)
  4750. + ab_pkg->state_status = pkg->state_status;
  4751. +
  4752. + ipkg_message(conf, IPKG_INFO, "Done.\n");
  4753. +
  4754. + if (use_signal)
  4755. + signal(SIGINT, old_handler);
  4756. + else
  4757. + sigprocmask(SIG_UNBLOCK, &newset, &oldset);
  4758. +
  4759. + return 0;
  4760. +
  4761. +
  4762. + /*
  4763. + UNWIND_POSTRM_UPGRADE_OLD_PKG:
  4764. + postrm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
  4765. + UNWIND_CHECK_DATA_FILE_CLASHES:
  4766. + check_data_file_clashes_unwind(conf, pkg, old_pkg);
  4767. + */
  4768. + UNWIND_BACKUP_MODIFIED_CONFFILES:
  4769. + backup_modified_conffiles_unwind(pkg, old_pkg);
  4770. + /*
  4771. + UNWIND_PREINST_CONFIGURE:
  4772. + preinst_configure_unwind(conf, pkg, old_pkg);
  4773. + UNWIND_PRERM_DECONFIGURE_CONFLICTORS:
  4774. + prerm_deconfigure_conflictors_unwind(conf, pkg, replacees);
  4775. + UNWIND_PRERM_UPGRADE_OLD_PKG:
  4776. + prerm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
  4777. + */
  4778. + UNWIND_REMOVE_INSTALLED_REPLACEES:
  4779. + pkg_remove_installed_replacees_unwind(conf, replacees);
  4780. +
  4781. + ipkg_message(conf, IPKG_INFO,
  4782. + " cleanup temp files\n");
  4783. + cleanup_temporary_files(conf, pkg);
  4784. +
  4785. + ipkg_message(conf, IPKG_INFO,
  4786. + "Failed.\n");
  4787. + if (use_signal)
  4788. + signal(SIGINT, old_handler);
  4789. + else
  4790. + sigprocmask(SIG_UNBLOCK, &newset, &oldset);
  4791. +
  4792. + return err;
  4793. + }
  4794. +}
  4795. +
  4796. +/*
  4797. +static int prerm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4798. +{
  4799. + DPKG_INCOMPATIBILITY:
  4800. + dpkg does some things here that we don't do yet. Do we care?
  4801. +
  4802. + 1. If a version of the package is already installed, call
  4803. + old-prerm upgrade new-version
  4804. + 2. If the script runs but exits with a non-zero exit status
  4805. + new-prerm failed-upgrade old-version
  4806. + Error unwind, for both the above cases:
  4807. + old-postinst abort-upgrade new-version
  4808. + return 0;
  4809. +}
  4810. +*/
  4811. +
  4812. +/*
  4813. +static int prerm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4814. +{
  4815. + DPKG_INCOMPATIBILITY:
  4816. + dpkg does some things here that we don't do yet. Do we care?
  4817. + (See prerm_upgrade_old_package for details)
  4818. +
  4819. + return 0;
  4820. +}
  4821. +*/
  4822. +
  4823. +/*
  4824. +static int prerm_deconfigure_conflictors(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors)
  4825. +{
  4826. + DPKG_INCOMPATIBILITY:
  4827. + dpkg does some things here that we don't do yet. Do we care?
  4828. + 2. If a 'conflicting' package is being removed at the same time:
  4829. + 1. If any packages depended on that conflicting package and
  4830. + --auto-deconfigure is specified, call, for each such package:
  4831. + deconfigured's-prerm deconfigure \
  4832. + in-favour package-being-installed version \
  4833. + removing conflicting-package version
  4834. + Error unwind:
  4835. + deconfigured's-postinst abort-deconfigure \
  4836. + in-favour package-being-installed-but-failed version \
  4837. + removing conflicting-package version
  4838. +
  4839. + The deconfigured packages are marked as requiring
  4840. + configuration, so that if --install is used they will be
  4841. + configured again if possible.
  4842. + 2. To prepare for removal of the conflicting package, call:
  4843. + conflictor's-prerm remove in-favour package new-version
  4844. + Error unwind:
  4845. + conflictor's-postinst abort-remove in-favour package new-version
  4846. + return 0;
  4847. +}
  4848. +*/
  4849. +
  4850. +/*
  4851. +static int prerm_deconfigure_conflictors_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors)
  4852. +{
  4853. + DPKG_INCOMPATIBILITY: dpkg does some things here that we don't
  4854. + do yet. Do we care? (See prerm_deconfigure_conflictors for
  4855. + details)
  4856. + return 0;
  4857. +}
  4858. +*/
  4859. +
  4860. +static int preinst_configure(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4861. +{
  4862. + int err;
  4863. + char *preinst_args;
  4864. +
  4865. + if (old_pkg) {
  4866. + char *old_version = pkg_version_str_alloc(old_pkg);
  4867. + sprintf_alloc(&preinst_args, "upgrade %s", old_version);
  4868. + free(old_version);
  4869. + } else if (pkg->state_status == SS_CONFIG_FILES) {
  4870. + char *pkg_version = pkg_version_str_alloc(pkg);
  4871. + sprintf_alloc(&preinst_args, "install %s", pkg_version);
  4872. + free(pkg_version);
  4873. + } else {
  4874. + preinst_args = strdup("install");
  4875. + }
  4876. +
  4877. + err = pkg_run_script(conf, pkg, "preinst", preinst_args);
  4878. + if (err) {
  4879. + ipkg_message(conf, IPKG_ERROR,
  4880. + "Aborting installation of %s\n", pkg->name);
  4881. + return 1;
  4882. + }
  4883. +
  4884. + free(preinst_args);
  4885. +
  4886. + return 0;
  4887. +}
  4888. +
  4889. +/*
  4890. +static int preinst_configure_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4891. +{
  4892. + DPKG_INCOMPATIBILITY:
  4893. + dpkg does the following error unwind, should we?
  4894. + pkg->postrm abort-upgrade old-version
  4895. + OR pkg->postrm abort-install old-version
  4896. + OR pkg->postrm abort-install
  4897. + return 0;
  4898. +}
  4899. +*/
  4900. +
  4901. +static int backup_modified_conffiles(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4902. +{
  4903. + int err;
  4904. + conffile_list_elt_t *iter;
  4905. + conffile_t *cf;
  4906. +
  4907. + if (conf->noaction) return 0;
  4908. +
  4909. + /* Backup all modified conffiles */
  4910. + if (old_pkg) {
  4911. + for (iter = old_pkg->conffiles.head; iter; iter = iter->next) {
  4912. + char *cf_name;
  4913. +
  4914. + cf = iter->data;
  4915. + cf_name = root_filename_alloc(conf, cf->name);
  4916. +
  4917. + /* Don't worry if the conffile is just plain gone */
  4918. + if (file_exists(cf_name) && conffile_has_been_modified(conf, cf)) {
  4919. + err = backup_make_backup(conf, cf_name);
  4920. + if (err) {
  4921. + return err;
  4922. + }
  4923. + }
  4924. + free(cf_name);
  4925. + }
  4926. + }
  4927. +
  4928. + /* Backup all conffiles that were not conffiles in old_pkg */
  4929. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  4930. + char *cf_name;
  4931. + cf = iter->data;
  4932. + cf_name = root_filename_alloc(conf, cf->name);
  4933. + /* Ignore if this was a conffile in old_pkg as well */
  4934. + if (pkg_get_conffile(old_pkg, cf->name)) {
  4935. + continue;
  4936. + }
  4937. +
  4938. + if (file_exists(cf_name) && (! backup_exists_for(cf_name))) {
  4939. + err = backup_make_backup(conf, cf_name);
  4940. + if (err) {
  4941. + return err;
  4942. + }
  4943. + }
  4944. + free(cf_name);
  4945. + }
  4946. +
  4947. + return 0;
  4948. +}
  4949. +
  4950. +static int backup_modified_conffiles_unwind(pkg_t *pkg, pkg_t *old_pkg)
  4951. +{
  4952. + conffile_list_elt_t *iter;
  4953. +
  4954. + if (old_pkg) {
  4955. + for (iter = old_pkg->conffiles.head; iter; iter = iter->next) {
  4956. + backup_remove(iter->data->name);
  4957. + }
  4958. + }
  4959. +
  4960. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  4961. + backup_remove(iter->data->name);
  4962. + }
  4963. +
  4964. + return 0;
  4965. +}
  4966. +
  4967. +
  4968. +static int check_data_file_clashes(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4969. +{
  4970. + /* DPKG_INCOMPATIBILITY:
  4971. + ipkg takes a slightly different approach than dpkg at this
  4972. + point. dpkg installs each file in the new package while
  4973. + creating a backup for any file that is replaced, (so that it
  4974. + can unwind if necessary). To avoid complexity and redundant
  4975. + storage, ipkg doesn't do any installation until later, (at the
  4976. + point at which dpkg removes the backups.
  4977. +
  4978. + But, we do have to check for data file clashes, since after
  4979. + installing a package with a file clash, removing either of the
  4980. + packages involved in the clash has the potential to break the
  4981. + other package.
  4982. + */
  4983. + str_list_t *files_list;
  4984. + str_list_elt_t *iter;
  4985. +
  4986. + int clashes = 0;
  4987. +
  4988. + files_list = pkg_get_installed_files(pkg);
  4989. + for (iter = files_list->head; iter; iter = iter->next) {
  4990. + char *root_filename;
  4991. + char *filename = iter->data;
  4992. + root_filename = root_filename_alloc(conf, filename);
  4993. + if (file_exists(root_filename) && (! file_is_dir(root_filename))) {
  4994. + pkg_t *owner;
  4995. + pkg_t *obs;
  4996. + /* Pre-existing conffiles are OK */
  4997. + /* @@@@ should have way to check that it is a conffile -Jamey */
  4998. + if (backup_exists_for(root_filename)) {
  4999. + continue;
  5000. + }
  5001. +
  5002. + /* Pre-existing files are OK if force-overwrite was asserted. */
  5003. + if (conf->force_overwrite) {
  5004. + /* but we need to change who owns this file */
  5005. + file_hash_set_file_owner(conf, filename, pkg);
  5006. + continue;
  5007. + }
  5008. +
  5009. + owner = file_hash_get_file_owner(conf, filename);
  5010. +
  5011. + /* Pre-existing files are OK if owned by the pkg being upgraded. */
  5012. + if (owner && old_pkg) {
  5013. + if (strcmp(owner->name, old_pkg->name) == 0) {
  5014. + continue;
  5015. + }
  5016. + }
  5017. +
  5018. + /* Pre-existing files are OK if owned by a package replaced by new pkg. */
  5019. + if (owner) {
  5020. + ipkg_message(conf, IPKG_DEBUG2, "Checking for replaces for %s in package %s\n", filename, owner->name);
  5021. + if (pkg_replaces(pkg, owner)) {
  5022. + continue;
  5023. + }
  5024. +/* If the file that would be installed is owned by the same package, ( as per a reinstall or similar )
  5025. + then it's ok to overwrite. */
  5026. + if (strcmp(owner->name,pkg->name)==0){
  5027. + ipkg_message(conf, IPKG_INFO, "Replacing pre-existing file %s owned by package %s\n", filename, owner->name);
  5028. + continue;
  5029. + }
  5030. + }
  5031. +
  5032. + /* Pre-existing files are OK if they are obsolete */
  5033. + obs = hash_table_get(&conf->obs_file_hash, filename);
  5034. + if (obs) {
  5035. + ipkg_message(conf, IPKG_INFO, "Pre-exiting file %s is obsolete. obs_pkg=%s\n", filename, obs->name);
  5036. + continue;
  5037. + }
  5038. +
  5039. + /* We have found a clash. */
  5040. + ipkg_message(conf, IPKG_ERROR,
  5041. + "Package %s wants to install file %s\n"
  5042. + "\tBut that file is already provided by package ",
  5043. + pkg->name, filename);
  5044. + if (owner) {
  5045. + ipkg_message(conf, IPKG_ERROR,
  5046. + "%s\n", owner->name);
  5047. + } else {
  5048. + ipkg_message(conf, IPKG_ERROR,
  5049. + "<no package>\nPlease move this file out of the way and try again.\n");
  5050. + }
  5051. + clashes++;
  5052. + }
  5053. + free(root_filename);
  5054. + }
  5055. + pkg_free_installed_files(pkg);
  5056. +
  5057. + return clashes;
  5058. +}
  5059. +
  5060. +static int check_data_file_clashes_change(ipkg_conf_t *conf, pkg_t *pkg)
  5061. +{
  5062. + /* Basically that's the worst hack I could do to be able to change ownership of
  5063. + file list, but, being that we have no way to unwind the mods, due to structure
  5064. + of hash table, probably is the quickest hack too, whishing it would not slow-up thing too much.
  5065. + What we do here is change the ownership of file in hash if a replace ( or similar events
  5066. + happens )
  5067. + Only the action that are needed to change name should be considered.
  5068. + @@@ To change after 1.0 release.
  5069. + */
  5070. + str_list_t *files_list;
  5071. + str_list_elt_t *iter;
  5072. +
  5073. + int clashes = 0;
  5074. +
  5075. + files_list = pkg_get_installed_files(pkg);
  5076. + for (iter = files_list->head; iter; iter = iter->next) {
  5077. + char *root_filename;
  5078. + char *filename = iter->data;
  5079. + root_filename = root_filename_alloc(conf, filename);
  5080. + if (file_exists(root_filename) && (! file_is_dir(root_filename))) {
  5081. + pkg_t *owner;
  5082. +
  5083. + if (conf->force_overwrite) {
  5084. + /* but we need to change who owns this file */
  5085. + file_hash_set_file_owner(conf, filename, pkg);
  5086. + continue;
  5087. + }
  5088. +
  5089. + owner = file_hash_get_file_owner(conf, filename);
  5090. +
  5091. + /* Pre-existing files are OK if owned by a package replaced by new pkg. */
  5092. + if (owner) {
  5093. + if (pkg_replaces(pkg, owner)) {
  5094. +/* It's now time to change the owner of that file.
  5095. + It has been "replaced" from the new "Replaces", then I need to inform lists file about that. */
  5096. + ipkg_message(conf, IPKG_INFO, "Replacing pre-existing file %s owned by package %s\n", filename, owner->name);
  5097. + file_hash_set_file_owner(conf, filename, pkg);
  5098. + continue;
  5099. + }
  5100. + }
  5101. +
  5102. + }
  5103. + free(root_filename);
  5104. + }
  5105. + pkg_free_installed_files(pkg);
  5106. +
  5107. + return clashes;
  5108. +}
  5109. +
  5110. +/*
  5111. +static int check_data_file_clashes_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5112. +{
  5113. + Nothing to do since check_data_file_clashes doesn't change state
  5114. + return 0;
  5115. +}
  5116. +*/
  5117. +
  5118. +/*
  5119. +static int postrm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5120. +{
  5121. + DPKG_INCOMPATIBILITY: dpkg does the following here, should we?
  5122. + 1. If the package is being upgraded, call
  5123. + old-postrm upgrade new-version
  5124. + 2. If this fails, attempt:
  5125. + new-postrm failed-upgrade old-version
  5126. + Error unwind, for both cases:
  5127. + old-preinst abort-upgrade new-version
  5128. + return 0;
  5129. +}
  5130. +*/
  5131. +
  5132. +/*
  5133. +static int postrm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5134. +{
  5135. + DPKG_INCOMPATIBILITY:
  5136. + dpkg does some things here that we don't do yet. Do we care?
  5137. + (See postrm_upgrade_old_pkg for details)
  5138. + return 0;
  5139. +}
  5140. +*/
  5141. +
  5142. +static int remove_obsolesced_files(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5143. +{
  5144. + int err;
  5145. + str_list_t *old_files;
  5146. + str_list_elt_t *of;
  5147. + str_list_t *new_files;
  5148. + str_list_elt_t *nf;
  5149. +
  5150. + if (old_pkg == NULL) {
  5151. + return 0;
  5152. + }
  5153. +
  5154. + old_files = pkg_get_installed_files(old_pkg);
  5155. + new_files = pkg_get_installed_files(pkg);
  5156. +
  5157. + for (of = old_files->head; of; of = of->next) {
  5158. + pkg_t *owner;
  5159. + char *old, *new;
  5160. + old = of->data;
  5161. + for (nf = new_files->head; nf; nf = nf->next) {
  5162. + new = nf->data;
  5163. + if (strcmp(old, new) == 0) {
  5164. + goto NOT_OBSOLETE;
  5165. + }
  5166. + }
  5167. + if (file_is_dir(old)) {
  5168. + continue;
  5169. + }
  5170. + owner = file_hash_get_file_owner(conf, old);
  5171. + if (owner != old_pkg) {
  5172. + /* in case obsolete file no longer belongs to old_pkg */
  5173. + continue;
  5174. + }
  5175. +
  5176. + /* old file is obsolete */
  5177. + ipkg_message(conf, IPKG_INFO,
  5178. + " removing obsolete file %s\n", old);
  5179. + if (!conf->noaction) {
  5180. + err = unlink(old);
  5181. + if (err) {
  5182. + ipkg_message(conf, IPKG_ERROR, " Warning: remove %s failed: %s\n", old,
  5183. + strerror(errno));
  5184. + }
  5185. + }
  5186. +
  5187. + NOT_OBSOLETE:
  5188. + ;
  5189. + }
  5190. +
  5191. + pkg_free_installed_files(old_pkg);
  5192. + pkg_free_installed_files(pkg);
  5193. +
  5194. + return 0;
  5195. +}
  5196. +
  5197. +static int remove_obsolete_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5198. +{
  5199. + int i;
  5200. + int err = 0;
  5201. + char *globpattern;
  5202. + glob_t globbuf;
  5203. + if (0) {
  5204. + if (!pkg->dest) {
  5205. + ipkg_message(conf, IPKG_ERROR, "%s: no dest for package %s\n", __FUNCTION__, pkg->name);
  5206. + return -1;
  5207. + }
  5208. + sprintf_alloc(&globpattern, "%s/%s.*", pkg->dest->info_dir, pkg->name);
  5209. + err = glob(globpattern, 0, NULL, &globbuf);
  5210. + free(globpattern);
  5211. + if (err) {
  5212. + return err;
  5213. + }
  5214. + /* XXXX this should perhaps only remove the ones that are not overwritten in new package. Jamey 11/11/2003 */
  5215. + for (i = 0; i < globbuf.gl_pathc; i++) {
  5216. + ipkg_message(conf, IPKG_DEBUG, "Removing control file %s from old_pkg %s\n",
  5217. + globbuf.gl_pathv[i], old_pkg->name);
  5218. + if (!conf->noaction)
  5219. + unlink(globbuf.gl_pathv[i]);
  5220. + }
  5221. + globfree(&globbuf);
  5222. + }
  5223. + return err;
  5224. +}
  5225. +
  5226. +static int install_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5227. +{
  5228. + int ret;
  5229. + char *prefix;
  5230. +
  5231. + if (old_pkg)
  5232. + remove_obsolete_maintainer_scripts(conf, pkg, old_pkg);
  5233. + sprintf_alloc(&prefix, "%s.", pkg->name);
  5234. + ret = pkg_extract_control_files_to_dir_with_prefix(pkg,
  5235. + pkg->dest->info_dir,
  5236. + prefix);
  5237. + free(prefix);
  5238. + return ret;
  5239. +}
  5240. +
  5241. +/*
  5242. +static int remove_disappeared(ipkg_conf_t *conf, pkg_t *pkg)
  5243. +{
  5244. + DPKG_INCOMPATIBILITY:
  5245. + This is a fairly sophisticated dpkg operation. Shall we
  5246. + skip it?
  5247. +
  5248. + Any packages all of whose files have been overwritten during the
  5249. + installation, and which aren't required for dependencies, are
  5250. + considered to have been removed. For each such package
  5251. + 1. disappearer's-postrm disappear overwriter overwriter-version
  5252. + 2. The package's maintainer scripts are removed
  5253. + 3. It is noted in the status database as being in a sane state,
  5254. + namely not installed (any conffiles it may have are ignored,
  5255. + rather than being removed by dpkg). Note that disappearing
  5256. + packages do not have their prerm called, because dpkg doesn't
  5257. + know in advance that the package is going to vanish.
  5258. +
  5259. +
  5260. + return 0;
  5261. +}
  5262. +*/
  5263. +
  5264. +static int install_data_files(ipkg_conf_t *conf, pkg_t *pkg)
  5265. +{
  5266. + int err;
  5267. +
  5268. + /* ipkg takes a slightly different approach to data file backups
  5269. + than dpkg. Rather than removing backups at this point, we
  5270. + actually do the data file installation now. See comments in
  5271. + check_data_file_clashes() for more details. */
  5272. +
  5273. + ipkg_message(conf, IPKG_INFO,
  5274. + " extracting data files to %s\n", pkg->dest->root_dir);
  5275. + err = pkg_extract_data_files_to_dir(pkg, pkg->dest->root_dir);
  5276. + if (err) {
  5277. + return err;
  5278. + }
  5279. +
  5280. + /* XXX: BUG or FEATURE : We are actually loosing the Essential flag,
  5281. + so we can't save ourself from removing important packages
  5282. + At this point we (should) have extracted the .control file, so it
  5283. + would be a good idea to reload the data in it, and set the Essential
  5284. + state in *pkg. From now on the Essential is back in status file and
  5285. + we can protect again.
  5286. + We should operate this way:
  5287. + fopen the file ( pkg->dest->root_dir/pkg->name.control )
  5288. + check for "Essential" in it
  5289. + set the value in pkg->essential.
  5290. + This new routine could be useful also for every other flag
  5291. + Pigi: 16/03/2004 */
  5292. + set_flags_from_control(conf, pkg) ;
  5293. +
  5294. + ipkg_message(conf, IPKG_DEBUG, " Calling pkg_write_filelist from %s\n", __FUNCTION__);
  5295. + err = pkg_write_filelist(conf, pkg);
  5296. + if (err)
  5297. + return err;
  5298. +
  5299. + /* XXX: FEATURE: ipkg should identify any files which existed
  5300. + before installation and which were overwritten, (see
  5301. + check_data_file_clashes()). What it must do is remove any such
  5302. + files from the filelist of the old package which provided the
  5303. + file. Otherwise, if the old package were removed at some point
  5304. + it would break the new package. Removing the new package will
  5305. + also break the old one, but this cannot be helped since the old
  5306. + package's file has already been deleted. This is the importance
  5307. + of check_data_file_clashes(), and only allowing ipkg to install
  5308. + a clashing package with a user force. */
  5309. +
  5310. + return 0;
  5311. +}
  5312. +
  5313. +static int resolve_conffiles(ipkg_conf_t *conf, pkg_t *pkg)
  5314. +{
  5315. + conffile_list_elt_t *iter;
  5316. + conffile_t *cf;
  5317. + char *cf_backup;
  5318. + uint8_t *md5sum;
  5319. +
  5320. +
  5321. + if (conf->noaction) return 0;
  5322. +
  5323. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  5324. + char *root_filename;
  5325. + cf = iter->data;
  5326. + root_filename = root_filename_alloc(conf, cf->name);
  5327. +
  5328. + /* Might need to initialize the md5sum for each conffile */
  5329. + if (cf->value == NULL) {
  5330. + cf->value = (char *)file_md5sum_alloc(root_filename);
  5331. + }
  5332. +
  5333. + if (!file_exists(root_filename)) {
  5334. + free(root_filename);
  5335. + continue;
  5336. + }
  5337. +
  5338. + cf_backup = backup_filename_alloc(root_filename);
  5339. +
  5340. +
  5341. + if (file_exists(cf_backup)) {
  5342. + /* Let's compute md5 to test if files are changed */
  5343. + md5sum = file_md5sum_alloc(cf_backup);
  5344. + if (strcmp( cf->value, (char *)md5sum) != 0 ) {
  5345. + if (conf->force_defaults
  5346. + || user_prefers_old_conffile(cf->name, cf_backup) ) {
  5347. + rename(cf_backup, root_filename);
  5348. + }
  5349. + }
  5350. + unlink(cf_backup);
  5351. + free(md5sum);
  5352. + }
  5353. +
  5354. + free(cf_backup);
  5355. + free(root_filename);
  5356. + }
  5357. +
  5358. + return 0;
  5359. +}
  5360. +
  5361. +static int user_prefers_old_conffile(const char *file_name, const char *backup)
  5362. +{
  5363. + char *response;
  5364. + const char *short_file_name;
  5365. +
  5366. + short_file_name = strrchr(file_name, '/');
  5367. + if (short_file_name) {
  5368. + short_file_name++;
  5369. + } else {
  5370. + short_file_name = file_name;
  5371. + }
  5372. +
  5373. + while (1) {
  5374. + response = get_user_response(" Configuration file '%s'\n"
  5375. + " ==> File on system created by you or by a script.\n"
  5376. + " ==> File also in package provided by package maintainer.\n"
  5377. + " What would you like to do about it ? Your options are:\n"
  5378. + " Y or I : install the package maintainer's version\n"
  5379. + " N or O : keep your currently-installed version\n"
  5380. +#ifdef CONFIG_DIFF
  5381. + " D : show the differences between the versions\n"
  5382. +#endif
  5383. + " The default action is to keep your current version.\n"
  5384. + " *** %s (Y/I/N/O"
  5385. +#ifdef CONFIG_DIFF
  5386. + "/D"
  5387. +#endif
  5388. + ") [default=N] ? ", file_name, short_file_name);
  5389. + if (strcmp(response, "y") == 0
  5390. + || strcmp(response, "i") == 0
  5391. + || strcmp(response, "yes") == 0) {
  5392. + free(response);
  5393. + return 0;
  5394. + }
  5395. +
  5396. +#ifdef CONFIG_DIFF
  5397. + if (strcmp(response, "d") == 0) {
  5398. + char *cmd;
  5399. +
  5400. + free(response);
  5401. + /* XXX: BUG rewrite to use exec or busybox's internal diff */
  5402. + sprintf_alloc(&cmd, "diff -u %s %s", backup, file_name);
  5403. + xsystem(cmd);
  5404. + free(cmd);
  5405. + printf(" [Press ENTER to continue]\n");
  5406. + response = file_read_line_alloc(stdin);
  5407. + free(response);
  5408. + continue;
  5409. + }
  5410. +#endif
  5411. +
  5412. + free(response);
  5413. + return 1;
  5414. + }
  5415. +}
  5416. +
  5417. +/* XXX: CLEANUP: I'd like to move all of the code for
  5418. + creating/cleaning pkg->tmp_unpack_dir directly into pkg.c. (Then,
  5419. + it would make sense to cleanup pkg->tmp_unpack_dir directly from
  5420. + pkg_deinit for example). */
  5421. +static int cleanup_temporary_files(ipkg_conf_t *conf, pkg_t *pkg)
  5422. +{
  5423. + DIR *tmp_dir;
  5424. + struct dirent *dirent;
  5425. + char *tmp_file;
  5426. +
  5427. +#ifdef IPKG_DEBUG_NO_TMP_CLEANUP
  5428. +#error
  5429. + ipkg_message(conf, IPKG_DEBUG,
  5430. + "%s: Not cleaning up %s since ipkg compiled with IPKG_DEBUG_NO_TMP_CLEANUP\n",
  5431. + __FUNCTION__, pkg->tmp_unpack_dir);
  5432. + return 0;
  5433. +#endif
  5434. +
  5435. + if (pkg->tmp_unpack_dir && file_is_dir(pkg->tmp_unpack_dir)) {
  5436. + tmp_dir = opendir(pkg->tmp_unpack_dir);
  5437. + if (tmp_dir) {
  5438. + while (1) {
  5439. + dirent = readdir(tmp_dir);
  5440. + if (dirent == NULL) {
  5441. + break;
  5442. + }
  5443. + sprintf_alloc(&tmp_file, "%s/%s",
  5444. + pkg->tmp_unpack_dir, dirent->d_name);
  5445. + if (! file_is_dir(tmp_file)) {
  5446. + unlink(tmp_file);
  5447. + }
  5448. + free(tmp_file);
  5449. + }
  5450. + closedir(tmp_dir);
  5451. + rmdir(pkg->tmp_unpack_dir);
  5452. + free(pkg->tmp_unpack_dir);
  5453. + pkg->tmp_unpack_dir = NULL;
  5454. + }
  5455. + }
  5456. +
  5457. + ipkg_message(conf, IPKG_INFO, "cleanup_temporary_files: pkg=%s local_filename=%s tmp_dir=%s\n",
  5458. + pkg->name, pkg->local_filename, conf->tmp_dir);
  5459. + if (pkg->local_filename && strncmp(pkg->local_filename, conf->tmp_dir, strlen(conf->tmp_dir)) == 0) {
  5460. + unlink(pkg->local_filename);
  5461. + free(pkg->local_filename);
  5462. + pkg->local_filename = NULL;
  5463. + }
  5464. +
  5465. + return 0;
  5466. +}
  5467. +
  5468. +static char *backup_filename_alloc(const char *file_name)
  5469. +{
  5470. + char *backup;
  5471. +
  5472. + sprintf_alloc(&backup, "%s%s", file_name, IPKG_BACKUP_SUFFIX);
  5473. +
  5474. + return backup;
  5475. +}
  5476. +
  5477. +int backup_make_backup(ipkg_conf_t *conf, const char *file_name)
  5478. +{
  5479. + int err;
  5480. + char *backup;
  5481. +
  5482. + backup = backup_filename_alloc(file_name);
  5483. + err = file_copy(file_name, backup);
  5484. + if (err) {
  5485. + ipkg_message(conf, IPKG_ERROR,
  5486. + "%s: Failed to copy %s to %s\n",
  5487. + __FUNCTION__, file_name, backup);
  5488. + }
  5489. +
  5490. + free(backup);
  5491. +
  5492. + return err;
  5493. +}
  5494. +
  5495. +static int backup_exists_for(const char *file_name)
  5496. +{
  5497. + int ret;
  5498. + char *backup;
  5499. +
  5500. + backup = backup_filename_alloc(file_name);
  5501. +
  5502. + ret = file_exists(backup);
  5503. +
  5504. + free(backup);
  5505. +
  5506. + return ret;
  5507. +}
  5508. +
  5509. +static int backup_remove(const char *file_name)
  5510. +{
  5511. + char *backup;
  5512. +
  5513. + backup = backup_filename_alloc(file_name);
  5514. + unlink(backup);
  5515. + free(backup);
  5516. +
  5517. + return 0;
  5518. +}
  5519. +
  5520. +
  5521. +
  5522. +#ifdef CONFIG_IPKG_PROCESS_ACTIONS
  5523. +
  5524. +int ipkg_remove_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove)
  5525. +{
  5526. + /* first, remove the packages that need removing */
  5527. + for (i = 0 ; i < pkgs_to_remove->len; i++ ) {
  5528. + pkg_t *pkg = pkgs_to_remove->pkgs[i];
  5529. + err = ipkg_remove_pkg(conf, pkg,0);
  5530. + if (err) return err;
  5531. + }
  5532. + return 0;
  5533. +}
  5534. +
  5535. +int ipkg_process_actions_sanity_check(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_superseded, pkg_vec_t *pkgs_to_install)
  5536. +{
  5537. + int i;
  5538. + /* now one more pass checking on the ones that need to be installed */
  5539. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5540. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5541. + if (pkg->dest == NULL)
  5542. + pkg->dest = conf->default_dest;
  5543. +
  5544. + pkg->state_want = SW_INSTALL;
  5545. +
  5546. + /* Abhaya: conflicts check */
  5547. + err = check_conflicts_for(conf, pkg);
  5548. + if (err) { return err; }
  5549. + }
  5550. + return 0;
  5551. +}
  5552. +
  5553. +int ipkg_process_actions_unpack_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_to_install)
  5554. +{
  5555. + int i;
  5556. + /* now one more pass checking on the ones that need to be installed */
  5557. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5558. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5559. +
  5560. + /* XXX: FEATURE: Need to really support Provides/Replaces: here at some point */
  5561. + pkg_vec_t *replacees = pkg_vec_alloc();
  5562. + pkg_get_installed_replacees(pkg, replacees);
  5563. +
  5564. + /* XXX: BUG: we really should treat replacement more like an upgrade
  5565. + * Instead, we're going to remove the replacees
  5566. + */
  5567. + err = pkg_remove_installed_replacees(conf, replacees);
  5568. + if (err) return err;
  5569. + pkg->state_flag |= SF_REMOVED_REPLACEES;
  5570. + }
  5571. + return 0;
  5572. +}
  5573. +
  5574. +int ipkg_process_actions_unpack_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_to_install)
  5575. +{
  5576. + int i;
  5577. + /* now one more pass checking on the ones that need to be installed */
  5578. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5579. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5580. + if (pkg->local_filename == NULL) {
  5581. + err = ipkg_download_pkg(conf, pkg, conf->tmp_dir);
  5582. + if (err) {
  5583. + ipkg_message(conf, IPKG_ERROR,
  5584. + "Failed to download %s. Perhaps you need to run 'ipkg update'?\n",
  5585. + pkg->name);
  5586. + return err;
  5587. + }
  5588. + }
  5589. + if (pkg->tmp_unpack_dir == NULL) {
  5590. + err = unpack_pkg_control_files(conf, pkg);
  5591. + if (err) return err;
  5592. + }
  5593. + }
  5594. + return 0;
  5595. +}
  5596. +
  5597. +int ipkg_process_actions_prerm(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
  5598. +{
  5599. + int i;
  5600. + /* now one more pass checking on the ones that need to be installed */
  5601. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5602. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5603. + pkg_t *old_pkg = pkg->old_pkg;
  5604. +
  5605. + err = prerm_upgrade_old_pkg(conf, pkg, old_pkg);
  5606. + if (err) return err;
  5607. +
  5608. + err = prerm_deconfigure_conflictors(conf, pkg, replacees);
  5609. + if (err) return err;
  5610. +
  5611. + err = preinst_configure(conf, pkg, old_pkg);
  5612. + if (err) return err;
  5613. +
  5614. + err = backup_modified_conffiles(conf, pkg, old_pkg);
  5615. + if (err) return err;
  5616. +
  5617. + err = postrm_upgrade_old_pkg(conf, pkg, old_pkg);
  5618. + if (err) return err;
  5619. + }
  5620. + return 0;
  5621. +}
  5622. +
  5623. +int ipkg_process_actions_install(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
  5624. +{
  5625. + int i;
  5626. + /* now one more pass checking on the ones that need to be installed */
  5627. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5628. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5629. + pkg_t *old_pkg = pkg->old_pkg;
  5630. +
  5631. + if (old_pkg) {
  5632. + old_pkg->state_want = SW_DEINSTALL;
  5633. +
  5634. + if (old_pkg->state_flag & SF_NOPRUNE) {
  5635. + ipkg_message(conf, IPKG_INFO,
  5636. + " not removing obsolesced files because package marked noprune\n");
  5637. + } else {
  5638. + ipkg_message(conf, IPKG_INFO,
  5639. + " removing obsolesced files\n");
  5640. + remove_obsolesced_files(conf, pkg, old_pkg);
  5641. + }
  5642. + }
  5643. +
  5644. + ipkg_message(conf, IPKG_INFO,
  5645. + " installing maintainer scripts\n");
  5646. + install_maintainer_scripts(conf, pkg, old_pkg);
  5647. +
  5648. + /* the following just returns 0 */
  5649. + remove_disappeared(conf, pkg);
  5650. +
  5651. + ipkg_message(conf, IPKG_INFO,
  5652. + " installing data files\n");
  5653. + install_data_files(conf, pkg);
  5654. +
  5655. + ipkg_message(conf, IPKG_INFO,
  5656. + " resolving conf files\n");
  5657. + resolve_conffiles(conf, pkg);
  5658. +
  5659. + pkg->state_status = SS_UNPACKED;
  5660. +
  5661. + if (old_pkg) {
  5662. + old_pkg->state_status = SS_NOT_INSTALLED;
  5663. + }
  5664. +
  5665. + time(&pkg->installed_time);
  5666. +
  5667. + ipkg_message(conf, IPKG_INFO,
  5668. + " cleanup temp files\n");
  5669. + cleanup_temporary_files(conf, pkg);
  5670. +
  5671. + if (pkg->parent)
  5672. + pkg->parent->state_status = pkg->state_status;
  5673. + }
  5674. + return 0;
  5675. +}
  5676. +
  5677. +int ipkg_process_actions_unwind_prerm(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
  5678. +{
  5679. + int i;
  5680. + /* now one more pass checking on the ones that need to be installed */
  5681. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5682. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5683. + pkg_t *old_pkg = pkg->old_pkg;
  5684. +
  5685. + if (old_pkg) {
  5686. + if (old_pkg->state_flags & SF_POSTRM_UPGRADE)
  5687. + postrm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
  5688. + if (old_pkg->state_flags & SF_CHECK_DATA_FILE_CLASHES)
  5689. + check_data_file_clashes_unwind(conf, pkg, old_pkg);
  5690. + if (old_pkg->state_flags & SF_BACKUP_MODIFIED_CONFFILES)
  5691. + backup_modified_conffiles_unwind(pkg, old_pkg);
  5692. + */
  5693. + if (old_pkg->state_flags & SF_PREINST_CONFIGURE)
  5694. + preinst_configure_unwind(conf, pkg, old_pkg);
  5695. + if (old_pkg->state_flags & SF_DECONFIGURE_CONFLICTORS)
  5696. + prerm_deconfigure_conflictors_unwind(conf, pkg, replacees);
  5697. + if (old_pkg->state_flags & SF_PRERM_UPGRADE)
  5698. + prerm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
  5699. + */
  5700. +
  5701. + if (old_pkg->state_flags & SF_REMOVED_REPLACEES)
  5702. + remove_installed_replacees_unwind(conf, pkg, old_pkg);
  5703. +
  5704. + }
  5705. + }
  5706. + return 0;
  5707. +}
  5708. +
  5709. +/*
  5710. + * Perform all the actions.
  5711. + *
  5712. + * pkgs_to_remove are packages marked for removal.
  5713. + * pkgs_superseded are the old packages being replaced by upgrades.
  5714. + *
  5715. + * Assumes pkgs_to_install includes all dependences, recursively, sorted in installable order.
  5716. + */
  5717. +int ipkg_process_actions(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_superseded, pkg_vec_t *pkgs_to_install)
  5718. +{
  5719. + int err;
  5720. + int i;
  5721. +
  5722. + err = ipkg_remove_packages(conf, pkgs_to_remove);
  5723. + if (err) return err;
  5724. +
  5725. + err = ipkg_process_actions_sanity_check(conf, pkgs_superseded, pkgs_to_install);
  5726. + if (err) return err;
  5727. +
  5728. + err = ipkg_process_actions_remove_replacees(conf, pkgs_to_install);
  5729. + if (err) goto UNWIND;
  5730. +
  5731. + /* @@@@ look at ipkg_install_pkg for handling replacements */
  5732. + err = ipkg_process_actions_unpack_packages(conf, pkgs_to_install);
  5733. + if (err) goto UNWIND;
  5734. +
  5735. + /*
  5736. + * Now that we have the packages unpacked, we can look for data
  5737. + * file clashes. First, we mark the files from the superseded
  5738. + * packages as obsolete. Then we scan the files in
  5739. + * pkgs_to_install, and only complain about clashes with
  5740. + * non-obsolete files.
  5741. + */
  5742. +
  5743. + err = ipkg_process_actions_check_data_file_clashes(conf, pkgs_superseded, pkgs_to_install);
  5744. + if (err) goto UNWIND;
  5745. +
  5746. + /* this was before checking data file clashes */
  5747. + err = ipkg_process_actions_prerm(conf, pkgs_superseded, pkgs_to_install);
  5748. + if (err) goto UNWIND;
  5749. +
  5750. + /* point of no return: no unwinding after this */
  5751. + err = ipkg_process_actions_install(conf, pkgs_to_install);
  5752. + if (err) return err;
  5753. +
  5754. + ipkg_message(conf, IPKG_INFO, "Done.\n");
  5755. + return 0;
  5756. +
  5757. + UNWIND:
  5758. + ipkg_process_actions_unwind(conf, pkgs_to_install);
  5759. +
  5760. + ipkg_message(conf, IPKG_INFO,
  5761. + " cleanup temp files\n");
  5762. + cleanup_temporary_files(conf, pkg);
  5763. +
  5764. + ipkg_message(conf, IPKG_INFO,
  5765. + "Failed.\n");
  5766. + return err;
  5767. +}
  5768. +
  5769. +#endif
  5770. diff -Nur busybox-1.19.4.orig/archival/libipkg/ipkg_install.h busybox-1.19.4/archival/libipkg/ipkg_install.h
  5771. --- busybox-1.19.4.orig/archival/libipkg/ipkg_install.h 1970-01-01 01:00:00.000000000 +0100
  5772. +++ busybox-1.19.4/archival/libipkg/ipkg_install.h 2012-03-17 00:58:08.193100680 +0100
  5773. @@ -0,0 +1,35 @@
  5774. +/* ipkg_install.h - the itsy package management system
  5775. +
  5776. + Carl D. Worth
  5777. +
  5778. + Copyright (C) 2001 University of Southern California
  5779. +
  5780. + This program is free software; you can redistribute it and/or
  5781. + modify it under the terms of the GNU General Public License as
  5782. + published by the Free Software Foundation; either version 2, or (at
  5783. + your option) any later version.
  5784. +
  5785. + This program is distributed in the hope that it will be useful, but
  5786. + WITHOUT ANY WARRANTY; without even the implied warranty of
  5787. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  5788. + General Public License for more details.
  5789. +*/
  5790. +
  5791. +#ifndef IPKG_INSTALL_H
  5792. +#define IPKG_INSTALL_H
  5793. +
  5794. +#include "pkg.h"
  5795. +#include "ipkg_conf.h"
  5796. +
  5797. +ipkg_error_t ipkg_install_by_name(ipkg_conf_t *conf, const char *pkg_name);
  5798. +ipkg_error_t ipkg_install_multi_by_name(ipkg_conf_t *conf, const char *pkg_name);
  5799. +int ipkg_install_from_file(ipkg_conf_t *conf, const char *filename);
  5800. +int ipkg_install_pkg(ipkg_conf_t *conf, pkg_t *pkg,int from_upgrading);
  5801. +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg);
  5802. +
  5803. +int ipkg_satisfy_all_dependences(ipkg_conf_t *conf);
  5804. +
  5805. +int pkg_mark_dependencies_for_installation(ipkg_conf_t *conf, pkg_t *pkg_name, pkg_vec_t *pkgs_needed);
  5806. +int name_mark_dependencies_for_installation(ipkg_conf_t *conf, const char *pkg_name, pkg_vec_t *pkgs_needed);
  5807. +
  5808. +#endif
  5809. diff -Nur busybox-1.19.4.orig/archival/libipkg/ipkg_message.c busybox-1.19.4/archival/libipkg/ipkg_message.c
  5810. --- busybox-1.19.4.orig/archival/libipkg/ipkg_message.c 1970-01-01 01:00:00.000000000 +0100
  5811. +++ busybox-1.19.4/archival/libipkg/ipkg_message.c 2012-03-17 00:58:08.193100680 +0100
  5812. @@ -0,0 +1,35 @@
  5813. +/* ipkg_message.c - the itsy package management system
  5814. +
  5815. + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
  5816. +
  5817. + This program is free software; you can redistribute it and/or
  5818. + modify it under the terms of the GNU General Public License as
  5819. + published by the Free Software Foundation; either version 2, or (at
  5820. + your option) any later version.
  5821. +
  5822. + This program is distributed in the hope that it will be useful, but
  5823. + WITHOUT ANY WARRANTY; without even the implied warranty of
  5824. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  5825. + General Public License for more details.
  5826. +*/
  5827. +
  5828. +
  5829. +#include "ipkg.h"
  5830. +#include "ipkg_conf.h"
  5831. +#include "ipkg_message.h"
  5832. +#include "libipkg.h"
  5833. +
  5834. +void
  5835. +ipkg_message (ipkg_conf_t * conf, message_level_t level, const char *fmt, ...)
  5836. +{
  5837. + va_list ap;
  5838. + char ts[256];
  5839. +
  5840. + if (ipkg_cb_message)
  5841. + {
  5842. + va_start (ap, fmt);
  5843. + vsnprintf (ts,256,fmt, ap);
  5844. + va_end (ap);
  5845. + ipkg_cb_message(conf,level,ts);
  5846. + }
  5847. +}
  5848. diff -Nur busybox-1.19.4.orig/archival/libipkg/ipkg_message.h busybox-1.19.4/archival/libipkg/ipkg_message.h
  5849. --- busybox-1.19.4.orig/archival/libipkg/ipkg_message.h 1970-01-01 01:00:00.000000000 +0100
  5850. +++ busybox-1.19.4/archival/libipkg/ipkg_message.h 2012-03-17 00:58:08.193100680 +0100
  5851. @@ -0,0 +1,32 @@
  5852. +/* ipkg_message.h - the itsy package management system
  5853. +
  5854. + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
  5855. +
  5856. + This program is free software; you can redistribute it and/or
  5857. + modify it under the terms of the GNU General Public License as
  5858. + published by the Free Software Foundation; either version 2, or (at
  5859. + your option) any later version.
  5860. +
  5861. + This program is distributed in the hope that it will be useful, but
  5862. + WITHOUT ANY WARRANTY; without even the implied warranty of
  5863. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  5864. + General Public License for more details.
  5865. +*/
  5866. +
  5867. +#ifndef _IPKG_MESSAGE_H_
  5868. +#define _IPKG_MESSAGE_H_
  5869. +
  5870. +#include "ipkg.h"
  5871. +#include "ipkg_conf.h"
  5872. +
  5873. +typedef enum {
  5874. + IPKG_ERROR, /* error conditions */
  5875. + IPKG_NOTICE, /* normal but significant condition */
  5876. + IPKG_INFO, /* informational message */
  5877. + IPKG_DEBUG, /* debug level message */
  5878. + IPKG_DEBUG2, /* more debug level message */
  5879. +} message_level_t;
  5880. +
  5881. +extern void ipkg_message(ipkg_conf_t *conf, message_level_t level, const char *fmt, ...);
  5882. +
  5883. +#endif /* _IPKG_MESSAGE_H_ */
  5884. diff -Nur busybox-1.19.4.orig/archival/libipkg/ipkg_remove.c busybox-1.19.4/archival/libipkg/ipkg_remove.c
  5885. --- busybox-1.19.4.orig/archival/libipkg/ipkg_remove.c 1970-01-01 01:00:00.000000000 +0100
  5886. +++ busybox-1.19.4/archival/libipkg/ipkg_remove.c 2012-03-17 00:58:08.193100680 +0100
  5887. @@ -0,0 +1,385 @@
  5888. +/* ipkg_remove.c - the itsy package management system
  5889. +
  5890. + Carl D. Worth
  5891. +
  5892. + Copyright (C) 2001 University of Southern California
  5893. +
  5894. + This program is free software; you can redistribute it and/or
  5895. + modify it under the terms of the GNU General Public License as
  5896. + published by the Free Software Foundation; either version 2, or (at
  5897. + your option) any later version.
  5898. +
  5899. + This program is distributed in the hope that it will be useful, but
  5900. + WITHOUT ANY WARRANTY; without even the implied warranty of
  5901. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  5902. + General Public License for more details.
  5903. +*/
  5904. +
  5905. +#include "ipkg.h"
  5906. +#include "ipkg_message.h"
  5907. +
  5908. +#include <glob.h>
  5909. +
  5910. +#include "ipkg_remove.h"
  5911. +
  5912. +#include "file_util.h"
  5913. +#include "sprintf_alloc.h"
  5914. +#include "str_util.h"
  5915. +
  5916. +#include "ipkg_cmd.h"
  5917. +
  5918. +int ipkg_remove_dependent_pkgs (ipkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **dependents);
  5919. +
  5920. +/*
  5921. + * Returns number of the number of packages depending on the packages provided by this package.
  5922. + * Every package implicitly provides itself.
  5923. + */
  5924. +int pkg_has_installed_dependents(pkg_t *pkg, abstract_pkg_t *** pdependents)
  5925. +{
  5926. + int nprovides = pkg->provides_count;
  5927. + abstract_pkg_t **provides = pkg->provides;
  5928. + int n_installed_dependents = 0;
  5929. + int i;
  5930. + for (i = 0; i <= nprovides; i++) {
  5931. + abstract_pkg_t *providee = provides[i];
  5932. + abstract_pkg_t **dependers = providee->depended_upon_by;
  5933. + abstract_pkg_t *dep_ab_pkg;
  5934. + if (dependers == NULL)
  5935. + continue;
  5936. + while ((dep_ab_pkg = *dependers++) != NULL) {
  5937. + if (dep_ab_pkg->state_status == SS_INSTALLED){
  5938. + n_installed_dependents++;
  5939. + }
  5940. + }
  5941. +
  5942. + }
  5943. + /* if caller requested the set of installed dependents */
  5944. + if (pdependents) {
  5945. + int p = 0;
  5946. + abstract_pkg_t **dependents = (abstract_pkg_t **)malloc((n_installed_dependents+1)*sizeof(abstract_pkg_t *));
  5947. +
  5948. + if ( dependents == NULL ){
  5949. + fprintf(stderr,"%s Unable to allocate memory. REPORT THIS BUG IN BUGZILLA PLEASE\n", __FUNCTION__);
  5950. + return -1;
  5951. + }
  5952. +
  5953. + *pdependents = dependents;
  5954. + for (i = 0; i <= nprovides; i++) {
  5955. + abstract_pkg_t *providee = provides[i];
  5956. + abstract_pkg_t **dependers = providee->depended_upon_by;
  5957. + abstract_pkg_t *dep_ab_pkg;
  5958. + if (dependers == NULL)
  5959. + continue;
  5960. + while ((dep_ab_pkg = *dependers++) != NULL) {
  5961. + if (dep_ab_pkg->state_status == SS_INSTALLED && !(dep_ab_pkg->state_flag & SF_MARKED)) {
  5962. + dependents[p++] = dep_ab_pkg;
  5963. + dep_ab_pkg->state_flag |= SF_MARKED;
  5964. + }
  5965. + }
  5966. + }
  5967. + dependents[p] = NULL;
  5968. + /* now clear the marks */
  5969. + for (i = 0; i < p; i++) {
  5970. + abstract_pkg_t *dep_ab_pkg = dependents[i];
  5971. + dep_ab_pkg->state_flag &= ~SF_MARKED;
  5972. + }
  5973. + }
  5974. + return n_installed_dependents;
  5975. +}
  5976. +
  5977. +int ipkg_remove_dependent_pkgs (ipkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **dependents)
  5978. +{
  5979. + int i;
  5980. + int a;
  5981. + int count;
  5982. + pkg_vec_t *dependent_pkgs = pkg_vec_alloc();
  5983. + abstract_pkg_t * ab_pkg;
  5984. +
  5985. + if((ab_pkg = pkg->parent) == NULL){
  5986. + fprintf(stderr, "%s: unable to get dependent pkgs. pkg %s isn't in hash table\n",
  5987. + __FUNCTION__, pkg->name);
  5988. + return 0;
  5989. + }
  5990. +
  5991. + if (dependents == NULL)
  5992. + return 0;
  5993. +
  5994. + // here i am using the dependencies_checked
  5995. + if (ab_pkg->dependencies_checked == 2) // variable to make out whether this package
  5996. + return 0; // has already been encountered in the process
  5997. + // of marking packages for removal - Karthik
  5998. + ab_pkg->dependencies_checked = 2;
  5999. +
  6000. + i = 0;
  6001. + count = 1;
  6002. + while (dependents [i] != NULL) {
  6003. + abstract_pkg_t *dep_ab_pkg = dependents[i];
  6004. +
  6005. + if (dep_ab_pkg->dependencies_checked == 2){
  6006. + i++;
  6007. + continue;
  6008. + }
  6009. + if (dep_ab_pkg->state_status == SS_INSTALLED) {
  6010. + for (a = 0; a < dep_ab_pkg->pkgs->len; a++) {
  6011. + pkg_t *dep_pkg = dep_ab_pkg->pkgs->pkgs[a];
  6012. + if (dep_pkg->state_status == SS_INSTALLED) {
  6013. + pkg_vec_insert(dependent_pkgs, dep_pkg);
  6014. + count++;
  6015. + }
  6016. + }
  6017. + }
  6018. + i++;
  6019. + /* 1 - to keep track of visited ab_pkgs when checking for possiblility of a broken removal of pkgs.
  6020. + * 2 - to keep track of pkgs whose deps have been checked alrdy - Karthik */
  6021. + }
  6022. +
  6023. + if (count == 1)
  6024. + return 0;
  6025. +
  6026. +
  6027. + for (i = 0; i < dependent_pkgs->len; i++) {
  6028. + int err = ipkg_remove_pkg(conf, dependent_pkgs->pkgs[i],0);
  6029. + if (err)
  6030. + return err;
  6031. + }
  6032. + return 0;
  6033. +}
  6034. +
  6035. +static int user_prefers_removing_dependents(ipkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **dependents)
  6036. +{
  6037. + abstract_pkg_t *dep_ab_pkg;
  6038. + ipkg_message(conf, IPKG_ERROR, "Package %s is depended upon by packages:\n", pkg->name);
  6039. + while ((dep_ab_pkg = *dependents++) != NULL) {
  6040. + if (dep_ab_pkg->state_status == SS_INSTALLED)
  6041. + ipkg_message(conf, IPKG_ERROR, "\t%s\n", dep_ab_pkg->name);
  6042. + }
  6043. + ipkg_message(conf, IPKG_ERROR, "These might cease to work if package %s is removed.\n\n", pkg->name);
  6044. + ipkg_message(conf, IPKG_ERROR, "");
  6045. + ipkg_message(conf, IPKG_ERROR, "You can force removal of this package with -force-depends.\n");
  6046. + ipkg_message(conf, IPKG_ERROR, "You can force removal of this package and its dependents\n");
  6047. + ipkg_message(conf, IPKG_ERROR, "with -force-removal-of-dependent-packages or -recursive\n");
  6048. + ipkg_message(conf, IPKG_ERROR, "or by setting option force_removal_of_dependent_packages\n");
  6049. + ipkg_message(conf, IPKG_ERROR, "in ipkg.conf.\n");
  6050. + return 0;
  6051. +}
  6052. +
  6053. +int ipkg_remove_pkg(ipkg_conf_t *conf, pkg_t *pkg,int message)
  6054. +{
  6055. +/* Actually, when "message == 1" I have been called from an upgrade, and not from a normal remove
  6056. + thus I wan't check for essential, as I'm upgrading.
  6057. + I hope it won't break anything :)
  6058. +*/
  6059. + int err;
  6060. + abstract_pkg_t *parent_pkg = NULL;
  6061. +
  6062. + if (pkg->essential && !message) {
  6063. + if (conf->force_removal_of_essential_packages) {
  6064. + fprintf(stderr, "WARNING: Removing essential package %s under your coercion.\n"
  6065. + "\tIf your system breaks, you get to keep both pieces\n",
  6066. + pkg->name);
  6067. + } else {
  6068. + fprintf(stderr, "ERROR: Refusing to remove essential package %s.\n"
  6069. + "\tRemoving an essential package may lead to an unusable system, but if\n"
  6070. + "\tyou enjoy that kind of pain, you can force ipkg to proceed against\n"
  6071. + "\tits will with the option: -force-removal-of-essential-packages\n",
  6072. + pkg->name);
  6073. + return IPKG_PKG_IS_ESSENTIAL;
  6074. + }
  6075. + }
  6076. +
  6077. + if ((parent_pkg = pkg->parent) == NULL)
  6078. + return 0;
  6079. +
  6080. + /* only attempt to remove dependent installed packages if
  6081. + * force_depends is not specified or the package is being
  6082. + * replaced.
  6083. + */
  6084. + if (!conf->force_depends
  6085. + && !(pkg->state_flag & SF_REPLACE)) {
  6086. + abstract_pkg_t **dependents;
  6087. + int has_installed_dependents =
  6088. + pkg_has_installed_dependents(pkg, &dependents);
  6089. +
  6090. + if (has_installed_dependents) {
  6091. + /*
  6092. + * if this package is depended up by others, then either we should
  6093. + * not remove it or we should remove it and all of its dependents
  6094. + */
  6095. +
  6096. + if (!conf->force_removal_of_dependent_packages
  6097. + && !user_prefers_removing_dependents(conf, pkg, dependents)) {
  6098. + return IPKG_PKG_HAS_DEPENDENTS;
  6099. + }
  6100. +
  6101. + /* remove packages depending on this package - Karthik */
  6102. + err = ipkg_remove_dependent_pkgs (conf, pkg, dependents);
  6103. + free(dependents);
  6104. + if (err) return err;
  6105. + }
  6106. + }
  6107. +
  6108. + if ( message==0 ){
  6109. + printf("Removing package %s from %s...\n", pkg->name, pkg->dest->name);
  6110. + fflush(stdout);
  6111. + }
  6112. + pkg->state_flag |= SF_FILELIST_CHANGED;
  6113. +
  6114. + pkg->state_want = SW_DEINSTALL;
  6115. + ipkg_state_changed++;
  6116. +
  6117. + pkg_run_script(conf, pkg, "prerm", "remove");
  6118. +
  6119. + /* DPKG_INCOMPATIBILITY: dpkg is slightly different here. It
  6120. + maintains an empty filelist rather than deleting it. That seems
  6121. + like a big pain, and I don't see that that should make a big
  6122. + difference, but for anyone who wants tighter compatibility,
  6123. + feel free to fix this. */
  6124. + remove_data_files_and_list(conf, pkg);
  6125. +
  6126. + pkg_run_script(conf, pkg, "postrm", "remove");
  6127. +
  6128. + remove_maintainer_scripts_except_postrm(conf, pkg);
  6129. +
  6130. + /* Aman Gupta - Since ipkg is made for handheld devices with limited
  6131. + * space, it doesn't make sense to leave extra configurations, files,
  6132. + * and maintainer scripts left around. So, we make remove like purge,
  6133. + * and take out all the crap :) */
  6134. +
  6135. + remove_postrm(conf, pkg);
  6136. + pkg->state_status = SS_NOT_INSTALLED;
  6137. +
  6138. + if (parent_pkg)
  6139. + parent_pkg->state_status = SS_NOT_INSTALLED;
  6140. +
  6141. + return 0;
  6142. +}
  6143. +
  6144. +int ipkg_purge_pkg(ipkg_conf_t *conf, pkg_t *pkg)
  6145. +{
  6146. + ipkg_remove_pkg(conf, pkg,0);
  6147. + return 0;
  6148. +}
  6149. +
  6150. +int remove_data_files_and_list(ipkg_conf_t *conf, pkg_t *pkg)
  6151. +{
  6152. + str_list_t installed_dirs;
  6153. + str_list_t *installed_files;
  6154. + str_list_elt_t *iter;
  6155. + char *file_name;
  6156. + conffile_t *conffile;
  6157. + int removed_a_dir;
  6158. + pkg_t *owner;
  6159. +
  6160. + str_list_init(&installed_dirs);
  6161. + installed_files = pkg_get_installed_files(pkg);
  6162. +
  6163. + for (iter = installed_files->head; iter; iter = iter->next) {
  6164. + file_name = iter->data;
  6165. +
  6166. + if (file_is_dir(file_name)) {
  6167. + str_list_append(&installed_dirs, strdup(file_name));
  6168. + continue;
  6169. + }
  6170. +
  6171. + conffile = pkg_get_conffile(pkg, file_name);
  6172. + if (conffile) {
  6173. + /* XXX: QUESTION: Is this right? I figure we only need to
  6174. + save the conffile if it has been modified. Is that what
  6175. + dpkg does? Or does dpkg preserve all conffiles? If so,
  6176. + this seems like a better thing to do to conserve
  6177. + space. */
  6178. + if (conffile_has_been_modified(conf, conffile)) {
  6179. + printf(" not deleting modified conffile %s\n", file_name);
  6180. + fflush(stdout);
  6181. + continue;
  6182. + }
  6183. + }
  6184. +
  6185. + ipkg_message(conf, IPKG_INFO, " deleting %s (noaction=%d)\n", file_name, conf->noaction);
  6186. + if (!conf->noaction)
  6187. + unlink(file_name);
  6188. + }
  6189. +
  6190. + if (!conf->noaction) {
  6191. + do {
  6192. + removed_a_dir = 0;
  6193. + for (iter = installed_dirs.head; iter; iter = iter->next) {
  6194. + file_name = iter->data;
  6195. +
  6196. + if (rmdir(file_name) == 0) {
  6197. + ipkg_message(conf, IPKG_INFO, " deleting %s\n", file_name);
  6198. + removed_a_dir = 1;
  6199. + str_list_remove(&installed_dirs, &iter);
  6200. + }
  6201. + }
  6202. + } while (removed_a_dir);
  6203. + }
  6204. +
  6205. + pkg_free_installed_files(pkg);
  6206. + /* We have to remove the file list now, so that
  6207. + find_pkg_owning_file does not always just report this package */
  6208. + pkg_remove_installed_files_list(conf, pkg);
  6209. +
  6210. + /* Don't print warning for dirs that are provided by other packages */
  6211. + for (iter = installed_dirs.head; iter; iter = iter->next) {
  6212. + file_name = iter->data;
  6213. +
  6214. + owner = file_hash_get_file_owner(conf, file_name);
  6215. + if (owner) {
  6216. + free(iter->data);
  6217. + iter->data = NULL;
  6218. + str_list_remove(&installed_dirs, &iter);
  6219. + }
  6220. + }
  6221. +
  6222. + /* cleanup */
  6223. + for (iter = installed_dirs.head; iter; iter = iter->next) {
  6224. + free(iter->data);
  6225. + iter->data = NULL;
  6226. + }
  6227. + str_list_deinit(&installed_dirs);
  6228. +
  6229. + return 0;
  6230. +}
  6231. +
  6232. +int remove_maintainer_scripts_except_postrm(ipkg_conf_t *conf, pkg_t *pkg)
  6233. +{
  6234. + int i, err;
  6235. + char *globpattern;
  6236. + glob_t globbuf;
  6237. +
  6238. + if (conf->noaction) return 0;
  6239. +
  6240. + sprintf_alloc(&globpattern, "%s/%s.*",
  6241. + pkg->dest->info_dir, pkg->name);
  6242. + err = glob(globpattern, 0, NULL, &globbuf);
  6243. + free(globpattern);
  6244. + if (err) {
  6245. + return 0;
  6246. + }
  6247. +
  6248. + for (i = 0; i < globbuf.gl_pathc; i++) {
  6249. + if (str_ends_with(globbuf.gl_pathv[i], ".postrm")) {
  6250. + continue;
  6251. + }
  6252. + ipkg_message(conf, IPKG_INFO, " deleting %s\n", globbuf.gl_pathv[i]);
  6253. + unlink(globbuf.gl_pathv[i]);
  6254. + }
  6255. + globfree(&globbuf);
  6256. +
  6257. + return 0;
  6258. +}
  6259. +
  6260. +int remove_postrm(ipkg_conf_t *conf, pkg_t *pkg)
  6261. +{
  6262. + char *postrm_file_name;
  6263. +
  6264. + if (conf->noaction) return 0;
  6265. +
  6266. + sprintf_alloc(&postrm_file_name, "%s/%s.postrm",
  6267. + pkg->dest->info_dir, pkg->name);
  6268. + unlink(postrm_file_name);
  6269. + free(postrm_file_name);
  6270. +
  6271. + return 0;
  6272. +}
  6273. diff -Nur busybox-1.19.4.orig/archival/libipkg/ipkg_remove.h busybox-1.19.4/archival/libipkg/ipkg_remove.h
  6274. --- busybox-1.19.4.orig/archival/libipkg/ipkg_remove.h 1970-01-01 01:00:00.000000000 +0100
  6275. +++ busybox-1.19.4/archival/libipkg/ipkg_remove.h 2012-03-17 00:58:08.193100680 +0100
  6276. @@ -0,0 +1,33 @@
  6277. +/* ipkg_remove.h - the itsy package management system
  6278. +
  6279. + Carl D. Worth
  6280. +
  6281. + Copyright (C) 2001 University of Southern California
  6282. +
  6283. + This program is free software; you can redistribute it and/or
  6284. + modify it under the terms of the GNU General Public License as
  6285. + published by the Free Software Foundation; either version 2, or (at
  6286. + your option) any later version.
  6287. +
  6288. + This program is distributed in the hope that it will be useful, but
  6289. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6290. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6291. + General Public License for more details.
  6292. +*/
  6293. +
  6294. +#ifndef IPKG_REMOVE_H
  6295. +#define IPKG_REMOVE_H
  6296. +
  6297. +#include "pkg.h"
  6298. +#include "ipkg_conf.h"
  6299. +
  6300. +int ipkg_remove_pkg(ipkg_conf_t *conf, pkg_t *pkg,int message);
  6301. +int ipkg_purge_pkg(ipkg_conf_t *conf, pkg_t *pkg);
  6302. +int possible_broken_removal_of_packages (ipkg_conf_t *conf, pkg_t *pkg);
  6303. +int pkg_has_installed_dependents(pkg_t *pkg, abstract_pkg_t *** pdependents);
  6304. +int remove_data_files_and_list(ipkg_conf_t *conf, pkg_t *pkg);
  6305. +int remove_maintainer_scripts_except_postrm (ipkg_conf_t *conf, pkg_t *pkg);
  6306. +int remove_postrm (ipkg_conf_t *conf, pkg_t *pkg);
  6307. +
  6308. +
  6309. +#endif
  6310. diff -Nur busybox-1.19.4.orig/archival/libipkg/ipkg_upgrade.c busybox-1.19.4/archival/libipkg/ipkg_upgrade.c
  6311. --- busybox-1.19.4.orig/archival/libipkg/ipkg_upgrade.c 1970-01-01 01:00:00.000000000 +0100
  6312. +++ busybox-1.19.4/archival/libipkg/ipkg_upgrade.c 2012-03-17 00:58:08.193100680 +0100
  6313. @@ -0,0 +1,79 @@
  6314. +/* ipkg_upgrade.c - the itsy package management system
  6315. +
  6316. + Carl D. Worth
  6317. + Copyright (C) 2001 University of Southern California
  6318. +
  6319. + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
  6320. +
  6321. + This program is free software; you can redistribute it and/or
  6322. + modify it under the terms of the GNU General Public License as
  6323. + published by the Free Software Foundation; either version 2, or (at
  6324. + your option) any later version.
  6325. +
  6326. + This program is distributed in the hope that it will be useful, but
  6327. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6328. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6329. + General Public License for more details.
  6330. +*/
  6331. +
  6332. +#include "ipkg.h"
  6333. +#include "ipkg_install.h"
  6334. +#include "ipkg_message.h"
  6335. +
  6336. +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old);
  6337. +
  6338. +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old)
  6339. +{
  6340. + pkg_t *new;
  6341. + int cmp;
  6342. + char *old_version, *new_version;
  6343. +
  6344. + if (old->state_flag & SF_HOLD) {
  6345. + ipkg_message(conf, IPKG_NOTICE,
  6346. + "Not upgrading package %s which is marked "
  6347. + "hold (flags=%#x)\n", old->name, old->state_flag);
  6348. + return 0;
  6349. + }
  6350. +
  6351. + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, old->name);
  6352. + if (new == NULL) {
  6353. + old_version = pkg_version_str_alloc(old);
  6354. + ipkg_message(conf, IPKG_NOTICE,
  6355. + "Assuming locally installed package %s (%s) "
  6356. + "is up to date.\n", old->name, old_version);
  6357. + free(old_version);
  6358. + return 0;
  6359. + }
  6360. +
  6361. + old_version = pkg_version_str_alloc(old);
  6362. + new_version = pkg_version_str_alloc(new);
  6363. +
  6364. + cmp = pkg_compare_versions(old, new);
  6365. + ipkg_message(conf, IPKG_DEBUG,
  6366. + "comparing visible versions of pkg %s:"
  6367. + "\n\t%s is installed "
  6368. + "\n\t%s is available "
  6369. + "\n\t%d was comparison result\n",
  6370. + old->name, old_version, new_version, cmp);
  6371. + if (cmp == 0) {
  6372. + ipkg_message(conf, IPKG_INFO,
  6373. + "Package %s (%s) installed in %s is up to date.\n",
  6374. + old->name, old_version, old->dest->name);
  6375. + free(old_version);
  6376. + free(new_version);
  6377. + return 0;
  6378. + } else if (cmp > 0) {
  6379. + ipkg_message(conf, IPKG_NOTICE,
  6380. + "Not downgrading package %s on %s from %s to %s.\n",
  6381. + old->name, old->dest->name, old_version, new_version);
  6382. + free(old_version);
  6383. + free(new_version);
  6384. + return 0;
  6385. + } else if (cmp < 0) {
  6386. + new->dest = old->dest;
  6387. + old->state_want = SW_DEINSTALL;
  6388. + }
  6389. +
  6390. + new->state_flag |= SF_USER;
  6391. + return ipkg_install_pkg(conf, new,1);
  6392. +}
  6393. diff -Nur busybox-1.19.4.orig/archival/libipkg/ipkg_upgrade.h busybox-1.19.4/archival/libipkg/ipkg_upgrade.h
  6394. --- busybox-1.19.4.orig/archival/libipkg/ipkg_upgrade.h 1970-01-01 01:00:00.000000000 +0100
  6395. +++ busybox-1.19.4/archival/libipkg/ipkg_upgrade.h 2012-03-17 00:58:08.193100680 +0100
  6396. @@ -0,0 +1,18 @@
  6397. +/* ipkg_upgrade.c - the itsy package management system
  6398. +
  6399. + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
  6400. +
  6401. + This program is free software; you can redistribute it and/or
  6402. + modify it under the terms of the GNU General Public License as
  6403. + published by the Free Software Foundation; either version 2, or (at
  6404. + your option) any later version.
  6405. +
  6406. + This program is distributed in the hope that it will be useful, but
  6407. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6408. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6409. + General Public License for more details.
  6410. +*/
  6411. +
  6412. +#include "ipkg.h"
  6413. +
  6414. +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old);
  6415. diff -Nur busybox-1.19.4.orig/archival/libipkg/ipkg_utils.c busybox-1.19.4/archival/libipkg/ipkg_utils.c
  6416. --- busybox-1.19.4.orig/archival/libipkg/ipkg_utils.c 1970-01-01 01:00:00.000000000 +0100
  6417. +++ busybox-1.19.4/archival/libipkg/ipkg_utils.c 2012-03-17 00:58:08.193100680 +0100
  6418. @@ -0,0 +1,185 @@
  6419. +/* ipkg_utils.c - the itsy package management system
  6420. +
  6421. + Steven M. Ayer
  6422. +
  6423. + Copyright (C) 2002 Compaq Computer Corporation
  6424. +
  6425. + This program is free software; you can redistribute it and/or
  6426. + modify it under the terms of the GNU General Public License as
  6427. + published by the Free Software Foundation; either version 2, or (at
  6428. + your option) any later version.
  6429. +
  6430. + This program is distributed in the hope that it will be useful, but
  6431. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6432. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6433. + General Public License for more details.
  6434. +*/
  6435. +
  6436. +#include "ipkg.h"
  6437. +#include <errno.h>
  6438. +#include <ctype.h>
  6439. +#include <sys/vfs.h>
  6440. +
  6441. +#include "ipkg_utils.h"
  6442. +#include "pkg.h"
  6443. +#include "pkg_hash.h"
  6444. +
  6445. +void push_error_list(struct errlist ** errors, char * msg);
  6446. +void reverse_error_list(struct errlist **errors);
  6447. +void free_error_list(struct errlist **errors);
  6448. +
  6449. +struct errlist* error_list;
  6450. +
  6451. +int get_available_blocks(char * filesystem)
  6452. +{
  6453. + struct statfs sfs;
  6454. +
  6455. + if(statfs(filesystem, &sfs)){
  6456. + fprintf(stderr, "bad statfs\n");
  6457. + return 0;
  6458. + }
  6459. + /* fprintf(stderr, "reported fs type %x\n", sfs.f_type); */
  6460. + return ((sfs.f_bavail * sfs.f_bsize) / 1024);
  6461. +}
  6462. +
  6463. +char **read_raw_pkgs_from_file(const char *file_name)
  6464. +{
  6465. + FILE *fp;
  6466. + char **ret;
  6467. +
  6468. + if(!(fp = fopen(file_name, "r"))){
  6469. + fprintf(stderr, "can't get %s open for read\n", file_name);
  6470. + return NULL;
  6471. + }
  6472. +
  6473. + ret = read_raw_pkgs_from_stream(fp);
  6474. +
  6475. + fclose(fp);
  6476. +
  6477. + return ret;
  6478. +}
  6479. +
  6480. +char **read_raw_pkgs_from_stream(FILE *fp)
  6481. +{
  6482. + char **raw = NULL, *buf, *scout;
  6483. + int count = 0;
  6484. + size_t size = 512;
  6485. +
  6486. + buf = malloc (size);
  6487. +
  6488. + while (fgets(buf, size, fp)) {
  6489. + while (strlen (buf) == (size - 1)
  6490. + && buf[size-2] != '\n') {
  6491. + size_t o = size - 1;
  6492. + size *= 2;
  6493. + buf = realloc (buf, size);
  6494. + if (fgets (buf + o, size - o, fp) == NULL)
  6495. + break;
  6496. + }
  6497. +
  6498. + if(!(count % 50))
  6499. + raw = realloc(raw, (count + 50) * sizeof(char *));
  6500. +
  6501. + if((scout = strchr(buf, '\n')))
  6502. + *scout = '\0';
  6503. +
  6504. + raw[count++] = strdup(buf);
  6505. + }
  6506. +
  6507. + raw = realloc(raw, (count + 1) * sizeof(char *));
  6508. + raw[count] = NULL;
  6509. +
  6510. + free (buf);
  6511. +
  6512. + return raw;
  6513. +}
  6514. +
  6515. +/* something to remove whitespace, a hash pooper */
  6516. +char *trim_alloc(char *line)
  6517. +{
  6518. + char *new;
  6519. + char *dest, *src, *end;
  6520. +
  6521. + new = malloc(strlen(line) + 1);
  6522. + if ( new == NULL ){
  6523. + fprintf(stderr,"%s: Unable to allocate memory\n",__FUNCTION__);
  6524. + return NULL;
  6525. + }
  6526. + dest = new, src = line, end = line + (strlen(line) - 1);
  6527. +
  6528. + /* remove it from the front */
  6529. + while(src &&
  6530. + isspace(*src) &&
  6531. + *src)
  6532. + src++;
  6533. + /* and now from the back */
  6534. + while((end > src) &&
  6535. + isspace(*end))
  6536. + end--;
  6537. + end++;
  6538. + *end = '\0';
  6539. + strcpy(new, src);
  6540. + /* this does from the first space
  6541. + * blasting away any versions stuff in depends
  6542. + while(src &&
  6543. + !isspace(*src) &&
  6544. + *src)
  6545. + *dest++ = *src++;
  6546. + *dest = '\0';
  6547. + */
  6548. +
  6549. + return new;
  6550. +}
  6551. +
  6552. +int line_is_blank(const char *line)
  6553. +{
  6554. + const char *s;
  6555. +
  6556. + for (s = line; *s; s++) {
  6557. + if (!isspace(*s))
  6558. + return 0;
  6559. + }
  6560. + return 1;
  6561. +}
  6562. +
  6563. +void push_error_list(struct errlist ** errors, char * msg){
  6564. + struct errlist *err_lst_tmp;
  6565. +
  6566. +
  6567. + err_lst_tmp = malloc ( sizeof (err_lst_tmp) );
  6568. + err_lst_tmp->errmsg=strdup(msg) ;
  6569. + err_lst_tmp->next = *errors;
  6570. + *errors = err_lst_tmp;
  6571. +}
  6572. +
  6573. +
  6574. +void reverse_error_list(struct errlist **errors){
  6575. + struct errlist *result=NULL;
  6576. + struct errlist *current= *errors;
  6577. + struct errlist *next;
  6578. +
  6579. + while ( current != NULL ) {
  6580. + next = current->next;
  6581. + current->next=result;
  6582. + result=current;
  6583. + current=next;
  6584. + }
  6585. + *errors=result;
  6586. +
  6587. +}
  6588. +
  6589. +
  6590. +void free_error_list(struct errlist **errors){
  6591. + struct errlist *current = *errors;
  6592. +
  6593. + while (current != NULL) {
  6594. + free(current->errmsg);
  6595. + current = (*errors)->next;
  6596. + free(*errors);
  6597. + *errors = current;
  6598. + }
  6599. +
  6600. +
  6601. +}
  6602. +
  6603. +
  6604. diff -Nur busybox-1.19.4.orig/archival/libipkg/ipkg_utils.h busybox-1.19.4/archival/libipkg/ipkg_utils.h
  6605. --- busybox-1.19.4.orig/archival/libipkg/ipkg_utils.h 1970-01-01 01:00:00.000000000 +0100
  6606. +++ busybox-1.19.4/archival/libipkg/ipkg_utils.h 2012-03-17 00:58:08.193100680 +0100
  6607. @@ -0,0 +1,29 @@
  6608. +/* ipkg_utils.h - the itsy package management system
  6609. +
  6610. + Steven M. Ayer
  6611. +
  6612. + Copyright (C) 2002 Compaq Computer Corporation
  6613. +
  6614. + This program is free software; you can redistribute it and/or
  6615. + modify it under the terms of the GNU General Public License as
  6616. + published by the Free Software Foundation; either version 2, or (at
  6617. + your option) any later version.
  6618. +
  6619. + This program is distributed in the hope that it will be useful, but
  6620. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6621. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6622. + General Public License for more details.
  6623. +*/
  6624. +
  6625. +#ifndef IPKG_UTILS_H
  6626. +#define IPKG_UTILS_H
  6627. +
  6628. +#include "pkg.h"
  6629. +
  6630. +int get_available_blocks(char * filesystem);
  6631. +char **read_raw_pkgs_from_file(const char *file_name);
  6632. +char **read_raw_pkgs_from_stream(FILE *fp);
  6633. +char *trim_alloc(char * line);
  6634. +int line_is_blank(const char *line);
  6635. +
  6636. +#endif
  6637. diff -Nur busybox-1.19.4.orig/archival/libipkg/libipkg.c busybox-1.19.4/archival/libipkg/libipkg.c
  6638. --- busybox-1.19.4.orig/archival/libipkg/libipkg.c 1970-01-01 01:00:00.000000000 +0100
  6639. +++ busybox-1.19.4/archival/libipkg/libipkg.c 2012-03-17 00:58:08.193100680 +0100
  6640. @@ -0,0 +1,583 @@
  6641. +/* ipkglib.c - the itsy package management system
  6642. +
  6643. + Florina Boor
  6644. +
  6645. + Copyright (C) 2003 kernel concepts
  6646. +
  6647. + This program is free software; you can redistribute it and/or
  6648. + modify it under the terms of the GNU General Public License as
  6649. + published by the Free Software Foundation; either version 2, or (at
  6650. + your option) any later version.
  6651. +
  6652. + This program is distributed in the hope that it will be useful, but
  6653. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6654. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6655. + General Public License for more details.
  6656. +*/
  6657. +
  6658. +#include "ipkg.h"
  6659. +#include "ipkg_includes.h"
  6660. +#include "libipkg.h"
  6661. +
  6662. +#include "args.h"
  6663. +#include "ipkg_conf.h"
  6664. +#include "ipkg_cmd.h"
  6665. +#include "file_util.h"
  6666. +
  6667. +int ipkg_file_what(args_t *args, const char *file, const char* command);
  6668. +int default_ipkg_message_callback(ipkg_conf_t *conf, message_level_t level,
  6669. + char *msg);
  6670. +int default_ipkg_list_callback(char *name, char *desc, char *version);
  6671. +int default_ipkg_files_callback(char *desc);
  6672. +int default_ipkg_status_callback(char *desc);
  6673. +char* default_ipkg_response_callback(char *question);
  6674. +
  6675. +
  6676. +ipkg_message_callback ipkg_cb_message = NULL;
  6677. +ipkg_response_callback ipkg_cb_response = NULL;
  6678. +ipkg_status_callback ipkg_cb_status = NULL;
  6679. +ipkg_list_callback ipkg_cb_list = NULL;
  6680. +
  6681. +
  6682. +int
  6683. +ipkg_init (ipkg_message_callback mcall,
  6684. + ipkg_response_callback rcall,
  6685. + args_t * args)
  6686. +{
  6687. + ipkg_cb_message = mcall;
  6688. + ipkg_cb_response = rcall;
  6689. +
  6690. + args_init (args);
  6691. +
  6692. + return 0;
  6693. +}
  6694. +
  6695. +
  6696. +int
  6697. +ipkg_deinit (args_t * args)
  6698. +{
  6699. + args_deinit (args);
  6700. + ipkg_cb_message = NULL;
  6701. + ipkg_cb_response = NULL;
  6702. +
  6703. + /* place other cleanup stuff here */
  6704. +
  6705. + return 0;
  6706. +}
  6707. +
  6708. +
  6709. +int
  6710. +ipkg_packages_list(args_t *args,
  6711. + const char *packages,
  6712. + ipkg_list_callback cblist,
  6713. + void *userdata)
  6714. +{
  6715. + ipkg_cmd_t *cmd;
  6716. + ipkg_conf_t ipkg_conf;
  6717. + int err;
  6718. +
  6719. + err = ipkg_conf_init (&ipkg_conf, args);
  6720. + if (err)
  6721. + {
  6722. + return err;
  6723. + }
  6724. +
  6725. + ipkg_cb_list = cblist;
  6726. + /* we need to do this because of static declarations,
  6727. + * maybe a good idea to change */
  6728. + cmd = ipkg_cmd_find ("list");
  6729. + if (packages)
  6730. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
  6731. + else
  6732. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
  6733. + ipkg_cb_list = NULL;
  6734. + ipkg_conf_deinit (&ipkg_conf);
  6735. + return (err);
  6736. +}
  6737. +
  6738. +
  6739. +int
  6740. +ipkg_packages_status(args_t *args,
  6741. + const char *packages,
  6742. + ipkg_status_callback cbstatus,
  6743. + void *userdata)
  6744. +{
  6745. + ipkg_cmd_t *cmd;
  6746. + ipkg_conf_t ipkg_conf;
  6747. + int err;
  6748. +
  6749. + err = ipkg_conf_init (&ipkg_conf, args);
  6750. + if (err)
  6751. + {
  6752. + return err;
  6753. + }
  6754. +
  6755. + ipkg_cb_status = cbstatus;
  6756. +
  6757. + /* we need to do this because of static declarations,
  6758. + * maybe a good idea to change */
  6759. + cmd = ipkg_cmd_find ("status");
  6760. + if (packages)
  6761. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
  6762. + else
  6763. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
  6764. +
  6765. + ipkg_cb_status = NULL;
  6766. + ipkg_conf_deinit (&ipkg_conf);
  6767. + return (err);
  6768. +}
  6769. +
  6770. +
  6771. +int
  6772. +ipkg_packages_info(args_t *args,
  6773. + const char *packages,
  6774. + ipkg_status_callback cbstatus,
  6775. + void *userdata)
  6776. +{
  6777. + ipkg_cmd_t *cmd;
  6778. + ipkg_conf_t ipkg_conf;
  6779. + int err;
  6780. +
  6781. + err = ipkg_conf_init (&ipkg_conf, args);
  6782. + if (err)
  6783. + {
  6784. + return err;
  6785. + }
  6786. +
  6787. + ipkg_cb_status = cbstatus;
  6788. +
  6789. + /* we need to do this because of static declarations,
  6790. + * maybe a good idea to change */
  6791. + cmd = ipkg_cmd_find ("info");
  6792. + if (packages)
  6793. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
  6794. + else
  6795. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
  6796. +
  6797. + ipkg_cb_status = NULL;
  6798. + ipkg_conf_deinit (&ipkg_conf);
  6799. + return (err);
  6800. +}
  6801. +
  6802. +
  6803. +int
  6804. +ipkg_packages_install (args_t * args, const char *name)
  6805. +{
  6806. + ipkg_cmd_t *cmd;
  6807. + ipkg_conf_t ipkg_conf;
  6808. + int err;
  6809. +
  6810. + /* this error should be handled in application */
  6811. + if (!name || !strlen (name))
  6812. + return (-1);
  6813. +
  6814. + err = ipkg_conf_init (&ipkg_conf, args);
  6815. + if (err)
  6816. + {
  6817. + return err;
  6818. + }
  6819. +
  6820. + /* we need to do this because of static declarations,
  6821. + * maybe a good idea to change */
  6822. + cmd = ipkg_cmd_find ("install");
  6823. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
  6824. +
  6825. + ipkg_conf_deinit(&ipkg_conf);
  6826. + return (err);
  6827. +}
  6828. +
  6829. +
  6830. +int
  6831. +ipkg_packages_remove(args_t *args, const char *name, int purge)
  6832. +{
  6833. + ipkg_cmd_t *cmd;
  6834. + ipkg_conf_t ipkg_conf;
  6835. + int err;
  6836. +
  6837. + /* this error should be handled in application */
  6838. + if (!name || !strlen (name))
  6839. + return (-1);
  6840. +
  6841. + err = ipkg_conf_init (&ipkg_conf, args);
  6842. + if (err)
  6843. + {
  6844. + return err;
  6845. + }
  6846. +
  6847. + /* we need to do this because of static declarations,
  6848. + * maybe a good idea to change */
  6849. + if (purge)
  6850. + cmd = ipkg_cmd_find ("purge");
  6851. + else
  6852. + cmd = ipkg_cmd_find ("remove");
  6853. +
  6854. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
  6855. +
  6856. + ipkg_conf_deinit(&ipkg_conf);
  6857. + return (err);
  6858. +}
  6859. +
  6860. +
  6861. +int
  6862. +ipkg_lists_update(args_t *args)
  6863. +{
  6864. + ipkg_cmd_t *cmd;
  6865. + ipkg_conf_t ipkg_conf;
  6866. + int err;
  6867. +
  6868. + err = ipkg_conf_init (&ipkg_conf, args);
  6869. + if (err)
  6870. + {
  6871. + return err;
  6872. + }
  6873. +
  6874. + /* we need to do this because of static declarations,
  6875. + * maybe a good idea to change */
  6876. + cmd = ipkg_cmd_find ("update");
  6877. +
  6878. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, NULL);
  6879. +
  6880. + ipkg_conf_deinit(&ipkg_conf);
  6881. + return (err);
  6882. +}
  6883. +
  6884. +
  6885. +int
  6886. +ipkg_packages_upgrade(args_t *args)
  6887. +{
  6888. + ipkg_cmd_t *cmd;
  6889. + ipkg_conf_t ipkg_conf;
  6890. + int err;
  6891. +
  6892. + err = ipkg_conf_init (&ipkg_conf, args);
  6893. + if (err)
  6894. + {
  6895. + return err;
  6896. + }
  6897. +
  6898. + /* we need to do this because of static declarations,
  6899. + * maybe a good idea to change */
  6900. + cmd = ipkg_cmd_find ("upgrade");
  6901. +
  6902. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, NULL);
  6903. +
  6904. + ipkg_conf_deinit(&ipkg_conf);
  6905. + return (err);
  6906. +}
  6907. +
  6908. +
  6909. +int
  6910. +ipkg_packages_download (args_t * args, const char *name)
  6911. +{
  6912. + ipkg_cmd_t *cmd;
  6913. + ipkg_conf_t ipkg_conf;
  6914. + int err;
  6915. +
  6916. + /* this error should be handled in application */
  6917. + if (!name || !strlen (name))
  6918. + return (-1);
  6919. +
  6920. + err = ipkg_conf_init (&ipkg_conf, args);
  6921. + if (err)
  6922. + {
  6923. + return err;
  6924. + }
  6925. +
  6926. + /* we need to do this because of static declarations,
  6927. + * maybe a good idea to change */
  6928. + cmd = ipkg_cmd_find ("download");
  6929. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
  6930. +
  6931. + ipkg_conf_deinit(&ipkg_conf);
  6932. + return (err);
  6933. +}
  6934. +
  6935. +
  6936. +int
  6937. +ipkg_package_files(args_t *args,
  6938. + const char *name,
  6939. + ipkg_list_callback cblist,
  6940. + void *userdata)
  6941. +{
  6942. + ipkg_cmd_t *cmd;
  6943. + ipkg_conf_t ipkg_conf;
  6944. + int err;
  6945. +
  6946. + /* this error should be handled in application */
  6947. + if (!name || !strlen (name))
  6948. + return (-1);
  6949. +
  6950. + err = ipkg_conf_init (&ipkg_conf, args);
  6951. + if (err)
  6952. + {
  6953. + return err;
  6954. + }
  6955. +
  6956. + ipkg_cb_list = cblist;
  6957. +
  6958. + /* we need to do this because of static declarations,
  6959. + * maybe a good idea to change */
  6960. + cmd = ipkg_cmd_find ("files");
  6961. +
  6962. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, userdata);
  6963. +
  6964. + ipkg_cb_list = NULL;
  6965. + ipkg_conf_deinit(&ipkg_conf);
  6966. + return (err);
  6967. +}
  6968. +
  6969. +
  6970. +int
  6971. +ipkg_file_search(args_t *args,
  6972. + const char *file,
  6973. + ipkg_list_callback cblist,
  6974. + void *userdata)
  6975. +{
  6976. + ipkg_cmd_t *cmd;
  6977. + ipkg_conf_t ipkg_conf;
  6978. + int err;
  6979. +
  6980. + /* this error should be handled in application */
  6981. + if (!file || !strlen (file))
  6982. + return (-1);
  6983. +
  6984. + err = ipkg_conf_init (&ipkg_conf, args);
  6985. + if (err)
  6986. + {
  6987. + return err;
  6988. + }
  6989. +
  6990. + ipkg_cb_list = cblist;
  6991. +
  6992. + /* we need to do this because of static declarations,
  6993. + * maybe a good idea to change */
  6994. + cmd = ipkg_cmd_find ("search");
  6995. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &file, userdata);
  6996. +
  6997. + ipkg_cb_list = NULL;
  6998. + ipkg_conf_deinit(&ipkg_conf);
  6999. + return(err);
  7000. +}
  7001. +
  7002. +
  7003. +int
  7004. +ipkg_file_what(args_t *args, const char *file, const char* command)
  7005. +{
  7006. + ipkg_cmd_t *cmd;
  7007. + ipkg_conf_t ipkg_conf;
  7008. + int err;
  7009. +
  7010. + /* this error should be handled in application */
  7011. + if (!file || !strlen (file))
  7012. + return (-1);
  7013. +
  7014. + err = ipkg_conf_init (&ipkg_conf, args);
  7015. + if (err)
  7016. + {
  7017. + return err;
  7018. + }
  7019. +
  7020. + /* we need to do this because of static declarations,
  7021. + * maybe a good idea to change */
  7022. + cmd = ipkg_cmd_find (command);
  7023. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &file, NULL);
  7024. +
  7025. + ipkg_conf_deinit(&ipkg_conf);
  7026. + return(err);
  7027. +}
  7028. +
  7029. +#define ipkg_package_whatdepends(args,file) ipkg_file_what(args,file,"whatdepends")
  7030. +#define ipkg_package_whatrecommends(args, file) ipkg_file_what(args,file,"whatrecommends")
  7031. +#define ipkg_package_whatprovides(args, file) ipkg_file_what(args,file,"whatprovides")
  7032. +#define ipkg_package_whatconflicts(args, file) ipkg_file_what(args,file,"whatconflicts")
  7033. +#define ipkg_package_whatreplaces(args, file) ipkg_file_what(args,file,"whatreplaces")
  7034. +
  7035. +
  7036. +int default_ipkg_message_callback(ipkg_conf_t *conf, message_level_t level,
  7037. + char *msg)
  7038. +{
  7039. + if (conf && (conf->verbosity < level)) {
  7040. + return 0;
  7041. + } else {
  7042. + if ( level == IPKG_ERROR )
  7043. + push_error_list(&error_list, msg);
  7044. + else
  7045. + printf(msg);
  7046. + }
  7047. + return 0;
  7048. +}
  7049. +
  7050. +int default_ipkg_list_callback(char *name, char *desc, char *version)
  7051. +{
  7052. + if (desc)
  7053. + printf("%s - %s - %s\n", name, version, desc);
  7054. + else
  7055. + printf("%s - %s\n", name, version);
  7056. + return 0;
  7057. +}
  7058. +
  7059. +int default_ipkg_files_callback(char *desc)
  7060. +{
  7061. + if (desc)
  7062. + printf("%s\n", desc);
  7063. + return 0;
  7064. +}
  7065. +
  7066. +int default_ipkg_status_callback(char *desc)
  7067. +{
  7068. + printf("%s\n", desc);
  7069. + return 0;
  7070. +}
  7071. +
  7072. +char* default_ipkg_response_callback(char *question)
  7073. +{
  7074. + char *response = NULL;
  7075. + printf(question);
  7076. + fflush(stdout);
  7077. + do {
  7078. + response = (char *)file_read_line_alloc(stdin);
  7079. + } while (response == NULL);
  7080. + return response;
  7081. +}
  7082. +
  7083. +/* This is used for backward compatibility */
  7084. +int
  7085. +ipkg_op (int argc, char *argv[])
  7086. +{
  7087. + int err, optind_;
  7088. + args_t args;
  7089. + char *cmd_name;
  7090. + ipkg_cmd_t *cmd;
  7091. + ipkg_conf_t ipkg_conf;
  7092. + const char *message = "ipkg must have one sub-command argument";
  7093. + FILE *f;
  7094. + struct mntent *mnt;
  7095. + int remountroot;
  7096. +
  7097. + args_init (&args);
  7098. +
  7099. + optind_ = args_parse (&args, argc, argv);
  7100. + if (optind_ == argc || optind_ < 0)
  7101. + {
  7102. + args_usage(message);
  7103. + }
  7104. +
  7105. + cmd_name = argv[optind_++];
  7106. +/* Pigi: added a flag to disable the checking of structures if the command does not need to
  7107. + read anything from there.
  7108. +*/
  7109. + if ( !strcmp(cmd_name,"print-architecture") ||
  7110. + !strcmp(cmd_name,"print_architecture") ||
  7111. + !strcmp(cmd_name,"print-installation-architecture") ||
  7112. + !strcmp(cmd_name,"print_installation_architecture") )
  7113. + args.nocheckfordirorfile = 1;
  7114. +
  7115. +/* Pigi: added a flag to disable the reading of feed files if the command does not need to
  7116. + read anything from there.
  7117. +*/
  7118. + if ( !strcmp(cmd_name,"flag") ||
  7119. + !strcmp(cmd_name,"configure") ||
  7120. + !strcmp(cmd_name,"remove") ||
  7121. + !strcmp(cmd_name,"files") ||
  7122. + !strcmp(cmd_name,"search") ||
  7123. + !strcmp(cmd_name,"compare_versions") ||
  7124. + !strcmp(cmd_name,"compare-versions") ||
  7125. + !strcmp(cmd_name,"list_installed") ||
  7126. + !strcmp(cmd_name,"list-installed") ||
  7127. + !strcmp(cmd_name,"status") )
  7128. + args.noreadfeedsfile = 1;
  7129. +
  7130. +
  7131. +
  7132. +
  7133. + err = ipkg_conf_init (&ipkg_conf, &args);
  7134. + if (err)
  7135. + {
  7136. + return err;
  7137. + }
  7138. +
  7139. + args_deinit (&args);
  7140. +
  7141. + ipkg_cb_message = default_ipkg_message_callback;
  7142. + ipkg_cb_response = default_ipkg_response_callback;
  7143. + ipkg_cb_status = (ipkg_status_callback)default_ipkg_status_callback;
  7144. + if ( strcmp(cmd_name, "files")==0)
  7145. + ipkg_cb_list = (ipkg_list_callback)default_ipkg_files_callback;
  7146. + else
  7147. + ipkg_cb_list = (ipkg_list_callback)default_ipkg_list_callback;
  7148. +
  7149. + cmd = ipkg_cmd_find (cmd_name);
  7150. + if (cmd == NULL)
  7151. + {
  7152. + fprintf (stderr, "%s: unknown sub-command %s\n", argv[0],
  7153. + cmd_name);
  7154. + args_usage (NULL);
  7155. + }
  7156. +
  7157. + if (cmd->requires_args && optind_ == argc)
  7158. + {
  7159. + fprintf (stderr,
  7160. + "%s: the ``%s'' command requires at least one argument\n",
  7161. + __FUNCTION__, cmd_name);
  7162. + args_usage (NULL);
  7163. + }
  7164. +
  7165. + remountroot = 0;
  7166. + /* check if /dev/root is mounted read-only */
  7167. + if ((f = setmntent("/proc/mounts", "r")) == NULL)
  7168. + fprintf (stderr, "Checking /proc/mounts failed\n");
  7169. +
  7170. + while ((mnt = getmntent(f)) != NULL) {
  7171. + if (strcmp(mnt->mnt_fsname, "/dev/root") == 0 &&
  7172. + hasmntopt(mnt, MNTOPT_RO) != NULL) {
  7173. + remountroot = 1;
  7174. + }
  7175. + }
  7176. +
  7177. + endmntent(f);
  7178. +
  7179. + if (remountroot) {
  7180. + if ( !strcmp(cmd_name,"install") ||
  7181. + !strcmp(cmd_name,"update") ||
  7182. + !strcmp(cmd_name,"upgrade") ||
  7183. + !strcmp(cmd_name,"flag") ||
  7184. + !strcmp(cmd_name,"configure") ||
  7185. + !strcmp(cmd_name,"remove") ) {
  7186. + /* mount rootfs read-write */
  7187. + if (mount("","/",0,MS_REMOUNT,0)<0)
  7188. + fprintf (stderr, "Mounting rootfs read-write failed\n");
  7189. + }
  7190. + }
  7191. +
  7192. + err = ipkg_cmd_exec (cmd, &ipkg_conf, argc - optind_, (const char **) (argv + optind_), NULL);
  7193. +
  7194. + ipkg_conf_deinit (&ipkg_conf);
  7195. +
  7196. + if (remountroot) {
  7197. + if ( !strcmp(cmd_name,"install") ||
  7198. + !strcmp(cmd_name,"update") ||
  7199. + !strcmp(cmd_name,"upgrade") ||
  7200. + !strcmp(cmd_name,"flag") ||
  7201. + !strcmp(cmd_name,"configure") ||
  7202. + !strcmp(cmd_name,"remove") ) {
  7203. + sync();
  7204. + /* mount rootfs read-only */
  7205. + if (mount("","/",0,MS_REMOUNT|MS_RDONLY,0)<0)
  7206. + fprintf (stderr, "Mounting rootfs read-only failed\n");
  7207. + }
  7208. + }
  7209. +
  7210. + /* check if cfgfs exists */
  7211. + if (access("/sbin/cfgfs", X_OK) == 0) {
  7212. + if ( !strcmp(cmd_name,"install") ||
  7213. + !strcmp(cmd_name,"update") ||
  7214. + !strcmp(cmd_name,"upgrade")) {
  7215. + if (system("cfgfs status -q") != 0) {
  7216. + fprintf (stdout, "Updates in /etc, please review changes\n");
  7217. + fprintf (stdout, "You can check via cfgfs status\n");
  7218. + }
  7219. + }
  7220. + }
  7221. +
  7222. + return err;
  7223. +}
  7224. diff -Nur busybox-1.19.4.orig/archival/libipkg/libipkg.h busybox-1.19.4/archival/libipkg/libipkg.h
  7225. --- busybox-1.19.4.orig/archival/libipkg/libipkg.h 1970-01-01 01:00:00.000000000 +0100
  7226. +++ busybox-1.19.4/archival/libipkg/libipkg.h 2012-03-17 00:58:08.193100680 +0100
  7227. @@ -0,0 +1,78 @@
  7228. +/* ipkglib.h - the itsy package management system
  7229. +
  7230. + Florian Boor <florian.boor@kernelconcepts.de>
  7231. +
  7232. + This program is free software; you can redistribute it and/or
  7233. + modify it under the terms of the GNU General Public License as
  7234. + published by the Free Software Foundation; either version 2, or (at
  7235. + your option) any later version.
  7236. +
  7237. + This program is distributed in the hope that it will be useful, but
  7238. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7239. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7240. + General Public License for more details.
  7241. +*/
  7242. +
  7243. +#ifndef IPKGLIB_H
  7244. +#define IPKGLIB_H
  7245. +
  7246. +#include "ipkg_conf.h"
  7247. +#include "ipkg_message.h"
  7248. +
  7249. +#include "args.h"
  7250. +#include "pkg.h"
  7251. +
  7252. +typedef int (*ipkg_message_callback)(ipkg_conf_t *conf, message_level_t level,
  7253. + char *msg);
  7254. +typedef int (*ipkg_list_callback)(char *name, char *desc, char *version,
  7255. + pkg_state_status_t status, void *userdata);
  7256. +typedef int (*ipkg_status_callback)(char *name, int istatus, char *desc,
  7257. + void *userdata);
  7258. +typedef char* (*ipkg_response_callback)(char *question);
  7259. +
  7260. +extern int ipkg_op(int argc, char *argv[]); /* ipkglib.c */
  7261. +extern int ipkg_init (ipkg_message_callback mcall,
  7262. + ipkg_response_callback rcall,
  7263. + args_t * args);
  7264. +
  7265. +extern int ipkg_deinit (args_t *args);
  7266. +extern int ipkg_packages_list(args_t *args,
  7267. + const char *packages,
  7268. + ipkg_list_callback cblist,
  7269. + void *userdata);
  7270. +extern int ipkg_packages_status(args_t *args,
  7271. + const char *packages,
  7272. + ipkg_status_callback cbstatus,
  7273. + void *userdata);
  7274. +extern int ipkg_packages_info(args_t *args,
  7275. + const char *packages,
  7276. + ipkg_status_callback cbstatus,
  7277. + void *userdata);
  7278. +extern int ipkg_packages_install(args_t *args, const char *name);
  7279. +extern int ipkg_packages_remove(args_t *args, const char *name, int purge);
  7280. +extern int ipkg_lists_update(args_t *args);
  7281. +extern int ipkg_packages_upgrade(args_t *args);
  7282. +extern int ipkg_packages_download(args_t *args, const char *name);
  7283. +extern int ipkg_package_files(args_t *args,
  7284. + const char *name,
  7285. + ipkg_list_callback cblist,
  7286. + void *userdata);
  7287. +extern int ipkg_file_search(args_t *args,
  7288. + const char *file,
  7289. + ipkg_list_callback cblist,
  7290. + void *userdata);
  7291. +extern int ipkg_package_whatdepends(args_t *args, const char *file);
  7292. +extern int ipkg_package_whatrecommends(args_t *args, const char *file);
  7293. +extern int ipkg_package_whatprovides(args_t *args, const char *file);
  7294. +extern int ipkg_package_whatconflicts(args_t *args, const char *file);
  7295. +extern int ipkg_package_whatreplaces(args_t *args, const char *file);
  7296. +
  7297. +extern ipkg_message_callback ipkg_cb_message; /* ipkglib.c */
  7298. +extern ipkg_response_callback ipkg_cb_response;
  7299. +extern ipkg_status_callback ipkg_cb_status;
  7300. +extern ipkg_list_callback ipkg_cb_list;
  7301. +extern void push_error_list(struct errlist **errors,char * msg);
  7302. +extern void reverse_error_list(struct errlist **errors);
  7303. +extern void free_error_list(struct errlist **errors);
  7304. +
  7305. +#endif
  7306. diff -Nur busybox-1.19.4.orig/archival/libipkg/nv_pair.c busybox-1.19.4/archival/libipkg/nv_pair.c
  7307. --- busybox-1.19.4.orig/archival/libipkg/nv_pair.c 1970-01-01 01:00:00.000000000 +0100
  7308. +++ busybox-1.19.4/archival/libipkg/nv_pair.c 2012-03-17 00:58:08.193100680 +0100
  7309. @@ -0,0 +1,40 @@
  7310. +/* nv_pair.c - the itsy package management system
  7311. +
  7312. + Carl D. Worth
  7313. +
  7314. + Copyright (C) 2001 University of Southern California
  7315. +
  7316. + This program is free software; you can redistribute it and/or
  7317. + modify it under the terms of the GNU General Public License as
  7318. + published by the Free Software Foundation; either version 2, or (at
  7319. + your option) any later version.
  7320. +
  7321. + This program is distributed in the hope that it will be useful, but
  7322. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7323. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7324. + General Public License for more details.
  7325. +*/
  7326. +
  7327. +#include "ipkg.h"
  7328. +
  7329. +#include "nv_pair.h"
  7330. +#include "str_util.h"
  7331. +
  7332. +int nv_pair_init(nv_pair_t *nv_pair, const char *name, const char *value)
  7333. +{
  7334. + nv_pair->name = str_dup_safe(name);
  7335. + nv_pair->value = str_dup_safe(value);
  7336. +
  7337. + return 0;
  7338. +}
  7339. +
  7340. +void nv_pair_deinit(nv_pair_t *nv_pair)
  7341. +{
  7342. + free(nv_pair->name);
  7343. + nv_pair->name = NULL;
  7344. +
  7345. + free(nv_pair->value);
  7346. + nv_pair->value = NULL;
  7347. +}
  7348. +
  7349. +
  7350. diff -Nur busybox-1.19.4.orig/archival/libipkg/nv_pair.h busybox-1.19.4/archival/libipkg/nv_pair.h
  7351. --- busybox-1.19.4.orig/archival/libipkg/nv_pair.h 1970-01-01 01:00:00.000000000 +0100
  7352. +++ busybox-1.19.4/archival/libipkg/nv_pair.h 2012-03-17 00:58:08.193100680 +0100
  7353. @@ -0,0 +1,32 @@
  7354. +/* nv_pair.h - the itsy package management system
  7355. +
  7356. + Carl D. Worth
  7357. +
  7358. + Copyright (C) 2001 University of Southern California
  7359. +
  7360. + This program is free software; you can redistribute it and/or
  7361. + modify it under the terms of the GNU General Public License as
  7362. + published by the Free Software Foundation; either version 2, or (at
  7363. + your option) any later version.
  7364. +
  7365. + This program is distributed in the hope that it will be useful, but
  7366. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7367. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7368. + General Public License for more details.
  7369. +*/
  7370. +
  7371. +#ifndef NV_PAIR_H
  7372. +#define NV_PAIR_H
  7373. +
  7374. +typedef struct nv_pair nv_pair_t;
  7375. +struct nv_pair
  7376. +{
  7377. + char *name;
  7378. + char *value;
  7379. +};
  7380. +
  7381. +int nv_pair_init(nv_pair_t *nv_pair, const char *name, const char *value);
  7382. +void nv_pair_deinit(nv_pair_t *nv_pair);
  7383. +
  7384. +#endif
  7385. +
  7386. diff -Nur busybox-1.19.4.orig/archival/libipkg/nv_pair_list.c busybox-1.19.4/archival/libipkg/nv_pair_list.c
  7387. --- busybox-1.19.4.orig/archival/libipkg/nv_pair_list.c 1970-01-01 01:00:00.000000000 +0100
  7388. +++ busybox-1.19.4/archival/libipkg/nv_pair_list.c 2012-03-17 00:58:08.193100680 +0100
  7389. @@ -0,0 +1,98 @@
  7390. +/* nv_pair_list.c - the itsy package management system
  7391. +
  7392. + Carl D. Worth
  7393. +
  7394. + Copyright (C) 2001 University of Southern California
  7395. +
  7396. + This program is free software; you can redistribute it and/or
  7397. + modify it under the terms of the GNU General Public License as
  7398. + published by the Free Software Foundation; either version 2, or (at
  7399. + your option) any later version.
  7400. +
  7401. + This program is distributed in the hope that it will be useful, but
  7402. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7403. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7404. + General Public License for more details.
  7405. +*/
  7406. +
  7407. +#include "ipkg.h"
  7408. +
  7409. +#include "nv_pair.h"
  7410. +#include "void_list.h"
  7411. +#include "nv_pair_list.h"
  7412. +
  7413. +int nv_pair_list_elt_init(nv_pair_list_elt_t *elt, nv_pair_t *data)
  7414. +{
  7415. + return void_list_elt_init((void_list_elt_t *) elt, data);
  7416. +}
  7417. +
  7418. +void nv_pair_list_elt_deinit(nv_pair_list_elt_t *elt)
  7419. +{
  7420. + void_list_elt_deinit((void_list_elt_t *) elt);
  7421. +}
  7422. +
  7423. +int nv_pair_list_init(nv_pair_list_t *list)
  7424. +{
  7425. + return void_list_init((void_list_t *) list);
  7426. +}
  7427. +
  7428. +void nv_pair_list_deinit(nv_pair_list_t *list)
  7429. +{
  7430. + nv_pair_list_elt_t *iter;
  7431. + nv_pair_t *nv_pair;
  7432. +
  7433. + for (iter = list->head; iter; iter = iter->next) {
  7434. + nv_pair = iter->data;
  7435. + nv_pair_deinit(nv_pair);
  7436. +
  7437. + /* malloced in nv_pair_list_append */
  7438. + free(nv_pair);
  7439. + iter->data = NULL;
  7440. + }
  7441. + void_list_deinit((void_list_t *) list);
  7442. +}
  7443. +
  7444. +nv_pair_t *nv_pair_list_append(nv_pair_list_t *list, const char *name, const char *value)
  7445. +{
  7446. + int err;
  7447. +
  7448. + /* freed in nv_pair_list_deinit */
  7449. + nv_pair_t *nv_pair = malloc(sizeof(nv_pair_t));
  7450. +
  7451. + if (nv_pair == NULL) {
  7452. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  7453. + return NULL;
  7454. + }
  7455. + nv_pair_init(nv_pair, name, value);
  7456. +
  7457. + err = void_list_append((void_list_t *) list, nv_pair);
  7458. + if (err) {
  7459. + return NULL;
  7460. + }
  7461. +
  7462. + return nv_pair;
  7463. +}
  7464. +
  7465. +int nv_pair_list_push(nv_pair_list_t *list, nv_pair_t *data)
  7466. +{
  7467. + return void_list_push((void_list_t *) list, data);
  7468. +}
  7469. +
  7470. +nv_pair_list_elt_t *nv_pair_list_pop(nv_pair_list_t *list)
  7471. +{
  7472. + return (nv_pair_list_elt_t *) void_list_pop((void_list_t *) list);
  7473. +}
  7474. +
  7475. +char *nv_pair_list_find(nv_pair_list_t *list, char *name)
  7476. +{
  7477. + nv_pair_list_elt_t *iter;
  7478. + nv_pair_t *nv_pair;
  7479. +
  7480. + for (iter = list->head; iter; iter = iter->next) {
  7481. + nv_pair = iter->data;
  7482. + if (strcmp(nv_pair->name, name) == 0) {
  7483. + return nv_pair->value;
  7484. + }
  7485. + }
  7486. + return NULL;
  7487. +}
  7488. diff -Nur busybox-1.19.4.orig/archival/libipkg/nv_pair_list.h busybox-1.19.4/archival/libipkg/nv_pair_list.h
  7489. --- busybox-1.19.4.orig/archival/libipkg/nv_pair_list.h 1970-01-01 01:00:00.000000000 +0100
  7490. +++ busybox-1.19.4/archival/libipkg/nv_pair_list.h 2012-03-17 00:58:08.193100680 +0100
  7491. @@ -0,0 +1,60 @@
  7492. +/* nv_pair_list.h - the itsy package management system
  7493. +
  7494. + Carl D. Worth
  7495. +
  7496. + Copyright (C) 2001 University of Southern California
  7497. +
  7498. + This program is free software; you can redistribute it and/or
  7499. + modify it under the terms of the GNU General Public License as
  7500. + published by the Free Software Foundation; either version 2, or (at
  7501. + your option) any later version.
  7502. +
  7503. + This program is distributed in the hope that it will be useful, but
  7504. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7505. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7506. + General Public License for more details.
  7507. +*/
  7508. +
  7509. +#ifndef NV_PAIR_LIST_H
  7510. +#define NV_PAIR_LIST_H
  7511. +
  7512. +#include "nv_pair.h"
  7513. +#include "void_list.h"
  7514. +
  7515. +typedef struct nv_pair_list_elt nv_pair_list_elt_t;
  7516. +struct nv_pair_list_elt
  7517. +{
  7518. + nv_pair_list_elt_t *next;
  7519. + nv_pair_t *data;
  7520. +};
  7521. +
  7522. +typedef struct nv_pair_list nv_pair_list_t;
  7523. +struct nv_pair_list
  7524. +{
  7525. + nv_pair_list_elt_t pre_head;
  7526. + nv_pair_list_elt_t *head;
  7527. + nv_pair_list_elt_t *tail;
  7528. +};
  7529. +
  7530. +static inline int nv_pair_list_empty(nv_pair_list_t *list)
  7531. +{
  7532. + if (list->head == NULL)
  7533. + return 1;
  7534. + else
  7535. + return 0;
  7536. +}
  7537. +
  7538. +int nv_pair_list_elt_init(nv_pair_list_elt_t *elt, nv_pair_t *data);
  7539. +void nv_pair_list_elt_deinit(nv_pair_list_elt_t *elt);
  7540. +
  7541. +int nv_pair_list_init(nv_pair_list_t *list);
  7542. +void nv_pair_list_deinit(nv_pair_list_t *list);
  7543. +
  7544. +nv_pair_t *nv_pair_list_append(nv_pair_list_t *list,
  7545. + const char *name, const char *value);
  7546. +int nv_pair_list_push(nv_pair_list_t *list, nv_pair_t *data);
  7547. +nv_pair_list_elt_t *nv_pair_list_pop(nv_pair_list_t *list);
  7548. +char *nv_pair_list_find(nv_pair_list_t *list, char *name);
  7549. +
  7550. +#endif
  7551. +
  7552. diff -Nur busybox-1.19.4.orig/archival/libipkg/pkg.c busybox-1.19.4/archival/libipkg/pkg.c
  7553. --- busybox-1.19.4.orig/archival/libipkg/pkg.c 1970-01-01 01:00:00.000000000 +0100
  7554. +++ busybox-1.19.4/archival/libipkg/pkg.c 2012-03-17 00:58:08.197100679 +0100
  7555. @@ -0,0 +1,1757 @@
  7556. +/* pkg.c - the itsy package management system
  7557. +
  7558. + Carl D. Worth
  7559. +
  7560. + Copyright (C) 2001 University of Southern California
  7561. +
  7562. + This program is free software; you can redistribute it and/or
  7563. + modify it under the terms of the GNU General Public License as
  7564. + published by the Free Software Foundation; either version 2, or (at
  7565. + your option) any later version.
  7566. +
  7567. + This program is distributed in the hope that it will be useful, but
  7568. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7569. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7570. + General Public License for more details.
  7571. +*/
  7572. +
  7573. +#include "ipkg.h"
  7574. +#include <ctype.h>
  7575. +#include <string.h>
  7576. +#include <errno.h>
  7577. +
  7578. +#include "pkg.h"
  7579. +
  7580. +#include "pkg_parse.h"
  7581. +#include "pkg_extract.h"
  7582. +#include "ipkg_message.h"
  7583. +#include "ipkg_utils.h"
  7584. +
  7585. +#include "sprintf_alloc.h"
  7586. +#include "file_util.h"
  7587. +#include "str_util.h"
  7588. +#include "xsystem.h"
  7589. +#include "ipkg_conf.h"
  7590. +
  7591. +int pkg_get_arch_priority(ipkg_conf_t *conf, const char *archname);
  7592. +void pkg_write_filelist_helper(const char *key, void *entry_, void *data_);
  7593. +
  7594. +typedef struct enum_map enum_map_t;
  7595. +struct enum_map
  7596. +{
  7597. + int value;
  7598. + const char *str;
  7599. +};
  7600. +
  7601. +static const enum_map_t pkg_state_want_map[] = {
  7602. + { SW_UNKNOWN, "unknown"},
  7603. + { SW_INSTALL, "install"},
  7604. + { SW_DEINSTALL, "deinstall"},
  7605. + { SW_PURGE, "purge"}
  7606. +};
  7607. +
  7608. +static const enum_map_t pkg_state_flag_map[] = {
  7609. + { SF_OK, "ok"},
  7610. + { SF_REINSTREQ, "reinstreq"},
  7611. + { SF_HOLD, "hold"},
  7612. + { SF_REPLACE, "replace"},
  7613. + { SF_NOPRUNE, "noprune"},
  7614. + { SF_PREFER, "prefer"},
  7615. + { SF_OBSOLETE, "obsolete"},
  7616. + { SF_USER, "user"},
  7617. +};
  7618. +
  7619. +static const enum_map_t pkg_state_status_map[] = {
  7620. + { SS_NOT_INSTALLED, "not-installed" },
  7621. + { SS_UNPACKED, "unpacked" },
  7622. + { SS_HALF_CONFIGURED, "half-configured" },
  7623. + { SS_INSTALLED, "installed" },
  7624. + { SS_HALF_INSTALLED, "half-installed" },
  7625. + { SS_CONFIG_FILES, "config-files" },
  7626. + { SS_POST_INST_FAILED, "post-inst-failed" },
  7627. + { SS_REMOVAL_FAILED, "removal-failed" }
  7628. +};
  7629. +
  7630. +static int verrevcmp(const char *val, const char *ref);
  7631. +
  7632. +
  7633. +pkg_t *pkg_new(void)
  7634. +{
  7635. + pkg_t *pkg;
  7636. +
  7637. + pkg = malloc(sizeof(pkg_t));
  7638. + if (pkg == NULL) {
  7639. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  7640. + return NULL;
  7641. + }
  7642. +
  7643. + pkg_init(pkg);
  7644. +
  7645. + return pkg;
  7646. +}
  7647. +
  7648. +int pkg_init(pkg_t *pkg)
  7649. +{
  7650. + memset(pkg, 0, sizeof(pkg_t));
  7651. + pkg->name = NULL;
  7652. + pkg->epoch = 0;
  7653. + pkg->version = NULL;
  7654. + pkg->revision = NULL;
  7655. + pkg->familiar_revision = NULL;
  7656. + pkg->dest = NULL;
  7657. + pkg->src = NULL;
  7658. + pkg->architecture = NULL;
  7659. + pkg->maintainer = NULL;
  7660. + pkg->section = NULL;
  7661. + pkg->description = NULL;
  7662. + pkg->state_want = SW_UNKNOWN;
  7663. + pkg->state_flag = SF_OK;
  7664. + pkg->state_status = SS_NOT_INSTALLED;
  7665. + pkg->depends_str = NULL;
  7666. + pkg->provides_str = NULL;
  7667. + pkg->depends_count = 0;
  7668. + pkg->depends = NULL;
  7669. + pkg->suggests_str = NULL;
  7670. + pkg->recommends_str = NULL;
  7671. + pkg->suggests_count = 0;
  7672. + pkg->recommends_count = 0;
  7673. +
  7674. + /* Abhaya: added init for conflicts fields */
  7675. + pkg->conflicts = NULL;
  7676. + pkg->conflicts_count = 0;
  7677. +
  7678. + /* added for replaces. Jamey 7/23/2002 */
  7679. + pkg->replaces = NULL;
  7680. + pkg->replaces_count = 0;
  7681. +
  7682. + pkg->pre_depends_count = 0;
  7683. + pkg->pre_depends_str = NULL;
  7684. + pkg->provides_count = 0;
  7685. + pkg->provides = NULL;
  7686. + pkg->filename = NULL;
  7687. + pkg->local_filename = NULL;
  7688. + pkg->tmp_unpack_dir = NULL;
  7689. + pkg->md5sum = NULL;
  7690. + pkg->size = NULL;
  7691. + pkg->installed_size = NULL;
  7692. + pkg->priority = NULL;
  7693. + pkg->source = NULL;
  7694. + conffile_list_init(&pkg->conffiles);
  7695. + pkg->installed_files = NULL;
  7696. + pkg->installed_files_ref_cnt = 0;
  7697. + pkg->essential = 0;
  7698. + pkg->provided_by_hand = 0;
  7699. +
  7700. + return 0;
  7701. +}
  7702. +
  7703. +void pkg_deinit(pkg_t *pkg)
  7704. +{
  7705. + free(pkg->name);
  7706. + pkg->name = NULL;
  7707. + pkg->epoch = 0;
  7708. + free(pkg->version);
  7709. + pkg->version = NULL;
  7710. + /* revision and familiar_revision share storage with version, so
  7711. + don't free */
  7712. + pkg->revision = NULL;
  7713. + pkg->familiar_revision = NULL;
  7714. + /* owned by ipkg_conf_t */
  7715. + pkg->dest = NULL;
  7716. + /* owned by ipkg_conf_t */
  7717. + pkg->src = NULL;
  7718. + free(pkg->architecture);
  7719. + pkg->architecture = NULL;
  7720. + free(pkg->maintainer);
  7721. + pkg->maintainer = NULL;
  7722. + free(pkg->section);
  7723. + pkg->section = NULL;
  7724. + free(pkg->description);
  7725. + pkg->description = NULL;
  7726. + pkg->state_want = SW_UNKNOWN;
  7727. + pkg->state_flag = SF_OK;
  7728. + pkg->state_status = SS_NOT_INSTALLED;
  7729. + free(pkg->depends_str);
  7730. + pkg->depends_str = NULL;
  7731. + free(pkg->provides_str);
  7732. + pkg->provides_str = NULL;
  7733. + pkg->depends_count = 0;
  7734. + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->depends ? */
  7735. + pkg->pre_depends_count = 0;
  7736. + free(pkg->pre_depends_str);
  7737. + pkg->pre_depends_str = NULL;
  7738. + pkg->provides_count = 0;
  7739. + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->provides ? */
  7740. + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->suggests ? */
  7741. + free(pkg->filename);
  7742. + pkg->filename = NULL;
  7743. + free(pkg->local_filename);
  7744. + pkg->local_filename = NULL;
  7745. + /* CLEANUP: It'd be nice to pullin the cleanup function from
  7746. + ipkg_install.c here. See comment in
  7747. + ipkg_install.c:cleanup_temporary_files */
  7748. + free(pkg->tmp_unpack_dir);
  7749. + pkg->tmp_unpack_dir = NULL;
  7750. + free(pkg->md5sum);
  7751. + pkg->md5sum = NULL;
  7752. + free(pkg->size);
  7753. + pkg->size = NULL;
  7754. + free(pkg->installed_size);
  7755. + pkg->installed_size = NULL;
  7756. + free(pkg->priority);
  7757. + pkg->priority = NULL;
  7758. + free(pkg->source);
  7759. + pkg->source = NULL;
  7760. + conffile_list_deinit(&pkg->conffiles);
  7761. + /* XXX: QUESTION: Is forcing this to 1 correct? I suppose so,
  7762. + since if they are calling deinit, they should know. Maybe do an
  7763. + assertion here instead? */
  7764. + pkg->installed_files_ref_cnt = 1;
  7765. + pkg_free_installed_files(pkg);
  7766. + pkg->essential = 0;
  7767. +}
  7768. +
  7769. +int pkg_init_from_file(pkg_t *pkg, const char *filename)
  7770. +{
  7771. + int err;
  7772. + char **raw;
  7773. + FILE *control_file;
  7774. +
  7775. + err = pkg_init(pkg);
  7776. + if (err) { return err; }
  7777. +
  7778. + pkg->local_filename = strdup(filename);
  7779. +
  7780. + control_file = tmpfile();
  7781. + err = pkg_extract_control_file_to_stream(pkg, control_file);
  7782. + if (err) { return err; }
  7783. +
  7784. + rewind(control_file);
  7785. + raw = read_raw_pkgs_from_stream(control_file);
  7786. + pkg_parse_raw(pkg, &raw, NULL, NULL);
  7787. +
  7788. + fclose(control_file);
  7789. +
  7790. + return 0;
  7791. +}
  7792. +
  7793. +/* Merge any new information in newpkg into oldpkg */
  7794. +/* XXX: CLEANUP: This function shouldn't actually modify anything in
  7795. + newpkg, but should leave it usable. This rework is so that
  7796. + pkg_hash_insert doesn't clobber the pkg that you pass into it. */
  7797. +/*
  7798. + * uh, i thought that i had originally written this so that it took
  7799. + * two pkgs and returned a new one? we can do that again... -sma
  7800. + */
  7801. +int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status)
  7802. +{
  7803. + if (oldpkg == newpkg) {
  7804. + return 0;
  7805. + }
  7806. +
  7807. + if (!oldpkg->src)
  7808. + oldpkg->src = newpkg->src;
  7809. + if (!oldpkg->dest)
  7810. + oldpkg->dest = newpkg->dest;
  7811. + if (!oldpkg->architecture)
  7812. + oldpkg->architecture = str_dup_safe(newpkg->architecture);
  7813. + if (!oldpkg->arch_priority)
  7814. + oldpkg->arch_priority = newpkg->arch_priority;
  7815. + if (!oldpkg->section)
  7816. + oldpkg->section = str_dup_safe(newpkg->section);
  7817. + if(!oldpkg->maintainer)
  7818. + oldpkg->maintainer = str_dup_safe(newpkg->maintainer);
  7819. + if(!oldpkg->description)
  7820. + oldpkg->description = str_dup_safe(newpkg->description);
  7821. + if (set_status) {
  7822. + /* merge the state_flags from the new package */
  7823. + oldpkg->state_want = newpkg->state_want;
  7824. + oldpkg->state_status = newpkg->state_status;
  7825. + oldpkg->state_flag = newpkg->state_flag;
  7826. + } else {
  7827. + if (oldpkg->state_want == SW_UNKNOWN)
  7828. + oldpkg->state_want = newpkg->state_want;
  7829. + if (oldpkg->state_status == SS_NOT_INSTALLED)
  7830. + oldpkg->state_status = newpkg->state_status;
  7831. + oldpkg->state_flag |= newpkg->state_flag;
  7832. + }
  7833. +
  7834. + if (!oldpkg->depends_str && !oldpkg->pre_depends_str && !oldpkg->recommends_str && !oldpkg->suggests_str) {
  7835. + oldpkg->depends_str = newpkg->depends_str;
  7836. + newpkg->depends_str = NULL;
  7837. + oldpkg->depends_count = newpkg->depends_count;
  7838. + newpkg->depends_count = 0;
  7839. +
  7840. + oldpkg->depends = newpkg->depends;
  7841. + newpkg->depends = NULL;
  7842. +
  7843. + oldpkg->pre_depends_str = newpkg->pre_depends_str;
  7844. + newpkg->pre_depends_str = NULL;
  7845. + oldpkg->pre_depends_count = newpkg->pre_depends_count;
  7846. + newpkg->pre_depends_count = 0;
  7847. +
  7848. + oldpkg->recommends_str = newpkg->recommends_str;
  7849. + newpkg->recommends_str = NULL;
  7850. + oldpkg->recommends_count = newpkg->recommends_count;
  7851. + newpkg->recommends_count = 0;
  7852. +
  7853. + oldpkg->suggests_str = newpkg->suggests_str;
  7854. + newpkg->suggests_str = NULL;
  7855. + oldpkg->suggests_count = newpkg->suggests_count;
  7856. + newpkg->suggests_count = 0;
  7857. + }
  7858. +
  7859. + if (!oldpkg->provides_str) {
  7860. + oldpkg->provides_str = newpkg->provides_str;
  7861. + newpkg->provides_str = NULL;
  7862. + oldpkg->provides_count = newpkg->provides_count;
  7863. + newpkg->provides_count = 0;
  7864. +
  7865. + oldpkg->provides = newpkg->provides;
  7866. + newpkg->provides = NULL;
  7867. + }
  7868. +
  7869. + if (!oldpkg->conflicts_str) {
  7870. + oldpkg->conflicts_str = newpkg->conflicts_str;
  7871. + newpkg->conflicts_str = NULL;
  7872. + oldpkg->conflicts_count = newpkg->conflicts_count;
  7873. + newpkg->conflicts_count = 0;
  7874. +
  7875. + oldpkg->conflicts = newpkg->conflicts;
  7876. + newpkg->conflicts = NULL;
  7877. + }
  7878. +
  7879. + if (!oldpkg->replaces_str) {
  7880. + oldpkg->replaces_str = newpkg->replaces_str;
  7881. + newpkg->replaces_str = NULL;
  7882. + oldpkg->replaces_count = newpkg->replaces_count;
  7883. + newpkg->replaces_count = 0;
  7884. +
  7885. + oldpkg->replaces = newpkg->replaces;
  7886. + newpkg->replaces = NULL;
  7887. + }
  7888. +
  7889. + if (!oldpkg->filename)
  7890. + oldpkg->filename = str_dup_safe(newpkg->filename);
  7891. + if (0)
  7892. + fprintf(stdout, "pkg=%s old local_filename=%s new local_filename=%s\n",
  7893. + oldpkg->name, oldpkg->local_filename, newpkg->local_filename);
  7894. + if (!oldpkg->local_filename)
  7895. + oldpkg->local_filename = str_dup_safe(newpkg->local_filename);
  7896. + if (!oldpkg->tmp_unpack_dir)
  7897. + oldpkg->tmp_unpack_dir = str_dup_safe(newpkg->tmp_unpack_dir);
  7898. + if (!oldpkg->md5sum)
  7899. + oldpkg->md5sum = str_dup_safe(newpkg->md5sum);
  7900. + if (!oldpkg->size)
  7901. + oldpkg->size = str_dup_safe(newpkg->size);
  7902. + if (!oldpkg->installed_size)
  7903. + oldpkg->installed_size = str_dup_safe(newpkg->installed_size);
  7904. + if (!oldpkg->priority)
  7905. + oldpkg->priority = str_dup_safe(newpkg->priority);
  7906. + if (!oldpkg->source)
  7907. + oldpkg->source = str_dup_safe(newpkg->source);
  7908. + if (oldpkg->conffiles.head == NULL){
  7909. + oldpkg->conffiles = newpkg->conffiles;
  7910. + conffile_list_init(&newpkg->conffiles);
  7911. + }
  7912. + if (!oldpkg->installed_files){
  7913. + oldpkg->installed_files = newpkg->installed_files;
  7914. + oldpkg->installed_files_ref_cnt = newpkg->installed_files_ref_cnt;
  7915. + newpkg->installed_files = NULL;
  7916. + }
  7917. + if (!oldpkg->essential)
  7918. + oldpkg->essential = newpkg->essential;
  7919. +
  7920. + return 0;
  7921. +}
  7922. +
  7923. +abstract_pkg_t *abstract_pkg_new(void)
  7924. +{
  7925. + abstract_pkg_t * ab_pkg;
  7926. +
  7927. + ab_pkg = malloc(sizeof(abstract_pkg_t));
  7928. +
  7929. + if (ab_pkg == NULL) {
  7930. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  7931. + return NULL;
  7932. + }
  7933. +
  7934. + if ( abstract_pkg_init(ab_pkg) < 0 )
  7935. + return NULL;
  7936. +
  7937. + return ab_pkg;
  7938. +}
  7939. +
  7940. +int abstract_pkg_init(abstract_pkg_t *ab_pkg)
  7941. +{
  7942. + memset(ab_pkg, 0, sizeof(abstract_pkg_t));
  7943. +
  7944. + ab_pkg->provided_by = abstract_pkg_vec_alloc();
  7945. + if (ab_pkg->provided_by==NULL){
  7946. + return -1;
  7947. + }
  7948. + ab_pkg->dependencies_checked = 0;
  7949. + ab_pkg->state_status = SS_NOT_INSTALLED;
  7950. +
  7951. + return 0;
  7952. +}
  7953. +
  7954. +void set_flags_from_control(ipkg_conf_t *conf, pkg_t *pkg){
  7955. + char * temp_str;
  7956. + char **raw =NULL;
  7957. + char **raw_start=NULL;
  7958. +
  7959. + temp_str = (char *) malloc (strlen(pkg->dest->info_dir)+strlen(pkg->name)+12);
  7960. + if (temp_str == NULL ){
  7961. + ipkg_message(conf, IPKG_INFO, "Out of memory in %s\n", __FUNCTION__);
  7962. + return;
  7963. + }
  7964. + sprintf( temp_str,"%s/%s.control",pkg->dest->info_dir,pkg->name);
  7965. +
  7966. + raw = raw_start = read_raw_pkgs_from_file(temp_str);
  7967. + if (raw == NULL ){
  7968. + ipkg_message(conf, IPKG_ERROR, "Unable to open the control file in %s\n", __FUNCTION__);
  7969. + return;
  7970. + }
  7971. +
  7972. + while(*raw){
  7973. + if (!pkg_valorize_other_field(pkg, &raw ) == 0) {
  7974. + ipkg_message(conf, IPKG_DEBUG, "unable to read control file for %s. May be empty\n", pkg->name);
  7975. + }
  7976. + }
  7977. + raw = raw_start;
  7978. + while (*raw) {
  7979. + if (raw!=NULL)
  7980. + free(*raw++);
  7981. + }
  7982. +
  7983. + free(raw_start);
  7984. + free(temp_str);
  7985. +
  7986. + return ;
  7987. +
  7988. +}
  7989. +
  7990. +char * pkg_formatted_info(pkg_t *pkg )
  7991. +{
  7992. + char *line;
  7993. + char * buff;
  7994. +
  7995. + buff = malloc(8192);
  7996. + if (buff == NULL) {
  7997. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  7998. + return NULL;
  7999. + }
  8000. +
  8001. + buff[0] = '\0';
  8002. +
  8003. + line = pkg_formatted_field(pkg, "Package");
  8004. + strncat(buff ,line, strlen(line));
  8005. + free(line);
  8006. +
  8007. + line = pkg_formatted_field(pkg, "Version");
  8008. + strncat(buff ,line, strlen(line));
  8009. + free(line);
  8010. +
  8011. + line = pkg_formatted_field(pkg, "Depends");
  8012. + strncat(buff ,line, strlen(line));
  8013. + free(line);
  8014. +
  8015. + line = pkg_formatted_field(pkg, "Recommends");
  8016. + strncat(buff ,line, strlen(line));
  8017. + free(line);
  8018. +
  8019. + line = pkg_formatted_field(pkg, "Suggests");
  8020. + strncat(buff ,line, strlen(line));
  8021. + free(line);
  8022. +
  8023. + line = pkg_formatted_field(pkg, "Provides");
  8024. + strncat(buff ,line, strlen(line));
  8025. + free(line);
  8026. +
  8027. + line = pkg_formatted_field(pkg, "Replaces");
  8028. + strncat(buff ,line, strlen(line));
  8029. + free(line);
  8030. +
  8031. + line = pkg_formatted_field(pkg, "Conflicts");
  8032. + strncat(buff ,line, strlen(line));
  8033. + free(line);
  8034. +
  8035. + line = pkg_formatted_field(pkg, "Status");
  8036. + strncat(buff ,line, strlen(line));
  8037. + free(line);
  8038. +
  8039. + line = pkg_formatted_field(pkg, "Section");
  8040. + strncat(buff ,line, strlen(line));
  8041. + free(line);
  8042. +
  8043. + line = pkg_formatted_field(pkg, "Essential"); /* @@@@ should be removed in future release. *//* I do not agree with this Pigi*/
  8044. + strncat(buff ,line, strlen(line));
  8045. + free(line);
  8046. +
  8047. + line = pkg_formatted_field(pkg, "Architecture");
  8048. + strncat(buff ,line, strlen(line));
  8049. + free(line);
  8050. +
  8051. + line = pkg_formatted_field(pkg, "Maintainer");
  8052. + strncat(buff ,line, strlen(line));
  8053. + free(line);
  8054. +
  8055. + line = pkg_formatted_field(pkg, "MD5sum");
  8056. + strncat(buff ,line, strlen(line));
  8057. + free(line);
  8058. +
  8059. + line = pkg_formatted_field(pkg, "Size");
  8060. + strncat(buff ,line, strlen(line));
  8061. + free(line);
  8062. +
  8063. + line = pkg_formatted_field(pkg, "Filename");
  8064. + strncat(buff ,line, strlen(line));
  8065. + free(line);
  8066. +
  8067. + line = pkg_formatted_field(pkg, "Conffiles");
  8068. + strncat(buff ,line, strlen(line));
  8069. + free(line);
  8070. +
  8071. + line = pkg_formatted_field(pkg, "Source");
  8072. + strncat(buff ,line, strlen(line));
  8073. + free(line);
  8074. +
  8075. + line = pkg_formatted_field(pkg, "Description");
  8076. + strncat(buff ,line, strlen(line));
  8077. + free(line);
  8078. +
  8079. + line = pkg_formatted_field(pkg, "Installed-Time");
  8080. + strncat(buff ,line, strlen(line));
  8081. + free(line);
  8082. +
  8083. + return buff;
  8084. +}
  8085. +
  8086. +char * pkg_formatted_field(pkg_t *pkg, const char *field )
  8087. +{
  8088. + static size_t LINE_LEN = 128;
  8089. + char * temp = (char *)malloc(1);
  8090. + int len = 0;
  8091. + int flag_provide_false = 0;
  8092. +
  8093. +/*
  8094. + Pigi: After some discussion with Florian we decided to modify the full procedure in
  8095. + dynamic memory allocation. This should avoid any other segv in this area ( except for bugs )
  8096. +*/
  8097. +
  8098. + if (strlen(field) < PKG_MINIMUM_FIELD_NAME_LEN) {
  8099. + goto UNKNOWN_FMT_FIELD;
  8100. + }
  8101. +
  8102. + temp[0]='\0';
  8103. +
  8104. + switch (field[0])
  8105. + {
  8106. + case 'a':
  8107. + case 'A':
  8108. + if (strcasecmp(field, "Architecture") == 0) {
  8109. + /* Architecture */
  8110. + if (pkg->architecture) {
  8111. + temp = (char *)realloc(temp,strlen(pkg->architecture)+17);
  8112. + if ( temp == NULL ){
  8113. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8114. + return NULL;
  8115. + }
  8116. + temp[0]='\0';
  8117. + snprintf(temp, (strlen(pkg->architecture)+17), "Architecture: %s\n", pkg->architecture);
  8118. + }
  8119. + } else {
  8120. + goto UNKNOWN_FMT_FIELD;
  8121. + }
  8122. + break;
  8123. + case 'c':
  8124. + case 'C':
  8125. + if (strcasecmp(field, "Conffiles") == 0) {
  8126. + /* Conffiles */
  8127. + conffile_list_elt_t *iter;
  8128. + char confstr_[LINE_LEN];
  8129. +
  8130. + if (pkg->conffiles.head == NULL) {
  8131. + return temp;
  8132. + }
  8133. +
  8134. + len = 14 ;
  8135. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  8136. + if (iter->data->name && iter->data->value) {
  8137. + len = len + (strlen(iter->data->name)+strlen(iter->data->value)+5);
  8138. + }
  8139. + }
  8140. + temp = (char *)realloc(temp,len);
  8141. + if ( temp == NULL ){
  8142. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8143. + return NULL;
  8144. + }
  8145. + temp[0]='\0';
  8146. + strncpy(temp, "Conffiles:\n", 12);
  8147. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  8148. + if (iter->data->name && iter->data->value) {
  8149. + snprintf(confstr_, LINE_LEN, "%s %s\n", iter->data->name, iter->data->value);
  8150. + strncat(temp, confstr_, strlen(confstr_));
  8151. + }
  8152. + }
  8153. + } else if (strcasecmp(field, "Conflicts") == 0) {
  8154. + int i;
  8155. +
  8156. + if (pkg->conflicts_count) {
  8157. + char conflictstr[LINE_LEN];
  8158. + len = 14 ;
  8159. + for(i = 0; i < pkg->conflicts_count; i++) {
  8160. + len = len + (strlen(pkg->conflicts_str[i])+5);
  8161. + }
  8162. + temp = (char *)realloc(temp,len);
  8163. + if ( temp == NULL ){
  8164. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8165. + return NULL;
  8166. + }
  8167. + temp[0]='\0';
  8168. + strncpy(temp, "Conflicts:", 11);
  8169. + for(i = 0; i < pkg->conflicts_count; i++) {
  8170. + snprintf(conflictstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->conflicts_str[i]);
  8171. + strncat(temp, conflictstr, strlen(conflictstr));
  8172. + }
  8173. + strncat(temp, "\n", strlen("\n"));
  8174. + }
  8175. + } else {
  8176. + goto UNKNOWN_FMT_FIELD;
  8177. + }
  8178. + break;
  8179. + case 'd':
  8180. + case 'D':
  8181. + if (strcasecmp(field, "Depends") == 0) {
  8182. + /* Depends */
  8183. + int i;
  8184. +
  8185. + if (pkg->depends_count) {
  8186. + char depstr[LINE_LEN];
  8187. + len = 14 ;
  8188. + for(i = 0; i < pkg->depends_count; i++) {
  8189. + len = len + (strlen(pkg->depends_str[i])+4);
  8190. + }
  8191. + temp = (char *)realloc(temp,len);
  8192. + if ( temp == NULL ){
  8193. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8194. + return NULL;
  8195. + }
  8196. + temp[0]='\0';
  8197. + strncpy(temp, "Depends:", 10);
  8198. + for(i = 0; i < pkg->depends_count; i++) {
  8199. + snprintf(depstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->depends_str[i]);
  8200. + strncat(temp, depstr, strlen(depstr));
  8201. + }
  8202. + strncat(temp, "\n", strlen("\n"));
  8203. + }
  8204. + } else if (strcasecmp(field, "Description") == 0) {
  8205. + /* Description */
  8206. + if (pkg->description) {
  8207. + temp = (char *)realloc(temp,strlen(pkg->description)+16);
  8208. + if ( temp == NULL ){
  8209. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8210. + return NULL;
  8211. + }
  8212. + temp[0]='\0';
  8213. + snprintf(temp, (strlen(pkg->description)+16), "Description: %s\n", pkg->description);
  8214. + }
  8215. + } else {
  8216. + goto UNKNOWN_FMT_FIELD;
  8217. + }
  8218. + break;
  8219. + case 'e':
  8220. + case 'E': {
  8221. + /* Essential */
  8222. + if (pkg->essential) {
  8223. + temp = (char *)realloc(temp,16);
  8224. + if ( temp == NULL ){
  8225. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8226. + return NULL;
  8227. + }
  8228. + temp[0]='\0';
  8229. + snprintf(temp, (16), "Essential: yes\n");
  8230. + }
  8231. + }
  8232. + break;
  8233. + case 'f':
  8234. + case 'F': {
  8235. + /* Filename */
  8236. + if (pkg->filename) {
  8237. + temp = (char *)realloc(temp,strlen(pkg->filename)+12);
  8238. + if ( temp == NULL ){
  8239. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8240. + return NULL;
  8241. + }
  8242. + temp[0]='\0';
  8243. + snprintf(temp, (strlen(pkg->filename)+12), "Filename: %s\n", pkg->filename);
  8244. + }
  8245. + }
  8246. + break;
  8247. + case 'i':
  8248. + case 'I': {
  8249. + if (strcasecmp(field, "Installed-Size") == 0) {
  8250. + /* Installed-Size */
  8251. + temp = (char *)realloc(temp,strlen(pkg->installed_size)+17);
  8252. + if ( temp == NULL ){
  8253. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8254. + return NULL;
  8255. + }
  8256. + temp[0]='\0';
  8257. + snprintf(temp, (strlen(pkg->installed_size)+17), "Installed-Size: %s\n", pkg->installed_size);
  8258. + } else if (strcasecmp(field, "Installed-Time") == 0 && pkg->installed_time) {
  8259. + temp = (char *)realloc(temp,29);
  8260. + if ( temp == NULL ){
  8261. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8262. + return NULL;
  8263. + }
  8264. + temp[0]='\0';
  8265. + snprintf(temp, 29, "Installed-Time: %lu\n", pkg->installed_time);
  8266. + }
  8267. + }
  8268. + break;
  8269. + case 'm':
  8270. + case 'M': {
  8271. + /* Maintainer | MD5sum */
  8272. + if (strcasecmp(field, "Maintainer") == 0) {
  8273. + /* Maintainer */
  8274. + if (pkg->maintainer) {
  8275. + temp = (char *)realloc(temp,strlen(pkg->maintainer)+14);
  8276. + if ( temp == NULL ){
  8277. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8278. + return NULL;
  8279. + }
  8280. + temp[0]='\0';
  8281. + snprintf(temp, (strlen(pkg->maintainer)+14), "maintainer: %s\n", pkg->maintainer);
  8282. + }
  8283. + } else if (strcasecmp(field, "MD5sum") == 0) {
  8284. + /* MD5sum */
  8285. + if (pkg->md5sum) {
  8286. + temp = (char *)realloc(temp,strlen(pkg->md5sum)+11);
  8287. + if ( temp == NULL ){
  8288. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8289. + return NULL;
  8290. + }
  8291. + temp[0]='\0';
  8292. + snprintf(temp, (strlen(pkg->md5sum)+11), "MD5Sum: %s\n", pkg->md5sum);
  8293. + }
  8294. + } else {
  8295. + goto UNKNOWN_FMT_FIELD;
  8296. + }
  8297. + }
  8298. + break;
  8299. + case 'p':
  8300. + case 'P': {
  8301. + if (strcasecmp(field, "Package") == 0) {
  8302. + /* Package */
  8303. + temp = (char *)realloc(temp,strlen(pkg->name)+11);
  8304. + if ( temp == NULL ){
  8305. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8306. + return NULL;
  8307. + }
  8308. + temp[0]='\0';
  8309. + snprintf(temp, (strlen(pkg->name)+11), "Package: %s\n", pkg->name);
  8310. + } else if (strcasecmp(field, "Priority") == 0) {
  8311. + /* Priority */
  8312. + temp = (char *)realloc(temp,strlen(pkg->priority)+12);
  8313. + if ( temp == NULL ){
  8314. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8315. + return NULL;
  8316. + }
  8317. + temp[0]='\0';
  8318. + snprintf(temp, (strlen(pkg->priority)+12), "Priority: %s\n", pkg->priority);
  8319. + } else if (strcasecmp(field, "Provides") == 0) {
  8320. + /* Provides */
  8321. + int i;
  8322. +
  8323. + if (pkg->provides_count) {
  8324. + /* Here we check if the ipkg_internal_use_only is used, and we discard it.*/
  8325. + for ( i=0; i < pkg->provides_count; i++ ){
  8326. + if (strstr(pkg->provides_str[i],"ipkg_internal_use_only")!=NULL) {
  8327. + memset (pkg->provides_str[i],'\x0',strlen(pkg->provides_str[i])); /* Pigi clear my trick flag, just in case */
  8328. + flag_provide_false = 1;
  8329. + }
  8330. + }
  8331. + if ( !flag_provide_false || /* Pigi there is not my trick flag */
  8332. + ((flag_provide_false) && (pkg->provides_count > 1))){ /* Pigi There is, but we also have others Provides */
  8333. + char provstr[LINE_LEN];
  8334. + len = 15;
  8335. + for(i = 0; i < pkg->provides_count; i++) {
  8336. + len = len + (strlen(pkg->provides_str[i])+5);
  8337. + }
  8338. + temp = (char *)realloc(temp,len);
  8339. + if ( temp == NULL ){
  8340. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8341. + return NULL;
  8342. + }
  8343. + temp[0]='\0';
  8344. + strncpy(temp, "Provides:", 12);
  8345. + for(i = 0; i < pkg->provides_count; i++) {
  8346. + if (strlen(pkg->provides_str[i])>0){;
  8347. + snprintf(provstr, LINE_LEN, "%s %s", i == 1 ? "" : ",", pkg->provides_str[i]);
  8348. + strncat(temp, provstr, strlen(provstr));
  8349. + }
  8350. + }
  8351. + strncat(temp, "\n", strlen("\n"));
  8352. + }
  8353. + }
  8354. + } else {
  8355. + goto UNKNOWN_FMT_FIELD;
  8356. + }
  8357. + }
  8358. + break;
  8359. + case 'r':
  8360. + case 'R': {
  8361. + int i;
  8362. + /* Replaces | Recommends*/
  8363. + if (strcasecmp (field, "Replaces") == 0) {
  8364. + if (pkg->replaces_count) {
  8365. + char replstr[LINE_LEN];
  8366. + len = 14;
  8367. + for (i = 0; i < pkg->replaces_count; i++) {
  8368. + len = len + (strlen(pkg->replaces_str[i])+5);
  8369. + }
  8370. + temp = (char *)realloc(temp,len);
  8371. + if ( temp == NULL ){
  8372. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8373. + return NULL;
  8374. + }
  8375. + temp[0]='\0';
  8376. + strncpy(temp, "Replaces:", 12);
  8377. + for (i = 0; i < pkg->replaces_count; i++) {
  8378. + snprintf(replstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->replaces_str[i]);
  8379. + strncat(temp, replstr, strlen(replstr));
  8380. + }
  8381. + strncat(temp, "\n", strlen("\n"));
  8382. + }
  8383. + } else if (strcasecmp (field, "Recommends") == 0) {
  8384. + if (pkg->recommends_count) {
  8385. + char recstr[LINE_LEN];
  8386. + len = 15;
  8387. + for(i = 0; i < pkg->recommends_count; i++) {
  8388. + len = len + (strlen( pkg->recommends_str[i])+5);
  8389. + }
  8390. + temp = (char *)realloc(temp,len);
  8391. + if ( temp == NULL ){
  8392. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8393. + return NULL;
  8394. + }
  8395. + temp[0]='\0';
  8396. + strncpy(temp, "Recommends:", 13);
  8397. + for(i = 0; i < pkg->recommends_count; i++) {
  8398. + snprintf(recstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->recommends_str[i]);
  8399. + strncat(temp, recstr, strlen(recstr));
  8400. + }
  8401. + strncat(temp, "\n", strlen("\n"));
  8402. + }
  8403. + } else {
  8404. + goto UNKNOWN_FMT_FIELD;
  8405. + }
  8406. + }
  8407. + break;
  8408. + case 's':
  8409. + case 'S': {
  8410. + /* Section | Size | Source | Status | Suggests */
  8411. + if (strcasecmp(field, "Section") == 0) {
  8412. + /* Section */
  8413. + if (pkg->section) {
  8414. + temp = (char *)realloc(temp,strlen(pkg->section)+11);
  8415. + if ( temp == NULL ){
  8416. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8417. + return NULL;
  8418. + }
  8419. + temp[0]='\0';
  8420. + snprintf(temp, (strlen(pkg->section)+11), "Section: %s\n", pkg->section);
  8421. + }
  8422. + } else if (strcasecmp(field, "Size") == 0) {
  8423. + /* Size */
  8424. + if (pkg->size) {
  8425. + temp = (char *)realloc(temp,strlen(pkg->size)+8);
  8426. + if ( temp == NULL ){
  8427. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8428. + return NULL;
  8429. + }
  8430. + temp[0]='\0';
  8431. + snprintf(temp, (strlen(pkg->size)+8), "Size: %s\n", pkg->size);
  8432. + }
  8433. + } else if (strcasecmp(field, "Source") == 0) {
  8434. + /* Source */
  8435. + if (pkg->source) {
  8436. + temp = (char *)realloc(temp,strlen(pkg->source)+10);
  8437. + if ( temp == NULL ){
  8438. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8439. + return NULL;
  8440. + }
  8441. + temp[0]='\0';
  8442. + snprintf(temp, (strlen(pkg->source)+10), "Source: %s\n", pkg->source);
  8443. + }
  8444. + } else if (strcasecmp(field, "Status") == 0) {
  8445. + /* Status */
  8446. + /* Benjamin Pineau note: we should avoid direct usage of
  8447. + * strlen(arg) without keeping "arg" for later free()
  8448. + */
  8449. + char *pflag=pkg_state_flag_to_str(pkg->state_flag);
  8450. + char *pstat=pkg_state_status_to_str(pkg->state_status);
  8451. + char *pwant=pkg_state_want_to_str(pkg->state_want);
  8452. +
  8453. + size_t sum_of_sizes = (size_t) ( strlen(pwant)+ strlen(pflag)+ strlen(pstat) + 12 );
  8454. + temp = (char *)realloc(temp,sum_of_sizes);
  8455. + if ( temp == NULL ){
  8456. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8457. + return NULL;
  8458. + }
  8459. + temp[0]='\0';
  8460. + snprintf(temp, sum_of_sizes , "Status: %s %s %s\n", pwant, pflag, pstat);
  8461. + free(pflag);
  8462. + free(pwant);
  8463. + if(pstat) /* pfstat can be NULL if ENOMEM */
  8464. + free(pstat);
  8465. + } else if (strcasecmp(field, "Suggests") == 0) {
  8466. + if (pkg->suggests_count) {
  8467. + int i;
  8468. + char sugstr[LINE_LEN];
  8469. + len = 13;
  8470. + for(i = 0; i < pkg->suggests_count; i++) {
  8471. + len = len + (strlen(pkg->suggests_str[i])+5);
  8472. + }
  8473. + temp = (char *)realloc(temp,len);
  8474. + if ( temp == NULL ){
  8475. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8476. + return NULL;
  8477. + }
  8478. + temp[0]='\0';
  8479. + strncpy(temp, "Suggests:", 10);
  8480. + for(i = 0; i < pkg->suggests_count; i++) {
  8481. + snprintf(sugstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->suggests_str[i]);
  8482. + strncat(temp, sugstr, strlen(sugstr));
  8483. + }
  8484. + strncat(temp, "\n", strlen("\n"));
  8485. + }
  8486. + } else {
  8487. + goto UNKNOWN_FMT_FIELD;
  8488. + }
  8489. + }
  8490. + break;
  8491. + case 'v':
  8492. + case 'V': {
  8493. + /* Version */
  8494. + char *version = pkg_version_str_alloc(pkg);
  8495. + temp = (char *)realloc(temp,strlen(version)+14);
  8496. + if ( temp == NULL ){
  8497. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8498. + return NULL;
  8499. + }
  8500. + temp[0]='\0';
  8501. + snprintf(temp, (strlen(version)+12), "Version: %s\n", version);
  8502. + free(version);
  8503. + }
  8504. + break;
  8505. + default:
  8506. + goto UNKNOWN_FMT_FIELD;
  8507. + }
  8508. +
  8509. + if ( strlen(temp)<2 ) {
  8510. + temp[0]='\0';
  8511. + }
  8512. + return temp;
  8513. +
  8514. + UNKNOWN_FMT_FIELD:
  8515. + fprintf(stderr, "%s: ERROR: Unknown field name: %s\n", __FUNCTION__, field);
  8516. + if ( strlen(temp)<2 ) {
  8517. + temp[0]='\0';
  8518. + }
  8519. +
  8520. + return temp;
  8521. +}
  8522. +
  8523. +void pkg_print_info(pkg_t *pkg, FILE *file)
  8524. +{
  8525. + char * buff;
  8526. + if (pkg == NULL) {
  8527. + return;
  8528. + }
  8529. +
  8530. + buff = pkg_formatted_info(pkg);
  8531. + if ( buff == NULL )
  8532. + return;
  8533. + if (strlen(buff)>2){
  8534. + fwrite(buff, 1, strlen(buff), file);
  8535. + }
  8536. + free(buff);
  8537. +}
  8538. +
  8539. +void pkg_print_status(pkg_t * pkg, FILE * file)
  8540. +{
  8541. + if (pkg == NULL) {
  8542. + return;
  8543. + }
  8544. +
  8545. + /* XXX: QUESTION: Do we actually want more fields here? The
  8546. + original idea was to save space by installing only what was
  8547. + needed for actual computation, (package, version, status,
  8548. + essential, conffiles). The assumption is that all other fields
  8549. + can be found in th available file.
  8550. +
  8551. + But, someone proposed the idea to make it possible to
  8552. + reconstruct a .ipk from an installed package, (ie. for beaming
  8553. + from one handheld to another). So, maybe we actually want a few
  8554. + more fields here, (depends, suggests, etc.), so that that would
  8555. + be guaranteed to work even in the absence of more information
  8556. + from the available file.
  8557. +
  8558. + 28-MAR-03: kergoth and I discussed this yesterday. We think
  8559. + the essential info needs to be here for all installed packages
  8560. + because they may not appear in the Packages files on various
  8561. + feeds. Furthermore, one should be able to install from URL or
  8562. + local storage without requiring a Packages file from any feed.
  8563. + -Jamey
  8564. + */
  8565. + pkg_print_field(pkg, file, "Package");
  8566. + pkg_print_field(pkg, file, "Version");
  8567. + pkg_print_field(pkg, file, "Depends");
  8568. + pkg_print_field(pkg, file, "Recommends");
  8569. + pkg_print_field(pkg, file, "Suggests");
  8570. + pkg_print_field(pkg, file, "Provides");
  8571. + pkg_print_field(pkg, file, "Replaces");
  8572. + pkg_print_field(pkg, file, "Conflicts");
  8573. + pkg_print_field(pkg, file, "Status");
  8574. + pkg_print_field(pkg, file, "Essential"); /* @@@@ should be removed in future release. */
  8575. + pkg_print_field(pkg, file, "Architecture");
  8576. + pkg_print_field(pkg, file, "Conffiles");
  8577. + pkg_print_field(pkg, file, "Installed-Time");
  8578. + fputs("\n", file);
  8579. +}
  8580. +
  8581. +void pkg_print_field(pkg_t *pkg, FILE *file, const char *field)
  8582. +{
  8583. + char *buff;
  8584. + if (strlen(field) < PKG_MINIMUM_FIELD_NAME_LEN) {
  8585. + fprintf(stderr, "%s: ERROR: Unknown field name: %s\n",
  8586. + __FUNCTION__, field);
  8587. + }
  8588. + buff = pkg_formatted_field(pkg, field);
  8589. + if (strlen(buff)>2) {
  8590. + fprintf(file, "%s", buff);
  8591. + fflush(file);
  8592. + }
  8593. + free(buff);
  8594. + return;
  8595. +}
  8596. +
  8597. +/*
  8598. + * libdpkg - Debian packaging suite library routines
  8599. + * vercmp.c - comparison of version numbers
  8600. + *
  8601. + * Copyright (C) 1995 Ian Jackson <iwj10@cus.cam.ac.uk>
  8602. + */
  8603. +int pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg)
  8604. +{
  8605. + int r;
  8606. +
  8607. + if (pkg->epoch > ref_pkg->epoch) {
  8608. + return 1;
  8609. + }
  8610. +
  8611. + if (pkg->epoch < ref_pkg->epoch) {
  8612. + return -1;
  8613. + }
  8614. +
  8615. + r = verrevcmp(pkg->version, ref_pkg->version);
  8616. + if (r) {
  8617. + return r;
  8618. + }
  8619. +
  8620. +#ifdef USE_DEBVERSION
  8621. + r = verrevcmp(pkg->revision, ref_pkg->revision);
  8622. + if (r) {
  8623. + return r;
  8624. + }
  8625. +
  8626. + r = verrevcmp(pkg->familiar_revision, ref_pkg->familiar_revision);
  8627. +#endif
  8628. +
  8629. + return r;
  8630. +}
  8631. +
  8632. +int verrevcmp(const char *val, const char *ref)
  8633. +{
  8634. + int vc, rc;
  8635. + long vl, rl;
  8636. + const char *vp, *rp;
  8637. + const char *vsep, *rsep;
  8638. +
  8639. + if (!val) val= "";
  8640. + if (!ref) ref= "";
  8641. + for (;;) {
  8642. + vp= val; while (*vp && !isdigit(*vp)) vp++;
  8643. + rp= ref; while (*rp && !isdigit(*rp)) rp++;
  8644. + for (;;) {
  8645. + vc= (val == vp) ? 0 : *val++;
  8646. + rc= (ref == rp) ? 0 : *ref++;
  8647. + if (!rc && !vc) break;
  8648. + if (vc && !isalpha(vc)) vc += 256; /* assumes ASCII character set */
  8649. + if (rc && !isalpha(rc)) rc += 256;
  8650. + if (vc != rc) return vc - rc;
  8651. + }
  8652. + val= vp;
  8653. + ref= rp;
  8654. + vl=0; if (isdigit(*vp)) vl= strtol(val,(char**)&val,10);
  8655. + rl=0; if (isdigit(*rp)) rl= strtol(ref,(char**)&ref,10);
  8656. + if (vl != rl) return vl - rl;
  8657. +
  8658. + vc = *val;
  8659. + rc = *ref;
  8660. + vsep = strchr(".-", vc);
  8661. + rsep = strchr(".-", rc);
  8662. + if (vsep && !rsep) return -1;
  8663. + if (!vsep && rsep) return +1;
  8664. +
  8665. + if (!*val && !*ref) return 0;
  8666. + if (!*val) return -1;
  8667. + if (!*ref) return +1;
  8668. + }
  8669. +}
  8670. +
  8671. +int pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op)
  8672. +{
  8673. + int r;
  8674. +
  8675. + r = pkg_compare_versions(it, ref);
  8676. +
  8677. + if (strcmp(op, "<=") == 0 || strcmp(op, "<") == 0) {
  8678. + return r <= 0;
  8679. + }
  8680. +
  8681. + if (strcmp(op, ">=") == 0 || strcmp(op, ">") == 0) {
  8682. + return r >= 0;
  8683. + }
  8684. +
  8685. + if (strcmp(op, "<<") == 0) {
  8686. + return r < 0;
  8687. + }
  8688. +
  8689. + if (strcmp(op, ">>") == 0) {
  8690. + return r > 0;
  8691. + }
  8692. +
  8693. + if (strcmp(op, "=") == 0) {
  8694. + return r == 0;
  8695. + }
  8696. +
  8697. + fprintf(stderr, "unknown operator: %s", op);
  8698. + return 0;
  8699. +}
  8700. +
  8701. +int pkg_name_version_and_architecture_compare(pkg_t *p1, pkg_t *p2)
  8702. +{
  8703. + const pkg_t *a = *(const pkg_t **)p1;
  8704. + const pkg_t *b = *(const pkg_t **)p2;
  8705. + int namecmp;
  8706. + int vercmp;
  8707. + if (!a->name || !b->name) {
  8708. + fprintf(stderr, "pkg_name_version_and_architecture_compare: a=%p a->name=%p b=%p b->name=%p\n",
  8709. + a, a->name, b, b->name);
  8710. + return 0;
  8711. + }
  8712. +
  8713. + namecmp = strcmp(a->name, b->name);
  8714. + if (namecmp)
  8715. + return namecmp;
  8716. + vercmp = pkg_compare_versions(a, b);
  8717. + if (vercmp)
  8718. + return vercmp;
  8719. + if (!a->arch_priority || !b->arch_priority) {
  8720. + fprintf(stderr, "pkg_name_version_and_architecture_compare: a=%p a->arch_priority=%i b=%p b->arch_priority=%i\n",
  8721. + a, a->arch_priority, b, b->arch_priority);
  8722. + return 0;
  8723. + }
  8724. + if (a->arch_priority > b->arch_priority)
  8725. + return 1;
  8726. + if (a->arch_priority < b->arch_priority)
  8727. + return -1;
  8728. + return 0;
  8729. +}
  8730. +
  8731. +int abstract_pkg_name_compare(abstract_pkg_t *p1, abstract_pkg_t *p2)
  8732. +{
  8733. + const abstract_pkg_t *a = *(const abstract_pkg_t **)p1;
  8734. + const abstract_pkg_t *b = *(const abstract_pkg_t **)p2;
  8735. + if (!a->name || !b->name) {
  8736. + fprintf(stderr, "abstract_pkg_name_compare: a=%p a->name=%p b=%p b->name=%p\n",
  8737. + a, a->name, b, b->name);
  8738. + return 0;
  8739. + }
  8740. + return strcmp(a->name, b->name);
  8741. +}
  8742. +
  8743. +
  8744. +char *pkg_version_str_alloc(pkg_t *pkg)
  8745. +{
  8746. + char *complete_version;
  8747. + char *epoch_str;
  8748. +#ifdef USE_DEBVERSION
  8749. + char *revision_str;
  8750. + char *familiar_revision_str;
  8751. +#endif
  8752. +
  8753. + if (pkg->epoch) {
  8754. + sprintf_alloc(&epoch_str, "%lu:", (unsigned long)pkg->epoch);
  8755. + } else {
  8756. + epoch_str = strdup("");
  8757. + }
  8758. +
  8759. +#ifdef USE_DEBVERSION
  8760. + if (pkg->revision && strlen(pkg->revision)) {
  8761. + sprintf_alloc(&revision_str, "-%s", pkg->revision);
  8762. + } else {
  8763. + revision_str = strdup("");
  8764. + }
  8765. +
  8766. + if (pkg->familiar_revision && strlen(pkg->familiar_revision)) {
  8767. + sprintf_alloc(&familiar_revision_str, "-fam%s", pkg->familiar_revision);
  8768. + } else {
  8769. + familiar_revision_str = strdup("");
  8770. + }
  8771. +#endif
  8772. +
  8773. +#ifdef USE_DEBVERSION
  8774. + sprintf_alloc(&complete_version, "%s%s%s%s",
  8775. + epoch_str, pkg->version, revision_str, familiar_revision_str);
  8776. +#else
  8777. + sprintf_alloc(&complete_version, "%s%s",
  8778. + epoch_str, pkg->version);
  8779. +#endif
  8780. +
  8781. + free(epoch_str);
  8782. +#ifdef USE_DEBVERSION
  8783. + free(revision_str);
  8784. + free(familiar_revision_str);
  8785. +#endif
  8786. +
  8787. + return complete_version;
  8788. +}
  8789. +
  8790. +str_list_t *pkg_get_installed_files(pkg_t *pkg)
  8791. +{
  8792. + int err;
  8793. + char *list_file_name = NULL;
  8794. + FILE *list_file = NULL;
  8795. + char *line;
  8796. + char *installed_file_name;
  8797. + int rootdirlen;
  8798. +
  8799. + pkg->installed_files_ref_cnt++;
  8800. +
  8801. + if (pkg->installed_files) {
  8802. + return pkg->installed_files;
  8803. + }
  8804. +
  8805. + pkg->installed_files = str_list_alloc();
  8806. + if (pkg->installed_files == NULL) {
  8807. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8808. + return NULL;
  8809. + }
  8810. +
  8811. + /* For uninstalled packages, get the file list firectly from the package.
  8812. + For installed packages, look at the package.list file in the database.
  8813. + */
  8814. + if (pkg->state_status == SS_NOT_INSTALLED || pkg->dest == NULL) {
  8815. + if (pkg->local_filename == NULL) {
  8816. + return pkg->installed_files;
  8817. + }
  8818. + /* XXX: CLEANUP: Maybe rewrite this to avoid using a temporary
  8819. + file. In other words, change deb_extract so that it can
  8820. + simply return the file list as a char *[] rather than
  8821. + insisting on writing in to a FILE * as it does now. */
  8822. + list_file = tmpfile();
  8823. + err = pkg_extract_data_file_names_to_stream(pkg, list_file);
  8824. + if (err) {
  8825. + fclose(list_file);
  8826. + fprintf(stderr, "%s: Error extracting file list from %s: %s\n",
  8827. + __FUNCTION__, pkg->local_filename, strerror(err));
  8828. + return pkg->installed_files;
  8829. + }
  8830. + rewind(list_file);
  8831. + } else {
  8832. + sprintf_alloc(&list_file_name, "%s/%s.list",
  8833. + pkg->dest->info_dir, pkg->name);
  8834. + if (! file_exists(list_file_name)) {
  8835. + free(list_file_name);
  8836. + return pkg->installed_files;
  8837. + }
  8838. +
  8839. + list_file = fopen(list_file_name, "r");
  8840. + if (list_file == NULL) {
  8841. + fprintf(stderr, "WARNING: Cannot open %s: %s\n",
  8842. + list_file_name, strerror(errno));
  8843. + free(list_file_name);
  8844. + return pkg->installed_files;
  8845. + }
  8846. + free(list_file_name);
  8847. + }
  8848. +
  8849. + rootdirlen = strlen( pkg->dest->root_dir );
  8850. + while (1) {
  8851. + char *file_name;
  8852. +
  8853. + line = file_read_line_alloc(list_file);
  8854. + if (line == NULL) {
  8855. + break;
  8856. + }
  8857. + str_chomp(line);
  8858. + file_name = line;
  8859. +
  8860. + /* Take pains to avoid uglies like "/./" in the middle of file_name. */
  8861. + if( strncmp( pkg->dest->root_dir,
  8862. + file_name,
  8863. + rootdirlen ) ) {
  8864. + if (*file_name == '.') {
  8865. + file_name++;
  8866. + }
  8867. + if (*file_name == '/') {
  8868. + file_name++;
  8869. + }
  8870. +
  8871. + /* Freed in pkg_free_installed_files */
  8872. + sprintf_alloc(&installed_file_name, "%s%s", pkg->dest->root_dir, file_name);
  8873. + } else {
  8874. + // already contains root_dir as header -> ABSOLUTE
  8875. + sprintf_alloc(&installed_file_name, "%s", file_name);
  8876. + }
  8877. + str_list_append(pkg->installed_files, installed_file_name);
  8878. + free(line);
  8879. + }
  8880. +
  8881. + fclose(list_file);
  8882. +
  8883. + return pkg->installed_files;
  8884. +}
  8885. +
  8886. +/* XXX: CLEANUP: This function and it's counterpart,
  8887. + (pkg_get_installed_files), do not match our init/deinit naming
  8888. + convention. Nor the alloc/free convention. But, then again, neither
  8889. + of these conventions currrently fit the way these two functions
  8890. + work. */
  8891. +int pkg_free_installed_files(pkg_t *pkg)
  8892. +{
  8893. + str_list_elt_t *iter;
  8894. +
  8895. + pkg->installed_files_ref_cnt--;
  8896. + if (pkg->installed_files_ref_cnt > 0) {
  8897. + return 0;
  8898. + }
  8899. +
  8900. + if (pkg->installed_files) {
  8901. +
  8902. + for (iter = pkg->installed_files->head; iter; iter = iter->next) {
  8903. + /* malloced in pkg_get_installed_files */
  8904. + free (iter->data);
  8905. + iter->data = NULL;
  8906. + }
  8907. +
  8908. + str_list_deinit(pkg->installed_files);
  8909. + }
  8910. +
  8911. + pkg->installed_files = NULL;
  8912. +
  8913. + return 0;
  8914. +}
  8915. +
  8916. +int pkg_remove_installed_files_list(ipkg_conf_t *conf, pkg_t *pkg)
  8917. +{
  8918. + int err;
  8919. + char *list_file_name;
  8920. +
  8921. + //I don't think pkg_free_installed_files should be called here. Jamey
  8922. + //pkg_free_installed_files(pkg);
  8923. +
  8924. + sprintf_alloc(&list_file_name, "%s/%s.list",
  8925. + pkg->dest->info_dir, pkg->name);
  8926. + if (!conf->noaction) {
  8927. + err = unlink(list_file_name);
  8928. + free(list_file_name);
  8929. +
  8930. + if (err) {
  8931. + return errno;
  8932. + }
  8933. + }
  8934. + return 0;
  8935. +}
  8936. +
  8937. +conffile_t *pkg_get_conffile(pkg_t *pkg, const char *file_name)
  8938. +{
  8939. + conffile_list_elt_t *iter;
  8940. + conffile_t *conffile;
  8941. +
  8942. + if (pkg == NULL) {
  8943. + return NULL;
  8944. + }
  8945. +
  8946. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  8947. + conffile = iter->data;
  8948. +
  8949. + if (strcmp(conffile->name, file_name) == 0) {
  8950. + return conffile;
  8951. + }
  8952. + }
  8953. +
  8954. + return NULL;
  8955. +}
  8956. +
  8957. +int pkg_run_script(ipkg_conf_t *conf, pkg_t *pkg,
  8958. + const char *script, const char *args)
  8959. +{
  8960. + int err;
  8961. + char *path;
  8962. + char *cmd;
  8963. +
  8964. + /* XXX: FEATURE: When conf->offline_root is set, we should run the
  8965. + maintainer script within a chroot environment. */
  8966. +
  8967. + /* Installed packages have scripts in pkg->dest->info_dir, uninstalled packages
  8968. + have scripts in pkg->tmp_unpack_dir. */
  8969. + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) {
  8970. + if (pkg->dest == NULL) {
  8971. + fprintf(stderr, "%s: ERROR: installed package %s has a NULL dest\n",
  8972. + __FUNCTION__, pkg->name);
  8973. + return EINVAL;
  8974. + }
  8975. + sprintf_alloc(&path, "%s/%s.%s", pkg->dest->info_dir, pkg->name, script);
  8976. + } else {
  8977. + if (pkg->tmp_unpack_dir == NULL) {
  8978. + fprintf(stderr, "%s: ERROR: uninstalled package %s has a NULL tmp_unpack_dir\n",
  8979. + __FUNCTION__, pkg->name);
  8980. + return EINVAL;
  8981. + }
  8982. + sprintf_alloc(&path, "%s/%s", pkg->tmp_unpack_dir, script);
  8983. + }
  8984. +
  8985. + ipkg_message(conf, IPKG_INFO, "Running script %s\n", path);
  8986. + if (conf->noaction) return 0;
  8987. +
  8988. + /* XXX: CLEANUP: There must be a better way to handle maintainer
  8989. + scripts when running with offline_root mode and/or a dest other
  8990. + than '/'. I've been playing around with some clever chroot
  8991. + tricks and I might come up with something workable. */
  8992. + if (conf->offline_root) {
  8993. + setenv("IPKG_OFFLINE_ROOT", conf->offline_root, 1);
  8994. + }
  8995. +
  8996. + setenv("PKG_ROOT",
  8997. + pkg->dest ? pkg->dest->root_dir : conf->default_dest->root_dir, 1);
  8998. +
  8999. + if (! file_exists(path)) {
  9000. + free(path);
  9001. + return 0;
  9002. + }
  9003. +
  9004. + if (conf->offline_root) {
  9005. + fprintf(stderr, "(offline root mode: not running %s.%s)\n", pkg->name, script);
  9006. + free(path);
  9007. + return 0;
  9008. + }
  9009. +
  9010. + sprintf_alloc(&cmd, "%s %s", path, args);
  9011. + free(path);
  9012. +
  9013. + err = xsystem(cmd);
  9014. + free(cmd);
  9015. +
  9016. + if (err) {
  9017. + fprintf(stderr, "%s script returned status %d\n", script, err);
  9018. + return err;
  9019. + }
  9020. +
  9021. + return 0;
  9022. +}
  9023. +
  9024. +char *pkg_state_want_to_str(pkg_state_want_t sw)
  9025. +{
  9026. + int i;
  9027. +
  9028. + for (i=0; i < ARRAY_SIZE(pkg_state_want_map); i++) {
  9029. + if (pkg_state_want_map[i].value == sw) {
  9030. + return strdup(pkg_state_want_map[i].str);
  9031. + }
  9032. + }
  9033. +
  9034. + fprintf(stderr, "%s: ERROR: Illegal value for state_want: %d\n",
  9035. + __FUNCTION__, sw);
  9036. + return strdup("<STATE_WANT_UNKNOWN>");
  9037. +}
  9038. +
  9039. +pkg_state_want_t pkg_state_want_from_str(char *str)
  9040. +{
  9041. + int i;
  9042. +
  9043. + for (i=0; i < ARRAY_SIZE(pkg_state_want_map); i++) {
  9044. + if (strcmp(str, pkg_state_want_map[i].str) == 0) {
  9045. + return pkg_state_want_map[i].value;
  9046. + }
  9047. + }
  9048. +
  9049. + fprintf(stderr, "%s: ERROR: Illegal value for state_want string: %s\n",
  9050. + __FUNCTION__, str);
  9051. + return SW_UNKNOWN;
  9052. +}
  9053. +
  9054. +char *pkg_state_flag_to_str(pkg_state_flag_t sf)
  9055. +{
  9056. + int i;
  9057. + int len = 3; /* ok\000 is minimum */
  9058. + char *str = NULL;
  9059. +
  9060. + /* clear the temporary flags before converting to string */
  9061. + sf &= SF_NONVOLATILE_FLAGS;
  9062. +
  9063. + if (sf == 0) {
  9064. + return strdup("ok");
  9065. + } else {
  9066. +
  9067. + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
  9068. + if (sf & pkg_state_flag_map[i].value) {
  9069. + len += strlen(pkg_state_flag_map[i].str) + 1;
  9070. + }
  9071. + }
  9072. + str = malloc(len);
  9073. + if ( str == NULL ) {
  9074. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  9075. + return NULL;
  9076. + }
  9077. + str[0] = 0;
  9078. + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
  9079. + if (sf & pkg_state_flag_map[i].value) {
  9080. + strcat(str, pkg_state_flag_map[i].str);
  9081. + strcat(str, ",");
  9082. + }
  9083. + }
  9084. + len = strlen(str);
  9085. + str[len-1] = 0; /* squash last comma */
  9086. + return str;
  9087. + }
  9088. +}
  9089. +
  9090. +pkg_state_flag_t pkg_state_flag_from_str(char *str)
  9091. +{
  9092. + int i;
  9093. + int sf = SF_OK;
  9094. +
  9095. + if (strcmp(str, "ok") == 0) {
  9096. + return SF_OK;
  9097. + }
  9098. + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
  9099. + const char *sfname = pkg_state_flag_map[i].str;
  9100. + int sfname_len = strlen(sfname);
  9101. + if (strncmp(str, sfname, sfname_len) == 0) {
  9102. + sf |= pkg_state_flag_map[i].value;
  9103. + str += sfname_len;
  9104. + if (str[0] == ',') {
  9105. + str++;
  9106. + } else {
  9107. + break;
  9108. + }
  9109. + }
  9110. + }
  9111. +
  9112. + return sf;
  9113. +}
  9114. +
  9115. +char *pkg_state_status_to_str(pkg_state_status_t ss)
  9116. +{
  9117. + int i;
  9118. +
  9119. + for (i=0; i < ARRAY_SIZE(pkg_state_status_map); i++) {
  9120. + if (pkg_state_status_map[i].value == ss) {
  9121. + return strdup(pkg_state_status_map[i].str);
  9122. + }
  9123. + }
  9124. +
  9125. + fprintf(stderr, "%s: ERROR: Illegal value for state_status: %d\n",
  9126. + __FUNCTION__, ss);
  9127. + return strdup("<STATE_STATUS_UNKNOWN>");
  9128. +}
  9129. +
  9130. +pkg_state_status_t pkg_state_status_from_str(char *str)
  9131. +{
  9132. + int i;
  9133. +
  9134. + for (i=0; i < ARRAY_SIZE(pkg_state_status_map); i++) {
  9135. + if (strcmp(str, pkg_state_status_map[i].str) == 0) {
  9136. + return pkg_state_status_map[i].value;
  9137. + }
  9138. + }
  9139. +
  9140. + fprintf(stderr, "%s: ERROR: Illegal value for state_status string: %s\n",
  9141. + __FUNCTION__, str);
  9142. + return SS_NOT_INSTALLED;
  9143. +}
  9144. +
  9145. +int pkg_arch_supported(ipkg_conf_t *conf, pkg_t *pkg)
  9146. +{
  9147. + nv_pair_list_elt_t *l;
  9148. +
  9149. + if (!pkg->architecture)
  9150. + return 1;
  9151. +
  9152. + l = conf->arch_list.head;
  9153. +
  9154. + while (l) {
  9155. + nv_pair_t *nv = l->data;
  9156. + if (strcmp(nv->name, pkg->architecture) == 0) {
  9157. + ipkg_message(conf, IPKG_DEBUG, "arch %s (priority %s) supported for pkg %s\n", nv->name, nv->value, pkg->name);
  9158. + return 1;
  9159. + }
  9160. + l = l->next;
  9161. + }
  9162. +
  9163. + ipkg_message(conf, IPKG_DEBUG, "arch %s unsupported for pkg %s\n", pkg->architecture, pkg->name);
  9164. + return 0;
  9165. +}
  9166. +
  9167. +int pkg_get_arch_priority(ipkg_conf_t *conf, const char *archname)
  9168. +{
  9169. + nv_pair_list_elt_t *l;
  9170. +
  9171. + l = conf->arch_list.head;
  9172. +
  9173. + while (l) {
  9174. + nv_pair_t *nv = l->data;
  9175. + if (strcmp(nv->name, archname) == 0) {
  9176. + int priority = strtol(nv->value, NULL, 0);
  9177. + return priority;
  9178. + }
  9179. + l = l->next;
  9180. + }
  9181. + return 0;
  9182. +}
  9183. +
  9184. +int pkg_info_preinstall_check(ipkg_conf_t *conf)
  9185. +{
  9186. + int i;
  9187. + hash_table_t *pkg_hash = &conf->pkg_hash;
  9188. + pkg_vec_t *available_pkgs = pkg_vec_alloc();
  9189. + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
  9190. +
  9191. + ipkg_message(conf, IPKG_INFO, "pkg_info_preinstall_check: updating arch priority for each package\n");
  9192. + pkg_hash_fetch_available(pkg_hash, available_pkgs);
  9193. + /* update arch_priority for each package */
  9194. + for (i = 0; i < available_pkgs->len; i++) {
  9195. + pkg_t *pkg = available_pkgs->pkgs[i];
  9196. + int arch_priority = 1;
  9197. + if (!pkg)
  9198. + continue;
  9199. + // ipkg_message(conf, IPKG_DEBUG2, " package %s version=%s arch=%p:", pkg->name, pkg->version, pkg->architecture);
  9200. + if (pkg->architecture)
  9201. + arch_priority = pkg_get_arch_priority(conf, pkg->architecture);
  9202. + else
  9203. + ipkg_message(conf, IPKG_ERROR, "pkg_info_preinstall_check: no architecture for package %s\n", pkg->name);
  9204. + // ipkg_message(conf, IPKG_DEBUG2, "%s arch_priority=%d\n", pkg->architecture, arch_priority);
  9205. + pkg->arch_priority = arch_priority;
  9206. + }
  9207. +
  9208. + for (i = 0; i < available_pkgs->len; i++) {
  9209. + pkg_t *pkg = available_pkgs->pkgs[i];
  9210. + if (!pkg->arch_priority && (pkg->state_flag || (pkg->state_want != SW_UNKNOWN))) {
  9211. + /* clear flags and want for any uninstallable package */
  9212. + ipkg_message(conf, IPKG_NOTICE, "Clearing state_want and state_flag for pkg=%s (arch_priority=%d flag=%d want=%d)\n",
  9213. + pkg->name, pkg->arch_priority, pkg->state_flag, pkg->state_want);
  9214. + pkg->state_want = SW_UNKNOWN;
  9215. + pkg->state_flag = 0;
  9216. + }
  9217. + }
  9218. + pkg_vec_free(available_pkgs);
  9219. +
  9220. + /* update the file owner data structure */
  9221. + ipkg_message(conf, IPKG_INFO, "pkg_info_preinstall_check: update file owner list\n");
  9222. + pkg_hash_fetch_all_installed(pkg_hash, installed_pkgs);
  9223. + for (i = 0; i < installed_pkgs->len; i++) {
  9224. + pkg_t *pkg = installed_pkgs->pkgs[i];
  9225. + str_list_t *installed_files = pkg_get_installed_files(pkg); /* this causes installed_files to be cached */
  9226. + str_list_elt_t *iter;
  9227. + if (installed_files == NULL) {
  9228. + ipkg_message(conf, IPKG_ERROR, "No installed files for pkg %s\n", pkg->name);
  9229. + break;
  9230. + }
  9231. + for (iter = installed_files->head; iter; iter = iter->next) {
  9232. + char *installed_file = iter->data;
  9233. + // ipkg_message(conf, IPKG_DEBUG2, "pkg %s: file=%s\n", pkg->name, installed_file);
  9234. + file_hash_set_file_owner(conf, installed_file, pkg);
  9235. + }
  9236. + }
  9237. + pkg_vec_free(installed_pkgs);
  9238. +
  9239. + return 0;
  9240. +}
  9241. +
  9242. +struct pkg_write_filelist_data {
  9243. + ipkg_conf_t *conf;
  9244. + pkg_t *pkg;
  9245. + FILE *stream;
  9246. +};
  9247. +
  9248. +void pkg_write_filelist_helper(const char *key, void *entry_, void *data_)
  9249. +{
  9250. + struct pkg_write_filelist_data *data = data_;
  9251. + pkg_t *entry = entry_;
  9252. + if (entry == data->pkg) {
  9253. + fprintf(data->stream, "%s\n", key);
  9254. + }
  9255. +}
  9256. +
  9257. +int pkg_write_filelist(ipkg_conf_t *conf, pkg_t *pkg)
  9258. +{
  9259. + struct pkg_write_filelist_data data;
  9260. + char *list_file_name = NULL;
  9261. + int err = 0;
  9262. +
  9263. + if (!pkg) {
  9264. + ipkg_message(conf, IPKG_ERROR, "Null pkg\n");
  9265. + return -EINVAL;
  9266. + }
  9267. + ipkg_message(conf, IPKG_INFO,
  9268. + " creating %s.list file\n", pkg->name);
  9269. + sprintf_alloc(&list_file_name, "%s/%s.list", pkg->dest->info_dir, pkg->name);
  9270. + if (!list_file_name) {
  9271. + ipkg_message(conf, IPKG_ERROR, "Failed to alloc list_file_name\n");
  9272. + return -ENOMEM;
  9273. + }
  9274. + ipkg_message(conf, IPKG_INFO,
  9275. + " creating %s file for pkg %s\n", list_file_name, pkg->name);
  9276. + data.stream = fopen(list_file_name, "w");
  9277. + if (!data.stream) {
  9278. + ipkg_message(conf, IPKG_ERROR, "Could not open %s for writing: %s\n",
  9279. + list_file_name, strerror(errno));
  9280. + return errno;
  9281. + }
  9282. + data.pkg = pkg;
  9283. + data.conf = conf;
  9284. + hash_table_foreach(&conf->file_hash, pkg_write_filelist_helper, &data);
  9285. + fclose(data.stream);
  9286. + free(list_file_name);
  9287. +
  9288. + return err;
  9289. +}
  9290. +
  9291. +int pkg_write_changed_filelists(ipkg_conf_t *conf)
  9292. +{
  9293. + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
  9294. + hash_table_t *pkg_hash = &conf->pkg_hash;
  9295. + int i;
  9296. + int err;
  9297. + if (conf->noaction)
  9298. + return 0;
  9299. +
  9300. + ipkg_message(conf, IPKG_INFO, "%s: saving changed filelists\n", __FUNCTION__);
  9301. + pkg_hash_fetch_all_installed(pkg_hash, installed_pkgs);
  9302. + for (i = 0; i < installed_pkgs->len; i++) {
  9303. + pkg_t *pkg = installed_pkgs->pkgs[i];
  9304. + if (pkg->state_flag & SF_FILELIST_CHANGED) {
  9305. + ipkg_message(conf, IPKG_DEBUG, "Calling pkg_write_filelist for pkg=%s from %s\n", pkg->name, __FUNCTION__);
  9306. + err = pkg_write_filelist(conf, pkg);
  9307. + if (err)
  9308. + ipkg_message(conf, IPKG_NOTICE, "pkg_write_filelist pkg=%s returned %d\n", pkg->name, err);
  9309. + }
  9310. + }
  9311. + return 0;
  9312. +}
  9313. diff -Nur busybox-1.19.4.orig/archival/libipkg/pkg.h busybox-1.19.4/archival/libipkg/pkg.h
  9314. --- busybox-1.19.4.orig/archival/libipkg/pkg.h 1970-01-01 01:00:00.000000000 +0100
  9315. +++ busybox-1.19.4/archival/libipkg/pkg.h 2012-03-17 00:58:08.197100679 +0100
  9316. @@ -0,0 +1,229 @@
  9317. +/* pkg.h - the itsy package management system
  9318. +
  9319. + Carl D. Worth
  9320. +
  9321. + Copyright (C) 2001 University of Southern California
  9322. +
  9323. + This program is free software; you can redistribute it and/or
  9324. + modify it under the terms of the GNU General Public License as
  9325. + published by the Free Software Foundation; either version 2, or (at
  9326. + your option) any later version.
  9327. +
  9328. + This program is distributed in the hope that it will be useful, but
  9329. + WITHOUT ANY WARRANTY; without even the implied warranty of
  9330. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  9331. + General Public License for more details.
  9332. +*/
  9333. +
  9334. +#ifndef PKG_H
  9335. +#define PKG_H
  9336. +
  9337. +#include <sys/types.h>
  9338. +#include <sys/stat.h>
  9339. +#include <unistd.h>
  9340. +
  9341. +#include "pkg_vec.h"
  9342. +#include "str_list.h"
  9343. +#include "pkg_src.h"
  9344. +#include "pkg_dest.h"
  9345. +#include "ipkg_conf.h"
  9346. +#include "conffile_list.h"
  9347. +
  9348. +struct ipkg_conf;
  9349. +
  9350. +/* I think "Size" is currently the shortest field name */
  9351. +#define PKG_MINIMUM_FIELD_NAME_LEN 4
  9352. +
  9353. +enum pkg_state_want
  9354. +{
  9355. + SW_UNKNOWN = 1,
  9356. + SW_INSTALL,
  9357. + SW_DEINSTALL,
  9358. + SW_PURGE,
  9359. + SW_LAST_STATE_WANT
  9360. +};
  9361. +typedef enum pkg_state_want pkg_state_want_t;
  9362. +
  9363. +enum pkg_state_flag
  9364. +{
  9365. + SF_OK = 0,
  9366. + SF_REINSTREQ = 1,
  9367. + SF_HOLD = 2, /* do not upgrade version */
  9368. + SF_REPLACE = 4, /* replace this package */
  9369. + SF_NOPRUNE = 8, /* do not remove obsolete files */
  9370. + SF_PREFER = 16, /* prefer this version */
  9371. + SF_OBSOLETE = 32, /* old package in upgrade pair */
  9372. + SF_MARKED = 64, /* temporary mark */
  9373. + SF_FILELIST_CHANGED = 128, /* needs filelist written */
  9374. + SF_USER = 256,
  9375. + SF_LAST_STATE_FLAG
  9376. +};
  9377. +typedef enum pkg_state_flag pkg_state_flag_t;
  9378. +#define SF_NONVOLATILE_FLAGS (SF_HOLD|SF_NOPRUNE|SF_PREFER|SF_OBSOLETE|SF_USER)
  9379. +
  9380. +enum pkg_state_status
  9381. +{
  9382. + SS_NOT_INSTALLED = 1,
  9383. + SS_UNPACKED,
  9384. + SS_HALF_CONFIGURED,
  9385. + SS_INSTALLED,
  9386. + SS_HALF_INSTALLED,
  9387. + SS_CONFIG_FILES,
  9388. + SS_POST_INST_FAILED,
  9389. + SS_REMOVAL_FAILED,
  9390. + SS_LAST_STATE_STATUS
  9391. +};
  9392. +typedef enum pkg_state_status pkg_state_status_t;
  9393. +
  9394. +struct abstract_pkg{
  9395. + char * name;
  9396. + int dependencies_checked;
  9397. + pkg_vec_t * pkgs;
  9398. + pkg_state_status_t state_status;
  9399. + pkg_state_flag_t state_flag;
  9400. + struct abstract_pkg ** depended_upon_by; /* @@@@ this should be abstract_pkg_vec_t -Jamey */
  9401. + abstract_pkg_vec_t * provided_by;
  9402. + abstract_pkg_vec_t * replaced_by;
  9403. +};
  9404. +
  9405. +#include "pkg_depends.h"
  9406. +
  9407. +/* XXX: CLEANUP: I'd like to clean up pkg_t in several ways:
  9408. +
  9409. + The 3 version fields should go into a single version struct. (This
  9410. + is especially important since, currently, pkg->version can easily
  9411. + be mistaken for pkg_verson_str_alloc(pkg) although they are very
  9412. + distinct. This has been the source of multiple bugs.
  9413. +
  9414. + The 3 state fields could possibly also go into their own struct.
  9415. +
  9416. + All fields which deal with lists of packages, (Depends,
  9417. + Pre-Depends, Provides, Suggests, Recommends, Enhances), should each
  9418. + be handled by a single struct in pkg_t
  9419. +
  9420. + All string fields for which there is a small set of possible
  9421. + values, (section, maintainer, architecture, maybe version?), that
  9422. + are reused among different packages -- for all such packages we
  9423. + should move from "char *"s to some atom datatype to share data
  9424. + storage and use less memory. We might even do reference counting,
  9425. + but probably not since most often we only create new pkg_t structs,
  9426. + we don't often free them. */
  9427. +struct pkg
  9428. +{
  9429. + char *name;
  9430. + unsigned long epoch;
  9431. + char *version;
  9432. + char *revision;
  9433. + char *familiar_revision;
  9434. + pkg_src_t *src;
  9435. + pkg_dest_t *dest;
  9436. + char *architecture;
  9437. + char *section;
  9438. + char *maintainer;
  9439. + char *description;
  9440. + pkg_state_want_t state_want;
  9441. + pkg_state_flag_t state_flag;
  9442. + pkg_state_status_t state_status;
  9443. + char **depends_str;
  9444. + int depends_count;
  9445. + char **pre_depends_str;
  9446. + int pre_depends_count;
  9447. + char **recommends_str;
  9448. + int recommends_count;
  9449. + char **suggests_str;
  9450. + int suggests_count;
  9451. + compound_depend_t * depends;
  9452. +
  9453. + /* Abhaya: new conflicts */
  9454. + char **conflicts_str;
  9455. + compound_depend_t * conflicts;
  9456. + int conflicts_count;
  9457. +
  9458. + char **replaces_str;
  9459. + int replaces_count;
  9460. + abstract_pkg_t ** replaces;
  9461. +
  9462. + char **provides_str;
  9463. + int provides_count;
  9464. + abstract_pkg_t ** provides;
  9465. +
  9466. + abstract_pkg_t *parent;
  9467. +
  9468. + pkg_t *old_pkg; /* during upgrade, points from installee to previously installed */
  9469. +
  9470. + char *filename;
  9471. + char *local_filename;
  9472. + char *url;
  9473. + char *tmp_unpack_dir;
  9474. + char *md5sum;
  9475. + char *size;
  9476. + char *installed_size;
  9477. + char *priority;
  9478. + char *source;
  9479. + conffile_list_t conffiles;
  9480. + time_t installed_time;
  9481. + /* As pointer for lazy evaluation */
  9482. + str_list_t *installed_files;
  9483. + /* XXX: CLEANUP: I'd like to perhaps come up with a better
  9484. + mechanism to avoid the problem here, (which is that the
  9485. + installed_files list was being freed from an inner loop while
  9486. + still being used within an outer loop. */
  9487. + int installed_files_ref_cnt;
  9488. + int essential;
  9489. + int arch_priority;
  9490. +/* Adding this flag, to "force" ipkg to choose a "provided_by_hand" package, if there are multiple choice */
  9491. + int provided_by_hand;
  9492. +};
  9493. +
  9494. +pkg_t *pkg_new(void);
  9495. +int pkg_init(pkg_t *pkg);
  9496. +void pkg_deinit(pkg_t *pkg);
  9497. +int pkg_init_from_file(pkg_t *pkg, const char *filename);
  9498. +abstract_pkg_t *abstract_pkg_new(void);
  9499. +int abstract_pkg_init(abstract_pkg_t *ab_pkg);
  9500. +
  9501. +/*
  9502. + * merges fields from newpkg into oldpkg.
  9503. + * Forcibly sets oldpkg state_status, state_want and state_flags if set_status is nonzero
  9504. + */
  9505. +int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status);
  9506. +
  9507. +char *pkg_version_str_alloc(pkg_t *pkg);
  9508. +
  9509. +int pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg);
  9510. +int pkg_name_version_and_architecture_compare(pkg_t *a, pkg_t *b);
  9511. +int abstract_pkg_name_compare(abstract_pkg_t *a, abstract_pkg_t *b);
  9512. +
  9513. +char * pkg_formatted_info(pkg_t *pkg );
  9514. +char * pkg_formatted_field(pkg_t *pkg, const char *field );
  9515. +
  9516. +void set_flags_from_control(ipkg_conf_t *conf, pkg_t *pkg);
  9517. +
  9518. +void pkg_print_info(pkg_t *pkg, FILE *file);
  9519. +void pkg_print_status(pkg_t * pkg, FILE * file);
  9520. +void pkg_print_field(pkg_t *pkg, FILE *file, const char *field);
  9521. +str_list_t *pkg_get_installed_files(pkg_t *pkg);
  9522. +int pkg_free_installed_files(pkg_t *pkg);
  9523. +int pkg_remove_installed_files_list(ipkg_conf_t *conf, pkg_t *pkg);
  9524. +conffile_t *pkg_get_conffile(pkg_t *pkg, const char *file_name);
  9525. +int pkg_run_script(struct ipkg_conf *conf, pkg_t *pkg,
  9526. + const char *script, const char *args);
  9527. +
  9528. +/* enum mappings */
  9529. +char *pkg_state_want_to_str(pkg_state_want_t sw);
  9530. +pkg_state_want_t pkg_state_want_from_str(char *str);
  9531. +char *pkg_state_flag_to_str(pkg_state_flag_t sf);
  9532. +pkg_state_flag_t pkg_state_flag_from_str(char *str);
  9533. +char *pkg_state_status_to_str(pkg_state_status_t ss);
  9534. +pkg_state_status_t pkg_state_status_from_str(char *str);
  9535. +
  9536. +int pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op);
  9537. +
  9538. +int pkg_arch_supported(ipkg_conf_t *conf, pkg_t *pkg);
  9539. +int pkg_info_preinstall_check(ipkg_conf_t *conf);
  9540. +int pkg_free_installed_files(pkg_t *pkg);
  9541. +
  9542. +int pkg_write_filelist(ipkg_conf_t *conf, pkg_t *pkg);
  9543. +int pkg_write_changed_filelists(ipkg_conf_t *conf);
  9544. +
  9545. +#endif
  9546. diff -Nur busybox-1.19.4.orig/archival/libipkg/pkg_depends.c busybox-1.19.4/archival/libipkg/pkg_depends.c
  9547. --- busybox-1.19.4.orig/archival/libipkg/pkg_depends.c 1970-01-01 01:00:00.000000000 +0100
  9548. +++ busybox-1.19.4/archival/libipkg/pkg_depends.c 2012-03-17 00:58:08.197100679 +0100
  9549. @@ -0,0 +1,1032 @@
  9550. +/* pkg_depends.c - the itsy package management system
  9551. +
  9552. + Steven M. Ayer
  9553. +
  9554. + Copyright (C) 2002 Compaq Computer Corporation
  9555. +
  9556. + This program is free software; you can redistribute it and/or
  9557. + modify it under the terms of the GNU General Public License as
  9558. + published by the Free Software Foundation; either version 2, or (at
  9559. + your option) any later version.
  9560. +
  9561. + This program is distributed in the hope that it will be useful, but
  9562. + WITHOUT ANY WARRANTY; without even the implied warranty of
  9563. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  9564. + General Public License for more details.
  9565. +*/
  9566. +
  9567. +#include "ipkg.h"
  9568. +#include <errno.h>
  9569. +#include <ctype.h>
  9570. +
  9571. +#include "pkg.h"
  9572. +#include "ipkg_utils.h"
  9573. +#include "pkg_hash.h"
  9574. +#include "ipkg_message.h"
  9575. +#include "pkg_parse.h"
  9576. +#include "hash_table.h"
  9577. +
  9578. +static int parseDepends(compound_depend_t *compound_depend, hash_table_t * hash, char * depend_str);
  9579. +static depend_t * depend_init(void);
  9580. +static void depend_deinit(depend_t *d);
  9581. +static char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx);
  9582. +static char ** merge_unresolved(char ** oldstuff, char ** newstuff);
  9583. +static int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg);
  9584. +int is_pkg_a_replaces(pkg_t *pkg_scout,pkg_t *pkg);
  9585. +
  9586. +static int pkg_installed_and_constraint_satisfied(pkg_t *pkg, void *cdata)
  9587. +{
  9588. + depend_t *depend = (depend_t *)cdata;
  9589. + if ((pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) && version_constraints_satisfied(depend, pkg))
  9590. + return 1;
  9591. + else
  9592. + return 0;
  9593. +}
  9594. +
  9595. +static int pkg_constraint_satisfied(pkg_t *pkg, void *cdata)
  9596. +{
  9597. + depend_t *depend = (depend_t *)cdata;
  9598. +#if 0
  9599. + pkg_t * temp = pkg_new();
  9600. + int comparison;
  9601. + parseVersion(temp, depend->version);
  9602. + comparison = pkg_compare_versions(pkg, temp);
  9603. + free(temp);
  9604. +
  9605. + fprintf(stderr, "%s: pkg=%s pkg->version=%s constraint=%p type=%d version=%s comparison=%d satisfied=%d\n",
  9606. + __FUNCTION__, pkg->name, pkg->version,
  9607. + depend, depend->constraint, depend->version,
  9608. + comparison, version_constraints_satisfied(depend, pkg));
  9609. +#endif
  9610. + if (version_constraints_satisfied(depend, pkg))
  9611. + return 1;
  9612. + else
  9613. + return 0;
  9614. +}
  9615. +
  9616. +/* returns ndependences or negative error value */
  9617. +int pkg_hash_fetch_unsatisfied_dependencies(ipkg_conf_t *conf, pkg_t * pkg,
  9618. + pkg_vec_t *unsatisfied, char *** unresolved)
  9619. +{
  9620. + pkg_t * satisfier_entry_pkg;
  9621. + register int i, j, k, l;
  9622. + int count, found;
  9623. + char ** the_lost;
  9624. + abstract_pkg_t * ab_pkg;
  9625. +
  9626. + /*
  9627. + * this is a setup to check for redundant/cyclic dependency checks,
  9628. + * which are marked at the abstract_pkg level
  9629. + */
  9630. + if (!(ab_pkg = pkg->parent)) {
  9631. + fprintf(stderr, "%s:%d: something terribly wrong with pkg %s\n", __FUNCTION__, __LINE__, pkg->name);
  9632. + *unresolved = NULL;
  9633. + return 0;
  9634. + }
  9635. + if (ab_pkg->dependencies_checked) { /* avoid duplicate or cyclic checks */
  9636. + *unresolved = NULL;
  9637. + return 0;
  9638. + } else {
  9639. + ab_pkg->dependencies_checked = 1; /* mark it for subsequent visits */
  9640. + }
  9641. + /**/
  9642. +
  9643. + count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count;
  9644. + if (!count){
  9645. + *unresolved = NULL;
  9646. + return 0;
  9647. + }
  9648. +
  9649. + the_lost = NULL;
  9650. +
  9651. + /* foreach dependency */
  9652. + for (i = 0; i < count; i++) {
  9653. + compound_depend_t * compound_depend = &pkg->depends[i];
  9654. + depend_t ** possible_satisfiers = compound_depend->possibilities;;
  9655. + found = 0;
  9656. + satisfier_entry_pkg = NULL;
  9657. +
  9658. + if (compound_depend->type == GREEDY_DEPEND) {
  9659. + /* foreach possible satisfier */
  9660. + for (j = 0; j < compound_depend->possibility_count; j++) {
  9661. + /* foreach provided_by, which includes the abstract_pkg itself */
  9662. + abstract_pkg_t *abpkg = possible_satisfiers[j]->pkg;
  9663. + abstract_pkg_vec_t *ab_provider_vec = abpkg->provided_by;
  9664. + int nposs = ab_provider_vec->len;
  9665. + abstract_pkg_t **ab_providers = ab_provider_vec->pkgs;
  9666. + for (l = 0; l < nposs; l++) {
  9667. + pkg_vec_t *test_vec = ab_providers[l]->pkgs;
  9668. + /* if no depends on this one, try the first package that Provides this one */
  9669. + if (!test_vec){ /* no pkg_vec hooked up to the abstract_pkg! (need another feed?) */
  9670. + continue;
  9671. + }
  9672. +
  9673. + /* cruise this possiblity's pkg_vec looking for an installed version */
  9674. + for (k = 0; k < test_vec->len; k++) {
  9675. + pkg_t *pkg_scout = test_vec->pkgs[k];
  9676. + /* not installed, and not already known about? */
  9677. + if ((pkg_scout->state_want != SW_INSTALL)
  9678. + && !pkg_scout->parent->dependencies_checked
  9679. + && !is_pkg_in_pkg_vec(unsatisfied, pkg_scout)) {
  9680. + char ** newstuff = NULL;
  9681. + int rc;
  9682. + pkg_vec_t *tmp_vec = pkg_vec_alloc ();
  9683. + /* check for not-already-installed dependencies */
  9684. + rc = pkg_hash_fetch_unsatisfied_dependencies(conf,
  9685. + pkg_scout,
  9686. + tmp_vec,
  9687. + &newstuff);
  9688. + if (newstuff == NULL) {
  9689. + int ok = 1;
  9690. + for (i = 0; i < rc; i++) {
  9691. + pkg_t *p = tmp_vec->pkgs[i];
  9692. + if (p->state_want == SW_INSTALL)
  9693. + continue;
  9694. + ipkg_message(conf, IPKG_DEBUG, "not installing %s due to requirement for %s\n", pkg_scout->name, p->name);
  9695. + ok = 0;
  9696. + break;
  9697. + }
  9698. + pkg_vec_free (tmp_vec);
  9699. + if (ok) {
  9700. + /* mark this one for installation */
  9701. + ipkg_message(conf, IPKG_NOTICE, "Adding satisfier for greedy dependence: %s\n", pkg_scout->name);
  9702. + pkg_vec_insert(unsatisfied, pkg_scout);
  9703. + }
  9704. + } else {
  9705. + ipkg_message(conf, IPKG_DEBUG, "not installing %s due to broken depends \n", pkg_scout->name);
  9706. + free (newstuff);
  9707. + }
  9708. + }
  9709. + }
  9710. + }
  9711. + }
  9712. +
  9713. + continue;
  9714. + }
  9715. +
  9716. + /* foreach possible satisfier, look for installed package */
  9717. + for (j = 0; j < compound_depend->possibility_count; j++) {
  9718. + /* foreach provided_by, which includes the abstract_pkg itself */
  9719. + depend_t *dependence_to_satisfy = possible_satisfiers[j];
  9720. + abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg;
  9721. + pkg_t *satisfying_pkg =
  9722. + pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg,
  9723. + pkg_installed_and_constraint_satisfied,
  9724. + dependence_to_satisfy, 1);
  9725. + /* Being that I can't test constraing in pkg_hash, I will test it here */
  9726. + if (satisfying_pkg != NULL) {
  9727. + if (!pkg_installed_and_constraint_satisfied ( satisfying_pkg,dependence_to_satisfy)) {
  9728. + satisfying_pkg = NULL;
  9729. + }
  9730. + }
  9731. + ipkg_message(conf, IPKG_DEBUG, "%s:%d: satisfying_pkg=%p \n", __FILE__, __LINE__, satisfying_pkg);
  9732. + if (satisfying_pkg != NULL) {
  9733. + found = 1;
  9734. + break;
  9735. + }
  9736. +
  9737. + }
  9738. + /* if nothing installed matches, then look for uninstalled satisfier */
  9739. + if (!found) {
  9740. + /* foreach possible satisfier, look for installed package */
  9741. + for (j = 0; j < compound_depend->possibility_count; j++) {
  9742. + /* foreach provided_by, which includes the abstract_pkg itself */
  9743. + depend_t *dependence_to_satisfy = possible_satisfiers[j];
  9744. + abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg;
  9745. + pkg_t *satisfying_pkg =
  9746. + pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg,
  9747. + pkg_constraint_satisfied,
  9748. + dependence_to_satisfy, 1);
  9749. + /* Being that I can't test constraing in pkg_hash, I will test it here too */
  9750. + if (satisfying_pkg != NULL) {
  9751. + if (!pkg_constraint_satisfied ( satisfying_pkg,dependence_to_satisfy)) {
  9752. + satisfying_pkg = NULL;
  9753. + }
  9754. + }
  9755. +
  9756. + /* user request overrides package recommendation */
  9757. + if (satisfying_pkg != NULL
  9758. + && (compound_depend->type == RECOMMEND || compound_depend->type == SUGGEST)
  9759. + && (satisfying_pkg->state_want == SW_DEINSTALL || satisfying_pkg->state_want == SW_PURGE)) {
  9760. + ipkg_message (conf, IPKG_NOTICE, "%s: ignoring recommendation for %s at user request\n",
  9761. + pkg->name, satisfying_pkg->name);
  9762. + continue;
  9763. + }
  9764. +
  9765. + ipkg_message(conf, IPKG_DEBUG, "%s:%d: satisfying_pkg=%p\n", __FILE__, __LINE__, satisfying_pkg);
  9766. + if (satisfying_pkg != NULL) {
  9767. + satisfier_entry_pkg = satisfying_pkg;
  9768. + break;
  9769. + }
  9770. + }
  9771. + }
  9772. +
  9773. + /* we didn't find one, add something to the unsatisfied vector */
  9774. + if (!found) {
  9775. + if (!satisfier_entry_pkg) {
  9776. + /* failure to meet recommendations is not an error */
  9777. + if (compound_depend->type != RECOMMEND && compound_depend->type != SUGGEST)
  9778. + the_lost = add_unresolved_dep(pkg, the_lost, i);
  9779. + else
  9780. + ipkg_message (conf, IPKG_NOTICE, "%s: unsatisfied recommendation for %s\n",
  9781. + pkg->name, compound_depend->possibilities[0]->pkg->name);
  9782. + }
  9783. + else {
  9784. + if (compound_depend->type == SUGGEST) {
  9785. + /* just mention it politely */
  9786. + ipkg_message (conf, IPKG_NOTICE, "package %s suggests installing %s\n",
  9787. + pkg->name, satisfier_entry_pkg->name);
  9788. + } else {
  9789. + char ** newstuff = NULL;
  9790. +
  9791. + if (satisfier_entry_pkg != pkg &&
  9792. + !is_pkg_in_pkg_vec(unsatisfied, satisfier_entry_pkg)) {
  9793. + pkg_vec_insert(unsatisfied, satisfier_entry_pkg);
  9794. + pkg_hash_fetch_unsatisfied_dependencies(conf,
  9795. + satisfier_entry_pkg,
  9796. + unsatisfied,
  9797. + &newstuff);
  9798. + the_lost = merge_unresolved(the_lost, newstuff);
  9799. + }
  9800. + }
  9801. + }
  9802. + }
  9803. + }
  9804. + *unresolved = the_lost;
  9805. +
  9806. + return unsatisfied->len;
  9807. +}
  9808. +
  9809. +/*checking for conflicts !in replaces
  9810. + If a packages conflicts with another but is also replacing it, I should not consider it a
  9811. + really conflicts
  9812. + returns 0 if conflicts <> replaces or 1 if conflicts == replaces
  9813. +*/
  9814. +int is_pkg_a_replaces(pkg_t *pkg_scout,pkg_t *pkg)
  9815. +{
  9816. + int i ;
  9817. + int replaces_count = pkg->replaces_count;
  9818. + abstract_pkg_t **replaces;
  9819. +
  9820. + if (pkg->replaces_count==0) // No replaces, it's surely a conflict
  9821. + return 0;
  9822. +
  9823. + replaces = pkg->replaces;
  9824. +
  9825. + for (i = 0; i < replaces_count; i++) {
  9826. + if (strcmp(pkg_scout->name,pkg->replaces[i]->name)==0) { // Found
  9827. + ipkg_message(NULL, IPKG_DEBUG2, "Seems I've found a replace %s %s \n",pkg_scout->name,pkg->replaces[i]->name);
  9828. + return 1;
  9829. + }
  9830. + }
  9831. + return 0;
  9832. +
  9833. +}
  9834. +
  9835. +
  9836. +/* Abhaya: added support for conflicts */
  9837. +pkg_vec_t * pkg_hash_fetch_conflicts(pkg_t * pkg)
  9838. +{
  9839. + pkg_vec_t * installed_conflicts, * test_vec;
  9840. + compound_depend_t * conflicts;
  9841. + depend_t ** possible_satisfiers;
  9842. + depend_t * possible_satisfier;
  9843. + register int i, j, k;
  9844. + int count;
  9845. + abstract_pkg_t * ab_pkg;
  9846. + pkg_t **pkg_scouts;
  9847. + pkg_t *pkg_scout;
  9848. +
  9849. + /*
  9850. + * this is a setup to check for redundant/cyclic dependency checks,
  9851. + * which are marked at the abstract_pkg level
  9852. + */
  9853. + if(!(ab_pkg = pkg->parent)){
  9854. + fprintf(stderr, "dependency check error. pkg %s isn't in hash table\n", pkg->name);
  9855. + return (pkg_vec_t *)NULL;
  9856. + }
  9857. +
  9858. + conflicts = pkg->conflicts;
  9859. + if(!conflicts){
  9860. + return (pkg_vec_t *)NULL;
  9861. + }
  9862. + installed_conflicts = pkg_vec_alloc();
  9863. +
  9864. + count = pkg->conflicts_count;
  9865. +
  9866. +
  9867. +
  9868. + /* foreach conflict */
  9869. + for(i = 0; i < pkg->conflicts_count; i++){
  9870. +
  9871. + possible_satisfiers = conflicts->possibilities;
  9872. +
  9873. + /* foreach possible satisfier */
  9874. + for(j = 0; j < conflicts->possibility_count; j++){
  9875. + possible_satisfier = possible_satisfiers[j];
  9876. + if (!possible_satisfier)
  9877. + fprintf(stderr, "%s:%d: possible_satisfier is null\n", __FUNCTION__, __LINE__);
  9878. + if (!possible_satisfier->pkg)
  9879. + fprintf(stderr, "%s:%d: possible_satisfier->pkg is null\n", __FUNCTION__, __LINE__);
  9880. + test_vec = possible_satisfier->pkg->pkgs;
  9881. + if (test_vec) {
  9882. + /* pkg_vec found, it is an actual package conflict
  9883. + * cruise this possiblity's pkg_vec looking for an installed version */
  9884. + pkg_scouts = test_vec->pkgs;
  9885. + for(k = 0; k < test_vec->len; k++){
  9886. + pkg_scout = pkg_scouts[k];
  9887. + if (!pkg_scout) {
  9888. + fprintf(stderr, "%s: null pkg scout\n", __FUNCTION__);
  9889. + continue;
  9890. + }
  9891. + if ((pkg_scout->state_status == SS_INSTALLED || pkg_scout->state_want == SW_INSTALL) &&
  9892. + version_constraints_satisfied(possible_satisfier, pkg_scout) && !is_pkg_a_replaces(pkg_scout,pkg)){
  9893. + if (!is_pkg_in_pkg_vec(installed_conflicts, pkg_scout)){
  9894. + pkg_vec_insert(installed_conflicts, pkg_scout);
  9895. + }
  9896. + }
  9897. + }
  9898. + }
  9899. + }
  9900. + conflicts++;
  9901. + }
  9902. +
  9903. + if (installed_conflicts->len)
  9904. + return installed_conflicts;
  9905. + pkg_vec_free(installed_conflicts);
  9906. + return (pkg_vec_t *)NULL;
  9907. +}
  9908. +
  9909. +int version_constraints_satisfied(depend_t * depends, pkg_t * pkg)
  9910. +{
  9911. + pkg_t * temp;
  9912. + int comparison;
  9913. +
  9914. + if(depends->constraint == NONE)
  9915. + return 1;
  9916. +
  9917. + temp = pkg_new();
  9918. +
  9919. + parseVersion(temp, depends->version);
  9920. +
  9921. + comparison = pkg_compare_versions(pkg, temp);
  9922. +
  9923. + free(temp);
  9924. +
  9925. + if((depends->constraint == EARLIER) &&
  9926. + (comparison < 0))
  9927. + return 1;
  9928. + else if((depends->constraint == LATER) &&
  9929. + (comparison > 0))
  9930. + return 1;
  9931. + else if(comparison == 0)
  9932. + return 1;
  9933. + else if((depends->constraint == LATER_EQUAL) &&
  9934. + (comparison >= 0))
  9935. + return 1;
  9936. + else if((depends->constraint == EARLIER_EQUAL) &&
  9937. + (comparison <= 0))
  9938. + return 1;
  9939. +
  9940. + return 0;
  9941. +}
  9942. +
  9943. +int pkg_dependence_satisfiable(depend_t *depend)
  9944. +{
  9945. + abstract_pkg_t *apkg = depend->pkg;
  9946. + abstract_pkg_vec_t *provider_apkgs = apkg->provided_by;
  9947. + int n_providers = provider_apkgs->len;
  9948. + abstract_pkg_t **apkgs = provider_apkgs->pkgs;
  9949. + pkg_vec_t *pkg_vec;
  9950. + int n_pkgs ;
  9951. + int i;
  9952. + int j;
  9953. +
  9954. + for (i = 0; i < n_providers; i++) {
  9955. + abstract_pkg_t *papkg = apkgs[i];
  9956. + pkg_vec = papkg->pkgs;
  9957. + if (pkg_vec) {
  9958. + n_pkgs = pkg_vec->len;
  9959. + for (j = 0; j < n_pkgs; j++) {
  9960. + pkg_t *pkg = pkg_vec->pkgs[j];
  9961. + if (version_constraints_satisfied(depend, pkg)) {
  9962. + return 1;
  9963. + }
  9964. + }
  9965. + }
  9966. + }
  9967. + return 0;
  9968. +}
  9969. +
  9970. +int pkg_dependence_satisfied(depend_t *depend)
  9971. +{
  9972. + abstract_pkg_t *apkg = depend->pkg;
  9973. + abstract_pkg_vec_t *provider_apkgs = apkg->provided_by;
  9974. + int n_providers = provider_apkgs->len;
  9975. + abstract_pkg_t **apkgs = provider_apkgs->pkgs;
  9976. + int i;
  9977. + int n_pkgs;
  9978. + int j;
  9979. +
  9980. + for (i = 0; i < n_providers; i++) {
  9981. + abstract_pkg_t *papkg = apkgs[i];
  9982. + pkg_vec_t *pkg_vec = papkg->pkgs;
  9983. + if (pkg_vec) {
  9984. + n_pkgs = pkg_vec->len;
  9985. + for (j = 0; j < n_pkgs; j++) {
  9986. + pkg_t *pkg = pkg_vec->pkgs[j];
  9987. + if (version_constraints_satisfied(depend, pkg)) {
  9988. + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED)
  9989. + return 1;
  9990. + }
  9991. + }
  9992. + }
  9993. + }
  9994. + return 0;
  9995. +}
  9996. +
  9997. +static int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg)
  9998. +{
  9999. + register int i;
  10000. + pkg_t ** pkgs = vec->pkgs;
  10001. +
  10002. + for(i = 0; i < vec->len; i++)
  10003. + if((strcmp(pkg->name, (*(pkgs + i))->name) == 0)
  10004. + && (pkg_compare_versions(pkg, *(pkgs + i)) == 0)
  10005. + && (strcmp(pkg->architecture, (*(pkgs + i))->architecture) == 0))
  10006. + return 1;
  10007. + return 0;
  10008. +}
  10009. +
  10010. +
  10011. +#ifdef DeadCode
  10012. +/**
  10013. + * pkg_has_common_provides returns 1 if pkg and replacee both provide
  10014. + * the same abstract package and 0 otherwise.
  10015. + */
  10016. +int pkg_has_common_provides(pkg_t *pkg, pkg_t *replacee)
  10017. +{
  10018. + abstract_pkg_t **provides = pkg->provides;
  10019. + int provides_count = pkg->provides_count;
  10020. + abstract_pkg_t **replacee_provides = replacee->provides;
  10021. + int replacee_provides_count = replacee->provides_count;
  10022. + int i, j;
  10023. + for (i = 0; i < provides_count; i++) {
  10024. + abstract_pkg_t *apkg = provides[i];
  10025. + for (j = 0; j < replacee_provides_count; j++) {
  10026. + abstract_pkg_t *replacee_apkg = replacee_provides[i];
  10027. + if (apkg == replacee_apkg)
  10028. + return 1;
  10029. + }
  10030. + }
  10031. + return 0;
  10032. +}
  10033. +#endif
  10034. +
  10035. +/**
  10036. + * pkg_provides_abstract returns 1 if pkg->provides contains providee
  10037. + * and 0 otherwise.
  10038. + */
  10039. +int pkg_provides_abstract(pkg_t *pkg, abstract_pkg_t *providee)
  10040. +{
  10041. + abstract_pkg_t **provides = pkg->provides;
  10042. + int provides_count = pkg->provides_count;
  10043. + int i;
  10044. + for (i = 0; i < provides_count; i++) {
  10045. + if (provides[i] == providee)
  10046. + return 1;
  10047. + }
  10048. + return 0;
  10049. +}
  10050. +
  10051. +/**
  10052. + * pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0
  10053. + * otherwise.
  10054. + */
  10055. +int pkg_replaces(pkg_t *pkg, pkg_t *replacee)
  10056. +{
  10057. + abstract_pkg_t **replaces = pkg->replaces;
  10058. + int replaces_count = pkg->replaces_count;
  10059. + /* abstract_pkg_t **replacee_provides = pkg->provides;
  10060. + int replacee_provides_count = pkg->provides_count; */
  10061. + int i, j;
  10062. + for (i = 0; i < replaces_count; i++) {
  10063. + abstract_pkg_t *abstract_replacee = replaces[i];
  10064. + for (j = 0; j < replaces_count; j++) {
  10065. + /* ipkg_message(NULL, IPKG_DEBUG2, "Searching pkg-name %s repprovname %s absrepname %s \n",
  10066. + pkg->name,replacee->provides[j]->name, abstract_replacee->name); */
  10067. + if (replacee->provides[j] == abstract_replacee)
  10068. + return 1;
  10069. + }
  10070. + }
  10071. + return 0;
  10072. +}
  10073. +
  10074. +
  10075. +/**
  10076. + * pkg_conflicts_abstract returns 1 if pkg->conflicts contains conflictee and 0
  10077. + * otherwise.
  10078. + */
  10079. +int pkg_conflicts_abstract(pkg_t *pkg, abstract_pkg_t *conflictee)
  10080. +{
  10081. + compound_depend_t *conflicts = pkg->conflicts;
  10082. + int conflicts_count = pkg->conflicts_count;
  10083. + int i, j;
  10084. + for (i = 0; i < conflicts_count; i++) {
  10085. + int possibility_count = conflicts[i].possibility_count;
  10086. + struct depend **possibilities = conflicts[i].possibilities;
  10087. + for (j = 0; j < possibility_count; j++) {
  10088. + if (possibilities[j]->pkg == conflictee) {
  10089. + return 1;
  10090. + }
  10091. + }
  10092. + }
  10093. + return 0;
  10094. +}
  10095. +
  10096. +/**
  10097. + * pkg_conflicts returns 1 if pkg->conflicts contains one of
  10098. + * conflictee's provides and 0 otherwise.
  10099. + */
  10100. +int pkg_conflicts(pkg_t *pkg, pkg_t *conflictee)
  10101. +{
  10102. + compound_depend_t *conflicts = pkg->conflicts;
  10103. + int conflicts_count = pkg->conflicts_count;
  10104. + abstract_pkg_t **conflictee_provides = conflictee->provides;
  10105. + int conflictee_provides_count = conflictee->provides_count;
  10106. + int i, j, k;
  10107. + int possibility_count;
  10108. + struct depend **possibilities;
  10109. + abstract_pkg_t *possibility ;
  10110. +
  10111. + for (i = 0; i < conflicts_count; i++) {
  10112. + possibility_count = conflicts[i].possibility_count;
  10113. + possibilities = conflicts[i].possibilities;
  10114. + for (j = 0; j < possibility_count; j++) {
  10115. + possibility = possibilities[j]->pkg;
  10116. + for (k = 0; k < conflictee_provides_count; k++) {
  10117. + if (possibility == conflictee_provides[k]) {
  10118. + return 1;
  10119. + }
  10120. + }
  10121. + }
  10122. + }
  10123. + return 0;
  10124. +}
  10125. +
  10126. +static char ** merge_unresolved(char ** oldstuff, char ** newstuff)
  10127. +{
  10128. + int oldlen = 0, newlen = 0;
  10129. + char ** result;
  10130. + register int i, j;
  10131. +
  10132. + if(!newstuff)
  10133. + return oldstuff;
  10134. +
  10135. + while(oldstuff && oldstuff[oldlen]) oldlen++;
  10136. + while(newstuff && newstuff[newlen]) newlen++;
  10137. +
  10138. + result = (char **)realloc(oldstuff, sizeof(char *) * (oldlen + newlen + 1));
  10139. + if (result == NULL) {
  10140. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10141. + return NULL;
  10142. + }
  10143. +
  10144. + for(i = oldlen, j = 0; i < (oldlen + newlen); i++, j++)
  10145. + *(result + i) = *(newstuff + j);
  10146. +
  10147. + *(result + i) = NULL;
  10148. +
  10149. + return result;
  10150. +}
  10151. +
  10152. +/*
  10153. + * a kinda kludgy way to back out depends str from two different arrays (reg'l'r 'n pre)
  10154. + * this is null terminated, no count is carried around
  10155. + */
  10156. +char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx)
  10157. +{
  10158. + int count;
  10159. + char ** resized;
  10160. + char *depend_str = pkg_depend_str(pkg, ref_ndx);
  10161. +
  10162. + count = 0;
  10163. + while(the_lost && the_lost[count]) count++;
  10164. +
  10165. + count++; /* need one to hold the null */
  10166. + resized = (char **)realloc(the_lost, sizeof(char *) * (count + 1));
  10167. + if (resized == NULL) {
  10168. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10169. + return NULL;
  10170. + }
  10171. + resized[count - 1] = strdup(depend_str);
  10172. + resized[count] = NULL;
  10173. +
  10174. + return resized;
  10175. +}
  10176. +
  10177. +void printDepends(pkg_t * pkg)
  10178. +{
  10179. + register int i, j;
  10180. + compound_depend_t * depend;
  10181. + int count;
  10182. +
  10183. + count = pkg->pre_depends_count + pkg->depends_count;
  10184. +
  10185. + depend = pkg->depends;
  10186. + if(!depend){
  10187. + fprintf(stderr, "Depends pointer is NULL\n");
  10188. + return;
  10189. + }
  10190. + for(i = 0; i < count; i++){
  10191. + fprintf(stderr, "%s has %d possibilities:\n",
  10192. + (depend->type == GREEDY_DEPEND) ? "Greedy-Depend" : ((depend->type == DEPEND) ? "Depend" : "Pre-Depend"),
  10193. + depend->possibility_count);
  10194. + for(j = 0; j < depend->possibility_count; j++)
  10195. + fprintf(stderr, "\t%s version %s (%d)\n",
  10196. + depend->possibilities[j]->pkg->name,
  10197. + depend->possibilities[j]->version,
  10198. + depend->possibilities[j]->constraint);
  10199. + depend++;
  10200. + }
  10201. +}
  10202. +
  10203. +int buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
  10204. +{
  10205. + register int i, j;
  10206. +
  10207. + /* every pkg provides itself */
  10208. + abstract_pkg_vec_insert(ab_pkg->provided_by, ab_pkg);
  10209. +
  10210. + if (!pkg->provides_count)
  10211. + return 0;
  10212. +
  10213. + pkg->provides = (abstract_pkg_t **)malloc(sizeof(abstract_pkg_t *) * (pkg->provides_count + 1));
  10214. + if (pkg->provides == NULL) {
  10215. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10216. + return -1 ;
  10217. + }
  10218. + pkg->provides[0] = ab_pkg;
  10219. +
  10220. + // if (strcmp(ab_pkg->name, pkg->name))
  10221. + // fprintf(stderr, __FUNCTION__ ": ab_pkg=%s pkg=%s\n", ab_pkg->name, pkg->name);
  10222. +
  10223. + for(i = 0; i < pkg->provides_count; i++){
  10224. + abstract_pkg_t *provided_abpkg = ensure_abstract_pkg_by_name(hash, pkg->provides_str[i]);
  10225. +
  10226. + pkg->provides[i+1] = provided_abpkg;
  10227. +
  10228. + j = 0;
  10229. + abstract_pkg_vec_insert(provided_abpkg->provided_by, ab_pkg);
  10230. + }
  10231. + return 0;
  10232. +}
  10233. +
  10234. +/* Abhaya: added conflicts support */
  10235. +int buildConflicts(hash_table_t * hash, pkg_t * pkg)
  10236. +{
  10237. + register int i;
  10238. + compound_depend_t * conflicts;
  10239. +
  10240. + if (!pkg->conflicts_count)
  10241. + return 0;
  10242. +
  10243. + conflicts = pkg->conflicts = malloc(sizeof(compound_depend_t) *
  10244. + pkg->conflicts_count);
  10245. + if (conflicts == NULL) {
  10246. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10247. + return -1;
  10248. + }
  10249. + for (i = 0; i < pkg->conflicts_count; i++) {
  10250. + conflicts->type = CONFLICTS;
  10251. + parseDepends(conflicts, hash,
  10252. + pkg->conflicts_str[i]);
  10253. +#if 0
  10254. + for (j = 0; j < conflicts->possibility_count; j++) {
  10255. + depend_t *possibility = conflicts->possibilities[j];
  10256. + abstract_pkg_t *conflicting_apkg = possibility->pkg;
  10257. + pkg_add_conflict_pair(ab_pkg, conflicting_apkg);
  10258. + }
  10259. +#endif
  10260. + conflicts++;
  10261. + }
  10262. + return 0;
  10263. +}
  10264. +
  10265. +int buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
  10266. +{
  10267. + register int i, j;
  10268. +
  10269. + if (!pkg->replaces_count)
  10270. + return 0;
  10271. +
  10272. + pkg->replaces = (abstract_pkg_t **)malloc(sizeof(abstract_pkg_t *) * pkg->replaces_count);
  10273. + if (pkg->replaces == NULL) {
  10274. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10275. + return -1;
  10276. + }
  10277. +
  10278. + // if (strcmp(ab_pkg->name, pkg->name))
  10279. + // fprintf(stderr, __FUNCTION__ ": ab_pkg=%s pkg=%s\n", ab_pkg->name, pkg->name);
  10280. +
  10281. + for(i = 0; i < pkg->replaces_count; i++){
  10282. + abstract_pkg_t *old_abpkg = ensure_abstract_pkg_by_name(hash, pkg->replaces_str[i]);
  10283. +
  10284. + pkg->replaces[i] = old_abpkg;
  10285. +
  10286. + j = 0;
  10287. + if (!old_abpkg->replaced_by)
  10288. + old_abpkg->replaced_by = abstract_pkg_vec_alloc();
  10289. + if ( old_abpkg->replaced_by == NULL ){
  10290. + return -1;
  10291. + }
  10292. + /* if a package pkg both replaces and conflicts old_abpkg,
  10293. + * then add it to the replaced_by vector so that old_abpkg
  10294. + * will be upgraded to ab_pkg automatically */
  10295. + if (pkg_conflicts_abstract(pkg, old_abpkg))
  10296. + abstract_pkg_vec_insert(old_abpkg->replaced_by, ab_pkg);
  10297. + }
  10298. + return 0;
  10299. +}
  10300. +
  10301. +int buildDepends(hash_table_t * hash, pkg_t * pkg)
  10302. +{
  10303. + int count;
  10304. + register int i;
  10305. + compound_depend_t * depends;
  10306. +
  10307. + if(!(count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count))
  10308. + return 0;
  10309. +
  10310. + if (0 && pkg->pre_depends_count)
  10311. + fprintf(stderr, "pkg=%s pre_depends_count=%d depends_count=%d\n",
  10312. + pkg->name, pkg->pre_depends_count, pkg->depends_count);
  10313. + depends = pkg->depends = malloc(sizeof(compound_depend_t) * count);
  10314. + if (depends == NULL) {
  10315. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10316. + return -1;
  10317. + }
  10318. +
  10319. +
  10320. + for(i = 0; i < pkg->pre_depends_count; i++){
  10321. + parseDepends(depends, hash, pkg->pre_depends_str[i]);
  10322. + if (0 && pkg->pre_depends_count)
  10323. + fprintf(stderr, " pre_depends_str=%s depends=%p possibility_count=%x\n",
  10324. + pkg->pre_depends_str[i], depends, depends->possibility_count);
  10325. + depends->type = PREDEPEND;
  10326. + depends++;
  10327. + }
  10328. +
  10329. + for(i = 0; i < pkg->recommends_count; i++){
  10330. + parseDepends(depends, hash, pkg->recommends_str[i]);
  10331. + if (0 && pkg->recommends_count)
  10332. + fprintf(stderr, " recommends_str=%s depends=%p possibility_count=%x\n",
  10333. + pkg->recommends_str[i], depends, depends->possibility_count);
  10334. + depends->type = RECOMMEND;
  10335. + depends++;
  10336. + }
  10337. +
  10338. + for(i = 0; i < pkg->suggests_count; i++){
  10339. + parseDepends(depends, hash, pkg->suggests_str[i]);
  10340. + if (0 && pkg->suggests_count)
  10341. + fprintf(stderr, " suggests_str=%s depends=%p possibility_count=%x\n",
  10342. + pkg->suggests_str[i], depends, depends->possibility_count);
  10343. + depends->type = SUGGEST;
  10344. + depends++;
  10345. + }
  10346. +
  10347. + for(i = 0; i < pkg->depends_count; i++){
  10348. + parseDepends(depends, hash, pkg->depends_str[i]);
  10349. + if (0 && pkg->depends_count)
  10350. + fprintf(stderr, " depends_str=%s depends=%p possibility_count=%x\n",
  10351. + pkg->depends_str[i], depends, depends->possibility_count);
  10352. + depends++;
  10353. + }
  10354. + return 0;
  10355. +}
  10356. +
  10357. +/*
  10358. + * pkg_depend_string: returns the depends string specified by index_.
  10359. + * All 4 kinds of dependences: dependence, pre-dependence, recommend, and suggest are number starting from 0.
  10360. + * [0,npredepends) -> returns pre_depends_str[index_]
  10361. + * [npredepends,npredepends+nrecommends) -> returns recommends_str[index_]
  10362. + * [npredepends+nrecommends,npredepends+nrecommends+nsuggests) -> returns recommends_str[index_]
  10363. + * [npredepends+nrecommends+nsuggests,npredepends+nrecommends+nsuggests+ndepends) -> returns depends_str[index_]
  10364. + */
  10365. +char *pkg_depend_str(pkg_t *pkg, int index_)
  10366. +{
  10367. + if (index_ < pkg->pre_depends_count) {
  10368. + return pkg->pre_depends_str[index_];
  10369. + }
  10370. + index_ -= pkg->pre_depends_count;
  10371. +
  10372. + if (index_ < pkg->recommends_count) {
  10373. + return pkg->recommends_str[index_];
  10374. + }
  10375. + index_ -= pkg->recommends_count;
  10376. +
  10377. + if (index_ < pkg->suggests_count) {
  10378. + return pkg->suggests_str[index_];
  10379. + }
  10380. + index_ -= pkg->suggests_count;
  10381. +
  10382. + if (index_ < pkg->depends_count) {
  10383. + return pkg->depends_str[index_];
  10384. + }
  10385. + fprintf(stderr, "pkg_depend_str: index_ %d out of range for pkg=%s\n", index_, pkg->name);
  10386. + return NULL;
  10387. +}
  10388. +
  10389. +void freeDepends(pkg_t *pkg)
  10390. +{
  10391. + int i;
  10392. +
  10393. + if (pkg == NULL || pkg->depends == NULL) {
  10394. + return;
  10395. + }
  10396. +
  10397. + fprintf(stderr, "Freeing depends=%p\n", pkg->depends);
  10398. + for (i=0; i < pkg->depends->possibility_count; i++) {
  10399. + depend_deinit(pkg->depends->possibilities[i]);
  10400. + }
  10401. + free(pkg->depends->possibilities);
  10402. + free(pkg->depends);
  10403. + pkg->depends = NULL;
  10404. +}
  10405. +
  10406. +void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg)
  10407. +{
  10408. + compound_depend_t * depends;
  10409. + int count, othercount;
  10410. + register int i, j;
  10411. + abstract_pkg_t * ab_depend;
  10412. + abstract_pkg_t ** temp;
  10413. +
  10414. + count = pkg->pre_depends_count + pkg->depends_count;
  10415. + depends = pkg->depends;
  10416. +
  10417. + if (0 && pkg->pre_depends_count)
  10418. + fprintf(stderr, "pkg=%s pre_depends_count=%d depends_count=%d\n",
  10419. + pkg->name, pkg->pre_depends_count, pkg->depends_count);
  10420. + for (i = 0; i < count; i++) {
  10421. + if (0 && pkg->pre_depends_count)
  10422. + fprintf(stderr, " i=%d possibility_count=%x depends=%p\n", i, depends->possibility_count, depends);
  10423. + for (j = 0; j < depends->possibility_count; j++){
  10424. + ab_depend = depends->possibilities[j]->pkg;
  10425. + if(!ab_depend->depended_upon_by)
  10426. + ab_depend->depended_upon_by = (abstract_pkg_t **)calloc(1, sizeof(abstract_pkg_t *));
  10427. +
  10428. + temp = ab_depend->depended_upon_by;
  10429. + othercount = 1;
  10430. + while(*temp){
  10431. + temp++;
  10432. + othercount++;
  10433. + }
  10434. + *temp = ab_pkg;
  10435. +
  10436. + ab_depend->depended_upon_by = (abstract_pkg_t **)realloc(ab_depend->depended_upon_by,
  10437. + (othercount + 1) * sizeof(abstract_pkg_t *));
  10438. + /* the array may have moved */
  10439. + temp = ab_depend->depended_upon_by + othercount;
  10440. + *temp = NULL;
  10441. + }
  10442. + depends++;
  10443. + }
  10444. +}
  10445. +
  10446. +static depend_t * depend_init(void)
  10447. +{
  10448. + depend_t * d = (depend_t *)malloc(sizeof(depend_t));
  10449. + if ( d==NULL ){
  10450. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10451. + return NULL;
  10452. + }
  10453. + d->constraint = NONE;
  10454. + d->version = NULL;
  10455. + d->pkg = NULL;
  10456. +
  10457. + return d;
  10458. +}
  10459. +
  10460. +static void depend_deinit(depend_t *d)
  10461. +{
  10462. + free(d);
  10463. +}
  10464. +
  10465. +static int parseDepends(compound_depend_t *compound_depend,
  10466. + hash_table_t * hash, char * depend_str)
  10467. +{
  10468. + char * pkg_name, buffer[2048];
  10469. + int num_of_ors = 0;
  10470. + register int i;
  10471. + register char * src, * dest;
  10472. + depend_t ** possibilities;
  10473. +
  10474. + /* first count the number of ored possibilities for satisfying dependency */
  10475. + src = depend_str;
  10476. + while(*src)
  10477. + if(*src++ == '|')
  10478. + num_of_ors++;
  10479. +
  10480. + compound_depend->type = DEPEND;
  10481. +
  10482. + compound_depend->possibility_count = num_of_ors + 1;
  10483. + possibilities = (depend_t **)malloc(sizeof(depend_t *) * (num_of_ors + 1));
  10484. + if (!possibilities)
  10485. + return -ENOMEM;
  10486. + compound_depend->possibilities = possibilities;
  10487. +
  10488. + src = depend_str;
  10489. + for(i = 0; i < num_of_ors + 1; i++){
  10490. + possibilities[i] = depend_init();
  10491. + if (!possibilities[i])
  10492. + return -ENOMEM;
  10493. + /* gobble up just the name first */
  10494. + dest = buffer;
  10495. + while(*src &&
  10496. + !isspace(*src) &&
  10497. + (*src != '(') &&
  10498. + (*src != '*') &&
  10499. + (*src != '|'))
  10500. + *dest++ = *src++;
  10501. + *dest = '\0';
  10502. + pkg_name = trim_alloc(buffer);
  10503. + if (pkg_name == NULL )
  10504. + return -ENOMEM;
  10505. +
  10506. + /* now look at possible version info */
  10507. +
  10508. + /* skip to next chars */
  10509. + if(isspace(*src))
  10510. + while(*src && isspace(*src)) src++;
  10511. +
  10512. + /* extract constraint and version */
  10513. + if(*src == '('){
  10514. + src++;
  10515. + if(!strncmp(src, "<<", 2)){
  10516. + possibilities[i]->constraint = EARLIER;
  10517. + src += 2;
  10518. + }
  10519. + else if(!strncmp(src, "<=", 2)){
  10520. + possibilities[i]->constraint = EARLIER_EQUAL;
  10521. + src += 2;
  10522. + }
  10523. + else if(!strncmp(src, ">=", 2)){
  10524. + possibilities[i]->constraint = LATER_EQUAL;
  10525. + src += 2;
  10526. + }
  10527. + else if(!strncmp(src, ">>", 2)){
  10528. + possibilities[i]->constraint = LATER;
  10529. + src += 2;
  10530. + }
  10531. + else if(!strncmp(src, "=", 1)){
  10532. + possibilities[i]->constraint = EQUAL;
  10533. + src++;
  10534. + }
  10535. + /* should these be here to support deprecated designations; dpkg does */
  10536. + else if(!strncmp(src, "<", 1)){
  10537. + possibilities[i]->constraint = EARLIER_EQUAL;
  10538. + src++;
  10539. + }
  10540. + else if(!strncmp(src, ">", 1)){
  10541. + possibilities[i]->constraint = LATER_EQUAL;
  10542. + src++;
  10543. + }
  10544. +
  10545. + /* now we have any constraint, pass space to version string */
  10546. + while(isspace(*src)) src++;
  10547. +
  10548. + /* this would be the version string */
  10549. + dest = buffer;
  10550. + while(*src && *src != ')')
  10551. + *dest++ = *src++;
  10552. + *dest = '\0';
  10553. +
  10554. + possibilities[i]->version = trim_alloc(buffer);
  10555. + /* fprintf(stderr, "let's print the depends version string:");
  10556. + fprintf(stderr, "version %s\n", possibilities[i]->version);*/
  10557. + if (possibilities[i]->version == NULL )
  10558. + return -ENOMEM;
  10559. +
  10560. +
  10561. + }
  10562. + /* hook up the dependency to its abstract pkg */
  10563. + possibilities[i]->pkg = ensure_abstract_pkg_by_name(hash, pkg_name);
  10564. +
  10565. + free(pkg_name);
  10566. +
  10567. + /* now get past the ) and any possible | chars */
  10568. + while(*src &&
  10569. + (isspace(*src) ||
  10570. + (*src == ')') ||
  10571. + (*src == '|')))
  10572. + src++;
  10573. + if (*src == '*')
  10574. + {
  10575. + compound_depend->type = GREEDY_DEPEND;
  10576. + src++;
  10577. + }
  10578. + }
  10579. +
  10580. + return 0;
  10581. +}
  10582. diff -Nur busybox-1.19.4.orig/archival/libipkg/pkg_depends.h busybox-1.19.4/archival/libipkg/pkg_depends.h
  10583. --- busybox-1.19.4.orig/archival/libipkg/pkg_depends.h 1970-01-01 01:00:00.000000000 +0100
  10584. +++ busybox-1.19.4/archival/libipkg/pkg_depends.h 2012-03-17 00:58:08.197100679 +0100
  10585. @@ -0,0 +1,105 @@
  10586. +/* pkg_depends.h - the itsy package management system
  10587. +
  10588. + Steven M. Ayer
  10589. +
  10590. + Copyright (C) 2002 Compaq Computer Corporation
  10591. +
  10592. + This program is free software; you can redistribute it and/or
  10593. + modify it under the terms of the GNU General Public License as
  10594. + published by the Free Software Foundation; either version 2, or (at
  10595. + your option) any later version.
  10596. +
  10597. + This program is distributed in the hope that it will be useful, but
  10598. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10599. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10600. + General Public License for more details.
  10601. +*/
  10602. +
  10603. +#ifndef PKG_DEPENDS_H
  10604. +#define PKG_DEPENDS_H
  10605. +
  10606. +#include "pkg.h"
  10607. +#include "pkg_hash.h"
  10608. +
  10609. +enum depend_type {
  10610. + PREDEPEND,
  10611. + DEPEND,
  10612. + CONFLICTS,
  10613. + GREEDY_DEPEND,
  10614. + RECOMMEND,
  10615. + SUGGEST
  10616. +};
  10617. +typedef enum depend_type depend_type_t;
  10618. +
  10619. +enum version_constraint {
  10620. + NONE,
  10621. + EARLIER,
  10622. + EARLIER_EQUAL,
  10623. + EQUAL,
  10624. + LATER_EQUAL,
  10625. + LATER
  10626. +};
  10627. +typedef enum version_constraint version_constraint_t;
  10628. +
  10629. +struct depend{
  10630. + version_constraint_t constraint;
  10631. + char * version;
  10632. + abstract_pkg_t * pkg;
  10633. +};
  10634. +typedef struct depend depend_t;
  10635. +
  10636. +struct compound_depend{
  10637. + depend_type_t type;
  10638. + int possibility_count;
  10639. + struct depend ** possibilities;
  10640. +};
  10641. +typedef struct compound_depend compound_depend_t;
  10642. +
  10643. +#include "hash_table.h"
  10644. +
  10645. +int buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
  10646. +int buildConflicts(hash_table_t * hash, pkg_t * pkg);
  10647. +int buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
  10648. +int buildDepends(hash_table_t * hash, pkg_t * pkg);
  10649. +
  10650. +/**
  10651. + * pkg_has_common_provides returns 1 if pkg and replacee both provide
  10652. + * the same abstract package and 0 otherwise.
  10653. + */
  10654. +int pkg_has_common_provides(pkg_t *pkg, pkg_t *replacee);
  10655. +
  10656. +/**
  10657. + * pkg_provides returns 1 if pkg->provides contains providee and 0
  10658. + * otherwise.
  10659. + */
  10660. +int pkg_provides_abstract(pkg_t *pkg, abstract_pkg_t *providee);
  10661. +
  10662. +/**
  10663. + * pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0
  10664. + * otherwise.
  10665. + */
  10666. +int pkg_replaces(pkg_t *pkg, pkg_t *replacee);
  10667. +
  10668. +/**
  10669. + * pkg_conflicts_abstract returns 1 if pkg->conflicts contains conflictee provides and 0
  10670. + * otherwise.
  10671. + */
  10672. +int pkg_conflicts_abstract(pkg_t *pkg, abstract_pkg_t *conflicts);
  10673. +
  10674. +/**
  10675. + * pkg_conflicts returns 1 if pkg->conflicts contains one of conflictee's provides and 0
  10676. + * otherwise.
  10677. + */
  10678. +int pkg_conflicts(pkg_t *pkg, pkg_t *conflicts);
  10679. +
  10680. +char *pkg_depend_str(pkg_t *pkg, int index_);
  10681. +void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg);
  10682. +void freeDepends(pkg_t *pkg);
  10683. +void printDepends(pkg_t * pkg);
  10684. +int version_constraints_satisfied(depend_t * depends, pkg_t * pkg);
  10685. +int pkg_hash_fetch_unsatisfied_dependencies(ipkg_conf_t *conf, pkg_t * pkg, pkg_vec_t *depends, char *** unresolved);
  10686. +pkg_vec_t * pkg_hash_fetch_conflicts(pkg_t * pkg);
  10687. +int pkg_dependence_satisfiable(depend_t *depend);
  10688. +int pkg_dependence_satisfied(depend_t *depend);
  10689. +
  10690. +#endif
  10691. diff -Nur busybox-1.19.4.orig/archival/libipkg/pkg_dest.c busybox-1.19.4/archival/libipkg/pkg_dest.c
  10692. --- busybox-1.19.4.orig/archival/libipkg/pkg_dest.c 1970-01-01 01:00:00.000000000 +0100
  10693. +++ busybox-1.19.4/archival/libipkg/pkg_dest.c 2012-03-17 00:58:08.197100679 +0100
  10694. @@ -0,0 +1,92 @@
  10695. +/* pkg_dest.c - the itsy package management system
  10696. +
  10697. + Carl D. Worth
  10698. +
  10699. + Copyright (C) 2001 University of Southern California
  10700. +
  10701. + This program is free software; you can redistribute it and/or
  10702. + modify it under the terms of the GNU General Public License as
  10703. + published by the Free Software Foundation; either version 2, or (at
  10704. + your option) any later version.
  10705. +
  10706. + This program is distributed in the hope that it will be useful, but
  10707. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10708. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10709. + General Public License for more details.
  10710. +*/
  10711. +
  10712. +#include "ipkg.h"
  10713. +
  10714. +#include "pkg_dest.h"
  10715. +#include "file_util.h"
  10716. +#include "str_util.h"
  10717. +#include "sprintf_alloc.h"
  10718. +
  10719. +int pkg_dest_init(pkg_dest_t *dest, const char *name, const char *root_dir,const char * lists_dir)
  10720. +{
  10721. + dest->name = strdup(name);
  10722. +
  10723. + /* Guarantee that dest->root_dir ends with a '/' */
  10724. + if (str_ends_with(root_dir, "/")) {
  10725. + dest->root_dir = strdup(root_dir);
  10726. + } else {
  10727. + sprintf_alloc(&dest->root_dir, "%s/", root_dir);
  10728. + }
  10729. + file_mkdir_hier(dest->root_dir, 0755);
  10730. +
  10731. + sprintf_alloc(&dest->ipkg_dir, "%s%s",
  10732. + dest->root_dir, IPKG_STATE_DIR_PREFIX);
  10733. + file_mkdir_hier(dest->ipkg_dir, 0755);
  10734. +
  10735. + if (str_starts_with (lists_dir, "/"))
  10736. + sprintf_alloc(&dest->lists_dir, "%s", lists_dir);
  10737. + else
  10738. + sprintf_alloc(&dest->lists_dir, "/%s", lists_dir);
  10739. +
  10740. + file_mkdir_hier(dest->lists_dir, 0755);
  10741. +
  10742. + sprintf_alloc(&dest->info_dir, "%s/%s",
  10743. + dest->ipkg_dir, IPKG_INFO_DIR_SUFFIX);
  10744. + file_mkdir_hier(dest->info_dir, 0755);
  10745. +
  10746. + sprintf_alloc(&dest->status_file_name, "%s/%s",
  10747. + dest->ipkg_dir, IPKG_STATUS_FILE_SUFFIX);
  10748. +
  10749. + sprintf_alloc(&dest->status_file_tmp_name, "%s/%s.tmp",
  10750. + dest->ipkg_dir, IPKG_STATUS_FILE_SUFFIX);
  10751. +
  10752. + dest->status_file = NULL;
  10753. +
  10754. + return 0;
  10755. +}
  10756. +
  10757. +void pkg_dest_deinit(pkg_dest_t *dest)
  10758. +{
  10759. + free(dest->name);
  10760. + dest->name = NULL;
  10761. +
  10762. + free(dest->root_dir);
  10763. + dest->root_dir = NULL;
  10764. +
  10765. + free(dest->ipkg_dir);
  10766. + dest->ipkg_dir = NULL;
  10767. +
  10768. + free(dest->lists_dir);
  10769. + dest->lists_dir = NULL;
  10770. +
  10771. + free(dest->info_dir);
  10772. + dest->info_dir = NULL;
  10773. +
  10774. + free(dest->status_file_name);
  10775. + dest->status_file_name = NULL;
  10776. +
  10777. + free(dest->status_file_tmp_name);
  10778. + dest->status_file_tmp_name = NULL;
  10779. +
  10780. + if (dest->status_file) {
  10781. + fclose(dest->status_file);
  10782. + }
  10783. + dest->status_file = NULL;
  10784. +
  10785. + dest->root_dir = NULL;
  10786. +}
  10787. diff -Nur busybox-1.19.4.orig/archival/libipkg/pkg_dest.h busybox-1.19.4/archival/libipkg/pkg_dest.h
  10788. --- busybox-1.19.4.orig/archival/libipkg/pkg_dest.h 1970-01-01 01:00:00.000000000 +0100
  10789. +++ busybox-1.19.4/archival/libipkg/pkg_dest.h 2012-03-17 00:58:08.197100679 +0100
  10790. @@ -0,0 +1,38 @@
  10791. +/* pkg_dest.h - the itsy package management system
  10792. +
  10793. + Carl D. Worth
  10794. +
  10795. + Copyright (C) 2001 University of Southern California
  10796. +
  10797. + This program is free software; you can redistribute it and/or
  10798. + modify it under the terms of the GNU General Public License as
  10799. + published by the Free Software Foundation; either version 2, or (at
  10800. + your option) any later version.
  10801. +
  10802. + This program is distributed in the hope that it will be useful, but
  10803. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10804. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10805. + General Public License for more details.
  10806. +*/
  10807. +
  10808. +#ifndef PKG_DEST_H
  10809. +#define PKG_DEST_H
  10810. +
  10811. +typedef struct pkg_dest pkg_dest_t;
  10812. +struct pkg_dest
  10813. +{
  10814. + char *name;
  10815. + char *root_dir;
  10816. + char *ipkg_dir;
  10817. + char *lists_dir;
  10818. + char *info_dir;
  10819. + char *status_file_name;
  10820. + char *status_file_tmp_name;
  10821. + FILE *status_file;
  10822. +};
  10823. +
  10824. +int pkg_dest_init(pkg_dest_t *dest, const char *name, const char *root_dir,const char *lists_dir);
  10825. +void pkg_dest_deinit(pkg_dest_t *dest);
  10826. +
  10827. +#endif
  10828. +
  10829. diff -Nur busybox-1.19.4.orig/archival/libipkg/pkg_dest_list.c busybox-1.19.4/archival/libipkg/pkg_dest_list.c
  10830. --- busybox-1.19.4.orig/archival/libipkg/pkg_dest_list.c 1970-01-01 01:00:00.000000000 +0100
  10831. +++ busybox-1.19.4/archival/libipkg/pkg_dest_list.c 2012-03-17 00:58:08.197100679 +0100
  10832. @@ -0,0 +1,85 @@
  10833. +/* pkg_dest_list.c - the itsy package management system
  10834. +
  10835. + Carl D. Worth
  10836. +
  10837. + Copyright (C) 2001 University of Southern California
  10838. +
  10839. + This program is free software; you can redistribute it and/or
  10840. + modify it under the terms of the GNU General Public License as
  10841. + published by the Free Software Foundation; either version 2, or (at
  10842. + your option) any later version.
  10843. +
  10844. + This program is distributed in the hope that it will be useful, but
  10845. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10846. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10847. + General Public License for more details.
  10848. +*/
  10849. +
  10850. +#include "ipkg.h"
  10851. +
  10852. +#include "pkg_dest.h"
  10853. +#include "void_list.h"
  10854. +#include "pkg_dest_list.h"
  10855. +
  10856. +int pkg_dest_list_elt_init(pkg_dest_list_elt_t *elt, pkg_dest_t *data)
  10857. +{
  10858. + return void_list_elt_init((void_list_elt_t *) elt, data);
  10859. +}
  10860. +
  10861. +void pkg_dest_list_elt_deinit(pkg_dest_list_elt_t *elt)
  10862. +{
  10863. + void_list_elt_deinit((void_list_elt_t *) elt);
  10864. +}
  10865. +
  10866. +int pkg_dest_list_init(pkg_dest_list_t *list)
  10867. +{
  10868. + return void_list_init((void_list_t *) list);
  10869. +}
  10870. +
  10871. +void pkg_dest_list_deinit(pkg_dest_list_t *list)
  10872. +{
  10873. + pkg_dest_list_elt_t *iter;
  10874. + pkg_dest_t *pkg_dest;
  10875. +
  10876. + for (iter = list->head; iter; iter = iter->next) {
  10877. + pkg_dest = iter->data;
  10878. + pkg_dest_deinit(pkg_dest);
  10879. +
  10880. + /* malloced in pkg_dest_list_append */
  10881. + free(pkg_dest);
  10882. + iter->data = NULL;
  10883. + }
  10884. + void_list_deinit((void_list_t *) list);
  10885. +}
  10886. +
  10887. +pkg_dest_t *pkg_dest_list_append(pkg_dest_list_t *list, const char *name,
  10888. + const char *root_dir,const char *lists_dir)
  10889. +{
  10890. + int err;
  10891. + pkg_dest_t *pkg_dest;
  10892. +
  10893. + /* freed in plg_dest_list_deinit */
  10894. + pkg_dest = malloc(sizeof(pkg_dest_t));
  10895. + if (pkg_dest == NULL) {
  10896. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10897. + return NULL;
  10898. + }
  10899. +
  10900. + pkg_dest_init(pkg_dest, name, root_dir,lists_dir);
  10901. + err = void_list_append((void_list_t *) list, pkg_dest);
  10902. + if (err) {
  10903. + return NULL;
  10904. + }
  10905. +
  10906. + return pkg_dest;
  10907. +}
  10908. +
  10909. +int pkg_dest_list_push(pkg_dest_list_t *list, pkg_dest_t *data)
  10910. +{
  10911. + return void_list_push((void_list_t *) list, data);
  10912. +}
  10913. +
  10914. +pkg_dest_list_elt_t *pkg_dest_list_pop(pkg_dest_list_t *list)
  10915. +{
  10916. + return (pkg_dest_list_elt_t *) void_list_pop((void_list_t *) list);
  10917. +}
  10918. diff -Nur busybox-1.19.4.orig/archival/libipkg/pkg_dest_list.h busybox-1.19.4/archival/libipkg/pkg_dest_list.h
  10919. --- busybox-1.19.4.orig/archival/libipkg/pkg_dest_list.h 1970-01-01 01:00:00.000000000 +0100
  10920. +++ busybox-1.19.4/archival/libipkg/pkg_dest_list.h 2012-03-17 00:58:08.197100679 +0100
  10921. @@ -0,0 +1,50 @@
  10922. +/* pkg_dest_list.h - the itsy package management system
  10923. +
  10924. + Carl D. Worth
  10925. +
  10926. + Copyright (C) 2001 University of Southern California
  10927. +
  10928. + This program is free software; you can redistribute it and/or
  10929. + modify it under the terms of the GNU General Public License as
  10930. + published by the Free Software Foundation; either version 2, or (at
  10931. + your option) any later version.
  10932. +
  10933. + This program is distributed in the hope that it will be useful, but
  10934. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10935. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10936. + General Public License for more details.
  10937. +*/
  10938. +
  10939. +#ifndef PKG_DEST_LIST_H
  10940. +#define PKG_DEST_LIST_H
  10941. +
  10942. +#include "pkg_dest.h"
  10943. +
  10944. +typedef struct pkg_dest_list_elt pkg_dest_list_elt_t;
  10945. +struct pkg_dest_list_elt
  10946. +{
  10947. + pkg_dest_list_elt_t *next;
  10948. + pkg_dest_t *data;
  10949. +};
  10950. +
  10951. +typedef struct pkg_dest_list pkg_dest_list_t;
  10952. +struct pkg_dest_list
  10953. +{
  10954. + pkg_dest_list_elt_t pre_head;
  10955. + pkg_dest_list_elt_t *head;
  10956. + pkg_dest_list_elt_t *tail;
  10957. +};
  10958. +
  10959. +int pkg_dest_list_elt_init(pkg_dest_list_elt_t *elt, pkg_dest_t *data);
  10960. +void pkg_dest_list_elt_deinit(pkg_dest_list_elt_t *elt);
  10961. +
  10962. +int pkg_dest_list_init(pkg_dest_list_t *list);
  10963. +void pkg_dest_list_deinit(pkg_dest_list_t *list);
  10964. +
  10965. +pkg_dest_t *pkg_dest_list_append(pkg_dest_list_t *list, const char *name,
  10966. + const char *root_dir,const char* lists_dir);
  10967. +int pkg_dest_list_push(pkg_dest_list_t *list, pkg_dest_t *data);
  10968. +pkg_dest_list_elt_t *pkg_dest_list_pop(pkg_dest_list_t *list);
  10969. +
  10970. +#endif
  10971. +
  10972. diff -Nur busybox-1.19.4.orig/archival/libipkg/pkg_extract.c busybox-1.19.4/archival/libipkg/pkg_extract.c
  10973. --- busybox-1.19.4.orig/archival/libipkg/pkg_extract.c 1970-01-01 01:00:00.000000000 +0100
  10974. +++ busybox-1.19.4/archival/libipkg/pkg_extract.c 2012-03-17 00:58:08.197100679 +0100
  10975. @@ -0,0 +1,255 @@
  10976. +/* pkg_extract.c - the itsy package management system
  10977. +
  10978. + Carl D. Worth
  10979. +
  10980. + Copyright (C) 2001 University of Southern California
  10981. +
  10982. + This program is free software; you can redistribute it and/or
  10983. + modify it under the terms of the GNU General Public License as
  10984. + published by the Free Software Foundation; either version 2, or (at
  10985. + your option) any later version.
  10986. +
  10987. + This program is distributed in the hope that it will be useful, but
  10988. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10989. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10990. + General Public License for more details.
  10991. +*/
  10992. +
  10993. +#include "ipkg.h"
  10994. +#include <errno.h>
  10995. +#include <fcntl.h>
  10996. +#include <stdio.h>
  10997. +
  10998. +#include "pkg_extract.h"
  10999. +
  11000. +#include "libbb.h"
  11001. +#include "file_util.h"
  11002. +#include "sprintf_alloc.h"
  11003. +#include "archive.h"
  11004. +
  11005. +#define IPKG_CONTROL_ARCHIVE "control.tar.gz"
  11006. +#define IPKG_DATA_ARCHIVE "data.tar.gz"
  11007. +#define IPKG_CONTROL_FILE "control"
  11008. +
  11009. +static void FAST_FUNC ipkg_data_extract_all_prefix(archive_handle_t *archive_handle)
  11010. +{
  11011. + char *name_ptr = archive_handle->file_header->name;
  11012. +
  11013. + /* Skip all leading "/" */
  11014. + while (*name_ptr == '/')
  11015. + name_ptr++;
  11016. + /* Skip all leading "./" and "../" */
  11017. + while (name_ptr[0] == '.') {
  11018. + if (name_ptr[1] == '.' && name_ptr[2] == '/')
  11019. + name_ptr++;
  11020. + if (name_ptr[1] != '/')
  11021. + break;
  11022. + name_ptr += 2;
  11023. + }
  11024. +
  11025. + if (name_ptr[0] != '\0') {
  11026. + archive_handle->file_header->name = xasprintf("%s%s", archive_handle->dpkg__buffer, name_ptr);
  11027. + data_extract_all(archive_handle);
  11028. + }
  11029. +}
  11030. +
  11031. +static void FAST_FUNC ipkg_data_extract_to_buffer(archive_handle_t *archive_handle)
  11032. +{
  11033. + unsigned size = archive_handle->file_header->size;
  11034. +
  11035. + archive_handle->dpkg__buffer = xzalloc(size + 1);
  11036. + xread(archive_handle->src_fd, archive_handle->dpkg__buffer, size);
  11037. +}
  11038. +
  11039. +static void extract_ipkg_file_to_dir(pkg_t *pkg, const char *dir, const char *filename)
  11040. +{
  11041. + archive_handle_t *archive;
  11042. + char *path;
  11043. +
  11044. + sprintf_alloc(&path, "%s/", dir);
  11045. + archive = init_handle();
  11046. + archive->src_fd = xopen(pkg->local_filename, O_RDONLY);
  11047. + archive->filter = filter_accept_list;
  11048. + llist_add_to(&(archive->accept), (char *)filename);
  11049. + archive->dpkg__buffer = path;
  11050. + archive->action_data = ipkg_data_extract_all_prefix;
  11051. + archive->ah_flags |= ARCHIVE_UNLINK_OLD;
  11052. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  11053. + close(archive->src_fd);
  11054. + free(archive->accept);
  11055. + free(archive);
  11056. + free(path);
  11057. +}
  11058. +
  11059. +static void FAST_FUNC data_extract_file_name_to_buffer(archive_handle_t *archive)
  11060. +{
  11061. + unsigned int size = strlen(archive->file_header->name) + 2;
  11062. +
  11063. + if (archive->dpkg__buffer == NULL) {
  11064. + archive->dpkg__buffer = xmalloc(size);
  11065. + strcpy(archive->dpkg__buffer, archive->file_header->name);
  11066. + } else {
  11067. + size += strlen(archive->dpkg__buffer);
  11068. + archive->dpkg__buffer = xrealloc(archive->dpkg__buffer, size);
  11069. + strcat(archive->dpkg__buffer, archive->file_header->name);
  11070. + }
  11071. + strcat(archive->dpkg__buffer, "\n");
  11072. + data_skip(archive);
  11073. +}
  11074. +
  11075. +int pkg_extract_control_file_to_stream(pkg_t *pkg, FILE *stream)
  11076. +{
  11077. + archive_handle_t *archive;
  11078. + char *name;
  11079. + const char *filename = IPKG_CONTROL_FILE;
  11080. +
  11081. + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_CONTROL_ARCHIVE);
  11082. + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_CONTROL_ARCHIVE);
  11083. + archive = init_handle();
  11084. + archive->src_fd = xopen(name, O_RDONLY);
  11085. + archive->filter = filter_accept_list;
  11086. + llist_add_to(&(archive->accept), (char *)filename);
  11087. + archive->action_data = ipkg_data_extract_to_buffer;
  11088. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  11089. + close(archive->src_fd);
  11090. + fputs(archive->dpkg__buffer, stream);
  11091. + free(archive->dpkg__buffer);
  11092. + free(archive->accept);
  11093. + free(archive);
  11094. + free(name);
  11095. +
  11096. + return 0;
  11097. +}
  11098. +
  11099. +int pkg_extract_control_files_to_dir(pkg_t *pkg, const char *dir)
  11100. +{
  11101. + return pkg_extract_control_files_to_dir_with_prefix(pkg, dir, "");
  11102. +}
  11103. +
  11104. +int pkg_extract_control_files_to_dir_with_prefix(pkg_t *pkg, const char *dir, const char *prefix)
  11105. +{
  11106. + archive_handle_t *archive;
  11107. + char *name;
  11108. + char *path;
  11109. +
  11110. + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_CONTROL_ARCHIVE);
  11111. + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_CONTROL_ARCHIVE);
  11112. + sprintf_alloc(&path, "%s/%s", dir, prefix);
  11113. + archive = init_handle();
  11114. + archive->src_fd = xopen(name, O_RDONLY);
  11115. + archive->filter = filter_accept_all;
  11116. + archive->dpkg__buffer = path;
  11117. + archive->action_data = ipkg_data_extract_all_prefix;
  11118. + archive->ah_flags |= ARCHIVE_CREATE_LEADING_DIRS | ARCHIVE_RESTORE_DATE | ARCHIVE_UNLINK_OLD;
  11119. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  11120. + close(archive->src_fd);
  11121. + free(archive);
  11122. + free(path);
  11123. + free(name);
  11124. +
  11125. + return 0;
  11126. +}
  11127. +
  11128. +int pkg_extract_data_files_to_dir(pkg_t *pkg, const char *dir)
  11129. +{
  11130. + archive_handle_t *archive;
  11131. + char *name;
  11132. + char *path;
  11133. +
  11134. + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_DATA_ARCHIVE);
  11135. + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_DATA_ARCHIVE);
  11136. + sprintf_alloc(&path, "%s/", dir);
  11137. + archive = init_handle();
  11138. + archive->src_fd = xopen(name, O_RDONLY);
  11139. + archive->filter = filter_accept_all;
  11140. + archive->dpkg__buffer = path;
  11141. + archive->action_data = ipkg_data_extract_all_prefix;
  11142. + archive->ah_flags |= ARCHIVE_CREATE_LEADING_DIRS | ARCHIVE_RESTORE_DATE | ARCHIVE_UNLINK_OLD;
  11143. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  11144. + close(archive->src_fd);
  11145. + free(archive);
  11146. + free(path);
  11147. + free(name);
  11148. +
  11149. + return 0;
  11150. +}
  11151. +
  11152. +int pkg_extract_data_file_names_to_file(pkg_t *pkg, const char *file_name)
  11153. +{
  11154. + int err=0;
  11155. + char *line, *data_file;
  11156. + FILE *file;
  11157. + FILE *tmp;
  11158. +
  11159. + file = fopen(file_name, "w");
  11160. + if (file == NULL) {
  11161. + fprintf(stderr, "%s: ERROR: Failed to open %s for writing.\n",
  11162. + __FUNCTION__, file_name);
  11163. + return EINVAL;
  11164. + }
  11165. +
  11166. + tmp = tmpfile();
  11167. + if (pkg->installed_files) {
  11168. + str_list_elt_t *elt;
  11169. + for (elt = pkg->installed_files->head; elt; elt = elt->next) {
  11170. + fprintf(file, "%s\n", elt->data);
  11171. + }
  11172. + } else {
  11173. + err = pkg_extract_data_file_names_to_stream(pkg, tmp);
  11174. + if (err) {
  11175. + fclose(file);
  11176. + fclose(tmp);
  11177. + return err;
  11178. + }
  11179. +
  11180. + /* Fixup data file names by removing the initial '.' */
  11181. + rewind(tmp);
  11182. + while (1) {
  11183. + line = file_read_line_alloc(tmp);
  11184. + if (line == NULL) {
  11185. + break;
  11186. + }
  11187. +
  11188. + data_file = line;
  11189. + if (*data_file == '.') {
  11190. + data_file++;
  11191. + }
  11192. +
  11193. + if (*data_file != '/') {
  11194. + fputs("/", file);
  11195. + }
  11196. +
  11197. + /* I have no idea why, but this is what dpkg does */
  11198. + if (strcmp(data_file, "/\n") == 0) {
  11199. + fputs("/.\n", file);
  11200. + } else {
  11201. + fputs(data_file, file);
  11202. + }
  11203. + }
  11204. + }
  11205. + fclose(tmp);
  11206. + fclose(file);
  11207. +
  11208. + return err;
  11209. +}
  11210. +
  11211. +int pkg_extract_data_file_names_to_stream(pkg_t *pkg, FILE *file)
  11212. +{
  11213. + archive_handle_t *archive;
  11214. + char *name;
  11215. +
  11216. + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_DATA_ARCHIVE);
  11217. + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_DATA_ARCHIVE);
  11218. + archive = init_handle();
  11219. + archive->src_fd = xopen(name, O_RDONLY);
  11220. + archive->filter = filter_accept_all;
  11221. + archive->action_data = data_extract_file_name_to_buffer;
  11222. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  11223. + close(archive->src_fd);
  11224. + fputs(archive->dpkg__buffer, file);
  11225. + free(archive->dpkg__buffer);
  11226. + free(archive);
  11227. + free(name);
  11228. +
  11229. + return 0;
  11230. +}
  11231. diff -Nur busybox-1.19.4.orig/archival/libipkg/pkg_extract.h busybox-1.19.4/archival/libipkg/pkg_extract.h
  11232. --- busybox-1.19.4.orig/archival/libipkg/pkg_extract.h 1970-01-01 01:00:00.000000000 +0100
  11233. +++ busybox-1.19.4/archival/libipkg/pkg_extract.h 2012-03-17 00:58:08.197100679 +0100
  11234. @@ -0,0 +1,32 @@
  11235. +/* pkg_extract.c - the itsy package management system
  11236. +
  11237. + Carl D. Worth
  11238. +
  11239. + Copyright (C) 2001 University of Southern California
  11240. +
  11241. + This program is free software; you can redistribute it and/or
  11242. + modify it under the terms of the GNU General Public License as
  11243. + published by the Free Software Foundation; either version 2, or (at
  11244. + your option) any later version.
  11245. +
  11246. + This program is distributed in the hope that it will be useful, but
  11247. + WITHOUT ANY WARRANTY; without even the implied warranty of
  11248. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11249. + General Public License for more details.
  11250. +*/
  11251. +
  11252. +#ifndef PKG_EXTRACT_H
  11253. +#define PKG_EXTRACT_H
  11254. +
  11255. +#include "pkg.h"
  11256. +
  11257. +int pkg_extract_control_file_to_stream(pkg_t *pkg, FILE *stream);
  11258. +int pkg_extract_control_files_to_dir(pkg_t *pkg, const char *dir);
  11259. +int pkg_extract_control_files_to_dir_with_prefix(pkg_t *pkg,
  11260. + const char *dir,
  11261. + const char *prefix);
  11262. +int pkg_extract_data_files_to_dir(pkg_t *pkg, const char *dir);
  11263. +int pkg_extract_data_file_names_to_file(pkg_t *pkg, const char *file_name);
  11264. +int pkg_extract_data_file_names_to_stream(pkg_t *pkg, FILE *file);
  11265. +
  11266. +#endif
  11267. diff -Nur busybox-1.19.4.orig/archival/libipkg/pkg_hash.c busybox-1.19.4/archival/libipkg/pkg_hash.c
  11268. --- busybox-1.19.4.orig/archival/libipkg/pkg_hash.c 1970-01-01 01:00:00.000000000 +0100
  11269. +++ busybox-1.19.4/archival/libipkg/pkg_hash.c 2012-03-17 00:58:08.197100679 +0100
  11270. @@ -0,0 +1,623 @@
  11271. +/* ipkg_hash.c - the itsy package management system
  11272. +
  11273. + Steven M. Ayer
  11274. +
  11275. + Copyright (C) 2002 Compaq Computer Corporation
  11276. +
  11277. + This program is free software; you can redistribute it and/or
  11278. + modify it under the terms of the GNU General Public License as
  11279. + published by the Free Software Foundation; either version 2, or (at
  11280. + your option) any later version.
  11281. +
  11282. + This program is distributed in the hope that it will be useful, but
  11283. + WITHOUT ANY WARRANTY; without even the implied warranty of
  11284. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11285. + General Public License for more details.
  11286. +*/
  11287. +
  11288. +#include "ipkg.h"
  11289. +#include <errno.h>
  11290. +#include <ctype.h>
  11291. +#include <stdlib.h>
  11292. +#include <string.h>
  11293. +
  11294. +#include "hash_table.h"
  11295. +#include "pkg.h"
  11296. +#include "ipkg_message.h"
  11297. +#include "pkg_vec.h"
  11298. +#include "pkg_hash.h"
  11299. +#include "pkg_parse.h"
  11300. +#include "ipkg_utils.h"
  11301. +
  11302. +static abstract_pkg_t * add_new_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name);
  11303. +
  11304. +/*
  11305. + * this will talk to both feeds-lists files and installed status files
  11306. + * example api:
  11307. + *
  11308. + * hash_table_t hash;
  11309. + * pkg_hash_init(name, &hash, 1000);
  11310. + * pkg_hash_add_from_file(<feed filename>);
  11311. + *
  11312. + * the query function is just there as a shell to prove to me that this
  11313. + * sort of works, but isn't far from doing something useful
  11314. + *
  11315. + * -sma, 12/21/01
  11316. + * modified: CDW 3 Jan. 2002
  11317. + */
  11318. +
  11319. +
  11320. +
  11321. +int pkg_hash_init(const char *name, hash_table_t *hash, int len)
  11322. +{
  11323. + return hash_table_init(name, hash, len);
  11324. +}
  11325. +
  11326. +void pkg_hash_deinit(hash_table_t *hash)
  11327. +{
  11328. + hash_table_deinit(hash);
  11329. +}
  11330. +
  11331. +
  11332. +/* Find the default arch for a given package status file if none is given. */
  11333. +static char *pkg_get_default_arch(ipkg_conf_t *conf)
  11334. +{
  11335. + nv_pair_list_elt_t *l;
  11336. + const char *def_arch = HOST_CPU_STR; /* Default arch */
  11337. + int def_prio = 0; /* Other archs override this */
  11338. +
  11339. + l = conf->arch_list.head;
  11340. +
  11341. + while (l) {
  11342. + nv_pair_t *nv = l->data;
  11343. + int priority = strtol(nv->value, NULL, 0);
  11344. +
  11345. + /* Check if this arch has higher priority, and is valid */
  11346. + if ((priority > def_prio) &&
  11347. + (strcmp(nv->name, "all")) && (strcmp(nv->name, "noarch"))) {
  11348. + /* Our new default */
  11349. + def_prio = priority;
  11350. + def_arch = nv->name;
  11351. + }
  11352. + l = l->next;
  11353. + }
  11354. +
  11355. + return strdup(def_arch);
  11356. +}
  11357. +
  11358. +int pkg_hash_add_from_file(ipkg_conf_t *conf, const char *file_name,
  11359. + pkg_src_t *src, pkg_dest_t *dest, int is_status_file)
  11360. +{
  11361. + hash_table_t *hash = &conf->pkg_hash;
  11362. + char **raw;
  11363. + char **raw_start;
  11364. + pkg_t *pkg;
  11365. +
  11366. + raw = raw_start = read_raw_pkgs_from_file(file_name);
  11367. + if (!raw)
  11368. + return -ENOMEM;
  11369. +
  11370. + while(*raw){ /* don't worry, we'll increment raw in the parsing function */
  11371. + pkg = pkg_new();
  11372. + if (!pkg)
  11373. + return -ENOMEM;
  11374. +
  11375. + if (pkg_parse_raw(pkg, &raw, src, dest) == 0) {
  11376. + if (!pkg->architecture) {
  11377. + char *version_str = pkg_version_str_alloc(pkg);
  11378. + pkg->architecture = pkg_get_default_arch(conf);
  11379. + ipkg_message(conf, IPKG_ERROR, "Package %s version %s has no architecture specified, defaulting to %s.\n",
  11380. + pkg->name, version_str, pkg->architecture);
  11381. + free(version_str);
  11382. + }
  11383. + hash_insert_pkg(hash, pkg, is_status_file,conf);
  11384. + } else {
  11385. + free(pkg);
  11386. + }
  11387. + }
  11388. +
  11389. + /* XXX: CLEANUP: I'd like a cleaner interface for cleaning up
  11390. + memory after read_raw_pkgs_from_file */
  11391. + raw = raw_start;
  11392. + while (*raw) {
  11393. + free(*raw++);
  11394. + }
  11395. + free(raw_start);
  11396. + return 0;
  11397. +}
  11398. +
  11399. +abstract_pkg_t * abstract_pkg_fetch_by_name(hash_table_t * hash, const char * pkg_name)
  11400. +{
  11401. + return (abstract_pkg_t *)hash_table_get(hash, pkg_name);
  11402. +}
  11403. +
  11404. +abstract_pkg_vec_t *pkg_hash_fetch_all_installation_candidates(hash_table_t *hash, const char *name)
  11405. +{
  11406. + abstract_pkg_t *apkg = abstract_pkg_fetch_by_name(hash, name);
  11407. + if (apkg)
  11408. + return NULL;
  11409. + return apkg->provided_by;
  11410. +}
  11411. +
  11412. +
  11413. +pkg_t *pkg_hash_fetch_best_installation_candidate(ipkg_conf_t *conf, abstract_pkg_t *apkg,
  11414. + int (*constraint_fcn)(pkg_t *pkg, void *cdata), void *cdata, int quiet)
  11415. +{
  11416. + int i;
  11417. + int nprovides = 0;
  11418. + int nmatching = 0;
  11419. + pkg_vec_t *matching_pkgs = pkg_vec_alloc();
  11420. + abstract_pkg_vec_t *matching_apkgs = abstract_pkg_vec_alloc();
  11421. + abstract_pkg_vec_t *provided_apkg_vec;
  11422. + abstract_pkg_t **provided_apkgs;
  11423. + abstract_pkg_vec_t *providers = abstract_pkg_vec_alloc();
  11424. + pkg_t *latest_installed_parent = NULL;
  11425. + pkg_t *latest_matching = NULL;
  11426. + pkg_t *held_pkg = NULL;
  11427. + pkg_t *good_pkg_by_name = NULL;
  11428. +
  11429. + if (matching_apkgs == NULL || providers == NULL ||
  11430. + apkg == NULL || apkg->provided_by == NULL || (apkg->provided_by->len == 0))
  11431. + return NULL;
  11432. +
  11433. + ipkg_message(conf, IPKG_DEBUG, "best installation candidate for %s\n", apkg->name);
  11434. +
  11435. + provided_apkg_vec = apkg->provided_by;
  11436. + nprovides = provided_apkg_vec->len;
  11437. + provided_apkgs = provided_apkg_vec->pkgs;
  11438. + if (nprovides > 1)
  11439. + ipkg_message(conf, IPKG_DEBUG, " apkg=%s nprovides=%d\n", apkg->name, nprovides);
  11440. +
  11441. + /* accumulate all the providers */
  11442. + for (i = 0; i < nprovides; i++) {
  11443. + abstract_pkg_t *provider_apkg = provided_apkgs[i];
  11444. + ipkg_message(conf, IPKG_DEBUG, " adding %s to providers\n", provider_apkg->name);
  11445. + abstract_pkg_vec_insert(providers, provider_apkg);
  11446. + }
  11447. + nprovides = providers->len;
  11448. +
  11449. + for (i = 0; i < nprovides; i++) {
  11450. + abstract_pkg_t *provider_apkg = abstract_pkg_vec_get(providers, i);
  11451. + abstract_pkg_t *replacement_apkg = NULL;
  11452. + pkg_vec_t *vec;
  11453. +
  11454. + if (provider_apkg->replaced_by && provider_apkg->replaced_by->len) {
  11455. + replacement_apkg = provider_apkg->replaced_by->pkgs[0];
  11456. + if (provider_apkg->replaced_by->len > 1) {
  11457. + ipkg_message(conf, IPKG_NOTICE, "Multiple replacers for %s, using first one (%s)\n",
  11458. + provider_apkg->name, replacement_apkg->name);
  11459. + }
  11460. + }
  11461. +
  11462. + if (replacement_apkg)
  11463. + ipkg_message(conf, IPKG_DEBUG, " replacement_apkg=%s for provider_apkg=%s\n",
  11464. + replacement_apkg->name, provider_apkg->name);
  11465. +
  11466. + if (replacement_apkg && (replacement_apkg != provider_apkg)) {
  11467. + if (abstract_pkg_vec_contains(providers, replacement_apkg))
  11468. + continue;
  11469. + else
  11470. + provider_apkg = replacement_apkg;
  11471. + }
  11472. +
  11473. + if (!(vec = provider_apkg->pkgs)) {
  11474. + ipkg_message(conf, IPKG_DEBUG, " no pkgs for provider_apkg %s\n", provider_apkg->name);
  11475. + continue;
  11476. + }
  11477. +
  11478. +
  11479. + /* now check for supported architecture */
  11480. + {
  11481. + int max_count = 0;
  11482. + int j;
  11483. +
  11484. + /* count packages matching max arch priority and keep track of last one */
  11485. + for (j = 0; j < vec->len; j++) {
  11486. + pkg_t *maybe = vec->pkgs[j];
  11487. + ipkg_message(conf, IPKG_DEBUG, " %s arch=%s arch_priority=%d version=%s \n",
  11488. + maybe->name, maybe->architecture, maybe->arch_priority, maybe->version);
  11489. + if (maybe->arch_priority > 0) {
  11490. + max_count++;
  11491. + abstract_pkg_vec_insert(matching_apkgs, maybe->parent);
  11492. + pkg_vec_insert(matching_pkgs, maybe);
  11493. + }
  11494. + }
  11495. + }
  11496. + }
  11497. +
  11498. + if (matching_pkgs->len > 1)
  11499. + pkg_vec_sort(matching_pkgs, pkg_name_version_and_architecture_compare);
  11500. + if (matching_apkgs->len > 1)
  11501. + abstract_pkg_vec_sort(matching_pkgs, abstract_pkg_name_compare);
  11502. +
  11503. +/* Here it is usefull, if ( matching_apkgs->len > 1 ), to test if one of this matching packages has the same name of the
  11504. + needed package. In this case, I would return it for install, otherwise I will continue with the procedure */
  11505. +/* The problem is what to do when there are more than a mathing package, with the same name and several version ?
  11506. + Until now I always got the latest, but that breaks the downgrade option.
  11507. + If I stop at the first one, I would probably miss the new ones
  11508. + Maybe the way is to have some kind of flag somewhere, to see if the package been asked to install is from a file,
  11509. + or from a Packages feed.
  11510. + It it is from a file it always need to be checked whatever version I have in feeds or everywhere, according to force-down or whatever options*/
  11511. +/*Pigi*/
  11512. +
  11513. + for (i = 0; i < matching_pkgs->len; i++) {
  11514. + pkg_t *matching = matching_pkgs->pkgs[i];
  11515. + if (constraint_fcn(matching, cdata)) { /* We found it */
  11516. + ipkg_message(conf, IPKG_DEBUG, " Found a valid candidate for the install: %s %s \n", matching->name, matching->version) ;
  11517. + good_pkg_by_name = matching;
  11518. + if ( matching->provided_by_hand == 1 ) /* It has been provided by hand, so it is what user want */
  11519. + break;
  11520. + }
  11521. + }
  11522. +
  11523. +
  11524. + for (i = 0; i < matching_pkgs->len; i++) {
  11525. + pkg_t *matching = matching_pkgs->pkgs[i];
  11526. + latest_matching = matching;
  11527. + if (matching->parent->state_status == SS_INSTALLED || matching->parent->state_status == SS_UNPACKED)
  11528. + latest_installed_parent = matching;
  11529. + if (matching->state_flag & (SF_HOLD|SF_PREFER)) {
  11530. + if (held_pkg)
  11531. + ipkg_message(conf, IPKG_ERROR, "Multiple packages (%s and %s) providing same name marked HOLD or PREFER. Using latest.\n",
  11532. + held_pkg->name, matching->name);
  11533. + held_pkg = matching;
  11534. + }
  11535. + }
  11536. +
  11537. + if (!good_pkg_by_name && !held_pkg && !latest_installed_parent && matching_apkgs->len > 1 && !quiet) {
  11538. + ipkg_message(conf, IPKG_ERROR, "Package=%s, %d matching providers\n",
  11539. + apkg->name, matching_apkgs->len);
  11540. + for (i = 0; i < matching_apkgs->len; i++) {
  11541. + abstract_pkg_t *matching = matching_apkgs->pkgs[i];
  11542. + ipkg_message(conf, IPKG_ERROR, " %s\n", matching->name);
  11543. + }
  11544. + ipkg_message(conf, IPKG_ERROR, "Please select one with ipkg install or ipkg flag prefer\n");
  11545. + }
  11546. +
  11547. + if (matching_apkgs->len > 1 && conf->verbosity > 1) {
  11548. + ipkg_message(conf, IPKG_NOTICE, "%s: for apkg=%s, %d matching pkgs\n",
  11549. + __FUNCTION__, apkg->name, matching_pkgs->len);
  11550. + for (i = 0; i < matching_pkgs->len; i++) {
  11551. + pkg_t *matching = matching_pkgs->pkgs[i];
  11552. + ipkg_message(conf, IPKG_INFO, " %s %s %s\n",
  11553. + matching->name, matching->version, matching->architecture);
  11554. + }
  11555. + }
  11556. +
  11557. + nmatching = matching_apkgs->len;
  11558. +
  11559. + pkg_vec_free(matching_pkgs);
  11560. + abstract_pkg_vec_free(matching_apkgs);
  11561. + abstract_pkg_vec_free(providers);
  11562. +
  11563. + if (good_pkg_by_name) { /* We found a good candidate, we will install it */
  11564. + return good_pkg_by_name;
  11565. + }
  11566. + if (held_pkg) {
  11567. + ipkg_message(conf, IPKG_INFO, " using held package %s\n", held_pkg->name);
  11568. + return held_pkg;
  11569. + }
  11570. + if (latest_installed_parent) {
  11571. + ipkg_message(conf, IPKG_INFO, " using latest version of installed package %s\n", latest_installed_parent->name);
  11572. + return latest_installed_parent;
  11573. + }
  11574. + if (nmatching > 1) {
  11575. + ipkg_message(conf, IPKG_INFO, " no matching pkg out of matching_apkgs=%d\n", nmatching);
  11576. + return NULL;
  11577. + }
  11578. + if (latest_matching) {
  11579. + ipkg_message(conf, IPKG_INFO, " using latest matching %s %s %s\n",
  11580. + latest_matching->name, latest_matching->version, latest_matching->architecture);
  11581. + return latest_matching;
  11582. + }
  11583. + return NULL;
  11584. +}
  11585. +
  11586. +static int pkg_name_constraint_fcn(pkg_t *pkg, void *cdata)
  11587. +{
  11588. + const char *name = (const char *)cdata;
  11589. + if (strcmp(pkg->name, name) == 0)
  11590. + return 1;
  11591. + else
  11592. + return 0;
  11593. +}
  11594. +
  11595. +pkg_t *pkg_hash_fetch_best_installation_candidate_by_name(ipkg_conf_t *conf, const char *name)
  11596. +{
  11597. + hash_table_t *hash = &conf->pkg_hash;
  11598. + abstract_pkg_t *apkg = NULL;
  11599. +
  11600. + if (!(apkg = abstract_pkg_fetch_by_name(hash, name)))
  11601. + return NULL;
  11602. +
  11603. + return pkg_hash_fetch_best_installation_candidate(conf, apkg, pkg_name_constraint_fcn, apkg->name, 0);
  11604. +}
  11605. +
  11606. +
  11607. +pkg_t * pkg_hash_fetch_by_name_version(hash_table_t *hash,
  11608. + const char *pkg_name,
  11609. + const char * version)
  11610. +{
  11611. + pkg_vec_t * vec;
  11612. + register int i;
  11613. + char *version_str = NULL;
  11614. +
  11615. + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name)))
  11616. + return NULL;
  11617. +
  11618. + for(i = 0; i < vec->len; i++) {
  11619. + version_str = pkg_version_str_alloc(vec->pkgs[i]);
  11620. + if(!strcmp(version_str, version)) {
  11621. + free(version_str);
  11622. + break;
  11623. + }
  11624. + free(version_str);
  11625. + }
  11626. +
  11627. + if(i == vec->len)
  11628. + return NULL;
  11629. +
  11630. + return vec->pkgs[i];
  11631. +}
  11632. +
  11633. +pkg_t *pkg_hash_fetch_installed_by_name_dest(hash_table_t *hash,
  11634. + const char *pkg_name,
  11635. + pkg_dest_t *dest)
  11636. +{
  11637. + pkg_vec_t * vec;
  11638. + register int i;
  11639. +
  11640. + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name))) {
  11641. + return NULL;
  11642. + }
  11643. +
  11644. + for(i = 0; i < vec->len; i++)
  11645. + if((vec->pkgs[i]->state_status == SS_INSTALLED || vec->pkgs[i]->state_status == SS_UNPACKED) && vec->pkgs[i]->dest == dest) {
  11646. + return vec->pkgs[i];
  11647. + }
  11648. + return NULL;
  11649. +}
  11650. +
  11651. +pkg_t *pkg_hash_fetch_installed_by_name(hash_table_t *hash,
  11652. + const char *pkg_name)
  11653. +{
  11654. + pkg_vec_t * vec;
  11655. + register int i;
  11656. +
  11657. + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name))){
  11658. + return NULL;
  11659. + }
  11660. +
  11661. + for(i = 0; i < vec->len; i++)
  11662. + if (vec->pkgs[i]->state_status == SS_INSTALLED || vec->pkgs[i]->state_status == SS_UNPACKED){
  11663. + return vec->pkgs[i];
  11664. + }
  11665. +
  11666. + return NULL;
  11667. +}
  11668. +
  11669. +pkg_vec_t *pkg_vec_fetch_by_name(hash_table_t *hash, const char *pkg_name)
  11670. +{
  11671. + abstract_pkg_t * ab_pkg;
  11672. +
  11673. + if(!(ab_pkg = abstract_pkg_fetch_by_name(hash, pkg_name))){
  11674. + return NULL;
  11675. + }
  11676. +
  11677. + if (ab_pkg->pkgs) {
  11678. + return ab_pkg->pkgs;
  11679. + } else if (ab_pkg->provided_by) {
  11680. + abstract_pkg_t *abpkg = abstract_pkg_vec_get(ab_pkg->provided_by, 0);
  11681. + if (abpkg != NULL){
  11682. + return abpkg->pkgs;
  11683. + } else {
  11684. + return ab_pkg->pkgs;
  11685. + }
  11686. + } else {
  11687. + return NULL;
  11688. + }
  11689. +}
  11690. +
  11691. +static int pkg_compare_names(const void *p1, const void *p2)
  11692. +{
  11693. + const pkg_t *pkg1 = *(const pkg_t **)p1;
  11694. + const pkg_t *pkg2 = *(const pkg_t **)p2;
  11695. + if (pkg1->name == NULL)
  11696. + return 1;
  11697. + if (pkg2->name == NULL)
  11698. + return -1;
  11699. + return(strcmp(pkg1->name, pkg2->name));
  11700. +}
  11701. +
  11702. +
  11703. +static void pkg_hash_fetch_available_helper(const char *pkg_name, void *entry, void *data)
  11704. +{
  11705. + int j;
  11706. + const char *name;
  11707. + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
  11708. + pkg_vec_t *all = (pkg_vec_t *)data;
  11709. + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
  11710. + name = pkg_name;
  11711. + if (pkg_vec) {
  11712. + for (j = 0; j < pkg_vec->len; j++) {
  11713. + pkg_t *pkg = pkg_vec->pkgs[j];
  11714. + pkg_vec_insert(all, pkg);
  11715. + }
  11716. + }
  11717. +}
  11718. +
  11719. +void pkg_hash_fetch_available(hash_table_t *hash, pkg_vec_t *all)
  11720. +{
  11721. + hash_table_foreach(hash, pkg_hash_fetch_available_helper, all);
  11722. + qsort(all->pkgs, all->len, sizeof(pkg_t *), pkg_compare_names);
  11723. +}
  11724. +
  11725. +static void pkg_hash_fetch_all_installed_helper(const char *pkg_name, void *entry, void *data)
  11726. +{
  11727. + const char *name;
  11728. + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
  11729. + pkg_vec_t *all = (pkg_vec_t *)data;
  11730. + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
  11731. + int j;
  11732. + name = pkg_name;
  11733. + if (pkg_vec) {
  11734. + for (j = 0; j < pkg_vec->len; j++) {
  11735. + pkg_t *pkg = pkg_vec->pkgs[j];
  11736. + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) {
  11737. + pkg_vec_insert(all, pkg);
  11738. + }
  11739. + }
  11740. + }
  11741. +}
  11742. +void pkg_hash_fetch_all_installed(hash_table_t *hash, pkg_vec_t *all)
  11743. +{
  11744. + hash_table_foreach(hash, pkg_hash_fetch_all_installed_helper, all);
  11745. + qsort(all->pkgs, all->len, sizeof(void*), pkg_compare_names);
  11746. +}
  11747. +
  11748. +static void pkg_hash_dump_helper(const char *pkg_name, void *entry, void *data)
  11749. +{
  11750. + int i;
  11751. + pkg_t *pkg;
  11752. + const char *name;
  11753. + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
  11754. + ipkg_conf_t *conf = (ipkg_conf_t *)data;
  11755. + abstract_pkg_t ** dependents = ab_pkg->depended_upon_by;
  11756. + name = pkg_name;
  11757. + fprintf(stdout, "%s\n", ab_pkg->name);
  11758. + i = 0;
  11759. + if (dependents != NULL)
  11760. + while (dependents [i] != NULL)
  11761. + printf ("\tdepended upon by - %s\n", dependents [i ++]->name);
  11762. + dependents = ab_pkg->provided_by->pkgs;
  11763. + i = 0;
  11764. + if (dependents != NULL)
  11765. + while (dependents [i] != NULL && i < ab_pkg->provided_by->len)
  11766. + printf ("\tprovided by - %s\n", dependents [i ++]->name);
  11767. + pkg = pkg_hash_fetch_best_installation_candidate_by_name (conf, ab_pkg->name);
  11768. + if (pkg) {
  11769. + i = 0;
  11770. + while (i < pkg->depends_count)
  11771. + printf ("\tdepends on - %s\n", pkg->depends_str [i ++]);
  11772. + }
  11773. +}
  11774. +void pkg_hash_dump(hash_table_t *hash, void *data)
  11775. +{
  11776. +
  11777. + printf ("\n\n+=+%s+=+\n\n", __FUNCTION__);
  11778. + hash_table_foreach(hash, pkg_hash_dump_helper, data);
  11779. + printf ("\n+=+%s+=+\n\n", __FUNCTION__);
  11780. +}
  11781. +
  11782. +abstract_pkg_t * ensure_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name)
  11783. +{
  11784. + abstract_pkg_t * ab_pkg;
  11785. +
  11786. + if(!(ab_pkg = abstract_pkg_fetch_by_name(hash, pkg_name)))
  11787. + ab_pkg = add_new_abstract_pkg_by_name(hash, pkg_name);
  11788. +
  11789. + return ab_pkg;
  11790. +}
  11791. +
  11792. +pkg_t *hash_insert_pkg(hash_table_t *hash, pkg_t *pkg, int set_status,ipkg_conf_t *conf)
  11793. +{
  11794. + abstract_pkg_t * ab_pkg;
  11795. + int arch_priority;
  11796. +
  11797. + if(!pkg)
  11798. + return pkg;
  11799. +
  11800. + arch_priority = pkg->arch_priority;
  11801. +
  11802. + if (buildDepends(hash, pkg)<0){
  11803. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  11804. + return NULL;
  11805. + }
  11806. + ab_pkg = ensure_abstract_pkg_by_name(hash, pkg->name);
  11807. +
  11808. + if (set_status) {
  11809. + if (pkg->state_status == SS_INSTALLED) {
  11810. + ab_pkg->state_status = SS_INSTALLED;
  11811. + } else if (pkg->state_status == SS_UNPACKED) {
  11812. + ab_pkg->state_status = SS_UNPACKED;
  11813. + }
  11814. + }
  11815. +
  11816. + if(!ab_pkg->pkgs)
  11817. + ab_pkg->pkgs = pkg_vec_alloc();
  11818. +
  11819. + /* pkg_vec_insert_merge might munge package, but it returns an unmunged pkg */
  11820. + pkg = pkg_vec_insert_merge(ab_pkg->pkgs, pkg, set_status,conf );
  11821. + pkg->parent = ab_pkg;
  11822. +
  11823. + if (buildProvides(hash, ab_pkg, pkg)<0){
  11824. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  11825. + return NULL;
  11826. + }
  11827. + /* need to build the conflicts graph before replaces for correct calculation of replaced_by relation */
  11828. + if (buildConflicts(hash, pkg)<0){
  11829. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  11830. + return NULL;
  11831. + }
  11832. + if (buildReplaces(hash, ab_pkg, pkg)<0) {
  11833. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  11834. + return NULL;
  11835. + }
  11836. +
  11837. + buildDependedUponBy(pkg, ab_pkg);
  11838. + return pkg;
  11839. +}
  11840. +
  11841. +/*
  11842. + * this will assume that we've already determined that
  11843. + * the abstract pkg doesn't exist, 'cause we should know these things...
  11844. + */
  11845. +static abstract_pkg_t * add_new_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name)
  11846. +{
  11847. + abstract_pkg_t * ab_pkg;
  11848. +
  11849. + ab_pkg = abstract_pkg_new();
  11850. + if (ab_pkg == NULL) { return NULL; }
  11851. +
  11852. + ab_pkg->name = strdup(pkg_name);
  11853. + hash_table_insert(hash, pkg_name, ab_pkg);
  11854. +
  11855. + return ab_pkg;
  11856. +}
  11857. +
  11858. +
  11859. +pkg_t *file_hash_get_file_owner(ipkg_conf_t *conf, const char *file_name)
  11860. +{
  11861. + hash_table_t *file_hash = &conf->file_hash;
  11862. +
  11863. + return hash_table_get(file_hash, file_name);
  11864. +}
  11865. +
  11866. +int file_hash_set_file_owner(ipkg_conf_t *conf, const char *file_name, pkg_t *owning_pkg)
  11867. +{
  11868. + hash_table_t *file_hash = &conf->file_hash;
  11869. + pkg_t *old_owning_pkg = hash_table_get(file_hash, file_name);
  11870. + int file_name_len = strlen(file_name);
  11871. +
  11872. + if (file_name[file_name_len -1] == '/')
  11873. + return 0;
  11874. +
  11875. + if (conf->offline_root) {
  11876. + int len = strlen(conf->offline_root);
  11877. + if (strncmp(file_name, conf->offline_root, len) == 0) {
  11878. + file_name += len;
  11879. + }
  11880. + }
  11881. +
  11882. + // ipkg_message(conf, IPKG_DEBUG2, "owning_pkg=%s filename=%s\n", owning_pkg->name, file_name);
  11883. + hash_table_insert(file_hash, file_name, owning_pkg);
  11884. + if (old_owning_pkg) {
  11885. + str_list_remove_elt(old_owning_pkg->installed_files, file_name);
  11886. + /* mark this package to have its filelist written */
  11887. + old_owning_pkg->state_flag |= SF_FILELIST_CHANGED;
  11888. + owning_pkg->state_flag |= SF_FILELIST_CHANGED;
  11889. + }
  11890. + return 0;
  11891. +}
  11892. +
  11893. +
  11894. diff -Nur busybox-1.19.4.orig/archival/libipkg/pkg_hash.h busybox-1.19.4/archival/libipkg/pkg_hash.h
  11895. --- busybox-1.19.4.orig/archival/libipkg/pkg_hash.h 1970-01-01 01:00:00.000000000 +0100
  11896. +++ busybox-1.19.4/archival/libipkg/pkg_hash.h 2012-03-17 00:58:08.197100679 +0100
  11897. @@ -0,0 +1,61 @@
  11898. +/* pkg_hash.h - the itsy package management system
  11899. +
  11900. + Steven M. Ayer
  11901. +
  11902. + Copyright (C) 2002 Compaq Computer Corporation
  11903. +
  11904. + This program is free software; you can redistribute it and/or
  11905. + modify it under the terms of the GNU General Public License as
  11906. + published by the Free Software Foundation; either version 2, or (at
  11907. + your option) any later version.
  11908. +
  11909. + This program is distributed in the hope that it will be useful, but
  11910. + WITHOUT ANY WARRANTY; without even the implied warranty of
  11911. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11912. + General Public License for more details.
  11913. +*/
  11914. +
  11915. +#ifndef PKG_HASH_H
  11916. +#define PKG_HASH_H
  11917. +
  11918. +#include "pkg.h"
  11919. +#include "pkg_vec.h"
  11920. +#include "hash_table.h"
  11921. +
  11922. +
  11923. +int pkg_hash_init(const char *name, hash_table_t *hash, int len);
  11924. +void pkg_hash_deinit(hash_table_t *hash);
  11925. +void pkg_hash_map(hash_table_t *hash, void (*f)(void *data, void *entry), void *data);
  11926. +
  11927. +void pkg_hash_dump(hash_table_t *hash, void *data);
  11928. +void pkg_hash_fetch_available(hash_table_t *hash, pkg_vec_t *available);
  11929. +
  11930. +int pkg_hash_add_from_file(ipkg_conf_t *conf, const char *file_name,
  11931. + pkg_src_t *src, pkg_dest_t *dest, int is_status_file);
  11932. +pkg_t *hash_insert_pkg(hash_table_t *hash, pkg_t *pkg, int set_status,ipkg_conf_t *conf);
  11933. +
  11934. +abstract_pkg_t * ensure_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name);
  11935. +abstract_pkg_t * abstract_pkg_fetch_by_name(hash_table_t * hash, const char * pkg_name);
  11936. +pkg_vec_t *pkg_hash_fetch_by_name(hash_table_t *hash, const char *pkg_name);
  11937. +void pkg_hash_fetch_all_installed(hash_table_t *hash, pkg_vec_t *installed);
  11938. +pkg_t * pkg_hash_fetch_by_name_version(hash_table_t *hash,
  11939. + const char *pkg_name,
  11940. + const char * version);
  11941. +abstract_pkg_vec_t *pkg_hash_fetch_all_installation_candidates(hash_table_t *hash, const char *name);
  11942. +pkg_t *pkg_hash_fetch_best_installation_candidate(ipkg_conf_t *conf, abstract_pkg_t *apkg,
  11943. + int (*constraint_fcn)(pkg_t *pkg, void *data), void *cdata, int quiet);
  11944. +pkg_t *pkg_hash_fetch_best_installation_candidate_by_name(ipkg_conf_t *conf, const char *name);
  11945. +pkg_t *pkg_hash_fetch_installed_by_name(hash_table_t *hash,
  11946. + const char *pkg_name);
  11947. +pkg_t *pkg_hash_fetch_installed_by_name_dest(hash_table_t *hash,
  11948. + const char *pkg_name,
  11949. + pkg_dest_t *dest);
  11950. +
  11951. +pkg_t *file_hash_get_file_owner(ipkg_conf_t *conf, const char *file_name);
  11952. +int file_hash_set_file_owner(ipkg_conf_t *conf, const char *file_name, pkg_t *pkg);
  11953. +
  11954. +/* XXX: shouldn't this go in pkg_vec.[ch]? */
  11955. +pkg_vec_t *pkg_vec_fetch_by_name(hash_table_t *hash, const char *pkg_name);
  11956. +
  11957. +#endif
  11958. +
  11959. diff -Nur busybox-1.19.4.orig/archival/libipkg/pkg_parse.c busybox-1.19.4/archival/libipkg/pkg_parse.c
  11960. --- busybox-1.19.4.orig/archival/libipkg/pkg_parse.c 1970-01-01 01:00:00.000000000 +0100
  11961. +++ busybox-1.19.4/archival/libipkg/pkg_parse.c 2012-03-17 00:58:08.197100679 +0100
  11962. @@ -0,0 +1,368 @@
  11963. +/* pkg_parse.c - the itsy package management system
  11964. +
  11965. + Steven M. Ayer
  11966. +
  11967. + Copyright (C) 2002 Compaq Computer Corporation
  11968. +
  11969. + This program is free software; you can redistribute it and/or
  11970. + modify it under the terms of the GNU General Public License as
  11971. + published by the Free Software Foundation; either version 2, or (at
  11972. + your option) any later version.
  11973. +
  11974. + This program is distributed in the hope that it will be useful, but
  11975. + WITHOUT ANY WARRANTY; without even the implied warranty of
  11976. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11977. + General Public License for more details.
  11978. +*/
  11979. +
  11980. +#include "ipkg.h"
  11981. +#include <errno.h>
  11982. +#include <ctype.h>
  11983. +
  11984. +#include "pkg.h"
  11985. +#include "ipkg_utils.h"
  11986. +#include "pkg_parse.h"
  11987. +
  11988. +int alterProvidesLine(char *raw, char *temp);
  11989. +
  11990. +int isGenericFieldType(char * type, char * line)
  11991. +{
  11992. + if(!strncmp(line, type, strlen(type)))
  11993. + return 1;
  11994. + return 0;
  11995. +}
  11996. +
  11997. +char * parseGenericFieldType(char * type, char * raw)
  11998. +{
  11999. + char * field_value = raw + (strlen(type) + 1);
  12000. + return trim_alloc(field_value);
  12001. +}
  12002. +
  12003. +void parseStatus(pkg_t *pkg, char * raw)
  12004. +{
  12005. + char sw_str[64], sf_str[64], ss_str[64];
  12006. +
  12007. + sscanf(raw, "Status: %s %s %s", sw_str, sf_str, ss_str);
  12008. + pkg->state_want = pkg_state_want_from_str(sw_str);
  12009. + pkg->state_flag = pkg_state_flag_from_str(sf_str);
  12010. + pkg->state_status = pkg_state_status_from_str(ss_str);
  12011. +}
  12012. +
  12013. +char ** parseDependsString(char * raw, int * depends_count)
  12014. +{
  12015. + char ** depends = NULL;
  12016. + int line_count = 0;
  12017. + char buff[2048], * dest;
  12018. +
  12019. + while(raw && *raw && !isspace(*raw)) {
  12020. + raw++;
  12021. + }
  12022. +
  12023. + if(line_is_blank(raw)){
  12024. + *depends_count = line_count;
  12025. + return NULL;
  12026. + }
  12027. + while(raw && *raw){
  12028. + depends = (char **)realloc(depends, sizeof(char *) * (line_count + 1));
  12029. +
  12030. + while(isspace(*raw)) raw++;
  12031. +
  12032. + dest = buff;
  12033. + while((*raw != ',') && *raw)
  12034. + *dest++ = *raw++;
  12035. +
  12036. + *dest = '\0';
  12037. + depends[line_count] = trim_alloc(buff);
  12038. + if(depends[line_count] ==NULL)
  12039. + return NULL;
  12040. + line_count++;
  12041. + if(*raw == ',')
  12042. + raw++;
  12043. + }
  12044. + *depends_count = line_count;
  12045. + return depends;
  12046. +}
  12047. +
  12048. +void parseConffiles(pkg_t * pkg, char * raw)
  12049. +{
  12050. + char file_name[1048], md5sum[1048]; /* please tell me there aren't any longer that 1k */
  12051. +
  12052. + if(!strncmp(raw, "Conffiles:", 10))
  12053. + raw += strlen("Conffiles:");
  12054. +
  12055. + while(*raw && (sscanf(raw, "%s%s", file_name, md5sum) == 2)){
  12056. + conffile_list_append(&pkg->conffiles, file_name, md5sum);
  12057. + /* fprintf(stderr, "%s %s ", file_name, md5sum);*/
  12058. + while (*raw && isspace(*raw)) {
  12059. + raw++;
  12060. + }
  12061. + raw += strlen(file_name);
  12062. + while (*raw && isspace(*raw)) {
  12063. + raw++;
  12064. + }
  12065. + raw += strlen(md5sum);
  12066. + }
  12067. +}
  12068. +
  12069. +int parseVersion(pkg_t *pkg, char *raw)
  12070. +{
  12071. + char *colon, *eepochcolon;
  12072. +#ifdef USE_DEBVERSION
  12073. + char *hyphen;
  12074. +#endif
  12075. + unsigned long epoch;
  12076. +
  12077. + if (!*raw) {
  12078. + fprintf(stderr, "%s: ERROR: version string is empty", __FUNCTION__);
  12079. + return EINVAL;
  12080. + }
  12081. +
  12082. + if (strncmp(raw, "Version:", 8) == 0) {
  12083. + raw += 8;
  12084. + }
  12085. + while (*raw && isspace(*raw)) {
  12086. + raw++;
  12087. + }
  12088. +
  12089. + colon= strchr(raw,':');
  12090. + if (colon) {
  12091. + epoch= strtoul(raw,&eepochcolon,10);
  12092. + if (colon != eepochcolon) {
  12093. + fprintf(stderr, "%s: ERROR: epoch in version is not number", __FUNCTION__);
  12094. + return EINVAL;
  12095. + }
  12096. + if (!*++colon) {
  12097. + fprintf(stderr, "%s: ERROR: nothing after colon in version number", __FUNCTION__);
  12098. + return EINVAL;
  12099. + }
  12100. + raw= colon;
  12101. + pkg->epoch= epoch;
  12102. + } else {
  12103. + pkg->epoch= 0;
  12104. + }
  12105. +
  12106. + pkg->revision = (char *)"";
  12107. + pkg->familiar_revision = (char *)"";
  12108. +
  12109. + pkg->version= malloc(strlen(raw)+1);
  12110. + if ( pkg->version == NULL ) {
  12111. + fprintf(stderr, "%s: out of memory \n", __FUNCTION__);
  12112. + return ENOMEM;
  12113. + }
  12114. + strcpy(pkg->version, raw);
  12115. +
  12116. +#ifdef USE_DEBVERSION
  12117. + hyphen= strrchr(pkg->version,'-');
  12118. +
  12119. + if (hyphen) {
  12120. + *hyphen++= 0;
  12121. + if (strncmp("fam", hyphen, 3) == 0) {
  12122. + pkg->familiar_revision=hyphen+3;
  12123. + hyphen= strrchr(pkg->version,'-');
  12124. + if (hyphen) {
  12125. + *hyphen++= 0;
  12126. + pkg->revision = hyphen;
  12127. + }
  12128. + } else {
  12129. + pkg->revision = hyphen;
  12130. + }
  12131. + }
  12132. +#endif
  12133. +
  12134. +/*
  12135. + fprintf(stderr,"Parsed version: %lu, %s, %s, %s\n",
  12136. + pkg->epoch,
  12137. + pkg->version,
  12138. + pkg->revision,
  12139. + pkg->familiar_revision);
  12140. +*/
  12141. +
  12142. + return 0;
  12143. +}
  12144. +
  12145. +
  12146. +/* This code is needed to insert in first position the keyword for the aligning bug */
  12147. +
  12148. +int alterProvidesLine(char *raw, char *temp)
  12149. +{
  12150. +
  12151. +
  12152. + if (!*raw) {
  12153. + fprintf(stderr, "%s: ERROR: Provides string is empty", __FUNCTION__);
  12154. + return -EINVAL;
  12155. + }
  12156. +
  12157. + if ( temp == NULL ) {
  12158. + fprintf(stderr, "%s: out of memory \n", __FUNCTION__);
  12159. + return -ENOMEM;
  12160. + }
  12161. +
  12162. + if (strncmp(raw, "Provides:", 9) == 0) {
  12163. + raw += 9;
  12164. + }
  12165. + while (*raw && isspace(*raw)) {
  12166. + raw++;
  12167. + }
  12168. +
  12169. + snprintf ( temp, 35, "Provides: ipkg_internal_use_only, "); /* First part of the line */
  12170. + while (*raw) {
  12171. + strncat( temp, raw++, 1);
  12172. + }
  12173. + return 0;
  12174. +
  12175. +}
  12176. +
  12177. +/* Some random thoughts from Carl:
  12178. +
  12179. + This function could be considerably simplified if we just kept
  12180. + an array of all the generic string-valued field names, and looped
  12181. + through those looking for a match. Also, these fields could perhaps
  12182. + be stored in the package as an array as well, (or, probably better,
  12183. + as an nv_pair_list_t).
  12184. +
  12185. + Fields which require special parsing or storage, (such as Depends:
  12186. + and Status:) could be handled as they are now.
  12187. +*/
  12188. +/* XXX: FEATURE: The Suggests: field needs to be changed from a string
  12189. + to a dependency list. And, since we already have
  12190. + Depends/Pre-Depends and need to add Conflicts, Recommends, and
  12191. + Enhances, perhaps we could generalize all of these and save some
  12192. + code duplication.
  12193. +*/
  12194. +int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest)
  12195. +{
  12196. + int reading_conffiles, reading_description;
  12197. + int pkg_false_provides=1;
  12198. + char ** lines;
  12199. + char * provide=NULL;
  12200. +
  12201. + pkg->src = src;
  12202. + pkg->dest = dest;
  12203. +
  12204. + reading_conffiles = reading_description = 0;
  12205. +
  12206. + for (lines = *raw; *lines; lines++) {
  12207. + /* fprintf(stderr, "PARSING %s\n", *lines);*/
  12208. + if(isGenericFieldType((char *)"Package:", *lines))
  12209. + pkg->name = parseGenericFieldType((char *)"Package", *lines);
  12210. + else if(isGenericFieldType((char *)"Architecture:", *lines))
  12211. + pkg->architecture = parseGenericFieldType((char *)"Architecture", *lines);
  12212. + else if(isGenericFieldType((char *)"Filename:", *lines))
  12213. + pkg->filename = parseGenericFieldType((char *)"Filename", *lines);
  12214. + else if(isGenericFieldType((char *)"Section:", *lines))
  12215. + pkg->section = parseGenericFieldType((char *)"Section", *lines);
  12216. + else if(isGenericFieldType((char *)"MD5sum:", *lines))
  12217. + pkg->md5sum = parseGenericFieldType((char *)"MD5sum", *lines);
  12218. + /* The old ipkg wrote out status files with the wrong case for MD5sum,
  12219. + let's parse it either way */
  12220. + else if(isGenericFieldType((char *)"MD5Sum:", *lines))
  12221. + pkg->md5sum = parseGenericFieldType((char *)"MD5Sum", *lines);
  12222. + else if(isGenericFieldType((char *)"Size:", *lines))
  12223. + pkg->size = parseGenericFieldType((char *)"Size", *lines);
  12224. + else if(isGenericFieldType((char *)"Source:", *lines))
  12225. + pkg->source = parseGenericFieldType((char *)"Source", *lines);
  12226. + else if(isGenericFieldType((char *)"Installed-Size:", *lines))
  12227. + pkg->installed_size = parseGenericFieldType((char *)"Installed-Size", *lines);
  12228. + else if(isGenericFieldType((char *)"Installed-Time:", *lines)) {
  12229. + char *time_str = parseGenericFieldType((char *)"Installed-Time", *lines);
  12230. + pkg->installed_time = strtoul(time_str, NULL, 0);
  12231. + } else if(isGenericFieldType((char *)"Priority:", *lines))
  12232. + pkg->priority = parseGenericFieldType((char *)"Priority", *lines);
  12233. + else if(isGenericFieldType((char *)"Essential:", *lines)) {
  12234. + char *essential_value;
  12235. + essential_value = parseGenericFieldType((char *)"Essential", *lines);
  12236. + if (strcmp(essential_value, "yes") == 0) {
  12237. + pkg->essential = 1;
  12238. + }
  12239. + free(essential_value);
  12240. + }
  12241. + else if(isGenericFieldType((char *)"Status", *lines))
  12242. + parseStatus(pkg, *lines);
  12243. + else if(isGenericFieldType((char *)"Version", *lines))
  12244. + parseVersion(pkg, *lines);
  12245. + else if(isGenericFieldType((char *)"Maintainer", *lines))
  12246. + pkg->maintainer = parseGenericFieldType((char *)"Maintainer", *lines);
  12247. + else if(isGenericFieldType((char *)"Conffiles", *lines)){
  12248. + parseConffiles(pkg, *lines);
  12249. + reading_conffiles = 1;
  12250. + }
  12251. + else if(isGenericFieldType((char *)"Description", *lines)) {
  12252. + pkg->description = parseGenericFieldType((char *)"Description", *lines);
  12253. + reading_conffiles = 0;
  12254. + reading_description = 1;
  12255. + }
  12256. +
  12257. + else if(isGenericFieldType((char *)"Provides", *lines)){
  12258. +/* Here we add the internal_use to align the off by one problem between provides_str and provides */
  12259. + provide = (char * ) malloc(strlen(*lines)+ 35 ); /* Preparing the space for the new ipkg_internal_use_only */
  12260. + if ( alterProvidesLine(*lines,provide) ){
  12261. + return EINVAL;
  12262. + }
  12263. + pkg->provides_str = parseDependsString( provide, &pkg->provides_count);
  12264. +/* Let's try to hack a bit here.
  12265. + The idea is that if a package has no Provides, we would add one generic, to permit the check of dependencies
  12266. + in alot of other places. We will remove it before writing down the status database */
  12267. + pkg_false_provides=0;
  12268. + free(provide);
  12269. + }
  12270. +
  12271. + else if(isGenericFieldType((char *)"Depends", *lines))
  12272. + pkg->depends_str = parseDependsString(*lines, &pkg->depends_count);
  12273. + else if(isGenericFieldType((char *)"Pre-Depends", *lines))
  12274. + pkg->pre_depends_str = parseDependsString(*lines, &pkg->pre_depends_count);
  12275. + else if(isGenericFieldType((char *)"Recommends", *lines))
  12276. + pkg->recommends_str = parseDependsString(*lines, &pkg->recommends_count);
  12277. + else if(isGenericFieldType((char *)"Suggests", *lines))
  12278. + pkg->suggests_str = parseDependsString(*lines, &pkg->suggests_count);
  12279. + /* Abhaya: support for conflicts */
  12280. + else if(isGenericFieldType((char *)"Conflicts", *lines))
  12281. + pkg->conflicts_str = parseDependsString(*lines, &pkg->conflicts_count);
  12282. + else if(isGenericFieldType((char *)"Replaces", *lines))
  12283. + pkg->replaces_str = parseDependsString(*lines, &pkg->replaces_count);
  12284. + else if(line_is_blank(*lines)) {
  12285. + lines++;
  12286. + break;
  12287. + }
  12288. + else if(**lines == ' '){
  12289. + if(reading_description) {
  12290. + /* we already know it's not blank, so the rest of description */
  12291. + pkg->description = realloc(pkg->description,
  12292. + strlen(pkg->description)
  12293. + + 1 + strlen(*lines) + 1);
  12294. + strcat(pkg->description, "\n");
  12295. + strcat(pkg->description, (*lines));
  12296. + }
  12297. + else if(reading_conffiles)
  12298. + parseConffiles(pkg, *lines);
  12299. + }
  12300. + }
  12301. + *raw = lines;
  12302. +/* If the ipk has not a Provides line, we insert our false line */
  12303. + if ( pkg_false_provides==1)
  12304. + pkg->provides_str = parseDependsString ((char *)"Provides: ipkg_internal_use_only ", &pkg->provides_count);
  12305. +
  12306. + if (pkg->name) {
  12307. + return 0;
  12308. + } else {
  12309. + return EINVAL;
  12310. + }
  12311. +}
  12312. +
  12313. +int pkg_valorize_other_field(pkg_t *pkg, char ***raw)
  12314. +{
  12315. + char ** lines;
  12316. +
  12317. + for (lines = *raw; *lines; lines++) {
  12318. + if(isGenericFieldType((char *)"Essential:", *lines)) {
  12319. + char *essential_value;
  12320. + essential_value = parseGenericFieldType((char *)"Essential", *lines);
  12321. + if (strcmp(essential_value, "yes") == 0) {
  12322. + pkg->essential = 1;
  12323. + }
  12324. + free(essential_value);
  12325. + }
  12326. + }
  12327. + *raw = lines;
  12328. +
  12329. + return 0;
  12330. +}
  12331. diff -Nur busybox-1.19.4.orig/archival/libipkg/pkg_parse.h busybox-1.19.4/archival/libipkg/pkg_parse.h
  12332. --- busybox-1.19.4.orig/archival/libipkg/pkg_parse.h 1970-01-01 01:00:00.000000000 +0100
  12333. +++ busybox-1.19.4/archival/libipkg/pkg_parse.h 2012-03-17 00:58:08.197100679 +0100
  12334. @@ -0,0 +1,31 @@
  12335. +/* pkg_parse.h - the itsy package management system
  12336. +
  12337. + Steven M. Ayer
  12338. +
  12339. + Copyright (C) 2002 Compaq Computer Corporation
  12340. +
  12341. + This program is free software; you can redistribute it and/or
  12342. + modify it under the terms of the GNU General Public License as
  12343. + published by the Free Software Foundation; either version 2, or (at
  12344. + your option) any later version.
  12345. +
  12346. + This program is distributed in the hope that it will be useful, but
  12347. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12348. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12349. + General Public License for more details.
  12350. +*/
  12351. +
  12352. +#ifndef PKG_PARSE_H
  12353. +#define PKG_PARSE_H
  12354. +
  12355. +int isGenericFieldType(char * type, char * line);
  12356. +char * parseGenericFieldType(char * type, char * raw);
  12357. +void parseStatus(pkg_t *pkg, char * raw);
  12358. +int parseVersion(pkg_t *pkg, char *raw);
  12359. +char ** parseDependsString(char * raw, int * depends_count);
  12360. +int parseVersion(pkg_t *pkg, char *raw);
  12361. +void parseConffiles(pkg_t * pkg, char * raw);
  12362. +int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest);
  12363. +int pkg_valorize_other_field(pkg_t *pkg, char ***raw);
  12364. +
  12365. +#endif
  12366. diff -Nur busybox-1.19.4.orig/archival/libipkg/pkg_src.c busybox-1.19.4/archival/libipkg/pkg_src.c
  12367. --- busybox-1.19.4.orig/archival/libipkg/pkg_src.c 1970-01-01 01:00:00.000000000 +0100
  12368. +++ busybox-1.19.4/archival/libipkg/pkg_src.c 2012-03-17 00:58:08.197100679 +0100
  12369. @@ -0,0 +1,43 @@
  12370. +/* pkg_src.c - the itsy package management system
  12371. +
  12372. + Carl D. Worth
  12373. +
  12374. + Copyright (C) 2001 University of Southern California
  12375. +
  12376. + This program is free software; you can redistribute it and/or
  12377. + modify it under the terms of the GNU General Public License as
  12378. + published by the Free Software Foundation; either version 2, or (at
  12379. + your option) any later version.
  12380. +
  12381. + This program is distributed in the hope that it will be useful, but
  12382. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12383. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12384. + General Public License for more details.
  12385. +*/
  12386. +
  12387. +#include "ipkg.h"
  12388. +
  12389. +#include "pkg_src.h"
  12390. +#include "str_util.h"
  12391. +
  12392. +int pkg_src_init(pkg_src_t *src, const char *name, const char *base_url, const char *extra_data, int gzip)
  12393. +{
  12394. + src->gzip = gzip;
  12395. + src->name = str_dup_safe (name);
  12396. + src->value = str_dup_safe (base_url);
  12397. + if (extra_data)
  12398. + src->extra_data = str_dup_safe (extra_data);
  12399. + else
  12400. + src->extra_data = NULL;
  12401. + return 0;
  12402. +}
  12403. +
  12404. +void pkg_src_deinit(pkg_src_t *src)
  12405. +{
  12406. + free (src->name);
  12407. + free (src->value);
  12408. + if (src->extra_data)
  12409. + free (src->extra_data);
  12410. +}
  12411. +
  12412. +
  12413. diff -Nur busybox-1.19.4.orig/archival/libipkg/pkg_src.h busybox-1.19.4/archival/libipkg/pkg_src.h
  12414. --- busybox-1.19.4.orig/archival/libipkg/pkg_src.h 1970-01-01 01:00:00.000000000 +0100
  12415. +++ busybox-1.19.4/archival/libipkg/pkg_src.h 2012-03-17 00:58:08.197100679 +0100
  12416. @@ -0,0 +1,34 @@
  12417. +/* pkg_src.h - the itsy package management system
  12418. +
  12419. + Carl D. Worth
  12420. +
  12421. + Copyright (C) 2001 University of Southern California
  12422. +
  12423. + This program is free software; you can redistribute it and/or
  12424. + modify it under the terms of the GNU General Public License as
  12425. + published by the Free Software Foundation; either version 2, or (at
  12426. + your option) any later version.
  12427. +
  12428. + This program is distributed in the hope that it will be useful, but
  12429. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12430. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12431. + General Public License for more details.
  12432. +*/
  12433. +
  12434. +#ifndef PKG_SRC_H
  12435. +#define PKG_SRC_H
  12436. +
  12437. +#include "nv_pair.h"
  12438. +
  12439. +typedef struct
  12440. +{
  12441. + char *name;
  12442. + char *value;
  12443. + char *extra_data;
  12444. + int gzip;
  12445. +} pkg_src_t;
  12446. +
  12447. +int pkg_src_init(pkg_src_t *src, const char *name, const char *base_url, const char *extra_data, int gzip);
  12448. +void pkg_src_deinit(pkg_src_t *src);
  12449. +
  12450. +#endif
  12451. diff -Nur busybox-1.19.4.orig/archival/libipkg/pkg_src_list.c busybox-1.19.4/archival/libipkg/pkg_src_list.c
  12452. --- busybox-1.19.4.orig/archival/libipkg/pkg_src_list.c 1970-01-01 01:00:00.000000000 +0100
  12453. +++ busybox-1.19.4/archival/libipkg/pkg_src_list.c 2012-03-17 00:58:08.197100679 +0100
  12454. @@ -0,0 +1,75 @@
  12455. +/* pkg_src_list.c - the itsy package management system
  12456. +
  12457. + Carl D. Worth
  12458. +
  12459. + Copyright (C) 2001 University of Southern California
  12460. +
  12461. + This program is free software; you can redistribute it and/or
  12462. + modify it under the terms of the GNU General Public License as
  12463. + published by the Free Software Foundation; either version 2, or (at
  12464. + your option) any later version.
  12465. +
  12466. + This program is distributed in the hope that it will be useful, but
  12467. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12468. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12469. + General Public License for more details.
  12470. +*/
  12471. +
  12472. +#include "ipkg.h"
  12473. +
  12474. +#include "pkg_src_list.h"
  12475. +#include "void_list.h"
  12476. +
  12477. +int pkg_src_list_init(pkg_src_list_t *list)
  12478. +{
  12479. + return void_list_init((void_list_t *) list);
  12480. +}
  12481. +
  12482. +void pkg_src_list_deinit(pkg_src_list_t *list)
  12483. +{
  12484. + pkg_src_list_elt_t *iter;
  12485. + pkg_src_t *pkg_src;
  12486. +
  12487. + for (iter = list->head; iter; iter = iter->next) {
  12488. + pkg_src = iter->data;
  12489. + pkg_src_deinit(pkg_src);
  12490. +
  12491. + /* malloced in pkg_src_list_append */
  12492. + free(pkg_src);
  12493. + iter->data = NULL;
  12494. + }
  12495. + void_list_deinit((void_list_t *) list);
  12496. +}
  12497. +
  12498. +pkg_src_t *pkg_src_list_append(pkg_src_list_t *list,
  12499. + const char *name, const char *base_url, const char *extra_data,
  12500. + int gzip)
  12501. +{
  12502. + int err;
  12503. +
  12504. + /* freed in pkg_src_list_deinit */
  12505. + pkg_src_t *pkg_src = malloc(sizeof(pkg_src_t));
  12506. +
  12507. + if (pkg_src == NULL) {
  12508. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  12509. + return NULL;
  12510. + }
  12511. + pkg_src_init(pkg_src, name, base_url, extra_data, gzip);
  12512. +
  12513. + err = void_list_append((void_list_t *) list, pkg_src);
  12514. + if (err) {
  12515. + return NULL;
  12516. + }
  12517. +
  12518. + return pkg_src;
  12519. +}
  12520. +
  12521. +int pkg_src_list_push(pkg_src_list_t *list, pkg_src_t *data)
  12522. +{
  12523. + return void_list_push((void_list_t *) list, data);
  12524. +}
  12525. +
  12526. +pkg_src_list_elt_t *pkg_src_list_pop(pkg_src_list_t *list)
  12527. +{
  12528. + return (pkg_src_list_elt_t *) void_list_pop((void_list_t *) list);
  12529. +}
  12530. diff -Nur busybox-1.19.4.orig/archival/libipkg/pkg_src_list.h busybox-1.19.4/archival/libipkg/pkg_src_list.h
  12531. --- busybox-1.19.4.orig/archival/libipkg/pkg_src_list.h 1970-01-01 01:00:00.000000000 +0100
  12532. +++ busybox-1.19.4/archival/libipkg/pkg_src_list.h 2012-03-17 00:58:08.197100679 +0100
  12533. @@ -0,0 +1,57 @@
  12534. +/* pkg_src_list.h - the itsy package management system
  12535. +
  12536. + Carl D. Worth
  12537. +
  12538. + Copyright (C) 2001 University of Southern California
  12539. +
  12540. + This program is free software; you can redistribute it and/or
  12541. + modify it under the terms of the GNU General Public License as
  12542. + published by the Free Software Foundation; either version 2, or (at
  12543. + your option) any later version.
  12544. +
  12545. + This program is distributed in the hope that it will be useful, but
  12546. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12547. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12548. + General Public License for more details.
  12549. +*/
  12550. +
  12551. +#ifndef PKG_SRC_LIST_H
  12552. +#define PKG_SRC_LIST_H
  12553. +
  12554. +#include "pkg_src.h"
  12555. +
  12556. +typedef struct pkg_src_list_elt pkg_src_list_elt_t;
  12557. +struct pkg_src_list_elt
  12558. +{
  12559. + pkg_src_list_elt_t *next;
  12560. + pkg_src_t *data;
  12561. +};
  12562. +
  12563. +typedef struct pkg_src_list pkg_src_list_t;
  12564. +struct pkg_src_list
  12565. +{
  12566. + pkg_src_list_elt_t pre_head;
  12567. + pkg_src_list_elt_t *head;
  12568. + pkg_src_list_elt_t *tail;
  12569. +};
  12570. +
  12571. +static inline int pkg_src_list_empty(pkg_src_list_t *list)
  12572. +{
  12573. + if (list->head == NULL)
  12574. + return 1;
  12575. + else
  12576. + return 0;
  12577. +}
  12578. +
  12579. +int pkg_src_list_elt_init(pkg_src_list_elt_t *elt, nv_pair_t *data);
  12580. +void pkg_src_list_elt_deinit(pkg_src_list_elt_t *elt);
  12581. +
  12582. +int pkg_src_list_init(pkg_src_list_t *list);
  12583. +void pkg_src_list_deinit(pkg_src_list_t *list);
  12584. +
  12585. +pkg_src_t *pkg_src_list_append(pkg_src_list_t *list, const char *name, const char *root_dir, const char *extra_data, int gzip);
  12586. +int pkg_src_list_push(pkg_src_list_t *list, pkg_src_t *data);
  12587. +pkg_src_list_elt_t *pkg_src_list_pop(pkg_src_list_t *list);
  12588. +
  12589. +#endif
  12590. +
  12591. diff -Nur busybox-1.19.4.orig/archival/libipkg/pkg_vec.c busybox-1.19.4/archival/libipkg/pkg_vec.c
  12592. --- busybox-1.19.4.orig/archival/libipkg/pkg_vec.c 1970-01-01 01:00:00.000000000 +0100
  12593. +++ busybox-1.19.4/archival/libipkg/pkg_vec.c 2012-03-17 00:58:08.197100679 +0100
  12594. @@ -0,0 +1,231 @@
  12595. +/* pkg_vec.c - the itsy package management system
  12596. +
  12597. + Steven M. Ayer
  12598. +
  12599. + Copyright (C) 2002 Compaq Computer Corporation
  12600. +
  12601. + This program is free software; you can redistribute it and/or
  12602. + modify it under the terms of the GNU General Public License as
  12603. + published by the Free Software Foundation; either version 2, or (at
  12604. + your option) any later version.
  12605. +
  12606. + This program is distributed in the hope that it will be useful, but
  12607. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12608. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12609. + General Public License for more details.
  12610. +*/
  12611. +
  12612. +#include <stdlib.h>
  12613. +#include <fnmatch.h>
  12614. +#include "libbb.h"
  12615. +#include "xregex.h"
  12616. +#include "ipkg.h"
  12617. +#include "pkg.h"
  12618. +
  12619. +pkg_vec_t * pkg_vec_alloc(void)
  12620. +{
  12621. + pkg_vec_t * vec = (pkg_vec_t *)malloc(sizeof(pkg_vec_t));
  12622. + if (!vec) {
  12623. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  12624. + return NULL;
  12625. + }
  12626. + vec->pkgs = NULL;
  12627. + vec->len = 0;
  12628. +
  12629. + return vec;
  12630. +}
  12631. +
  12632. +void pkg_vec_free(pkg_vec_t *vec)
  12633. +{
  12634. + free(vec->pkgs);
  12635. + free(vec);
  12636. +}
  12637. +
  12638. +/*
  12639. + * assumption: all names in a vector are identical
  12640. + * assumption: all version strings are trimmed,
  12641. + * so identical versions have identical version strings,
  12642. + * implying identical packages; let's marry these
  12643. + */
  12644. +pkg_t *pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status,ipkg_conf_t *conf)
  12645. +{
  12646. + int i;
  12647. + int found = 0;
  12648. +
  12649. + /* look for a duplicate pkg by name, version, and architecture */
  12650. + for (i = 0; i < vec->len; i++){
  12651. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Found pkg=%s version=%s arch=%s cmp=%s version=%s arch=%s \n",
  12652. + __FUNCTION__, pkg->name, pkg->version, pkg->architecture,
  12653. + vec->pkgs[i]->name, vec->pkgs[i]->version,vec->pkgs[i]->architecture );
  12654. + if ((strcmp(pkg->name, vec->pkgs[i]->name) == 0)
  12655. + && (pkg_compare_versions(pkg, vec->pkgs[i]) == 0)
  12656. + && (strcmp(pkg->architecture, vec->pkgs[i]->architecture) == 0)) {
  12657. + found = 1;
  12658. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Found duplicate for pkg=%s version=%s arch=%s\n",
  12659. + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
  12660. + break;
  12661. + }
  12662. + }
  12663. +
  12664. + /* we didn't find one, add it */
  12665. + if (!found){
  12666. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Adding new pkg=%s version=%s arch=%s\n",
  12667. + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
  12668. +
  12669. + vec->pkgs = (pkg_t **)realloc(vec->pkgs, (vec->len + 1) * sizeof(pkg_t *));
  12670. + vec->pkgs[vec->len] = pkg;
  12671. + vec->len++;
  12672. + return pkg;
  12673. + }
  12674. + /* update the one that we have */
  12675. + else {
  12676. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. calling pkg_merge for pkg=%s version=%s arch=%s",
  12677. + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
  12678. + if (set_status) {
  12679. + /* this is from the status file, so need to merge with existing database */
  12680. + ipkg_message(conf, IPKG_DEBUG2, " with set_status\n");
  12681. + pkg_merge(vec->pkgs[i], pkg, set_status);
  12682. + /* XXX: CLEANUP: It's not so polite to free something here
  12683. + that was passed in from above. */
  12684. + pkg_deinit(pkg);
  12685. + free(pkg);
  12686. + } else {
  12687. + ipkg_message(conf, IPKG_DEBUG2, " WITHOUT set_status\n");
  12688. + /* just overwrite the old one */
  12689. + pkg_deinit(vec->pkgs[i]);
  12690. + free(vec->pkgs[i]);
  12691. + vec->pkgs[i] = pkg;
  12692. + }
  12693. + return vec->pkgs[i];
  12694. + }
  12695. +}
  12696. +
  12697. +void pkg_vec_insert(pkg_vec_t *vec, const pkg_t *pkg)
  12698. +{
  12699. + int i;
  12700. + int found = 0;
  12701. +
  12702. + /* look for a duplicate pkg by name, version, and architecture */
  12703. + for (i = 0; i < vec->len; i++)
  12704. + if ((strcmp(pkg->name, vec->pkgs[i]->name) == 0)
  12705. + && (pkg_compare_versions(pkg, vec->pkgs[i]) == 0)
  12706. + && (strcmp(pkg->architecture, vec->pkgs[i]->name) == 0)) {
  12707. + found = 1;
  12708. + break;
  12709. + }
  12710. +
  12711. + /* we didn't find one, add it */
  12712. + if(!found){
  12713. + vec->pkgs = (pkg_t **)realloc(vec->pkgs, (vec->len + 1) * sizeof(pkg_t *));
  12714. + *(const pkg_t **)&vec->pkgs[vec->len] = pkg;
  12715. + vec->len++;
  12716. + }
  12717. +}
  12718. +
  12719. +int pkg_vec_contains(pkg_vec_t *vec, pkg_t *apkg)
  12720. +{
  12721. + int i;
  12722. + for (i = 0; i < vec->len; i++)
  12723. + if (vec->pkgs[i] == apkg)
  12724. + return 1;
  12725. + return 0;
  12726. +}
  12727. +
  12728. +typedef int (*compare_fcn_t)(const void *, const void *);
  12729. +void pkg_vec_sort(pkg_vec_t *vec, int (*compar)(pkg_t *, pkg_t *))
  12730. +{
  12731. + qsort(vec->pkgs, vec->len, sizeof(pkg_t *), (compare_fcn_t)compar);
  12732. +}
  12733. +
  12734. +int pkg_vec_clear_marks(pkg_vec_t *vec)
  12735. +{
  12736. + int npkgs = vec->len;
  12737. + int i;
  12738. + for (i = 0; i < npkgs; i++) {
  12739. + pkg_t *pkg = vec->pkgs[i];
  12740. + pkg->state_flag &= ~SF_MARKED;
  12741. + }
  12742. + return 0;
  12743. +}
  12744. +
  12745. +int pkg_vec_mark_if_matches(pkg_vec_t *vec, const char *pattern)
  12746. +{
  12747. + int matching_count = 0;
  12748. + pkg_t **pkgs = vec->pkgs;
  12749. + int npkgs = vec->len;
  12750. + int i;
  12751. + for (i = 0; i < npkgs; i++) {
  12752. + pkg_t *pkg = pkgs[i];
  12753. + if (fnmatch(pattern, pkg->name, 0)==0) {
  12754. + pkg->state_flag |= SF_MARKED;
  12755. + matching_count++;
  12756. + }
  12757. + }
  12758. + return matching_count;
  12759. +}
  12760. +
  12761. +
  12762. +abstract_pkg_vec_t * abstract_pkg_vec_alloc(void)
  12763. +{
  12764. + abstract_pkg_vec_t * vec ;
  12765. + vec = (abstract_pkg_vec_t *)malloc(sizeof(abstract_pkg_vec_t));
  12766. + if (!vec) {
  12767. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  12768. + return NULL;
  12769. + }
  12770. + vec->pkgs = NULL;
  12771. + vec->len = 0;
  12772. +
  12773. + return vec;
  12774. +}
  12775. +
  12776. +void abstract_pkg_vec_free(abstract_pkg_vec_t *vec)
  12777. +{
  12778. + free(vec->pkgs);
  12779. + free(vec);
  12780. +}
  12781. +
  12782. +/*
  12783. + * assumption: all names in a vector are unique
  12784. + */
  12785. +void abstract_pkg_vec_insert(abstract_pkg_vec_t *vec, abstract_pkg_t *pkg)
  12786. +{
  12787. + int i;
  12788. +
  12789. + /* look for a duplicate pkg by name */
  12790. + for(i = 0; i < vec->len; i++)
  12791. + if (strcmp(pkg->name, vec->pkgs[i]->name) == 0)
  12792. + break;
  12793. +
  12794. + /* we didn't find one, add it */
  12795. + if(i == vec->len){
  12796. + vec->pkgs =
  12797. + (abstract_pkg_t **)
  12798. + realloc(vec->pkgs, (vec->len + 1) * sizeof(abstract_pkg_t *));
  12799. + vec->pkgs[vec->len] = pkg;
  12800. + vec->len++;
  12801. + }
  12802. +}
  12803. +
  12804. +abstract_pkg_t * abstract_pkg_vec_get(abstract_pkg_vec_t *vec, int i)
  12805. +{
  12806. + if (vec->len > i)
  12807. + return vec->pkgs[i];
  12808. + else
  12809. + return NULL;
  12810. +}
  12811. +
  12812. +int abstract_pkg_vec_contains(abstract_pkg_vec_t *vec, abstract_pkg_t *apkg)
  12813. +{
  12814. + int i;
  12815. + for (i = 0; i < vec->len; i++)
  12816. + if (vec->pkgs[i] == apkg)
  12817. + return 1;
  12818. + return 0;
  12819. +}
  12820. +
  12821. +void abstract_pkg_vec_sort(pkg_vec_t *vec, int (*compar)(abstract_pkg_t *, abstract_pkg_t *))
  12822. +{
  12823. + qsort(vec->pkgs, vec->len, sizeof(pkg_t *), (compare_fcn_t)compar);
  12824. +}
  12825. +
  12826. diff -Nur busybox-1.19.4.orig/archival/libipkg/pkg_vec.h busybox-1.19.4/archival/libipkg/pkg_vec.h
  12827. --- busybox-1.19.4.orig/archival/libipkg/pkg_vec.h 1970-01-01 01:00:00.000000000 +0100
  12828. +++ busybox-1.19.4/archival/libipkg/pkg_vec.h 2012-03-17 00:58:08.197100679 +0100
  12829. @@ -0,0 +1,62 @@
  12830. +/* pkg_vec.h - the itsy package management system
  12831. +
  12832. + Steven M. Ayer
  12833. +
  12834. + Copyright (C) 2002 Compaq Computer Corporation
  12835. +
  12836. + This program is free software; you can redistribute it and/or
  12837. + modify it under the terms of the GNU General Public License as
  12838. + published by the Free Software Foundation; either version 2, or (at
  12839. + your option) any later version.
  12840. +
  12841. + This program is distributed in the hope that it will be useful, but
  12842. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12843. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12844. + General Public License for more details.
  12845. +*/
  12846. +
  12847. +#ifndef PKG_VEC_H
  12848. +#define PKG_VEC_H
  12849. +
  12850. +typedef struct pkg pkg_t;
  12851. +typedef struct abstract_pkg abstract_pkg_t;
  12852. +
  12853. +struct pkg_vec
  12854. +{
  12855. + pkg_t **pkgs;
  12856. + int len;
  12857. +};
  12858. +typedef struct pkg_vec pkg_vec_t;
  12859. +
  12860. +struct abstract_pkg_vec
  12861. +{
  12862. + abstract_pkg_t **pkgs;
  12863. + int len;
  12864. +};
  12865. +typedef struct abstract_pkg_vec abstract_pkg_vec_t;
  12866. +
  12867. +
  12868. +pkg_vec_t * pkg_vec_alloc(void);
  12869. +void pkg_vec_free(pkg_vec_t *vec);
  12870. +void marry_two_packages(pkg_t * newpkg, pkg_t * oldpkg);
  12871. +
  12872. +void pkg_vec_add(pkg_vec_t *vec, pkg_t *pkg);
  12873. +/* pkg_vec_insert_merge: might munge pkg.
  12874. +* returns the pkg that is in the pkg graph */
  12875. +pkg_t *pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status, ipkg_conf_t *conf);
  12876. +/* this one never munges pkg */
  12877. +void pkg_vec_insert(pkg_vec_t *vec, const pkg_t *pkg);
  12878. +int pkg_vec_contains(pkg_vec_t *vec, pkg_t *apkg);
  12879. +void pkg_vec_sort(pkg_vec_t *vec, int (*compar)(pkg_t *, pkg_t *));
  12880. +
  12881. +int pkg_vec_clear_marks(pkg_vec_t *vec);
  12882. +int pkg_vec_mark_if_matches(pkg_vec_t *vec, const char *pattern);
  12883. +
  12884. +abstract_pkg_vec_t * abstract_pkg_vec_alloc(void);
  12885. +void abstract_pkg_vec_free(abstract_pkg_vec_t *vec);
  12886. +void abstract_pkg_vec_insert(abstract_pkg_vec_t *vec, abstract_pkg_t *pkg);
  12887. +abstract_pkg_t * abstract_pkg_vec_get(abstract_pkg_vec_t *vec, int i);
  12888. +int abstract_pkg_vec_contains(abstract_pkg_vec_t *vec, abstract_pkg_t *apkg);
  12889. +void abstract_pkg_vec_sort(pkg_vec_t *vec, int (*compar)(abstract_pkg_t *, abstract_pkg_t *));
  12890. +#endif
  12891. +
  12892. diff -Nur busybox-1.19.4.orig/archival/libipkg/sprintf_alloc.h busybox-1.19.4/archival/libipkg/sprintf_alloc.h
  12893. --- busybox-1.19.4.orig/archival/libipkg/sprintf_alloc.h 1970-01-01 01:00:00.000000000 +0100
  12894. +++ busybox-1.19.4/archival/libipkg/sprintf_alloc.h 2012-03-17 00:58:08.197100679 +0100
  12895. @@ -0,0 +1,25 @@
  12896. +/* sprintf_alloca.c -- like sprintf with memory allocation
  12897. +
  12898. + Carl D. Worth
  12899. +
  12900. + Copyright (C) 2001 University of Southern California
  12901. +
  12902. + This program is free software; you can redistribute it and/or modify
  12903. + it under the terms of the GNU General Public License as published by
  12904. + the Free Software Foundation; either version 2, or (at your option)
  12905. + any later version.
  12906. +
  12907. + This program is distributed in the hope that it will be useful,
  12908. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  12909. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12910. + GNU General Public License for more details.
  12911. +*/
  12912. +
  12913. +#ifndef SPRINTF_ALLOC_H
  12914. +#define SPRINTF_ALLOC_H
  12915. +
  12916. +#include "libbb.h"
  12917. +
  12918. +#define sprintf_alloc(str, fmt, args...) *str = xasprintf(fmt, ## args)
  12919. +
  12920. +#endif
  12921. diff -Nur busybox-1.19.4.orig/archival/libipkg/str_list.c busybox-1.19.4/archival/libipkg/str_list.c
  12922. --- busybox-1.19.4.orig/archival/libipkg/str_list.c 1970-01-01 01:00:00.000000000 +0100
  12923. +++ busybox-1.19.4/archival/libipkg/str_list.c 2012-03-17 00:58:08.201100676 +0100
  12924. @@ -0,0 +1,76 @@
  12925. +/* str_list.c - the itsy package management system
  12926. +
  12927. + Carl D. Worth
  12928. +
  12929. + Copyright (C) 2001 University of Southern California
  12930. +
  12931. + This program is free software; you can redistribute it and/or
  12932. + modify it under the terms of the GNU General Public License as
  12933. + published by the Free Software Foundation; either version 2, or (at
  12934. + your option) any later version.
  12935. +
  12936. + This program is distributed in the hope that it will be useful, but
  12937. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12938. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12939. + General Public License for more details.
  12940. +*/
  12941. +
  12942. +#include "ipkg.h"
  12943. +
  12944. +#include "str_list.h"
  12945. +
  12946. +int str_list_elt_init(str_list_elt_t *elt, char *data)
  12947. +{
  12948. + return void_list_elt_init((void_list_elt_t *) elt, data);
  12949. +}
  12950. +
  12951. +void str_list_elt_deinit(str_list_elt_t *elt)
  12952. +{
  12953. + void_list_elt_deinit((void_list_elt_t *) elt);
  12954. +}
  12955. +
  12956. +str_list_t *str_list_alloc(void)
  12957. +{
  12958. + str_list_t *list = (str_list_t *)malloc(sizeof(str_list_t));
  12959. + if (list)
  12960. + str_list_init(list);
  12961. + return list;
  12962. +}
  12963. +
  12964. +int str_list_init(str_list_t *list)
  12965. +{
  12966. + return void_list_init((void_list_t *) list);
  12967. +}
  12968. +
  12969. +void str_list_deinit(str_list_t *list)
  12970. +{
  12971. + void_list_deinit((void_list_t *) list);
  12972. +}
  12973. +
  12974. +int str_list_append(str_list_t *list, char *data)
  12975. +{
  12976. + return void_list_append((void_list_t *) list, data);
  12977. +}
  12978. +
  12979. +int str_list_push(str_list_t *list, char *data)
  12980. +{
  12981. + return void_list_push((void_list_t *) list, data);
  12982. +}
  12983. +
  12984. +str_list_elt_t *str_list_pop(str_list_t *list)
  12985. +{
  12986. + return (str_list_elt_t *) void_list_pop((void_list_t *) list);
  12987. +}
  12988. +
  12989. +str_list_elt_t *str_list_remove(str_list_t *list, str_list_elt_t **iter)
  12990. +{
  12991. + return (str_list_elt_t *) void_list_remove((void_list_t *) list,
  12992. + (void_list_elt_t **) iter);
  12993. +}
  12994. +
  12995. +char *str_list_remove_elt(str_list_t *list, const char *target_str)
  12996. +{
  12997. + return (char *)void_list_remove_elt((void_list_t *) list,
  12998. + (void *)target_str,
  12999. + (void_list_cmp_t)strcmp);
  13000. +}
  13001. diff -Nur busybox-1.19.4.orig/archival/libipkg/str_list.h busybox-1.19.4/archival/libipkg/str_list.h
  13002. --- busybox-1.19.4.orig/archival/libipkg/str_list.h 1970-01-01 01:00:00.000000000 +0100
  13003. +++ busybox-1.19.4/archival/libipkg/str_list.h 2012-03-17 00:58:08.201100676 +0100
  13004. @@ -0,0 +1,51 @@
  13005. +/* str_list.h - the itsy package management system
  13006. +
  13007. + Carl D. Worth
  13008. +
  13009. + Copyright (C) 2001 University of Southern California
  13010. +
  13011. + This program is free software; you can redistribute it and/or
  13012. + modify it under the terms of the GNU General Public License as
  13013. + published by the Free Software Foundation; either version 2, or (at
  13014. + your option) any later version.
  13015. +
  13016. + This program is distributed in the hope that it will be useful, but
  13017. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13018. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13019. + General Public License for more details.
  13020. +*/
  13021. +
  13022. +#ifndef STR_LIST_H
  13023. +#define STR_LIST_H
  13024. +
  13025. +#include "void_list.h"
  13026. +
  13027. +typedef struct str_list_elt str_list_elt_t;
  13028. +struct str_list_elt
  13029. +{
  13030. + str_list_elt_t *next;
  13031. + char *data;
  13032. +};
  13033. +
  13034. +typedef struct xstr_list str_list_t;
  13035. +struct xstr_list
  13036. +{
  13037. + str_list_elt_t pre_head;
  13038. + str_list_elt_t *head;
  13039. + str_list_elt_t *tail;
  13040. +};
  13041. +
  13042. +int str_list_elt_init(str_list_elt_t *elt, char *data);
  13043. +void str_list_elt_deinit(str_list_elt_t *elt);
  13044. +
  13045. +str_list_t *str_list_alloc(void);
  13046. +int str_list_init(str_list_t *list);
  13047. +void str_list_deinit(str_list_t *list);
  13048. +
  13049. +int str_list_append(str_list_t *list, char *data);
  13050. +int str_list_push(str_list_t *list, char *data);
  13051. +str_list_elt_t *str_list_pop(str_list_t *list);
  13052. +str_list_elt_t *str_list_remove(str_list_t *list, str_list_elt_t **iter);
  13053. +char *str_list_remove_elt(str_list_t *list, const char *target_str);
  13054. +
  13055. +#endif
  13056. diff -Nur busybox-1.19.4.orig/archival/libipkg/str_util.c busybox-1.19.4/archival/libipkg/str_util.c
  13057. --- busybox-1.19.4.orig/archival/libipkg/str_util.c 1970-01-01 01:00:00.000000000 +0100
  13058. +++ busybox-1.19.4/archival/libipkg/str_util.c 2012-03-17 00:58:08.201100676 +0100
  13059. @@ -0,0 +1,69 @@
  13060. +/* str_utils.c - the itsy package management system
  13061. +
  13062. + Carl D. Worth
  13063. +
  13064. + Copyright (C) 2001 University of Southern California
  13065. +
  13066. + This program is free software; you can redistribute it and/or
  13067. + modify it under the terms of the GNU General Public License as
  13068. + published by the Free Software Foundation; either version 2, or (at
  13069. + your option) any later version.
  13070. +
  13071. + This program is distributed in the hope that it will be useful, but
  13072. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13073. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13074. + General Public License for more details.
  13075. +*/
  13076. +
  13077. +#include "ipkg.h"
  13078. +
  13079. +int str_starts_with(const char *str, const char *prefix);
  13080. +int str_ends_with(const char *str, const char *suffix);
  13081. +int str_chomp(char *str);
  13082. +int str_toupper(char *str);
  13083. +char *str_dup_safe(const char *str);
  13084. +
  13085. +int str_starts_with(const char *str, const char *prefix)
  13086. +{
  13087. + return (strncmp(str, prefix, strlen(prefix)) == 0);
  13088. +}
  13089. +
  13090. +int str_ends_with(const char *str, const char *suffix)
  13091. +{
  13092. + int suffix_len;
  13093. + int str_len;
  13094. +
  13095. + str_len = strlen(str);
  13096. + suffix_len = strlen(suffix);
  13097. +
  13098. + if (str_len < suffix_len) {
  13099. + return 0;
  13100. + }
  13101. +
  13102. + return (strcmp(str + str_len - suffix_len, suffix) == 0);
  13103. +}
  13104. +
  13105. +int str_chomp(char *str)
  13106. +{
  13107. + if (str[strlen(str) - 1] == '\n') {
  13108. + str[strlen(str) - 1] = '\0';
  13109. + return 1;
  13110. + }
  13111. + return 0;
  13112. +}
  13113. +
  13114. +int str_toupper(char *str)
  13115. +{
  13116. + while (*str) {
  13117. + *str = toupper(*str);
  13118. + str++;
  13119. + }
  13120. +
  13121. + return 0;
  13122. +}
  13123. +
  13124. +char *str_dup_safe(const char *str)
  13125. +{
  13126. + return str ? strdup(str) : NULL;
  13127. +}
  13128. +
  13129. diff -Nur busybox-1.19.4.orig/archival/libipkg/str_util.h busybox-1.19.4/archival/libipkg/str_util.h
  13130. --- busybox-1.19.4.orig/archival/libipkg/str_util.h 1970-01-01 01:00:00.000000000 +0100
  13131. +++ busybox-1.19.4/archival/libipkg/str_util.h 2012-03-17 00:58:08.201100676 +0100
  13132. @@ -0,0 +1,27 @@
  13133. +/* str_utils.h - the itsy package management system
  13134. +
  13135. + Carl D. Worth
  13136. +
  13137. + Copyright (C) 2001 University of Southern California
  13138. +
  13139. + This program is free software; you can redistribute it and/or
  13140. + modify it under the terms of the GNU General Public License as
  13141. + published by the Free Software Foundation; either version 2, or (at
  13142. + your option) any later version.
  13143. +
  13144. + This program is distributed in the hope that it will be useful, but
  13145. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13146. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13147. + General Public License for more details.
  13148. +*/
  13149. +
  13150. +#ifndef STR_UTILS_H
  13151. +#define STR_UTILS_H
  13152. +
  13153. +int str_starts_with(const char *str, const char *prefix);
  13154. +int str_ends_with(const char *str, const char *suffix);
  13155. +int str_chomp(char *str);
  13156. +int str_toupper(char *str);
  13157. +char *str_dup_safe(const char *str);
  13158. +
  13159. +#endif
  13160. diff -Nur busybox-1.19.4.orig/archival/libipkg/user.c busybox-1.19.4/archival/libipkg/user.c
  13161. --- busybox-1.19.4.orig/archival/libipkg/user.c 1970-01-01 01:00:00.000000000 +0100
  13162. +++ busybox-1.19.4/archival/libipkg/user.c 2012-03-17 00:58:08.201100676 +0100
  13163. @@ -0,0 +1,49 @@
  13164. +/* user.c - the itsy package management system
  13165. +
  13166. + Jamey Hicks
  13167. +
  13168. + Copyright (C) 2002 Hewlett Packard Company
  13169. + Copyright (C) 2001 University of Southern California
  13170. +
  13171. + This program is free software; you can redistribute it and/or
  13172. + modify it under the terms of the GNU General Public License as
  13173. + published by the Free Software Foundation; either version 2, or (at
  13174. + your option) any later version.
  13175. +
  13176. + This program is distributed in the hope that it will be useful, but
  13177. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13178. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13179. + General Public License for more details.
  13180. +*/
  13181. +
  13182. +#include <stdio.h>
  13183. +#include <stdarg.h>
  13184. +#include "libbb.h"
  13185. +#include "file_util.h"
  13186. +#include "str_util.h"
  13187. +#include "libipkg.h"
  13188. +
  13189. +char *get_user_response(const char *format, ...);
  13190. +static char *question = NULL;
  13191. +static int question_len = 255;
  13192. +
  13193. +char *get_user_response(const char *format, ...)
  13194. +{
  13195. + int len = question_len;
  13196. + va_list ap;
  13197. + char *response;
  13198. + va_start(ap, format);
  13199. +
  13200. + do {
  13201. + if (question == NULL || len > question_len) {
  13202. + question = realloc(question, len + 1);
  13203. + question_len = len;
  13204. + }
  13205. + len = vsnprintf(question,question_len,format,ap);
  13206. + } while (len > question_len);
  13207. + response = strdup(ipkg_cb_response(question));
  13208. + str_chomp(response);
  13209. + str_tolower(response);
  13210. +
  13211. + return response;
  13212. +}
  13213. diff -Nur busybox-1.19.4.orig/archival/libipkg/user.h busybox-1.19.4/archival/libipkg/user.h
  13214. --- busybox-1.19.4.orig/archival/libipkg/user.h 1970-01-01 01:00:00.000000000 +0100
  13215. +++ busybox-1.19.4/archival/libipkg/user.h 2012-03-17 00:58:08.201100676 +0100
  13216. @@ -0,0 +1,23 @@
  13217. +/* user.c - the itsy package management system
  13218. +
  13219. + Jamey Hicks
  13220. +
  13221. + Copyright (C) 2002 Hewlett Packard Company
  13222. + Copyright (C) 2001 University of Southern California
  13223. +
  13224. + This program is free software; you can redistribute it and/or
  13225. + modify it under the terms of the GNU General Public License as
  13226. + published by the Free Software Foundation; either version 2, or (at
  13227. + your option) any later version.
  13228. +
  13229. + This program is distributed in the hope that it will be useful, but
  13230. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13231. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13232. + General Public License for more details.
  13233. +*/
  13234. +
  13235. +#include <stdio.h>
  13236. +#include <stdarg.h>
  13237. +
  13238. +char *get_user_response(const char *format, ...);
  13239. +
  13240. diff -Nur busybox-1.19.4.orig/archival/libipkg/void_list.c busybox-1.19.4/archival/libipkg/void_list.c
  13241. --- busybox-1.19.4.orig/archival/libipkg/void_list.c 1970-01-01 01:00:00.000000000 +0100
  13242. +++ busybox-1.19.4/archival/libipkg/void_list.c 2012-03-17 00:58:08.201100676 +0100
  13243. @@ -0,0 +1,194 @@
  13244. +/* void_list.c - the itsy package management system
  13245. +
  13246. + Carl D. Worth
  13247. +
  13248. + Copyright (C) 2001 University of Southern California
  13249. +
  13250. + This program is free software; you can redistribute it and/or
  13251. + modify it under the terms of the GNU General Public License as
  13252. + published by the Free Software Foundation; either version 2, or (at
  13253. + your option) any later version.
  13254. +
  13255. + This program is distributed in the hope that it will be useful, but
  13256. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13257. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13258. + General Public License for more details.
  13259. +*/
  13260. +
  13261. +#include "ipkg.h"
  13262. +#include <errno.h>
  13263. +
  13264. +#include "void_list.h"
  13265. +
  13266. +int void_list_elt_init(void_list_elt_t *elt, void *data)
  13267. +{
  13268. + elt->next = NULL;
  13269. + elt->data = data;
  13270. +
  13271. + return 0;
  13272. +}
  13273. +
  13274. +void void_list_elt_deinit(void_list_elt_t *elt)
  13275. +{
  13276. + void_list_elt_init(elt, NULL);
  13277. +}
  13278. +
  13279. +int void_list_init(void_list_t *list)
  13280. +{
  13281. + void_list_elt_init(&list->pre_head, NULL);
  13282. + list->head = NULL;
  13283. + list->pre_head.next = list->head;
  13284. + list->tail = NULL;
  13285. +
  13286. + return 0;
  13287. +}
  13288. +
  13289. +void void_list_deinit(void_list_t *list)
  13290. +{
  13291. + void_list_elt_t *elt;
  13292. +
  13293. + while (list->head) {
  13294. + elt = void_list_pop(list);
  13295. + void_list_elt_deinit(elt);
  13296. + /* malloced in void_list_append */
  13297. + free(elt);
  13298. + }
  13299. +}
  13300. +
  13301. +int void_list_append(void_list_t *list, void *data)
  13302. +{
  13303. + void_list_elt_t *elt;
  13304. +
  13305. + /* freed in void_list_deinit */
  13306. + elt = malloc(sizeof(void_list_elt_t));
  13307. + if (elt == NULL) {
  13308. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  13309. + return ENOMEM;
  13310. + }
  13311. +
  13312. + void_list_elt_init(elt, data);
  13313. +
  13314. + if (list->tail) {
  13315. + list->tail->next = elt;
  13316. + list->tail = elt;
  13317. + } else {
  13318. + list->head = elt;
  13319. + list->pre_head.next = list->head;
  13320. + list->tail = elt;
  13321. + }
  13322. +
  13323. + return 0;
  13324. +}
  13325. +
  13326. +int void_list_push(void_list_t *list, void *data)
  13327. +{
  13328. + void_list_elt_t *elt;
  13329. +
  13330. + elt = malloc(sizeof(void_list_elt_t));
  13331. + if (elt == NULL) {
  13332. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  13333. + return ENOMEM;
  13334. + }
  13335. +
  13336. + void_list_elt_init(elt, data);
  13337. +
  13338. + elt->next = list->head;
  13339. + list->head->next = elt;
  13340. + if (list->tail == NULL) {
  13341. + list->tail = list->head;
  13342. + }
  13343. +
  13344. + return 0;
  13345. +}
  13346. +
  13347. +void_list_elt_t *void_list_pop(void_list_t *list)
  13348. +{
  13349. + void_list_elt_t *elt;
  13350. +
  13351. + elt = list->head;
  13352. +
  13353. + if (list->head) {
  13354. + list->head = list->head->next;
  13355. + list->pre_head.next = list->head;
  13356. + if (list->head == NULL) {
  13357. + list->tail = NULL;
  13358. + }
  13359. + }
  13360. +
  13361. + return elt;
  13362. +}
  13363. +
  13364. +void *void_list_remove(void_list_t *list, void_list_elt_t **iter)
  13365. +{
  13366. + void_list_elt_t *prior;
  13367. + void_list_elt_t *old_elt;
  13368. + void *old_data;
  13369. +
  13370. + old_elt = *iter;
  13371. + old_data = old_elt->data;
  13372. +
  13373. + if (old_elt == list->head) {
  13374. + prior = &list->pre_head;
  13375. + void_list_pop(list);
  13376. + } else {
  13377. + for (prior = list->head; prior; prior = prior->next) {
  13378. + if (prior->next == old_elt) {
  13379. + break;
  13380. + }
  13381. + }
  13382. + if (prior == NULL || prior->next != old_elt) {
  13383. + fprintf(stderr, "%s: ERROR: element not found in list\n", __FUNCTION__);
  13384. + return NULL;
  13385. + }
  13386. + prior->next = old_elt->next;
  13387. +
  13388. + if (old_elt == list->tail) {
  13389. + list->tail = prior;
  13390. + }
  13391. + }
  13392. +
  13393. + void_list_elt_deinit(old_elt);
  13394. + *iter = prior;
  13395. +
  13396. + return old_data;
  13397. +}
  13398. +
  13399. +/* remove element containing elt data, using cmp(elt->data, target_data) == 0. */
  13400. +void *void_list_remove_elt(void_list_t *list, const void *target_data, void_list_cmp_t cmp)
  13401. +{
  13402. + void_list_elt_t *prior;
  13403. + void_list_elt_t *old_elt = NULL;
  13404. + void *old_data = NULL;
  13405. +
  13406. + /* first element */
  13407. + if (list->head && list->head->data && (cmp(list->head->data, target_data) == 0)) {
  13408. + old_elt = list->head;
  13409. + old_data = list->head->data;
  13410. + void_list_pop(list);
  13411. + } else {
  13412. + int found = 0;
  13413. + for (prior = list->head; prior && prior->next; prior = prior->next) {
  13414. + if (prior->next->data && (cmp(prior->next->data, target_data) == 0)) {
  13415. + old_elt = prior->next;
  13416. + old_data = old_elt->data;
  13417. + found = 1;
  13418. + break;
  13419. + }
  13420. + }
  13421. + if (!found) {
  13422. + return NULL;
  13423. + }
  13424. + prior->next = old_elt->next;
  13425. +
  13426. + if (old_elt == list->tail) {
  13427. + list->tail = prior;
  13428. + }
  13429. + }
  13430. + if (old_elt)
  13431. + void_list_elt_deinit(old_elt);
  13432. +
  13433. + if (old_data)
  13434. + return old_data;
  13435. + else
  13436. + return NULL;
  13437. +}
  13438. diff -Nur busybox-1.19.4.orig/archival/libipkg/void_list.h busybox-1.19.4/archival/libipkg/void_list.h
  13439. --- busybox-1.19.4.orig/archival/libipkg/void_list.h 1970-01-01 01:00:00.000000000 +0100
  13440. +++ busybox-1.19.4/archival/libipkg/void_list.h 2012-03-17 00:58:08.201100676 +0100
  13441. @@ -0,0 +1,59 @@
  13442. +/* void_list.h - the itsy package management system
  13443. +
  13444. + Carl D. Worth
  13445. +
  13446. + Copyright (C) 2001 University of Southern California
  13447. +
  13448. + This program is free software; you can redistribute it and/or
  13449. + modify it under the terms of the GNU General Public License as
  13450. + published by the Free Software Foundation; either version 2, or (at
  13451. + your option) any later version.
  13452. +
  13453. + This program is distributed in the hope that it will be useful, but
  13454. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13455. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13456. + General Public License for more details.
  13457. +*/
  13458. +
  13459. +#ifndef VOID_LIST_H
  13460. +#define VOID_LIST_H
  13461. +
  13462. +typedef struct void_list_elt void_list_elt_t;
  13463. +struct void_list_elt
  13464. +{
  13465. + void_list_elt_t *next;
  13466. + void *data;
  13467. +};
  13468. +
  13469. +typedef struct void_list void_list_t;
  13470. +struct void_list
  13471. +{
  13472. + void_list_elt_t pre_head;
  13473. + void_list_elt_t *head;
  13474. + void_list_elt_t *tail;
  13475. +};
  13476. +
  13477. +static inline int void_list_empty(void_list_t *list)
  13478. +{
  13479. + if (list->head == NULL)
  13480. + return 1;
  13481. + else
  13482. + return 0;
  13483. +}
  13484. +
  13485. +int void_list_elt_init(void_list_elt_t *elt, void *data);
  13486. +void void_list_elt_deinit(void_list_elt_t *elt);
  13487. +
  13488. +int void_list_init(void_list_t *list);
  13489. +void void_list_deinit(void_list_t *list);
  13490. +
  13491. +int void_list_append(void_list_t *list, void *data);
  13492. +int void_list_push(void_list_t *list, void *data);
  13493. +void_list_elt_t *void_list_pop(void_list_t *list);
  13494. +
  13495. +void *void_list_remove(void_list_t *list, void_list_elt_t **iter);
  13496. +/* remove element containing elt data, using cmp(elt->data, target_data) == 0. */
  13497. +typedef int (*void_list_cmp_t)(const void *, const void *);
  13498. +void *void_list_remove_elt(void_list_t *list, const void *target_data, void_list_cmp_t cmp);
  13499. +
  13500. +#endif
  13501. diff -Nur busybox-1.19.4.orig/archival/libipkg/xsystem.c busybox-1.19.4/archival/libipkg/xsystem.c
  13502. --- busybox-1.19.4.orig/archival/libipkg/xsystem.c 1970-01-01 01:00:00.000000000 +0100
  13503. +++ busybox-1.19.4/archival/libipkg/xsystem.c 2012-03-17 00:58:08.201100676 +0100
  13504. @@ -0,0 +1,64 @@
  13505. +/* xsystem.c - system(3) with error messages
  13506. +
  13507. + Carl D. Worth
  13508. +
  13509. + Copyright (C) 2001 University of Southern California
  13510. +
  13511. + This program is free software; you can redistribute it and/or
  13512. + modify it under the terms of the GNU General Public License as
  13513. + published by the Free Software Foundation; either version 2, or (at
  13514. + your option) any later version.
  13515. +
  13516. + This program is distributed in the hope that it will be useful, but
  13517. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13518. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13519. + General Public License for more details.
  13520. +*/
  13521. +
  13522. +#include "ipkg.h"
  13523. +#include <sys/wait.h>
  13524. +
  13525. +#include "xsystem.h"
  13526. +
  13527. +/* XXX: FEATURE: I shouldn't actually use system(3) at all. I don't
  13528. + really need the /bin/sh invocation which takes resources and
  13529. + introduces security problems. I should switch all of this to a sort
  13530. + of execl() or execv() interface/implementation.
  13531. +*/
  13532. +
  13533. +/* Like system(3), but with error messages printed if the fork fails
  13534. + or if the child process dies due to an uncaught signal. Also, the
  13535. + return value is a bit simpler:
  13536. +
  13537. + -1 if there was any problem
  13538. + Otherwise, the 8-bit return value of the program ala WEXITSTATUS
  13539. + as defined in <sys/wait.h>.
  13540. +*/
  13541. +int xsystem(const char *cmd)
  13542. +{
  13543. + int err;
  13544. +
  13545. + err = system(cmd);
  13546. +
  13547. + if (err == -1) {
  13548. + fprintf(stderr, "%s: ERROR: fork failed before execution: `%s'\n",
  13549. + __FUNCTION__, cmd);
  13550. + return -1;
  13551. + }
  13552. +
  13553. + if (WIFSIGNALED(err)) {
  13554. + fprintf(stderr, "%s: ERROR: Child process died due to signal %d: `%s'\n",
  13555. + __FUNCTION__, WTERMSIG(err), cmd);
  13556. + return -1;
  13557. + }
  13558. +
  13559. + if (WIFEXITED(err)) {
  13560. + /* Normal child exit */
  13561. + return WEXITSTATUS(err);
  13562. + }
  13563. +
  13564. + fprintf(stderr, "%s: ERROR: Received unintelligible return value from system: %d",
  13565. + __FUNCTION__, err);
  13566. + return -1;
  13567. +}
  13568. +
  13569. diff -Nur busybox-1.19.4.orig/archival/libipkg/xsystem.h busybox-1.19.4/archival/libipkg/xsystem.h
  13570. --- busybox-1.19.4.orig/archival/libipkg/xsystem.h 1970-01-01 01:00:00.000000000 +0100
  13571. +++ busybox-1.19.4/archival/libipkg/xsystem.h 2012-03-17 00:58:08.201100676 +0100
  13572. @@ -0,0 +1,34 @@
  13573. +/* xsystem.h - system(3) with error messages
  13574. +
  13575. + Carl D. Worth
  13576. +
  13577. + Copyright (C) 2001 University of Southern California
  13578. +
  13579. + This program is free software; you can redistribute it and/or
  13580. + modify it under the terms of the GNU General Public License as
  13581. + published by the Free Software Foundation; either version 2, or (at
  13582. + your option) any later version.
  13583. +
  13584. + This program is distributed in the hope that it will be useful, but
  13585. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13586. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13587. + General Public License for more details.
  13588. +*/
  13589. +
  13590. +#ifndef XSYSTEM_H
  13591. +#define XSYSTEM_H
  13592. +
  13593. +#include <stdlib.h>
  13594. +
  13595. +/* Like system(3), but with error messages printed if the fork fails
  13596. + or if the child process dies due to an uncaught signal. Also, the
  13597. + return value is a bit simpler:
  13598. +
  13599. + -1 if there was any problem
  13600. + Otherwise, the 8-bit return value of the program ala WEXITSTATUS
  13601. + as defined in <sys/wait.h>.
  13602. +*/
  13603. +int xsystem(const char *cmd);
  13604. +
  13605. +#endif
  13606. +
  13607. diff -Nur busybox-1.19.4.orig/include/applets.src.h busybox-1.19.4/include/applets.src.h
  13608. --- busybox-1.19.4.orig/include/applets.src.h 2012-02-04 20:34:24.000000000 +0100
  13609. +++ busybox-1.19.4/include/applets.src.h 2012-03-17 00:58:53.526834671 +0100
  13610. @@ -200,6 +200,7 @@
  13611. IF_IPCALC(APPLET(ipcalc, BB_DIR_BIN, BB_SUID_DROP))
  13612. IF_IPCRM(APPLET(ipcrm, BB_DIR_USR_BIN, BB_SUID_DROP))
  13613. IF_IPCS(APPLET(ipcs, BB_DIR_USR_BIN, BB_SUID_DROP))
  13614. +IF_IPKG(APPLET(ipkg, BB_DIR_USR_BIN, BB_SUID_DROP))
  13615. IF_IPLINK(APPLET(iplink, BB_DIR_BIN, BB_SUID_DROP))
  13616. IF_IPROUTE(APPLET(iproute, BB_DIR_BIN, BB_SUID_DROP))
  13617. IF_IPRULE(APPLET(iprule, BB_DIR_BIN, BB_SUID_DROP))
  13618. diff -Nur busybox-1.19.4.orig/include/archive.h busybox-1.19.4/include/archive.h
  13619. --- busybox-1.19.4.orig/include/archive.h 2012-02-04 20:34:24.000000000 +0100
  13620. +++ busybox-1.19.4/include/archive.h 2012-03-17 00:58:08.201100676 +0100
  13621. @@ -96,7 +96,7 @@
  13622. struct hardlinks_t *cpio__hardlinks_to_create;
  13623. struct hardlinks_t *cpio__created_hardlinks;
  13624. #endif
  13625. -#if ENABLE_DPKG || ENABLE_DPKG_DEB
  13626. +#if ENABLE_DPKG || ENABLE_DPKG_DEB || ENABLE_IPKG
  13627. /* Temporary storage */
  13628. char *dpkg__buffer;
  13629. /* How to process any sub archive, e.g. get_header_tar_gz */
  13630. diff -Nur busybox-1.19.4.orig/include/usage.src.h busybox-1.19.4/include/usage.src.h
  13631. --- busybox-1.19.4.orig/include/usage.src.h 2012-02-04 20:24:55.000000000 +0100
  13632. +++ busybox-1.19.4/include/usage.src.h 2012-03-17 01:01:02.169888238 +0100
  13633. @@ -19,4 +19,80 @@
  13634. #define busybox_notes_usage \
  13635. "Hello world!\n"
  13636. +#define ipkg_trivial_usage \
  13637. + "[options]... sub-command [arguments]..."
  13638. +#define ipkg_full_usage \
  13639. + "ipkg is an utility to install, remove and manage .ipk packages.\n" \
  13640. + "\n" \
  13641. + "Sub-commands:\n" \
  13642. + "\nPackage Manipulation:\n" \
  13643. + "\tupdate Update list of available packages\n" \
  13644. + "\tupgrade Upgrade all installed packages to latest version\n" \
  13645. + "\tinstall <pkg> Download and install <pkg> (and dependencies)\n" \
  13646. + "\tinstall <file.ipk> Install package <file.ipk>\n" \
  13647. + "\tconfigure [<pkg>] Configure unpacked packages\n" \
  13648. + "\tremove <pkg|regexp> Remove package <pkg|packages following regexp>\n" \
  13649. + "\tflag <flag> <pkg> ... Flag package(s) <pkg>\n" \
  13650. + "\t <flag>=hold|noprune|user|ok|installed|unpacked (one per invocation) \n" \
  13651. + "\n" \
  13652. + "Informational Commands:\n" \
  13653. + "\tlist List available packages and descriptions\n" \
  13654. + "\tlist_installed List all and only the installed packages and description \n" \
  13655. + "\tfiles <pkg> List all files belonging to <pkg>\n" \
  13656. + "\tsearch <file|regexp> Search for a package providing <file>\n" \
  13657. + "\tinfo [pkg|regexp [<field>]] Display all/some info fields for <pkg> or all\n" \
  13658. + "\tstatus [pkg|regexp [<field>]] Display all/some status fields for <pkg> or all\n" \
  13659. + "\tdownload <pkg> Download <pkg> to current directory.\n" \
  13660. + "\tcompare_versions <v1> <op> <v2>\n" \
  13661. + "\t compare versions using <= < > >= = << >>\n" \
  13662. + "\tprint_architecture prints the architecture.\n" \
  13663. + "\tprint_installation_architecture\n" \
  13664. + "\twhatdepends [-A] [pkgname|pat]+\n" \
  13665. + "\twhatdependsrec [-A] [pkgname|pat]+\n" \
  13666. + "\twhatprovides [-A] [pkgname|pat]+\n" \
  13667. + "\twhatconflicts [-A] [pkgname|pat]+\n" \
  13668. + "\twhatreplaces [-A] [pkgname|pat]+\n" \
  13669. + "\t prints the installation architecture.\n" \
  13670. + "\n" \
  13671. + "\nOptions:\n" \
  13672. + "\t-A Query all packages with whatdepends, whatprovides, whatreplaces, whatconflicts\n" \
  13673. + "\t-V <level> Set verbosity level to <level>. If no value is\n" \
  13674. + "\t--verbosity <level> provided increase verbosity by one. Verbosity levels:\n" \
  13675. + "\t 0 errors only\n" \
  13676. + "\t 1 normal messages (default)\n" \
  13677. + "\t 2 informative messages\n" \
  13678. + "\t 3 debug output\n" \
  13679. + "\t-f <conf_file> Use <conf_file> as the ipkg configuration file\n" \
  13680. + "\t-conf <conf_file> Default configuration file location\n" \
  13681. + " is /etc/ipkg.conf\n" \
  13682. + "\t-d <dest_name> Use <dest_name> as the the root directory for\n" \
  13683. + "\t-dest <dest_name> package installation, removal, upgrading.\n" \
  13684. + " <dest_name> should be a defined dest name from\n" \
  13685. + " the configuration file, (but can also be a\n" \
  13686. + " directory name in a pinch).\n" \
  13687. + "\t-o <offline_root> Use <offline_root> as the root directory for\n" \
  13688. + "\t-offline <offline_root> offline installation of packages.\n" \
  13689. + "\t-verbose_wget more wget messages\n" \
  13690. + "\n" \
  13691. + "Force Options (use when ipkg is too smart for its own good):\n" \
  13692. + "\t-force-depends Make dependency checks warnings instead of errors\n" \
  13693. + "\t Install/remove package in spite of failed dependences\n" \
  13694. + "\t-force-defaults Use default options for questions asked by ipkg.\n" \
  13695. + " (no prompts). Note that this will not prevent\n" \
  13696. + " package installation scripts from prompting.\n" \
  13697. + "\t-force-reinstall Allow ipkg to reinstall a package.\n" \
  13698. + "\t-force-overwrite Allow ipkg to overwrite files from another package during an install.\n" \
  13699. + "\t-force-downgrade Allow ipkg to downgrade packages.\n" \
  13700. + "\t-force_space Install even if there does not seem to be enough space.\n" \
  13701. + "\t-noaction No action -- test only\n" \
  13702. + "\t-nodeps Do not follow dependences\n" \
  13703. + "\t-force-removal-of-dependent-packages\n" \
  13704. + "\t-recursive Allow ipkg to remove package and all that depend on it.\n" \
  13705. + "\t-test No action -- test only\n" \
  13706. + "\t-t Specify tmp-dir.\n" \
  13707. + "\t--tmp-dir Specify tmp-dir.\n" \
  13708. + "\n" \
  13709. + "\tregexp could be something like 'pkgname*' '*file*' or similar\n" \
  13710. + "\teg: ipkg info 'libstd*' or ipkg search '*libop*' or ipkg remove 'libncur*'\n"
  13711. +
  13712. #endif