001-ipkg.patch 425 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773
  1. diff -Nur busybox-1.21.1.orig/archival/Config.src busybox-1.21.1/archival/Config.src
  2. --- busybox-1.21.1.orig/archival/Config.src 2013-05-12 01:30:43.000000000 +0200
  3. +++ busybox-1.21.1/archival/Config.src 2014-02-17 14:25:39.802534016 +0100
  4. @@ -214,6 +214,12 @@
  5. are actually slower than gzip at equivalent compression ratios
  6. and take up 3.2K of code.
  7. +config IPKG
  8. + bool "ipkg"
  9. + default n
  10. + help
  11. + ipkg is the itsy package management system.
  12. +
  13. config RPM2CPIO
  14. bool "rpm2cpio"
  15. default y
  16. diff -Nur busybox-1.21.1.orig/archival/ipkg.c busybox-1.21.1/archival/ipkg.c
  17. --- busybox-1.21.1.orig/archival/ipkg.c 1970-01-01 01:00:00.000000000 +0100
  18. +++ busybox-1.21.1/archival/ipkg.c 2014-02-17 14:25:39.802534016 +0100
  19. @@ -0,0 +1,28 @@
  20. +/* ipkg.c - the itsy package management system
  21. +
  22. + Florina Boor
  23. +
  24. + Copyright (C) 2003 kernel concepts
  25. +
  26. + This program is free software; you can redistribute it and/or
  27. + modify it under the terms of the GNU General Public License as
  28. + published by the Free Software Foundation; either version 2, or (at
  29. + your option) any later version.
  30. +
  31. + This program is distributed in the hope that it will be useful, but
  32. + WITHOUT ANY WARRANTY; without even the implied warranty of
  33. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  34. + General Public License for more details.
  35. +
  36. + ipkg command line frontend using libipkg
  37. +
  38. +*/
  39. +
  40. +#include "libbb.h"
  41. +#include "libipkg/libipkg.h"
  42. +
  43. +int ipkg_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  44. +int ipkg_main(int argc, char **argv)
  45. +{
  46. + return ipkg_op(argc, argv);
  47. +}
  48. diff -Nur busybox-1.21.1.orig/archival/Kbuild.src busybox-1.21.1/archival/Kbuild.src
  49. --- busybox-1.21.1.orig/archival/Kbuild.src 2013-05-12 01:30:43.000000000 +0200
  50. +++ busybox-1.21.1/archival/Kbuild.src 2014-02-17 14:25:39.802534016 +0100
  51. @@ -22,6 +22,7 @@
  52. lib-$(CONFIG_LZOP) += lzop.o bbunzip.o
  53. lib-$(CONFIG_GZIP) += gzip.o bbunzip.o
  54. lib-$(CONFIG_BZIP2) += bzip2.o bbunzip.o
  55. +lib-$(CONFIG_IPKG) += ipkg.o
  56. lib-$(CONFIG_UNXZ) += bbunzip.o
  57. lib-$(CONFIG_UNLZMA) += bbunzip.o
  58. diff -Nur busybox-1.21.1.orig/archival/libarchive/Kbuild.src busybox-1.21.1/archival/libarchive/Kbuild.src
  59. --- busybox-1.21.1.orig/archival/libarchive/Kbuild.src 2013-06-29 16:58:06.000000000 +0200
  60. +++ busybox-1.21.1/archival/libarchive/Kbuild.src 2014-02-17 14:25:39.802534016 +0100
  61. @@ -25,14 +25,14 @@
  62. \
  63. data_align.o \
  64. find_list_entry.o \
  65. + get_header_tar.o \
  66. + get_header_tar_gz.o \
  67. init_handle.o
  68. DPKG_FILES:= \
  69. unpack_ar_archive.o \
  70. filter_accept_list_reassign.o \
  71. get_header_ar.o \
  72. - get_header_tar.o \
  73. - get_header_tar_gz.o \
  74. get_header_tar_bz2.o \
  75. get_header_tar_lzma.o \
  76. diff -Nur busybox-1.21.1.orig/archival/libipkg/args.c busybox-1.21.1/archival/libipkg/args.c
  77. --- busybox-1.21.1.orig/archival/libipkg/args.c 1970-01-01 01:00:00.000000000 +0100
  78. +++ busybox-1.21.1/archival/libipkg/args.c 2014-02-17 14:25:39.826534090 +0100
  79. @@ -0,0 +1,242 @@
  80. +/* args.c - parse command-line args
  81. +
  82. + Carl D. Worth
  83. +
  84. + Copyright 2001 University of Southern California
  85. +
  86. + This program is free software; you can redistribute it and/or modify
  87. + it under the terms of the GNU General Public License as published by
  88. + the Free Software Foundation; either version 2, or (at your option)
  89. + any later version.
  90. +
  91. + This program is distributed in the hope that it will be useful,
  92. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  93. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  94. + GNU General Public License for more details.
  95. + */
  96. +
  97. +#include <getopt.h>
  98. +#include <stdlib.h>
  99. +#include <string.h>
  100. +#include <unistd.h>
  101. +
  102. +#include "ipkg.h"
  103. +#include "ipkg_message.h"
  104. +
  105. +#include "args.h"
  106. +#include "sprintf_alloc.h"
  107. +
  108. +#include "libbb.h"
  109. +
  110. +
  111. +static void print_version(void);
  112. +
  113. +enum long_args_opt
  114. +{
  115. + ARGS_OPT_FORCE_DEFAULTS = 129,
  116. + ARGS_OPT_FORCE_DEPENDS,
  117. + ARGS_OPT_FORCE_OVERWRITE,
  118. + ARGS_OPT_FORCE_DOWNGRADE,
  119. + ARGS_OPT_FORCE_REINSTALL,
  120. + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES,
  121. + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES,
  122. + ARGS_OPT_FORCE_SPACE,
  123. + ARGS_OPT_NOACTION,
  124. + ARGS_OPT_NODEPS,
  125. + ARGS_OPT_VERBOSE_WGET,
  126. + ARGS_OPT_VERBOSITY,
  127. + ARGS_OPT_MULTIPLE_PROVIDERS
  128. +};
  129. +
  130. +int args_init(args_t *args)
  131. +{
  132. + const char *conf_file_dir;
  133. +
  134. + memset(args, 0, sizeof(args_t));
  135. +
  136. + args->dest = ARGS_DEFAULT_DEST;
  137. +
  138. + conf_file_dir = getenv("IPKG_CONF_DIR");
  139. + if (conf_file_dir == NULL || conf_file_dir[0] == '\0') {
  140. + conf_file_dir = ARGS_DEFAULT_CONF_FILE_DIR;
  141. + }
  142. + sprintf_alloc(&args->conf_file, "%s/%s", conf_file_dir,
  143. + ARGS_DEFAULT_CONF_FILE_NAME);
  144. +
  145. + args->force_defaults = ARGS_DEFAULT_FORCE_DEFAULTS;
  146. + args->force_depends = ARGS_DEFAULT_FORCE_DEPENDS;
  147. + args->force_overwrite = ARGS_DEFAULT_FORCE_OVERWRITE;
  148. + args->force_downgrade = ARGS_DEFAULT_FORCE_DOWNGRADE;
  149. + args->force_reinstall = ARGS_DEFAULT_FORCE_REINSTALL;
  150. + args->force_removal_of_dependent_packages = ARGS_DEFAULT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES;
  151. + args->force_removal_of_essential_packages = ARGS_DEFAULT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES;
  152. + args->noaction = ARGS_DEFAULT_NOACTION;
  153. + args->nodeps = ARGS_DEFAULT_NODEPS;
  154. + args->verbose_wget = ARGS_DEFAULT_VERBOSE_WGET;
  155. + args->verbosity = ARGS_DEFAULT_VERBOSITY;
  156. + args->offline_root = ARGS_DEFAULT_OFFLINE_ROOT;
  157. + args->offline_root_pre_script_cmd = ARGS_DEFAULT_OFFLINE_ROOT_PRE_SCRIPT_CMD;
  158. + args->offline_root_post_script_cmd = ARGS_DEFAULT_OFFLINE_ROOT_POST_SCRIPT_CMD;
  159. + args->multiple_providers = 0;
  160. + args->nocheckfordirorfile = 0;
  161. + args->noreadfeedsfile = 0;
  162. +
  163. + return 1;
  164. +}
  165. +
  166. +void args_deinit(args_t *args)
  167. +{
  168. + free(args->conf_file);
  169. + args->conf_file = NULL;
  170. +}
  171. +
  172. +int args_parse(args_t *args, int argc, char *argv[])
  173. +{
  174. + int c;
  175. + int option_index = 0;
  176. + int parse_err = 0;
  177. + static struct option long_options[] = {
  178. + {"query-all", 0, 0, 'A'},
  179. + {"conf-file", 1, 0, 'f'},
  180. + {"conf", 1, 0, 'f'},
  181. + {"dest", 1, 0, 'd'},
  182. + {"force-defaults", 0, 0, ARGS_OPT_FORCE_DEFAULTS},
  183. + {"force_defaults", 0, 0, ARGS_OPT_FORCE_DEFAULTS},
  184. + {"force-depends", 0, 0, ARGS_OPT_FORCE_DEPENDS},
  185. + {"force_depends", 0, 0, ARGS_OPT_FORCE_DEPENDS},
  186. + {"force-overwrite", 0, 0, ARGS_OPT_FORCE_OVERWRITE},
  187. + {"force_overwrite", 0, 0, ARGS_OPT_FORCE_OVERWRITE},
  188. + {"force_downgrade", 0, 0, ARGS_OPT_FORCE_DOWNGRADE},
  189. + {"force-downgrade", 0, 0, ARGS_OPT_FORCE_DOWNGRADE},
  190. + {"force-reinstall", 0, 0, ARGS_OPT_FORCE_REINSTALL},
  191. + {"force_reinstall", 0, 0, ARGS_OPT_FORCE_REINSTALL},
  192. + {"force-space", 0, 0, ARGS_OPT_FORCE_SPACE},
  193. + {"force_space", 0, 0, ARGS_OPT_FORCE_SPACE},
  194. + {"recursive", 0, 0,
  195. + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
  196. + {"force-removal-of-dependent-packages", 0, 0,
  197. + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
  198. + {"force_removal_of_dependent_packages", 0, 0,
  199. + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
  200. + {"force-removal-of-essential-packages", 0, 0,
  201. + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES},
  202. + {"force_removal_of_essential_packages", 0, 0,
  203. + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES},
  204. + {"multiple-providers", 0, 0, ARGS_OPT_MULTIPLE_PROVIDERS},
  205. + {"multiple_providers", 0, 0, ARGS_OPT_MULTIPLE_PROVIDERS},
  206. + {"noaction", 0, 0, ARGS_OPT_NOACTION},
  207. + {"nodeps", 0, 0, ARGS_OPT_NODEPS},
  208. + {"offline", 1, 0, 'o'},
  209. + {"offline-root", 1, 0, 'o'},
  210. + {"test", 0, 0, ARGS_OPT_NOACTION},
  211. + {"tmp-dir", 1, 0, 't'},
  212. + {"verbose-wget", 0, 0, ARGS_OPT_VERBOSE_WGET},
  213. + {"verbose_wget", 0, 0, ARGS_OPT_VERBOSE_WGET},
  214. + {"verbosity", 2, 0, 'V'},
  215. + {"version", 0, 0, 'v'},
  216. + {0, 0, 0, 0}
  217. + };
  218. +
  219. + while (1) {
  220. + c = getopt_long_only(argc, argv, "Ad:f:no:t:vV:", long_options, &option_index);
  221. + if (c == -1)
  222. + break;
  223. +
  224. + switch (c) {
  225. + case 'A':
  226. + args->query_all = 1;
  227. + break;
  228. + case 'd':
  229. + args->dest = optarg;
  230. + break;
  231. + case 'f':
  232. + free(args->conf_file);
  233. + args->conf_file = strdup(optarg);
  234. + break;
  235. + case 'o':
  236. + args->offline_root = optarg;
  237. + break;
  238. + case 'n':
  239. + args->noaction = 1;
  240. + break;
  241. + case 't':
  242. + args->tmp_dir = strdup(optarg);
  243. + break;
  244. + case 'v':
  245. + print_version();
  246. + exit(0);
  247. + case 'V':
  248. + case ARGS_OPT_VERBOSITY:
  249. + if (optarg)
  250. + args->verbosity = atoi(optarg);
  251. + else
  252. + args->verbosity += 1;
  253. + break;
  254. + case ARGS_OPT_FORCE_DEFAULTS:
  255. + args->force_defaults = 1;
  256. + break;
  257. + case ARGS_OPT_FORCE_DEPENDS:
  258. + args->force_depends = 1;
  259. + break;
  260. + case ARGS_OPT_FORCE_OVERWRITE:
  261. + args->force_overwrite = 1;
  262. + break;
  263. + case ARGS_OPT_FORCE_DOWNGRADE:
  264. + args->force_downgrade = 1;
  265. + break;
  266. + case ARGS_OPT_FORCE_REINSTALL:
  267. + args->force_reinstall = 1;
  268. + break;
  269. + case ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES:
  270. + args->force_removal_of_essential_packages = 1;
  271. + break;
  272. + case ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES:
  273. + args->force_removal_of_dependent_packages = 1;
  274. + break;
  275. + case ARGS_OPT_FORCE_SPACE:
  276. + args->force_space = 1;
  277. + break;
  278. + case ARGS_OPT_VERBOSE_WGET:
  279. + args->verbose_wget = 1;
  280. + break;
  281. + case ARGS_OPT_MULTIPLE_PROVIDERS:
  282. + args->multiple_providers = 1;
  283. + break;
  284. + case ARGS_OPT_NODEPS:
  285. + args->nodeps = 1;
  286. + break;
  287. + case ARGS_OPT_NOACTION:
  288. + args->noaction = 1;
  289. + break;
  290. + case ':':
  291. + parse_err++;
  292. + break;
  293. + case '?':
  294. + parse_err++;
  295. + break;
  296. + default:
  297. + bb_error_msg("Confusion: getopt_long returned %d\n", c);
  298. + }
  299. + }
  300. +
  301. + if (parse_err) {
  302. + return -parse_err;
  303. + } else {
  304. + return optind;
  305. + }
  306. +}
  307. +
  308. +void args_usage(const char *complaint)
  309. +{
  310. + if (complaint) {
  311. + bb_error_msg("%s\n", complaint);
  312. + }
  313. + print_version();
  314. + bb_show_usage();
  315. + exit(1);
  316. +}
  317. +
  318. +static void print_version(void)
  319. +{
  320. + bb_error_msg("version %s\n", IPKG_VERSION);
  321. +}
  322. diff -Nur busybox-1.21.1.orig/archival/libipkg/args.h busybox-1.21.1/archival/libipkg/args.h
  323. --- busybox-1.21.1.orig/archival/libipkg/args.h 1970-01-01 01:00:00.000000000 +0100
  324. +++ busybox-1.21.1/archival/libipkg/args.h 2014-02-17 14:25:39.826534090 +0100
  325. @@ -0,0 +1,72 @@
  326. +/* args.h - parse command-line args
  327. +
  328. + Carl D. Worth
  329. +
  330. + Copyright 2001 University of Southern California
  331. +
  332. + This program is free software; you can redistribute it and/or modify
  333. + it under the terms of the GNU General Public License as published by
  334. + the Free Software Foundation; either version 2, or (at your option)
  335. + any later version.
  336. +
  337. + This program is distributed in the hope that it will be useful,
  338. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  339. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  340. + GNU General Public License for more details.
  341. +*/
  342. +
  343. +#ifndef ARGS_H
  344. +#define ARGS_H
  345. +
  346. +struct args
  347. +{
  348. + char *conf_file;
  349. + char *dest;
  350. + char *tmp_dir;
  351. + int force_defaults;
  352. + int force_depends;
  353. + int force_overwrite;
  354. + int force_downgrade;
  355. + int force_reinstall;
  356. + int force_removal_of_essential_packages;
  357. + int force_removal_of_dependent_packages;
  358. + int force_space;
  359. + int noaction;
  360. + int nodeps;
  361. + int multiple_providers;
  362. + int query_all;
  363. + int verbose_wget;
  364. + int verbosity;
  365. + int nocheckfordirorfile;
  366. + int noreadfeedsfile;
  367. + char *offline_root;
  368. + char *offline_root_pre_script_cmd;
  369. + char *offline_root_post_script_cmd;
  370. +};
  371. +typedef struct args args_t;
  372. +
  373. +#define ARGS_DEFAULT_CONF_FILE_DIR "/etc"
  374. +#define ARGS_DEFAULT_CONF_FILE_NAME "ipkg.conf"
  375. +#define ARGS_DEFAULT_DEST NULL
  376. +#define ARGS_DEFAULT_FORCE_DEFAULTS 0
  377. +#define ARGS_DEFAULT_FORCE_DEPENDS 0
  378. +#define ARGS_DEFAULT_FORCE_OVERWRITE 0
  379. +#define ARGS_DEFAULT_FORCE_DOWNGRADE 0
  380. +#define ARGS_DEFAULT_FORCE_REINSTALL 0
  381. +#define ARGS_DEFAULT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES 0
  382. +#define ARGS_DEFAULT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES 0
  383. +#define ARGS_DEFAULT_FORCE_SPACE 0
  384. +#define ARGS_DEFAULT_OFFLINE_ROOT NULL
  385. +#define ARGS_DEFAULT_OFFLINE_ROOT_PRE_SCRIPT_CMD NULL
  386. +#define ARGS_DEFAULT_OFFLINE_ROOT_POST_SCRIPT_CMD NULL
  387. +#define ARGS_DEFAULT_NOACTION 0
  388. +#define ARGS_DEFAULT_NODEPS 0
  389. +#define ARGS_DEFAULT_VERBOSE_WGET 0
  390. +#define ARGS_DEFAULT_VERBOSITY 1
  391. +
  392. +int args_init(args_t *args);
  393. +void args_deinit(args_t *args);
  394. +int args_parse(args_t *args, int argc, char *argv[]);
  395. +void args_usage(const char *complaint);
  396. +
  397. +#endif
  398. diff -Nur busybox-1.21.1.orig/archival/libipkg/conffile.c busybox-1.21.1/archival/libipkg/conffile.c
  399. --- busybox-1.21.1.orig/archival/libipkg/conffile.c 1970-01-01 01:00:00.000000000 +0100
  400. +++ busybox-1.21.1/archival/libipkg/conffile.c 2014-02-17 14:25:39.826534090 +0100
  401. @@ -0,0 +1,65 @@
  402. +/* conffile.c - the itsy package management system
  403. +
  404. + Carl D. Worth
  405. +
  406. + Copyright (C) 2001 University of Southern California
  407. +
  408. + This program is free software; you can redistribute it and/or
  409. + modify it under the terms of the GNU General Public License as
  410. + published by the Free Software Foundation; either version 2, or (at
  411. + your option) any later version.
  412. +
  413. + This program is distributed in the hope that it will be useful, but
  414. + WITHOUT ANY WARRANTY; without even the implied warranty of
  415. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  416. + General Public License for more details.
  417. +*/
  418. +
  419. +#include <string.h>
  420. +#include <stdlib.h>
  421. +
  422. +#include "libbb.h"
  423. +#include "ipkg.h"
  424. +#include "ipkg_message.h"
  425. +
  426. +#include "conffile.h"
  427. +#include "file_util.h"
  428. +#include "sprintf_alloc.h"
  429. +
  430. +int conffile_init(conffile_t *conffile, const char *file_name, const uint8_t *md5sum)
  431. +{
  432. + return nv_pair_init(conffile, file_name, (char *)md5sum);
  433. +}
  434. +
  435. +void conffile_deinit(conffile_t *conffile)
  436. +{
  437. + nv_pair_deinit(conffile);
  438. +}
  439. +
  440. +int conffile_has_been_modified(ipkg_conf_t *conf, conffile_t *conffile)
  441. +{
  442. + uint8_t *md5sum;
  443. + char *filename = conffile->name;
  444. + char *root_filename;
  445. + int ret;
  446. +
  447. + if (conffile->value == NULL) {
  448. + ipkg_message(conf, IPKG_NOTICE, "%s: conffile %s has no md5sum\n", __FUNCTION__, conffile->name);
  449. + return 1;
  450. + }
  451. +
  452. + root_filename = root_filename_alloc(conf, filename);
  453. +
  454. + md5sum = file_md5sum_alloc(root_filename);
  455. +
  456. + ret = strcmp((char *)md5sum, conffile->value);
  457. + if (ret) {
  458. + ipkg_message(conf, IPKG_NOTICE, "%s: conffile %s: \t\nold md5=%s \t\nnew md5=%s\n", __FUNCTION__,
  459. + conffile->name, md5sum, conffile->value);
  460. + }
  461. +
  462. + free(root_filename);
  463. + free(md5sum);
  464. +
  465. + return ret;
  466. +}
  467. diff -Nur busybox-1.21.1.orig/archival/libipkg/conffile.h busybox-1.21.1/archival/libipkg/conffile.h
  468. --- busybox-1.21.1.orig/archival/libipkg/conffile.h 1970-01-01 01:00:00.000000000 +0100
  469. +++ busybox-1.21.1/archival/libipkg/conffile.h 2014-02-17 14:25:39.826534090 +0100
  470. @@ -0,0 +1,30 @@
  471. +/* conffile.h - the itsy package management system
  472. +
  473. + Carl D. Worth
  474. +
  475. + Copyright (C) 2001 University of Southern California
  476. +
  477. + This program is free software; you can redistribute it and/or
  478. + modify it under the terms of the GNU General Public License as
  479. + published by the Free Software Foundation; either version 2, or (at
  480. + your option) any later version.
  481. +
  482. + This program is distributed in the hope that it will be useful, but
  483. + WITHOUT ANY WARRANTY; without even the implied warranty of
  484. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  485. + General Public License for more details.
  486. +*/
  487. +
  488. +#ifndef CONFFILE_H
  489. +#define CONFFILE_H
  490. +
  491. +#include "nv_pair.h"
  492. +
  493. +typedef struct nv_pair conffile_t;
  494. +
  495. +int conffile_init(conffile_t *conffile, const char *file_name, const uint8_t *md5sum);
  496. +void conffile_deinit(conffile_t *conffile);
  497. +int conffile_has_been_modified(struct ipkg_conf *conf, conffile_t *conffile);
  498. +
  499. +#endif
  500. +
  501. diff -Nur busybox-1.21.1.orig/archival/libipkg/conffile_list.c busybox-1.21.1/archival/libipkg/conffile_list.c
  502. --- busybox-1.21.1.orig/archival/libipkg/conffile_list.c 1970-01-01 01:00:00.000000000 +0100
  503. +++ busybox-1.21.1/archival/libipkg/conffile_list.c 2014-02-17 14:25:39.850534164 +0100
  504. @@ -0,0 +1,47 @@
  505. +/* conffile_list.c - the itsy package management system
  506. +
  507. + Carl D. Worth
  508. +
  509. + Copyright (C) 2001 University of Southern California
  510. +
  511. + This program is free software; you can redistribute it and/or
  512. + modify it under the terms of the GNU General Public License as
  513. + published by the Free Software Foundation; either version 2, or (at
  514. + your option) any later version.
  515. +
  516. + This program is distributed in the hope that it will be useful, but
  517. + WITHOUT ANY WARRANTY; without even the implied warranty of
  518. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  519. + General Public License for more details.
  520. +*/
  521. +
  522. +#include "ipkg.h"
  523. +
  524. +#include "conffile_list.h"
  525. +
  526. +int conffile_list_init(conffile_list_t *list)
  527. +{
  528. + return nv_pair_list_init(list);
  529. +}
  530. +
  531. +void conffile_list_deinit(conffile_list_t *list)
  532. +{
  533. + nv_pair_list_deinit(list);
  534. +}
  535. +
  536. +conffile_t *conffile_list_append(conffile_list_t *list, const char *file_name,
  537. + const char *md5sum)
  538. +{
  539. + return nv_pair_list_append(list, file_name, md5sum);
  540. +}
  541. +
  542. +int conffile_list_push(conffile_list_t *list, conffile_t *data)
  543. +{
  544. + return nv_pair_list_push(list, data);
  545. +}
  546. +
  547. +conffile_list_elt_t *conffile_list_pop(conffile_list_t *list)
  548. +{
  549. + return nv_pair_list_pop(list);
  550. +}
  551. +
  552. diff -Nur busybox-1.21.1.orig/archival/libipkg/conffile_list.h busybox-1.21.1/archival/libipkg/conffile_list.h
  553. --- busybox-1.21.1.orig/archival/libipkg/conffile_list.h 1970-01-01 01:00:00.000000000 +0100
  554. +++ busybox-1.21.1/archival/libipkg/conffile_list.h 2014-02-17 14:25:39.850534164 +0100
  555. @@ -0,0 +1,36 @@
  556. +/* conffile_list.h - the itsy package management system
  557. +
  558. + Carl D. Worth
  559. +
  560. + Copyright (C) 2001 University of Southern California
  561. +
  562. + This program is free software; you can redistribute it and/or
  563. + modify it under the terms of the GNU General Public License as
  564. + published by the Free Software Foundation; either version 2, or (at
  565. + your option) any later version.
  566. +
  567. + This program is distributed in the hope that it will be useful, but
  568. + WITHOUT ANY WARRANTY; without even the implied warranty of
  569. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  570. + General Public License for more details.
  571. +*/
  572. +
  573. +#ifndef CONFFILE_LIST_H
  574. +#define CONFFILE_LIST_H
  575. +
  576. +#include "conffile.h"
  577. +#include "nv_pair_list.h"
  578. +
  579. +typedef struct nv_pair_list_elt conffile_list_elt_t;
  580. +typedef struct nv_pair_list conffile_list_t;
  581. +
  582. +int conffile_list_init(conffile_list_t *list);
  583. +void conffile_list_deinit(conffile_list_t *list);
  584. +
  585. +conffile_t *conffile_list_append(conffile_list_t *list, const char *name,
  586. + const char *root_dir);
  587. +int conffile_list_push(conffile_list_t *list, conffile_t *data);
  588. +conffile_list_elt_t *conffile_list_pop(conffile_list_t *list);
  589. +
  590. +#endif
  591. +
  592. diff -Nur busybox-1.21.1.orig/archival/libipkg/file_util.c busybox-1.21.1/archival/libipkg/file_util.c
  593. --- busybox-1.21.1.orig/archival/libipkg/file_util.c 1970-01-01 01:00:00.000000000 +0100
  594. +++ busybox-1.21.1/archival/libipkg/file_util.c 2014-02-17 14:25:39.850534164 +0100
  595. @@ -0,0 +1,186 @@
  596. +/* file_util.c - convenience routines for common stat operations
  597. +
  598. + Carl D. Worth
  599. +
  600. + Copyright (C) 2001 University of Southern California
  601. +
  602. + This program is free software; you can redistribute it and/or
  603. + modify it under the terms of the GNU General Public License as
  604. + published by the Free Software Foundation; either version 2, or (at
  605. + your option) any later version.
  606. +
  607. + This program is distributed in the hope that it will be useful, but
  608. + WITHOUT ANY WARRANTY; without even the implied warranty of
  609. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  610. + General Public License for more details.
  611. +*/
  612. +
  613. +#include "ipkg.h"
  614. +#include <sys/types.h>
  615. +#include <sys/stat.h>
  616. +
  617. +#include "sprintf_alloc.h"
  618. +#include "file_util.h"
  619. +#include "libbb.h"
  620. +#undef strlen
  621. +
  622. +int file_exists(const char *file_name)
  623. +{
  624. + int err;
  625. + struct stat stat_buf;
  626. +
  627. + err = stat(file_name, &stat_buf);
  628. + if (err == 0) {
  629. + return 1;
  630. + } else {
  631. + return 0;
  632. + }
  633. +}
  634. +
  635. +int file_is_dir(const char *file_name)
  636. +{
  637. + int err;
  638. + struct stat stat_buf;
  639. +
  640. + err = stat(file_name, &stat_buf);
  641. + if (err) {
  642. + return 0;
  643. + }
  644. +
  645. + return S_ISDIR(stat_buf.st_mode);
  646. +}
  647. +
  648. +/* read a single line from a file, stopping at a newline or EOF.
  649. + If a newline is read, it will appear in the resulting string.
  650. + Return value is a malloc'ed char * which should be freed at
  651. + some point by the caller.
  652. +
  653. + Return value is NULL if the file is at EOF when called.
  654. +*/
  655. +#define FILE_READ_LINE_BUF_SIZE 1024
  656. +char *file_read_line_alloc(FILE *file)
  657. +{
  658. + char buf[FILE_READ_LINE_BUF_SIZE];
  659. + int buf_len;
  660. + char *line = NULL;
  661. + int line_size = 0;
  662. +
  663. + memset(buf, 0, FILE_READ_LINE_BUF_SIZE);
  664. + while (fgets(buf, FILE_READ_LINE_BUF_SIZE, file)) {
  665. + buf_len = strlen(buf);
  666. + if (line) {
  667. + line_size += buf_len;
  668. + line = realloc(line, line_size);
  669. + if (line == NULL) {
  670. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  671. + break;
  672. + }
  673. + strcat(line, buf);
  674. + } else {
  675. + line_size = buf_len + 1;
  676. + line = strdup(buf);
  677. + }
  678. + if (buf[buf_len - 1] == '\n') {
  679. + break;
  680. + }
  681. + }
  682. +
  683. + return line;
  684. +}
  685. +
  686. +int file_move(const char *src, const char *dest)
  687. +{
  688. + int err;
  689. +
  690. + err = rename(src, dest);
  691. +
  692. + if (err && errno == EXDEV) {
  693. + err = file_copy(src, dest);
  694. + unlink(src);
  695. + } else if (err) {
  696. + fprintf(stderr, "%s: ERROR: failed to rename %s to %s: %s\n",
  697. + __FUNCTION__, src, dest, strerror(errno));
  698. + }
  699. +
  700. + return err;
  701. +}
  702. +
  703. +/* I put these here to keep libbb dependencies from creeping all over
  704. + the ipkg code */
  705. +int file_copy(const char *src, const char *dest)
  706. +{
  707. + int err;
  708. +
  709. + err = copy_file(src, dest, FILEUTILS_FORCE | FILEUTILS_PRESERVE_STATUS);
  710. + if (err) {
  711. + fprintf(stderr, "%s: ERROR: failed to copy %s to %s\n",
  712. + __FUNCTION__, src, dest);
  713. + }
  714. +
  715. + return err;
  716. +}
  717. +
  718. +int file_mkdir_hier(char *path, long mode)
  719. +{
  720. + return bb_make_directory(path, mode, FILEUTILS_RECUR);
  721. +}
  722. +
  723. +static unsigned char *hash_bin_to_hex(unsigned char *hash_value,
  724. + unsigned hash_length)
  725. +{
  726. + /* xzalloc zero-terminates */
  727. + char *hex_value = xzalloc((hash_length * 2) + 1);
  728. + bin2hex(hex_value, (char*)hash_value, hash_length);
  729. + return (unsigned char *)hex_value;
  730. +}
  731. +
  732. +static uint8_t *hash_file(const char *filename, hash_algo_t hash_algo)
  733. +{
  734. + int src_fd, hash_len, count;
  735. + union _ctx_ {
  736. + sha1_ctx_t sha1;
  737. + md5_ctx_t md5;
  738. + } context;
  739. + uint8_t *hash_value = NULL;
  740. + RESERVE_CONFIG_UBUFFER(in_buf, 4096);
  741. + void FAST_FUNC (*update)(void*, const void*, size_t);
  742. + void FAST_FUNC (*final)(void*, void*);
  743. +
  744. + src_fd = open_or_warn_stdin(filename);
  745. + if (src_fd < 0) {
  746. + return NULL;
  747. + }
  748. +
  749. + /* figure specific hash algorithims */
  750. + if (ENABLE_MD5SUM && hash_algo == HASH_MD5) {
  751. + md5_begin(&context.md5);
  752. + update = (void*)md5_hash;
  753. + final = (void*)md5_end;
  754. + hash_len = 16;
  755. + } else {
  756. + bb_error_msg_and_die("algorithm not supported");
  757. + }
  758. +
  759. + while ((count = safe_read(src_fd, in_buf, 4096)) > 0) {
  760. + update(&context, in_buf, count);
  761. + }
  762. +
  763. + if (count == 0) {
  764. + final(&context, in_buf);
  765. + hash_value = hash_bin_to_hex(in_buf, hash_len);
  766. + }
  767. +
  768. + RELEASE_CONFIG_BUFFER(in_buf);
  769. +
  770. + if (src_fd != STDIN_FILENO) {
  771. + close(src_fd);
  772. + }
  773. +
  774. + return hash_value;
  775. +}
  776. +
  777. +uint8_t *file_md5sum_alloc(const char *file_name)
  778. +{
  779. + return hash_file(file_name, HASH_MD5);
  780. +}
  781. +
  782. diff -Nur busybox-1.21.1.orig/archival/libipkg/file_util.h busybox-1.21.1/archival/libipkg/file_util.h
  783. --- busybox-1.21.1.orig/archival/libipkg/file_util.h 1970-01-01 01:00:00.000000000 +0100
  784. +++ busybox-1.21.1/archival/libipkg/file_util.h 2014-02-17 14:25:39.850534164 +0100
  785. @@ -0,0 +1,29 @@
  786. +/* file_util.h - convenience routines for common file operations
  787. +
  788. + Carl D. Worth
  789. +
  790. + Copyright (C) 2001 University of Southern California
  791. +
  792. + This program is free software; you can redistribute it and/or
  793. + modify it under the terms of the GNU General Public License as
  794. + published by the Free Software Foundation; either version 2, or (at
  795. + your option) any later version.
  796. +
  797. + This program is distributed in the hope that it will be useful, but
  798. + WITHOUT ANY WARRANTY; without even the implied warranty of
  799. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  800. + General Public License for more details.
  801. +*/
  802. +
  803. +#ifndef FILE_UTIL_H
  804. +#define FILE_UTIL_H
  805. +
  806. +int file_exists(const char *file_name);
  807. +int file_is_dir(const char *file_name);
  808. +char *file_read_line_alloc(FILE *file);
  809. +int file_move(const char *src, const char *dest);
  810. +int file_copy(const char *src, const char *dest);
  811. +int file_mkdir_hier(char *path, long mode);
  812. +uint8_t *file_md5sum_alloc(const char *file_name);
  813. +
  814. +#endif
  815. diff -Nur busybox-1.21.1.orig/archival/libipkg/hash_table.c busybox-1.21.1/archival/libipkg/hash_table.c
  816. --- busybox-1.21.1.orig/archival/libipkg/hash_table.c 1970-01-01 01:00:00.000000000 +0100
  817. +++ busybox-1.21.1/archival/libipkg/hash_table.c 2014-02-17 14:25:39.850534164 +0100
  818. @@ -0,0 +1,155 @@
  819. +/* hash.c - hash tables for ipkg
  820. +
  821. + Steven M. Ayer, Jamey Hicks
  822. +
  823. + Copyright (C) 2002 Compaq Computer Corporation
  824. +
  825. + This program is free software; you can redistribute it and/or
  826. + modify it under the terms of the GNU General Public License as
  827. + published by the Free Software Foundation; either version 2, or (at
  828. + your option) any later version.
  829. +
  830. + This program is distributed in the hope that it will be useful, but
  831. + WITHOUT ANY WARRANTY; without even the implied warranty of
  832. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  833. + General Public License for more details.
  834. +*/
  835. +
  836. +#include <errno.h>
  837. +#include <stdio.h>
  838. +#include <stdlib.h>
  839. +#include <string.h>
  840. +#include "hash_table.h"
  841. +#include "ipkg_message.h"
  842. +
  843. +
  844. +static int hash_index(hash_table_t *hash, const char *pkg_name);
  845. +static int rotating(const char *key, int len, int prime);
  846. +
  847. +static int hash_index(hash_table_t *hash, const char *pkg_name)
  848. +{
  849. + return rotating(pkg_name, strlen(pkg_name), hash->n_entries);
  850. +}
  851. +
  852. +static int rotating(const char *key, int len, int prime)
  853. +{
  854. + unsigned int hash, i;
  855. + for (hash=len, i=0; i<len; ++i)
  856. + hash = (hash<<4)^(hash>>28)^key[i];
  857. + return (hash % prime);
  858. +}
  859. +
  860. +
  861. +/*
  862. + * this is an open table keyed by strings
  863. + */
  864. +int hash_table_init(const char *name, hash_table_t *hash, int len)
  865. +{
  866. + static int primes_table[] = {
  867. + 379, 761, 983, 1423, 2711, 3361, 3931, 4679, 5519, 6701, 9587,
  868. + 19471, 23143, 33961, 46499, 49727, 99529, 0
  869. + };
  870. + int *picker;
  871. +
  872. + if (hash->entries != NULL) {
  873. + /* we have been here already */
  874. + return 0;
  875. + }
  876. +
  877. + hash->name = name;
  878. + hash->entries = NULL;
  879. + hash->n_entries = 0;
  880. + hash->hash_entry_key = NULL;
  881. +
  882. + picker = primes_table;
  883. + while(*picker && (*picker++ < len));
  884. + if(!*picker)
  885. + fprintf(stderr, "%s: primes table might not be big enough (! << %d)\n", __FUNCTION__, len);
  886. + --picker;
  887. +
  888. + hash->n_entries = *picker;
  889. + hash->entries = (hash_entry_t *)calloc(hash->n_entries, sizeof(hash_entry_t));
  890. + if (hash->entries == NULL) {
  891. + fprintf(stderr, "%s: Out of memory.\n", __FUNCTION__);
  892. + return ENOMEM;
  893. + }
  894. + return 0;
  895. +}
  896. +
  897. +void hash_table_deinit(hash_table_t *hash)
  898. +{
  899. + free(hash->entries);
  900. + hash->entries = NULL;
  901. + hash->n_entries = 0;
  902. +}
  903. +
  904. +void *hash_table_get(hash_table_t *hash, const char *key)
  905. +{
  906. + int ndx= hash_index(hash, key);
  907. + hash_entry_t *hash_entry = hash->entries + ndx;
  908. + while (hash_entry)
  909. + {
  910. + if (hash_entry->key)
  911. + {
  912. + if (strcmp(key, hash_entry->key) == 0) {
  913. + // ipkg_message(NULL, IPKG_DEBUG, "Function: %s. Key found for '%s' \n", __FUNCTION__, key);
  914. + return hash_entry->data;
  915. + }
  916. + }
  917. + hash_entry = hash_entry->next;
  918. + }
  919. + return NULL;
  920. +}
  921. +
  922. +int hash_table_insert(hash_table_t *hash, const char *key, void *value)
  923. +{
  924. + int ndx= hash_index(hash, key);
  925. + hash_entry_t *hash_entry = hash->entries + ndx;
  926. + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Inserting in hash for '%s' \n", __FUNCTION__, key);
  927. + if (hash_entry->key) {
  928. + if (strcmp(hash_entry->key, key) == 0) {
  929. + /* alread in table, update the value */
  930. + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Value already in hash for '%s' \n", __FUNCTION__, key);
  931. + hash_entry->data = value;
  932. + return 0;
  933. + } else {
  934. + /*
  935. + * if this is a collision, we have to go to the end of the ll,
  936. + * then add a new entry
  937. + * before we can hook up the value
  938. + */
  939. + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Value already in hash by collision for '%s' \n", __FUNCTION__, key);
  940. + while (hash_entry->next)
  941. + hash_entry = hash_entry->next;
  942. + hash_entry->next = (hash_entry_t *)malloc(sizeof(hash_entry_t));
  943. + if (!hash_entry->next) {
  944. + return -ENOMEM;
  945. + }
  946. + hash_entry = hash_entry->next;
  947. + hash_entry->next = NULL;
  948. + }
  949. + }
  950. + hash->n_elements++;
  951. + hash_entry->key = strdup(key);
  952. + hash_entry->data = value;
  953. +
  954. + return 0;
  955. +}
  956. +
  957. +
  958. +void hash_table_foreach(hash_table_t *hash, void (*f)(const char *key, void *entry, void *data), void *data)
  959. +{
  960. + int i;
  961. + if (!hash || !f)
  962. + return;
  963. +
  964. + for (i = 0; i < hash->n_entries; i++) {
  965. + hash_entry_t *hash_entry = (hash->entries + i);
  966. + do {
  967. + if(hash_entry->key) {
  968. + f(hash_entry->key, hash_entry->data, data);
  969. + }
  970. + } while((hash_entry = hash_entry->next));
  971. + }
  972. +}
  973. +
  974. diff -Nur busybox-1.21.1.orig/archival/libipkg/hash_table.h busybox-1.21.1/archival/libipkg/hash_table.h
  975. --- busybox-1.21.1.orig/archival/libipkg/hash_table.h 1970-01-01 01:00:00.000000000 +0100
  976. +++ busybox-1.21.1/archival/libipkg/hash_table.h 2014-02-17 14:25:39.854534176 +0100
  977. @@ -0,0 +1,44 @@
  978. +/* hash.h - hash tables for ipkg
  979. +
  980. + Steven M. Ayer, Jamey Hicks
  981. +
  982. + Copyright (C) 2002 Compaq Computer Corporation
  983. +
  984. + This program is free software; you can redistribute it and/or
  985. + modify it under the terms of the GNU General Public License as
  986. + published by the Free Software Foundation; either version 2, or (at
  987. + your option) any later version.
  988. +
  989. + This program is distributed in the hope that it will be useful, but
  990. + WITHOUT ANY WARRANTY; without even the implied warranty of
  991. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  992. + General Public License for more details.
  993. +*/
  994. +
  995. +#ifndef _HASH_TABLE_H_
  996. +#define _HASH_TABLE_H_
  997. +
  998. +typedef struct hash_entry hash_entry_t;
  999. +typedef struct hash_table hash_table_t;
  1000. +
  1001. +struct hash_entry {
  1002. + const char * key;
  1003. + void * data;
  1004. + struct hash_entry * next;
  1005. +};
  1006. +
  1007. +struct hash_table {
  1008. + const char *name;
  1009. + hash_entry_t * entries;
  1010. + int n_entries; /* number of buckets */
  1011. + int n_elements;
  1012. + const char * (*hash_entry_key)(void * data);
  1013. +};
  1014. +
  1015. +int hash_table_init(const char *name, hash_table_t *hash, int len);
  1016. +void hash_table_deinit(hash_table_t *hash);
  1017. +void *hash_table_get(hash_table_t *hash, const char *key);
  1018. +int hash_table_insert(hash_table_t *hash, const char *key, void *value);
  1019. +void hash_table_foreach(hash_table_t *hash, void (*f)(const char *key, void *entry, void *data), void *data);
  1020. +
  1021. +#endif /* _HASH_TABLE_H_ */
  1022. diff -Nur busybox-1.21.1.orig/archival/libipkg/ipkg_cmd.c busybox-1.21.1/archival/libipkg/ipkg_cmd.c
  1023. --- busybox-1.21.1.orig/archival/libipkg/ipkg_cmd.c 1970-01-01 01:00:00.000000000 +0100
  1024. +++ busybox-1.21.1/archival/libipkg/ipkg_cmd.c 2014-02-17 14:25:39.858534188 +0100
  1025. @@ -0,0 +1,1367 @@
  1026. +/* ipkg_cmd.c - the itsy package management system
  1027. +
  1028. + Carl D. Worth
  1029. +
  1030. + Copyright (C) 2001 University of Southern California
  1031. +
  1032. + This program is free software; you can redistribute it and/or
  1033. + modify it under the terms of the GNU General Public License as
  1034. + published by the Free Software Foundation; either version 2, or (at
  1035. + your option) any later version.
  1036. +
  1037. + This program is distributed in the hope that it will be useful, but
  1038. + WITHOUT ANY WARRANTY; without even the implied warranty of
  1039. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  1040. + General Public License for more details.
  1041. +*/
  1042. +
  1043. +#include <string.h>
  1044. +
  1045. +#include "ipkg.h"
  1046. +#include <libgen.h>
  1047. +#include <glob.h>
  1048. +#include <errno.h>
  1049. +#include <stdlib.h>
  1050. +#include <unistd.h>
  1051. +#include <signal.h>
  1052. +#include <stdio.h>
  1053. +#include <dirent.h>
  1054. +
  1055. +#include "ipkg_conf.h"
  1056. +#include "ipkg_cmd.h"
  1057. +#include "ipkg_message.h"
  1058. +#include "pkg.h"
  1059. +#include "pkg_dest.h"
  1060. +#include "pkg_parse.h"
  1061. +#include "sprintf_alloc.h"
  1062. +#include "pkg.h"
  1063. +#include "file_util.h"
  1064. +#include "str_util.h"
  1065. +#include "bb_archive.h"
  1066. +
  1067. +#include <fnmatch.h>
  1068. +
  1069. +
  1070. +#include "ipkg_download.h"
  1071. +#include "ipkg_install.h"
  1072. +#include "ipkg_upgrade.h"
  1073. +#include "ipkg_remove.h"
  1074. +#include "ipkg_configure.h"
  1075. +#include "ipkg_message.h"
  1076. +
  1077. +#include "libipkg.h"
  1078. +static void *p_userdata = NULL;
  1079. +
  1080. +static int ipkg_update_cmd(ipkg_conf_t *conf);
  1081. +static int ipkg_upgrade_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1082. +static int ipkg_list_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1083. +static int ipkg_info_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1084. +static int ipkg_status_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1085. +static int ipkg_install_pending_cmd(ipkg_conf_t *conf);
  1086. +static int ipkg_install_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1087. +static int ipkg_list_installed_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1088. +static int ipkg_remove_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1089. +static int ipkg_purge_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1090. +static int ipkg_flag_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1091. +static int ipkg_files_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1092. +static int ipkg_search_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1093. +static int ipkg_download_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1094. +static int ipkg_depends_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1095. +static int ipkg_whatdepends_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1096. +static int ipkg_whatdepends_recursively_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1097. +static int ipkg_whatsuggests_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1098. +static int ipkg_whatrecommends_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1099. +static int ipkg_whatprovides_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1100. +static int ipkg_whatconflicts_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1101. +static int ipkg_whatreplaces_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1102. +static int ipkg_compare_versions_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1103. +static int ipkg_print_architecture_cmd(ipkg_conf_t *conf);
  1104. +static int ipkg_configure_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1105. +
  1106. +/* XXX: CLEANUP: The usage strings should be incorporated into this
  1107. + array for easier maintenance */
  1108. +static ipkg_cmd_t cmds[] = {
  1109. + {"update", 0, (ipkg_cmd_fun_t)ipkg_update_cmd},
  1110. + {"upgrade", 0, (ipkg_cmd_fun_t)ipkg_upgrade_cmd},
  1111. + {"list", 0, (ipkg_cmd_fun_t)ipkg_list_cmd},
  1112. + {"list_installed", 0, (ipkg_cmd_fun_t)ipkg_list_installed_cmd},
  1113. + {"info", 0, (ipkg_cmd_fun_t)ipkg_info_cmd},
  1114. + {"flag", 1, (ipkg_cmd_fun_t)ipkg_flag_cmd},
  1115. + {"status", 0, (ipkg_cmd_fun_t)ipkg_status_cmd},
  1116. + {"install_pending", 0, (ipkg_cmd_fun_t)ipkg_install_pending_cmd},
  1117. + {"install", 1, (ipkg_cmd_fun_t)ipkg_install_cmd},
  1118. + {"remove", 1, (ipkg_cmd_fun_t)ipkg_remove_cmd},
  1119. + {"purge", 1, (ipkg_cmd_fun_t)ipkg_purge_cmd},
  1120. + {"configure", 0, (ipkg_cmd_fun_t)ipkg_configure_cmd},
  1121. + {"files", 1, (ipkg_cmd_fun_t)ipkg_files_cmd},
  1122. + {"search", 1, (ipkg_cmd_fun_t)ipkg_search_cmd},
  1123. + {"download", 1, (ipkg_cmd_fun_t)ipkg_download_cmd},
  1124. + {"compare_versions", 1, (ipkg_cmd_fun_t)ipkg_compare_versions_cmd},
  1125. + {"compare-versions", 1, (ipkg_cmd_fun_t)ipkg_compare_versions_cmd},
  1126. + {"print-architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
  1127. + {"print_architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
  1128. + {"print-installation-architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
  1129. + {"print_installation_architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
  1130. + {"depends", 1, (ipkg_cmd_fun_t)ipkg_depends_cmd},
  1131. + {"whatdepends", 1, (ipkg_cmd_fun_t)ipkg_whatdepends_cmd},
  1132. + {"whatdependsrec", 1, (ipkg_cmd_fun_t)ipkg_whatdepends_recursively_cmd},
  1133. + {"whatrecommends", 1, (ipkg_cmd_fun_t)ipkg_whatrecommends_cmd},
  1134. + {"whatsuggests", 1, (ipkg_cmd_fun_t)ipkg_whatsuggests_cmd},
  1135. + {"whatprovides", 1, (ipkg_cmd_fun_t)ipkg_whatprovides_cmd},
  1136. + {"whatreplaces", 1, (ipkg_cmd_fun_t)ipkg_whatreplaces_cmd},
  1137. + {"whatconflicts", 1, (ipkg_cmd_fun_t)ipkg_whatconflicts_cmd},
  1138. +};
  1139. +
  1140. +int ipkg_state_changed;
  1141. +static void write_status_files_if_changed(ipkg_conf_t *conf)
  1142. +{
  1143. + if (ipkg_state_changed && !conf->noaction) {
  1144. + ipkg_message(conf, IPKG_INFO,
  1145. + " writing status file\n");
  1146. + ipkg_conf_write_status_files(conf);
  1147. + pkg_write_changed_filelists(conf);
  1148. + } else {
  1149. + ipkg_message(conf, IPKG_NOTICE, "Nothing to be done\n");
  1150. + }
  1151. +}
  1152. +
  1153. +
  1154. +static int num_cmds = sizeof(cmds) / sizeof(ipkg_cmd_t);
  1155. +
  1156. +ipkg_cmd_t *ipkg_cmd_find(const char *name)
  1157. +{
  1158. + int i;
  1159. + ipkg_cmd_t *cmd;
  1160. +
  1161. + for (i=0; i < num_cmds; i++) {
  1162. + cmd = &cmds[i];
  1163. + if (strcmp(name, cmd->name) == 0) {
  1164. + return cmd;
  1165. + }
  1166. + }
  1167. +
  1168. + return NULL;
  1169. +}
  1170. +
  1171. +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc, const char **argv, void *userdata)
  1172. +{
  1173. + int result;
  1174. + p_userdata = userdata;
  1175. +
  1176. +
  1177. + result = (cmd->fun)(conf, argc, argv);
  1178. + if ( result == 0 ) {
  1179. + ipkg_message(conf, IPKG_NOTICE, "Done.\n");
  1180. + } else {
  1181. + ipkg_message(conf, IPKG_NOTICE, "An error ocurred, return value: %d.\n", result);
  1182. +
  1183. + }
  1184. + if ( error_list ) {
  1185. + reverse_error_list(&error_list);
  1186. +
  1187. + ipkg_message(conf, IPKG_NOTICE, "Collected errors:\n");
  1188. + /* Here we print the errors collected and free the list */
  1189. + while (error_list != NULL) {
  1190. + ipkg_message(conf, IPKG_NOTICE, "%s",error_list->errmsg);
  1191. + error_list = error_list->next;
  1192. +
  1193. + }
  1194. + free_error_list(&error_list);
  1195. +
  1196. + }
  1197. +
  1198. + p_userdata = NULL;
  1199. + return result;
  1200. +}
  1201. +
  1202. +static int ipkg_update_cmd(ipkg_conf_t *conf)
  1203. +{
  1204. + int err;
  1205. + int failures;
  1206. + char *lists_dir;
  1207. + pkg_src_list_elt_t *iter;
  1208. + pkg_src_t *src;
  1209. +
  1210. +
  1211. + sprintf_alloc(&lists_dir, "%s", conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir);
  1212. +
  1213. + if (! file_is_dir(lists_dir)) {
  1214. + if (file_exists(lists_dir)) {
  1215. + ipkg_message(conf, IPKG_ERROR,
  1216. + "%s: ERROR: %s exists, but is not a directory\n",
  1217. + __FUNCTION__, lists_dir);
  1218. + free(lists_dir);
  1219. + return EINVAL;
  1220. + }
  1221. + err = file_mkdir_hier(lists_dir, 0755);
  1222. + if (err) {
  1223. + ipkg_message(conf, IPKG_ERROR,
  1224. + "%s: ERROR: failed to make directory %s: %s\n",
  1225. + __FUNCTION__, lists_dir, strerror(errno));
  1226. + free(lists_dir);
  1227. + return EINVAL;
  1228. + }
  1229. + }
  1230. +
  1231. + failures = 0;
  1232. + for (iter = conf->pkg_src_list.head; iter; iter = iter->next) {
  1233. + char *url, *list_file_name;
  1234. +
  1235. + src = iter->data;
  1236. +
  1237. + if (src->extra_data) /* debian style? */
  1238. + sprintf_alloc(&url, "%s/%s/%s", src->value, src->extra_data,
  1239. + src->gzip ? "Packages.gz" : "Packages");
  1240. + else
  1241. + sprintf_alloc(&url, "%s/%s", src->value, src->gzip ? "Packages.gz" : "Packages");
  1242. +
  1243. + sprintf_alloc(&list_file_name, "%s/%s", lists_dir, src->name);
  1244. + if (src->gzip) {
  1245. + char *tmp;
  1246. + char *tmp_file_name;
  1247. + FILE *in, *out;
  1248. +
  1249. + tmp = strdup ("/tmp/ipkg.XXXXXX");
  1250. +
  1251. + if (mkdtemp (tmp) == NULL) {
  1252. + perror ("mkdtemp");
  1253. + failures++;
  1254. + continue;
  1255. + }
  1256. +
  1257. + sprintf_alloc (&tmp_file_name, "%s/%s.gz", tmp, src->name);
  1258. + err = ipkg_download(conf, url, tmp_file_name);
  1259. + if (err == 0) {
  1260. + ipkg_message (conf, IPKG_NOTICE, "Inflating %s\n", url);
  1261. + in = fopen (tmp_file_name, "r");
  1262. + out = fopen (list_file_name, "w");
  1263. + if (in && out) {
  1264. + transformer_aux_data_t aux;
  1265. + init_transformer_aux_data(&aux);
  1266. + inflate_unzip (&aux, fileno(in), fileno(out));
  1267. + } else
  1268. + err = 1;
  1269. + if (in)
  1270. + fclose (in);
  1271. + if (out)
  1272. + fclose (out);
  1273. + unlink (tmp_file_name);
  1274. + rmdir (tmp);
  1275. + free (tmp);
  1276. + }
  1277. + } else
  1278. + err = ipkg_download(conf, url, list_file_name);
  1279. + if (err) {
  1280. + failures++;
  1281. + } else {
  1282. + ipkg_message(conf, IPKG_NOTICE,
  1283. + "Updated list of available packages in %s\n",
  1284. + list_file_name);
  1285. + }
  1286. + free(url);
  1287. + free(list_file_name);
  1288. + }
  1289. + free(lists_dir);
  1290. +
  1291. +#ifdef CONFIG_CLEAR_SW_INSTALL_FLAG
  1292. +#warning here
  1293. + /* clear SW_INSTALL on any package where state is SS_NOT_INSTALLED.
  1294. + * this is a hack to work around poor bookkeeping in old ipkg upgrade code
  1295. + * -Jamey 3/1/03
  1296. + */
  1297. + {
  1298. + int i;
  1299. + int changed = 0;
  1300. + pkg_vec_t *available = pkg_vec_alloc();
  1301. + pkg_hash_fetch_available(&conf->pkg_hash, available);
  1302. + ipkg_message(conf, IPKG_DEBUG, "Clearing SW_INSTALL for SS_NOT_INSTALLED packages.\n");
  1303. + for (i = 0; i < available->len; i++) {
  1304. + pkg_t *pkg = available->pkgs[i];
  1305. + if (pkg->state_want == SW_INSTALL && pkg->state_status == SS_NOT_INSTALLED) {
  1306. + ipkg_message(conf, IPKG_DEBUG, "Clearing SW_INSTALL on package %s.\n", pkg->name);
  1307. + pkg->state_want = SW_UNKNOWN;
  1308. + changed = 1;
  1309. + }
  1310. + }
  1311. + pkg_vec_free(available);
  1312. + if (changed) {
  1313. + write_status_files_if_changed(conf);
  1314. + }
  1315. + }
  1316. +#endif
  1317. +
  1318. + return failures;
  1319. +}
  1320. +
  1321. +
  1322. +/* scan the args passed and cache the local filenames of the packages */
  1323. +int ipkg_multiple_files_scan(ipkg_conf_t *conf, int argc, char **argv)
  1324. +{
  1325. + int i;
  1326. + int err;
  1327. +
  1328. + /*
  1329. + * First scan through package names/urls
  1330. + * For any urls, download the packages and install in database.
  1331. + * For any files, install package info in database.
  1332. + */
  1333. + for (i = 0; i < argc; i ++) {
  1334. + char *filename = argv [i];
  1335. + //char *tmp = basename (tmp);
  1336. + //int tmplen = strlen (tmp);
  1337. +
  1338. + //if (strcmp (tmp + (tmplen - strlen (IPKG_PKG_EXTENSION)), IPKG_PKG_EXTENSION) != 0)
  1339. + // continue;
  1340. + //if (strcmp (tmp + (tmplen - strlen (DPKG_PKG_EXTENSION)), DPKG_PKG_EXTENSION) != 0)
  1341. + // continue;
  1342. +
  1343. + ipkg_message(conf, IPKG_DEBUG2, "Debug mfs: %s \n",filename );
  1344. +
  1345. + err = ipkg_prepare_url_for_install(conf, filename, &argv[i]);
  1346. + if (err)
  1347. + return err;
  1348. + }
  1349. + return 0;
  1350. +}
  1351. +
  1352. +struct ipkg_intercept
  1353. +{
  1354. + char *oldpath;
  1355. + char *statedir;
  1356. +};
  1357. +
  1358. +typedef struct ipkg_intercept *ipkg_intercept_t;
  1359. +ipkg_intercept_t ipkg_prep_intercepts(void);
  1360. +
  1361. +ipkg_intercept_t ipkg_prep_intercepts(void)
  1362. +{
  1363. + ipkg_intercept_t ctx;
  1364. + char *newpath;
  1365. + int gen;
  1366. +
  1367. + ctx = malloc (sizeof (*ctx));
  1368. + ctx->oldpath = strdup (getenv ("PATH"));
  1369. +
  1370. + sprintf_alloc (&newpath, "%s/ipkg/intercept:%s", IPKGLIBDIR, ctx->oldpath);
  1371. + setenv ("PATH", newpath, 1);
  1372. + free (newpath);
  1373. +
  1374. + gen = 0;
  1375. + retry:
  1376. + sprintf_alloc (&ctx->statedir, "/tmp/ipkg-intercept-%d-%d", getpid (), gen);
  1377. + if (mkdir (ctx->statedir, 0770) < 0) {
  1378. + if (errno == EEXIST) {
  1379. + free (ctx->statedir);
  1380. + gen++;
  1381. + goto retry;
  1382. + }
  1383. + perror (ctx->statedir);
  1384. + return NULL;
  1385. + }
  1386. + setenv ("IPKG_INTERCEPT_DIR", ctx->statedir, 1);
  1387. + return ctx;
  1388. +}
  1389. +
  1390. +int ipkg_finalize_intercepts(ipkg_intercept_t ctx);
  1391. +
  1392. +int ipkg_finalize_intercepts(ipkg_intercept_t ctx)
  1393. +{
  1394. + char *cmd;
  1395. + DIR *dir;
  1396. + int err = 0;
  1397. +
  1398. + setenv ("PATH", ctx->oldpath, 1);
  1399. + free (ctx->oldpath);
  1400. +
  1401. + dir = opendir (ctx->statedir);
  1402. + if (dir) {
  1403. + struct dirent *de;
  1404. + while (de = readdir (dir), de != NULL) {
  1405. + char *path;
  1406. +
  1407. + if (de->d_name[0] == '.')
  1408. + continue;
  1409. +
  1410. + sprintf_alloc (&path, "%s/%s", ctx->statedir, de->d_name);
  1411. + if (access (path, X_OK) == 0) {
  1412. + if (system (path)) {
  1413. + err = errno;
  1414. + perror (de->d_name);
  1415. + }
  1416. + }
  1417. + free (path);
  1418. + }
  1419. + } else
  1420. + perror (ctx->statedir);
  1421. +
  1422. + sprintf_alloc (&cmd, "rm -rf %s", ctx->statedir);
  1423. + system (cmd);
  1424. + free (cmd);
  1425. +
  1426. + free (ctx->statedir);
  1427. + free (ctx);
  1428. +
  1429. + return err;
  1430. +}
  1431. +
  1432. +int ipkg_configure_packages(ipkg_conf_t *conf, char *pkg_name)
  1433. +{
  1434. + pkg_vec_t *all;
  1435. + int i;
  1436. + pkg_t *pkg;
  1437. + ipkg_intercept_t ic;
  1438. + int r, err = 0;
  1439. +
  1440. + ipkg_message(conf, IPKG_INFO,
  1441. + "Configuring unpacked packages\n");
  1442. + fflush( stdout );
  1443. +
  1444. + all = pkg_vec_alloc();
  1445. + pkg_hash_fetch_available(&conf->pkg_hash, all);
  1446. +
  1447. + ic = ipkg_prep_intercepts();
  1448. +
  1449. + for(i = 0; i < all->len; i++) {
  1450. + pkg = all->pkgs[i];
  1451. +
  1452. + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
  1453. + continue;
  1454. +
  1455. + if (pkg->state_status == SS_UNPACKED) {
  1456. + ipkg_message(conf, IPKG_NOTICE,
  1457. + "Configuring %s\n", pkg->name);
  1458. + fflush( stdout );
  1459. + r = ipkg_configure(conf, pkg);
  1460. + if (r == 0) {
  1461. + pkg->state_status = SS_INSTALLED;
  1462. + pkg->parent->state_status = SS_INSTALLED;
  1463. + pkg->state_flag &= ~SF_PREFER;
  1464. + } else {
  1465. + if (!err)
  1466. + err = r;
  1467. + }
  1468. + }
  1469. + }
  1470. +
  1471. + r = ipkg_finalize_intercepts (ic);
  1472. + if (r && !err)
  1473. + err = r;
  1474. +
  1475. + pkg_vec_free(all);
  1476. + return err;
  1477. +}
  1478. +
  1479. +static void sigint_handler(int sig)
  1480. +{
  1481. + signal(sig, SIG_DFL);
  1482. + ipkg_message(NULL, IPKG_NOTICE,
  1483. + "ipkg: interrupted. writing out status database\n");
  1484. + write_status_files_if_changed(global_conf);
  1485. + exit(128 + sig);
  1486. +}
  1487. +
  1488. +static int ipkg_install_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1489. +{
  1490. + int i;
  1491. + char *arg;
  1492. + int err=0;
  1493. +
  1494. + global_conf = conf;
  1495. + signal(SIGINT, sigint_handler);
  1496. +
  1497. + /*
  1498. + * Now scan through package names and install
  1499. + */
  1500. + for (i=0; i < argc; i++) {
  1501. + arg = argv[i];
  1502. +
  1503. + ipkg_message(conf, IPKG_DEBUG2, "Debug install_cmd: %s \n",arg );
  1504. + err = ipkg_prepare_url_for_install(conf, arg, &argv[i]);
  1505. + if (err != EINVAL && err != 0)
  1506. + return err;
  1507. + }
  1508. + pkg_info_preinstall_check(conf);
  1509. +
  1510. + for (i=0; i < argc; i++) {
  1511. + arg = argv[i];
  1512. + if (conf->multiple_providers)
  1513. + err = ipkg_install_multi_by_name(conf, arg);
  1514. + else{
  1515. + err = ipkg_install_by_name(conf, arg);
  1516. + }
  1517. + if (err == IPKG_PKG_HAS_NO_CANDIDATE) {
  1518. + ipkg_message(conf, IPKG_ERROR,
  1519. + "Cannot find package %s.\n"
  1520. + "Check the spelling or perhaps run 'ipkg update'\n",
  1521. + arg);
  1522. + }
  1523. + }
  1524. +
  1525. + /* recheck to verify that all dependences are satisfied */
  1526. + if (0) ipkg_satisfy_all_dependences(conf);
  1527. +
  1528. + ipkg_configure_packages(conf, NULL);
  1529. +
  1530. + write_status_files_if_changed(conf);
  1531. +
  1532. + return err;
  1533. +}
  1534. +
  1535. +static int ipkg_upgrade_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1536. +{
  1537. + int i;
  1538. + pkg_t *pkg;
  1539. + int err;
  1540. +
  1541. + global_conf = conf;
  1542. + signal(SIGINT, sigint_handler);
  1543. +
  1544. + if (argc) {
  1545. + for (i=0; i < argc; i++) {
  1546. + char *arg = argv[i];
  1547. +
  1548. + err = ipkg_prepare_url_for_install(conf, arg, &arg);
  1549. + if (err != EINVAL && err != 0)
  1550. + return err;
  1551. + }
  1552. + pkg_info_preinstall_check(conf);
  1553. +
  1554. + for (i=0; i < argc; i++) {
  1555. + char *arg = argv[i];
  1556. + if (conf->restrict_to_default_dest) {
  1557. + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
  1558. + argv[i],
  1559. + conf->default_dest);
  1560. + if (pkg == NULL) {
  1561. + ipkg_message(conf, IPKG_NOTICE,
  1562. + "Package %s not installed in %s\n",
  1563. + argv[i], conf->default_dest->name);
  1564. + continue;
  1565. + }
  1566. + } else {
  1567. + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash,
  1568. + argv[i]);
  1569. + }
  1570. + if (pkg)
  1571. + ipkg_upgrade_pkg(conf, pkg);
  1572. + else {
  1573. + ipkg_install_by_name(conf, arg);
  1574. + }
  1575. + }
  1576. + } else {
  1577. + pkg_vec_t *installed = pkg_vec_alloc();
  1578. +
  1579. + pkg_info_preinstall_check(conf);
  1580. +
  1581. + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
  1582. + for (i = 0; i < installed->len; i++) {
  1583. + pkg = installed->pkgs[i];
  1584. + ipkg_upgrade_pkg(conf, pkg);
  1585. + }
  1586. + pkg_vec_free(installed);
  1587. + }
  1588. +
  1589. + /* recheck to verify that all dependences are satisfied */
  1590. + if (0) ipkg_satisfy_all_dependences(conf);
  1591. +
  1592. + ipkg_configure_packages(conf, NULL);
  1593. +
  1594. + write_status_files_if_changed(conf);
  1595. +
  1596. + return 0;
  1597. +}
  1598. +
  1599. +static int ipkg_download_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1600. +{
  1601. + int i, err;
  1602. + char *arg;
  1603. + pkg_t *pkg;
  1604. +
  1605. + pkg_info_preinstall_check(conf);
  1606. + for (i = 0; i < argc; i++) {
  1607. + arg = argv[i];
  1608. +
  1609. + pkg = pkg_hash_fetch_best_installation_candidate_by_name(conf, arg);
  1610. + if (pkg == NULL) {
  1611. + ipkg_message(conf, IPKG_ERROR,
  1612. + "Cannot find package %s.\n"
  1613. + "Check the spelling or perhaps run 'ipkg update'\n",
  1614. + arg);
  1615. + continue;
  1616. + }
  1617. +
  1618. + err = ipkg_download_pkg(conf, pkg, ".");
  1619. +
  1620. + if (err) {
  1621. + ipkg_message(conf, IPKG_ERROR,
  1622. + "Failed to download %s\n", pkg->name);
  1623. + } else {
  1624. + ipkg_message(conf, IPKG_NOTICE,
  1625. + "Downloaded %s as %s\n",
  1626. + pkg->name, pkg->local_filename);
  1627. + }
  1628. + }
  1629. +
  1630. + return 0;
  1631. +}
  1632. +
  1633. +
  1634. +static int ipkg_list_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1635. +{
  1636. + int i ;
  1637. + pkg_vec_t *available;
  1638. + pkg_t *pkg;
  1639. + char desc_short[IPKG_LIST_DESCRIPTION_LENGTH];
  1640. + char *newline;
  1641. + char *pkg_name = NULL;
  1642. + char *version_str;
  1643. +
  1644. + if (argc > 0) {
  1645. + pkg_name = argv[0];
  1646. + }
  1647. + available = pkg_vec_alloc();
  1648. + pkg_hash_fetch_available(&conf->pkg_hash, available);
  1649. + for (i=0; i < available->len; i++) {
  1650. + pkg = available->pkgs[i];
  1651. + /* if we have package name or pattern and pkg does not match, then skip it */
  1652. + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
  1653. + continue;
  1654. + if (pkg->description) {
  1655. + strncpy(desc_short, pkg->description, IPKG_LIST_DESCRIPTION_LENGTH);
  1656. + } else {
  1657. + desc_short[0] = '\0';
  1658. + }
  1659. + desc_short[IPKG_LIST_DESCRIPTION_LENGTH - 1] = '\0';
  1660. + newline = strchr(desc_short, '\n');
  1661. + if (newline) {
  1662. + *newline = '\0';
  1663. + }
  1664. + if (ipkg_cb_list) {
  1665. + version_str = pkg_version_str_alloc(pkg);
  1666. + ipkg_cb_list(pkg->name,desc_short,
  1667. + version_str,
  1668. + pkg->state_status,
  1669. + p_userdata);
  1670. + free(version_str);
  1671. + }
  1672. + }
  1673. + pkg_vec_free(available);
  1674. +
  1675. + return 0;
  1676. +}
  1677. +
  1678. +
  1679. +static int ipkg_list_installed_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1680. +{
  1681. + int i ;
  1682. + pkg_vec_t *available;
  1683. + pkg_t *pkg;
  1684. + char desc_short[IPKG_LIST_DESCRIPTION_LENGTH];
  1685. + char *newline;
  1686. + char *pkg_name = NULL;
  1687. + char *version_str;
  1688. +
  1689. + if (argc > 0) {
  1690. + pkg_name = argv[0];
  1691. + }
  1692. + available = pkg_vec_alloc();
  1693. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
  1694. + for (i=0; i < available->len; i++) {
  1695. + pkg = available->pkgs[i];
  1696. + /* if we have package name or pattern and pkg does not match, then skip it */
  1697. + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
  1698. + continue;
  1699. + if (pkg->description) {
  1700. + strncpy(desc_short, pkg->description, IPKG_LIST_DESCRIPTION_LENGTH);
  1701. + } else {
  1702. + desc_short[0] = '\0';
  1703. + }
  1704. + desc_short[IPKG_LIST_DESCRIPTION_LENGTH - 1] = '\0';
  1705. + newline = strchr(desc_short, '\n');
  1706. + if (newline) {
  1707. + *newline = '\0';
  1708. + }
  1709. + if (ipkg_cb_list) {
  1710. + version_str = pkg_version_str_alloc(pkg);
  1711. + ipkg_cb_list(pkg->name,desc_short,
  1712. + version_str,
  1713. + pkg->state_status,
  1714. + p_userdata);
  1715. + free(version_str);
  1716. + }
  1717. + }
  1718. +
  1719. + return 0;
  1720. +}
  1721. +
  1722. +static int ipkg_info_status_cmd(ipkg_conf_t *conf, int argc, char **argv, int installed_only)
  1723. +{
  1724. + int i;
  1725. + pkg_vec_t *available;
  1726. + pkg_t *pkg;
  1727. + char *pkg_name = NULL;
  1728. + char **pkg_fields = NULL;
  1729. + int n_fields = 0;
  1730. + char *buff ; // = (char *)malloc(1);
  1731. +
  1732. + if (argc > 0) {
  1733. + pkg_name = argv[0];
  1734. + }
  1735. + if (argc > 1) {
  1736. + pkg_fields = &argv[1];
  1737. + n_fields = argc - 1;
  1738. + }
  1739. +
  1740. + available = pkg_vec_alloc();
  1741. + if (installed_only)
  1742. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
  1743. + else
  1744. + pkg_hash_fetch_available(&conf->pkg_hash, available);
  1745. + for (i=0; i < available->len; i++) {
  1746. + pkg = available->pkgs[i];
  1747. + if (pkg_name && fnmatch(pkg_name, pkg->name, 0)) {
  1748. + continue;
  1749. + }
  1750. + buff = pkg_formatted_info(pkg);
  1751. + if ( buff ) {
  1752. + if (ipkg_cb_status) ipkg_cb_status(pkg->name,
  1753. + pkg->state_status,
  1754. + buff,
  1755. + p_userdata);
  1756. + free(buff);
  1757. + }
  1758. + if (conf->verbosity > 1) {
  1759. + conffile_list_elt_t *iter;
  1760. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  1761. + conffile_t *cf = iter->data;
  1762. + int modified = conffile_has_been_modified(conf, cf);
  1763. + ipkg_message(conf, IPKG_NOTICE, "conffile=%s md5sum=%s modified=%d\n",
  1764. + cf->name, cf->value, modified);
  1765. + }
  1766. + }
  1767. + }
  1768. + pkg_vec_free(available);
  1769. +
  1770. + return 0;
  1771. +}
  1772. +
  1773. +static int ipkg_info_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1774. +{
  1775. + return ipkg_info_status_cmd(conf, argc, argv, 0);
  1776. +}
  1777. +
  1778. +static int ipkg_status_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1779. +{
  1780. + return ipkg_info_status_cmd(conf, argc, argv, 1);
  1781. +}
  1782. +
  1783. +static int ipkg_configure_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1784. +{
  1785. +
  1786. + int err;
  1787. + if (argc > 0) {
  1788. + char *pkg_name = NULL;
  1789. +
  1790. + pkg_name = argv[0];
  1791. +
  1792. + err = ipkg_configure_packages (conf, pkg_name);
  1793. +
  1794. + } else {
  1795. + err = ipkg_configure_packages (conf, NULL);
  1796. + }
  1797. +
  1798. + write_status_files_if_changed(conf);
  1799. +
  1800. + return err;
  1801. +}
  1802. +
  1803. +static int ipkg_install_pending_cmd(ipkg_conf_t *conf)
  1804. +{
  1805. + int i, err;
  1806. + char *globpattern;
  1807. + glob_t globbuf;
  1808. +
  1809. + sprintf_alloc(&globpattern, "%s/*" IPKG_PKG_EXTENSION, conf->pending_dir);
  1810. + err = glob(globpattern, 0, NULL, &globbuf);
  1811. + free(globpattern);
  1812. + if (err) {
  1813. + return 0;
  1814. + }
  1815. +
  1816. + ipkg_message(conf, IPKG_NOTICE,
  1817. + "The following packages in %s will now be installed.\n",
  1818. + conf->pending_dir);
  1819. + for (i = 0; i < globbuf.gl_pathc; i++) {
  1820. + ipkg_message(conf, IPKG_NOTICE,
  1821. + "%s%s", i == 0 ? "" : " ", globbuf.gl_pathv[i]);
  1822. + }
  1823. + ipkg_message(conf, IPKG_NOTICE, "\n");
  1824. + for (i = 0; i < globbuf.gl_pathc; i++) {
  1825. + err = ipkg_install_from_file(conf, globbuf.gl_pathv[i]);
  1826. + if (err == 0) {
  1827. + err = unlink(globbuf.gl_pathv[i]);
  1828. + if (err) {
  1829. + ipkg_message(conf, IPKG_ERROR,
  1830. + "%s: ERROR: failed to unlink %s: %s\n",
  1831. + __FUNCTION__, globbuf.gl_pathv[i], strerror(err));
  1832. + return err;
  1833. + }
  1834. + }
  1835. + }
  1836. + globfree(&globbuf);
  1837. +
  1838. + return err;
  1839. +}
  1840. +
  1841. +static int ipkg_remove_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1842. +{
  1843. + int i,a,done;
  1844. + pkg_t *pkg;
  1845. + pkg_t *pkg_to_remove;
  1846. + pkg_vec_t *available;
  1847. + char *pkg_name = NULL;
  1848. + global_conf = conf;
  1849. + signal(SIGINT, sigint_handler);
  1850. +
  1851. +// ENH: Add the "no pkg removed" just in case.
  1852. +
  1853. + done = 0;
  1854. +
  1855. + available = pkg_vec_alloc();
  1856. + pkg_info_preinstall_check(conf);
  1857. + if ( argc > 0 ) {
  1858. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
  1859. + for (i=0; i < argc; i++) {
  1860. + pkg_name = malloc(strlen(argv[i])+2);
  1861. + strcpy(pkg_name,argv[i]);
  1862. + for (a=0; a < available->len; a++) {
  1863. + pkg = available->pkgs[a];
  1864. + if (pkg_name && fnmatch(pkg_name, pkg->name, 0)) {
  1865. + continue;
  1866. + }
  1867. + if (conf->restrict_to_default_dest) {
  1868. + pkg_to_remove = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
  1869. + pkg->name,
  1870. + conf->default_dest);
  1871. + } else {
  1872. + pkg_to_remove = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name );
  1873. + }
  1874. +
  1875. + if (pkg == NULL) {
  1876. + ipkg_message(conf, IPKG_ERROR, "Package %s is not installed.\n", pkg->name);
  1877. + continue;
  1878. + }
  1879. + if (pkg->state_status == SS_NOT_INSTALLED) { // Added the control, so every already removed package could be skipped
  1880. + ipkg_message(conf, IPKG_ERROR, "Package seems to be %s not installed (STATUS = NOT_INSTALLED).\n", pkg->name);
  1881. + continue;
  1882. + }
  1883. + ipkg_remove_pkg(conf, pkg_to_remove,0);
  1884. + done = 1;
  1885. + }
  1886. + free (pkg_name);
  1887. + }
  1888. + pkg_vec_free(available);
  1889. + } else {
  1890. + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
  1891. + int flagged_pkg_count = 0;
  1892. + int removed;
  1893. +
  1894. + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed_pkgs);
  1895. +
  1896. + for (i = 0; i < installed_pkgs->len; i++) {
  1897. + pkg = installed_pkgs->pkgs[i];
  1898. + if (pkg->state_flag & SF_USER) {
  1899. + flagged_pkg_count++;
  1900. + } else {
  1901. + if (!pkg_has_installed_dependents(pkg, NULL))
  1902. + ipkg_message(conf, IPKG_NOTICE, "Non-user leaf package: %s\n", pkg->name);
  1903. + }
  1904. + }
  1905. + if (!flagged_pkg_count) {
  1906. + ipkg_message(conf, IPKG_NOTICE, "No packages flagged as installed by user, \n"
  1907. + "so refusing to uninstall unflagged non-leaf packages\n");
  1908. + return 0;
  1909. + }
  1910. +
  1911. + /* find packages not flagged SF_USER (i.e., installed to
  1912. + * satisfy a dependence) and not having any dependents, and
  1913. + * remove them */
  1914. + do {
  1915. + removed = 0;
  1916. + for (i = 0; i < installed_pkgs->len; i++) {
  1917. + pkg = installed_pkgs->pkgs[i];
  1918. + if (!(pkg->state_flag & SF_USER)
  1919. + && !pkg_has_installed_dependents(pkg, NULL)) {
  1920. + removed++;
  1921. + ipkg_message(conf, IPKG_NOTICE, "Removing non-user leaf package %s\n");
  1922. + ipkg_remove_pkg(conf, pkg,0);
  1923. + done = 1;
  1924. + }
  1925. + }
  1926. + } while (removed);
  1927. + pkg_vec_free(installed_pkgs);
  1928. + }
  1929. +
  1930. + if ( done == 0 )
  1931. + ipkg_message(conf, IPKG_NOTICE, "No packages removed.\n");
  1932. +
  1933. + write_status_files_if_changed(conf);
  1934. + return 0;
  1935. +}
  1936. +
  1937. +static int ipkg_purge_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1938. +{
  1939. + int i;
  1940. + pkg_t *pkg;
  1941. +
  1942. + global_conf = conf;
  1943. + signal(SIGINT, sigint_handler);
  1944. +
  1945. + pkg_info_preinstall_check(conf);
  1946. +
  1947. + for (i=0; i < argc; i++) {
  1948. + if (conf->restrict_to_default_dest) {
  1949. + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
  1950. + argv[i],
  1951. + conf->default_dest);
  1952. + } else {
  1953. + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, argv[i]);
  1954. + }
  1955. +
  1956. + if (pkg == NULL) {
  1957. + ipkg_message(conf, IPKG_ERROR,
  1958. + "Package %s is not installed.\n", argv[i]);
  1959. + continue;
  1960. + }
  1961. + ipkg_purge_pkg(conf, pkg);
  1962. + }
  1963. +
  1964. + write_status_files_if_changed(conf);
  1965. + return 0;
  1966. +}
  1967. +
  1968. +static int ipkg_flag_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1969. +{
  1970. + int i;
  1971. + pkg_t *pkg;
  1972. + char *flags = argv[0];
  1973. +
  1974. + global_conf = conf;
  1975. + signal(SIGINT, sigint_handler);
  1976. +
  1977. + for (i=1; i < argc; i++) {
  1978. + if (conf->restrict_to_default_dest) {
  1979. + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
  1980. + argv[i],
  1981. + conf->default_dest);
  1982. + } else {
  1983. + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, argv[i]);
  1984. + }
  1985. +
  1986. + if (pkg == NULL) {
  1987. + ipkg_message(conf, IPKG_ERROR,
  1988. + "Package %s is not installed.\n", argv[i]);
  1989. + continue;
  1990. + }
  1991. + if (( strcmp(flags,"hold")==0)||( strcmp(flags,"noprune")==0)||
  1992. + ( strcmp(flags,"user")==0)||( strcmp(flags,"ok")==0)) {
  1993. + pkg->state_flag = pkg_state_flag_from_str(flags);
  1994. + }
  1995. +/* pb_ asked this feature 03292004 */
  1996. +/* Actually I will use only this two, but this is an open for various status */
  1997. + if (( strcmp(flags,"installed")==0)||( strcmp(flags,"unpacked")==0)){
  1998. + pkg->state_status = pkg_state_status_from_str(flags);
  1999. + }
  2000. + ipkg_state_changed++;
  2001. + ipkg_message(conf, IPKG_NOTICE,
  2002. + "Setting flags for package %s to %s\n",
  2003. + pkg->name, flags);
  2004. + }
  2005. +
  2006. + write_status_files_if_changed(conf);
  2007. + return 0;
  2008. +}
  2009. +
  2010. +static int ipkg_files_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2011. +{
  2012. + pkg_t *pkg;
  2013. + str_list_t *installed_files;
  2014. + str_list_elt_t *iter;
  2015. + char *pkg_version;
  2016. + size_t buff_len = 8192;
  2017. + size_t used_len;
  2018. + char *buff ;
  2019. +
  2020. + buff = (char *)malloc(buff_len);
  2021. + if ( buff == NULL ) {
  2022. + fprintf( stderr,"%s: Unable to allocate memory \n",__FUNCTION__);
  2023. + return ENOMEM;
  2024. + }
  2025. +
  2026. + if (argc < 1) {
  2027. + return EINVAL;
  2028. + }
  2029. +
  2030. + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash,
  2031. + argv[0]);
  2032. + if (pkg == NULL) {
  2033. + ipkg_message(conf, IPKG_ERROR,
  2034. + "Package %s not installed.\n", argv[0]);
  2035. + return 0;
  2036. + }
  2037. +
  2038. + installed_files = pkg_get_installed_files(pkg);
  2039. + pkg_version = pkg_version_str_alloc(pkg);
  2040. +
  2041. + printf("Package %s (%s) is installed on %s and has the following files:\n",
  2042. + pkg->name, pkg_version, pkg->dest->name);
  2043. + for (iter = installed_files->head; iter; iter = iter->next) {
  2044. + puts(iter->data);
  2045. + }
  2046. +
  2047. + free(pkg_version);
  2048. + pkg_free_installed_files(pkg);
  2049. +
  2050. + return 0;
  2051. +}
  2052. +
  2053. +static int ipkg_depends_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2054. +{
  2055. +
  2056. + if (argc > 0) {
  2057. + pkg_vec_t *available_pkgs = pkg_vec_alloc();
  2058. + const char *rel_str = "depends on";
  2059. + int i;
  2060. +
  2061. + pkg_info_preinstall_check(conf);
  2062. +
  2063. + if (conf->query_all)
  2064. + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
  2065. + else
  2066. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
  2067. + for (i = 0; i < argc; i++) {
  2068. + const char *target = argv[i];
  2069. + int j;
  2070. +
  2071. + ipkg_message(conf, IPKG_ERROR, "target=%s\n", target);
  2072. +
  2073. + for (j = 0; j < available_pkgs->len; j++) {
  2074. + pkg_t *pkg = available_pkgs->pkgs[j];
  2075. + if (fnmatch(target, pkg->name, 0) == 0) {
  2076. + int k;
  2077. + int count = pkg->depends_count + pkg->pre_depends_count;
  2078. + ipkg_message(conf, IPKG_ERROR, "What %s (arch=%s) %s\n",
  2079. + target, pkg->architecture, rel_str);
  2080. + for (k = 0; k < count; k++) {
  2081. + compound_depend_t *cdepend = &pkg->depends[k];
  2082. + int l;
  2083. + for (l = 0; l < cdepend->possibility_count; l++) {
  2084. + depend_t *possibility = cdepend->possibilities[l];
  2085. + ipkg_message(conf, IPKG_ERROR, " %s", possibility->pkg->name);
  2086. + if (conf->verbosity > 0) {
  2087. + // char *ver = abstract_pkg_version_str_alloc(possibility->pkg);
  2088. + ipkg_message(conf, IPKG_NOTICE, " %s", possibility->version);
  2089. + if (possibility->version) {
  2090. + const char *typestr = NULL;
  2091. + switch (possibility->constraint) {
  2092. + case NONE: typestr = "none"; break;
  2093. + case EARLIER: typestr = "<"; break;
  2094. + case EARLIER_EQUAL: typestr = "<="; break;
  2095. + case EQUAL: typestr = "="; break;
  2096. + case LATER_EQUAL: typestr = ">="; break;
  2097. + case LATER: typestr = ">"; break;
  2098. + }
  2099. + ipkg_message(conf, IPKG_NOTICE, " (%s %s)", typestr, possibility->version);
  2100. + }
  2101. + // free(ver);
  2102. + }
  2103. + ipkg_message(conf, IPKG_ERROR, "\n");
  2104. + }
  2105. + }
  2106. + }
  2107. + }
  2108. + }
  2109. + pkg_vec_free(available_pkgs);
  2110. + }
  2111. + return 0;
  2112. +}
  2113. +
  2114. +enum what_field_type {
  2115. + WHATDEPENDS,
  2116. + WHATCONFLICTS,
  2117. + WHATPROVIDES,
  2118. + WHATREPLACES,
  2119. + WHATRECOMMENDS,
  2120. + WHATSUGGESTS
  2121. +};
  2122. +
  2123. +static int ipkg_what_depends_conflicts_cmd(ipkg_conf_t *conf, enum what_field_type what_field_type, int recursive, int argc, char **argv)
  2124. +{
  2125. +
  2126. + if (argc > 0) {
  2127. + pkg_vec_t *available_pkgs = pkg_vec_alloc();
  2128. + const char *rel_str = NULL;
  2129. + int i;
  2130. + int changed;
  2131. +
  2132. + switch (what_field_type) {
  2133. + case WHATDEPENDS: rel_str = "depends on"; break;
  2134. + case WHATCONFLICTS: rel_str = "conflicts with"; break;
  2135. + case WHATSUGGESTS: rel_str = "suggests"; break;
  2136. + case WHATRECOMMENDS: rel_str = "recommends"; break;
  2137. + case WHATPROVIDES: rel_str = "provides"; break;
  2138. + case WHATREPLACES: rel_str = "replaces"; break;
  2139. + }
  2140. +
  2141. + if (conf->query_all)
  2142. + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
  2143. + else
  2144. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
  2145. +
  2146. + /* mark the root set */
  2147. + pkg_vec_clear_marks(available_pkgs);
  2148. + ipkg_message(conf, IPKG_NOTICE, "Root set:\n");
  2149. + for (i = 0; i < argc; i++) {
  2150. + const char *dependee_pattern = argv[i];
  2151. + pkg_vec_mark_if_matches(available_pkgs, dependee_pattern);
  2152. + }
  2153. + for (i = 0; i < available_pkgs->len; i++) {
  2154. + pkg_t *pkg = available_pkgs->pkgs[i];
  2155. + if (pkg->state_flag & SF_MARKED) {
  2156. + /* mark the parent (abstract) package */
  2157. + pkg_mark_provides(pkg);
  2158. + ipkg_message(conf, IPKG_NOTICE, " %s\n", pkg->name);
  2159. + }
  2160. + }
  2161. +
  2162. + ipkg_message(conf, IPKG_NOTICE, "What %s root set\n", rel_str);
  2163. + do {
  2164. + int j;
  2165. + changed = 0;
  2166. +
  2167. + for (j = 0; j < available_pkgs->len; j++) {
  2168. + pkg_t *pkg = available_pkgs->pkgs[j];
  2169. + int k;
  2170. + int count = ((what_field_type == WHATCONFLICTS)
  2171. + ? pkg->conflicts_count
  2172. + : pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count);
  2173. + /* skip this package if it is already marked */
  2174. + if (pkg->parent->state_flag & SF_MARKED) {
  2175. + continue;
  2176. + }
  2177. + for (k = 0; k < count; k++) {
  2178. + compound_depend_t *cdepend =
  2179. + (what_field_type == WHATCONFLICTS) ? &pkg->conflicts[k] : &pkg->depends[k];
  2180. + int l;
  2181. + for (l = 0; l < cdepend->possibility_count; l++) {
  2182. + depend_t *possibility = cdepend->possibilities[l];
  2183. + if (possibility->pkg->state_flag & SF_MARKED) {
  2184. + /* mark the depending package so we won't visit it again */
  2185. + pkg->state_flag |= SF_MARKED;
  2186. + pkg_mark_provides(pkg);
  2187. + changed++;
  2188. +
  2189. + ipkg_message(conf, IPKG_NOTICE, " %s", pkg->name);
  2190. + if (conf->verbosity > 0) {
  2191. + char *ver = pkg_version_str_alloc(pkg);
  2192. + ipkg_message(conf, IPKG_NOTICE, " %s", ver);
  2193. + ipkg_message(conf, IPKG_NOTICE, "\t%s %s", rel_str, possibility->pkg->name);
  2194. + if (possibility->version) {
  2195. + const char *typestr = NULL;
  2196. + switch (possibility->constraint) {
  2197. + case NONE: typestr = "none"; break;
  2198. + case EARLIER: typestr = "<"; break;
  2199. + case EARLIER_EQUAL: typestr = "<="; break;
  2200. + case EQUAL: typestr = "="; break;
  2201. + case LATER_EQUAL: typestr = ">="; break;
  2202. + case LATER: typestr = ">"; break;
  2203. + }
  2204. + ipkg_message(conf, IPKG_NOTICE, " (%s %s)", typestr, possibility->version);
  2205. + }
  2206. + free(ver);
  2207. + if (!pkg_dependence_satisfiable(possibility))
  2208. + ipkg_message(conf, IPKG_NOTICE, " unsatisfiable");
  2209. + }
  2210. + ipkg_message(conf, IPKG_NOTICE, "\n");
  2211. + goto next_package;
  2212. + }
  2213. + }
  2214. + }
  2215. + next_package:
  2216. + ;
  2217. + }
  2218. + } while (changed && recursive);
  2219. + pkg_vec_free(available_pkgs);
  2220. + }
  2221. +
  2222. + return 0;
  2223. +}
  2224. +
  2225. +int pkg_mark_provides(pkg_t *pkg)
  2226. +{
  2227. + int provides_count = pkg->provides_count;
  2228. + abstract_pkg_t **provides = pkg->provides;
  2229. + int i;
  2230. + pkg->parent->state_flag |= SF_MARKED;
  2231. + for (i = 0; i < provides_count; i++) {
  2232. + provides[i]->state_flag |= SF_MARKED;
  2233. + }
  2234. + return 0;
  2235. +}
  2236. +
  2237. +static int ipkg_whatdepends_recursively_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2238. +{
  2239. + return ipkg_what_depends_conflicts_cmd(conf, WHATDEPENDS, 1, argc, argv);
  2240. +}
  2241. +static int ipkg_whatdepends_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2242. +{
  2243. + return ipkg_what_depends_conflicts_cmd(conf, WHATDEPENDS, 0, argc, argv);
  2244. +}
  2245. +
  2246. +static int ipkg_whatsuggests_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2247. +{
  2248. + return ipkg_what_depends_conflicts_cmd(conf, WHATSUGGESTS, 0, argc, argv);
  2249. +}
  2250. +
  2251. +static int ipkg_whatrecommends_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2252. +{
  2253. + return ipkg_what_depends_conflicts_cmd(conf, WHATRECOMMENDS, 0, argc, argv);
  2254. +}
  2255. +
  2256. +static int ipkg_whatconflicts_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2257. +{
  2258. + return ipkg_what_depends_conflicts_cmd(conf, WHATCONFLICTS, 0, argc, argv);
  2259. +}
  2260. +
  2261. +static int ipkg_what_provides_replaces_cmd(ipkg_conf_t *conf, enum what_field_type what_field_type, int argc, char **argv)
  2262. +{
  2263. +
  2264. + if (argc > 0) {
  2265. + pkg_vec_t *available_pkgs = pkg_vec_alloc();
  2266. + const char *rel_str = (what_field_type == WHATPROVIDES ? "provides" : "replaces");
  2267. + int i;
  2268. +
  2269. + pkg_info_preinstall_check(conf);
  2270. +
  2271. + if (conf->query_all)
  2272. + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
  2273. + else
  2274. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
  2275. + for (i = 0; i < argc; i++) {
  2276. + const char *target = argv[i];
  2277. + int j;
  2278. +
  2279. + ipkg_message(conf, IPKG_ERROR, "What %s %s\n",
  2280. + rel_str, target);
  2281. + for (j = 0; j < available_pkgs->len; j++) {
  2282. + pkg_t *pkg = available_pkgs->pkgs[j];
  2283. + int k;
  2284. + int count = (what_field_type == WHATPROVIDES) ? pkg->provides_count : pkg->replaces_count;
  2285. + for (k = 0; k < count; k++) {
  2286. + abstract_pkg_t *apkg =
  2287. + ((what_field_type == WHATPROVIDES)
  2288. + ? pkg->provides[k]
  2289. + : pkg->replaces[k]);
  2290. + if (fnmatch(target, apkg->name, 0) == 0) {
  2291. + ipkg_message(conf, IPKG_ERROR, " %s", pkg->name);
  2292. + if (strcmp(target, apkg->name) != 0)
  2293. + ipkg_message(conf, IPKG_ERROR, "\t%s %s\n", rel_str, apkg->name);
  2294. + ipkg_message(conf, IPKG_ERROR, "\n");
  2295. + }
  2296. + }
  2297. + }
  2298. + }
  2299. + pkg_vec_free(available_pkgs);
  2300. + }
  2301. + return 0;
  2302. +}
  2303. +
  2304. +static int ipkg_whatprovides_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2305. +{
  2306. + return ipkg_what_provides_replaces_cmd(conf, WHATPROVIDES, argc, argv);
  2307. +}
  2308. +
  2309. +static int ipkg_whatreplaces_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2310. +{
  2311. + return ipkg_what_provides_replaces_cmd(conf, WHATREPLACES, argc, argv);
  2312. +}
  2313. +
  2314. +static int ipkg_search_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2315. +{
  2316. + int i;
  2317. +
  2318. + pkg_vec_t *installed;
  2319. + pkg_t *pkg;
  2320. + str_list_t *installed_files;
  2321. + str_list_elt_t *iter;
  2322. + char *installed_file;
  2323. +
  2324. + if (argc < 1) {
  2325. + return EINVAL;
  2326. + }
  2327. +
  2328. + installed = pkg_vec_alloc();
  2329. + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
  2330. +
  2331. + for (i=0; i < installed->len; i++) {
  2332. + pkg = installed->pkgs[i];
  2333. +
  2334. + installed_files = pkg_get_installed_files(pkg);
  2335. +
  2336. + for (iter = installed_files->head; iter; iter = iter->next) {
  2337. + installed_file = iter->data;
  2338. + if (fnmatch(argv[0], installed_file, 0)==0) {
  2339. + if (ipkg_cb_list) ipkg_cb_list(pkg->name,
  2340. + installed_file,
  2341. + pkg_version_str_alloc(pkg),
  2342. + pkg->state_status, p_userdata);
  2343. + }
  2344. + }
  2345. +
  2346. + pkg_free_installed_files(pkg);
  2347. + }
  2348. +
  2349. + /* XXX: CLEANUP: It's not obvious from the name of
  2350. + pkg_hash_fetch_all_installed that we need to call
  2351. + pkg_vec_free to avoid a memory leak. */
  2352. + pkg_vec_free(installed);
  2353. +
  2354. + return 0;
  2355. +}
  2356. +
  2357. +static int ipkg_compare_versions_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2358. +{
  2359. + if (argc == 3) {
  2360. + /* this is a bit gross */
  2361. + struct pkg p1, p2;
  2362. + parseVersion(&p1, argv[0]);
  2363. + parseVersion(&p2, argv[2]);
  2364. + return pkg_version_satisfied(&p1, &p2, argv[1]);
  2365. + } else {
  2366. + ipkg_message(conf, IPKG_ERROR,
  2367. + "ipkg compare_versions <v1> <op> <v2>\n"
  2368. + "<op> is one of <= >= << >> =\n");
  2369. + return -1;
  2370. + }
  2371. +}
  2372. +
  2373. +#ifndef HOST_CPU_STR
  2374. +#define HOST_CPU_STR__(X) #X
  2375. +#define HOST_CPU_STR_(X) HOST_CPU_STR__(X)
  2376. +#define HOST_CPU_STR HOST_CPU_STR_(HOST_CPU_FOO)
  2377. +#endif
  2378. +
  2379. +static int ipkg_print_architecture_cmd(ipkg_conf_t *conf)
  2380. +{
  2381. + nv_pair_list_elt_t *l;
  2382. +
  2383. + l = conf->arch_list.head;
  2384. + while (l) {
  2385. + nv_pair_t *nv = l->data;
  2386. + printf("arch %s %s\n", nv->name, nv->value);
  2387. + l = l->next;
  2388. + }
  2389. + return 0;
  2390. +}
  2391. +
  2392. +
  2393. diff -Nur busybox-1.21.1.orig/archival/libipkg/ipkg_cmd.h busybox-1.21.1/archival/libipkg/ipkg_cmd.h
  2394. --- busybox-1.21.1.orig/archival/libipkg/ipkg_cmd.h 1970-01-01 01:00:00.000000000 +0100
  2395. +++ busybox-1.21.1/archival/libipkg/ipkg_cmd.h 2014-02-17 14:25:39.858534188 +0100
  2396. @@ -0,0 +1,41 @@
  2397. +/* ipkg_cmd.h - the itsy package management system
  2398. +
  2399. + Carl D. Worth
  2400. +
  2401. + Copyright (C) 2001 University of Southern California
  2402. +
  2403. + This program is free software; you can redistribute it and/or
  2404. + modify it under the terms of the GNU General Public License as
  2405. + published by the Free Software Foundation; either version 2, or (at
  2406. + your option) any later version.
  2407. +
  2408. + This program is distributed in the hope that it will be useful, but
  2409. + WITHOUT ANY WARRANTY; without even the implied warranty of
  2410. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  2411. + General Public License for more details.
  2412. +*/
  2413. +
  2414. +#ifndef IPKG_CMD_H
  2415. +#define IPKG_CMD_H
  2416. +
  2417. +typedef int (*ipkg_cmd_fun_t)(ipkg_conf_t *conf, int argc, const char **argv);
  2418. +
  2419. +struct ipkg_cmd
  2420. +{
  2421. + const char *name;
  2422. + int requires_args;
  2423. + ipkg_cmd_fun_t fun;
  2424. +};
  2425. +typedef struct ipkg_cmd ipkg_cmd_t;
  2426. +
  2427. +ipkg_cmd_t *ipkg_cmd_find(const char *name);
  2428. +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc,
  2429. + const char **argv, void *userdata);
  2430. +int ipkg_multiple_files_scan (ipkg_conf_t *conf, int argc, char *argv[]);
  2431. +/* install any packges with state_want == SW_INSTALL */
  2432. +int ipkg_install_wanted_packages(ipkg_conf_t *conf);
  2433. +/* ensure that all dependences are satisfied */
  2434. +int ipkg_configure_packages(ipkg_conf_t *conf, char *pkg_name);
  2435. +int pkg_mark_provides(pkg_t *pkg);
  2436. +
  2437. +#endif
  2438. diff -Nur busybox-1.21.1.orig/archival/libipkg/ipkg_conf.c busybox-1.21.1/archival/libipkg/ipkg_conf.c
  2439. --- busybox-1.21.1.orig/archival/libipkg/ipkg_conf.c 1970-01-01 01:00:00.000000000 +0100
  2440. +++ busybox-1.21.1/archival/libipkg/ipkg_conf.c 2014-02-17 19:29:30.303924578 +0100
  2441. @@ -0,0 +1,739 @@
  2442. +/* ipkg_conf.c - the itsy package management system
  2443. +
  2444. + Carl D. Worth
  2445. +
  2446. + Copyright (C) 2001 University of Southern California
  2447. +
  2448. + This program is free software; you can redistribute it and/or
  2449. + modify it under the terms of the GNU General Public License as
  2450. + published by the Free Software Foundation; either version 2, or (at
  2451. + your option) any later version.
  2452. +
  2453. + This program is distributed in the hope that it will be useful, but
  2454. + WITHOUT ANY WARRANTY; without even the implied warranty of
  2455. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  2456. + General Public License for more details.
  2457. +*/
  2458. +
  2459. +#include <glob.h>
  2460. +
  2461. +#include "ipkg.h"
  2462. +#include "ipkg_conf.h"
  2463. +
  2464. +#include "xregex.h"
  2465. +#include "sprintf_alloc.h"
  2466. +#include "ipkg_conf.h"
  2467. +#include "ipkg_message.h"
  2468. +#include "file_util.h"
  2469. +#include "str_util.h"
  2470. +#include "xsystem.h"
  2471. +
  2472. +
  2473. +ipkg_conf_t *global_conf;
  2474. +
  2475. +static int ipkg_conf_parse_file(ipkg_conf_t *conf, const char *filename,
  2476. + pkg_src_list_t *pkg_src_list,
  2477. + nv_pair_list_t *tmp_dest_nv_pair_list,
  2478. + char **tmp_lists_dir);
  2479. +static int ipkg_init_options_array(const ipkg_conf_t *conf, ipkg_option_t **options);
  2480. +static int ipkg_conf_set_option(const ipkg_option_t *options,
  2481. + const char *name, const char *value);
  2482. +static int ipkg_conf_set_default_dest(ipkg_conf_t *conf,
  2483. + const char *default_dest_name);
  2484. +static int set_and_load_pkg_src_list(ipkg_conf_t *conf,
  2485. + pkg_src_list_t *nv_pair_list);
  2486. +static int set_and_load_pkg_dest_list(ipkg_conf_t *conf,
  2487. + nv_pair_list_t *nv_pair_list, char * lists_dir);
  2488. +
  2489. +int ipkg_init_options_array(const ipkg_conf_t *conf, ipkg_option_t **options)
  2490. +{
  2491. + ipkg_option_t tmp[] = {
  2492. + { "force_defaults", IPKG_OPT_TYPE_BOOL, &conf->force_defaults },
  2493. + { "force_depends", IPKG_OPT_TYPE_BOOL, &conf->force_depends },
  2494. + { "force_overwrite", IPKG_OPT_TYPE_BOOL, &conf->force_overwrite },
  2495. + { "force_downgrade", IPKG_OPT_TYPE_BOOL, &conf->force_downgrade },
  2496. + { "force_reinstall", IPKG_OPT_TYPE_BOOL, &conf->force_reinstall },
  2497. + { "force_space", IPKG_OPT_TYPE_BOOL, &conf->force_space },
  2498. + { "ftp_proxy", IPKG_OPT_TYPE_STRING, &conf->ftp_proxy },
  2499. + { "http_proxy", IPKG_OPT_TYPE_STRING, &conf->http_proxy },
  2500. + { "multiple_providers", IPKG_OPT_TYPE_BOOL, &conf->multiple_providers },
  2501. + { "no_proxy", IPKG_OPT_TYPE_STRING, &conf->no_proxy },
  2502. + { "test", IPKG_OPT_TYPE_INT, &conf->noaction },
  2503. + { "noaction", IPKG_OPT_TYPE_INT, &conf->noaction },
  2504. + { "nodeps", IPKG_OPT_TYPE_BOOL, &conf->nodeps },
  2505. + { "offline_root", IPKG_OPT_TYPE_STRING, &conf->offline_root },
  2506. + { "offline_root_post_script_cmd", IPKG_OPT_TYPE_STRING, &conf->offline_root_post_script_cmd },
  2507. + { "offline_root_pre_script_cmd", IPKG_OPT_TYPE_STRING, &conf->offline_root_pre_script_cmd },
  2508. + { "proxy_passwd", IPKG_OPT_TYPE_STRING, &conf->proxy_passwd },
  2509. + { "proxy_user", IPKG_OPT_TYPE_STRING, &conf->proxy_user },
  2510. + { "query-all", IPKG_OPT_TYPE_BOOL, &conf->query_all },
  2511. + { "verbose-wget", IPKG_OPT_TYPE_BOOL, &conf->verbose_wget },
  2512. + { "verbosity", IPKG_OPT_TYPE_BOOL, &conf->verbosity },
  2513. + { NULL }
  2514. + };
  2515. +
  2516. + *options = (ipkg_option_t *)malloc(sizeof(tmp));
  2517. + if ( options == NULL ){
  2518. + fprintf(stderr,"%s: Unable to allocate memory\n",__FUNCTION__);
  2519. + return -1;
  2520. + }
  2521. +
  2522. + memcpy(*options, tmp, sizeof(tmp));
  2523. + return 0;
  2524. +};
  2525. +
  2526. +static void ipkg_conf_override_string(char **conf_str, char *arg_str)
  2527. +{
  2528. + if (arg_str) {
  2529. + if (*conf_str) {
  2530. + free(*conf_str);
  2531. + }
  2532. + *conf_str = strdup(arg_str);
  2533. + }
  2534. +}
  2535. +
  2536. +static void ipkg_conf_free_string(char **conf_str)
  2537. +{
  2538. + if (*conf_str) {
  2539. + free(*conf_str);
  2540. + *conf_str = NULL;
  2541. + }
  2542. +}
  2543. +
  2544. +int ipkg_conf_init(ipkg_conf_t *conf, const args_t *args)
  2545. +{
  2546. + int err;
  2547. + int remountroot;
  2548. + struct mntent *mnt;
  2549. + FILE *f;
  2550. + char *tmp_dir_base;
  2551. + nv_pair_list_t tmp_dest_nv_pair_list;
  2552. + char * lists_dir =NULL;
  2553. + glob_t globbuf;
  2554. + const char *etc_ipkg_conf_pattern = "/etc/ipkg/*.conf";
  2555. + char *pending_dir =NULL;
  2556. +
  2557. + memset(conf, 0, sizeof(ipkg_conf_t));
  2558. +
  2559. + pkg_src_list_init(&conf->pkg_src_list);
  2560. +
  2561. + nv_pair_list_init(&tmp_dest_nv_pair_list);
  2562. + pkg_dest_list_init(&conf->pkg_dest_list);
  2563. +
  2564. + nv_pair_list_init(&conf->arch_list);
  2565. +
  2566. + conf->restrict_to_default_dest = 0;
  2567. + conf->default_dest = NULL;
  2568. +
  2569. +
  2570. + if (args->tmp_dir)
  2571. + tmp_dir_base = args->tmp_dir;
  2572. + else
  2573. + tmp_dir_base = getenv("IPKGTMPDIR");
  2574. + sprintf_alloc(&conf->tmp_dir, "%s/%s",
  2575. + tmp_dir_base ? tmp_dir_base : IPKG_CONF_DEFAULT_TMP_DIR_BASE,
  2576. + IPKG_CONF_TMP_DIR_SUFFIX);
  2577. +
  2578. + remountroot = 0;
  2579. + /* check if /dev/root is mounted read-only */
  2580. + if ((f = setmntent("/proc/mounts", "r")) == NULL)
  2581. + fprintf (stderr, "Checking /proc/mounts failed\n");
  2582. + while ((mnt = getmntent(f)) != NULL) {
  2583. + if (strcmp(mnt->mnt_fsname, "/dev/root") == 0 &&
  2584. + hasmntopt(mnt, MNTOPT_RO) != NULL) {
  2585. + remountroot = 1;
  2586. + }
  2587. + }
  2588. + endmntent(f);
  2589. +
  2590. + if (remountroot) {
  2591. + /* mount rootfs read-write */
  2592. + if (mount("","/",0,MS_REMOUNT,0)<0)
  2593. + fprintf (stderr, "Mounting rootfs read-write failed\n");
  2594. + }
  2595. + mkdir(tmp_dir_base, S_IRWXU);
  2596. + conf->tmp_dir = mkdtemp(conf->tmp_dir);
  2597. + if (conf->tmp_dir == NULL) {
  2598. + fprintf(stderr, "%s: Failed to create temporary directory `%s': %s\n",
  2599. + __FUNCTION__, conf->tmp_dir, strerror(errno));
  2600. + return errno;
  2601. + }
  2602. + if (remountroot) {
  2603. + sync();
  2604. + /* mount rootfs read-only */
  2605. + if (mount("","/",0,MS_REMOUNT|MS_RDONLY,0)<0)
  2606. + fprintf (stderr, "Mounting rootfs read-only failed\n");
  2607. + }
  2608. +
  2609. + conf->force_depends = 0;
  2610. + conf->force_defaults = 0;
  2611. + conf->force_overwrite = 0;
  2612. + conf->force_downgrade = 0;
  2613. + conf->force_reinstall = 0;
  2614. + conf->force_space = 0;
  2615. + conf->force_removal_of_essential_packages = 0;
  2616. + conf->force_removal_of_dependent_packages = 0;
  2617. + conf->nodeps = 0;
  2618. + conf->verbose_wget = 0;
  2619. + conf->offline_root = NULL;
  2620. + conf->offline_root_pre_script_cmd = NULL;
  2621. + conf->offline_root_post_script_cmd = NULL;
  2622. + conf->multiple_providers = 0;
  2623. + conf->verbosity = 1;
  2624. + conf->noaction = 0;
  2625. +
  2626. + conf->http_proxy = NULL;
  2627. + conf->ftp_proxy = NULL;
  2628. + conf->no_proxy = NULL;
  2629. + conf->proxy_user = NULL;
  2630. + conf->proxy_passwd = NULL;
  2631. +
  2632. + pkg_hash_init("pkg-hash", &conf->pkg_hash, IPKG_CONF_DEFAULT_HASH_LEN);
  2633. + hash_table_init("file-hash", &conf->file_hash, IPKG_CONF_DEFAULT_HASH_LEN);
  2634. + hash_table_init("obs-file-hash", &conf->obs_file_hash, IPKG_CONF_DEFAULT_HASH_LEN);
  2635. + lists_dir=(char *)malloc(1);
  2636. + lists_dir[0]='\0';
  2637. + if (args->conf_file) {
  2638. + struct stat stat_buf;
  2639. + err = stat(args->conf_file, &stat_buf);
  2640. + if (err == 0)
  2641. + if (ipkg_conf_parse_file(conf, args->conf_file,
  2642. + &conf->pkg_src_list, &tmp_dest_nv_pair_list,&lists_dir)<0) {
  2643. + /* Memory leakage from ipkg_conf_parse-file */
  2644. + return -1;
  2645. + }
  2646. +
  2647. + }
  2648. +
  2649. + /* if (!lists_dir ){*/
  2650. + if (strlen(lists_dir)<=1 ){
  2651. + lists_dir = realloc(lists_dir,strlen(IPKG_CONF_LISTS_DIR)+2);
  2652. + sprintf (lists_dir,"%s",IPKG_CONF_LISTS_DIR);
  2653. + }
  2654. +
  2655. + if (args->offline_root) {
  2656. + char *tmp = malloc(strlen(lists_dir) + strlen(args->offline_root) + 1);
  2657. + sprintf_alloc(&tmp, "%s/%s",args->offline_root,lists_dir);
  2658. + free(lists_dir);
  2659. + lists_dir = tmp;
  2660. + }
  2661. +
  2662. + pending_dir = malloc(strlen(lists_dir)+strlen("/pending")+5);
  2663. + snprintf(pending_dir,strlen(lists_dir)+strlen("/pending") ,"%s%s",lists_dir,"/pending");
  2664. +
  2665. + conf->lists_dir = strdup(lists_dir);
  2666. + conf->pending_dir = strdup(pending_dir);
  2667. +
  2668. + if (args->offline_root)
  2669. + sprintf_alloc(&etc_ipkg_conf_pattern, "%s/etc/ipkg/*.conf", args->offline_root);
  2670. + memset(&globbuf, 0, sizeof(globbuf));
  2671. + err = glob(etc_ipkg_conf_pattern, 0, NULL, &globbuf);
  2672. + if (!err) {
  2673. + int i;
  2674. + for (i = 0; i < globbuf.gl_pathc; i++) {
  2675. + if (globbuf.gl_pathv[i])
  2676. + if ( ipkg_conf_parse_file(conf, globbuf.gl_pathv[i],
  2677. + &conf->pkg_src_list, &tmp_dest_nv_pair_list,&lists_dir)<0) {
  2678. + /* Memory leakage from ipkg_conf_parse-file */
  2679. + return -1;
  2680. + }
  2681. + }
  2682. + }
  2683. + globfree(&globbuf);
  2684. +
  2685. + /* if no architectures were defined, then default all, noarch, and host architecture */
  2686. + if (nv_pair_list_empty(&conf->arch_list)) {
  2687. + nv_pair_list_append(&conf->arch_list, "all", "1");
  2688. + nv_pair_list_append(&conf->arch_list, "noarch", "1");
  2689. + nv_pair_list_append(&conf->arch_list, HOST_CPU_STR, "10");
  2690. + }
  2691. +
  2692. + /* Even if there is no conf file, we'll need at least one dest. */
  2693. + if (tmp_dest_nv_pair_list.head == NULL) {
  2694. + nv_pair_list_append(&tmp_dest_nv_pair_list,
  2695. + IPKG_CONF_DEFAULT_DEST_NAME,
  2696. + IPKG_CONF_DEFAULT_DEST_ROOT_DIR);
  2697. + }
  2698. +
  2699. + /* After parsing the file, set options from command-line, (so that
  2700. + command-line arguments take precedence) */
  2701. + /* XXX: CLEANUP: The interaction between args.c and ipkg_conf.c
  2702. + really needs to be cleaned up. There is so much duplication
  2703. + right now it is ridiculous. Maybe ipkg_conf_t should just save
  2704. + a pointer to args_t (which could then not be freed), rather
  2705. + than duplicating every field here? */
  2706. + if (args->force_depends) {
  2707. + conf->force_depends = 1;
  2708. + }
  2709. + if (args->force_defaults) {
  2710. + conf->force_defaults = 1;
  2711. + }
  2712. + if (args->force_overwrite) {
  2713. + conf->force_overwrite = 1;
  2714. + }
  2715. + if (args->force_downgrade) {
  2716. + conf->force_downgrade = 1;
  2717. + }
  2718. + if (args->force_reinstall) {
  2719. + conf->force_reinstall = 1;
  2720. + }
  2721. + if (args->force_removal_of_dependent_packages) {
  2722. + conf->force_removal_of_dependent_packages = 1;
  2723. + }
  2724. + if (args->force_removal_of_essential_packages) {
  2725. + conf->force_removal_of_essential_packages = 1;
  2726. + }
  2727. + if (args->nodeps) {
  2728. + conf->nodeps = 1;
  2729. + }
  2730. + if (args->noaction) {
  2731. + conf->noaction = 1;
  2732. + }
  2733. + if (args->query_all) {
  2734. + conf->query_all = 1;
  2735. + }
  2736. + if (args->verbose_wget) {
  2737. + conf->verbose_wget = 1;
  2738. + }
  2739. + if (args->multiple_providers) {
  2740. + conf->multiple_providers = 1;
  2741. + }
  2742. + if (args->verbosity != conf->verbosity) {
  2743. + conf->verbosity = args->verbosity;
  2744. + }
  2745. +
  2746. + ipkg_conf_override_string(&conf->offline_root,
  2747. + args->offline_root);
  2748. + ipkg_conf_override_string(&conf->offline_root_pre_script_cmd,
  2749. + args->offline_root_pre_script_cmd);
  2750. + ipkg_conf_override_string(&conf->offline_root_post_script_cmd,
  2751. + args->offline_root_post_script_cmd);
  2752. +
  2753. +/* Pigi: added a flag to disable the checking of structures if the command does not need to
  2754. + read anything from there.
  2755. +*/
  2756. + if ( !(args->nocheckfordirorfile)){
  2757. + /* need to run load the source list before dest list -Jamey */
  2758. + if ( !(args->noreadfeedsfile))
  2759. + set_and_load_pkg_src_list(conf, &conf->pkg_src_list);
  2760. +
  2761. + /* Now that we have resolved conf->offline_root, we can commit to
  2762. + the directory names for the dests and load in all the package
  2763. + lists. */
  2764. + set_and_load_pkg_dest_list(conf, &tmp_dest_nv_pair_list,lists_dir);
  2765. +
  2766. + if (args->dest) {
  2767. + err = ipkg_conf_set_default_dest(conf, args->dest);
  2768. + if (err) {
  2769. + return err;
  2770. + }
  2771. + }
  2772. + }
  2773. + nv_pair_list_deinit(&tmp_dest_nv_pair_list);
  2774. + free(lists_dir);
  2775. + free(pending_dir);
  2776. +
  2777. + return 0;
  2778. +}
  2779. +
  2780. +void ipkg_conf_deinit(ipkg_conf_t *conf)
  2781. +{
  2782. +#ifdef IPKG_DEBUG_NO_TMP_CLEANUP
  2783. +#error
  2784. + fprintf(stderr, "%s: Not cleaning up %s since ipkg compiled "
  2785. + "with IPKG_DEBUG_NO_TMP_CLEANUP\n",
  2786. + __FUNCTION__, conf->tmp_dir);
  2787. +#else
  2788. + int err;
  2789. +
  2790. + err = rmdir(conf->tmp_dir);
  2791. + if (err) {
  2792. + if (errno == ENOTEMPTY) {
  2793. + char *cmd;
  2794. + sprintf_alloc(&cmd, "rm -fr %s\n", conf->tmp_dir);
  2795. + err = xsystem(cmd);
  2796. + free(cmd);
  2797. + }
  2798. + if (err)
  2799. + fprintf(stderr, "WARNING: Unable to remove temporary directory: %s: %s\n", conf->tmp_dir, strerror(errno));
  2800. + }
  2801. +#endif /* IPKG_DEBUG_NO_TMP_CLEANUP */
  2802. +
  2803. + free(conf->tmp_dir); /*XXX*/
  2804. +
  2805. + pkg_src_list_deinit(&conf->pkg_src_list);
  2806. + pkg_dest_list_deinit(&conf->pkg_dest_list);
  2807. + nv_pair_list_deinit(&conf->arch_list);
  2808. + if (&conf->pkg_hash)
  2809. + pkg_hash_deinit(&conf->pkg_hash);
  2810. + if (&conf->file_hash)
  2811. + hash_table_deinit(&conf->file_hash);
  2812. + if (&conf->obs_file_hash)
  2813. + hash_table_deinit(&conf->obs_file_hash);
  2814. +
  2815. + ipkg_conf_free_string(&conf->offline_root);
  2816. + ipkg_conf_free_string(&conf->offline_root_pre_script_cmd);
  2817. + ipkg_conf_free_string(&conf->offline_root_post_script_cmd);
  2818. +
  2819. + if (conf->verbosity > 1) {
  2820. + int i;
  2821. + hash_table_t *hashes[] = {
  2822. + &conf->pkg_hash,
  2823. + &conf->file_hash,
  2824. + &conf->obs_file_hash };
  2825. + for (i = 0; i < 3; i++) {
  2826. + hash_table_t *hash = hashes[i];
  2827. + int c = 0;
  2828. + int n_conflicts = 0;
  2829. + int j;
  2830. + for (j = 0; j < hash->n_entries; j++) {
  2831. + int len = 0;
  2832. + hash_entry_t *e = &hash->entries[j];
  2833. + if (e->next)
  2834. + n_conflicts++;
  2835. + while (e && e->key) {
  2836. + len++;
  2837. + e = e->next;
  2838. + }
  2839. + if (len > c)
  2840. + c = len;
  2841. + }
  2842. + ipkg_message(conf, IPKG_DEBUG, "hash_table[%s] n_buckets=%d n_elements=%d max_conflicts=%d n_conflicts=%d\n",
  2843. + hash->name, hash->n_entries, hash->n_elements, c, n_conflicts);
  2844. + hash_table_deinit(hash);
  2845. + }
  2846. + }
  2847. +}
  2848. +
  2849. +static int ipkg_conf_set_default_dest(ipkg_conf_t *conf,
  2850. + const char *default_dest_name)
  2851. +{
  2852. + pkg_dest_list_elt_t *iter;
  2853. + pkg_dest_t *dest;
  2854. +
  2855. + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
  2856. + dest = iter->data;
  2857. + if (strcmp(dest->name, default_dest_name) == 0) {
  2858. + conf->default_dest = dest;
  2859. + conf->restrict_to_default_dest = 1;
  2860. + return 0;
  2861. + }
  2862. + }
  2863. +
  2864. + fprintf(stderr, "ERROR: Unknown dest name: `%s'\n", default_dest_name);
  2865. +
  2866. + return 1;
  2867. +}
  2868. +
  2869. +static int set_and_load_pkg_src_list(ipkg_conf_t *conf, pkg_src_list_t *pkg_src_list)
  2870. +{
  2871. + pkg_src_list_elt_t *iter;
  2872. + pkg_src_t *src;
  2873. + char *list_file;
  2874. +
  2875. + for (iter = pkg_src_list->head; iter; iter = iter->next) {
  2876. + src = iter->data;
  2877. + if (src == NULL) {
  2878. + continue;
  2879. + }
  2880. +
  2881. + sprintf_alloc(&list_file, "%s/%s",
  2882. + conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir,
  2883. + src->name);
  2884. +
  2885. + if (file_exists(list_file)) {
  2886. + pkg_hash_add_from_file(conf, list_file, src, NULL, 0);
  2887. + }
  2888. + free(list_file);
  2889. + }
  2890. +
  2891. + return 0;
  2892. +}
  2893. +
  2894. +static int set_and_load_pkg_dest_list(ipkg_conf_t *conf, nv_pair_list_t *nv_pair_list, char *lists_dir )
  2895. +{
  2896. + nv_pair_list_elt_t *iter;
  2897. + nv_pair_t *nv_pair;
  2898. + pkg_dest_t *dest;
  2899. + char *root_dir;
  2900. +
  2901. + for (iter = nv_pair_list->head; iter; iter = iter->next) {
  2902. + nv_pair = iter->data;
  2903. +
  2904. + if (conf->offline_root) {
  2905. + sprintf_alloc(&root_dir, "%s%s", conf->offline_root, nv_pair->value);
  2906. + } else {
  2907. + root_dir = strdup(nv_pair->value);
  2908. + }
  2909. + dest = pkg_dest_list_append(&conf->pkg_dest_list, nv_pair->name, root_dir, lists_dir);
  2910. + free(root_dir);
  2911. + if (dest == NULL) {
  2912. + continue;
  2913. + }
  2914. + if (conf->default_dest == NULL) {
  2915. + conf->default_dest = dest;
  2916. + }
  2917. + if (file_exists(dest->status_file_name)) {
  2918. + pkg_hash_add_from_file(conf, dest->status_file_name,
  2919. + NULL, dest, 1);
  2920. + }
  2921. + }
  2922. +
  2923. + return 0;
  2924. +}
  2925. +
  2926. +static int ipkg_conf_parse_file(ipkg_conf_t *conf, const char *filename,
  2927. + pkg_src_list_t *pkg_src_list,
  2928. + nv_pair_list_t *tmp_dest_nv_pair_list,
  2929. + char **lists_dir)
  2930. +{
  2931. + ipkg_option_t * options;
  2932. + FILE *file = fopen(filename, "r");
  2933. + regex_t valid_line_re, comment_re;
  2934. +#define regmatch_size 12
  2935. + regmatch_t regmatch[regmatch_size];
  2936. +
  2937. + if (ipkg_init_options_array(conf, &options)<0)
  2938. + return ENOMEM;
  2939. +
  2940. + if (file == NULL) {
  2941. + fprintf(stderr, "%s: failed to open %s: %s\n",
  2942. + __FUNCTION__, filename, strerror(errno));
  2943. + free(options);
  2944. + return errno;
  2945. + }
  2946. + ipkg_message(conf, IPKG_NOTICE, "loading conf file %s\n", filename);
  2947. +
  2948. + xregcomp(&comment_re,
  2949. + "^[[:space:]]*(#.*|[[:space:]]*)$",
  2950. + REG_EXTENDED);
  2951. + xregcomp(&valid_line_re, "^[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))([[:space:]]+([^[:space:]]+))?[[:space:]]*$", REG_EXTENDED);
  2952. +
  2953. + while(1) {
  2954. + int line_num = 0;
  2955. + char *line;
  2956. + char *type, *name, *value, *extra;
  2957. +
  2958. + line = file_read_line_alloc(file);
  2959. + line_num++;
  2960. + if (line == NULL) {
  2961. + break;
  2962. + }
  2963. +
  2964. + str_chomp(line);
  2965. +
  2966. + if (regexec(&comment_re, line, 0, 0, 0) == 0) {
  2967. + goto NEXT_LINE;
  2968. + }
  2969. +
  2970. + if (regexec(&valid_line_re, line, regmatch_size, regmatch, 0) == REG_NOMATCH) {
  2971. + str_chomp(line);
  2972. + fprintf(stderr, "%s:%d: Ignoring invalid line: `%s'\n",
  2973. + filename, line_num, line);
  2974. + goto NEXT_LINE;
  2975. + }
  2976. +
  2977. + /* This has to be so ugly to deal with optional quotation marks */
  2978. + if (regmatch[2].rm_so > 0) {
  2979. + type = strndup(line + regmatch[2].rm_so,
  2980. + regmatch[2].rm_eo - regmatch[2].rm_so);
  2981. + } else {
  2982. + type = strndup(line + regmatch[3].rm_so,
  2983. + regmatch[3].rm_eo - regmatch[3].rm_so);
  2984. + }
  2985. + if (regmatch[5].rm_so > 0) {
  2986. + name = strndup(line + regmatch[5].rm_so,
  2987. + regmatch[5].rm_eo - regmatch[5].rm_so);
  2988. + } else {
  2989. + name = strndup(line + regmatch[6].rm_so,
  2990. + regmatch[6].rm_eo - regmatch[6].rm_so);
  2991. + }
  2992. + if (regmatch[8].rm_so > 0) {
  2993. + value = strndup(line + regmatch[8].rm_so,
  2994. + regmatch[8].rm_eo - regmatch[8].rm_so);
  2995. + } else {
  2996. + value = strndup(line + regmatch[9].rm_so,
  2997. + regmatch[9].rm_eo - regmatch[9].rm_so);
  2998. + }
  2999. + extra = NULL;
  3000. + if (regmatch[11].rm_so > 0) {
  3001. + extra = strndup (line + regmatch[11].rm_so,
  3002. + regmatch[11].rm_eo - regmatch[11].rm_so);
  3003. + }
  3004. +
  3005. + /* We use the tmp_dest_nv_pair_list below instead of
  3006. + conf->pkg_dest_list because we might encounter an
  3007. + offline_root option later and that would invalidate the
  3008. + directories we would have computed in
  3009. + pkg_dest_list_init. (We do a similar thing with
  3010. + tmp_src_nv_pair_list for sake of symmetry.) */
  3011. + if (strcmp(type, "option") == 0) {
  3012. + ipkg_conf_set_option(options, name, value);
  3013. + } else if (strcmp(type, "src") == 0) {
  3014. + if (!nv_pair_list_find((nv_pair_list_t *)pkg_src_list, name)) {
  3015. + pkg_src_list_append (pkg_src_list, name, value, extra, 0);
  3016. + } else {
  3017. + ipkg_message(conf, IPKG_ERROR, "ERROR: duplicate src declaration. Skipping:\n\t src %s %s\n",
  3018. + name, value);
  3019. + }
  3020. + } else if (strcmp(type, "src/gz") == 0) {
  3021. + if (!nv_pair_list_find((nv_pair_list_t *)pkg_src_list, name)) {
  3022. + pkg_src_list_append (pkg_src_list, name, value, extra, 1);
  3023. + } else {
  3024. + ipkg_message(conf, IPKG_ERROR, "ERROR: duplicate src declaration. Skipping:\n\t src %s %s\n",
  3025. + name, value);
  3026. + }
  3027. + } else if (strcmp(type, "dest") == 0) {
  3028. + nv_pair_list_append(tmp_dest_nv_pair_list, name, value);
  3029. + } else if (strcmp(type, "lists_dir") == 0) {
  3030. + *lists_dir = realloc(*lists_dir,strlen(value)+1);
  3031. + if (*lists_dir == NULL) {
  3032. + ipkg_message(conf, IPKG_ERROR, "ERROR: Not enough memory\n");
  3033. + free(options);
  3034. + return EINVAL;
  3035. + }
  3036. + sprintf (*lists_dir,"%s",value);
  3037. + } else if (strcmp(type, "arch") == 0) {
  3038. + ipkg_message(conf, IPKG_INFO, "supported arch %s priority (%s)\n", name, value);
  3039. + if (!value) {
  3040. + ipkg_message(conf, IPKG_NOTICE, "defaulting architecture %s priority to 10\n", name);
  3041. + value = strdup("10");
  3042. + }
  3043. + nv_pair_list_append(&conf->arch_list, strdup(name), strdup(value));
  3044. + } else {
  3045. + fprintf(stderr, "WARNING: Ignoring unknown configuration "
  3046. + "parameter: %s %s %s\n", type, name, value);
  3047. + free(options);
  3048. + return EINVAL;
  3049. + }
  3050. +
  3051. + free(type);
  3052. + free(name);
  3053. + free(value);
  3054. + if (extra)
  3055. + free (extra);
  3056. +
  3057. + NEXT_LINE:
  3058. + free(line);
  3059. + }
  3060. +
  3061. + free(options);
  3062. + regfree(&comment_re);
  3063. + regfree(&valid_line_re);
  3064. + fclose(file);
  3065. +
  3066. + return 0;
  3067. +}
  3068. +
  3069. +static int ipkg_conf_set_option(const ipkg_option_t *options,
  3070. + const char *name, const char *value)
  3071. +{
  3072. + int i = 0;
  3073. + while (options[i].name) {
  3074. + if (strcmp(options[i].name, name) == 0) {
  3075. + switch (options[i].type) {
  3076. + case IPKG_OPT_TYPE_BOOL:
  3077. + *((int *)options[i].value) = 1;
  3078. + return 0;
  3079. + case IPKG_OPT_TYPE_INT:
  3080. + if (value) {
  3081. + *((int *)options[i].value) = atoi(value);
  3082. + return 0;
  3083. + } else {
  3084. + printf("%s: Option %s need an argument\n",
  3085. + __FUNCTION__, name);
  3086. + return EINVAL;
  3087. + }
  3088. + case IPKG_OPT_TYPE_STRING:
  3089. + if (value) {
  3090. + *((char **)options[i].value) = strdup(value);
  3091. + return 0;
  3092. + } else {
  3093. + printf("%s: Option %s need an argument\n",
  3094. + __FUNCTION__, name);
  3095. + return EINVAL;
  3096. + }
  3097. + }
  3098. + }
  3099. + i++;
  3100. + }
  3101. +
  3102. + fprintf(stderr, "%s: Unrecognized option: %s=%s\n",
  3103. + __FUNCTION__, name, value);
  3104. + return EINVAL;
  3105. +}
  3106. +
  3107. +int ipkg_conf_write_status_files(ipkg_conf_t *conf)
  3108. +{
  3109. + pkg_dest_list_elt_t *iter;
  3110. + pkg_dest_t *dest;
  3111. + pkg_vec_t *all;
  3112. + pkg_t *pkg;
  3113. + register int i;
  3114. + int err;
  3115. +
  3116. + if (conf->noaction)
  3117. + return 0;
  3118. + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
  3119. + dest = iter->data;
  3120. + dest->status_file = fopen(dest->status_file_tmp_name, "w");
  3121. + if (dest->status_file == NULL) {
  3122. + fprintf(stderr, "%s: Can't open status file: %s for writing: %s\n",
  3123. + __FUNCTION__, dest->status_file_name, strerror(errno));
  3124. + }
  3125. + }
  3126. +
  3127. + all = pkg_vec_alloc();
  3128. + pkg_hash_fetch_available(&conf->pkg_hash, all);
  3129. +
  3130. + for(i = 0; i < all->len; i++) {
  3131. + pkg = all->pkgs[i];
  3132. + /* We don't need most uninstalled packages in the status file */
  3133. + if (pkg->state_status == SS_NOT_INSTALLED
  3134. + && (pkg->state_want == SW_UNKNOWN
  3135. + || pkg->state_want == SW_DEINSTALL
  3136. + || pkg->state_want == SW_PURGE)) {
  3137. + continue;
  3138. + }
  3139. + if (!pkg) {
  3140. + fprintf(stderr, "Null package\n");
  3141. + }
  3142. + if (pkg->dest == NULL) {
  3143. + fprintf(stderr, "%s: ERROR: Can't write status for "
  3144. + "package %s since it has a NULL dest\n",
  3145. + __FUNCTION__, pkg->name);
  3146. + continue;
  3147. + }
  3148. + if (pkg->dest->status_file) {
  3149. + pkg_print_status(pkg, pkg->dest->status_file);
  3150. + }
  3151. + }
  3152. +
  3153. + pkg_vec_free(all);
  3154. +
  3155. + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
  3156. + dest = iter->data;
  3157. + if (dest->status_file) {
  3158. + err = ferror(dest->status_file);
  3159. + fclose(dest->status_file);
  3160. + dest->status_file = NULL;
  3161. + if (!err) {
  3162. + file_move(dest->status_file_tmp_name, dest->status_file_name);
  3163. + } else {
  3164. + fprintf(stderr, "%s: ERROR: An error has occurred writing %s, "
  3165. + "retaining old %s\n", __FUNCTION__,
  3166. + dest->status_file_tmp_name, dest->status_file_name);
  3167. + }
  3168. + }
  3169. + }
  3170. +
  3171. + return 0;
  3172. +}
  3173. +
  3174. +
  3175. +char *root_filename_alloc(ipkg_conf_t *conf, char *filename)
  3176. +{
  3177. + char *root_filename;
  3178. + sprintf_alloc(&root_filename, "%s%s", (conf->offline_root ? conf->offline_root : ""), filename);
  3179. + return root_filename;
  3180. +}
  3181. diff -Nur busybox-1.21.1.orig/archival/libipkg/ipkg_conf.h busybox-1.21.1/archival/libipkg/ipkg_conf.h
  3182. --- busybox-1.21.1.orig/archival/libipkg/ipkg_conf.h 1970-01-01 01:00:00.000000000 +0100
  3183. +++ busybox-1.21.1/archival/libipkg/ipkg_conf.h 2014-02-17 14:25:39.858534188 +0100
  3184. @@ -0,0 +1,107 @@
  3185. +/* ipkg_conf.h - the itsy package management system
  3186. +
  3187. + Carl D. Worth
  3188. +
  3189. + Copyright (C) 2001 University of Southern California
  3190. +
  3191. + This program is free software; you can redistribute it and/or
  3192. + modify it under the terms of the GNU General Public License as
  3193. + published by the Free Software Foundation; either version 2, or (at
  3194. + your option) any later version.
  3195. +
  3196. + This program is distributed in the hope that it will be useful, but
  3197. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3198. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3199. + General Public License for more details.
  3200. +*/
  3201. +
  3202. +#ifndef IPKG_CONF_H
  3203. +#define IPKG_CONF_H
  3204. +
  3205. +typedef struct ipkg_conf ipkg_conf_t;
  3206. +
  3207. +#include "hash_table.h"
  3208. +#include "ipkg.h"
  3209. +#include "args.h"
  3210. +#include "pkg.h"
  3211. +#include "pkg_hash.h"
  3212. +#include "pkg_src_list.h"
  3213. +#include "pkg_dest_list.h"
  3214. +#include "nv_pair_list.h"
  3215. +
  3216. +#define IPKG_CONF_DEFAULT_TMP_DIR_BASE "/tmp"
  3217. +#define IPKG_CONF_TMP_DIR_SUFFIX "ipkg-XXXXXX"
  3218. +#define IPKG_CONF_LISTS_DIR IPKG_STATE_DIR_PREFIX "/lists"
  3219. +#define IPKG_CONF_PENDING_DIR IPKG_STATE_DIR_PREFIX "/pending"
  3220. +
  3221. +/* In case the config file defines no dest */
  3222. +#define IPKG_CONF_DEFAULT_DEST_NAME "root"
  3223. +#define IPKG_CONF_DEFAULT_DEST_ROOT_DIR "/"
  3224. +
  3225. +#define IPKG_CONF_DEFAULT_HASH_LEN 1024
  3226. +
  3227. +struct ipkg_conf
  3228. +{
  3229. + pkg_src_list_t pkg_src_list;
  3230. + pkg_dest_list_t pkg_dest_list;
  3231. + nv_pair_list_t arch_list;
  3232. +
  3233. + int restrict_to_default_dest;
  3234. + pkg_dest_t *default_dest;
  3235. +
  3236. + char *tmp_dir;
  3237. + char *lists_dir;
  3238. + char *pending_dir;
  3239. +
  3240. + /* options */
  3241. + int force_depends;
  3242. + int force_defaults;
  3243. + int force_overwrite;
  3244. + int force_downgrade;
  3245. + int force_reinstall;
  3246. + int force_space;
  3247. + int force_removal_of_dependent_packages;
  3248. + int force_removal_of_essential_packages;
  3249. + int nodeps; /* do not follow dependences */
  3250. + int verbose_wget;
  3251. + int multiple_providers;
  3252. + char *offline_root;
  3253. + char *offline_root_pre_script_cmd;
  3254. + char *offline_root_post_script_cmd;
  3255. + int query_all;
  3256. + int verbosity;
  3257. + int noaction;
  3258. +
  3259. + /* proxy options */
  3260. + char *http_proxy;
  3261. + char *ftp_proxy;
  3262. + char *no_proxy;
  3263. + char *proxy_user;
  3264. + char *proxy_passwd;
  3265. +
  3266. + hash_table_t pkg_hash;
  3267. + hash_table_t file_hash;
  3268. + hash_table_t obs_file_hash;
  3269. +};
  3270. +
  3271. +enum ipkg_option_type {
  3272. + IPKG_OPT_TYPE_BOOL,
  3273. + IPKG_OPT_TYPE_INT,
  3274. + IPKG_OPT_TYPE_STRING
  3275. +};
  3276. +typedef enum ipkg_option_type ipkg_option_type_t;
  3277. +
  3278. +typedef struct ipkg_option ipkg_option_t;
  3279. +struct ipkg_option {
  3280. + const char *name;
  3281. + const ipkg_option_type_t type;
  3282. + const void *value;
  3283. +};
  3284. +
  3285. +int ipkg_conf_init(ipkg_conf_t *conf, const args_t *args);
  3286. +void ipkg_conf_deinit(ipkg_conf_t *conf);
  3287. +
  3288. +int ipkg_conf_write_status_files(ipkg_conf_t *conf);
  3289. +char *root_filename_alloc(ipkg_conf_t *conf, char *filename);
  3290. +
  3291. +#endif
  3292. diff -Nur busybox-1.21.1.orig/archival/libipkg/ipkg_configure.c busybox-1.21.1/archival/libipkg/ipkg_configure.c
  3293. --- busybox-1.21.1.orig/archival/libipkg/ipkg_configure.c 1970-01-01 01:00:00.000000000 +0100
  3294. +++ busybox-1.21.1/archival/libipkg/ipkg_configure.c 2014-02-17 14:25:39.858534188 +0100
  3295. @@ -0,0 +1,40 @@
  3296. +/* ipkg_configure.c - the itsy package management system
  3297. +
  3298. + Carl D. Worth
  3299. +
  3300. + Copyright (C) 2001 University of Southern California
  3301. +
  3302. + This program is free software; you can redistribute it and/or
  3303. + modify it under the terms of the GNU General Public License as
  3304. + published by the Free Software Foundation; either version 2, or (at
  3305. + your option) any later version.
  3306. +
  3307. + This program is distributed in the hope that it will be useful, but
  3308. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3309. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3310. + General Public License for more details.
  3311. +*/
  3312. +
  3313. +#include "ipkg.h"
  3314. +
  3315. +#include "ipkg_configure.h"
  3316. +
  3317. +int ipkg_configure(ipkg_conf_t *conf, pkg_t *pkg)
  3318. +{
  3319. + int err;
  3320. +
  3321. + /* DPKG_INCOMPATIBILITY:
  3322. + dpkg actually does some conffile handling here, rather than at the
  3323. + end of ipkg_install(). Do we care? */
  3324. + /* DPKG_INCOMPATIBILITY:
  3325. + dpkg actually includes a version number to this script call */
  3326. + err = pkg_run_script(conf, pkg, "postinst", "configure");
  3327. + if (err) {
  3328. + printf("ERROR: %s.postinst returned %d\n", pkg->name, err);
  3329. + return err;
  3330. + }
  3331. +
  3332. + ipkg_state_changed++;
  3333. + return 0;
  3334. +}
  3335. +
  3336. diff -Nur busybox-1.21.1.orig/archival/libipkg/ipkg_configure.h busybox-1.21.1/archival/libipkg/ipkg_configure.h
  3337. --- busybox-1.21.1.orig/archival/libipkg/ipkg_configure.h 1970-01-01 01:00:00.000000000 +0100
  3338. +++ busybox-1.21.1/archival/libipkg/ipkg_configure.h 2014-02-17 14:25:39.858534188 +0100
  3339. @@ -0,0 +1,25 @@
  3340. +/* ipkg_configure.h - the itsy package management system
  3341. +
  3342. + Carl D. Worth
  3343. +
  3344. + Copyright (C) 2001 University of Southern California
  3345. +
  3346. + This program is free software; you can redistribute it and/or
  3347. + modify it under the terms of the GNU General Public License as
  3348. + published by the Free Software Foundation; either version 2, or (at
  3349. + your option) any later version.
  3350. +
  3351. + This program is distributed in the hope that it will be useful, but
  3352. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3353. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3354. + General Public License for more details.
  3355. +*/
  3356. +
  3357. +#ifndef IPKG_CONFIGURE_H
  3358. +#define IPKG_CONFIGURE_H
  3359. +
  3360. +#include "ipkg_conf.h"
  3361. +
  3362. +int ipkg_configure(ipkg_conf_t *ipkg_conf, pkg_t *pkg);
  3363. +
  3364. +#endif
  3365. diff -Nur busybox-1.21.1.orig/archival/libipkg/ipkg_download.c busybox-1.21.1/archival/libipkg/ipkg_download.c
  3366. --- busybox-1.21.1.orig/archival/libipkg/ipkg_download.c 1970-01-01 01:00:00.000000000 +0100
  3367. +++ busybox-1.21.1/archival/libipkg/ipkg_download.c 2014-02-17 14:25:39.858534188 +0100
  3368. @@ -0,0 +1,195 @@
  3369. +/* ipkg_download.c - the itsy package management system
  3370. +
  3371. + Carl D. Worth
  3372. +
  3373. + Copyright (C) 2001 University of Southern California
  3374. +
  3375. + This program is free software; you can redistribute it and/or
  3376. + modify it under the terms of the GNU General Public License as
  3377. + published by the Free Software Foundation; either version 2, or (at
  3378. + your option) any later version.
  3379. +
  3380. + This program is distributed in the hope that it will be useful, but
  3381. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3382. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3383. + General Public License for more details.
  3384. +*/
  3385. +
  3386. +#include "ipkg.h"
  3387. +#include "ipkg_download.h"
  3388. +#include "ipkg_message.h"
  3389. +
  3390. +#include "sprintf_alloc.h"
  3391. +#include "xsystem.h"
  3392. +#include "file_util.h"
  3393. +#include "str_util.h"
  3394. +
  3395. +int ipkg_download(ipkg_conf_t *conf, const char *src, const char *dest_file_name)
  3396. +{
  3397. + int err = 0;
  3398. +
  3399. + char *src_basec = strdup(src);
  3400. + char *src_base = bb_basename(src_basec);
  3401. + char *tmp_file_location;
  3402. + char *cmd;
  3403. +
  3404. + ipkg_message(conf,IPKG_NOTICE,"Downloading %s\n", src);
  3405. +
  3406. + fflush(stdout);
  3407. +
  3408. + if (str_starts_with(src, "file:")) {
  3409. + int ret;
  3410. + const char *file_src = src + 5;
  3411. + ipkg_message(conf,IPKG_INFO,"Copying %s to %s...", file_src, dest_file_name);
  3412. + ret = file_copy(src + 5, dest_file_name);
  3413. + ipkg_message(conf,IPKG_INFO,"Done.\n");
  3414. + return ret;
  3415. + }
  3416. +
  3417. + sprintf_alloc(&tmp_file_location, "%s/%s", conf->tmp_dir, src_base);
  3418. + err = unlink(tmp_file_location);
  3419. + if (err && errno != ENOENT) {
  3420. + ipkg_message(conf,IPKG_ERROR, "%s: ERROR: failed to unlink %s: %s\n",
  3421. + __FUNCTION__, tmp_file_location, strerror(errno));
  3422. + free(tmp_file_location);
  3423. + return errno;
  3424. + }
  3425. +
  3426. + if (conf->http_proxy) {
  3427. + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: http_proxy = %s\n", conf->http_proxy);
  3428. + setenv("http_proxy", conf->http_proxy, 1);
  3429. + }
  3430. + if (conf->ftp_proxy) {
  3431. + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: ftp_proxy = %s\n", conf->ftp_proxy);
  3432. + setenv("ftp_proxy", conf->ftp_proxy, 1);
  3433. + }
  3434. + if (conf->no_proxy) {
  3435. + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: no_proxy = %s\n", conf->no_proxy);
  3436. + setenv("no_proxy", conf->no_proxy, 1);
  3437. + }
  3438. +
  3439. + /* XXX: BUG rewrite to use execvp or else busybox's internal wget -Jamey 7/23/2002 */
  3440. + sprintf_alloc(&cmd, "wget %s %s%s %s%s %s -P %s %s",
  3441. + (conf->http_proxy || conf->ftp_proxy) ? "-Y on" : "",
  3442. + conf->proxy_user ? "--proxy-user=" : "",
  3443. + conf->proxy_user ? conf->proxy_user : "",
  3444. + conf->proxy_passwd ? "--proxy-passwd=" : "",
  3445. + conf->proxy_passwd ? conf->proxy_passwd : "",
  3446. + conf->verbose_wget ? "" : "-q",
  3447. + conf->tmp_dir,
  3448. + src);
  3449. + err = xsystem(cmd);
  3450. + if (err) {
  3451. + if (err != -1) {
  3452. + ipkg_message(conf,IPKG_ERROR, "%s: ERROR: Command failed with return value %d: `%s'\n",
  3453. + __FUNCTION__, err, cmd);
  3454. + }
  3455. + unlink(tmp_file_location);
  3456. + free(tmp_file_location);
  3457. + free(src_basec);
  3458. + free(cmd);
  3459. + return EINVAL;
  3460. + }
  3461. + free(cmd);
  3462. +
  3463. + err = file_move(tmp_file_location, dest_file_name);
  3464. +
  3465. + free(tmp_file_location);
  3466. + free(src_basec);
  3467. +
  3468. + if (err) {
  3469. + return err;
  3470. + }
  3471. +
  3472. + return 0;
  3473. +}
  3474. +
  3475. +int ipkg_download_pkg(ipkg_conf_t *conf, pkg_t *pkg, const char *dir)
  3476. +{
  3477. + int err;
  3478. + char *url;
  3479. +
  3480. + if (pkg->src == NULL) {
  3481. + ipkg_message(conf,IPKG_ERROR, "ERROR: Package %s (parent %s) is not available from any configured src.\n",
  3482. + pkg->name, pkg->parent->name);
  3483. + return -1;
  3484. + }
  3485. +
  3486. + sprintf_alloc(&url, "%s/%s", pkg->src->value, pkg->filename);
  3487. +
  3488. + /* XXX: BUG: The pkg->filename might be something like
  3489. + "../../foo.ipk". While this is correct, and exactly what we
  3490. + want to use to construct url above, here we actually need to
  3491. + use just the filename part, without any directory. */
  3492. + sprintf_alloc(&pkg->local_filename, "%s/%s", dir, pkg->filename);
  3493. +
  3494. + err = ipkg_download(conf, url, pkg->local_filename);
  3495. + free(url);
  3496. +
  3497. + return err;
  3498. +}
  3499. +
  3500. +/*
  3501. + * Downloads file from url, installs in package database, return package name.
  3502. + */
  3503. +int ipkg_prepare_url_for_install(ipkg_conf_t *conf, const char *url, char **namep)
  3504. +{
  3505. + int err = 0;
  3506. + pkg_t *pkg;
  3507. + pkg = pkg_new();
  3508. + if (pkg == NULL)
  3509. + return ENOMEM;
  3510. +
  3511. + if (str_starts_with(url, "http://")
  3512. + || str_starts_with(url, "ftp://")) {
  3513. + char *tmp_file;
  3514. + char *file_basec = strdup(url);
  3515. + char *file_base = bb_basename(file_basec);
  3516. +
  3517. + sprintf_alloc(&tmp_file, "%s/%s", conf->tmp_dir, file_base);
  3518. + err = ipkg_download(conf, url, tmp_file);
  3519. + if (err)
  3520. + return err;
  3521. +
  3522. + err = pkg_init_from_file(pkg, tmp_file);
  3523. + if (err)
  3524. + return err;
  3525. + pkg->local_filename = strdup(tmp_file);
  3526. +
  3527. + free(tmp_file);
  3528. + free(file_basec);
  3529. +
  3530. + } else if (strcmp(&url[strlen(url) - 4], IPKG_PKG_EXTENSION) == 0
  3531. + || strcmp(&url[strlen(url) - 4], DPKG_PKG_EXTENSION) == 0) {
  3532. +
  3533. + err = pkg_init_from_file(pkg, url);
  3534. + if (err)
  3535. + return err;
  3536. + pkg->local_filename = strdup(url);
  3537. + ipkg_message(conf, IPKG_DEBUG2, "Package %s provided by hand (%s).\n", pkg->name,pkg->local_filename);
  3538. + pkg->provided_by_hand = 1;
  3539. +
  3540. + } else {
  3541. + pkg_deinit(pkg);
  3542. + free(pkg);
  3543. + return 0;
  3544. + }
  3545. +
  3546. + if (!pkg->architecture) {
  3547. + ipkg_message(conf, IPKG_ERROR, "Package %s has no Architecture defined.\n", pkg->name);
  3548. + return -EINVAL;
  3549. + }
  3550. +
  3551. + pkg->dest = conf->default_dest;
  3552. + pkg->state_want = SW_INSTALL;
  3553. + pkg->state_flag |= SF_PREFER;
  3554. + pkg = hash_insert_pkg(&conf->pkg_hash, pkg, 1,conf);
  3555. + if ( pkg == NULL ){
  3556. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  3557. + return 0;
  3558. + }
  3559. + if (namep) {
  3560. + *namep = strdup(pkg->name);
  3561. + }
  3562. + return 0;
  3563. +}
  3564. diff -Nur busybox-1.21.1.orig/archival/libipkg/ipkg_download.h busybox-1.21.1/archival/libipkg/ipkg_download.h
  3565. --- busybox-1.21.1.orig/archival/libipkg/ipkg_download.h 1970-01-01 01:00:00.000000000 +0100
  3566. +++ busybox-1.21.1/archival/libipkg/ipkg_download.h 2014-02-17 14:25:39.858534188 +0100
  3567. @@ -0,0 +1,30 @@
  3568. +/* ipkg_download.h - the itsy package management system
  3569. +
  3570. + Carl D. Worth
  3571. +
  3572. + Copyright (C) 2001 University of Southern California
  3573. +
  3574. + This program is free software; you can redistribute it and/or
  3575. + modify it under the terms of the GNU General Public License as
  3576. + published by the Free Software Foundation; either version 2, or (at
  3577. + your option) any later version.
  3578. +
  3579. + This program is distributed in the hope that it will be useful, but
  3580. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3581. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3582. + General Public License for more details.
  3583. +*/
  3584. +
  3585. +#ifndef IPKG_DOWNLOAD_H
  3586. +#define IPKG_DOWNLOAD_H
  3587. +
  3588. +#include "ipkg_conf.h"
  3589. +
  3590. +int ipkg_download(ipkg_conf_t *conf, const char *src, const char *dest_file_name);
  3591. +int ipkg_download_pkg(ipkg_conf_t *conf, pkg_t *pkg, const char *dir);
  3592. +/*
  3593. + * Downloads file from url, installs in package database, return package name.
  3594. + */
  3595. +int ipkg_prepare_url_for_install(ipkg_conf_t *conf, const char *url, char **namep);
  3596. +
  3597. +#endif
  3598. diff -Nur busybox-1.21.1.orig/archival/libipkg/ipkg.h busybox-1.21.1/archival/libipkg/ipkg.h
  3599. --- busybox-1.21.1.orig/archival/libipkg/ipkg.h 1970-01-01 01:00:00.000000000 +0100
  3600. +++ busybox-1.21.1/archival/libipkg/ipkg.h 2014-02-17 14:25:39.858534188 +0100
  3601. @@ -0,0 +1,68 @@
  3602. +/* ipkg.h - the itsy package management system
  3603. +
  3604. + Carl D. Worth
  3605. +
  3606. + Copyright (C) 2001 University of Southern California
  3607. +
  3608. + This program is free software; you can redistribute it and/or
  3609. + modify it under the terms of the GNU General Public License as
  3610. + published by the Free Software Foundation; either version 2, or (at
  3611. + your option) any later version.
  3612. +
  3613. + This program is distributed in the hope that it will be useful, but
  3614. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3615. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3616. + General Public License for more details.
  3617. +*/
  3618. +
  3619. +#ifndef IPKG_H
  3620. +#define IPKG_H
  3621. +
  3622. +#include "libbb.h"
  3623. +
  3624. +#include "ipkg_includes.h"
  3625. +#include "ipkg_conf.h"
  3626. +#include "ipkg_message.h"
  3627. +
  3628. +#define IPKG_PKG_EXTENSION ".ipk"
  3629. +#define DPKG_PKG_EXTENSION ".deb"
  3630. +
  3631. +#define IPKG_LEGAL_PKG_NAME_CHARS "abcdefghijklmnopqrstuvwxyz0123456789.+-"
  3632. +#define IPKG_PKG_VERSION_SEP_CHAR '_'
  3633. +
  3634. +#define IPKG_STATE_DIR_PREFIX IPKGLIBDIR"/ipkg"
  3635. +#define IPKG_LISTS_DIR_SUFFIX "lists"
  3636. +#define IPKG_INFO_DIR_SUFFIX "info"
  3637. +#define IPKG_STATUS_FILE_SUFFIX "status"
  3638. +
  3639. +#define IPKG_BACKUP_SUFFIX "-ipkg.backup"
  3640. +
  3641. +#define IPKG_LIST_DESCRIPTION_LENGTH 128
  3642. +
  3643. +#define IPKG_VERSION "1.00"
  3644. +
  3645. +
  3646. +enum ipkg_error {
  3647. + IPKG_SUCCESS = 0,
  3648. + IPKG_PKG_DEPS_UNSATISFIED,
  3649. + IPKG_PKG_IS_ESSENTIAL,
  3650. + IPKG_PKG_HAS_DEPENDENTS,
  3651. + IPKG_PKG_HAS_NO_CANDIDATE
  3652. +};
  3653. +typedef enum ipkg_error ipkg_error_t;
  3654. +
  3655. +extern int ipkg_state_changed;
  3656. +
  3657. +
  3658. +struct errlist {
  3659. + char * errmsg;
  3660. + struct errlist * next;
  3661. +} ;
  3662. +
  3663. +extern struct errlist* error_list;
  3664. +
  3665. +extern ipkg_conf_t *global_conf;
  3666. +
  3667. +typedef enum { HASH_SHA1, HASH_MD5 } hash_algo_t;
  3668. +
  3669. +#endif
  3670. diff -Nur busybox-1.21.1.orig/archival/libipkg/ipkg_includes.h busybox-1.21.1/archival/libipkg/ipkg_includes.h
  3671. --- busybox-1.21.1.orig/archival/libipkg/ipkg_includes.h 1970-01-01 01:00:00.000000000 +0100
  3672. +++ busybox-1.21.1/archival/libipkg/ipkg_includes.h 2014-02-17 14:25:39.858534188 +0100
  3673. @@ -0,0 +1,82 @@
  3674. +#ifndef IPKG_INCLUDES_H
  3675. +#define IPKG_INCLUDES_H
  3676. +
  3677. +/* Define to 1 if you have the <memory.h> header file. */
  3678. +#define HAVE_MEMORY_H 1
  3679. +
  3680. +/* Define to 1 if you have the <regex.h> header file. */
  3681. +#define HAVE_REGEX_H 1
  3682. +
  3683. +/* Define to 1 if you have the <stdlib.h> header file. */
  3684. +#define HAVE_STDLIB_H 1
  3685. +
  3686. +/* Define to 1 if you have the <strings.h> header file. */
  3687. +#define HAVE_STRINGS_H 1
  3688. +
  3689. +/* Define to 1 if you have the <string.h> header file. */
  3690. +#define HAVE_STRING_H 1
  3691. +
  3692. +/* Define to 1 if you have the <sys/stat.h> header file. */
  3693. +#define HAVE_SYS_STAT_H 1
  3694. +
  3695. +/* Define to 1 if you have <sys/wait.h> that is POSIX.1 compatible. */
  3696. +#define HAVE_SYS_WAIT_H 1
  3697. +
  3698. +/* Define to 1 if you have the <unistd.h> header file. */
  3699. +#define HAVE_UNISTD_H 1
  3700. +
  3701. +/* Define to 1 if you have the ANSI C header files. */
  3702. +#define STDC_HEADERS 1
  3703. +
  3704. +
  3705. +#include <stdio.h>
  3706. +
  3707. +#if STDC_HEADERS
  3708. +# include <stdlib.h>
  3709. +# include <stdarg.h>
  3710. +# include <stddef.h>
  3711. +# include <ctype.h>
  3712. +# include <errno.h>
  3713. +#else
  3714. +# if HAVE_STDLIB_H
  3715. +# include <stdlib.h>
  3716. +# endif
  3717. +#endif
  3718. +
  3719. +#if HAVE_REGEX_H
  3720. +# include <regex.h>
  3721. +#endif
  3722. +
  3723. +#if HAVE_STRING_H
  3724. +# if !STDC_HEADERS && HAVE_MEMORY_H
  3725. +# include <memory.h>
  3726. +# endif
  3727. +/* XXX: What's the right way to pick up GNU's strndup declaration? */
  3728. +# if __GNUC__
  3729. +# define __USE_GNU 1
  3730. +# endif
  3731. +# include <string.h>
  3732. +# undef __USE_GNU
  3733. +#endif
  3734. +
  3735. +#if HAVE_STRINGS_H
  3736. +# include <strings.h>
  3737. +#endif
  3738. +
  3739. +#if HAVE_SYS_STAT_H
  3740. +# include <sys/stat.h>
  3741. +#endif
  3742. +
  3743. +#if HAVE_SYS_WAIT_H
  3744. +# include <sys/wait.h>
  3745. +#endif
  3746. +
  3747. +#if HAVE_UNISTD_H
  3748. +# include <sys/types.h>
  3749. +# include <unistd.h>
  3750. +#endif
  3751. +
  3752. +#include <sys/mount.h>
  3753. +#include <mntent.h>
  3754. +
  3755. +#endif /* IPKG_INCLUDES_H */
  3756. diff -Nur busybox-1.21.1.orig/archival/libipkg/ipkg_install.c busybox-1.21.1/archival/libipkg/ipkg_install.c
  3757. --- busybox-1.21.1.orig/archival/libipkg/ipkg_install.c 1970-01-01 01:00:00.000000000 +0100
  3758. +++ busybox-1.21.1/archival/libipkg/ipkg_install.c 2014-02-17 14:25:39.858534188 +0100
  3759. @@ -0,0 +1,1982 @@
  3760. +/* ipkg_install.c - the itsy package management system
  3761. +
  3762. + Carl D. Worth
  3763. +
  3764. + Copyright (C) 2001 University of Southern California
  3765. +
  3766. + This program is free software; you can redistribute it and/or
  3767. + modify it under the terms of the GNU General Public License as
  3768. + published by the Free Software Foundation; either version 2, or (at
  3769. + your option) any later version.
  3770. +
  3771. + This program is distributed in the hope that it will be useful, but
  3772. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3773. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3774. + General Public License for more details.
  3775. +*/
  3776. +
  3777. +#include "ipkg.h"
  3778. +#include <errno.h>
  3779. +#include <dirent.h>
  3780. +#include <glob.h>
  3781. +#include <time.h>
  3782. +#include <signal.h>
  3783. +typedef void (*sighandler_t)(int);
  3784. +
  3785. +#include "pkg.h"
  3786. +#include "pkg_hash.h"
  3787. +#include "pkg_extract.h"
  3788. +
  3789. +#include "ipkg_install.h"
  3790. +#include "ipkg_configure.h"
  3791. +#include "ipkg_download.h"
  3792. +#include "ipkg_remove.h"
  3793. +
  3794. +#include "ipkg_utils.h"
  3795. +#include "ipkg_message.h"
  3796. +
  3797. +#include "sprintf_alloc.h"
  3798. +#include "file_util.h"
  3799. +#include "str_util.h"
  3800. +#include "xsystem.h"
  3801. +#include "user.h"
  3802. +
  3803. +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg);
  3804. +static int verify_pkg_installable(ipkg_conf_t *conf, pkg_t *pkg);
  3805. +static int unpack_pkg_control_files(ipkg_conf_t *conf, pkg_t *pkg);
  3806. +
  3807. +/*
  3808. +static int prerm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3809. +static int prerm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3810. +static int prerm_deconfigure_conflictors(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors);
  3811. +static int prerm_deconfigure_conflictors_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors);
  3812. +static int preinst_configure_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3813. +static int check_data_file_clashes_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3814. +static int postrm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3815. +static int remove_disappeared(ipkg_conf_t *conf, pkg_t *pkg);
  3816. +static int postrm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3817. +*/
  3818. +static int preinst_configure(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3819. +static int check_data_file_clashes(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3820. +static int check_data_file_clashes_change(ipkg_conf_t *conf, pkg_t *pkg);
  3821. +static int backup_modified_conffiles(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3822. +static int backup_modified_conffiles_unwind(pkg_t *pkg, pkg_t *old_pkg);
  3823. +
  3824. +static int remove_obsolesced_files(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3825. +static int install_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3826. +static int install_data_files(ipkg_conf_t *conf, pkg_t *pkg);
  3827. +static int resolve_conffiles(ipkg_conf_t *conf, pkg_t *pkg);
  3828. +
  3829. +static int cleanup_temporary_files(ipkg_conf_t *conf, pkg_t *pkg);
  3830. +
  3831. +static int user_prefers_old_conffile(const char *file, const char *backup);
  3832. +
  3833. +static char *backup_filename_alloc(const char *file_name);
  3834. +static int backup_make_backup(ipkg_conf_t *conf, const char *file_name);
  3835. +static int backup_exists_for(const char *file_name);
  3836. +static int backup_remove(const char *file_name);
  3837. +
  3838. +int pkg_get_installed_replacees(pkg_t *pkg, pkg_vec_t *installed_replacees);
  3839. +int pkg_remove_installed_replacees(ipkg_conf_t *conf, pkg_vec_t *replacees);
  3840. +int pkg_remove_installed_replacees_unwind(ipkg_conf_t *conf, pkg_vec_t *replacees);
  3841. +
  3842. +int ipkg_install_from_file(ipkg_conf_t *conf, const char *filename)
  3843. +{
  3844. + int err, cmp;
  3845. + pkg_t *pkg, *old;
  3846. + char *old_version, *new_version;
  3847. +
  3848. + pkg = pkg_new();
  3849. + if (pkg == NULL) {
  3850. + return ENOMEM;
  3851. + }
  3852. +
  3853. + err = pkg_init_from_file(pkg, filename);
  3854. + if (err) {
  3855. + return err;
  3856. + }
  3857. +
  3858. + if (!pkg->architecture) {
  3859. + ipkg_message(conf, IPKG_ERROR, "Package %s has no Architecture defined.\n", pkg->name);
  3860. + return -EINVAL;
  3861. + }
  3862. +
  3863. + /* XXX: CLEANUP: hash_insert_pkg has a nasty side effect of possibly
  3864. + freeing the pkg that we pass in. It might be nice to clean this up
  3865. + if possible. */
  3866. + pkg = hash_insert_pkg(&conf->pkg_hash, pkg, 1,conf);
  3867. + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name);
  3868. +
  3869. + pkg->local_filename = strdup(filename);
  3870. +
  3871. + if (old) {
  3872. + old_version = pkg_version_str_alloc(old);
  3873. + new_version = pkg_version_str_alloc(pkg);
  3874. +
  3875. + cmp = pkg_compare_versions(old, pkg);
  3876. + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
  3877. + cmp = -1 ; /* then we force ipkg to downgrade */
  3878. + /* We need to use a value < 0 because in the 0 case we are asking to */
  3879. + /* reinstall, and some check could fail asking the "force-reinstall" option */
  3880. + }
  3881. + if (cmp > 0) {
  3882. + ipkg_message(conf, IPKG_NOTICE,
  3883. + "Not downgrading package %s on %s from %s to %s.\n",
  3884. + old->name, old->dest->name, old_version, new_version);
  3885. + pkg->state_want = SW_DEINSTALL;
  3886. + pkg->state_flag |= SF_OBSOLETE;
  3887. + free(old_version);
  3888. + free(new_version);
  3889. + return 0;
  3890. + } else {
  3891. + free(old_version);
  3892. + free(new_version);
  3893. + }
  3894. + }
  3895. +
  3896. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
  3897. + return ipkg_install_pkg(conf, pkg,0);
  3898. +}
  3899. +
  3900. +ipkg_error_t ipkg_install_by_name(ipkg_conf_t *conf, const char *pkg_name)
  3901. +{
  3902. + int cmp;
  3903. + pkg_t *old, *new;
  3904. + char *old_version, *new_version;
  3905. +
  3906. + ipkg_message(conf, IPKG_DEBUG2, " Getting old from pkg_hash_fetch \n" );
  3907. + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg_name);
  3908. + if ( old )
  3909. + ipkg_message(conf, IPKG_DEBUG2, " Old versions from pkg_hash_fetch %s \n", old->version );
  3910. +
  3911. + ipkg_message(conf, IPKG_DEBUG2, " Getting new from pkg_hash_fetch \n" );
  3912. + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, pkg_name);
  3913. + if ( new )
  3914. + ipkg_message(conf, IPKG_DEBUG2, " New versions from pkg_hash_fetch %s \n", new->version );
  3915. +
  3916. +/* Pigi Basically here is broken the version stuff.
  3917. + What's happening is that nothing provide the version to differents
  3918. + functions, so the returned struct is always the latest.
  3919. + That's why the install by name don't work.
  3920. +*/
  3921. + ipkg_message(conf, IPKG_DEBUG2, " Versions from pkg_hash_fetch in %s ", __FUNCTION__ );
  3922. +
  3923. + if ( old )
  3924. + ipkg_message(conf, IPKG_DEBUG2, " old %s ", old->version );
  3925. + if ( new )
  3926. + ipkg_message(conf, IPKG_DEBUG2, " new %s ", new->version );
  3927. + ipkg_message(conf, IPKG_DEBUG2, " \n");
  3928. +
  3929. + if (new == NULL) {
  3930. + return IPKG_PKG_HAS_NO_CANDIDATE;
  3931. + }
  3932. +
  3933. + new->state_flag |= SF_USER;
  3934. + if (old) {
  3935. + old_version = pkg_version_str_alloc(old);
  3936. + new_version = pkg_version_str_alloc(new);
  3937. +
  3938. + cmp = pkg_compare_versions(old, new);
  3939. + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
  3940. + ipkg_message(conf, IPKG_DEBUG, " Forcing downgrade \n");
  3941. + cmp = -1 ; /* then we force ipkg to downgrade */
  3942. + /* We need to use a value < 0 because in the 0 case we are asking to */
  3943. + /* reinstall, and some check could fail asking the "force-reinstall" option */
  3944. + }
  3945. + ipkg_message(conf, IPKG_DEBUG,
  3946. + "Comparing visible versions of pkg %s:"
  3947. + "\n\t%s is installed "
  3948. + "\n\t%s is available "
  3949. + "\n\t%d was comparison result\n",
  3950. + pkg_name, old_version, new_version, cmp);
  3951. + if (cmp == 0 && !conf->force_reinstall) {
  3952. + ipkg_message(conf, IPKG_NOTICE,
  3953. + "Package %s (%s) installed in %s is up to date.\n",
  3954. + old->name, old_version, old->dest->name);
  3955. + free(old_version);
  3956. + free(new_version);
  3957. + return 0;
  3958. + } else if (cmp > 0) {
  3959. + ipkg_message(conf, IPKG_NOTICE,
  3960. + "Not downgrading package %s on %s from %s to %s.\n",
  3961. + old->name, old->dest->name, old_version, new_version);
  3962. + free(old_version);
  3963. + free(new_version);
  3964. + return 0;
  3965. + } else if (cmp < 0) {
  3966. + new->dest = old->dest;
  3967. + old->state_want = SW_DEINSTALL; /* Here probably the problem for bug 1277 */
  3968. + }
  3969. + }
  3970. +
  3971. + /* XXX: CLEANUP: The error code of ipkg_install_by_name is really
  3972. + supposed to be an ipkg_error_t, but ipkg_install_pkg could
  3973. + return any kind of integer, (might be errno from a syscall,
  3974. + etc.). This is a real mess and will need to be cleaned up if
  3975. + anyone ever wants to make a nice libipkg. */
  3976. +
  3977. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
  3978. + return ipkg_install_pkg(conf, new,0);
  3979. +}
  3980. +
  3981. +ipkg_error_t ipkg_install_multi_by_name(ipkg_conf_t *conf, const char *pkg_name)
  3982. +{
  3983. + abstract_pkg_vec_t *providers = pkg_hash_fetch_all_installation_candidates (&conf->pkg_hash, pkg_name);
  3984. + int i;
  3985. + ipkg_error_t err;
  3986. + abstract_pkg_t *ppkg ;
  3987. +
  3988. + if (providers == NULL)
  3989. + return IPKG_PKG_HAS_NO_CANDIDATE;
  3990. +
  3991. + for (i = 0; i < providers->len; i++) {
  3992. + ppkg = abstract_pkg_vec_get(providers, i);
  3993. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_by_name %d \n",__FUNCTION__, i);
  3994. + err = ipkg_install_by_name(conf, ppkg->name);
  3995. + if (err)
  3996. + return err;
  3997. +/* XXX Maybe ppkg should be freed ? */
  3998. + }
  3999. + return 0;
  4000. +}
  4001. +
  4002. +/*
  4003. + * Walk dependence graph starting with pkg, collect packages to be
  4004. + * installed into pkgs_needed, in dependence order.
  4005. + */
  4006. +int pkg_mark_dependencies_for_installation(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *pkgs_needed)
  4007. +{
  4008. + int i, err;
  4009. + pkg_vec_t *depends = pkg_vec_alloc();
  4010. + char **unresolved = NULL;
  4011. + int ndepends;
  4012. +
  4013. + ndepends = pkg_hash_fetch_unsatisfied_dependencies(conf,
  4014. + pkg, depends,
  4015. + &unresolved);
  4016. +
  4017. + if (unresolved) {
  4018. + ipkg_message(conf, IPKG_ERROR,
  4019. + "%s: Cannot satisfy the following dependencies for %s:\n\t",
  4020. + conf->force_depends ? "Warning" : "ERROR", pkg->name);
  4021. + while (*unresolved) {
  4022. + ipkg_message(conf, IPKG_ERROR, " %s", *unresolved);
  4023. + unresolved++;
  4024. + }
  4025. + ipkg_message(conf, IPKG_ERROR, "\n");
  4026. + if (! conf->force_depends) {
  4027. + ipkg_message(conf, IPKG_INFO,
  4028. + "This could mean that your package list is out of date or that the packages\n"
  4029. + "mentioned above do not yet exist (try 'ipkg update'). To proceed in spite\n"
  4030. + "of this problem try again with the '-force-depends' option.\n");
  4031. + pkg_vec_free(depends);
  4032. + return IPKG_PKG_DEPS_UNSATISFIED;
  4033. + }
  4034. + }
  4035. +
  4036. + if (ndepends <= 0) {
  4037. + pkg_vec_free(depends);
  4038. + return 0;
  4039. + }
  4040. +
  4041. + for (i = 0; i < depends->len; i++) {
  4042. + pkg_t *dep = depends->pkgs[i];
  4043. + /* The package was uninstalled when we started, but another
  4044. + dep earlier in this loop may have depended on it and pulled
  4045. + it in, so check first. */
  4046. + if ((dep->state_status != SS_INSTALLED)
  4047. + && (dep->state_status != SS_UNPACKED)
  4048. + && (dep->state_want != SW_INSTALL)) {
  4049. +
  4050. + /* Mark packages as to-be-installed */
  4051. + dep->state_want = SW_INSTALL;
  4052. +
  4053. + /* Dependencies should be installed the same place as pkg */
  4054. + if (dep->dest == NULL) {
  4055. + dep->dest = pkg->dest;
  4056. + }
  4057. +
  4058. + err = pkg_mark_dependencies_for_installation(conf, dep, pkgs_needed);
  4059. + if (err) {
  4060. + pkg_vec_free(depends);
  4061. + return err;
  4062. + }
  4063. + }
  4064. + }
  4065. + if (pkgs_needed)
  4066. + pkg_vec_insert(pkgs_needed, pkg);
  4067. +
  4068. + pkg_vec_free(depends);
  4069. +
  4070. + return 0;
  4071. +}
  4072. +
  4073. +int name_mark_dependencies_for_installation(ipkg_conf_t *conf, const char *pkg_name, pkg_vec_t *pkgs_needed)
  4074. +{
  4075. + int cmp;
  4076. + pkg_t *old, *new;
  4077. + char *old_version, *new_version;
  4078. +
  4079. + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg_name);
  4080. +
  4081. + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, pkg_name);
  4082. + if (new == NULL) {
  4083. + return IPKG_PKG_HAS_NO_CANDIDATE;
  4084. + }
  4085. + if (old) {
  4086. + old_version = pkg_version_str_alloc(old);
  4087. + new_version = pkg_version_str_alloc(new);
  4088. +
  4089. + cmp = pkg_compare_versions(old, new);
  4090. + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
  4091. + ipkg_message(conf, IPKG_DEBUG, " Forcing downgrade ");
  4092. + cmp = -1 ; /* then we force ipkg to downgrade */
  4093. + /* We need to use a value < 0 because in the 0 case we are asking to */
  4094. + /* reinstall, and some check could fail asking the "force-reinstall" option */
  4095. + }
  4096. + ipkg_message(conf, IPKG_DEBUG,
  4097. + "comparing visible versions of pkg %s:"
  4098. + "\n\t%s is installed "
  4099. + "\n\t%s is available "
  4100. + "\n\t%d was comparison result\n",
  4101. + pkg_name, old_version, new_version, cmp);
  4102. + if (cmp == 0 && !conf->force_reinstall) {
  4103. + ipkg_message(conf, IPKG_NOTICE,
  4104. + "Package %s (%s) installed in %s is up to date.\n",
  4105. + old->name, old_version, old->dest->name);
  4106. + free(old_version);
  4107. + free(new_version);
  4108. + return 0;
  4109. + } else if (cmp > 0) {
  4110. + ipkg_message(conf, IPKG_NOTICE,
  4111. + "Not downgrading package %s on %s from %s to %s.\n",
  4112. + old->name, old->dest->name, old_version, new_version);
  4113. + free(old_version);
  4114. + free(new_version);
  4115. + return 0;
  4116. + } else if (cmp < 0) {
  4117. + new->dest = old->dest;
  4118. + old->state_want = SW_DEINSTALL;
  4119. + old->state_flag |= SF_OBSOLETE;
  4120. + }
  4121. + }
  4122. + return pkg_mark_dependencies_for_installation(conf, new, pkgs_needed);
  4123. +}
  4124. +
  4125. +
  4126. +
  4127. +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg)
  4128. +{
  4129. + int i, err;
  4130. + pkg_vec_t *depends = pkg_vec_alloc();
  4131. + pkg_t *dep;
  4132. + char **unresolved = NULL;
  4133. + int ndepends;
  4134. +
  4135. + ndepends = pkg_hash_fetch_unsatisfied_dependencies(conf,
  4136. + pkg, depends,
  4137. + &unresolved);
  4138. +
  4139. + if (unresolved) {
  4140. + ipkg_message(conf, IPKG_ERROR,
  4141. + "%s: Cannot satisfy the following dependencies for %s:\n\t",
  4142. + conf->force_depends ? "Warning" : "ERROR", pkg->name);
  4143. + while (*unresolved) {
  4144. + ipkg_message(conf, IPKG_ERROR, " %s", *unresolved);
  4145. + unresolved++;
  4146. + }
  4147. + ipkg_message(conf, IPKG_ERROR, "\n");
  4148. + if (! conf->force_depends) {
  4149. + ipkg_message(conf, IPKG_INFO,
  4150. + "This could mean that your package list is out of date or that the packages\n"
  4151. + "mentioned above do not yet exist (try 'ipkg update'). To proceed in spite\n"
  4152. + "of this problem try again with the '-force-depends' option.\n");
  4153. + pkg_vec_free(depends);
  4154. + return IPKG_PKG_DEPS_UNSATISFIED;
  4155. + }
  4156. + }
  4157. +
  4158. + if (ndepends <= 0) {
  4159. + return 0;
  4160. + }
  4161. +
  4162. + /* Mark packages as to-be-installed */
  4163. + for (i=0; i < depends->len; i++) {
  4164. + /* Dependencies should be installed the same place as pkg */
  4165. + if (depends->pkgs[i]->dest == NULL) {
  4166. + depends->pkgs[i]->dest = pkg->dest;
  4167. + }
  4168. + depends->pkgs[i]->state_want = SW_INSTALL;
  4169. + }
  4170. +
  4171. + for (i = 0; i < depends->len; i++) {
  4172. + dep = depends->pkgs[i];
  4173. + /* The package was uninstalled when we started, but another
  4174. + dep earlier in this loop may have depended on it and pulled
  4175. + it in, so check first. */
  4176. + if ((dep->state_status != SS_INSTALLED)
  4177. + && (dep->state_status != SS_UNPACKED)) {
  4178. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
  4179. + err = ipkg_install_pkg(conf, dep,0);
  4180. + if (err) {
  4181. + pkg_vec_free(depends);
  4182. + return err;
  4183. + }
  4184. + }
  4185. + }
  4186. +
  4187. + pkg_vec_free(depends);
  4188. +
  4189. + return 0;
  4190. +}
  4191. +
  4192. +
  4193. +/* check all packages have their dependences satisfied, e.g., in case an upgraded package split */
  4194. +int ipkg_satisfy_all_dependences(ipkg_conf_t *conf)
  4195. +{
  4196. + if (conf->nodeps == 0) {
  4197. + int i;
  4198. + pkg_vec_t *installed = pkg_vec_alloc();
  4199. + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
  4200. + for (i = 0; i < installed->len; i++) {
  4201. + pkg_t *pkg = installed->pkgs[i];
  4202. + satisfy_dependencies_for(conf, pkg);
  4203. + }
  4204. + pkg_vec_free(installed);
  4205. + }
  4206. + return 0;
  4207. +}
  4208. +
  4209. +
  4210. +
  4211. +static int check_conflicts_for(ipkg_conf_t *conf, pkg_t *pkg)
  4212. +{
  4213. + int i;
  4214. + pkg_vec_t *conflicts = NULL;
  4215. + int level;
  4216. + const char *prefix;
  4217. + if (conf->force_depends) {
  4218. + level = IPKG_NOTICE;
  4219. + prefix = "Warning";
  4220. + } else {
  4221. + level = IPKG_ERROR;
  4222. + prefix = "ERROR";
  4223. + }
  4224. +
  4225. + if (!conf->force_depends)
  4226. + conflicts = (pkg_vec_t *)pkg_hash_fetch_conflicts(pkg);
  4227. +
  4228. + if (conflicts) {
  4229. + ipkg_message(conf, level,
  4230. + "%s: The following packages conflict with %s:\n\t", prefix, pkg->name);
  4231. + i = 0;
  4232. + while (i < conflicts->len)
  4233. + ipkg_message(conf, level, " %s", conflicts->pkgs[i++]->name);
  4234. + ipkg_message(conf, level, "\n");
  4235. + pkg_vec_free(conflicts);
  4236. + return IPKG_PKG_DEPS_UNSATISFIED;
  4237. + }
  4238. + return 0;
  4239. +}
  4240. +
  4241. +static int update_file_ownership(ipkg_conf_t *conf, pkg_t *new_pkg, pkg_t *old_pkg)
  4242. +{
  4243. + str_list_t *new_list = pkg_get_installed_files(new_pkg);
  4244. + str_list_elt_t *iter;
  4245. +
  4246. + for (iter = new_list->head; iter; iter = iter->next) {
  4247. + char *new_file = iter->data;
  4248. + pkg_t *owner = file_hash_get_file_owner(conf, new_file);
  4249. + if (!new_file)
  4250. + ipkg_message(conf, IPKG_ERROR, "Null new_file for new_pkg=%s\n", new_pkg->name);
  4251. + if (!owner || (owner == old_pkg))
  4252. + file_hash_set_file_owner(conf, new_file, new_pkg);
  4253. + }
  4254. + if (old_pkg) {
  4255. + str_list_t *old_list = pkg_get_installed_files(old_pkg);
  4256. + for (iter = old_list->head; iter; iter = iter->next) {
  4257. + char *old_file = iter->data;
  4258. + pkg_t *owner = file_hash_get_file_owner(conf, old_file);
  4259. + if (owner == old_pkg) {
  4260. + /* obsolete */
  4261. + hash_table_insert(&conf->obs_file_hash, old_file, old_pkg);
  4262. + }
  4263. + }
  4264. + }
  4265. + return 0;
  4266. +}
  4267. +
  4268. +static int verify_pkg_installable(ipkg_conf_t *conf, pkg_t *pkg)
  4269. +{
  4270. + /* XXX: FEATURE: Anything else needed here? Maybe a check on free space? */
  4271. +
  4272. + /* sma 6.20.02: yup; here's the first bit */
  4273. + /*
  4274. + * XXX: BUG easy for cworth
  4275. + * 1) please point the call below to the correct current root destination
  4276. + * 2) we need to resolve how to check the required space for a pending pkg,
  4277. + * my diddling with the .ipk file size below isn't going to cut it.
  4278. + * 3) return a proper error code instead of 1
  4279. + */
  4280. + int comp_size, blocks_available;
  4281. +
  4282. + if (!conf->force_space && pkg->installed_size != NULL) {
  4283. + blocks_available = get_available_blocks(conf->default_dest->root_dir);
  4284. +
  4285. + comp_size = strtoul(pkg->installed_size, NULL, 0);
  4286. + /* round up a blocks count without doing fancy-but-slow casting jazz */
  4287. + comp_size = (int)((comp_size + 1023) / 1024);
  4288. +
  4289. + if (comp_size >= blocks_available) {
  4290. + ipkg_message(conf, IPKG_ERROR,
  4291. + "Only have %d available blocks on filesystem %s, pkg %s needs %d\n",
  4292. + blocks_available, conf->default_dest->root_dir, pkg->name, comp_size);
  4293. + return ENOSPC;
  4294. + }
  4295. + }
  4296. + return 0;
  4297. +}
  4298. +
  4299. +static int unpack_pkg_control_files(ipkg_conf_t *conf, pkg_t *pkg)
  4300. +{
  4301. + int err;
  4302. + char *conffiles_file_name;
  4303. + char *root_dir;
  4304. + FILE *conffiles_file;
  4305. +
  4306. + sprintf_alloc(&pkg->tmp_unpack_dir, "%s/%s-XXXXXX", conf->tmp_dir, pkg->name);
  4307. +
  4308. + pkg->tmp_unpack_dir = mkdtemp(pkg->tmp_unpack_dir);
  4309. + if (pkg->tmp_unpack_dir == NULL) {
  4310. + ipkg_message(conf, IPKG_ERROR,
  4311. + "%s: Failed to create temporary directory '%s': %s\n",
  4312. + __FUNCTION__, pkg->tmp_unpack_dir, strerror(errno));
  4313. + return errno;
  4314. + }
  4315. +
  4316. + err = pkg_extract_control_files_to_dir(pkg, pkg->tmp_unpack_dir);
  4317. + if (err) {
  4318. + return err;
  4319. + }
  4320. +
  4321. + /* XXX: CLEANUP: There might be a cleaner place to read in the
  4322. + conffiles. Seems like I should be able to get everything to go
  4323. + through pkg_init_from_file. If so, maybe it would make sense to
  4324. + move all of unpack_pkg_control_files to that function. */
  4325. +
  4326. + /* Don't need to re-read conffiles if we already have it */
  4327. + if (pkg->conffiles.head) {
  4328. + return 0;
  4329. + }
  4330. +
  4331. + sprintf_alloc(&conffiles_file_name, "%s/conffiles", pkg->tmp_unpack_dir);
  4332. + if (! file_exists(conffiles_file_name)) {
  4333. + free(conffiles_file_name);
  4334. + return 0;
  4335. + }
  4336. +
  4337. + conffiles_file = fopen(conffiles_file_name, "r");
  4338. + if (conffiles_file == NULL) {
  4339. + fprintf(stderr, "%s: failed to open %s: %s\n",
  4340. + __FUNCTION__, conffiles_file_name, strerror(errno));
  4341. + free(conffiles_file_name);
  4342. + return errno;
  4343. + }
  4344. + free(conffiles_file_name);
  4345. +
  4346. + while (1) {
  4347. + char *cf_name;
  4348. + char *cf_name_in_dest;
  4349. +
  4350. + cf_name = file_read_line_alloc(conffiles_file);
  4351. + if (cf_name == NULL) {
  4352. + break;
  4353. + }
  4354. + str_chomp(cf_name);
  4355. + if (cf_name[0] == '\0') {
  4356. + continue;
  4357. + }
  4358. +
  4359. + /* Prepend dest->root_dir to conffile name.
  4360. + Take pains to avoid multiple slashes. */
  4361. + root_dir = pkg->dest->root_dir;
  4362. + if (conf->offline_root)
  4363. + /* skip the offline_root prefix */
  4364. + root_dir = pkg->dest->root_dir + strlen(conf->offline_root);
  4365. + sprintf_alloc(&cf_name_in_dest, "%s%s", root_dir,
  4366. + cf_name[0] == '/' ? (cf_name + 1) : cf_name);
  4367. +
  4368. + /* Can't get an md5sum now, (file isn't extracted yet).
  4369. + We'll wait until resolve_conffiles */
  4370. + conffile_list_append(&pkg->conffiles, cf_name_in_dest, NULL);
  4371. +
  4372. + free(cf_name);
  4373. + free(cf_name_in_dest);
  4374. + }
  4375. +
  4376. + fclose(conffiles_file);
  4377. +
  4378. + return 0;
  4379. +}
  4380. +
  4381. +/* returns number of installed replacees */
  4382. +int pkg_get_installed_replacees(pkg_t *pkg, pkg_vec_t *installed_replacees)
  4383. +{
  4384. + abstract_pkg_t **replaces = pkg->replaces;
  4385. + int replaces_count = pkg->replaces_count;
  4386. + int i, j;
  4387. + for (i = 0; i < replaces_count; i++) {
  4388. + abstract_pkg_t *ab_pkg = replaces[i];
  4389. + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
  4390. + if (pkg_vec) {
  4391. + for (j = 0; j < pkg_vec->len; j++) {
  4392. + pkg_t *replacee = pkg_vec->pkgs[j];
  4393. + if (!pkg_conflicts(pkg, replacee))
  4394. + continue;
  4395. + if (replacee->state_status == SS_INSTALLED) {
  4396. + pkg_vec_insert(installed_replacees, replacee);
  4397. + }
  4398. + }
  4399. + }
  4400. + }
  4401. + return installed_replacees->len;
  4402. +}
  4403. +
  4404. +int pkg_remove_installed_replacees(ipkg_conf_t *conf, pkg_vec_t *replacees)
  4405. +{
  4406. + int i;
  4407. + int replaces_count = replacees->len;
  4408. + for (i = 0; i < replaces_count; i++) {
  4409. + pkg_t *replacee = replacees->pkgs[i];
  4410. + int err;
  4411. + replacee->state_flag |= SF_REPLACE; /* flag it so remove won't complain */
  4412. + err = ipkg_remove_pkg(conf, replacee,0);
  4413. + if (err)
  4414. + return err;
  4415. + }
  4416. + return 0;
  4417. +}
  4418. +
  4419. +/* to unwind the removal: make sure they are installed */
  4420. +int pkg_remove_installed_replacees_unwind(ipkg_conf_t *conf, pkg_vec_t *replacees)
  4421. +{
  4422. + int i, err;
  4423. + int replaces_count = replacees->len;
  4424. + for (i = 0; i < replaces_count; i++) {
  4425. + pkg_t *replacee = replacees->pkgs[i];
  4426. + if (replacee->state_status != SS_INSTALLED) {
  4427. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
  4428. + err = ipkg_install_pkg(conf, replacee,0);
  4429. + if (err)
  4430. + return err;
  4431. + }
  4432. + }
  4433. + return 0;
  4434. +}
  4435. +
  4436. +int caught_sigint = 0;
  4437. +static void ipkg_install_pkg_sigint_handler(int sig)
  4438. +{
  4439. + caught_sigint = sig;
  4440. +}
  4441. +
  4442. +/* compares versions of pkg and old_pkg, returns 0 if OK to proceed with installation of pkg, 1 otherwise */
  4443. +static int ipkg_install_check_downgrade(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg, int message)
  4444. +{
  4445. + if (old_pkg) {
  4446. + char message_out[15];
  4447. + char *old_version = pkg_version_str_alloc(old_pkg);
  4448. + char *new_version = pkg_version_str_alloc(pkg);
  4449. + int cmp = pkg_compare_versions(old_pkg, pkg);
  4450. + int rc = 0;
  4451. +
  4452. + memset(message_out,'\x0',15);
  4453. + strncpy (message_out,"Upgrading ",strlen("Upgrading "));
  4454. + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
  4455. + cmp = -1 ; /* then we force ipkg to downgrade */
  4456. + strncpy (message_out,"Downgrading ",strlen("Downgrading ")); /* We need to use a value < 0 because in the 0 case we are asking to */
  4457. + /* reinstall, and some check could fail asking the "force-reinstall" option */
  4458. + }
  4459. +
  4460. + if (cmp > 0) {
  4461. + ipkg_message(conf, IPKG_NOTICE,
  4462. + "Not downgrading package %s on %s from %s to %s.\n",
  4463. + old_pkg->name, old_pkg->dest->name, old_version, new_version);
  4464. + rc = 1;
  4465. + } else if (cmp < 0) {
  4466. + ipkg_message(conf, IPKG_NOTICE,
  4467. + "%s%s on %s from %s to %s...\n",
  4468. + message_out, pkg->name, old_pkg->dest->name, old_version, new_version);
  4469. + pkg->dest = old_pkg->dest;
  4470. + rc = 0;
  4471. + } else /* cmp == 0 */ {
  4472. + if (conf->force_reinstall) {
  4473. + ipkg_message(conf, IPKG_NOTICE,
  4474. + "Reinstalling %s (%s) on %s...\n",
  4475. + pkg->name, new_version, old_pkg->dest->name);
  4476. + pkg->dest = old_pkg->dest;
  4477. + rc = 0;
  4478. + } else {
  4479. + ipkg_message(conf, IPKG_NOTICE,
  4480. + "Not installing %s (%s) on %s -- already installed.\n",
  4481. + pkg->name, new_version, old_pkg->dest->name);
  4482. + rc = 1;
  4483. + }
  4484. + }
  4485. + free(old_version);
  4486. + free(new_version);
  4487. + return rc;
  4488. + } else {
  4489. + char message_out[15], *version ;
  4490. + memset(message_out,'\x0',15);
  4491. + if ( message )
  4492. + strncpy( message_out,"Upgrading ",strlen("Upgrading ") );
  4493. + else
  4494. + strncpy( message_out,"Installing ",strlen("Installing ") );
  4495. + version = pkg_version_str_alloc(pkg);
  4496. +
  4497. + ipkg_message(conf, IPKG_NOTICE,
  4498. + "%s%s (%s) to %s...\n", message_out,
  4499. + pkg->name, version, pkg->dest->name);
  4500. + free(version);
  4501. + return 0;
  4502. + }
  4503. +}
  4504. +
  4505. +/* and now the meat... */
  4506. +int ipkg_install_pkg(ipkg_conf_t *conf, pkg_t *pkg, int from_upgrade)
  4507. +{
  4508. + int err = 0;
  4509. + int message = 0;
  4510. + pkg_t *old_pkg = NULL;
  4511. + pkg_vec_t *replacees;
  4512. + abstract_pkg_t *ab_pkg = NULL;
  4513. + int old_state_flag;
  4514. + uint8_t *file_md5;
  4515. +
  4516. +
  4517. + if ( from_upgrade )
  4518. + message = 1; /* Coming from an upgrade, and should change the output message */
  4519. +
  4520. + if (!pkg) {
  4521. + ipkg_message(conf, IPKG_ERROR,
  4522. + "INTERNAL ERROR: null pkg passed to ipkg_install_pkg\n");
  4523. + return -EINVAL;
  4524. + }
  4525. +
  4526. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s calling pkg_arch_supported %s \n", __FUNCTION__, __FUNCTION__);
  4527. +
  4528. + if (!pkg_arch_supported(conf, pkg)) {
  4529. + ipkg_message(conf, IPKG_ERROR, "INTERNAL ERROR: architecture %s for pkg %s is unsupported.\n",
  4530. + pkg->architecture, pkg->name);
  4531. + return -EINVAL;
  4532. + }
  4533. + if (pkg->state_status == SS_INSTALLED && conf->force_reinstall == 0 && conf->nodeps == 0) {
  4534. + err = satisfy_dependencies_for(conf, pkg);
  4535. + if (err) { return err; }
  4536. +
  4537. + ipkg_message(conf, IPKG_NOTICE,
  4538. + "Package %s is already installed in %s.\n",
  4539. + pkg->name, pkg->dest->name);
  4540. + return 0;
  4541. + }
  4542. +
  4543. + if (pkg->dest == NULL) {
  4544. + pkg->dest = conf->default_dest;
  4545. + }
  4546. +
  4547. + old_pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name);
  4548. +
  4549. + err = ipkg_install_check_downgrade(conf, pkg, old_pkg, message);
  4550. + if (err) { return err; }
  4551. +
  4552. + pkg->state_want = SW_INSTALL;
  4553. + if (old_pkg){
  4554. + old_pkg->state_want = SW_DEINSTALL; /* needed for check_data_file_clashes of dependences */
  4555. + }
  4556. +
  4557. +
  4558. + /* Abhaya: conflicts check */
  4559. + err = check_conflicts_for(conf, pkg);
  4560. + if (err) { return err; }
  4561. +
  4562. + /* this setup is to remove the upgrade scenario in the end when
  4563. + installing pkg A, A deps B & B deps on A. So both B and A are
  4564. + installed. Then A's installation is started resulting in an
  4565. + uncecessary upgrade */
  4566. + if (pkg->state_status == SS_INSTALLED
  4567. + && conf->force_reinstall == 0) return 0;
  4568. +
  4569. + err = verify_pkg_installable(conf, pkg);
  4570. + if (err) { return err; }
  4571. +
  4572. + if (pkg->local_filename == NULL) {
  4573. + err = ipkg_download_pkg(conf, pkg, conf->tmp_dir);
  4574. + if (err) {
  4575. + ipkg_message(conf, IPKG_ERROR,
  4576. + "Failed to download %s. Perhaps you need to run 'ipkg update'?\n",
  4577. + pkg->name);
  4578. + return err;
  4579. + }
  4580. + }
  4581. +
  4582. +/* Check for md5 values */
  4583. + if (pkg->md5sum)
  4584. + {
  4585. + file_md5 = file_md5sum_alloc(pkg->local_filename);
  4586. + if (strcmp((char *)file_md5, pkg->md5sum))
  4587. + {
  4588. + ipkg_message(conf, IPKG_ERROR,
  4589. + "Package %s md5sum mismatch. Either the ipkg or the package index are corrupt. Try 'ipkg update'.\n",
  4590. + pkg->name);
  4591. + free(file_md5);
  4592. + return err;
  4593. + }
  4594. + free(file_md5);
  4595. + }
  4596. +
  4597. + if (pkg->tmp_unpack_dir == NULL) {
  4598. + unpack_pkg_control_files(conf, pkg);
  4599. + }
  4600. +
  4601. + /* We should update the filelist here, so that upgrades of packages that split will not fail. -Jamey 27-MAR-03 */
  4602. +/* Pigi: check if it will pass from here when replacing. It seems to fail */
  4603. +/* That's rather strange that files don't change owner. Investigate !!!!!!*/
  4604. + err = update_file_ownership(conf, pkg, old_pkg);
  4605. + if (err) { return err; }
  4606. +
  4607. + if (conf->nodeps == 0) {
  4608. + err = satisfy_dependencies_for(conf, pkg);
  4609. + if (err) { return err; }
  4610. + }
  4611. +
  4612. + replacees = pkg_vec_alloc();
  4613. + pkg_get_installed_replacees(pkg, replacees);
  4614. +
  4615. + /* this next section we do with SIGINT blocked to prevent inconsistency between ipkg database and filesystem */
  4616. + {
  4617. + sigset_t newset, oldset;
  4618. + sighandler_t old_handler = NULL;
  4619. + int use_signal = 0;
  4620. + caught_sigint = 0;
  4621. + if (use_signal) {
  4622. + old_handler = signal(SIGINT, ipkg_install_pkg_sigint_handler);
  4623. + } else {
  4624. + sigemptyset(&newset);
  4625. + sigaddset(&newset, SIGINT);
  4626. + sigprocmask(SIG_BLOCK, &newset, &oldset);
  4627. + }
  4628. +
  4629. + ipkg_state_changed++;
  4630. + pkg->state_flag |= SF_FILELIST_CHANGED;
  4631. +
  4632. + /* XXX: BUG: we really should treat replacement more like an upgrade
  4633. + * Instead, we're going to remove the replacees
  4634. + */
  4635. + err = pkg_remove_installed_replacees(conf, replacees);
  4636. + if (err) goto UNWIND_REMOVE_INSTALLED_REPLACEES;
  4637. +
  4638. + /*
  4639. + err = prerm_upgrade_old_pkg(conf, pkg, old_pkg);
  4640. + if (err) goto UNWIND_PRERM_UPGRADE_OLD_PKG;
  4641. +
  4642. + err = prerm_deconfigure_conflictors(conf, pkg, replacees);
  4643. + if (err) goto UNWIND_PRERM_DECONFIGURE_CONFLICTORS;
  4644. + */
  4645. +
  4646. + err = preinst_configure(conf, pkg, old_pkg);
  4647. + /*
  4648. + if (err) goto UNWIND_PREINST_CONFIGURE;
  4649. + */
  4650. +
  4651. + err = backup_modified_conffiles(conf, pkg, old_pkg);
  4652. + if (err) goto UNWIND_BACKUP_MODIFIED_CONFFILES;
  4653. +
  4654. + err = check_data_file_clashes(conf, pkg, old_pkg);
  4655. + /*
  4656. + if (err) goto UNWIND_CHECK_DATA_FILE_CLASHES;
  4657. +
  4658. + err = postrm_upgrade_old_pkg(conf, pkg, old_pkg);
  4659. + if (err) goto UNWIND_POSTRM_UPGRADE_OLD_PKG;
  4660. + */
  4661. +
  4662. + if (conf->noaction) return 0;
  4663. +
  4664. + /* point of no return: no unwinding after this */
  4665. + if (old_pkg && !conf->force_reinstall) {
  4666. + old_pkg->state_want = SW_DEINSTALL;
  4667. +
  4668. + if (old_pkg->state_flag & SF_NOPRUNE) {
  4669. + ipkg_message(conf, IPKG_INFO,
  4670. + " not removing obsolesced files because package marked noprune\n");
  4671. + } else {
  4672. + ipkg_message(conf, IPKG_INFO,
  4673. + " removing obsolesced files\n");
  4674. + remove_obsolesced_files(conf, pkg, old_pkg);
  4675. + }
  4676. + /* removing files from old package, to avoid ghost files */
  4677. + remove_data_files_and_list(conf, old_pkg);
  4678. +/* Pigi : It should be better to remove also maintainer and postrem scripts here, just in case*/
  4679. + remove_maintainer_scripts_except_postrm(conf, old_pkg);
  4680. + remove_postrm(conf, old_pkg);
  4681. +/* Pigi */
  4682. +
  4683. + }
  4684. +
  4685. +
  4686. + ipkg_message(conf, IPKG_INFO,
  4687. + " installing maintainer scripts\n");
  4688. + install_maintainer_scripts(conf, pkg, old_pkg);
  4689. +
  4690. + /* the following just returns 0
  4691. + remove_disappeared(conf, pkg);
  4692. + */
  4693. +
  4694. + ipkg_message(conf, IPKG_INFO,
  4695. + " installing data files\n");
  4696. + install_data_files(conf, pkg);
  4697. +
  4698. +/* read comments from function for detail but I will execute this here as all other tests are ok.*/
  4699. + err = check_data_file_clashes_change(conf, pkg);
  4700. +
  4701. + ipkg_message(conf, IPKG_INFO,
  4702. + " resolving conf files\n");
  4703. + resolve_conffiles(conf, pkg);
  4704. +
  4705. + pkg->state_status = SS_UNPACKED;
  4706. + old_state_flag = pkg->state_flag;
  4707. + pkg->state_flag &= ~SF_PREFER;
  4708. + ipkg_message(conf, IPKG_DEBUG, " pkg=%s old_state_flag=%x state_flag=%x\n", pkg->name, old_state_flag, pkg->state_flag);
  4709. +
  4710. + if (old_pkg && !conf->force_reinstall) {
  4711. + old_pkg->state_status = SS_NOT_INSTALLED;
  4712. + }
  4713. +
  4714. + time(&pkg->installed_time);
  4715. +
  4716. + ipkg_message(conf, IPKG_INFO,
  4717. + " cleanup temp files\n");
  4718. + cleanup_temporary_files(conf, pkg);
  4719. +
  4720. + ab_pkg = pkg->parent;
  4721. + if (ab_pkg)
  4722. + ab_pkg->state_status = pkg->state_status;
  4723. +
  4724. + ipkg_message(conf, IPKG_INFO, "Done.\n");
  4725. +
  4726. + if (use_signal)
  4727. + signal(SIGINT, old_handler);
  4728. + else
  4729. + sigprocmask(SIG_UNBLOCK, &newset, &oldset);
  4730. +
  4731. + return 0;
  4732. +
  4733. +
  4734. + /*
  4735. + UNWIND_POSTRM_UPGRADE_OLD_PKG:
  4736. + postrm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
  4737. + UNWIND_CHECK_DATA_FILE_CLASHES:
  4738. + check_data_file_clashes_unwind(conf, pkg, old_pkg);
  4739. + */
  4740. + UNWIND_BACKUP_MODIFIED_CONFFILES:
  4741. + backup_modified_conffiles_unwind(pkg, old_pkg);
  4742. + /*
  4743. + UNWIND_PREINST_CONFIGURE:
  4744. + preinst_configure_unwind(conf, pkg, old_pkg);
  4745. + UNWIND_PRERM_DECONFIGURE_CONFLICTORS:
  4746. + prerm_deconfigure_conflictors_unwind(conf, pkg, replacees);
  4747. + UNWIND_PRERM_UPGRADE_OLD_PKG:
  4748. + prerm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
  4749. + */
  4750. + UNWIND_REMOVE_INSTALLED_REPLACEES:
  4751. + pkg_remove_installed_replacees_unwind(conf, replacees);
  4752. +
  4753. + ipkg_message(conf, IPKG_INFO,
  4754. + " cleanup temp files\n");
  4755. + cleanup_temporary_files(conf, pkg);
  4756. +
  4757. + ipkg_message(conf, IPKG_INFO,
  4758. + "Failed.\n");
  4759. + if (use_signal)
  4760. + signal(SIGINT, old_handler);
  4761. + else
  4762. + sigprocmask(SIG_UNBLOCK, &newset, &oldset);
  4763. +
  4764. + return err;
  4765. + }
  4766. +}
  4767. +
  4768. +/*
  4769. +static int prerm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4770. +{
  4771. + DPKG_INCOMPATIBILITY:
  4772. + dpkg does some things here that we don't do yet. Do we care?
  4773. +
  4774. + 1. If a version of the package is already installed, call
  4775. + old-prerm upgrade new-version
  4776. + 2. If the script runs but exits with a non-zero exit status
  4777. + new-prerm failed-upgrade old-version
  4778. + Error unwind, for both the above cases:
  4779. + old-postinst abort-upgrade new-version
  4780. + return 0;
  4781. +}
  4782. +*/
  4783. +
  4784. +/*
  4785. +static int prerm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4786. +{
  4787. + DPKG_INCOMPATIBILITY:
  4788. + dpkg does some things here that we don't do yet. Do we care?
  4789. + (See prerm_upgrade_old_package for details)
  4790. +
  4791. + return 0;
  4792. +}
  4793. +*/
  4794. +
  4795. +/*
  4796. +static int prerm_deconfigure_conflictors(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors)
  4797. +{
  4798. + DPKG_INCOMPATIBILITY:
  4799. + dpkg does some things here that we don't do yet. Do we care?
  4800. + 2. If a 'conflicting' package is being removed at the same time:
  4801. + 1. If any packages depended on that conflicting package and
  4802. + --auto-deconfigure is specified, call, for each such package:
  4803. + deconfigured's-prerm deconfigure \
  4804. + in-favour package-being-installed version \
  4805. + removing conflicting-package version
  4806. + Error unwind:
  4807. + deconfigured's-postinst abort-deconfigure \
  4808. + in-favour package-being-installed-but-failed version \
  4809. + removing conflicting-package version
  4810. +
  4811. + The deconfigured packages are marked as requiring
  4812. + configuration, so that if --install is used they will be
  4813. + configured again if possible.
  4814. + 2. To prepare for removal of the conflicting package, call:
  4815. + conflictor's-prerm remove in-favour package new-version
  4816. + Error unwind:
  4817. + conflictor's-postinst abort-remove in-favour package new-version
  4818. + return 0;
  4819. +}
  4820. +*/
  4821. +
  4822. +/*
  4823. +static int prerm_deconfigure_conflictors_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors)
  4824. +{
  4825. + DPKG_INCOMPATIBILITY: dpkg does some things here that we don't
  4826. + do yet. Do we care? (See prerm_deconfigure_conflictors for
  4827. + details)
  4828. + return 0;
  4829. +}
  4830. +*/
  4831. +
  4832. +static int preinst_configure(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4833. +{
  4834. + int err;
  4835. + char *preinst_args;
  4836. +
  4837. + if (old_pkg) {
  4838. + char *old_version = pkg_version_str_alloc(old_pkg);
  4839. + sprintf_alloc(&preinst_args, "upgrade %s", old_version);
  4840. + free(old_version);
  4841. + } else if (pkg->state_status == SS_CONFIG_FILES) {
  4842. + char *pkg_version = pkg_version_str_alloc(pkg);
  4843. + sprintf_alloc(&preinst_args, "install %s", pkg_version);
  4844. + free(pkg_version);
  4845. + } else {
  4846. + preinst_args = strdup("install");
  4847. + }
  4848. +
  4849. + err = pkg_run_script(conf, pkg, "preinst", preinst_args);
  4850. + if (err) {
  4851. + ipkg_message(conf, IPKG_ERROR,
  4852. + "Aborting installation of %s\n", pkg->name);
  4853. + return 1;
  4854. + }
  4855. +
  4856. + free(preinst_args);
  4857. +
  4858. + return 0;
  4859. +}
  4860. +
  4861. +/*
  4862. +static int preinst_configure_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4863. +{
  4864. + DPKG_INCOMPATIBILITY:
  4865. + dpkg does the following error unwind, should we?
  4866. + pkg->postrm abort-upgrade old-version
  4867. + OR pkg->postrm abort-install old-version
  4868. + OR pkg->postrm abort-install
  4869. + return 0;
  4870. +}
  4871. +*/
  4872. +
  4873. +static int backup_modified_conffiles(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4874. +{
  4875. + int err;
  4876. + conffile_list_elt_t *iter;
  4877. + conffile_t *cf;
  4878. +
  4879. + if (conf->noaction) return 0;
  4880. +
  4881. + /* Backup all modified conffiles */
  4882. + if (old_pkg) {
  4883. + for (iter = old_pkg->conffiles.head; iter; iter = iter->next) {
  4884. + char *cf_name;
  4885. +
  4886. + cf = iter->data;
  4887. + cf_name = root_filename_alloc(conf, cf->name);
  4888. +
  4889. + /* Don't worry if the conffile is just plain gone */
  4890. + if (file_exists(cf_name) && conffile_has_been_modified(conf, cf)) {
  4891. + err = backup_make_backup(conf, cf_name);
  4892. + if (err) {
  4893. + return err;
  4894. + }
  4895. + }
  4896. + free(cf_name);
  4897. + }
  4898. + }
  4899. +
  4900. + /* Backup all conffiles that were not conffiles in old_pkg */
  4901. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  4902. + char *cf_name;
  4903. + cf = iter->data;
  4904. + cf_name = root_filename_alloc(conf, cf->name);
  4905. + /* Ignore if this was a conffile in old_pkg as well */
  4906. + if (pkg_get_conffile(old_pkg, cf->name)) {
  4907. + continue;
  4908. + }
  4909. +
  4910. + if (file_exists(cf_name) && (! backup_exists_for(cf_name))) {
  4911. + err = backup_make_backup(conf, cf_name);
  4912. + if (err) {
  4913. + return err;
  4914. + }
  4915. + }
  4916. + free(cf_name);
  4917. + }
  4918. +
  4919. + return 0;
  4920. +}
  4921. +
  4922. +static int backup_modified_conffiles_unwind(pkg_t *pkg, pkg_t *old_pkg)
  4923. +{
  4924. + conffile_list_elt_t *iter;
  4925. +
  4926. + if (old_pkg) {
  4927. + for (iter = old_pkg->conffiles.head; iter; iter = iter->next) {
  4928. + backup_remove(iter->data->name);
  4929. + }
  4930. + }
  4931. +
  4932. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  4933. + backup_remove(iter->data->name);
  4934. + }
  4935. +
  4936. + return 0;
  4937. +}
  4938. +
  4939. +
  4940. +static int check_data_file_clashes(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4941. +{
  4942. + /* DPKG_INCOMPATIBILITY:
  4943. + ipkg takes a slightly different approach than dpkg at this
  4944. + point. dpkg installs each file in the new package while
  4945. + creating a backup for any file that is replaced, (so that it
  4946. + can unwind if necessary). To avoid complexity and redundant
  4947. + storage, ipkg doesn't do any installation until later, (at the
  4948. + point at which dpkg removes the backups.
  4949. +
  4950. + But, we do have to check for data file clashes, since after
  4951. + installing a package with a file clash, removing either of the
  4952. + packages involved in the clash has the potential to break the
  4953. + other package.
  4954. + */
  4955. + str_list_t *files_list;
  4956. + str_list_elt_t *iter;
  4957. +
  4958. + int clashes = 0;
  4959. +
  4960. + files_list = pkg_get_installed_files(pkg);
  4961. + for (iter = files_list->head; iter; iter = iter->next) {
  4962. + char *root_filename;
  4963. + char *filename = iter->data;
  4964. + root_filename = root_filename_alloc(conf, filename);
  4965. + if (file_exists(root_filename) && (! file_is_dir(root_filename))) {
  4966. + pkg_t *owner;
  4967. + pkg_t *obs;
  4968. + /* Pre-existing conffiles are OK */
  4969. + /* @@@@ should have way to check that it is a conffile -Jamey */
  4970. + if (backup_exists_for(root_filename)) {
  4971. + continue;
  4972. + }
  4973. +
  4974. + /* Pre-existing files are OK if force-overwrite was asserted. */
  4975. + if (conf->force_overwrite) {
  4976. + /* but we need to change who owns this file */
  4977. + file_hash_set_file_owner(conf, filename, pkg);
  4978. + continue;
  4979. + }
  4980. +
  4981. + owner = file_hash_get_file_owner(conf, filename);
  4982. +
  4983. + /* Pre-existing files are OK if owned by the pkg being upgraded. */
  4984. + if (owner && old_pkg) {
  4985. + if (strcmp(owner->name, old_pkg->name) == 0) {
  4986. + continue;
  4987. + }
  4988. + }
  4989. +
  4990. + /* Pre-existing files are OK if owned by a package replaced by new pkg. */
  4991. + if (owner) {
  4992. + ipkg_message(conf, IPKG_DEBUG2, "Checking for replaces for %s in package %s\n", filename, owner->name);
  4993. + if (pkg_replaces(pkg, owner)) {
  4994. + continue;
  4995. + }
  4996. +/* If the file that would be installed is owned by the same package, ( as per a reinstall or similar )
  4997. + then it's ok to overwrite. */
  4998. + if (strcmp(owner->name,pkg->name)==0){
  4999. + ipkg_message(conf, IPKG_INFO, "Replacing pre-existing file %s owned by package %s\n", filename, owner->name);
  5000. + continue;
  5001. + }
  5002. + }
  5003. +
  5004. + /* Pre-existing files are OK if they are obsolete */
  5005. + obs = hash_table_get(&conf->obs_file_hash, filename);
  5006. + if (obs) {
  5007. + ipkg_message(conf, IPKG_INFO, "Pre-exiting file %s is obsolete. obs_pkg=%s\n", filename, obs->name);
  5008. + continue;
  5009. + }
  5010. +
  5011. + /* We have found a clash. */
  5012. + ipkg_message(conf, IPKG_ERROR,
  5013. + "Package %s wants to install file %s\n"
  5014. + "\tBut that file is already provided by package ",
  5015. + pkg->name, filename);
  5016. + if (owner) {
  5017. + ipkg_message(conf, IPKG_ERROR,
  5018. + "%s\n", owner->name);
  5019. + } else {
  5020. + ipkg_message(conf, IPKG_ERROR,
  5021. + "<no package>\nPlease move this file out of the way and try again.\n");
  5022. + }
  5023. + clashes++;
  5024. + }
  5025. + free(root_filename);
  5026. + }
  5027. + pkg_free_installed_files(pkg);
  5028. +
  5029. + return clashes;
  5030. +}
  5031. +
  5032. +static int check_data_file_clashes_change(ipkg_conf_t *conf, pkg_t *pkg)
  5033. +{
  5034. + /* Basically that's the worst hack I could do to be able to change ownership of
  5035. + file list, but, being that we have no way to unwind the mods, due to structure
  5036. + of hash table, probably is the quickest hack too, whishing it would not slow-up thing too much.
  5037. + What we do here is change the ownership of file in hash if a replace ( or similar events
  5038. + happens )
  5039. + Only the action that are needed to change name should be considered.
  5040. + @@@ To change after 1.0 release.
  5041. + */
  5042. + str_list_t *files_list;
  5043. + str_list_elt_t *iter;
  5044. +
  5045. + int clashes = 0;
  5046. +
  5047. + files_list = pkg_get_installed_files(pkg);
  5048. + for (iter = files_list->head; iter; iter = iter->next) {
  5049. + char *root_filename;
  5050. + char *filename = iter->data;
  5051. + root_filename = root_filename_alloc(conf, filename);
  5052. + if (file_exists(root_filename) && (! file_is_dir(root_filename))) {
  5053. + pkg_t *owner;
  5054. +
  5055. + if (conf->force_overwrite) {
  5056. + /* but we need to change who owns this file */
  5057. + file_hash_set_file_owner(conf, filename, pkg);
  5058. + continue;
  5059. + }
  5060. +
  5061. + owner = file_hash_get_file_owner(conf, filename);
  5062. +
  5063. + /* Pre-existing files are OK if owned by a package replaced by new pkg. */
  5064. + if (owner) {
  5065. + if (pkg_replaces(pkg, owner)) {
  5066. +/* It's now time to change the owner of that file.
  5067. + It has been "replaced" from the new "Replaces", then I need to inform lists file about that. */
  5068. + ipkg_message(conf, IPKG_INFO, "Replacing pre-existing file %s owned by package %s\n", filename, owner->name);
  5069. + file_hash_set_file_owner(conf, filename, pkg);
  5070. + continue;
  5071. + }
  5072. + }
  5073. +
  5074. + }
  5075. + free(root_filename);
  5076. + }
  5077. + pkg_free_installed_files(pkg);
  5078. +
  5079. + return clashes;
  5080. +}
  5081. +
  5082. +/*
  5083. +static int check_data_file_clashes_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5084. +{
  5085. + Nothing to do since check_data_file_clashes doesn't change state
  5086. + return 0;
  5087. +}
  5088. +*/
  5089. +
  5090. +/*
  5091. +static int postrm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5092. +{
  5093. + DPKG_INCOMPATIBILITY: dpkg does the following here, should we?
  5094. + 1. If the package is being upgraded, call
  5095. + old-postrm upgrade new-version
  5096. + 2. If this fails, attempt:
  5097. + new-postrm failed-upgrade old-version
  5098. + Error unwind, for both cases:
  5099. + old-preinst abort-upgrade new-version
  5100. + return 0;
  5101. +}
  5102. +*/
  5103. +
  5104. +/*
  5105. +static int postrm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5106. +{
  5107. + DPKG_INCOMPATIBILITY:
  5108. + dpkg does some things here that we don't do yet. Do we care?
  5109. + (See postrm_upgrade_old_pkg for details)
  5110. + return 0;
  5111. +}
  5112. +*/
  5113. +
  5114. +static int remove_obsolesced_files(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5115. +{
  5116. + int err;
  5117. + str_list_t *old_files;
  5118. + str_list_elt_t *of;
  5119. + str_list_t *new_files;
  5120. + str_list_elt_t *nf;
  5121. +
  5122. + if (old_pkg == NULL) {
  5123. + return 0;
  5124. + }
  5125. +
  5126. + old_files = pkg_get_installed_files(old_pkg);
  5127. + new_files = pkg_get_installed_files(pkg);
  5128. +
  5129. + for (of = old_files->head; of; of = of->next) {
  5130. + pkg_t *owner;
  5131. + char *old, *new;
  5132. + old = of->data;
  5133. + for (nf = new_files->head; nf; nf = nf->next) {
  5134. + new = nf->data;
  5135. + if (strcmp(old, new) == 0) {
  5136. + goto NOT_OBSOLETE;
  5137. + }
  5138. + }
  5139. + if (file_is_dir(old)) {
  5140. + continue;
  5141. + }
  5142. + owner = file_hash_get_file_owner(conf, old);
  5143. + if (owner != old_pkg) {
  5144. + /* in case obsolete file no longer belongs to old_pkg */
  5145. + continue;
  5146. + }
  5147. +
  5148. + /* old file is obsolete */
  5149. + ipkg_message(conf, IPKG_INFO,
  5150. + " removing obsolete file %s\n", old);
  5151. + if (!conf->noaction) {
  5152. + err = unlink(old);
  5153. + if (err) {
  5154. + ipkg_message(conf, IPKG_ERROR, " Warning: remove %s failed: %s\n", old,
  5155. + strerror(errno));
  5156. + }
  5157. + }
  5158. +
  5159. + NOT_OBSOLETE:
  5160. + ;
  5161. + }
  5162. +
  5163. + pkg_free_installed_files(old_pkg);
  5164. + pkg_free_installed_files(pkg);
  5165. +
  5166. + return 0;
  5167. +}
  5168. +
  5169. +static int remove_obsolete_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5170. +{
  5171. + int i;
  5172. + int err = 0;
  5173. + char *globpattern;
  5174. + glob_t globbuf;
  5175. + if (0) {
  5176. + if (!pkg->dest) {
  5177. + ipkg_message(conf, IPKG_ERROR, "%s: no dest for package %s\n", __FUNCTION__, pkg->name);
  5178. + return -1;
  5179. + }
  5180. + sprintf_alloc(&globpattern, "%s/%s.*", pkg->dest->info_dir, pkg->name);
  5181. + err = glob(globpattern, 0, NULL, &globbuf);
  5182. + free(globpattern);
  5183. + if (err) {
  5184. + return err;
  5185. + }
  5186. + /* XXXX this should perhaps only remove the ones that are not overwritten in new package. Jamey 11/11/2003 */
  5187. + for (i = 0; i < globbuf.gl_pathc; i++) {
  5188. + ipkg_message(conf, IPKG_DEBUG, "Removing control file %s from old_pkg %s\n",
  5189. + globbuf.gl_pathv[i], old_pkg->name);
  5190. + if (!conf->noaction)
  5191. + unlink(globbuf.gl_pathv[i]);
  5192. + }
  5193. + globfree(&globbuf);
  5194. + }
  5195. + return err;
  5196. +}
  5197. +
  5198. +static int install_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5199. +{
  5200. + int ret;
  5201. + char *prefix;
  5202. +
  5203. + if (old_pkg)
  5204. + remove_obsolete_maintainer_scripts(conf, pkg, old_pkg);
  5205. + sprintf_alloc(&prefix, "%s.", pkg->name);
  5206. + ret = pkg_extract_control_files_to_dir_with_prefix(pkg,
  5207. + pkg->dest->info_dir,
  5208. + prefix);
  5209. + free(prefix);
  5210. + return ret;
  5211. +}
  5212. +
  5213. +/*
  5214. +static int remove_disappeared(ipkg_conf_t *conf, pkg_t *pkg)
  5215. +{
  5216. + DPKG_INCOMPATIBILITY:
  5217. + This is a fairly sophisticated dpkg operation. Shall we
  5218. + skip it?
  5219. +
  5220. + Any packages all of whose files have been overwritten during the
  5221. + installation, and which aren't required for dependencies, are
  5222. + considered to have been removed. For each such package
  5223. + 1. disappearer's-postrm disappear overwriter overwriter-version
  5224. + 2. The package's maintainer scripts are removed
  5225. + 3. It is noted in the status database as being in a sane state,
  5226. + namely not installed (any conffiles it may have are ignored,
  5227. + rather than being removed by dpkg). Note that disappearing
  5228. + packages do not have their prerm called, because dpkg doesn't
  5229. + know in advance that the package is going to vanish.
  5230. +
  5231. +
  5232. + return 0;
  5233. +}
  5234. +*/
  5235. +
  5236. +static int install_data_files(ipkg_conf_t *conf, pkg_t *pkg)
  5237. +{
  5238. + int err;
  5239. +
  5240. + /* ipkg takes a slightly different approach to data file backups
  5241. + than dpkg. Rather than removing backups at this point, we
  5242. + actually do the data file installation now. See comments in
  5243. + check_data_file_clashes() for more details. */
  5244. +
  5245. + ipkg_message(conf, IPKG_INFO,
  5246. + " extracting data files to %s\n", pkg->dest->root_dir);
  5247. + err = pkg_extract_data_files_to_dir(pkg, pkg->dest->root_dir);
  5248. + if (err) {
  5249. + return err;
  5250. + }
  5251. +
  5252. + /* XXX: BUG or FEATURE : We are actually loosing the Essential flag,
  5253. + so we can't save ourself from removing important packages
  5254. + At this point we (should) have extracted the .control file, so it
  5255. + would be a good idea to reload the data in it, and set the Essential
  5256. + state in *pkg. From now on the Essential is back in status file and
  5257. + we can protect again.
  5258. + We should operate this way:
  5259. + fopen the file ( pkg->dest->root_dir/pkg->name.control )
  5260. + check for "Essential" in it
  5261. + set the value in pkg->essential.
  5262. + This new routine could be useful also for every other flag
  5263. + Pigi: 16/03/2004 */
  5264. + set_flags_from_control(conf, pkg) ;
  5265. +
  5266. + ipkg_message(conf, IPKG_DEBUG, " Calling pkg_write_filelist from %s\n", __FUNCTION__);
  5267. + err = pkg_write_filelist(conf, pkg);
  5268. + if (err)
  5269. + return err;
  5270. +
  5271. + /* XXX: FEATURE: ipkg should identify any files which existed
  5272. + before installation and which were overwritten, (see
  5273. + check_data_file_clashes()). What it must do is remove any such
  5274. + files from the filelist of the old package which provided the
  5275. + file. Otherwise, if the old package were removed at some point
  5276. + it would break the new package. Removing the new package will
  5277. + also break the old one, but this cannot be helped since the old
  5278. + package's file has already been deleted. This is the importance
  5279. + of check_data_file_clashes(), and only allowing ipkg to install
  5280. + a clashing package with a user force. */
  5281. +
  5282. + return 0;
  5283. +}
  5284. +
  5285. +static int resolve_conffiles(ipkg_conf_t *conf, pkg_t *pkg)
  5286. +{
  5287. + conffile_list_elt_t *iter;
  5288. + conffile_t *cf;
  5289. + char *cf_backup;
  5290. + uint8_t *md5sum;
  5291. +
  5292. +
  5293. + if (conf->noaction) return 0;
  5294. +
  5295. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  5296. + char *root_filename;
  5297. + cf = iter->data;
  5298. + root_filename = root_filename_alloc(conf, cf->name);
  5299. +
  5300. + /* Might need to initialize the md5sum for each conffile */
  5301. + if (cf->value == NULL) {
  5302. + cf->value = (char *)file_md5sum_alloc(root_filename);
  5303. + }
  5304. +
  5305. + if (!file_exists(root_filename)) {
  5306. + free(root_filename);
  5307. + continue;
  5308. + }
  5309. +
  5310. + cf_backup = backup_filename_alloc(root_filename);
  5311. +
  5312. +
  5313. + if (file_exists(cf_backup)) {
  5314. + /* Let's compute md5 to test if files are changed */
  5315. + md5sum = file_md5sum_alloc(cf_backup);
  5316. + if (strcmp( cf->value, (char *)md5sum) != 0 ) {
  5317. + if (conf->force_defaults
  5318. + || user_prefers_old_conffile(cf->name, cf_backup) ) {
  5319. + rename(cf_backup, root_filename);
  5320. + }
  5321. + }
  5322. + unlink(cf_backup);
  5323. + free(md5sum);
  5324. + }
  5325. +
  5326. + free(cf_backup);
  5327. + free(root_filename);
  5328. + }
  5329. +
  5330. + return 0;
  5331. +}
  5332. +
  5333. +static int user_prefers_old_conffile(const char *file_name, const char *backup)
  5334. +{
  5335. + char *response;
  5336. + const char *short_file_name;
  5337. +
  5338. + short_file_name = strrchr(file_name, '/');
  5339. + if (short_file_name) {
  5340. + short_file_name++;
  5341. + } else {
  5342. + short_file_name = file_name;
  5343. + }
  5344. +
  5345. + while (1) {
  5346. + response = get_user_response(" Configuration file '%s'\n"
  5347. + " ==> File on system created by you or by a script.\n"
  5348. + " ==> File also in package provided by package maintainer.\n"
  5349. + " What would you like to do about it ? Your options are:\n"
  5350. + " Y or I : install the package maintainer's version\n"
  5351. + " N or O : keep your currently-installed version\n"
  5352. +#ifdef CONFIG_DIFF
  5353. + " D : show the differences between the versions\n"
  5354. +#endif
  5355. + " The default action is to keep your current version.\n"
  5356. + " *** %s (Y/I/N/O"
  5357. +#ifdef CONFIG_DIFF
  5358. + "/D"
  5359. +#endif
  5360. + ") [default=N] ? ", file_name, short_file_name);
  5361. + if (strcmp(response, "y") == 0
  5362. + || strcmp(response, "i") == 0
  5363. + || strcmp(response, "yes") == 0) {
  5364. + free(response);
  5365. + return 0;
  5366. + }
  5367. +
  5368. +#ifdef CONFIG_DIFF
  5369. + if (strcmp(response, "d") == 0) {
  5370. + char *cmd;
  5371. +
  5372. + free(response);
  5373. + /* XXX: BUG rewrite to use exec or busybox's internal diff */
  5374. + sprintf_alloc(&cmd, "diff -u %s %s", backup, file_name);
  5375. + xsystem(cmd);
  5376. + free(cmd);
  5377. + printf(" [Press ENTER to continue]\n");
  5378. + response = file_read_line_alloc(stdin);
  5379. + free(response);
  5380. + continue;
  5381. + }
  5382. +#endif
  5383. +
  5384. + free(response);
  5385. + return 1;
  5386. + }
  5387. +}
  5388. +
  5389. +/* XXX: CLEANUP: I'd like to move all of the code for
  5390. + creating/cleaning pkg->tmp_unpack_dir directly into pkg.c. (Then,
  5391. + it would make sense to cleanup pkg->tmp_unpack_dir directly from
  5392. + pkg_deinit for example). */
  5393. +static int cleanup_temporary_files(ipkg_conf_t *conf, pkg_t *pkg)
  5394. +{
  5395. + DIR *tmp_dir;
  5396. + struct dirent *dirent;
  5397. + char *tmp_file;
  5398. +
  5399. +#ifdef IPKG_DEBUG_NO_TMP_CLEANUP
  5400. +#error
  5401. + ipkg_message(conf, IPKG_DEBUG,
  5402. + "%s: Not cleaning up %s since ipkg compiled with IPKG_DEBUG_NO_TMP_CLEANUP\n",
  5403. + __FUNCTION__, pkg->tmp_unpack_dir);
  5404. + return 0;
  5405. +#endif
  5406. +
  5407. + if (pkg->tmp_unpack_dir && file_is_dir(pkg->tmp_unpack_dir)) {
  5408. + tmp_dir = opendir(pkg->tmp_unpack_dir);
  5409. + if (tmp_dir) {
  5410. + while (1) {
  5411. + dirent = readdir(tmp_dir);
  5412. + if (dirent == NULL) {
  5413. + break;
  5414. + }
  5415. + sprintf_alloc(&tmp_file, "%s/%s",
  5416. + pkg->tmp_unpack_dir, dirent->d_name);
  5417. + if (! file_is_dir(tmp_file)) {
  5418. + unlink(tmp_file);
  5419. + }
  5420. + free(tmp_file);
  5421. + }
  5422. + closedir(tmp_dir);
  5423. + rmdir(pkg->tmp_unpack_dir);
  5424. + free(pkg->tmp_unpack_dir);
  5425. + pkg->tmp_unpack_dir = NULL;
  5426. + }
  5427. + }
  5428. +
  5429. + ipkg_message(conf, IPKG_INFO, "cleanup_temporary_files: pkg=%s local_filename=%s tmp_dir=%s\n",
  5430. + pkg->name, pkg->local_filename, conf->tmp_dir);
  5431. + if (pkg->local_filename && strncmp(pkg->local_filename, conf->tmp_dir, strlen(conf->tmp_dir)) == 0) {
  5432. + unlink(pkg->local_filename);
  5433. + free(pkg->local_filename);
  5434. + pkg->local_filename = NULL;
  5435. + }
  5436. +
  5437. + return 0;
  5438. +}
  5439. +
  5440. +static char *backup_filename_alloc(const char *file_name)
  5441. +{
  5442. + char *backup;
  5443. +
  5444. + sprintf_alloc(&backup, "%s%s", file_name, IPKG_BACKUP_SUFFIX);
  5445. +
  5446. + return backup;
  5447. +}
  5448. +
  5449. +int backup_make_backup(ipkg_conf_t *conf, const char *file_name)
  5450. +{
  5451. + int err;
  5452. + char *backup;
  5453. +
  5454. + backup = backup_filename_alloc(file_name);
  5455. + err = file_copy(file_name, backup);
  5456. + if (err) {
  5457. + ipkg_message(conf, IPKG_ERROR,
  5458. + "%s: Failed to copy %s to %s\n",
  5459. + __FUNCTION__, file_name, backup);
  5460. + }
  5461. +
  5462. + free(backup);
  5463. +
  5464. + return err;
  5465. +}
  5466. +
  5467. +static int backup_exists_for(const char *file_name)
  5468. +{
  5469. + int ret;
  5470. + char *backup;
  5471. +
  5472. + backup = backup_filename_alloc(file_name);
  5473. +
  5474. + ret = file_exists(backup);
  5475. +
  5476. + free(backup);
  5477. +
  5478. + return ret;
  5479. +}
  5480. +
  5481. +static int backup_remove(const char *file_name)
  5482. +{
  5483. + char *backup;
  5484. +
  5485. + backup = backup_filename_alloc(file_name);
  5486. + unlink(backup);
  5487. + free(backup);
  5488. +
  5489. + return 0;
  5490. +}
  5491. +
  5492. +
  5493. +
  5494. +#ifdef CONFIG_IPKG_PROCESS_ACTIONS
  5495. +
  5496. +int ipkg_remove_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove)
  5497. +{
  5498. + /* first, remove the packages that need removing */
  5499. + for (i = 0 ; i < pkgs_to_remove->len; i++ ) {
  5500. + pkg_t *pkg = pkgs_to_remove->pkgs[i];
  5501. + err = ipkg_remove_pkg(conf, pkg,0);
  5502. + if (err) return err;
  5503. + }
  5504. + return 0;
  5505. +}
  5506. +
  5507. +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)
  5508. +{
  5509. + int i;
  5510. + /* now one more pass checking on the ones that need to be installed */
  5511. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5512. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5513. + if (pkg->dest == NULL)
  5514. + pkg->dest = conf->default_dest;
  5515. +
  5516. + pkg->state_want = SW_INSTALL;
  5517. +
  5518. + /* Abhaya: conflicts check */
  5519. + err = check_conflicts_for(conf, pkg);
  5520. + if (err) { return err; }
  5521. + }
  5522. + return 0;
  5523. +}
  5524. +
  5525. +int ipkg_process_actions_unpack_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_to_install)
  5526. +{
  5527. + int i;
  5528. + /* now one more pass checking on the ones that need to be installed */
  5529. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5530. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5531. +
  5532. + /* XXX: FEATURE: Need to really support Provides/Replaces: here at some point */
  5533. + pkg_vec_t *replacees = pkg_vec_alloc();
  5534. + pkg_get_installed_replacees(pkg, replacees);
  5535. +
  5536. + /* XXX: BUG: we really should treat replacement more like an upgrade
  5537. + * Instead, we're going to remove the replacees
  5538. + */
  5539. + err = pkg_remove_installed_replacees(conf, replacees);
  5540. + if (err) return err;
  5541. + pkg->state_flag |= SF_REMOVED_REPLACEES;
  5542. + }
  5543. + return 0;
  5544. +}
  5545. +
  5546. +int ipkg_process_actions_unpack_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_to_install)
  5547. +{
  5548. + int i;
  5549. + /* now one more pass checking on the ones that need to be installed */
  5550. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5551. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5552. + if (pkg->local_filename == NULL) {
  5553. + err = ipkg_download_pkg(conf, pkg, conf->tmp_dir);
  5554. + if (err) {
  5555. + ipkg_message(conf, IPKG_ERROR,
  5556. + "Failed to download %s. Perhaps you need to run 'ipkg update'?\n",
  5557. + pkg->name);
  5558. + return err;
  5559. + }
  5560. + }
  5561. + if (pkg->tmp_unpack_dir == NULL) {
  5562. + err = unpack_pkg_control_files(conf, pkg);
  5563. + if (err) return err;
  5564. + }
  5565. + }
  5566. + return 0;
  5567. +}
  5568. +
  5569. +int ipkg_process_actions_prerm(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
  5570. +{
  5571. + int i;
  5572. + /* now one more pass checking on the ones that need to be installed */
  5573. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5574. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5575. + pkg_t *old_pkg = pkg->old_pkg;
  5576. +
  5577. + err = prerm_upgrade_old_pkg(conf, pkg, old_pkg);
  5578. + if (err) return err;
  5579. +
  5580. + err = prerm_deconfigure_conflictors(conf, pkg, replacees);
  5581. + if (err) return err;
  5582. +
  5583. + err = preinst_configure(conf, pkg, old_pkg);
  5584. + if (err) return err;
  5585. +
  5586. + err = backup_modified_conffiles(conf, pkg, old_pkg);
  5587. + if (err) return err;
  5588. +
  5589. + err = postrm_upgrade_old_pkg(conf, pkg, old_pkg);
  5590. + if (err) return err;
  5591. + }
  5592. + return 0;
  5593. +}
  5594. +
  5595. +int ipkg_process_actions_install(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
  5596. +{
  5597. + int i;
  5598. + /* now one more pass checking on the ones that need to be installed */
  5599. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5600. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5601. + pkg_t *old_pkg = pkg->old_pkg;
  5602. +
  5603. + if (old_pkg) {
  5604. + old_pkg->state_want = SW_DEINSTALL;
  5605. +
  5606. + if (old_pkg->state_flag & SF_NOPRUNE) {
  5607. + ipkg_message(conf, IPKG_INFO,
  5608. + " not removing obsolesced files because package marked noprune\n");
  5609. + } else {
  5610. + ipkg_message(conf, IPKG_INFO,
  5611. + " removing obsolesced files\n");
  5612. + remove_obsolesced_files(conf, pkg, old_pkg);
  5613. + }
  5614. + }
  5615. +
  5616. + ipkg_message(conf, IPKG_INFO,
  5617. + " installing maintainer scripts\n");
  5618. + install_maintainer_scripts(conf, pkg, old_pkg);
  5619. +
  5620. + /* the following just returns 0 */
  5621. + remove_disappeared(conf, pkg);
  5622. +
  5623. + ipkg_message(conf, IPKG_INFO,
  5624. + " installing data files\n");
  5625. + install_data_files(conf, pkg);
  5626. +
  5627. + ipkg_message(conf, IPKG_INFO,
  5628. + " resolving conf files\n");
  5629. + resolve_conffiles(conf, pkg);
  5630. +
  5631. + pkg->state_status = SS_UNPACKED;
  5632. +
  5633. + if (old_pkg) {
  5634. + old_pkg->state_status = SS_NOT_INSTALLED;
  5635. + }
  5636. +
  5637. + time(&pkg->installed_time);
  5638. +
  5639. + ipkg_message(conf, IPKG_INFO,
  5640. + " cleanup temp files\n");
  5641. + cleanup_temporary_files(conf, pkg);
  5642. +
  5643. + if (pkg->parent)
  5644. + pkg->parent->state_status = pkg->state_status;
  5645. + }
  5646. + return 0;
  5647. +}
  5648. +
  5649. +int ipkg_process_actions_unwind_prerm(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
  5650. +{
  5651. + int i;
  5652. + /* now one more pass checking on the ones that need to be installed */
  5653. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5654. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5655. + pkg_t *old_pkg = pkg->old_pkg;
  5656. +
  5657. + if (old_pkg) {
  5658. + if (old_pkg->state_flags & SF_POSTRM_UPGRADE)
  5659. + postrm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
  5660. + if (old_pkg->state_flags & SF_CHECK_DATA_FILE_CLASHES)
  5661. + check_data_file_clashes_unwind(conf, pkg, old_pkg);
  5662. + if (old_pkg->state_flags & SF_BACKUP_MODIFIED_CONFFILES)
  5663. + backup_modified_conffiles_unwind(pkg, old_pkg);
  5664. + */
  5665. + if (old_pkg->state_flags & SF_PREINST_CONFIGURE)
  5666. + preinst_configure_unwind(conf, pkg, old_pkg);
  5667. + if (old_pkg->state_flags & SF_DECONFIGURE_CONFLICTORS)
  5668. + prerm_deconfigure_conflictors_unwind(conf, pkg, replacees);
  5669. + if (old_pkg->state_flags & SF_PRERM_UPGRADE)
  5670. + prerm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
  5671. + */
  5672. +
  5673. + if (old_pkg->state_flags & SF_REMOVED_REPLACEES)
  5674. + remove_installed_replacees_unwind(conf, pkg, old_pkg);
  5675. +
  5676. + }
  5677. + }
  5678. + return 0;
  5679. +}
  5680. +
  5681. +/*
  5682. + * Perform all the actions.
  5683. + *
  5684. + * pkgs_to_remove are packages marked for removal.
  5685. + * pkgs_superseded are the old packages being replaced by upgrades.
  5686. + *
  5687. + * Assumes pkgs_to_install includes all dependences, recursively, sorted in installable order.
  5688. + */
  5689. +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)
  5690. +{
  5691. + int err;
  5692. + int i;
  5693. +
  5694. + err = ipkg_remove_packages(conf, pkgs_to_remove);
  5695. + if (err) return err;
  5696. +
  5697. + err = ipkg_process_actions_sanity_check(conf, pkgs_superseded, pkgs_to_install);
  5698. + if (err) return err;
  5699. +
  5700. + err = ipkg_process_actions_remove_replacees(conf, pkgs_to_install);
  5701. + if (err) goto UNWIND;
  5702. +
  5703. + /* @@@@ look at ipkg_install_pkg for handling replacements */
  5704. + err = ipkg_process_actions_unpack_packages(conf, pkgs_to_install);
  5705. + if (err) goto UNWIND;
  5706. +
  5707. + /*
  5708. + * Now that we have the packages unpacked, we can look for data
  5709. + * file clashes. First, we mark the files from the superseded
  5710. + * packages as obsolete. Then we scan the files in
  5711. + * pkgs_to_install, and only complain about clashes with
  5712. + * non-obsolete files.
  5713. + */
  5714. +
  5715. + err = ipkg_process_actions_check_data_file_clashes(conf, pkgs_superseded, pkgs_to_install);
  5716. + if (err) goto UNWIND;
  5717. +
  5718. + /* this was before checking data file clashes */
  5719. + err = ipkg_process_actions_prerm(conf, pkgs_superseded, pkgs_to_install);
  5720. + if (err) goto UNWIND;
  5721. +
  5722. + /* point of no return: no unwinding after this */
  5723. + err = ipkg_process_actions_install(conf, pkgs_to_install);
  5724. + if (err) return err;
  5725. +
  5726. + ipkg_message(conf, IPKG_INFO, "Done.\n");
  5727. + return 0;
  5728. +
  5729. + UNWIND:
  5730. + ipkg_process_actions_unwind(conf, pkgs_to_install);
  5731. +
  5732. + ipkg_message(conf, IPKG_INFO,
  5733. + " cleanup temp files\n");
  5734. + cleanup_temporary_files(conf, pkg);
  5735. +
  5736. + ipkg_message(conf, IPKG_INFO,
  5737. + "Failed.\n");
  5738. + return err;
  5739. +}
  5740. +
  5741. +#endif
  5742. diff -Nur busybox-1.21.1.orig/archival/libipkg/ipkg_install.h busybox-1.21.1/archival/libipkg/ipkg_install.h
  5743. --- busybox-1.21.1.orig/archival/libipkg/ipkg_install.h 1970-01-01 01:00:00.000000000 +0100
  5744. +++ busybox-1.21.1/archival/libipkg/ipkg_install.h 2014-02-17 14:25:39.858534188 +0100
  5745. @@ -0,0 +1,35 @@
  5746. +/* ipkg_install.h - the itsy package management system
  5747. +
  5748. + Carl D. Worth
  5749. +
  5750. + Copyright (C) 2001 University of Southern California
  5751. +
  5752. + This program is free software; you can redistribute it and/or
  5753. + modify it under the terms of the GNU General Public License as
  5754. + published by the Free Software Foundation; either version 2, or (at
  5755. + your option) any later version.
  5756. +
  5757. + This program is distributed in the hope that it will be useful, but
  5758. + WITHOUT ANY WARRANTY; without even the implied warranty of
  5759. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  5760. + General Public License for more details.
  5761. +*/
  5762. +
  5763. +#ifndef IPKG_INSTALL_H
  5764. +#define IPKG_INSTALL_H
  5765. +
  5766. +#include "pkg.h"
  5767. +#include "ipkg_conf.h"
  5768. +
  5769. +ipkg_error_t ipkg_install_by_name(ipkg_conf_t *conf, const char *pkg_name);
  5770. +ipkg_error_t ipkg_install_multi_by_name(ipkg_conf_t *conf, const char *pkg_name);
  5771. +int ipkg_install_from_file(ipkg_conf_t *conf, const char *filename);
  5772. +int ipkg_install_pkg(ipkg_conf_t *conf, pkg_t *pkg,int from_upgrading);
  5773. +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg);
  5774. +
  5775. +int ipkg_satisfy_all_dependences(ipkg_conf_t *conf);
  5776. +
  5777. +int pkg_mark_dependencies_for_installation(ipkg_conf_t *conf, pkg_t *pkg_name, pkg_vec_t *pkgs_needed);
  5778. +int name_mark_dependencies_for_installation(ipkg_conf_t *conf, const char *pkg_name, pkg_vec_t *pkgs_needed);
  5779. +
  5780. +#endif
  5781. diff -Nur busybox-1.21.1.orig/archival/libipkg/ipkg_message.c busybox-1.21.1/archival/libipkg/ipkg_message.c
  5782. --- busybox-1.21.1.orig/archival/libipkg/ipkg_message.c 1970-01-01 01:00:00.000000000 +0100
  5783. +++ busybox-1.21.1/archival/libipkg/ipkg_message.c 2014-02-17 14:25:39.858534188 +0100
  5784. @@ -0,0 +1,35 @@
  5785. +/* ipkg_message.c - the itsy package management system
  5786. +
  5787. + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
  5788. +
  5789. + This program is free software; you can redistribute it and/or
  5790. + modify it under the terms of the GNU General Public License as
  5791. + published by the Free Software Foundation; either version 2, or (at
  5792. + your option) any later version.
  5793. +
  5794. + This program is distributed in the hope that it will be useful, but
  5795. + WITHOUT ANY WARRANTY; without even the implied warranty of
  5796. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  5797. + General Public License for more details.
  5798. +*/
  5799. +
  5800. +
  5801. +#include "ipkg.h"
  5802. +#include "ipkg_conf.h"
  5803. +#include "ipkg_message.h"
  5804. +#include "libipkg.h"
  5805. +
  5806. +void
  5807. +ipkg_message (ipkg_conf_t * conf, message_level_t level, const char *fmt, ...)
  5808. +{
  5809. + va_list ap;
  5810. + char ts[256];
  5811. +
  5812. + if (ipkg_cb_message)
  5813. + {
  5814. + va_start (ap, fmt);
  5815. + vsnprintf (ts,256,fmt, ap);
  5816. + va_end (ap);
  5817. + ipkg_cb_message(conf,level,ts);
  5818. + }
  5819. +}
  5820. diff -Nur busybox-1.21.1.orig/archival/libipkg/ipkg_message.h busybox-1.21.1/archival/libipkg/ipkg_message.h
  5821. --- busybox-1.21.1.orig/archival/libipkg/ipkg_message.h 1970-01-01 01:00:00.000000000 +0100
  5822. +++ busybox-1.21.1/archival/libipkg/ipkg_message.h 2014-02-17 14:25:39.858534188 +0100
  5823. @@ -0,0 +1,32 @@
  5824. +/* ipkg_message.h - the itsy package management system
  5825. +
  5826. + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
  5827. +
  5828. + This program is free software; you can redistribute it and/or
  5829. + modify it under the terms of the GNU General Public License as
  5830. + published by the Free Software Foundation; either version 2, or (at
  5831. + your option) any later version.
  5832. +
  5833. + This program is distributed in the hope that it will be useful, but
  5834. + WITHOUT ANY WARRANTY; without even the implied warranty of
  5835. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  5836. + General Public License for more details.
  5837. +*/
  5838. +
  5839. +#ifndef _IPKG_MESSAGE_H_
  5840. +#define _IPKG_MESSAGE_H_
  5841. +
  5842. +#include "ipkg.h"
  5843. +#include "ipkg_conf.h"
  5844. +
  5845. +typedef enum {
  5846. + IPKG_ERROR, /* error conditions */
  5847. + IPKG_NOTICE, /* normal but significant condition */
  5848. + IPKG_INFO, /* informational message */
  5849. + IPKG_DEBUG, /* debug level message */
  5850. + IPKG_DEBUG2, /* more debug level message */
  5851. +} message_level_t;
  5852. +
  5853. +extern void ipkg_message(ipkg_conf_t *conf, message_level_t level, const char *fmt, ...);
  5854. +
  5855. +#endif /* _IPKG_MESSAGE_H_ */
  5856. diff -Nur busybox-1.21.1.orig/archival/libipkg/ipkg_remove.c busybox-1.21.1/archival/libipkg/ipkg_remove.c
  5857. --- busybox-1.21.1.orig/archival/libipkg/ipkg_remove.c 1970-01-01 01:00:00.000000000 +0100
  5858. +++ busybox-1.21.1/archival/libipkg/ipkg_remove.c 2014-02-17 14:25:39.858534188 +0100
  5859. @@ -0,0 +1,385 @@
  5860. +/* ipkg_remove.c - the itsy package management system
  5861. +
  5862. + Carl D. Worth
  5863. +
  5864. + Copyright (C) 2001 University of Southern California
  5865. +
  5866. + This program is free software; you can redistribute it and/or
  5867. + modify it under the terms of the GNU General Public License as
  5868. + published by the Free Software Foundation; either version 2, or (at
  5869. + your option) any later version.
  5870. +
  5871. + This program is distributed in the hope that it will be useful, but
  5872. + WITHOUT ANY WARRANTY; without even the implied warranty of
  5873. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  5874. + General Public License for more details.
  5875. +*/
  5876. +
  5877. +#include "ipkg.h"
  5878. +#include "ipkg_message.h"
  5879. +
  5880. +#include <glob.h>
  5881. +
  5882. +#include "ipkg_remove.h"
  5883. +
  5884. +#include "file_util.h"
  5885. +#include "sprintf_alloc.h"
  5886. +#include "str_util.h"
  5887. +
  5888. +#include "ipkg_cmd.h"
  5889. +
  5890. +int ipkg_remove_dependent_pkgs (ipkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **dependents);
  5891. +
  5892. +/*
  5893. + * Returns number of the number of packages depending on the packages provided by this package.
  5894. + * Every package implicitly provides itself.
  5895. + */
  5896. +int pkg_has_installed_dependents(pkg_t *pkg, abstract_pkg_t *** pdependents)
  5897. +{
  5898. + int nprovides = pkg->provides_count;
  5899. + abstract_pkg_t **provides = pkg->provides;
  5900. + int n_installed_dependents = 0;
  5901. + int i;
  5902. + for (i = 0; i <= nprovides; i++) {
  5903. + abstract_pkg_t *providee = provides[i];
  5904. + abstract_pkg_t **dependers = providee->depended_upon_by;
  5905. + abstract_pkg_t *dep_ab_pkg;
  5906. + if (dependers == NULL)
  5907. + continue;
  5908. + while ((dep_ab_pkg = *dependers++) != NULL) {
  5909. + if (dep_ab_pkg->state_status == SS_INSTALLED){
  5910. + n_installed_dependents++;
  5911. + }
  5912. + }
  5913. +
  5914. + }
  5915. + /* if caller requested the set of installed dependents */
  5916. + if (pdependents) {
  5917. + int p = 0;
  5918. + abstract_pkg_t **dependents = (abstract_pkg_t **)malloc((n_installed_dependents+1)*sizeof(abstract_pkg_t *));
  5919. +
  5920. + if ( dependents == NULL ){
  5921. + fprintf(stderr,"%s Unable to allocate memory. REPORT THIS BUG IN BUGZILLA PLEASE\n", __FUNCTION__);
  5922. + return -1;
  5923. + }
  5924. +
  5925. + *pdependents = dependents;
  5926. + for (i = 0; i <= nprovides; i++) {
  5927. + abstract_pkg_t *providee = provides[i];
  5928. + abstract_pkg_t **dependers = providee->depended_upon_by;
  5929. + abstract_pkg_t *dep_ab_pkg;
  5930. + if (dependers == NULL)
  5931. + continue;
  5932. + while ((dep_ab_pkg = *dependers++) != NULL) {
  5933. + if (dep_ab_pkg->state_status == SS_INSTALLED && !(dep_ab_pkg->state_flag & SF_MARKED)) {
  5934. + dependents[p++] = dep_ab_pkg;
  5935. + dep_ab_pkg->state_flag |= SF_MARKED;
  5936. + }
  5937. + }
  5938. + }
  5939. + dependents[p] = NULL;
  5940. + /* now clear the marks */
  5941. + for (i = 0; i < p; i++) {
  5942. + abstract_pkg_t *dep_ab_pkg = dependents[i];
  5943. + dep_ab_pkg->state_flag &= ~SF_MARKED;
  5944. + }
  5945. + }
  5946. + return n_installed_dependents;
  5947. +}
  5948. +
  5949. +int ipkg_remove_dependent_pkgs (ipkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **dependents)
  5950. +{
  5951. + int i;
  5952. + int a;
  5953. + int count;
  5954. + pkg_vec_t *dependent_pkgs = pkg_vec_alloc();
  5955. + abstract_pkg_t * ab_pkg;
  5956. +
  5957. + if((ab_pkg = pkg->parent) == NULL){
  5958. + fprintf(stderr, "%s: unable to get dependent pkgs. pkg %s isn't in hash table\n",
  5959. + __FUNCTION__, pkg->name);
  5960. + return 0;
  5961. + }
  5962. +
  5963. + if (dependents == NULL)
  5964. + return 0;
  5965. +
  5966. + // here i am using the dependencies_checked
  5967. + if (ab_pkg->dependencies_checked == 2) // variable to make out whether this package
  5968. + return 0; // has already been encountered in the process
  5969. + // of marking packages for removal - Karthik
  5970. + ab_pkg->dependencies_checked = 2;
  5971. +
  5972. + i = 0;
  5973. + count = 1;
  5974. + while (dependents [i] != NULL) {
  5975. + abstract_pkg_t *dep_ab_pkg = dependents[i];
  5976. +
  5977. + if (dep_ab_pkg->dependencies_checked == 2){
  5978. + i++;
  5979. + continue;
  5980. + }
  5981. + if (dep_ab_pkg->state_status == SS_INSTALLED) {
  5982. + for (a = 0; a < dep_ab_pkg->pkgs->len; a++) {
  5983. + pkg_t *dep_pkg = dep_ab_pkg->pkgs->pkgs[a];
  5984. + if (dep_pkg->state_status == SS_INSTALLED) {
  5985. + pkg_vec_insert(dependent_pkgs, dep_pkg);
  5986. + count++;
  5987. + }
  5988. + }
  5989. + }
  5990. + i++;
  5991. + /* 1 - to keep track of visited ab_pkgs when checking for possiblility of a broken removal of pkgs.
  5992. + * 2 - to keep track of pkgs whose deps have been checked alrdy - Karthik */
  5993. + }
  5994. +
  5995. + if (count == 1)
  5996. + return 0;
  5997. +
  5998. +
  5999. + for (i = 0; i < dependent_pkgs->len; i++) {
  6000. + int err = ipkg_remove_pkg(conf, dependent_pkgs->pkgs[i],0);
  6001. + if (err)
  6002. + return err;
  6003. + }
  6004. + return 0;
  6005. +}
  6006. +
  6007. +static int user_prefers_removing_dependents(ipkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **dependents)
  6008. +{
  6009. + abstract_pkg_t *dep_ab_pkg;
  6010. + ipkg_message(conf, IPKG_ERROR, "Package %s is depended upon by packages:\n", pkg->name);
  6011. + while ((dep_ab_pkg = *dependents++) != NULL) {
  6012. + if (dep_ab_pkg->state_status == SS_INSTALLED)
  6013. + ipkg_message(conf, IPKG_ERROR, "\t%s\n", dep_ab_pkg->name);
  6014. + }
  6015. + ipkg_message(conf, IPKG_ERROR, "These might cease to work if package %s is removed.\n\n", pkg->name);
  6016. + ipkg_message(conf, IPKG_ERROR, "");
  6017. + ipkg_message(conf, IPKG_ERROR, "You can force removal of this package with -force-depends.\n");
  6018. + ipkg_message(conf, IPKG_ERROR, "You can force removal of this package and its dependents\n");
  6019. + ipkg_message(conf, IPKG_ERROR, "with -force-removal-of-dependent-packages or -recursive\n");
  6020. + ipkg_message(conf, IPKG_ERROR, "or by setting option force_removal_of_dependent_packages\n");
  6021. + ipkg_message(conf, IPKG_ERROR, "in ipkg.conf.\n");
  6022. + return 0;
  6023. +}
  6024. +
  6025. +int ipkg_remove_pkg(ipkg_conf_t *conf, pkg_t *pkg,int message)
  6026. +{
  6027. +/* Actually, when "message == 1" I have been called from an upgrade, and not from a normal remove
  6028. + thus I wan't check for essential, as I'm upgrading.
  6029. + I hope it won't break anything :)
  6030. +*/
  6031. + int err;
  6032. + abstract_pkg_t *parent_pkg = NULL;
  6033. +
  6034. + if (pkg->essential && !message) {
  6035. + if (conf->force_removal_of_essential_packages) {
  6036. + fprintf(stderr, "WARNING: Removing essential package %s under your coercion.\n"
  6037. + "\tIf your system breaks, you get to keep both pieces\n",
  6038. + pkg->name);
  6039. + } else {
  6040. + fprintf(stderr, "ERROR: Refusing to remove essential package %s.\n"
  6041. + "\tRemoving an essential package may lead to an unusable system, but if\n"
  6042. + "\tyou enjoy that kind of pain, you can force ipkg to proceed against\n"
  6043. + "\tits will with the option: -force-removal-of-essential-packages\n",
  6044. + pkg->name);
  6045. + return IPKG_PKG_IS_ESSENTIAL;
  6046. + }
  6047. + }
  6048. +
  6049. + if ((parent_pkg = pkg->parent) == NULL)
  6050. + return 0;
  6051. +
  6052. + /* only attempt to remove dependent installed packages if
  6053. + * force_depends is not specified or the package is being
  6054. + * replaced.
  6055. + */
  6056. + if (!conf->force_depends
  6057. + && !(pkg->state_flag & SF_REPLACE)) {
  6058. + abstract_pkg_t **dependents;
  6059. + int has_installed_dependents =
  6060. + pkg_has_installed_dependents(pkg, &dependents);
  6061. +
  6062. + if (has_installed_dependents) {
  6063. + /*
  6064. + * if this package is depended up by others, then either we should
  6065. + * not remove it or we should remove it and all of its dependents
  6066. + */
  6067. +
  6068. + if (!conf->force_removal_of_dependent_packages
  6069. + && !user_prefers_removing_dependents(conf, pkg, dependents)) {
  6070. + return IPKG_PKG_HAS_DEPENDENTS;
  6071. + }
  6072. +
  6073. + /* remove packages depending on this package - Karthik */
  6074. + err = ipkg_remove_dependent_pkgs (conf, pkg, dependents);
  6075. + free(dependents);
  6076. + if (err) return err;
  6077. + }
  6078. + }
  6079. +
  6080. + if ( message==0 ){
  6081. + printf("Removing package %s from %s...\n", pkg->name, pkg->dest->name);
  6082. + fflush(stdout);
  6083. + }
  6084. + pkg->state_flag |= SF_FILELIST_CHANGED;
  6085. +
  6086. + pkg->state_want = SW_DEINSTALL;
  6087. + ipkg_state_changed++;
  6088. +
  6089. + pkg_run_script(conf, pkg, "prerm", "remove");
  6090. +
  6091. + /* DPKG_INCOMPATIBILITY: dpkg is slightly different here. It
  6092. + maintains an empty filelist rather than deleting it. That seems
  6093. + like a big pain, and I don't see that that should make a big
  6094. + difference, but for anyone who wants tighter compatibility,
  6095. + feel free to fix this. */
  6096. + remove_data_files_and_list(conf, pkg);
  6097. +
  6098. + pkg_run_script(conf, pkg, "postrm", "remove");
  6099. +
  6100. + remove_maintainer_scripts_except_postrm(conf, pkg);
  6101. +
  6102. + /* Aman Gupta - Since ipkg is made for handheld devices with limited
  6103. + * space, it doesn't make sense to leave extra configurations, files,
  6104. + * and maintainer scripts left around. So, we make remove like purge,
  6105. + * and take out all the crap :) */
  6106. +
  6107. + remove_postrm(conf, pkg);
  6108. + pkg->state_status = SS_NOT_INSTALLED;
  6109. +
  6110. + if (parent_pkg)
  6111. + parent_pkg->state_status = SS_NOT_INSTALLED;
  6112. +
  6113. + return 0;
  6114. +}
  6115. +
  6116. +int ipkg_purge_pkg(ipkg_conf_t *conf, pkg_t *pkg)
  6117. +{
  6118. + ipkg_remove_pkg(conf, pkg,0);
  6119. + return 0;
  6120. +}
  6121. +
  6122. +int remove_data_files_and_list(ipkg_conf_t *conf, pkg_t *pkg)
  6123. +{
  6124. + str_list_t installed_dirs;
  6125. + str_list_t *installed_files;
  6126. + str_list_elt_t *iter;
  6127. + char *file_name;
  6128. + conffile_t *conffile;
  6129. + int removed_a_dir;
  6130. + pkg_t *owner;
  6131. +
  6132. + str_list_init(&installed_dirs);
  6133. + installed_files = pkg_get_installed_files(pkg);
  6134. +
  6135. + for (iter = installed_files->head; iter; iter = iter->next) {
  6136. + file_name = iter->data;
  6137. +
  6138. + if (file_is_dir(file_name)) {
  6139. + str_list_append(&installed_dirs, strdup(file_name));
  6140. + continue;
  6141. + }
  6142. +
  6143. + conffile = pkg_get_conffile(pkg, file_name);
  6144. + if (conffile) {
  6145. + /* XXX: QUESTION: Is this right? I figure we only need to
  6146. + save the conffile if it has been modified. Is that what
  6147. + dpkg does? Or does dpkg preserve all conffiles? If so,
  6148. + this seems like a better thing to do to conserve
  6149. + space. */
  6150. + if (conffile_has_been_modified(conf, conffile)) {
  6151. + printf(" not deleting modified conffile %s\n", file_name);
  6152. + fflush(stdout);
  6153. + continue;
  6154. + }
  6155. + }
  6156. +
  6157. + ipkg_message(conf, IPKG_INFO, " deleting %s (noaction=%d)\n", file_name, conf->noaction);
  6158. + if (!conf->noaction)
  6159. + unlink(file_name);
  6160. + }
  6161. +
  6162. + if (!conf->noaction) {
  6163. + do {
  6164. + removed_a_dir = 0;
  6165. + for (iter = installed_dirs.head; iter; iter = iter->next) {
  6166. + file_name = iter->data;
  6167. +
  6168. + if (rmdir(file_name) == 0) {
  6169. + ipkg_message(conf, IPKG_INFO, " deleting %s\n", file_name);
  6170. + removed_a_dir = 1;
  6171. + str_list_remove(&installed_dirs, &iter);
  6172. + }
  6173. + }
  6174. + } while (removed_a_dir);
  6175. + }
  6176. +
  6177. + pkg_free_installed_files(pkg);
  6178. + /* We have to remove the file list now, so that
  6179. + find_pkg_owning_file does not always just report this package */
  6180. + pkg_remove_installed_files_list(conf, pkg);
  6181. +
  6182. + /* Don't print warning for dirs that are provided by other packages */
  6183. + for (iter = installed_dirs.head; iter; iter = iter->next) {
  6184. + file_name = iter->data;
  6185. +
  6186. + owner = file_hash_get_file_owner(conf, file_name);
  6187. + if (owner) {
  6188. + free(iter->data);
  6189. + iter->data = NULL;
  6190. + str_list_remove(&installed_dirs, &iter);
  6191. + }
  6192. + }
  6193. +
  6194. + /* cleanup */
  6195. + for (iter = installed_dirs.head; iter; iter = iter->next) {
  6196. + free(iter->data);
  6197. + iter->data = NULL;
  6198. + }
  6199. + str_list_deinit(&installed_dirs);
  6200. +
  6201. + return 0;
  6202. +}
  6203. +
  6204. +int remove_maintainer_scripts_except_postrm(ipkg_conf_t *conf, pkg_t *pkg)
  6205. +{
  6206. + int i, err;
  6207. + char *globpattern;
  6208. + glob_t globbuf;
  6209. +
  6210. + if (conf->noaction) return 0;
  6211. +
  6212. + sprintf_alloc(&globpattern, "%s/%s.*",
  6213. + pkg->dest->info_dir, pkg->name);
  6214. + err = glob(globpattern, 0, NULL, &globbuf);
  6215. + free(globpattern);
  6216. + if (err) {
  6217. + return 0;
  6218. + }
  6219. +
  6220. + for (i = 0; i < globbuf.gl_pathc; i++) {
  6221. + if (str_ends_with(globbuf.gl_pathv[i], ".postrm")) {
  6222. + continue;
  6223. + }
  6224. + ipkg_message(conf, IPKG_INFO, " deleting %s\n", globbuf.gl_pathv[i]);
  6225. + unlink(globbuf.gl_pathv[i]);
  6226. + }
  6227. + globfree(&globbuf);
  6228. +
  6229. + return 0;
  6230. +}
  6231. +
  6232. +int remove_postrm(ipkg_conf_t *conf, pkg_t *pkg)
  6233. +{
  6234. + char *postrm_file_name;
  6235. +
  6236. + if (conf->noaction) return 0;
  6237. +
  6238. + sprintf_alloc(&postrm_file_name, "%s/%s.postrm",
  6239. + pkg->dest->info_dir, pkg->name);
  6240. + unlink(postrm_file_name);
  6241. + free(postrm_file_name);
  6242. +
  6243. + return 0;
  6244. +}
  6245. diff -Nur busybox-1.21.1.orig/archival/libipkg/ipkg_remove.h busybox-1.21.1/archival/libipkg/ipkg_remove.h
  6246. --- busybox-1.21.1.orig/archival/libipkg/ipkg_remove.h 1970-01-01 01:00:00.000000000 +0100
  6247. +++ busybox-1.21.1/archival/libipkg/ipkg_remove.h 2014-02-17 14:25:39.858534188 +0100
  6248. @@ -0,0 +1,33 @@
  6249. +/* ipkg_remove.h - the itsy package management system
  6250. +
  6251. + Carl D. Worth
  6252. +
  6253. + Copyright (C) 2001 University of Southern California
  6254. +
  6255. + This program is free software; you can redistribute it and/or
  6256. + modify it under the terms of the GNU General Public License as
  6257. + published by the Free Software Foundation; either version 2, or (at
  6258. + your option) any later version.
  6259. +
  6260. + This program is distributed in the hope that it will be useful, but
  6261. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6262. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6263. + General Public License for more details.
  6264. +*/
  6265. +
  6266. +#ifndef IPKG_REMOVE_H
  6267. +#define IPKG_REMOVE_H
  6268. +
  6269. +#include "pkg.h"
  6270. +#include "ipkg_conf.h"
  6271. +
  6272. +int ipkg_remove_pkg(ipkg_conf_t *conf, pkg_t *pkg,int message);
  6273. +int ipkg_purge_pkg(ipkg_conf_t *conf, pkg_t *pkg);
  6274. +int possible_broken_removal_of_packages (ipkg_conf_t *conf, pkg_t *pkg);
  6275. +int pkg_has_installed_dependents(pkg_t *pkg, abstract_pkg_t *** pdependents);
  6276. +int remove_data_files_and_list(ipkg_conf_t *conf, pkg_t *pkg);
  6277. +int remove_maintainer_scripts_except_postrm (ipkg_conf_t *conf, pkg_t *pkg);
  6278. +int remove_postrm (ipkg_conf_t *conf, pkg_t *pkg);
  6279. +
  6280. +
  6281. +#endif
  6282. diff -Nur busybox-1.21.1.orig/archival/libipkg/ipkg_upgrade.c busybox-1.21.1/archival/libipkg/ipkg_upgrade.c
  6283. --- busybox-1.21.1.orig/archival/libipkg/ipkg_upgrade.c 1970-01-01 01:00:00.000000000 +0100
  6284. +++ busybox-1.21.1/archival/libipkg/ipkg_upgrade.c 2014-02-17 14:25:39.858534188 +0100
  6285. @@ -0,0 +1,79 @@
  6286. +/* ipkg_upgrade.c - the itsy package management system
  6287. +
  6288. + Carl D. Worth
  6289. + Copyright (C) 2001 University of Southern California
  6290. +
  6291. + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
  6292. +
  6293. + This program is free software; you can redistribute it and/or
  6294. + modify it under the terms of the GNU General Public License as
  6295. + published by the Free Software Foundation; either version 2, or (at
  6296. + your option) any later version.
  6297. +
  6298. + This program is distributed in the hope that it will be useful, but
  6299. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6300. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6301. + General Public License for more details.
  6302. +*/
  6303. +
  6304. +#include "ipkg.h"
  6305. +#include "ipkg_install.h"
  6306. +#include "ipkg_message.h"
  6307. +
  6308. +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old);
  6309. +
  6310. +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old)
  6311. +{
  6312. + pkg_t *new;
  6313. + int cmp;
  6314. + char *old_version, *new_version;
  6315. +
  6316. + if (old->state_flag & SF_HOLD) {
  6317. + ipkg_message(conf, IPKG_NOTICE,
  6318. + "Not upgrading package %s which is marked "
  6319. + "hold (flags=%#x)\n", old->name, old->state_flag);
  6320. + return 0;
  6321. + }
  6322. +
  6323. + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, old->name);
  6324. + if (new == NULL) {
  6325. + old_version = pkg_version_str_alloc(old);
  6326. + ipkg_message(conf, IPKG_NOTICE,
  6327. + "Assuming locally installed package %s (%s) "
  6328. + "is up to date.\n", old->name, old_version);
  6329. + free(old_version);
  6330. + return 0;
  6331. + }
  6332. +
  6333. + old_version = pkg_version_str_alloc(old);
  6334. + new_version = pkg_version_str_alloc(new);
  6335. +
  6336. + cmp = pkg_compare_versions(old, new);
  6337. + ipkg_message(conf, IPKG_DEBUG,
  6338. + "comparing visible versions of pkg %s:"
  6339. + "\n\t%s is installed "
  6340. + "\n\t%s is available "
  6341. + "\n\t%d was comparison result\n",
  6342. + old->name, old_version, new_version, cmp);
  6343. + if (cmp == 0) {
  6344. + ipkg_message(conf, IPKG_INFO,
  6345. + "Package %s (%s) installed in %s is up to date.\n",
  6346. + old->name, old_version, old->dest->name);
  6347. + free(old_version);
  6348. + free(new_version);
  6349. + return 0;
  6350. + } else if (cmp > 0) {
  6351. + ipkg_message(conf, IPKG_NOTICE,
  6352. + "Not downgrading package %s on %s from %s to %s.\n",
  6353. + old->name, old->dest->name, old_version, new_version);
  6354. + free(old_version);
  6355. + free(new_version);
  6356. + return 0;
  6357. + } else if (cmp < 0) {
  6358. + new->dest = old->dest;
  6359. + old->state_want = SW_DEINSTALL;
  6360. + }
  6361. +
  6362. + new->state_flag |= SF_USER;
  6363. + return ipkg_install_pkg(conf, new,1);
  6364. +}
  6365. diff -Nur busybox-1.21.1.orig/archival/libipkg/ipkg_upgrade.h busybox-1.21.1/archival/libipkg/ipkg_upgrade.h
  6366. --- busybox-1.21.1.orig/archival/libipkg/ipkg_upgrade.h 1970-01-01 01:00:00.000000000 +0100
  6367. +++ busybox-1.21.1/archival/libipkg/ipkg_upgrade.h 2014-02-17 14:25:39.862534201 +0100
  6368. @@ -0,0 +1,18 @@
  6369. +/* ipkg_upgrade.c - the itsy package management system
  6370. +
  6371. + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
  6372. +
  6373. + This program is free software; you can redistribute it and/or
  6374. + modify it under the terms of the GNU General Public License as
  6375. + published by the Free Software Foundation; either version 2, or (at
  6376. + your option) any later version.
  6377. +
  6378. + This program is distributed in the hope that it will be useful, but
  6379. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6380. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6381. + General Public License for more details.
  6382. +*/
  6383. +
  6384. +#include "ipkg.h"
  6385. +
  6386. +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old);
  6387. diff -Nur busybox-1.21.1.orig/archival/libipkg/ipkg_utils.c busybox-1.21.1/archival/libipkg/ipkg_utils.c
  6388. --- busybox-1.21.1.orig/archival/libipkg/ipkg_utils.c 1970-01-01 01:00:00.000000000 +0100
  6389. +++ busybox-1.21.1/archival/libipkg/ipkg_utils.c 2014-02-17 14:25:39.862534201 +0100
  6390. @@ -0,0 +1,185 @@
  6391. +/* ipkg_utils.c - the itsy package management system
  6392. +
  6393. + Steven M. Ayer
  6394. +
  6395. + Copyright (C) 2002 Compaq Computer Corporation
  6396. +
  6397. + This program is free software; you can redistribute it and/or
  6398. + modify it under the terms of the GNU General Public License as
  6399. + published by the Free Software Foundation; either version 2, or (at
  6400. + your option) any later version.
  6401. +
  6402. + This program is distributed in the hope that it will be useful, but
  6403. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6404. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6405. + General Public License for more details.
  6406. +*/
  6407. +
  6408. +#include "ipkg.h"
  6409. +#include <errno.h>
  6410. +#include <ctype.h>
  6411. +#include <sys/vfs.h>
  6412. +
  6413. +#include "ipkg_utils.h"
  6414. +#include "pkg.h"
  6415. +#include "pkg_hash.h"
  6416. +
  6417. +void push_error_list(struct errlist ** errors, char * msg);
  6418. +void reverse_error_list(struct errlist **errors);
  6419. +void free_error_list(struct errlist **errors);
  6420. +
  6421. +struct errlist* error_list;
  6422. +
  6423. +int get_available_blocks(char * filesystem)
  6424. +{
  6425. + struct statfs sfs;
  6426. +
  6427. + if(statfs(filesystem, &sfs)){
  6428. + fprintf(stderr, "bad statfs\n");
  6429. + return 0;
  6430. + }
  6431. + /* fprintf(stderr, "reported fs type %x\n", sfs.f_type); */
  6432. + return ((sfs.f_bavail * sfs.f_bsize) / 1024);
  6433. +}
  6434. +
  6435. +char **read_raw_pkgs_from_file(const char *file_name)
  6436. +{
  6437. + FILE *fp;
  6438. + char **ret;
  6439. +
  6440. + if(!(fp = fopen(file_name, "r"))){
  6441. + fprintf(stderr, "can't get %s open for read\n", file_name);
  6442. + return NULL;
  6443. + }
  6444. +
  6445. + ret = read_raw_pkgs_from_stream(fp);
  6446. +
  6447. + fclose(fp);
  6448. +
  6449. + return ret;
  6450. +}
  6451. +
  6452. +char **read_raw_pkgs_from_stream(FILE *fp)
  6453. +{
  6454. + char **raw = NULL, *buf, *scout;
  6455. + int count = 0;
  6456. + size_t size = 512;
  6457. +
  6458. + buf = malloc (size);
  6459. +
  6460. + while (fgets(buf, size, fp)) {
  6461. + while (strlen (buf) == (size - 1)
  6462. + && buf[size-2] != '\n') {
  6463. + size_t o = size - 1;
  6464. + size *= 2;
  6465. + buf = realloc (buf, size);
  6466. + if (fgets (buf + o, size - o, fp) == NULL)
  6467. + break;
  6468. + }
  6469. +
  6470. + if(!(count % 50))
  6471. + raw = realloc(raw, (count + 50) * sizeof(char *));
  6472. +
  6473. + if((scout = strchr(buf, '\n')))
  6474. + *scout = '\0';
  6475. +
  6476. + raw[count++] = strdup(buf);
  6477. + }
  6478. +
  6479. + raw = realloc(raw, (count + 1) * sizeof(char *));
  6480. + raw[count] = NULL;
  6481. +
  6482. + free (buf);
  6483. +
  6484. + return raw;
  6485. +}
  6486. +
  6487. +/* something to remove whitespace, a hash pooper */
  6488. +char *trim_alloc(char *line)
  6489. +{
  6490. + char *new;
  6491. + char *dest, *src, *end;
  6492. +
  6493. + new = malloc(strlen(line) + 1);
  6494. + if ( new == NULL ){
  6495. + fprintf(stderr,"%s: Unable to allocate memory\n",__FUNCTION__);
  6496. + return NULL;
  6497. + }
  6498. + dest = new, src = line, end = line + (strlen(line) - 1);
  6499. +
  6500. + /* remove it from the front */
  6501. + while(src &&
  6502. + isspace(*src) &&
  6503. + *src)
  6504. + src++;
  6505. + /* and now from the back */
  6506. + while((end > src) &&
  6507. + isspace(*end))
  6508. + end--;
  6509. + end++;
  6510. + *end = '\0';
  6511. + strcpy(new, src);
  6512. + /* this does from the first space
  6513. + * blasting away any versions stuff in depends
  6514. + while(src &&
  6515. + !isspace(*src) &&
  6516. + *src)
  6517. + *dest++ = *src++;
  6518. + *dest = '\0';
  6519. + */
  6520. +
  6521. + return new;
  6522. +}
  6523. +
  6524. +int line_is_blank(const char *line)
  6525. +{
  6526. + const char *s;
  6527. +
  6528. + for (s = line; *s; s++) {
  6529. + if (!isspace(*s))
  6530. + return 0;
  6531. + }
  6532. + return 1;
  6533. +}
  6534. +
  6535. +void push_error_list(struct errlist ** errors, char * msg){
  6536. + struct errlist *err_lst_tmp;
  6537. +
  6538. +
  6539. + err_lst_tmp = malloc ( sizeof (err_lst_tmp) );
  6540. + err_lst_tmp->errmsg=strdup(msg) ;
  6541. + err_lst_tmp->next = *errors;
  6542. + *errors = err_lst_tmp;
  6543. +}
  6544. +
  6545. +
  6546. +void reverse_error_list(struct errlist **errors){
  6547. + struct errlist *result=NULL;
  6548. + struct errlist *current= *errors;
  6549. + struct errlist *next;
  6550. +
  6551. + while ( current != NULL ) {
  6552. + next = current->next;
  6553. + current->next=result;
  6554. + result=current;
  6555. + current=next;
  6556. + }
  6557. + *errors=result;
  6558. +
  6559. +}
  6560. +
  6561. +
  6562. +void free_error_list(struct errlist **errors){
  6563. + struct errlist *current = *errors;
  6564. +
  6565. + while (current != NULL) {
  6566. + free(current->errmsg);
  6567. + current = (*errors)->next;
  6568. + free(*errors);
  6569. + *errors = current;
  6570. + }
  6571. +
  6572. +
  6573. +}
  6574. +
  6575. +
  6576. diff -Nur busybox-1.21.1.orig/archival/libipkg/ipkg_utils.h busybox-1.21.1/archival/libipkg/ipkg_utils.h
  6577. --- busybox-1.21.1.orig/archival/libipkg/ipkg_utils.h 1970-01-01 01:00:00.000000000 +0100
  6578. +++ busybox-1.21.1/archival/libipkg/ipkg_utils.h 2014-02-17 14:25:39.862534201 +0100
  6579. @@ -0,0 +1,29 @@
  6580. +/* ipkg_utils.h - the itsy package management system
  6581. +
  6582. + Steven M. Ayer
  6583. +
  6584. + Copyright (C) 2002 Compaq Computer Corporation
  6585. +
  6586. + This program is free software; you can redistribute it and/or
  6587. + modify it under the terms of the GNU General Public License as
  6588. + published by the Free Software Foundation; either version 2, or (at
  6589. + your option) any later version.
  6590. +
  6591. + This program is distributed in the hope that it will be useful, but
  6592. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6593. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6594. + General Public License for more details.
  6595. +*/
  6596. +
  6597. +#ifndef IPKG_UTILS_H
  6598. +#define IPKG_UTILS_H
  6599. +
  6600. +#include "pkg.h"
  6601. +
  6602. +int get_available_blocks(char * filesystem);
  6603. +char **read_raw_pkgs_from_file(const char *file_name);
  6604. +char **read_raw_pkgs_from_stream(FILE *fp);
  6605. +char *trim_alloc(char * line);
  6606. +int line_is_blank(const char *line);
  6607. +
  6608. +#endif
  6609. diff -Nur busybox-1.21.1.orig/archival/libipkg/Kbuild busybox-1.21.1/archival/libipkg/Kbuild
  6610. --- busybox-1.21.1.orig/archival/libipkg/Kbuild 1970-01-01 01:00:00.000000000 +0100
  6611. +++ busybox-1.21.1/archival/libipkg/Kbuild 2014-02-17 14:25:39.862534201 +0100
  6612. @@ -0,0 +1,60 @@
  6613. +# Makefile for busybox
  6614. +#
  6615. +# Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
  6616. +# Copyright (C) 2006 OpenWrt.org
  6617. +#
  6618. +# Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
  6619. +
  6620. +LIBIPKG_CORE_OBJS:= \
  6621. + args.o \
  6622. + libipkg.o \
  6623. + user.o \
  6624. +
  6625. +LIBIPKG_CMD_OBJS:= \
  6626. + ipkg_cmd.o \
  6627. + ipkg_configure.o \
  6628. + ipkg_download.o \
  6629. + ipkg_install.o \
  6630. + ipkg_remove.o \
  6631. + ipkg_upgrade.o \
  6632. +
  6633. +LIBIPKG_DB_OBJS:= \
  6634. + hash_table.o \
  6635. + ipkg_conf.o \
  6636. + ipkg_utils.o \
  6637. + pkg.o \
  6638. + pkg_depends.o \
  6639. + pkg_extract.o \
  6640. + pkg_hash.o \
  6641. + pkg_parse.o \
  6642. + pkg_vec.o \
  6643. +
  6644. +LIBIPKG_LIST_OBJS:= \
  6645. + conffile.o \
  6646. + conffile_list.o \
  6647. + nv_pair.o \
  6648. + nv_pair_list.o \
  6649. + pkg_dest.o \
  6650. + pkg_dest_list.o \
  6651. + pkg_src.o \
  6652. + pkg_src_list.o \
  6653. + str_list.o \
  6654. + void_list.o \
  6655. +
  6656. +LIBIPKG_UTIL_OBJS:= \
  6657. + file_util.o \
  6658. + ipkg_message.o \
  6659. + str_util.o \
  6660. + xsystem.o \
  6661. +
  6662. +lib-y :=
  6663. +lib-$(CONFIG_IPKG) += $(LIBIPKG_CORE_OBJS)
  6664. +lib-$(CONFIG_IPKG) += $(LIBIPKG_CMD_OBJS)
  6665. +lib-$(CONFIG_IPKG) += $(LIBIPKG_DB_OBJS)
  6666. +lib-$(CONFIG_IPKG) += $(LIBIPKG_LIST_OBJS)
  6667. +lib-$(CONFIG_IPKG) += $(LIBIPKG_UTIL_OBJS)
  6668. +
  6669. +ifeq ($(strip $(IPKG_ARCH)),)
  6670. +IPKG_ARCH:=$(TARGET_ARCH)
  6671. +endif
  6672. +CFLAGS += -DIPKGLIBDIR="\"/usr/lib\"" -DHOST_CPU_STR="\"$(IPKG_ARCH)\""
  6673. diff -Nur busybox-1.21.1.orig/archival/libipkg/libipkg.c busybox-1.21.1/archival/libipkg/libipkg.c
  6674. --- busybox-1.21.1.orig/archival/libipkg/libipkg.c 1970-01-01 01:00:00.000000000 +0100
  6675. +++ busybox-1.21.1/archival/libipkg/libipkg.c 2014-02-17 14:25:39.862534201 +0100
  6676. @@ -0,0 +1,583 @@
  6677. +/* ipkglib.c - the itsy package management system
  6678. +
  6679. + Florina Boor
  6680. +
  6681. + Copyright (C) 2003 kernel concepts
  6682. +
  6683. + This program is free software; you can redistribute it and/or
  6684. + modify it under the terms of the GNU General Public License as
  6685. + published by the Free Software Foundation; either version 2, or (at
  6686. + your option) any later version.
  6687. +
  6688. + This program is distributed in the hope that it will be useful, but
  6689. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6690. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6691. + General Public License for more details.
  6692. +*/
  6693. +
  6694. +#include "ipkg.h"
  6695. +#include "ipkg_includes.h"
  6696. +#include "libipkg.h"
  6697. +
  6698. +#include "args.h"
  6699. +#include "ipkg_conf.h"
  6700. +#include "ipkg_cmd.h"
  6701. +#include "file_util.h"
  6702. +
  6703. +int ipkg_file_what(args_t *args, const char *file, const char* command);
  6704. +int default_ipkg_message_callback(ipkg_conf_t *conf, message_level_t level,
  6705. + char *msg);
  6706. +int default_ipkg_list_callback(char *name, char *desc, char *version);
  6707. +int default_ipkg_files_callback(char *desc);
  6708. +int default_ipkg_status_callback(char *desc);
  6709. +char* default_ipkg_response_callback(char *question);
  6710. +
  6711. +
  6712. +ipkg_message_callback ipkg_cb_message = NULL;
  6713. +ipkg_response_callback ipkg_cb_response = NULL;
  6714. +ipkg_status_callback ipkg_cb_status = NULL;
  6715. +ipkg_list_callback ipkg_cb_list = NULL;
  6716. +
  6717. +
  6718. +int
  6719. +ipkg_init (ipkg_message_callback mcall,
  6720. + ipkg_response_callback rcall,
  6721. + args_t * args)
  6722. +{
  6723. + ipkg_cb_message = mcall;
  6724. + ipkg_cb_response = rcall;
  6725. +
  6726. + args_init (args);
  6727. +
  6728. + return 0;
  6729. +}
  6730. +
  6731. +
  6732. +int
  6733. +ipkg_deinit (args_t * args)
  6734. +{
  6735. + args_deinit (args);
  6736. + ipkg_cb_message = NULL;
  6737. + ipkg_cb_response = NULL;
  6738. +
  6739. + /* place other cleanup stuff here */
  6740. +
  6741. + return 0;
  6742. +}
  6743. +
  6744. +
  6745. +int
  6746. +ipkg_packages_list(args_t *args,
  6747. + const char *packages,
  6748. + ipkg_list_callback cblist,
  6749. + void *userdata)
  6750. +{
  6751. + ipkg_cmd_t *cmd;
  6752. + ipkg_conf_t ipkg_conf;
  6753. + int err;
  6754. +
  6755. + err = ipkg_conf_init (&ipkg_conf, args);
  6756. + if (err)
  6757. + {
  6758. + return err;
  6759. + }
  6760. +
  6761. + ipkg_cb_list = cblist;
  6762. + /* we need to do this because of static declarations,
  6763. + * maybe a good idea to change */
  6764. + cmd = ipkg_cmd_find ("list");
  6765. + if (packages)
  6766. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
  6767. + else
  6768. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
  6769. + ipkg_cb_list = NULL;
  6770. + ipkg_conf_deinit (&ipkg_conf);
  6771. + return (err);
  6772. +}
  6773. +
  6774. +
  6775. +int
  6776. +ipkg_packages_status(args_t *args,
  6777. + const char *packages,
  6778. + ipkg_status_callback cbstatus,
  6779. + void *userdata)
  6780. +{
  6781. + ipkg_cmd_t *cmd;
  6782. + ipkg_conf_t ipkg_conf;
  6783. + int err;
  6784. +
  6785. + err = ipkg_conf_init (&ipkg_conf, args);
  6786. + if (err)
  6787. + {
  6788. + return err;
  6789. + }
  6790. +
  6791. + ipkg_cb_status = cbstatus;
  6792. +
  6793. + /* we need to do this because of static declarations,
  6794. + * maybe a good idea to change */
  6795. + cmd = ipkg_cmd_find ("status");
  6796. + if (packages)
  6797. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
  6798. + else
  6799. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
  6800. +
  6801. + ipkg_cb_status = NULL;
  6802. + ipkg_conf_deinit (&ipkg_conf);
  6803. + return (err);
  6804. +}
  6805. +
  6806. +
  6807. +int
  6808. +ipkg_packages_info(args_t *args,
  6809. + const char *packages,
  6810. + ipkg_status_callback cbstatus,
  6811. + void *userdata)
  6812. +{
  6813. + ipkg_cmd_t *cmd;
  6814. + ipkg_conf_t ipkg_conf;
  6815. + int err;
  6816. +
  6817. + err = ipkg_conf_init (&ipkg_conf, args);
  6818. + if (err)
  6819. + {
  6820. + return err;
  6821. + }
  6822. +
  6823. + ipkg_cb_status = cbstatus;
  6824. +
  6825. + /* we need to do this because of static declarations,
  6826. + * maybe a good idea to change */
  6827. + cmd = ipkg_cmd_find ("info");
  6828. + if (packages)
  6829. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
  6830. + else
  6831. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
  6832. +
  6833. + ipkg_cb_status = NULL;
  6834. + ipkg_conf_deinit (&ipkg_conf);
  6835. + return (err);
  6836. +}
  6837. +
  6838. +
  6839. +int
  6840. +ipkg_packages_install (args_t * args, const char *name)
  6841. +{
  6842. + ipkg_cmd_t *cmd;
  6843. + ipkg_conf_t ipkg_conf;
  6844. + int err;
  6845. +
  6846. + /* this error should be handled in application */
  6847. + if (!name || !strlen (name))
  6848. + return (-1);
  6849. +
  6850. + err = ipkg_conf_init (&ipkg_conf, args);
  6851. + if (err)
  6852. + {
  6853. + return err;
  6854. + }
  6855. +
  6856. + /* we need to do this because of static declarations,
  6857. + * maybe a good idea to change */
  6858. + cmd = ipkg_cmd_find ("install");
  6859. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
  6860. +
  6861. + ipkg_conf_deinit(&ipkg_conf);
  6862. + return (err);
  6863. +}
  6864. +
  6865. +
  6866. +int
  6867. +ipkg_packages_remove(args_t *args, const char *name, int purge)
  6868. +{
  6869. + ipkg_cmd_t *cmd;
  6870. + ipkg_conf_t ipkg_conf;
  6871. + int err;
  6872. +
  6873. + /* this error should be handled in application */
  6874. + if (!name || !strlen (name))
  6875. + return (-1);
  6876. +
  6877. + err = ipkg_conf_init (&ipkg_conf, args);
  6878. + if (err)
  6879. + {
  6880. + return err;
  6881. + }
  6882. +
  6883. + /* we need to do this because of static declarations,
  6884. + * maybe a good idea to change */
  6885. + if (purge)
  6886. + cmd = ipkg_cmd_find ("purge");
  6887. + else
  6888. + cmd = ipkg_cmd_find ("remove");
  6889. +
  6890. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
  6891. +
  6892. + ipkg_conf_deinit(&ipkg_conf);
  6893. + return (err);
  6894. +}
  6895. +
  6896. +
  6897. +int
  6898. +ipkg_lists_update(args_t *args)
  6899. +{
  6900. + ipkg_cmd_t *cmd;
  6901. + ipkg_conf_t ipkg_conf;
  6902. + int err;
  6903. +
  6904. + err = ipkg_conf_init (&ipkg_conf, args);
  6905. + if (err)
  6906. + {
  6907. + return err;
  6908. + }
  6909. +
  6910. + /* we need to do this because of static declarations,
  6911. + * maybe a good idea to change */
  6912. + cmd = ipkg_cmd_find ("update");
  6913. +
  6914. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, NULL);
  6915. +
  6916. + ipkg_conf_deinit(&ipkg_conf);
  6917. + return (err);
  6918. +}
  6919. +
  6920. +
  6921. +int
  6922. +ipkg_packages_upgrade(args_t *args)
  6923. +{
  6924. + ipkg_cmd_t *cmd;
  6925. + ipkg_conf_t ipkg_conf;
  6926. + int err;
  6927. +
  6928. + err = ipkg_conf_init (&ipkg_conf, args);
  6929. + if (err)
  6930. + {
  6931. + return err;
  6932. + }
  6933. +
  6934. + /* we need to do this because of static declarations,
  6935. + * maybe a good idea to change */
  6936. + cmd = ipkg_cmd_find ("upgrade");
  6937. +
  6938. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, NULL);
  6939. +
  6940. + ipkg_conf_deinit(&ipkg_conf);
  6941. + return (err);
  6942. +}
  6943. +
  6944. +
  6945. +int
  6946. +ipkg_packages_download (args_t * args, const char *name)
  6947. +{
  6948. + ipkg_cmd_t *cmd;
  6949. + ipkg_conf_t ipkg_conf;
  6950. + int err;
  6951. +
  6952. + /* this error should be handled in application */
  6953. + if (!name || !strlen (name))
  6954. + return (-1);
  6955. +
  6956. + err = ipkg_conf_init (&ipkg_conf, args);
  6957. + if (err)
  6958. + {
  6959. + return err;
  6960. + }
  6961. +
  6962. + /* we need to do this because of static declarations,
  6963. + * maybe a good idea to change */
  6964. + cmd = ipkg_cmd_find ("download");
  6965. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
  6966. +
  6967. + ipkg_conf_deinit(&ipkg_conf);
  6968. + return (err);
  6969. +}
  6970. +
  6971. +
  6972. +int
  6973. +ipkg_package_files(args_t *args,
  6974. + const char *name,
  6975. + ipkg_list_callback cblist,
  6976. + void *userdata)
  6977. +{
  6978. + ipkg_cmd_t *cmd;
  6979. + ipkg_conf_t ipkg_conf;
  6980. + int err;
  6981. +
  6982. + /* this error should be handled in application */
  6983. + if (!name || !strlen (name))
  6984. + return (-1);
  6985. +
  6986. + err = ipkg_conf_init (&ipkg_conf, args);
  6987. + if (err)
  6988. + {
  6989. + return err;
  6990. + }
  6991. +
  6992. + ipkg_cb_list = cblist;
  6993. +
  6994. + /* we need to do this because of static declarations,
  6995. + * maybe a good idea to change */
  6996. + cmd = ipkg_cmd_find ("files");
  6997. +
  6998. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, userdata);
  6999. +
  7000. + ipkg_cb_list = NULL;
  7001. + ipkg_conf_deinit(&ipkg_conf);
  7002. + return (err);
  7003. +}
  7004. +
  7005. +
  7006. +int
  7007. +ipkg_file_search(args_t *args,
  7008. + const char *file,
  7009. + ipkg_list_callback cblist,
  7010. + void *userdata)
  7011. +{
  7012. + ipkg_cmd_t *cmd;
  7013. + ipkg_conf_t ipkg_conf;
  7014. + int err;
  7015. +
  7016. + /* this error should be handled in application */
  7017. + if (!file || !strlen (file))
  7018. + return (-1);
  7019. +
  7020. + err = ipkg_conf_init (&ipkg_conf, args);
  7021. + if (err)
  7022. + {
  7023. + return err;
  7024. + }
  7025. +
  7026. + ipkg_cb_list = cblist;
  7027. +
  7028. + /* we need to do this because of static declarations,
  7029. + * maybe a good idea to change */
  7030. + cmd = ipkg_cmd_find ("search");
  7031. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &file, userdata);
  7032. +
  7033. + ipkg_cb_list = NULL;
  7034. + ipkg_conf_deinit(&ipkg_conf);
  7035. + return(err);
  7036. +}
  7037. +
  7038. +
  7039. +int
  7040. +ipkg_file_what(args_t *args, const char *file, const char* command)
  7041. +{
  7042. + ipkg_cmd_t *cmd;
  7043. + ipkg_conf_t ipkg_conf;
  7044. + int err;
  7045. +
  7046. + /* this error should be handled in application */
  7047. + if (!file || !strlen (file))
  7048. + return (-1);
  7049. +
  7050. + err = ipkg_conf_init (&ipkg_conf, args);
  7051. + if (err)
  7052. + {
  7053. + return err;
  7054. + }
  7055. +
  7056. + /* we need to do this because of static declarations,
  7057. + * maybe a good idea to change */
  7058. + cmd = ipkg_cmd_find (command);
  7059. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &file, NULL);
  7060. +
  7061. + ipkg_conf_deinit(&ipkg_conf);
  7062. + return(err);
  7063. +}
  7064. +
  7065. +#define ipkg_package_whatdepends(args,file) ipkg_file_what(args,file,"whatdepends")
  7066. +#define ipkg_package_whatrecommends(args, file) ipkg_file_what(args,file,"whatrecommends")
  7067. +#define ipkg_package_whatprovides(args, file) ipkg_file_what(args,file,"whatprovides")
  7068. +#define ipkg_package_whatconflicts(args, file) ipkg_file_what(args,file,"whatconflicts")
  7069. +#define ipkg_package_whatreplaces(args, file) ipkg_file_what(args,file,"whatreplaces")
  7070. +
  7071. +
  7072. +int default_ipkg_message_callback(ipkg_conf_t *conf, message_level_t level,
  7073. + char *msg)
  7074. +{
  7075. + if (conf && (conf->verbosity < level)) {
  7076. + return 0;
  7077. + } else {
  7078. + if ( level == IPKG_ERROR )
  7079. + push_error_list(&error_list, msg);
  7080. + else
  7081. + printf(msg);
  7082. + }
  7083. + return 0;
  7084. +}
  7085. +
  7086. +int default_ipkg_list_callback(char *name, char *desc, char *version)
  7087. +{
  7088. + if (desc)
  7089. + printf("%s - %s - %s\n", name, version, desc);
  7090. + else
  7091. + printf("%s - %s\n", name, version);
  7092. + return 0;
  7093. +}
  7094. +
  7095. +int default_ipkg_files_callback(char *desc)
  7096. +{
  7097. + if (desc)
  7098. + printf("%s\n", desc);
  7099. + return 0;
  7100. +}
  7101. +
  7102. +int default_ipkg_status_callback(char *desc)
  7103. +{
  7104. + printf("%s\n", desc);
  7105. + return 0;
  7106. +}
  7107. +
  7108. +char* default_ipkg_response_callback(char *question)
  7109. +{
  7110. + char *response = NULL;
  7111. + printf(question);
  7112. + fflush(stdout);
  7113. + do {
  7114. + response = (char *)file_read_line_alloc(stdin);
  7115. + } while (response == NULL);
  7116. + return response;
  7117. +}
  7118. +
  7119. +/* This is used for backward compatibility */
  7120. +int
  7121. +ipkg_op (int argc, char *argv[])
  7122. +{
  7123. + int err, optind_;
  7124. + args_t args;
  7125. + char *cmd_name;
  7126. + ipkg_cmd_t *cmd;
  7127. + ipkg_conf_t ipkg_conf;
  7128. + const char *message = "ipkg must have one sub-command argument";
  7129. + FILE *f;
  7130. + struct mntent *mnt;
  7131. + int remountroot;
  7132. +
  7133. + args_init (&args);
  7134. +
  7135. + optind_ = args_parse (&args, argc, argv);
  7136. + if (optind_ == argc || optind_ < 0)
  7137. + {
  7138. + args_usage(message);
  7139. + }
  7140. +
  7141. + cmd_name = argv[optind_++];
  7142. +/* Pigi: added a flag to disable the checking of structures if the command does not need to
  7143. + read anything from there.
  7144. +*/
  7145. + if ( !strcmp(cmd_name,"print-architecture") ||
  7146. + !strcmp(cmd_name,"print_architecture") ||
  7147. + !strcmp(cmd_name,"print-installation-architecture") ||
  7148. + !strcmp(cmd_name,"print_installation_architecture") )
  7149. + args.nocheckfordirorfile = 1;
  7150. +
  7151. +/* Pigi: added a flag to disable the reading of feed files if the command does not need to
  7152. + read anything from there.
  7153. +*/
  7154. + if ( !strcmp(cmd_name,"flag") ||
  7155. + !strcmp(cmd_name,"configure") ||
  7156. + !strcmp(cmd_name,"remove") ||
  7157. + !strcmp(cmd_name,"files") ||
  7158. + !strcmp(cmd_name,"search") ||
  7159. + !strcmp(cmd_name,"compare_versions") ||
  7160. + !strcmp(cmd_name,"compare-versions") ||
  7161. + !strcmp(cmd_name,"list_installed") ||
  7162. + !strcmp(cmd_name,"list-installed") ||
  7163. + !strcmp(cmd_name,"status") )
  7164. + args.noreadfeedsfile = 1;
  7165. +
  7166. +
  7167. +
  7168. +
  7169. + err = ipkg_conf_init (&ipkg_conf, &args);
  7170. + if (err)
  7171. + {
  7172. + return err;
  7173. + }
  7174. +
  7175. + args_deinit (&args);
  7176. +
  7177. + ipkg_cb_message = default_ipkg_message_callback;
  7178. + ipkg_cb_response = default_ipkg_response_callback;
  7179. + ipkg_cb_status = (ipkg_status_callback)default_ipkg_status_callback;
  7180. + if ( strcmp(cmd_name, "files")==0)
  7181. + ipkg_cb_list = (ipkg_list_callback)default_ipkg_files_callback;
  7182. + else
  7183. + ipkg_cb_list = (ipkg_list_callback)default_ipkg_list_callback;
  7184. +
  7185. + cmd = ipkg_cmd_find (cmd_name);
  7186. + if (cmd == NULL)
  7187. + {
  7188. + fprintf (stderr, "%s: unknown sub-command %s\n", argv[0],
  7189. + cmd_name);
  7190. + args_usage (NULL);
  7191. + }
  7192. +
  7193. + if (cmd->requires_args && optind_ == argc)
  7194. + {
  7195. + fprintf (stderr,
  7196. + "%s: the ``%s'' command requires at least one argument\n",
  7197. + __FUNCTION__, cmd_name);
  7198. + args_usage (NULL);
  7199. + }
  7200. +
  7201. + remountroot = 0;
  7202. + /* check if /dev/root is mounted read-only */
  7203. + if ((f = setmntent("/proc/mounts", "r")) == NULL)
  7204. + fprintf (stderr, "Checking /proc/mounts failed\n");
  7205. +
  7206. + while ((mnt = getmntent(f)) != NULL) {
  7207. + if (strcmp(mnt->mnt_fsname, "/dev/root") == 0 &&
  7208. + hasmntopt(mnt, MNTOPT_RO) != NULL) {
  7209. + remountroot = 1;
  7210. + }
  7211. + }
  7212. +
  7213. + endmntent(f);
  7214. +
  7215. + if (remountroot) {
  7216. + if ( !strcmp(cmd_name,"install") ||
  7217. + !strcmp(cmd_name,"update") ||
  7218. + !strcmp(cmd_name,"upgrade") ||
  7219. + !strcmp(cmd_name,"flag") ||
  7220. + !strcmp(cmd_name,"configure") ||
  7221. + !strcmp(cmd_name,"remove") ) {
  7222. + /* mount rootfs read-write */
  7223. + if (mount("","/",0,MS_REMOUNT,0)<0)
  7224. + fprintf (stderr, "Mounting rootfs read-write failed\n");
  7225. + }
  7226. + }
  7227. +
  7228. + err = ipkg_cmd_exec (cmd, &ipkg_conf, argc - optind_, (const char **) (argv + optind_), NULL);
  7229. +
  7230. + ipkg_conf_deinit (&ipkg_conf);
  7231. +
  7232. + if (remountroot) {
  7233. + if ( !strcmp(cmd_name,"install") ||
  7234. + !strcmp(cmd_name,"update") ||
  7235. + !strcmp(cmd_name,"upgrade") ||
  7236. + !strcmp(cmd_name,"flag") ||
  7237. + !strcmp(cmd_name,"configure") ||
  7238. + !strcmp(cmd_name,"remove") ) {
  7239. + sync();
  7240. + /* mount rootfs read-only */
  7241. + if (mount("","/",0,MS_REMOUNT|MS_RDONLY,0)<0)
  7242. + fprintf (stderr, "Mounting rootfs read-only failed\n");
  7243. + }
  7244. + }
  7245. +
  7246. + /* check if cfgfs exists */
  7247. + if (access("/sbin/cfgfs", X_OK) == 0) {
  7248. + if ( !strcmp(cmd_name,"install") ||
  7249. + !strcmp(cmd_name,"update") ||
  7250. + !strcmp(cmd_name,"upgrade")) {
  7251. + if (system("cfgfs status -q") != 0) {
  7252. + fprintf (stdout, "Updates in /etc, please review changes\n");
  7253. + fprintf (stdout, "You can check via cfgfs status\n");
  7254. + }
  7255. + }
  7256. + }
  7257. +
  7258. + return err;
  7259. +}
  7260. diff -Nur busybox-1.21.1.orig/archival/libipkg/libipkg.h busybox-1.21.1/archival/libipkg/libipkg.h
  7261. --- busybox-1.21.1.orig/archival/libipkg/libipkg.h 1970-01-01 01:00:00.000000000 +0100
  7262. +++ busybox-1.21.1/archival/libipkg/libipkg.h 2014-02-17 14:25:39.862534201 +0100
  7263. @@ -0,0 +1,78 @@
  7264. +/* ipkglib.h - the itsy package management system
  7265. +
  7266. + Florian Boor <florian.boor@kernelconcepts.de>
  7267. +
  7268. + This program is free software; you can redistribute it and/or
  7269. + modify it under the terms of the GNU General Public License as
  7270. + published by the Free Software Foundation; either version 2, or (at
  7271. + your option) any later version.
  7272. +
  7273. + This program is distributed in the hope that it will be useful, but
  7274. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7275. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7276. + General Public License for more details.
  7277. +*/
  7278. +
  7279. +#ifndef IPKGLIB_H
  7280. +#define IPKGLIB_H
  7281. +
  7282. +#include "ipkg_conf.h"
  7283. +#include "ipkg_message.h"
  7284. +
  7285. +#include "args.h"
  7286. +#include "pkg.h"
  7287. +
  7288. +typedef int (*ipkg_message_callback)(ipkg_conf_t *conf, message_level_t level,
  7289. + char *msg);
  7290. +typedef int (*ipkg_list_callback)(char *name, char *desc, char *version,
  7291. + pkg_state_status_t status, void *userdata);
  7292. +typedef int (*ipkg_status_callback)(char *name, int istatus, char *desc,
  7293. + void *userdata);
  7294. +typedef char* (*ipkg_response_callback)(char *question);
  7295. +
  7296. +extern int ipkg_op(int argc, char *argv[]); /* ipkglib.c */
  7297. +extern int ipkg_init (ipkg_message_callback mcall,
  7298. + ipkg_response_callback rcall,
  7299. + args_t * args);
  7300. +
  7301. +extern int ipkg_deinit (args_t *args);
  7302. +extern int ipkg_packages_list(args_t *args,
  7303. + const char *packages,
  7304. + ipkg_list_callback cblist,
  7305. + void *userdata);
  7306. +extern int ipkg_packages_status(args_t *args,
  7307. + const char *packages,
  7308. + ipkg_status_callback cbstatus,
  7309. + void *userdata);
  7310. +extern int ipkg_packages_info(args_t *args,
  7311. + const char *packages,
  7312. + ipkg_status_callback cbstatus,
  7313. + void *userdata);
  7314. +extern int ipkg_packages_install(args_t *args, const char *name);
  7315. +extern int ipkg_packages_remove(args_t *args, const char *name, int purge);
  7316. +extern int ipkg_lists_update(args_t *args);
  7317. +extern int ipkg_packages_upgrade(args_t *args);
  7318. +extern int ipkg_packages_download(args_t *args, const char *name);
  7319. +extern int ipkg_package_files(args_t *args,
  7320. + const char *name,
  7321. + ipkg_list_callback cblist,
  7322. + void *userdata);
  7323. +extern int ipkg_file_search(args_t *args,
  7324. + const char *file,
  7325. + ipkg_list_callback cblist,
  7326. + void *userdata);
  7327. +extern int ipkg_package_whatdepends(args_t *args, const char *file);
  7328. +extern int ipkg_package_whatrecommends(args_t *args, const char *file);
  7329. +extern int ipkg_package_whatprovides(args_t *args, const char *file);
  7330. +extern int ipkg_package_whatconflicts(args_t *args, const char *file);
  7331. +extern int ipkg_package_whatreplaces(args_t *args, const char *file);
  7332. +
  7333. +extern ipkg_message_callback ipkg_cb_message; /* ipkglib.c */
  7334. +extern ipkg_response_callback ipkg_cb_response;
  7335. +extern ipkg_status_callback ipkg_cb_status;
  7336. +extern ipkg_list_callback ipkg_cb_list;
  7337. +extern void push_error_list(struct errlist **errors,char * msg);
  7338. +extern void reverse_error_list(struct errlist **errors);
  7339. +extern void free_error_list(struct errlist **errors);
  7340. +
  7341. +#endif
  7342. diff -Nur busybox-1.21.1.orig/archival/libipkg/nv_pair.c busybox-1.21.1/archival/libipkg/nv_pair.c
  7343. --- busybox-1.21.1.orig/archival/libipkg/nv_pair.c 1970-01-01 01:00:00.000000000 +0100
  7344. +++ busybox-1.21.1/archival/libipkg/nv_pair.c 2014-02-17 14:25:39.862534201 +0100
  7345. @@ -0,0 +1,40 @@
  7346. +/* nv_pair.c - the itsy package management system
  7347. +
  7348. + Carl D. Worth
  7349. +
  7350. + Copyright (C) 2001 University of Southern California
  7351. +
  7352. + This program is free software; you can redistribute it and/or
  7353. + modify it under the terms of the GNU General Public License as
  7354. + published by the Free Software Foundation; either version 2, or (at
  7355. + your option) any later version.
  7356. +
  7357. + This program is distributed in the hope that it will be useful, but
  7358. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7359. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7360. + General Public License for more details.
  7361. +*/
  7362. +
  7363. +#include "ipkg.h"
  7364. +
  7365. +#include "nv_pair.h"
  7366. +#include "str_util.h"
  7367. +
  7368. +int nv_pair_init(nv_pair_t *nv_pair, const char *name, const char *value)
  7369. +{
  7370. + nv_pair->name = str_dup_safe(name);
  7371. + nv_pair->value = str_dup_safe(value);
  7372. +
  7373. + return 0;
  7374. +}
  7375. +
  7376. +void nv_pair_deinit(nv_pair_t *nv_pair)
  7377. +{
  7378. + free(nv_pair->name);
  7379. + nv_pair->name = NULL;
  7380. +
  7381. + free(nv_pair->value);
  7382. + nv_pair->value = NULL;
  7383. +}
  7384. +
  7385. +
  7386. diff -Nur busybox-1.21.1.orig/archival/libipkg/nv_pair.h busybox-1.21.1/archival/libipkg/nv_pair.h
  7387. --- busybox-1.21.1.orig/archival/libipkg/nv_pair.h 1970-01-01 01:00:00.000000000 +0100
  7388. +++ busybox-1.21.1/archival/libipkg/nv_pair.h 2014-02-17 14:25:39.862534201 +0100
  7389. @@ -0,0 +1,32 @@
  7390. +/* nv_pair.h - 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. +#ifndef NV_PAIR_H
  7408. +#define NV_PAIR_H
  7409. +
  7410. +typedef struct nv_pair nv_pair_t;
  7411. +struct nv_pair
  7412. +{
  7413. + char *name;
  7414. + char *value;
  7415. +};
  7416. +
  7417. +int nv_pair_init(nv_pair_t *nv_pair, const char *name, const char *value);
  7418. +void nv_pair_deinit(nv_pair_t *nv_pair);
  7419. +
  7420. +#endif
  7421. +
  7422. diff -Nur busybox-1.21.1.orig/archival/libipkg/nv_pair_list.c busybox-1.21.1/archival/libipkg/nv_pair_list.c
  7423. --- busybox-1.21.1.orig/archival/libipkg/nv_pair_list.c 1970-01-01 01:00:00.000000000 +0100
  7424. +++ busybox-1.21.1/archival/libipkg/nv_pair_list.c 2014-02-17 14:25:39.862534201 +0100
  7425. @@ -0,0 +1,98 @@
  7426. +/* nv_pair_list.c - the itsy package management system
  7427. +
  7428. + Carl D. Worth
  7429. +
  7430. + Copyright (C) 2001 University of Southern California
  7431. +
  7432. + This program is free software; you can redistribute it and/or
  7433. + modify it under the terms of the GNU General Public License as
  7434. + published by the Free Software Foundation; either version 2, or (at
  7435. + your option) any later version.
  7436. +
  7437. + This program is distributed in the hope that it will be useful, but
  7438. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7439. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7440. + General Public License for more details.
  7441. +*/
  7442. +
  7443. +#include "ipkg.h"
  7444. +
  7445. +#include "nv_pair.h"
  7446. +#include "void_list.h"
  7447. +#include "nv_pair_list.h"
  7448. +
  7449. +int nv_pair_list_elt_init(nv_pair_list_elt_t *elt, nv_pair_t *data)
  7450. +{
  7451. + return void_list_elt_init((void_list_elt_t *) elt, data);
  7452. +}
  7453. +
  7454. +void nv_pair_list_elt_deinit(nv_pair_list_elt_t *elt)
  7455. +{
  7456. + void_list_elt_deinit((void_list_elt_t *) elt);
  7457. +}
  7458. +
  7459. +int nv_pair_list_init(nv_pair_list_t *list)
  7460. +{
  7461. + return void_list_init((void_list_t *) list);
  7462. +}
  7463. +
  7464. +void nv_pair_list_deinit(nv_pair_list_t *list)
  7465. +{
  7466. + nv_pair_list_elt_t *iter;
  7467. + nv_pair_t *nv_pair;
  7468. +
  7469. + for (iter = list->head; iter; iter = iter->next) {
  7470. + nv_pair = iter->data;
  7471. + nv_pair_deinit(nv_pair);
  7472. +
  7473. + /* malloced in nv_pair_list_append */
  7474. + free(nv_pair);
  7475. + iter->data = NULL;
  7476. + }
  7477. + void_list_deinit((void_list_t *) list);
  7478. +}
  7479. +
  7480. +nv_pair_t *nv_pair_list_append(nv_pair_list_t *list, const char *name, const char *value)
  7481. +{
  7482. + int err;
  7483. +
  7484. + /* freed in nv_pair_list_deinit */
  7485. + nv_pair_t *nv_pair = malloc(sizeof(nv_pair_t));
  7486. +
  7487. + if (nv_pair == NULL) {
  7488. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  7489. + return NULL;
  7490. + }
  7491. + nv_pair_init(nv_pair, name, value);
  7492. +
  7493. + err = void_list_append((void_list_t *) list, nv_pair);
  7494. + if (err) {
  7495. + return NULL;
  7496. + }
  7497. +
  7498. + return nv_pair;
  7499. +}
  7500. +
  7501. +int nv_pair_list_push(nv_pair_list_t *list, nv_pair_t *data)
  7502. +{
  7503. + return void_list_push((void_list_t *) list, data);
  7504. +}
  7505. +
  7506. +nv_pair_list_elt_t *nv_pair_list_pop(nv_pair_list_t *list)
  7507. +{
  7508. + return (nv_pair_list_elt_t *) void_list_pop((void_list_t *) list);
  7509. +}
  7510. +
  7511. +char *nv_pair_list_find(nv_pair_list_t *list, char *name)
  7512. +{
  7513. + nv_pair_list_elt_t *iter;
  7514. + nv_pair_t *nv_pair;
  7515. +
  7516. + for (iter = list->head; iter; iter = iter->next) {
  7517. + nv_pair = iter->data;
  7518. + if (strcmp(nv_pair->name, name) == 0) {
  7519. + return nv_pair->value;
  7520. + }
  7521. + }
  7522. + return NULL;
  7523. +}
  7524. diff -Nur busybox-1.21.1.orig/archival/libipkg/nv_pair_list.h busybox-1.21.1/archival/libipkg/nv_pair_list.h
  7525. --- busybox-1.21.1.orig/archival/libipkg/nv_pair_list.h 1970-01-01 01:00:00.000000000 +0100
  7526. +++ busybox-1.21.1/archival/libipkg/nv_pair_list.h 2014-02-17 14:25:39.862534201 +0100
  7527. @@ -0,0 +1,60 @@
  7528. +/* nv_pair_list.h - the itsy package management system
  7529. +
  7530. + Carl D. Worth
  7531. +
  7532. + Copyright (C) 2001 University of Southern California
  7533. +
  7534. + This program is free software; you can redistribute it and/or
  7535. + modify it under the terms of the GNU General Public License as
  7536. + published by the Free Software Foundation; either version 2, or (at
  7537. + your option) any later version.
  7538. +
  7539. + This program is distributed in the hope that it will be useful, but
  7540. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7541. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7542. + General Public License for more details.
  7543. +*/
  7544. +
  7545. +#ifndef NV_PAIR_LIST_H
  7546. +#define NV_PAIR_LIST_H
  7547. +
  7548. +#include "nv_pair.h"
  7549. +#include "void_list.h"
  7550. +
  7551. +typedef struct nv_pair_list_elt nv_pair_list_elt_t;
  7552. +struct nv_pair_list_elt
  7553. +{
  7554. + nv_pair_list_elt_t *next;
  7555. + nv_pair_t *data;
  7556. +};
  7557. +
  7558. +typedef struct nv_pair_list nv_pair_list_t;
  7559. +struct nv_pair_list
  7560. +{
  7561. + nv_pair_list_elt_t pre_head;
  7562. + nv_pair_list_elt_t *head;
  7563. + nv_pair_list_elt_t *tail;
  7564. +};
  7565. +
  7566. +static inline int nv_pair_list_empty(nv_pair_list_t *list)
  7567. +{
  7568. + if (list->head == NULL)
  7569. + return 1;
  7570. + else
  7571. + return 0;
  7572. +}
  7573. +
  7574. +int nv_pair_list_elt_init(nv_pair_list_elt_t *elt, nv_pair_t *data);
  7575. +void nv_pair_list_elt_deinit(nv_pair_list_elt_t *elt);
  7576. +
  7577. +int nv_pair_list_init(nv_pair_list_t *list);
  7578. +void nv_pair_list_deinit(nv_pair_list_t *list);
  7579. +
  7580. +nv_pair_t *nv_pair_list_append(nv_pair_list_t *list,
  7581. + const char *name, const char *value);
  7582. +int nv_pair_list_push(nv_pair_list_t *list, nv_pair_t *data);
  7583. +nv_pair_list_elt_t *nv_pair_list_pop(nv_pair_list_t *list);
  7584. +char *nv_pair_list_find(nv_pair_list_t *list, char *name);
  7585. +
  7586. +#endif
  7587. +
  7588. diff -Nur busybox-1.21.1.orig/archival/libipkg/pkg.c busybox-1.21.1/archival/libipkg/pkg.c
  7589. --- busybox-1.21.1.orig/archival/libipkg/pkg.c 1970-01-01 01:00:00.000000000 +0100
  7590. +++ busybox-1.21.1/archival/libipkg/pkg.c 2014-02-17 14:25:39.862534201 +0100
  7591. @@ -0,0 +1,1757 @@
  7592. +/* pkg.c - the itsy package management system
  7593. +
  7594. + Carl D. Worth
  7595. +
  7596. + Copyright (C) 2001 University of Southern California
  7597. +
  7598. + This program is free software; you can redistribute it and/or
  7599. + modify it under the terms of the GNU General Public License as
  7600. + published by the Free Software Foundation; either version 2, or (at
  7601. + your option) any later version.
  7602. +
  7603. + This program is distributed in the hope that it will be useful, but
  7604. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7605. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7606. + General Public License for more details.
  7607. +*/
  7608. +
  7609. +#include "ipkg.h"
  7610. +#include <ctype.h>
  7611. +#include <string.h>
  7612. +#include <errno.h>
  7613. +
  7614. +#include "pkg.h"
  7615. +
  7616. +#include "pkg_parse.h"
  7617. +#include "pkg_extract.h"
  7618. +#include "ipkg_message.h"
  7619. +#include "ipkg_utils.h"
  7620. +
  7621. +#include "sprintf_alloc.h"
  7622. +#include "file_util.h"
  7623. +#include "str_util.h"
  7624. +#include "xsystem.h"
  7625. +#include "ipkg_conf.h"
  7626. +
  7627. +int pkg_get_arch_priority(ipkg_conf_t *conf, const char *archname);
  7628. +void pkg_write_filelist_helper(const char *key, void *entry_, void *data_);
  7629. +
  7630. +typedef struct enum_map enum_map_t;
  7631. +struct enum_map
  7632. +{
  7633. + int value;
  7634. + const char *str;
  7635. +};
  7636. +
  7637. +static const enum_map_t pkg_state_want_map[] = {
  7638. + { SW_UNKNOWN, "unknown"},
  7639. + { SW_INSTALL, "install"},
  7640. + { SW_DEINSTALL, "deinstall"},
  7641. + { SW_PURGE, "purge"}
  7642. +};
  7643. +
  7644. +static const enum_map_t pkg_state_flag_map[] = {
  7645. + { SF_OK, "ok"},
  7646. + { SF_REINSTREQ, "reinstreq"},
  7647. + { SF_HOLD, "hold"},
  7648. + { SF_REPLACE, "replace"},
  7649. + { SF_NOPRUNE, "noprune"},
  7650. + { SF_PREFER, "prefer"},
  7651. + { SF_OBSOLETE, "obsolete"},
  7652. + { SF_USER, "user"},
  7653. +};
  7654. +
  7655. +static const enum_map_t pkg_state_status_map[] = {
  7656. + { SS_NOT_INSTALLED, "not-installed" },
  7657. + { SS_UNPACKED, "unpacked" },
  7658. + { SS_HALF_CONFIGURED, "half-configured" },
  7659. + { SS_INSTALLED, "installed" },
  7660. + { SS_HALF_INSTALLED, "half-installed" },
  7661. + { SS_CONFIG_FILES, "config-files" },
  7662. + { SS_POST_INST_FAILED, "post-inst-failed" },
  7663. + { SS_REMOVAL_FAILED, "removal-failed" }
  7664. +};
  7665. +
  7666. +static int verrevcmp(const char *val, const char *ref);
  7667. +
  7668. +
  7669. +pkg_t *pkg_new(void)
  7670. +{
  7671. + pkg_t *pkg;
  7672. +
  7673. + pkg = malloc(sizeof(pkg_t));
  7674. + if (pkg == NULL) {
  7675. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  7676. + return NULL;
  7677. + }
  7678. +
  7679. + pkg_init(pkg);
  7680. +
  7681. + return pkg;
  7682. +}
  7683. +
  7684. +int pkg_init(pkg_t *pkg)
  7685. +{
  7686. + memset(pkg, 0, sizeof(pkg_t));
  7687. + pkg->name = NULL;
  7688. + pkg->epoch = 0;
  7689. + pkg->version = NULL;
  7690. + pkg->revision = NULL;
  7691. + pkg->familiar_revision = NULL;
  7692. + pkg->dest = NULL;
  7693. + pkg->src = NULL;
  7694. + pkg->architecture = NULL;
  7695. + pkg->maintainer = NULL;
  7696. + pkg->section = NULL;
  7697. + pkg->description = NULL;
  7698. + pkg->state_want = SW_UNKNOWN;
  7699. + pkg->state_flag = SF_OK;
  7700. + pkg->state_status = SS_NOT_INSTALLED;
  7701. + pkg->depends_str = NULL;
  7702. + pkg->provides_str = NULL;
  7703. + pkg->depends_count = 0;
  7704. + pkg->depends = NULL;
  7705. + pkg->suggests_str = NULL;
  7706. + pkg->recommends_str = NULL;
  7707. + pkg->suggests_count = 0;
  7708. + pkg->recommends_count = 0;
  7709. +
  7710. + /* Abhaya: added init for conflicts fields */
  7711. + pkg->conflicts = NULL;
  7712. + pkg->conflicts_count = 0;
  7713. +
  7714. + /* added for replaces. Jamey 7/23/2002 */
  7715. + pkg->replaces = NULL;
  7716. + pkg->replaces_count = 0;
  7717. +
  7718. + pkg->pre_depends_count = 0;
  7719. + pkg->pre_depends_str = NULL;
  7720. + pkg->provides_count = 0;
  7721. + pkg->provides = NULL;
  7722. + pkg->filename = NULL;
  7723. + pkg->local_filename = NULL;
  7724. + pkg->tmp_unpack_dir = NULL;
  7725. + pkg->md5sum = NULL;
  7726. + pkg->size = NULL;
  7727. + pkg->installed_size = NULL;
  7728. + pkg->priority = NULL;
  7729. + pkg->source = NULL;
  7730. + conffile_list_init(&pkg->conffiles);
  7731. + pkg->installed_files = NULL;
  7732. + pkg->installed_files_ref_cnt = 0;
  7733. + pkg->essential = 0;
  7734. + pkg->provided_by_hand = 0;
  7735. +
  7736. + return 0;
  7737. +}
  7738. +
  7739. +void pkg_deinit(pkg_t *pkg)
  7740. +{
  7741. + free(pkg->name);
  7742. + pkg->name = NULL;
  7743. + pkg->epoch = 0;
  7744. + free(pkg->version);
  7745. + pkg->version = NULL;
  7746. + /* revision and familiar_revision share storage with version, so
  7747. + don't free */
  7748. + pkg->revision = NULL;
  7749. + pkg->familiar_revision = NULL;
  7750. + /* owned by ipkg_conf_t */
  7751. + pkg->dest = NULL;
  7752. + /* owned by ipkg_conf_t */
  7753. + pkg->src = NULL;
  7754. + free(pkg->architecture);
  7755. + pkg->architecture = NULL;
  7756. + free(pkg->maintainer);
  7757. + pkg->maintainer = NULL;
  7758. + free(pkg->section);
  7759. + pkg->section = NULL;
  7760. + free(pkg->description);
  7761. + pkg->description = NULL;
  7762. + pkg->state_want = SW_UNKNOWN;
  7763. + pkg->state_flag = SF_OK;
  7764. + pkg->state_status = SS_NOT_INSTALLED;
  7765. + free(pkg->depends_str);
  7766. + pkg->depends_str = NULL;
  7767. + free(pkg->provides_str);
  7768. + pkg->provides_str = NULL;
  7769. + pkg->depends_count = 0;
  7770. + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->depends ? */
  7771. + pkg->pre_depends_count = 0;
  7772. + free(pkg->pre_depends_str);
  7773. + pkg->pre_depends_str = NULL;
  7774. + pkg->provides_count = 0;
  7775. + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->provides ? */
  7776. + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->suggests ? */
  7777. + free(pkg->filename);
  7778. + pkg->filename = NULL;
  7779. + free(pkg->local_filename);
  7780. + pkg->local_filename = NULL;
  7781. + /* CLEANUP: It'd be nice to pullin the cleanup function from
  7782. + ipkg_install.c here. See comment in
  7783. + ipkg_install.c:cleanup_temporary_files */
  7784. + free(pkg->tmp_unpack_dir);
  7785. + pkg->tmp_unpack_dir = NULL;
  7786. + free(pkg->md5sum);
  7787. + pkg->md5sum = NULL;
  7788. + free(pkg->size);
  7789. + pkg->size = NULL;
  7790. + free(pkg->installed_size);
  7791. + pkg->installed_size = NULL;
  7792. + free(pkg->priority);
  7793. + pkg->priority = NULL;
  7794. + free(pkg->source);
  7795. + pkg->source = NULL;
  7796. + conffile_list_deinit(&pkg->conffiles);
  7797. + /* XXX: QUESTION: Is forcing this to 1 correct? I suppose so,
  7798. + since if they are calling deinit, they should know. Maybe do an
  7799. + assertion here instead? */
  7800. + pkg->installed_files_ref_cnt = 1;
  7801. + pkg_free_installed_files(pkg);
  7802. + pkg->essential = 0;
  7803. +}
  7804. +
  7805. +int pkg_init_from_file(pkg_t *pkg, const char *filename)
  7806. +{
  7807. + int err;
  7808. + char **raw;
  7809. + FILE *control_file;
  7810. +
  7811. + err = pkg_init(pkg);
  7812. + if (err) { return err; }
  7813. +
  7814. + pkg->local_filename = strdup(filename);
  7815. +
  7816. + control_file = tmpfile();
  7817. + err = pkg_extract_control_file_to_stream(pkg, control_file);
  7818. + if (err) { return err; }
  7819. +
  7820. + rewind(control_file);
  7821. + raw = read_raw_pkgs_from_stream(control_file);
  7822. + pkg_parse_raw(pkg, &raw, NULL, NULL);
  7823. +
  7824. + fclose(control_file);
  7825. +
  7826. + return 0;
  7827. +}
  7828. +
  7829. +/* Merge any new information in newpkg into oldpkg */
  7830. +/* XXX: CLEANUP: This function shouldn't actually modify anything in
  7831. + newpkg, but should leave it usable. This rework is so that
  7832. + pkg_hash_insert doesn't clobber the pkg that you pass into it. */
  7833. +/*
  7834. + * uh, i thought that i had originally written this so that it took
  7835. + * two pkgs and returned a new one? we can do that again... -sma
  7836. + */
  7837. +int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status)
  7838. +{
  7839. + if (oldpkg == newpkg) {
  7840. + return 0;
  7841. + }
  7842. +
  7843. + if (!oldpkg->src)
  7844. + oldpkg->src = newpkg->src;
  7845. + if (!oldpkg->dest)
  7846. + oldpkg->dest = newpkg->dest;
  7847. + if (!oldpkg->architecture)
  7848. + oldpkg->architecture = str_dup_safe(newpkg->architecture);
  7849. + if (!oldpkg->arch_priority)
  7850. + oldpkg->arch_priority = newpkg->arch_priority;
  7851. + if (!oldpkg->section)
  7852. + oldpkg->section = str_dup_safe(newpkg->section);
  7853. + if(!oldpkg->maintainer)
  7854. + oldpkg->maintainer = str_dup_safe(newpkg->maintainer);
  7855. + if(!oldpkg->description)
  7856. + oldpkg->description = str_dup_safe(newpkg->description);
  7857. + if (set_status) {
  7858. + /* merge the state_flags from the new package */
  7859. + oldpkg->state_want = newpkg->state_want;
  7860. + oldpkg->state_status = newpkg->state_status;
  7861. + oldpkg->state_flag = newpkg->state_flag;
  7862. + } else {
  7863. + if (oldpkg->state_want == SW_UNKNOWN)
  7864. + oldpkg->state_want = newpkg->state_want;
  7865. + if (oldpkg->state_status == SS_NOT_INSTALLED)
  7866. + oldpkg->state_status = newpkg->state_status;
  7867. + oldpkg->state_flag |= newpkg->state_flag;
  7868. + }
  7869. +
  7870. + if (!oldpkg->depends_str && !oldpkg->pre_depends_str && !oldpkg->recommends_str && !oldpkg->suggests_str) {
  7871. + oldpkg->depends_str = newpkg->depends_str;
  7872. + newpkg->depends_str = NULL;
  7873. + oldpkg->depends_count = newpkg->depends_count;
  7874. + newpkg->depends_count = 0;
  7875. +
  7876. + oldpkg->depends = newpkg->depends;
  7877. + newpkg->depends = NULL;
  7878. +
  7879. + oldpkg->pre_depends_str = newpkg->pre_depends_str;
  7880. + newpkg->pre_depends_str = NULL;
  7881. + oldpkg->pre_depends_count = newpkg->pre_depends_count;
  7882. + newpkg->pre_depends_count = 0;
  7883. +
  7884. + oldpkg->recommends_str = newpkg->recommends_str;
  7885. + newpkg->recommends_str = NULL;
  7886. + oldpkg->recommends_count = newpkg->recommends_count;
  7887. + newpkg->recommends_count = 0;
  7888. +
  7889. + oldpkg->suggests_str = newpkg->suggests_str;
  7890. + newpkg->suggests_str = NULL;
  7891. + oldpkg->suggests_count = newpkg->suggests_count;
  7892. + newpkg->suggests_count = 0;
  7893. + }
  7894. +
  7895. + if (!oldpkg->provides_str) {
  7896. + oldpkg->provides_str = newpkg->provides_str;
  7897. + newpkg->provides_str = NULL;
  7898. + oldpkg->provides_count = newpkg->provides_count;
  7899. + newpkg->provides_count = 0;
  7900. +
  7901. + oldpkg->provides = newpkg->provides;
  7902. + newpkg->provides = NULL;
  7903. + }
  7904. +
  7905. + if (!oldpkg->conflicts_str) {
  7906. + oldpkg->conflicts_str = newpkg->conflicts_str;
  7907. + newpkg->conflicts_str = NULL;
  7908. + oldpkg->conflicts_count = newpkg->conflicts_count;
  7909. + newpkg->conflicts_count = 0;
  7910. +
  7911. + oldpkg->conflicts = newpkg->conflicts;
  7912. + newpkg->conflicts = NULL;
  7913. + }
  7914. +
  7915. + if (!oldpkg->replaces_str) {
  7916. + oldpkg->replaces_str = newpkg->replaces_str;
  7917. + newpkg->replaces_str = NULL;
  7918. + oldpkg->replaces_count = newpkg->replaces_count;
  7919. + newpkg->replaces_count = 0;
  7920. +
  7921. + oldpkg->replaces = newpkg->replaces;
  7922. + newpkg->replaces = NULL;
  7923. + }
  7924. +
  7925. + if (!oldpkg->filename)
  7926. + oldpkg->filename = str_dup_safe(newpkg->filename);
  7927. + if (0)
  7928. + fprintf(stdout, "pkg=%s old local_filename=%s new local_filename=%s\n",
  7929. + oldpkg->name, oldpkg->local_filename, newpkg->local_filename);
  7930. + if (!oldpkg->local_filename)
  7931. + oldpkg->local_filename = str_dup_safe(newpkg->local_filename);
  7932. + if (!oldpkg->tmp_unpack_dir)
  7933. + oldpkg->tmp_unpack_dir = str_dup_safe(newpkg->tmp_unpack_dir);
  7934. + if (!oldpkg->md5sum)
  7935. + oldpkg->md5sum = str_dup_safe(newpkg->md5sum);
  7936. + if (!oldpkg->size)
  7937. + oldpkg->size = str_dup_safe(newpkg->size);
  7938. + if (!oldpkg->installed_size)
  7939. + oldpkg->installed_size = str_dup_safe(newpkg->installed_size);
  7940. + if (!oldpkg->priority)
  7941. + oldpkg->priority = str_dup_safe(newpkg->priority);
  7942. + if (!oldpkg->source)
  7943. + oldpkg->source = str_dup_safe(newpkg->source);
  7944. + if (oldpkg->conffiles.head == NULL){
  7945. + oldpkg->conffiles = newpkg->conffiles;
  7946. + conffile_list_init(&newpkg->conffiles);
  7947. + }
  7948. + if (!oldpkg->installed_files){
  7949. + oldpkg->installed_files = newpkg->installed_files;
  7950. + oldpkg->installed_files_ref_cnt = newpkg->installed_files_ref_cnt;
  7951. + newpkg->installed_files = NULL;
  7952. + }
  7953. + if (!oldpkg->essential)
  7954. + oldpkg->essential = newpkg->essential;
  7955. +
  7956. + return 0;
  7957. +}
  7958. +
  7959. +abstract_pkg_t *abstract_pkg_new(void)
  7960. +{
  7961. + abstract_pkg_t * ab_pkg;
  7962. +
  7963. + ab_pkg = malloc(sizeof(abstract_pkg_t));
  7964. +
  7965. + if (ab_pkg == NULL) {
  7966. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  7967. + return NULL;
  7968. + }
  7969. +
  7970. + if ( abstract_pkg_init(ab_pkg) < 0 )
  7971. + return NULL;
  7972. +
  7973. + return ab_pkg;
  7974. +}
  7975. +
  7976. +int abstract_pkg_init(abstract_pkg_t *ab_pkg)
  7977. +{
  7978. + memset(ab_pkg, 0, sizeof(abstract_pkg_t));
  7979. +
  7980. + ab_pkg->provided_by = abstract_pkg_vec_alloc();
  7981. + if (ab_pkg->provided_by==NULL){
  7982. + return -1;
  7983. + }
  7984. + ab_pkg->dependencies_checked = 0;
  7985. + ab_pkg->state_status = SS_NOT_INSTALLED;
  7986. +
  7987. + return 0;
  7988. +}
  7989. +
  7990. +void set_flags_from_control(ipkg_conf_t *conf, pkg_t *pkg){
  7991. + char * temp_str;
  7992. + char **raw =NULL;
  7993. + char **raw_start=NULL;
  7994. +
  7995. + temp_str = (char *) malloc (strlen(pkg->dest->info_dir)+strlen(pkg->name)+12);
  7996. + if (temp_str == NULL ){
  7997. + ipkg_message(conf, IPKG_INFO, "Out of memory in %s\n", __FUNCTION__);
  7998. + return;
  7999. + }
  8000. + sprintf( temp_str,"%s/%s.control",pkg->dest->info_dir,pkg->name);
  8001. +
  8002. + raw = raw_start = read_raw_pkgs_from_file(temp_str);
  8003. + if (raw == NULL ){
  8004. + ipkg_message(conf, IPKG_ERROR, "Unable to open the control file in %s\n", __FUNCTION__);
  8005. + return;
  8006. + }
  8007. +
  8008. + while(*raw){
  8009. + if (!pkg_valorize_other_field(pkg, &raw ) == 0) {
  8010. + ipkg_message(conf, IPKG_DEBUG, "unable to read control file for %s. May be empty\n", pkg->name);
  8011. + }
  8012. + }
  8013. + raw = raw_start;
  8014. + while (*raw) {
  8015. + if (raw!=NULL)
  8016. + free(*raw++);
  8017. + }
  8018. +
  8019. + free(raw_start);
  8020. + free(temp_str);
  8021. +
  8022. + return ;
  8023. +
  8024. +}
  8025. +
  8026. +char * pkg_formatted_info(pkg_t *pkg )
  8027. +{
  8028. + char *line;
  8029. + char * buff;
  8030. +
  8031. + buff = malloc(8192);
  8032. + if (buff == NULL) {
  8033. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8034. + return NULL;
  8035. + }
  8036. +
  8037. + buff[0] = '\0';
  8038. +
  8039. + line = pkg_formatted_field(pkg, "Package");
  8040. + strncat(buff ,line, strlen(line));
  8041. + free(line);
  8042. +
  8043. + line = pkg_formatted_field(pkg, "Version");
  8044. + strncat(buff ,line, strlen(line));
  8045. + free(line);
  8046. +
  8047. + line = pkg_formatted_field(pkg, "Depends");
  8048. + strncat(buff ,line, strlen(line));
  8049. + free(line);
  8050. +
  8051. + line = pkg_formatted_field(pkg, "Recommends");
  8052. + strncat(buff ,line, strlen(line));
  8053. + free(line);
  8054. +
  8055. + line = pkg_formatted_field(pkg, "Suggests");
  8056. + strncat(buff ,line, strlen(line));
  8057. + free(line);
  8058. +
  8059. + line = pkg_formatted_field(pkg, "Provides");
  8060. + strncat(buff ,line, strlen(line));
  8061. + free(line);
  8062. +
  8063. + line = pkg_formatted_field(pkg, "Replaces");
  8064. + strncat(buff ,line, strlen(line));
  8065. + free(line);
  8066. +
  8067. + line = pkg_formatted_field(pkg, "Conflicts");
  8068. + strncat(buff ,line, strlen(line));
  8069. + free(line);
  8070. +
  8071. + line = pkg_formatted_field(pkg, "Status");
  8072. + strncat(buff ,line, strlen(line));
  8073. + free(line);
  8074. +
  8075. + line = pkg_formatted_field(pkg, "Section");
  8076. + strncat(buff ,line, strlen(line));
  8077. + free(line);
  8078. +
  8079. + line = pkg_formatted_field(pkg, "Essential"); /* @@@@ should be removed in future release. *//* I do not agree with this Pigi*/
  8080. + strncat(buff ,line, strlen(line));
  8081. + free(line);
  8082. +
  8083. + line = pkg_formatted_field(pkg, "Architecture");
  8084. + strncat(buff ,line, strlen(line));
  8085. + free(line);
  8086. +
  8087. + line = pkg_formatted_field(pkg, "Maintainer");
  8088. + strncat(buff ,line, strlen(line));
  8089. + free(line);
  8090. +
  8091. + line = pkg_formatted_field(pkg, "MD5sum");
  8092. + strncat(buff ,line, strlen(line));
  8093. + free(line);
  8094. +
  8095. + line = pkg_formatted_field(pkg, "Size");
  8096. + strncat(buff ,line, strlen(line));
  8097. + free(line);
  8098. +
  8099. + line = pkg_formatted_field(pkg, "Filename");
  8100. + strncat(buff ,line, strlen(line));
  8101. + free(line);
  8102. +
  8103. + line = pkg_formatted_field(pkg, "Conffiles");
  8104. + strncat(buff ,line, strlen(line));
  8105. + free(line);
  8106. +
  8107. + line = pkg_formatted_field(pkg, "Source");
  8108. + strncat(buff ,line, strlen(line));
  8109. + free(line);
  8110. +
  8111. + line = pkg_formatted_field(pkg, "Description");
  8112. + strncat(buff ,line, strlen(line));
  8113. + free(line);
  8114. +
  8115. + line = pkg_formatted_field(pkg, "Installed-Time");
  8116. + strncat(buff ,line, strlen(line));
  8117. + free(line);
  8118. +
  8119. + return buff;
  8120. +}
  8121. +
  8122. +char * pkg_formatted_field(pkg_t *pkg, const char *field )
  8123. +{
  8124. + static size_t LINE_LEN = 128;
  8125. + char * temp = (char *)malloc(1);
  8126. + int len = 0;
  8127. + int flag_provide_false = 0;
  8128. +
  8129. +/*
  8130. + Pigi: After some discussion with Florian we decided to modify the full procedure in
  8131. + dynamic memory allocation. This should avoid any other segv in this area ( except for bugs )
  8132. +*/
  8133. +
  8134. + if (strlen(field) < PKG_MINIMUM_FIELD_NAME_LEN) {
  8135. + goto UNKNOWN_FMT_FIELD;
  8136. + }
  8137. +
  8138. + temp[0]='\0';
  8139. +
  8140. + switch (field[0])
  8141. + {
  8142. + case 'a':
  8143. + case 'A':
  8144. + if (strcasecmp(field, "Architecture") == 0) {
  8145. + /* Architecture */
  8146. + if (pkg->architecture) {
  8147. + temp = (char *)realloc(temp,strlen(pkg->architecture)+17);
  8148. + if ( temp == NULL ){
  8149. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8150. + return NULL;
  8151. + }
  8152. + temp[0]='\0';
  8153. + snprintf(temp, (strlen(pkg->architecture)+17), "Architecture: %s\n", pkg->architecture);
  8154. + }
  8155. + } else {
  8156. + goto UNKNOWN_FMT_FIELD;
  8157. + }
  8158. + break;
  8159. + case 'c':
  8160. + case 'C':
  8161. + if (strcasecmp(field, "Conffiles") == 0) {
  8162. + /* Conffiles */
  8163. + conffile_list_elt_t *iter;
  8164. + char confstr_[LINE_LEN];
  8165. +
  8166. + if (pkg->conffiles.head == NULL) {
  8167. + return temp;
  8168. + }
  8169. +
  8170. + len = 14 ;
  8171. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  8172. + if (iter->data->name && iter->data->value) {
  8173. + len = len + (strlen(iter->data->name)+strlen(iter->data->value)+5);
  8174. + }
  8175. + }
  8176. + temp = (char *)realloc(temp,len);
  8177. + if ( temp == NULL ){
  8178. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8179. + return NULL;
  8180. + }
  8181. + temp[0]='\0';
  8182. + strncpy(temp, "Conffiles:\n", 12);
  8183. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  8184. + if (iter->data->name && iter->data->value) {
  8185. + snprintf(confstr_, LINE_LEN, "%s %s\n", iter->data->name, iter->data->value);
  8186. + strncat(temp, confstr_, strlen(confstr_));
  8187. + }
  8188. + }
  8189. + } else if (strcasecmp(field, "Conflicts") == 0) {
  8190. + int i;
  8191. +
  8192. + if (pkg->conflicts_count) {
  8193. + char conflictstr[LINE_LEN];
  8194. + len = 14 ;
  8195. + for(i = 0; i < pkg->conflicts_count; i++) {
  8196. + len = len + (strlen(pkg->conflicts_str[i])+5);
  8197. + }
  8198. + temp = (char *)realloc(temp,len);
  8199. + if ( temp == NULL ){
  8200. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8201. + return NULL;
  8202. + }
  8203. + temp[0]='\0';
  8204. + strncpy(temp, "Conflicts:", 11);
  8205. + for(i = 0; i < pkg->conflicts_count; i++) {
  8206. + snprintf(conflictstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->conflicts_str[i]);
  8207. + strncat(temp, conflictstr, strlen(conflictstr));
  8208. + }
  8209. + strncat(temp, "\n", strlen("\n"));
  8210. + }
  8211. + } else {
  8212. + goto UNKNOWN_FMT_FIELD;
  8213. + }
  8214. + break;
  8215. + case 'd':
  8216. + case 'D':
  8217. + if (strcasecmp(field, "Depends") == 0) {
  8218. + /* Depends */
  8219. + int i;
  8220. +
  8221. + if (pkg->depends_count) {
  8222. + char depstr[LINE_LEN];
  8223. + len = 14 ;
  8224. + for(i = 0; i < pkg->depends_count; i++) {
  8225. + len = len + (strlen(pkg->depends_str[i])+4);
  8226. + }
  8227. + temp = (char *)realloc(temp,len);
  8228. + if ( temp == NULL ){
  8229. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8230. + return NULL;
  8231. + }
  8232. + temp[0]='\0';
  8233. + strncpy(temp, "Depends:", 10);
  8234. + for(i = 0; i < pkg->depends_count; i++) {
  8235. + snprintf(depstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->depends_str[i]);
  8236. + strncat(temp, depstr, strlen(depstr));
  8237. + }
  8238. + strncat(temp, "\n", strlen("\n"));
  8239. + }
  8240. + } else if (strcasecmp(field, "Description") == 0) {
  8241. + /* Description */
  8242. + if (pkg->description) {
  8243. + temp = (char *)realloc(temp,strlen(pkg->description)+16);
  8244. + if ( temp == NULL ){
  8245. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8246. + return NULL;
  8247. + }
  8248. + temp[0]='\0';
  8249. + snprintf(temp, (strlen(pkg->description)+16), "Description: %s\n", pkg->description);
  8250. + }
  8251. + } else {
  8252. + goto UNKNOWN_FMT_FIELD;
  8253. + }
  8254. + break;
  8255. + case 'e':
  8256. + case 'E': {
  8257. + /* Essential */
  8258. + if (pkg->essential) {
  8259. + temp = (char *)realloc(temp,16);
  8260. + if ( temp == NULL ){
  8261. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8262. + return NULL;
  8263. + }
  8264. + temp[0]='\0';
  8265. + snprintf(temp, (16), "Essential: yes\n");
  8266. + }
  8267. + }
  8268. + break;
  8269. + case 'f':
  8270. + case 'F': {
  8271. + /* Filename */
  8272. + if (pkg->filename) {
  8273. + temp = (char *)realloc(temp,strlen(pkg->filename)+12);
  8274. + if ( temp == NULL ){
  8275. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8276. + return NULL;
  8277. + }
  8278. + temp[0]='\0';
  8279. + snprintf(temp, (strlen(pkg->filename)+12), "Filename: %s\n", pkg->filename);
  8280. + }
  8281. + }
  8282. + break;
  8283. + case 'i':
  8284. + case 'I': {
  8285. + if (strcasecmp(field, "Installed-Size") == 0) {
  8286. + /* Installed-Size */
  8287. + temp = (char *)realloc(temp,strlen(pkg->installed_size)+17);
  8288. + if ( temp == NULL ){
  8289. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8290. + return NULL;
  8291. + }
  8292. + temp[0]='\0';
  8293. + snprintf(temp, (strlen(pkg->installed_size)+17), "Installed-Size: %s\n", pkg->installed_size);
  8294. + } else if (strcasecmp(field, "Installed-Time") == 0 && pkg->installed_time) {
  8295. + temp = (char *)realloc(temp,29);
  8296. + if ( temp == NULL ){
  8297. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8298. + return NULL;
  8299. + }
  8300. + temp[0]='\0';
  8301. + snprintf(temp, 29, "Installed-Time: %lu\n", pkg->installed_time);
  8302. + }
  8303. + }
  8304. + break;
  8305. + case 'm':
  8306. + case 'M': {
  8307. + /* Maintainer | MD5sum */
  8308. + if (strcasecmp(field, "Maintainer") == 0) {
  8309. + /* Maintainer */
  8310. + if (pkg->maintainer) {
  8311. + temp = (char *)realloc(temp,strlen(pkg->maintainer)+14);
  8312. + if ( temp == NULL ){
  8313. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8314. + return NULL;
  8315. + }
  8316. + temp[0]='\0';
  8317. + snprintf(temp, (strlen(pkg->maintainer)+14), "maintainer: %s\n", pkg->maintainer);
  8318. + }
  8319. + } else if (strcasecmp(field, "MD5sum") == 0) {
  8320. + /* MD5sum */
  8321. + if (pkg->md5sum) {
  8322. + temp = (char *)realloc(temp,strlen(pkg->md5sum)+11);
  8323. + if ( temp == NULL ){
  8324. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8325. + return NULL;
  8326. + }
  8327. + temp[0]='\0';
  8328. + snprintf(temp, (strlen(pkg->md5sum)+11), "MD5Sum: %s\n", pkg->md5sum);
  8329. + }
  8330. + } else {
  8331. + goto UNKNOWN_FMT_FIELD;
  8332. + }
  8333. + }
  8334. + break;
  8335. + case 'p':
  8336. + case 'P': {
  8337. + if (strcasecmp(field, "Package") == 0) {
  8338. + /* Package */
  8339. + temp = (char *)realloc(temp,strlen(pkg->name)+11);
  8340. + if ( temp == NULL ){
  8341. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8342. + return NULL;
  8343. + }
  8344. + temp[0]='\0';
  8345. + snprintf(temp, (strlen(pkg->name)+11), "Package: %s\n", pkg->name);
  8346. + } else if (strcasecmp(field, "Priority") == 0) {
  8347. + /* Priority */
  8348. + temp = (char *)realloc(temp,strlen(pkg->priority)+12);
  8349. + if ( temp == NULL ){
  8350. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8351. + return NULL;
  8352. + }
  8353. + temp[0]='\0';
  8354. + snprintf(temp, (strlen(pkg->priority)+12), "Priority: %s\n", pkg->priority);
  8355. + } else if (strcasecmp(field, "Provides") == 0) {
  8356. + /* Provides */
  8357. + int i;
  8358. +
  8359. + if (pkg->provides_count) {
  8360. + /* Here we check if the ipkg_internal_use_only is used, and we discard it.*/
  8361. + for ( i=0; i < pkg->provides_count; i++ ){
  8362. + if (strstr(pkg->provides_str[i],"ipkg_internal_use_only")!=NULL) {
  8363. + memset (pkg->provides_str[i],'\x0',strlen(pkg->provides_str[i])); /* Pigi clear my trick flag, just in case */
  8364. + flag_provide_false = 1;
  8365. + }
  8366. + }
  8367. + if ( !flag_provide_false || /* Pigi there is not my trick flag */
  8368. + ((flag_provide_false) && (pkg->provides_count > 1))){ /* Pigi There is, but we also have others Provides */
  8369. + char provstr[LINE_LEN];
  8370. + len = 15;
  8371. + for(i = 0; i < pkg->provides_count; i++) {
  8372. + len = len + (strlen(pkg->provides_str[i])+5);
  8373. + }
  8374. + temp = (char *)realloc(temp,len);
  8375. + if ( temp == NULL ){
  8376. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8377. + return NULL;
  8378. + }
  8379. + temp[0]='\0';
  8380. + strncpy(temp, "Provides:", 12);
  8381. + for(i = 0; i < pkg->provides_count; i++) {
  8382. + if (strlen(pkg->provides_str[i])>0){;
  8383. + snprintf(provstr, LINE_LEN, "%s %s", i == 1 ? "" : ",", pkg->provides_str[i]);
  8384. + strncat(temp, provstr, strlen(provstr));
  8385. + }
  8386. + }
  8387. + strncat(temp, "\n", strlen("\n"));
  8388. + }
  8389. + }
  8390. + } else {
  8391. + goto UNKNOWN_FMT_FIELD;
  8392. + }
  8393. + }
  8394. + break;
  8395. + case 'r':
  8396. + case 'R': {
  8397. + int i;
  8398. + /* Replaces | Recommends*/
  8399. + if (strcasecmp (field, "Replaces") == 0) {
  8400. + if (pkg->replaces_count) {
  8401. + char replstr[LINE_LEN];
  8402. + len = 14;
  8403. + for (i = 0; i < pkg->replaces_count; i++) {
  8404. + len = len + (strlen(pkg->replaces_str[i])+5);
  8405. + }
  8406. + temp = (char *)realloc(temp,len);
  8407. + if ( temp == NULL ){
  8408. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8409. + return NULL;
  8410. + }
  8411. + temp[0]='\0';
  8412. + strncpy(temp, "Replaces:", 12);
  8413. + for (i = 0; i < pkg->replaces_count; i++) {
  8414. + snprintf(replstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->replaces_str[i]);
  8415. + strncat(temp, replstr, strlen(replstr));
  8416. + }
  8417. + strncat(temp, "\n", strlen("\n"));
  8418. + }
  8419. + } else if (strcasecmp (field, "Recommends") == 0) {
  8420. + if (pkg->recommends_count) {
  8421. + char recstr[LINE_LEN];
  8422. + len = 15;
  8423. + for(i = 0; i < pkg->recommends_count; i++) {
  8424. + len = len + (strlen( pkg->recommends_str[i])+5);
  8425. + }
  8426. + temp = (char *)realloc(temp,len);
  8427. + if ( temp == NULL ){
  8428. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8429. + return NULL;
  8430. + }
  8431. + temp[0]='\0';
  8432. + strncpy(temp, "Recommends:", 13);
  8433. + for(i = 0; i < pkg->recommends_count; i++) {
  8434. + snprintf(recstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->recommends_str[i]);
  8435. + strncat(temp, recstr, strlen(recstr));
  8436. + }
  8437. + strncat(temp, "\n", strlen("\n"));
  8438. + }
  8439. + } else {
  8440. + goto UNKNOWN_FMT_FIELD;
  8441. + }
  8442. + }
  8443. + break;
  8444. + case 's':
  8445. + case 'S': {
  8446. + /* Section | Size | Source | Status | Suggests */
  8447. + if (strcasecmp(field, "Section") == 0) {
  8448. + /* Section */
  8449. + if (pkg->section) {
  8450. + temp = (char *)realloc(temp,strlen(pkg->section)+11);
  8451. + if ( temp == NULL ){
  8452. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8453. + return NULL;
  8454. + }
  8455. + temp[0]='\0';
  8456. + snprintf(temp, (strlen(pkg->section)+11), "Section: %s\n", pkg->section);
  8457. + }
  8458. + } else if (strcasecmp(field, "Size") == 0) {
  8459. + /* Size */
  8460. + if (pkg->size) {
  8461. + temp = (char *)realloc(temp,strlen(pkg->size)+8);
  8462. + if ( temp == NULL ){
  8463. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8464. + return NULL;
  8465. + }
  8466. + temp[0]='\0';
  8467. + snprintf(temp, (strlen(pkg->size)+8), "Size: %s\n", pkg->size);
  8468. + }
  8469. + } else if (strcasecmp(field, "Source") == 0) {
  8470. + /* Source */
  8471. + if (pkg->source) {
  8472. + temp = (char *)realloc(temp,strlen(pkg->source)+10);
  8473. + if ( temp == NULL ){
  8474. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8475. + return NULL;
  8476. + }
  8477. + temp[0]='\0';
  8478. + snprintf(temp, (strlen(pkg->source)+10), "Source: %s\n", pkg->source);
  8479. + }
  8480. + } else if (strcasecmp(field, "Status") == 0) {
  8481. + /* Status */
  8482. + /* Benjamin Pineau note: we should avoid direct usage of
  8483. + * strlen(arg) without keeping "arg" for later free()
  8484. + */
  8485. + char *pflag=pkg_state_flag_to_str(pkg->state_flag);
  8486. + char *pstat=pkg_state_status_to_str(pkg->state_status);
  8487. + char *pwant=pkg_state_want_to_str(pkg->state_want);
  8488. +
  8489. + size_t sum_of_sizes = (size_t) ( strlen(pwant)+ strlen(pflag)+ strlen(pstat) + 12 );
  8490. + temp = (char *)realloc(temp,sum_of_sizes);
  8491. + if ( temp == NULL ){
  8492. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8493. + return NULL;
  8494. + }
  8495. + temp[0]='\0';
  8496. + snprintf(temp, sum_of_sizes , "Status: %s %s %s\n", pwant, pflag, pstat);
  8497. + free(pflag);
  8498. + free(pwant);
  8499. + if(pstat) /* pfstat can be NULL if ENOMEM */
  8500. + free(pstat);
  8501. + } else if (strcasecmp(field, "Suggests") == 0) {
  8502. + if (pkg->suggests_count) {
  8503. + int i;
  8504. + char sugstr[LINE_LEN];
  8505. + len = 13;
  8506. + for(i = 0; i < pkg->suggests_count; i++) {
  8507. + len = len + (strlen(pkg->suggests_str[i])+5);
  8508. + }
  8509. + temp = (char *)realloc(temp,len);
  8510. + if ( temp == NULL ){
  8511. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8512. + return NULL;
  8513. + }
  8514. + temp[0]='\0';
  8515. + strncpy(temp, "Suggests:", 10);
  8516. + for(i = 0; i < pkg->suggests_count; i++) {
  8517. + snprintf(sugstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->suggests_str[i]);
  8518. + strncat(temp, sugstr, strlen(sugstr));
  8519. + }
  8520. + strncat(temp, "\n", strlen("\n"));
  8521. + }
  8522. + } else {
  8523. + goto UNKNOWN_FMT_FIELD;
  8524. + }
  8525. + }
  8526. + break;
  8527. + case 'v':
  8528. + case 'V': {
  8529. + /* Version */
  8530. + char *version = pkg_version_str_alloc(pkg);
  8531. + temp = (char *)realloc(temp,strlen(version)+14);
  8532. + if ( temp == NULL ){
  8533. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8534. + return NULL;
  8535. + }
  8536. + temp[0]='\0';
  8537. + snprintf(temp, (strlen(version)+12), "Version: %s\n", version);
  8538. + free(version);
  8539. + }
  8540. + break;
  8541. + default:
  8542. + goto UNKNOWN_FMT_FIELD;
  8543. + }
  8544. +
  8545. + if ( strlen(temp)<2 ) {
  8546. + temp[0]='\0';
  8547. + }
  8548. + return temp;
  8549. +
  8550. + UNKNOWN_FMT_FIELD:
  8551. + fprintf(stderr, "%s: ERROR: Unknown field name: %s\n", __FUNCTION__, field);
  8552. + if ( strlen(temp)<2 ) {
  8553. + temp[0]='\0';
  8554. + }
  8555. +
  8556. + return temp;
  8557. +}
  8558. +
  8559. +void pkg_print_info(pkg_t *pkg, FILE *file)
  8560. +{
  8561. + char * buff;
  8562. + if (pkg == NULL) {
  8563. + return;
  8564. + }
  8565. +
  8566. + buff = pkg_formatted_info(pkg);
  8567. + if ( buff == NULL )
  8568. + return;
  8569. + if (strlen(buff)>2){
  8570. + fwrite(buff, 1, strlen(buff), file);
  8571. + }
  8572. + free(buff);
  8573. +}
  8574. +
  8575. +void pkg_print_status(pkg_t * pkg, FILE * file)
  8576. +{
  8577. + if (pkg == NULL) {
  8578. + return;
  8579. + }
  8580. +
  8581. + /* XXX: QUESTION: Do we actually want more fields here? The
  8582. + original idea was to save space by installing only what was
  8583. + needed for actual computation, (package, version, status,
  8584. + essential, conffiles). The assumption is that all other fields
  8585. + can be found in th available file.
  8586. +
  8587. + But, someone proposed the idea to make it possible to
  8588. + reconstruct a .ipk from an installed package, (ie. for beaming
  8589. + from one handheld to another). So, maybe we actually want a few
  8590. + more fields here, (depends, suggests, etc.), so that that would
  8591. + be guaranteed to work even in the absence of more information
  8592. + from the available file.
  8593. +
  8594. + 28-MAR-03: kergoth and I discussed this yesterday. We think
  8595. + the essential info needs to be here for all installed packages
  8596. + because they may not appear in the Packages files on various
  8597. + feeds. Furthermore, one should be able to install from URL or
  8598. + local storage without requiring a Packages file from any feed.
  8599. + -Jamey
  8600. + */
  8601. + pkg_print_field(pkg, file, "Package");
  8602. + pkg_print_field(pkg, file, "Version");
  8603. + pkg_print_field(pkg, file, "Depends");
  8604. + pkg_print_field(pkg, file, "Recommends");
  8605. + pkg_print_field(pkg, file, "Suggests");
  8606. + pkg_print_field(pkg, file, "Provides");
  8607. + pkg_print_field(pkg, file, "Replaces");
  8608. + pkg_print_field(pkg, file, "Conflicts");
  8609. + pkg_print_field(pkg, file, "Status");
  8610. + pkg_print_field(pkg, file, "Essential"); /* @@@@ should be removed in future release. */
  8611. + pkg_print_field(pkg, file, "Architecture");
  8612. + pkg_print_field(pkg, file, "Conffiles");
  8613. + pkg_print_field(pkg, file, "Installed-Time");
  8614. + fputs("\n", file);
  8615. +}
  8616. +
  8617. +void pkg_print_field(pkg_t *pkg, FILE *file, const char *field)
  8618. +{
  8619. + char *buff;
  8620. + if (strlen(field) < PKG_MINIMUM_FIELD_NAME_LEN) {
  8621. + fprintf(stderr, "%s: ERROR: Unknown field name: %s\n",
  8622. + __FUNCTION__, field);
  8623. + }
  8624. + buff = pkg_formatted_field(pkg, field);
  8625. + if (strlen(buff)>2) {
  8626. + fprintf(file, "%s", buff);
  8627. + fflush(file);
  8628. + }
  8629. + free(buff);
  8630. + return;
  8631. +}
  8632. +
  8633. +/*
  8634. + * libdpkg - Debian packaging suite library routines
  8635. + * vercmp.c - comparison of version numbers
  8636. + *
  8637. + * Copyright (C) 1995 Ian Jackson <iwj10@cus.cam.ac.uk>
  8638. + */
  8639. +int pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg)
  8640. +{
  8641. + int r;
  8642. +
  8643. + if (pkg->epoch > ref_pkg->epoch) {
  8644. + return 1;
  8645. + }
  8646. +
  8647. + if (pkg->epoch < ref_pkg->epoch) {
  8648. + return -1;
  8649. + }
  8650. +
  8651. + r = verrevcmp(pkg->version, ref_pkg->version);
  8652. + if (r) {
  8653. + return r;
  8654. + }
  8655. +
  8656. +#ifdef USE_DEBVERSION
  8657. + r = verrevcmp(pkg->revision, ref_pkg->revision);
  8658. + if (r) {
  8659. + return r;
  8660. + }
  8661. +
  8662. + r = verrevcmp(pkg->familiar_revision, ref_pkg->familiar_revision);
  8663. +#endif
  8664. +
  8665. + return r;
  8666. +}
  8667. +
  8668. +int verrevcmp(const char *val, const char *ref)
  8669. +{
  8670. + int vc, rc;
  8671. + long vl, rl;
  8672. + const char *vp, *rp;
  8673. + const char *vsep, *rsep;
  8674. +
  8675. + if (!val) val= "";
  8676. + if (!ref) ref= "";
  8677. + for (;;) {
  8678. + vp= val; while (*vp && !isdigit(*vp)) vp++;
  8679. + rp= ref; while (*rp && !isdigit(*rp)) rp++;
  8680. + for (;;) {
  8681. + vc= (val == vp) ? 0 : *val++;
  8682. + rc= (ref == rp) ? 0 : *ref++;
  8683. + if (!rc && !vc) break;
  8684. + if (vc && !isalpha(vc)) vc += 256; /* assumes ASCII character set */
  8685. + if (rc && !isalpha(rc)) rc += 256;
  8686. + if (vc != rc) return vc - rc;
  8687. + }
  8688. + val= vp;
  8689. + ref= rp;
  8690. + vl=0; if (isdigit(*vp)) vl= strtol(val,(char**)&val,10);
  8691. + rl=0; if (isdigit(*rp)) rl= strtol(ref,(char**)&ref,10);
  8692. + if (vl != rl) return vl - rl;
  8693. +
  8694. + vc = *val;
  8695. + rc = *ref;
  8696. + vsep = strchr(".-", vc);
  8697. + rsep = strchr(".-", rc);
  8698. + if (vsep && !rsep) return -1;
  8699. + if (!vsep && rsep) return +1;
  8700. +
  8701. + if (!*val && !*ref) return 0;
  8702. + if (!*val) return -1;
  8703. + if (!*ref) return +1;
  8704. + }
  8705. +}
  8706. +
  8707. +int pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op)
  8708. +{
  8709. + int r;
  8710. +
  8711. + r = pkg_compare_versions(it, ref);
  8712. +
  8713. + if (strcmp(op, "<=") == 0 || strcmp(op, "<") == 0) {
  8714. + return r <= 0;
  8715. + }
  8716. +
  8717. + if (strcmp(op, ">=") == 0 || strcmp(op, ">") == 0) {
  8718. + return r >= 0;
  8719. + }
  8720. +
  8721. + if (strcmp(op, "<<") == 0) {
  8722. + return r < 0;
  8723. + }
  8724. +
  8725. + if (strcmp(op, ">>") == 0) {
  8726. + return r > 0;
  8727. + }
  8728. +
  8729. + if (strcmp(op, "=") == 0) {
  8730. + return r == 0;
  8731. + }
  8732. +
  8733. + fprintf(stderr, "unknown operator: %s", op);
  8734. + return 0;
  8735. +}
  8736. +
  8737. +int pkg_name_version_and_architecture_compare(pkg_t *p1, pkg_t *p2)
  8738. +{
  8739. + const pkg_t *a = *(const pkg_t **)p1;
  8740. + const pkg_t *b = *(const pkg_t **)p2;
  8741. + int namecmp;
  8742. + int vercmp;
  8743. + if (!a->name || !b->name) {
  8744. + fprintf(stderr, "pkg_name_version_and_architecture_compare: a=%p a->name=%p b=%p b->name=%p\n",
  8745. + a, a->name, b, b->name);
  8746. + return 0;
  8747. + }
  8748. +
  8749. + namecmp = strcmp(a->name, b->name);
  8750. + if (namecmp)
  8751. + return namecmp;
  8752. + vercmp = pkg_compare_versions(a, b);
  8753. + if (vercmp)
  8754. + return vercmp;
  8755. + if (!a->arch_priority || !b->arch_priority) {
  8756. + fprintf(stderr, "pkg_name_version_and_architecture_compare: a=%p a->arch_priority=%i b=%p b->arch_priority=%i\n",
  8757. + a, a->arch_priority, b, b->arch_priority);
  8758. + return 0;
  8759. + }
  8760. + if (a->arch_priority > b->arch_priority)
  8761. + return 1;
  8762. + if (a->arch_priority < b->arch_priority)
  8763. + return -1;
  8764. + return 0;
  8765. +}
  8766. +
  8767. +int abstract_pkg_name_compare(abstract_pkg_t *p1, abstract_pkg_t *p2)
  8768. +{
  8769. + const abstract_pkg_t *a = *(const abstract_pkg_t **)p1;
  8770. + const abstract_pkg_t *b = *(const abstract_pkg_t **)p2;
  8771. + if (!a->name || !b->name) {
  8772. + fprintf(stderr, "abstract_pkg_name_compare: a=%p a->name=%p b=%p b->name=%p\n",
  8773. + a, a->name, b, b->name);
  8774. + return 0;
  8775. + }
  8776. + return strcmp(a->name, b->name);
  8777. +}
  8778. +
  8779. +
  8780. +char *pkg_version_str_alloc(pkg_t *pkg)
  8781. +{
  8782. + char *complete_version;
  8783. + char *epoch_str;
  8784. +#ifdef USE_DEBVERSION
  8785. + char *revision_str;
  8786. + char *familiar_revision_str;
  8787. +#endif
  8788. +
  8789. + if (pkg->epoch) {
  8790. + sprintf_alloc(&epoch_str, "%lu:", (unsigned long)pkg->epoch);
  8791. + } else {
  8792. + epoch_str = strdup("");
  8793. + }
  8794. +
  8795. +#ifdef USE_DEBVERSION
  8796. + if (pkg->revision && strlen(pkg->revision)) {
  8797. + sprintf_alloc(&revision_str, "-%s", pkg->revision);
  8798. + } else {
  8799. + revision_str = strdup("");
  8800. + }
  8801. +
  8802. + if (pkg->familiar_revision && strlen(pkg->familiar_revision)) {
  8803. + sprintf_alloc(&familiar_revision_str, "-fam%s", pkg->familiar_revision);
  8804. + } else {
  8805. + familiar_revision_str = strdup("");
  8806. + }
  8807. +#endif
  8808. +
  8809. +#ifdef USE_DEBVERSION
  8810. + sprintf_alloc(&complete_version, "%s%s%s%s",
  8811. + epoch_str, pkg->version, revision_str, familiar_revision_str);
  8812. +#else
  8813. + sprintf_alloc(&complete_version, "%s%s",
  8814. + epoch_str, pkg->version);
  8815. +#endif
  8816. +
  8817. + free(epoch_str);
  8818. +#ifdef USE_DEBVERSION
  8819. + free(revision_str);
  8820. + free(familiar_revision_str);
  8821. +#endif
  8822. +
  8823. + return complete_version;
  8824. +}
  8825. +
  8826. +str_list_t *pkg_get_installed_files(pkg_t *pkg)
  8827. +{
  8828. + int err;
  8829. + char *list_file_name = NULL;
  8830. + FILE *list_file = NULL;
  8831. + char *line;
  8832. + char *installed_file_name;
  8833. + int rootdirlen;
  8834. +
  8835. + pkg->installed_files_ref_cnt++;
  8836. +
  8837. + if (pkg->installed_files) {
  8838. + return pkg->installed_files;
  8839. + }
  8840. +
  8841. + pkg->installed_files = str_list_alloc();
  8842. + if (pkg->installed_files == NULL) {
  8843. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8844. + return NULL;
  8845. + }
  8846. +
  8847. + /* For uninstalled packages, get the file list firectly from the package.
  8848. + For installed packages, look at the package.list file in the database.
  8849. + */
  8850. + if (pkg->state_status == SS_NOT_INSTALLED || pkg->dest == NULL) {
  8851. + if (pkg->local_filename == NULL) {
  8852. + return pkg->installed_files;
  8853. + }
  8854. + /* XXX: CLEANUP: Maybe rewrite this to avoid using a temporary
  8855. + file. In other words, change deb_extract so that it can
  8856. + simply return the file list as a char *[] rather than
  8857. + insisting on writing in to a FILE * as it does now. */
  8858. + list_file = tmpfile();
  8859. + err = pkg_extract_data_file_names_to_stream(pkg, list_file);
  8860. + if (err) {
  8861. + fclose(list_file);
  8862. + fprintf(stderr, "%s: Error extracting file list from %s: %s\n",
  8863. + __FUNCTION__, pkg->local_filename, strerror(err));
  8864. + return pkg->installed_files;
  8865. + }
  8866. + rewind(list_file);
  8867. + } else {
  8868. + sprintf_alloc(&list_file_name, "%s/%s.list",
  8869. + pkg->dest->info_dir, pkg->name);
  8870. + if (! file_exists(list_file_name)) {
  8871. + free(list_file_name);
  8872. + return pkg->installed_files;
  8873. + }
  8874. +
  8875. + list_file = fopen(list_file_name, "r");
  8876. + if (list_file == NULL) {
  8877. + fprintf(stderr, "WARNING: Cannot open %s: %s\n",
  8878. + list_file_name, strerror(errno));
  8879. + free(list_file_name);
  8880. + return pkg->installed_files;
  8881. + }
  8882. + free(list_file_name);
  8883. + }
  8884. +
  8885. + rootdirlen = strlen( pkg->dest->root_dir );
  8886. + while (1) {
  8887. + char *file_name;
  8888. +
  8889. + line = file_read_line_alloc(list_file);
  8890. + if (line == NULL) {
  8891. + break;
  8892. + }
  8893. + str_chomp(line);
  8894. + file_name = line;
  8895. +
  8896. + /* Take pains to avoid uglies like "/./" in the middle of file_name. */
  8897. + if( strncmp( pkg->dest->root_dir,
  8898. + file_name,
  8899. + rootdirlen ) ) {
  8900. + if (*file_name == '.') {
  8901. + file_name++;
  8902. + }
  8903. + if (*file_name == '/') {
  8904. + file_name++;
  8905. + }
  8906. +
  8907. + /* Freed in pkg_free_installed_files */
  8908. + sprintf_alloc(&installed_file_name, "%s%s", pkg->dest->root_dir, file_name);
  8909. + } else {
  8910. + // already contains root_dir as header -> ABSOLUTE
  8911. + sprintf_alloc(&installed_file_name, "%s", file_name);
  8912. + }
  8913. + str_list_append(pkg->installed_files, installed_file_name);
  8914. + free(line);
  8915. + }
  8916. +
  8917. + fclose(list_file);
  8918. +
  8919. + return pkg->installed_files;
  8920. +}
  8921. +
  8922. +/* XXX: CLEANUP: This function and it's counterpart,
  8923. + (pkg_get_installed_files), do not match our init/deinit naming
  8924. + convention. Nor the alloc/free convention. But, then again, neither
  8925. + of these conventions currrently fit the way these two functions
  8926. + work. */
  8927. +int pkg_free_installed_files(pkg_t *pkg)
  8928. +{
  8929. + str_list_elt_t *iter;
  8930. +
  8931. + pkg->installed_files_ref_cnt--;
  8932. + if (pkg->installed_files_ref_cnt > 0) {
  8933. + return 0;
  8934. + }
  8935. +
  8936. + if (pkg->installed_files) {
  8937. +
  8938. + for (iter = pkg->installed_files->head; iter; iter = iter->next) {
  8939. + /* malloced in pkg_get_installed_files */
  8940. + free (iter->data);
  8941. + iter->data = NULL;
  8942. + }
  8943. +
  8944. + str_list_deinit(pkg->installed_files);
  8945. + }
  8946. +
  8947. + pkg->installed_files = NULL;
  8948. +
  8949. + return 0;
  8950. +}
  8951. +
  8952. +int pkg_remove_installed_files_list(ipkg_conf_t *conf, pkg_t *pkg)
  8953. +{
  8954. + int err;
  8955. + char *list_file_name;
  8956. +
  8957. + //I don't think pkg_free_installed_files should be called here. Jamey
  8958. + //pkg_free_installed_files(pkg);
  8959. +
  8960. + sprintf_alloc(&list_file_name, "%s/%s.list",
  8961. + pkg->dest->info_dir, pkg->name);
  8962. + if (!conf->noaction) {
  8963. + err = unlink(list_file_name);
  8964. + free(list_file_name);
  8965. +
  8966. + if (err) {
  8967. + return errno;
  8968. + }
  8969. + }
  8970. + return 0;
  8971. +}
  8972. +
  8973. +conffile_t *pkg_get_conffile(pkg_t *pkg, const char *file_name)
  8974. +{
  8975. + conffile_list_elt_t *iter;
  8976. + conffile_t *conffile;
  8977. +
  8978. + if (pkg == NULL) {
  8979. + return NULL;
  8980. + }
  8981. +
  8982. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  8983. + conffile = iter->data;
  8984. +
  8985. + if (strcmp(conffile->name, file_name) == 0) {
  8986. + return conffile;
  8987. + }
  8988. + }
  8989. +
  8990. + return NULL;
  8991. +}
  8992. +
  8993. +int pkg_run_script(ipkg_conf_t *conf, pkg_t *pkg,
  8994. + const char *script, const char *args)
  8995. +{
  8996. + int err;
  8997. + char *path;
  8998. + char *cmd;
  8999. +
  9000. + /* XXX: FEATURE: When conf->offline_root is set, we should run the
  9001. + maintainer script within a chroot environment. */
  9002. +
  9003. + /* Installed packages have scripts in pkg->dest->info_dir, uninstalled packages
  9004. + have scripts in pkg->tmp_unpack_dir. */
  9005. + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) {
  9006. + if (pkg->dest == NULL) {
  9007. + fprintf(stderr, "%s: ERROR: installed package %s has a NULL dest\n",
  9008. + __FUNCTION__, pkg->name);
  9009. + return EINVAL;
  9010. + }
  9011. + sprintf_alloc(&path, "%s/%s.%s", pkg->dest->info_dir, pkg->name, script);
  9012. + } else {
  9013. + if (pkg->tmp_unpack_dir == NULL) {
  9014. + fprintf(stderr, "%s: ERROR: uninstalled package %s has a NULL tmp_unpack_dir\n",
  9015. + __FUNCTION__, pkg->name);
  9016. + return EINVAL;
  9017. + }
  9018. + sprintf_alloc(&path, "%s/%s", pkg->tmp_unpack_dir, script);
  9019. + }
  9020. +
  9021. + ipkg_message(conf, IPKG_INFO, "Running script %s\n", path);
  9022. + if (conf->noaction) return 0;
  9023. +
  9024. + /* XXX: CLEANUP: There must be a better way to handle maintainer
  9025. + scripts when running with offline_root mode and/or a dest other
  9026. + than '/'. I've been playing around with some clever chroot
  9027. + tricks and I might come up with something workable. */
  9028. + if (conf->offline_root) {
  9029. + setenv("IPKG_OFFLINE_ROOT", conf->offline_root, 1);
  9030. + }
  9031. +
  9032. + setenv("PKG_ROOT",
  9033. + pkg->dest ? pkg->dest->root_dir : conf->default_dest->root_dir, 1);
  9034. +
  9035. + if (! file_exists(path)) {
  9036. + free(path);
  9037. + return 0;
  9038. + }
  9039. +
  9040. + if (conf->offline_root) {
  9041. + fprintf(stderr, "(offline root mode: not running %s.%s)\n", pkg->name, script);
  9042. + free(path);
  9043. + return 0;
  9044. + }
  9045. +
  9046. + sprintf_alloc(&cmd, "%s %s", path, args);
  9047. + free(path);
  9048. +
  9049. + err = xsystem(cmd);
  9050. + free(cmd);
  9051. +
  9052. + if (err) {
  9053. + fprintf(stderr, "%s script returned status %d\n", script, err);
  9054. + return err;
  9055. + }
  9056. +
  9057. + return 0;
  9058. +}
  9059. +
  9060. +char *pkg_state_want_to_str(pkg_state_want_t sw)
  9061. +{
  9062. + int i;
  9063. +
  9064. + for (i=0; i < ARRAY_SIZE(pkg_state_want_map); i++) {
  9065. + if (pkg_state_want_map[i].value == sw) {
  9066. + return strdup(pkg_state_want_map[i].str);
  9067. + }
  9068. + }
  9069. +
  9070. + fprintf(stderr, "%s: ERROR: Illegal value for state_want: %d\n",
  9071. + __FUNCTION__, sw);
  9072. + return strdup("<STATE_WANT_UNKNOWN>");
  9073. +}
  9074. +
  9075. +pkg_state_want_t pkg_state_want_from_str(char *str)
  9076. +{
  9077. + int i;
  9078. +
  9079. + for (i=0; i < ARRAY_SIZE(pkg_state_want_map); i++) {
  9080. + if (strcmp(str, pkg_state_want_map[i].str) == 0) {
  9081. + return pkg_state_want_map[i].value;
  9082. + }
  9083. + }
  9084. +
  9085. + fprintf(stderr, "%s: ERROR: Illegal value for state_want string: %s\n",
  9086. + __FUNCTION__, str);
  9087. + return SW_UNKNOWN;
  9088. +}
  9089. +
  9090. +char *pkg_state_flag_to_str(pkg_state_flag_t sf)
  9091. +{
  9092. + int i;
  9093. + int len = 3; /* ok\000 is minimum */
  9094. + char *str = NULL;
  9095. +
  9096. + /* clear the temporary flags before converting to string */
  9097. + sf &= SF_NONVOLATILE_FLAGS;
  9098. +
  9099. + if (sf == 0) {
  9100. + return strdup("ok");
  9101. + } else {
  9102. +
  9103. + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
  9104. + if (sf & pkg_state_flag_map[i].value) {
  9105. + len += strlen(pkg_state_flag_map[i].str) + 1;
  9106. + }
  9107. + }
  9108. + str = malloc(len);
  9109. + if ( str == NULL ) {
  9110. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  9111. + return NULL;
  9112. + }
  9113. + str[0] = 0;
  9114. + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
  9115. + if (sf & pkg_state_flag_map[i].value) {
  9116. + strcat(str, pkg_state_flag_map[i].str);
  9117. + strcat(str, ",");
  9118. + }
  9119. + }
  9120. + len = strlen(str);
  9121. + str[len-1] = 0; /* squash last comma */
  9122. + return str;
  9123. + }
  9124. +}
  9125. +
  9126. +pkg_state_flag_t pkg_state_flag_from_str(char *str)
  9127. +{
  9128. + int i;
  9129. + int sf = SF_OK;
  9130. +
  9131. + if (strcmp(str, "ok") == 0) {
  9132. + return SF_OK;
  9133. + }
  9134. + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
  9135. + const char *sfname = pkg_state_flag_map[i].str;
  9136. + int sfname_len = strlen(sfname);
  9137. + if (strncmp(str, sfname, sfname_len) == 0) {
  9138. + sf |= pkg_state_flag_map[i].value;
  9139. + str += sfname_len;
  9140. + if (str[0] == ',') {
  9141. + str++;
  9142. + } else {
  9143. + break;
  9144. + }
  9145. + }
  9146. + }
  9147. +
  9148. + return sf;
  9149. +}
  9150. +
  9151. +char *pkg_state_status_to_str(pkg_state_status_t ss)
  9152. +{
  9153. + int i;
  9154. +
  9155. + for (i=0; i < ARRAY_SIZE(pkg_state_status_map); i++) {
  9156. + if (pkg_state_status_map[i].value == ss) {
  9157. + return strdup(pkg_state_status_map[i].str);
  9158. + }
  9159. + }
  9160. +
  9161. + fprintf(stderr, "%s: ERROR: Illegal value for state_status: %d\n",
  9162. + __FUNCTION__, ss);
  9163. + return strdup("<STATE_STATUS_UNKNOWN>");
  9164. +}
  9165. +
  9166. +pkg_state_status_t pkg_state_status_from_str(char *str)
  9167. +{
  9168. + int i;
  9169. +
  9170. + for (i=0; i < ARRAY_SIZE(pkg_state_status_map); i++) {
  9171. + if (strcmp(str, pkg_state_status_map[i].str) == 0) {
  9172. + return pkg_state_status_map[i].value;
  9173. + }
  9174. + }
  9175. +
  9176. + fprintf(stderr, "%s: ERROR: Illegal value for state_status string: %s\n",
  9177. + __FUNCTION__, str);
  9178. + return SS_NOT_INSTALLED;
  9179. +}
  9180. +
  9181. +int pkg_arch_supported(ipkg_conf_t *conf, pkg_t *pkg)
  9182. +{
  9183. + nv_pair_list_elt_t *l;
  9184. +
  9185. + if (!pkg->architecture)
  9186. + return 1;
  9187. +
  9188. + l = conf->arch_list.head;
  9189. +
  9190. + while (l) {
  9191. + nv_pair_t *nv = l->data;
  9192. + if (strcmp(nv->name, pkg->architecture) == 0) {
  9193. + ipkg_message(conf, IPKG_DEBUG, "arch %s (priority %s) supported for pkg %s\n", nv->name, nv->value, pkg->name);
  9194. + return 1;
  9195. + }
  9196. + l = l->next;
  9197. + }
  9198. +
  9199. + ipkg_message(conf, IPKG_DEBUG, "arch %s unsupported for pkg %s\n", pkg->architecture, pkg->name);
  9200. + return 0;
  9201. +}
  9202. +
  9203. +int pkg_get_arch_priority(ipkg_conf_t *conf, const char *archname)
  9204. +{
  9205. + nv_pair_list_elt_t *l;
  9206. +
  9207. + l = conf->arch_list.head;
  9208. +
  9209. + while (l) {
  9210. + nv_pair_t *nv = l->data;
  9211. + if (strcmp(nv->name, archname) == 0) {
  9212. + int priority = strtol(nv->value, NULL, 0);
  9213. + return priority;
  9214. + }
  9215. + l = l->next;
  9216. + }
  9217. + return 0;
  9218. +}
  9219. +
  9220. +int pkg_info_preinstall_check(ipkg_conf_t *conf)
  9221. +{
  9222. + int i;
  9223. + hash_table_t *pkg_hash = &conf->pkg_hash;
  9224. + pkg_vec_t *available_pkgs = pkg_vec_alloc();
  9225. + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
  9226. +
  9227. + ipkg_message(conf, IPKG_INFO, "pkg_info_preinstall_check: updating arch priority for each package\n");
  9228. + pkg_hash_fetch_available(pkg_hash, available_pkgs);
  9229. + /* update arch_priority for each package */
  9230. + for (i = 0; i < available_pkgs->len; i++) {
  9231. + pkg_t *pkg = available_pkgs->pkgs[i];
  9232. + int arch_priority = 1;
  9233. + if (!pkg)
  9234. + continue;
  9235. + // ipkg_message(conf, IPKG_DEBUG2, " package %s version=%s arch=%p:", pkg->name, pkg->version, pkg->architecture);
  9236. + if (pkg->architecture)
  9237. + arch_priority = pkg_get_arch_priority(conf, pkg->architecture);
  9238. + else
  9239. + ipkg_message(conf, IPKG_ERROR, "pkg_info_preinstall_check: no architecture for package %s\n", pkg->name);
  9240. + // ipkg_message(conf, IPKG_DEBUG2, "%s arch_priority=%d\n", pkg->architecture, arch_priority);
  9241. + pkg->arch_priority = arch_priority;
  9242. + }
  9243. +
  9244. + for (i = 0; i < available_pkgs->len; i++) {
  9245. + pkg_t *pkg = available_pkgs->pkgs[i];
  9246. + if (!pkg->arch_priority && (pkg->state_flag || (pkg->state_want != SW_UNKNOWN))) {
  9247. + /* clear flags and want for any uninstallable package */
  9248. + ipkg_message(conf, IPKG_NOTICE, "Clearing state_want and state_flag for pkg=%s (arch_priority=%d flag=%d want=%d)\n",
  9249. + pkg->name, pkg->arch_priority, pkg->state_flag, pkg->state_want);
  9250. + pkg->state_want = SW_UNKNOWN;
  9251. + pkg->state_flag = 0;
  9252. + }
  9253. + }
  9254. + pkg_vec_free(available_pkgs);
  9255. +
  9256. + /* update the file owner data structure */
  9257. + ipkg_message(conf, IPKG_INFO, "pkg_info_preinstall_check: update file owner list\n");
  9258. + pkg_hash_fetch_all_installed(pkg_hash, installed_pkgs);
  9259. + for (i = 0; i < installed_pkgs->len; i++) {
  9260. + pkg_t *pkg = installed_pkgs->pkgs[i];
  9261. + str_list_t *installed_files = pkg_get_installed_files(pkg); /* this causes installed_files to be cached */
  9262. + str_list_elt_t *iter;
  9263. + if (installed_files == NULL) {
  9264. + ipkg_message(conf, IPKG_ERROR, "No installed files for pkg %s\n", pkg->name);
  9265. + break;
  9266. + }
  9267. + for (iter = installed_files->head; iter; iter = iter->next) {
  9268. + char *installed_file = iter->data;
  9269. + // ipkg_message(conf, IPKG_DEBUG2, "pkg %s: file=%s\n", pkg->name, installed_file);
  9270. + file_hash_set_file_owner(conf, installed_file, pkg);
  9271. + }
  9272. + }
  9273. + pkg_vec_free(installed_pkgs);
  9274. +
  9275. + return 0;
  9276. +}
  9277. +
  9278. +struct pkg_write_filelist_data {
  9279. + ipkg_conf_t *conf;
  9280. + pkg_t *pkg;
  9281. + FILE *stream;
  9282. +};
  9283. +
  9284. +void pkg_write_filelist_helper(const char *key, void *entry_, void *data_)
  9285. +{
  9286. + struct pkg_write_filelist_data *data = data_;
  9287. + pkg_t *entry = entry_;
  9288. + if (entry == data->pkg) {
  9289. + fprintf(data->stream, "%s\n", key);
  9290. + }
  9291. +}
  9292. +
  9293. +int pkg_write_filelist(ipkg_conf_t *conf, pkg_t *pkg)
  9294. +{
  9295. + struct pkg_write_filelist_data data;
  9296. + char *list_file_name = NULL;
  9297. + int err = 0;
  9298. +
  9299. + if (!pkg) {
  9300. + ipkg_message(conf, IPKG_ERROR, "Null pkg\n");
  9301. + return -EINVAL;
  9302. + }
  9303. + ipkg_message(conf, IPKG_INFO,
  9304. + " creating %s.list file\n", pkg->name);
  9305. + sprintf_alloc(&list_file_name, "%s/%s.list", pkg->dest->info_dir, pkg->name);
  9306. + if (!list_file_name) {
  9307. + ipkg_message(conf, IPKG_ERROR, "Failed to alloc list_file_name\n");
  9308. + return -ENOMEM;
  9309. + }
  9310. + ipkg_message(conf, IPKG_INFO,
  9311. + " creating %s file for pkg %s\n", list_file_name, pkg->name);
  9312. + data.stream = fopen(list_file_name, "w");
  9313. + if (!data.stream) {
  9314. + ipkg_message(conf, IPKG_ERROR, "Could not open %s for writing: %s\n",
  9315. + list_file_name, strerror(errno));
  9316. + return errno;
  9317. + }
  9318. + data.pkg = pkg;
  9319. + data.conf = conf;
  9320. + hash_table_foreach(&conf->file_hash, pkg_write_filelist_helper, &data);
  9321. + fclose(data.stream);
  9322. + free(list_file_name);
  9323. +
  9324. + return err;
  9325. +}
  9326. +
  9327. +int pkg_write_changed_filelists(ipkg_conf_t *conf)
  9328. +{
  9329. + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
  9330. + hash_table_t *pkg_hash = &conf->pkg_hash;
  9331. + int i;
  9332. + int err;
  9333. + if (conf->noaction)
  9334. + return 0;
  9335. +
  9336. + ipkg_message(conf, IPKG_INFO, "%s: saving changed filelists\n", __FUNCTION__);
  9337. + pkg_hash_fetch_all_installed(pkg_hash, installed_pkgs);
  9338. + for (i = 0; i < installed_pkgs->len; i++) {
  9339. + pkg_t *pkg = installed_pkgs->pkgs[i];
  9340. + if (pkg->state_flag & SF_FILELIST_CHANGED) {
  9341. + ipkg_message(conf, IPKG_DEBUG, "Calling pkg_write_filelist for pkg=%s from %s\n", pkg->name, __FUNCTION__);
  9342. + err = pkg_write_filelist(conf, pkg);
  9343. + if (err)
  9344. + ipkg_message(conf, IPKG_NOTICE, "pkg_write_filelist pkg=%s returned %d\n", pkg->name, err);
  9345. + }
  9346. + }
  9347. + return 0;
  9348. +}
  9349. diff -Nur busybox-1.21.1.orig/archival/libipkg/pkg_depends.c busybox-1.21.1/archival/libipkg/pkg_depends.c
  9350. --- busybox-1.21.1.orig/archival/libipkg/pkg_depends.c 1970-01-01 01:00:00.000000000 +0100
  9351. +++ busybox-1.21.1/archival/libipkg/pkg_depends.c 2014-02-17 14:25:39.862534201 +0100
  9352. @@ -0,0 +1,1032 @@
  9353. +/* pkg_depends.c - the itsy package management system
  9354. +
  9355. + Steven M. Ayer
  9356. +
  9357. + Copyright (C) 2002 Compaq Computer Corporation
  9358. +
  9359. + This program is free software; you can redistribute it and/or
  9360. + modify it under the terms of the GNU General Public License as
  9361. + published by the Free Software Foundation; either version 2, or (at
  9362. + your option) any later version.
  9363. +
  9364. + This program is distributed in the hope that it will be useful, but
  9365. + WITHOUT ANY WARRANTY; without even the implied warranty of
  9366. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  9367. + General Public License for more details.
  9368. +*/
  9369. +
  9370. +#include "ipkg.h"
  9371. +#include <errno.h>
  9372. +#include <ctype.h>
  9373. +
  9374. +#include "pkg.h"
  9375. +#include "ipkg_utils.h"
  9376. +#include "pkg_hash.h"
  9377. +#include "ipkg_message.h"
  9378. +#include "pkg_parse.h"
  9379. +#include "hash_table.h"
  9380. +
  9381. +static int parseDepends(compound_depend_t *compound_depend, hash_table_t * hash, char * depend_str);
  9382. +static depend_t * depend_init(void);
  9383. +static void depend_deinit(depend_t *d);
  9384. +static char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx);
  9385. +static char ** merge_unresolved(char ** oldstuff, char ** newstuff);
  9386. +static int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg);
  9387. +int is_pkg_a_replaces(pkg_t *pkg_scout,pkg_t *pkg);
  9388. +
  9389. +static int pkg_installed_and_constraint_satisfied(pkg_t *pkg, void *cdata)
  9390. +{
  9391. + depend_t *depend = (depend_t *)cdata;
  9392. + if ((pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) && version_constraints_satisfied(depend, pkg))
  9393. + return 1;
  9394. + else
  9395. + return 0;
  9396. +}
  9397. +
  9398. +static int pkg_constraint_satisfied(pkg_t *pkg, void *cdata)
  9399. +{
  9400. + depend_t *depend = (depend_t *)cdata;
  9401. +#if 0
  9402. + pkg_t * temp = pkg_new();
  9403. + int comparison;
  9404. + parseVersion(temp, depend->version);
  9405. + comparison = pkg_compare_versions(pkg, temp);
  9406. + free(temp);
  9407. +
  9408. + fprintf(stderr, "%s: pkg=%s pkg->version=%s constraint=%p type=%d version=%s comparison=%d satisfied=%d\n",
  9409. + __FUNCTION__, pkg->name, pkg->version,
  9410. + depend, depend->constraint, depend->version,
  9411. + comparison, version_constraints_satisfied(depend, pkg));
  9412. +#endif
  9413. + if (version_constraints_satisfied(depend, pkg))
  9414. + return 1;
  9415. + else
  9416. + return 0;
  9417. +}
  9418. +
  9419. +/* returns ndependences or negative error value */
  9420. +int pkg_hash_fetch_unsatisfied_dependencies(ipkg_conf_t *conf, pkg_t * pkg,
  9421. + pkg_vec_t *unsatisfied, char *** unresolved)
  9422. +{
  9423. + pkg_t * satisfier_entry_pkg;
  9424. + register int i, j, k, l;
  9425. + int count, found;
  9426. + char ** the_lost;
  9427. + abstract_pkg_t * ab_pkg;
  9428. +
  9429. + /*
  9430. + * this is a setup to check for redundant/cyclic dependency checks,
  9431. + * which are marked at the abstract_pkg level
  9432. + */
  9433. + if (!(ab_pkg = pkg->parent)) {
  9434. + fprintf(stderr, "%s:%d: something terribly wrong with pkg %s\n", __FUNCTION__, __LINE__, pkg->name);
  9435. + *unresolved = NULL;
  9436. + return 0;
  9437. + }
  9438. + if (ab_pkg->dependencies_checked) { /* avoid duplicate or cyclic checks */
  9439. + *unresolved = NULL;
  9440. + return 0;
  9441. + } else {
  9442. + ab_pkg->dependencies_checked = 1; /* mark it for subsequent visits */
  9443. + }
  9444. + /**/
  9445. +
  9446. + count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count;
  9447. + if (!count){
  9448. + *unresolved = NULL;
  9449. + return 0;
  9450. + }
  9451. +
  9452. + the_lost = NULL;
  9453. +
  9454. + /* foreach dependency */
  9455. + for (i = 0; i < count; i++) {
  9456. + compound_depend_t * compound_depend = &pkg->depends[i];
  9457. + depend_t ** possible_satisfiers = compound_depend->possibilities;;
  9458. + found = 0;
  9459. + satisfier_entry_pkg = NULL;
  9460. +
  9461. + if (compound_depend->type == GREEDY_DEPEND) {
  9462. + /* foreach possible satisfier */
  9463. + for (j = 0; j < compound_depend->possibility_count; j++) {
  9464. + /* foreach provided_by, which includes the abstract_pkg itself */
  9465. + abstract_pkg_t *abpkg = possible_satisfiers[j]->pkg;
  9466. + abstract_pkg_vec_t *ab_provider_vec = abpkg->provided_by;
  9467. + int nposs = ab_provider_vec->len;
  9468. + abstract_pkg_t **ab_providers = ab_provider_vec->pkgs;
  9469. + for (l = 0; l < nposs; l++) {
  9470. + pkg_vec_t *test_vec = ab_providers[l]->pkgs;
  9471. + /* if no depends on this one, try the first package that Provides this one */
  9472. + if (!test_vec){ /* no pkg_vec hooked up to the abstract_pkg! (need another feed?) */
  9473. + continue;
  9474. + }
  9475. +
  9476. + /* cruise this possiblity's pkg_vec looking for an installed version */
  9477. + for (k = 0; k < test_vec->len; k++) {
  9478. + pkg_t *pkg_scout = test_vec->pkgs[k];
  9479. + /* not installed, and not already known about? */
  9480. + if ((pkg_scout->state_want != SW_INSTALL)
  9481. + && !pkg_scout->parent->dependencies_checked
  9482. + && !is_pkg_in_pkg_vec(unsatisfied, pkg_scout)) {
  9483. + char ** newstuff = NULL;
  9484. + int rc;
  9485. + pkg_vec_t *tmp_vec = pkg_vec_alloc ();
  9486. + /* check for not-already-installed dependencies */
  9487. + rc = pkg_hash_fetch_unsatisfied_dependencies(conf,
  9488. + pkg_scout,
  9489. + tmp_vec,
  9490. + &newstuff);
  9491. + if (newstuff == NULL) {
  9492. + int ok = 1;
  9493. + for (i = 0; i < rc; i++) {
  9494. + pkg_t *p = tmp_vec->pkgs[i];
  9495. + if (p->state_want == SW_INSTALL)
  9496. + continue;
  9497. + ipkg_message(conf, IPKG_DEBUG, "not installing %s due to requirement for %s\n", pkg_scout->name, p->name);
  9498. + ok = 0;
  9499. + break;
  9500. + }
  9501. + pkg_vec_free (tmp_vec);
  9502. + if (ok) {
  9503. + /* mark this one for installation */
  9504. + ipkg_message(conf, IPKG_NOTICE, "Adding satisfier for greedy dependence: %s\n", pkg_scout->name);
  9505. + pkg_vec_insert(unsatisfied, pkg_scout);
  9506. + }
  9507. + } else {
  9508. + ipkg_message(conf, IPKG_DEBUG, "not installing %s due to broken depends \n", pkg_scout->name);
  9509. + free (newstuff);
  9510. + }
  9511. + }
  9512. + }
  9513. + }
  9514. + }
  9515. +
  9516. + continue;
  9517. + }
  9518. +
  9519. + /* foreach possible satisfier, look for installed package */
  9520. + for (j = 0; j < compound_depend->possibility_count; j++) {
  9521. + /* foreach provided_by, which includes the abstract_pkg itself */
  9522. + depend_t *dependence_to_satisfy = possible_satisfiers[j];
  9523. + abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg;
  9524. + pkg_t *satisfying_pkg =
  9525. + pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg,
  9526. + pkg_installed_and_constraint_satisfied,
  9527. + dependence_to_satisfy, 1);
  9528. + /* Being that I can't test constraing in pkg_hash, I will test it here */
  9529. + if (satisfying_pkg != NULL) {
  9530. + if (!pkg_installed_and_constraint_satisfied ( satisfying_pkg,dependence_to_satisfy)) {
  9531. + satisfying_pkg = NULL;
  9532. + }
  9533. + }
  9534. + ipkg_message(conf, IPKG_DEBUG, "%s:%d: satisfying_pkg=%p \n", __FILE__, __LINE__, satisfying_pkg);
  9535. + if (satisfying_pkg != NULL) {
  9536. + found = 1;
  9537. + break;
  9538. + }
  9539. +
  9540. + }
  9541. + /* if nothing installed matches, then look for uninstalled satisfier */
  9542. + if (!found) {
  9543. + /* foreach possible satisfier, look for installed package */
  9544. + for (j = 0; j < compound_depend->possibility_count; j++) {
  9545. + /* foreach provided_by, which includes the abstract_pkg itself */
  9546. + depend_t *dependence_to_satisfy = possible_satisfiers[j];
  9547. + abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg;
  9548. + pkg_t *satisfying_pkg =
  9549. + pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg,
  9550. + pkg_constraint_satisfied,
  9551. + dependence_to_satisfy, 1);
  9552. + /* Being that I can't test constraing in pkg_hash, I will test it here too */
  9553. + if (satisfying_pkg != NULL) {
  9554. + if (!pkg_constraint_satisfied ( satisfying_pkg,dependence_to_satisfy)) {
  9555. + satisfying_pkg = NULL;
  9556. + }
  9557. + }
  9558. +
  9559. + /* user request overrides package recommendation */
  9560. + if (satisfying_pkg != NULL
  9561. + && (compound_depend->type == RECOMMEND || compound_depend->type == SUGGEST)
  9562. + && (satisfying_pkg->state_want == SW_DEINSTALL || satisfying_pkg->state_want == SW_PURGE)) {
  9563. + ipkg_message (conf, IPKG_NOTICE, "%s: ignoring recommendation for %s at user request\n",
  9564. + pkg->name, satisfying_pkg->name);
  9565. + continue;
  9566. + }
  9567. +
  9568. + ipkg_message(conf, IPKG_DEBUG, "%s:%d: satisfying_pkg=%p\n", __FILE__, __LINE__, satisfying_pkg);
  9569. + if (satisfying_pkg != NULL) {
  9570. + satisfier_entry_pkg = satisfying_pkg;
  9571. + break;
  9572. + }
  9573. + }
  9574. + }
  9575. +
  9576. + /* we didn't find one, add something to the unsatisfied vector */
  9577. + if (!found) {
  9578. + if (!satisfier_entry_pkg) {
  9579. + /* failure to meet recommendations is not an error */
  9580. + if (compound_depend->type != RECOMMEND && compound_depend->type != SUGGEST)
  9581. + the_lost = add_unresolved_dep(pkg, the_lost, i);
  9582. + else
  9583. + ipkg_message (conf, IPKG_NOTICE, "%s: unsatisfied recommendation for %s\n",
  9584. + pkg->name, compound_depend->possibilities[0]->pkg->name);
  9585. + }
  9586. + else {
  9587. + if (compound_depend->type == SUGGEST) {
  9588. + /* just mention it politely */
  9589. + ipkg_message (conf, IPKG_NOTICE, "package %s suggests installing %s\n",
  9590. + pkg->name, satisfier_entry_pkg->name);
  9591. + } else {
  9592. + char ** newstuff = NULL;
  9593. +
  9594. + if (satisfier_entry_pkg != pkg &&
  9595. + !is_pkg_in_pkg_vec(unsatisfied, satisfier_entry_pkg)) {
  9596. + pkg_vec_insert(unsatisfied, satisfier_entry_pkg);
  9597. + pkg_hash_fetch_unsatisfied_dependencies(conf,
  9598. + satisfier_entry_pkg,
  9599. + unsatisfied,
  9600. + &newstuff);
  9601. + the_lost = merge_unresolved(the_lost, newstuff);
  9602. + }
  9603. + }
  9604. + }
  9605. + }
  9606. + }
  9607. + *unresolved = the_lost;
  9608. +
  9609. + return unsatisfied->len;
  9610. +}
  9611. +
  9612. +/*checking for conflicts !in replaces
  9613. + If a packages conflicts with another but is also replacing it, I should not consider it a
  9614. + really conflicts
  9615. + returns 0 if conflicts <> replaces or 1 if conflicts == replaces
  9616. +*/
  9617. +int is_pkg_a_replaces(pkg_t *pkg_scout,pkg_t *pkg)
  9618. +{
  9619. + int i ;
  9620. + int replaces_count = pkg->replaces_count;
  9621. + abstract_pkg_t **replaces;
  9622. +
  9623. + if (pkg->replaces_count==0) // No replaces, it's surely a conflict
  9624. + return 0;
  9625. +
  9626. + replaces = pkg->replaces;
  9627. +
  9628. + for (i = 0; i < replaces_count; i++) {
  9629. + if (strcmp(pkg_scout->name,pkg->replaces[i]->name)==0) { // Found
  9630. + ipkg_message(NULL, IPKG_DEBUG2, "Seems I've found a replace %s %s \n",pkg_scout->name,pkg->replaces[i]->name);
  9631. + return 1;
  9632. + }
  9633. + }
  9634. + return 0;
  9635. +
  9636. +}
  9637. +
  9638. +
  9639. +/* Abhaya: added support for conflicts */
  9640. +pkg_vec_t * pkg_hash_fetch_conflicts(pkg_t * pkg)
  9641. +{
  9642. + pkg_vec_t * installed_conflicts, * test_vec;
  9643. + compound_depend_t * conflicts;
  9644. + depend_t ** possible_satisfiers;
  9645. + depend_t * possible_satisfier;
  9646. + register int i, j, k;
  9647. + int count;
  9648. + abstract_pkg_t * ab_pkg;
  9649. + pkg_t **pkg_scouts;
  9650. + pkg_t *pkg_scout;
  9651. +
  9652. + /*
  9653. + * this is a setup to check for redundant/cyclic dependency checks,
  9654. + * which are marked at the abstract_pkg level
  9655. + */
  9656. + if(!(ab_pkg = pkg->parent)){
  9657. + fprintf(stderr, "dependency check error. pkg %s isn't in hash table\n", pkg->name);
  9658. + return (pkg_vec_t *)NULL;
  9659. + }
  9660. +
  9661. + conflicts = pkg->conflicts;
  9662. + if(!conflicts){
  9663. + return (pkg_vec_t *)NULL;
  9664. + }
  9665. + installed_conflicts = pkg_vec_alloc();
  9666. +
  9667. + count = pkg->conflicts_count;
  9668. +
  9669. +
  9670. +
  9671. + /* foreach conflict */
  9672. + for(i = 0; i < pkg->conflicts_count; i++){
  9673. +
  9674. + possible_satisfiers = conflicts->possibilities;
  9675. +
  9676. + /* foreach possible satisfier */
  9677. + for(j = 0; j < conflicts->possibility_count; j++){
  9678. + possible_satisfier = possible_satisfiers[j];
  9679. + if (!possible_satisfier)
  9680. + fprintf(stderr, "%s:%d: possible_satisfier is null\n", __FUNCTION__, __LINE__);
  9681. + if (!possible_satisfier->pkg)
  9682. + fprintf(stderr, "%s:%d: possible_satisfier->pkg is null\n", __FUNCTION__, __LINE__);
  9683. + test_vec = possible_satisfier->pkg->pkgs;
  9684. + if (test_vec) {
  9685. + /* pkg_vec found, it is an actual package conflict
  9686. + * cruise this possiblity's pkg_vec looking for an installed version */
  9687. + pkg_scouts = test_vec->pkgs;
  9688. + for(k = 0; k < test_vec->len; k++){
  9689. + pkg_scout = pkg_scouts[k];
  9690. + if (!pkg_scout) {
  9691. + fprintf(stderr, "%s: null pkg scout\n", __FUNCTION__);
  9692. + continue;
  9693. + }
  9694. + if ((pkg_scout->state_status == SS_INSTALLED || pkg_scout->state_want == SW_INSTALL) &&
  9695. + version_constraints_satisfied(possible_satisfier, pkg_scout) && !is_pkg_a_replaces(pkg_scout,pkg)){
  9696. + if (!is_pkg_in_pkg_vec(installed_conflicts, pkg_scout)){
  9697. + pkg_vec_insert(installed_conflicts, pkg_scout);
  9698. + }
  9699. + }
  9700. + }
  9701. + }
  9702. + }
  9703. + conflicts++;
  9704. + }
  9705. +
  9706. + if (installed_conflicts->len)
  9707. + return installed_conflicts;
  9708. + pkg_vec_free(installed_conflicts);
  9709. + return (pkg_vec_t *)NULL;
  9710. +}
  9711. +
  9712. +int version_constraints_satisfied(depend_t * depends, pkg_t * pkg)
  9713. +{
  9714. + pkg_t * temp;
  9715. + int comparison;
  9716. +
  9717. + if(depends->constraint == NONE)
  9718. + return 1;
  9719. +
  9720. + temp = pkg_new();
  9721. +
  9722. + parseVersion(temp, depends->version);
  9723. +
  9724. + comparison = pkg_compare_versions(pkg, temp);
  9725. +
  9726. + free(temp);
  9727. +
  9728. + if((depends->constraint == EARLIER) &&
  9729. + (comparison < 0))
  9730. + return 1;
  9731. + else if((depends->constraint == LATER) &&
  9732. + (comparison > 0))
  9733. + return 1;
  9734. + else if(comparison == 0)
  9735. + return 1;
  9736. + else if((depends->constraint == LATER_EQUAL) &&
  9737. + (comparison >= 0))
  9738. + return 1;
  9739. + else if((depends->constraint == EARLIER_EQUAL) &&
  9740. + (comparison <= 0))
  9741. + return 1;
  9742. +
  9743. + return 0;
  9744. +}
  9745. +
  9746. +int pkg_dependence_satisfiable(depend_t *depend)
  9747. +{
  9748. + abstract_pkg_t *apkg = depend->pkg;
  9749. + abstract_pkg_vec_t *provider_apkgs = apkg->provided_by;
  9750. + int n_providers = provider_apkgs->len;
  9751. + abstract_pkg_t **apkgs = provider_apkgs->pkgs;
  9752. + pkg_vec_t *pkg_vec;
  9753. + int n_pkgs ;
  9754. + int i;
  9755. + int j;
  9756. +
  9757. + for (i = 0; i < n_providers; i++) {
  9758. + abstract_pkg_t *papkg = apkgs[i];
  9759. + pkg_vec = papkg->pkgs;
  9760. + if (pkg_vec) {
  9761. + n_pkgs = pkg_vec->len;
  9762. + for (j = 0; j < n_pkgs; j++) {
  9763. + pkg_t *pkg = pkg_vec->pkgs[j];
  9764. + if (version_constraints_satisfied(depend, pkg)) {
  9765. + return 1;
  9766. + }
  9767. + }
  9768. + }
  9769. + }
  9770. + return 0;
  9771. +}
  9772. +
  9773. +int pkg_dependence_satisfied(depend_t *depend)
  9774. +{
  9775. + abstract_pkg_t *apkg = depend->pkg;
  9776. + abstract_pkg_vec_t *provider_apkgs = apkg->provided_by;
  9777. + int n_providers = provider_apkgs->len;
  9778. + abstract_pkg_t **apkgs = provider_apkgs->pkgs;
  9779. + int i;
  9780. + int n_pkgs;
  9781. + int j;
  9782. +
  9783. + for (i = 0; i < n_providers; i++) {
  9784. + abstract_pkg_t *papkg = apkgs[i];
  9785. + pkg_vec_t *pkg_vec = papkg->pkgs;
  9786. + if (pkg_vec) {
  9787. + n_pkgs = pkg_vec->len;
  9788. + for (j = 0; j < n_pkgs; j++) {
  9789. + pkg_t *pkg = pkg_vec->pkgs[j];
  9790. + if (version_constraints_satisfied(depend, pkg)) {
  9791. + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED)
  9792. + return 1;
  9793. + }
  9794. + }
  9795. + }
  9796. + }
  9797. + return 0;
  9798. +}
  9799. +
  9800. +static int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg)
  9801. +{
  9802. + register int i;
  9803. + pkg_t ** pkgs = vec->pkgs;
  9804. +
  9805. + for(i = 0; i < vec->len; i++)
  9806. + if((strcmp(pkg->name, (*(pkgs + i))->name) == 0)
  9807. + && (pkg_compare_versions(pkg, *(pkgs + i)) == 0)
  9808. + && (strcmp(pkg->architecture, (*(pkgs + i))->architecture) == 0))
  9809. + return 1;
  9810. + return 0;
  9811. +}
  9812. +
  9813. +
  9814. +#ifdef DeadCode
  9815. +/**
  9816. + * pkg_has_common_provides returns 1 if pkg and replacee both provide
  9817. + * the same abstract package and 0 otherwise.
  9818. + */
  9819. +int pkg_has_common_provides(pkg_t *pkg, pkg_t *replacee)
  9820. +{
  9821. + abstract_pkg_t **provides = pkg->provides;
  9822. + int provides_count = pkg->provides_count;
  9823. + abstract_pkg_t **replacee_provides = replacee->provides;
  9824. + int replacee_provides_count = replacee->provides_count;
  9825. + int i, j;
  9826. + for (i = 0; i < provides_count; i++) {
  9827. + abstract_pkg_t *apkg = provides[i];
  9828. + for (j = 0; j < replacee_provides_count; j++) {
  9829. + abstract_pkg_t *replacee_apkg = replacee_provides[i];
  9830. + if (apkg == replacee_apkg)
  9831. + return 1;
  9832. + }
  9833. + }
  9834. + return 0;
  9835. +}
  9836. +#endif
  9837. +
  9838. +/**
  9839. + * pkg_provides_abstract returns 1 if pkg->provides contains providee
  9840. + * and 0 otherwise.
  9841. + */
  9842. +int pkg_provides_abstract(pkg_t *pkg, abstract_pkg_t *providee)
  9843. +{
  9844. + abstract_pkg_t **provides = pkg->provides;
  9845. + int provides_count = pkg->provides_count;
  9846. + int i;
  9847. + for (i = 0; i < provides_count; i++) {
  9848. + if (provides[i] == providee)
  9849. + return 1;
  9850. + }
  9851. + return 0;
  9852. +}
  9853. +
  9854. +/**
  9855. + * pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0
  9856. + * otherwise.
  9857. + */
  9858. +int pkg_replaces(pkg_t *pkg, pkg_t *replacee)
  9859. +{
  9860. + abstract_pkg_t **replaces = pkg->replaces;
  9861. + int replaces_count = pkg->replaces_count;
  9862. + /* abstract_pkg_t **replacee_provides = pkg->provides;
  9863. + int replacee_provides_count = pkg->provides_count; */
  9864. + int i, j;
  9865. + for (i = 0; i < replaces_count; i++) {
  9866. + abstract_pkg_t *abstract_replacee = replaces[i];
  9867. + for (j = 0; j < replaces_count; j++) {
  9868. + /* ipkg_message(NULL, IPKG_DEBUG2, "Searching pkg-name %s repprovname %s absrepname %s \n",
  9869. + pkg->name,replacee->provides[j]->name, abstract_replacee->name); */
  9870. + if (replacee->provides[j] == abstract_replacee)
  9871. + return 1;
  9872. + }
  9873. + }
  9874. + return 0;
  9875. +}
  9876. +
  9877. +
  9878. +/**
  9879. + * pkg_conflicts_abstract returns 1 if pkg->conflicts contains conflictee and 0
  9880. + * otherwise.
  9881. + */
  9882. +int pkg_conflicts_abstract(pkg_t *pkg, abstract_pkg_t *conflictee)
  9883. +{
  9884. + compound_depend_t *conflicts = pkg->conflicts;
  9885. + int conflicts_count = pkg->conflicts_count;
  9886. + int i, j;
  9887. + for (i = 0; i < conflicts_count; i++) {
  9888. + int possibility_count = conflicts[i].possibility_count;
  9889. + struct depend **possibilities = conflicts[i].possibilities;
  9890. + for (j = 0; j < possibility_count; j++) {
  9891. + if (possibilities[j]->pkg == conflictee) {
  9892. + return 1;
  9893. + }
  9894. + }
  9895. + }
  9896. + return 0;
  9897. +}
  9898. +
  9899. +/**
  9900. + * pkg_conflicts returns 1 if pkg->conflicts contains one of
  9901. + * conflictee's provides and 0 otherwise.
  9902. + */
  9903. +int pkg_conflicts(pkg_t *pkg, pkg_t *conflictee)
  9904. +{
  9905. + compound_depend_t *conflicts = pkg->conflicts;
  9906. + int conflicts_count = pkg->conflicts_count;
  9907. + abstract_pkg_t **conflictee_provides = conflictee->provides;
  9908. + int conflictee_provides_count = conflictee->provides_count;
  9909. + int i, j, k;
  9910. + int possibility_count;
  9911. + struct depend **possibilities;
  9912. + abstract_pkg_t *possibility ;
  9913. +
  9914. + for (i = 0; i < conflicts_count; i++) {
  9915. + possibility_count = conflicts[i].possibility_count;
  9916. + possibilities = conflicts[i].possibilities;
  9917. + for (j = 0; j < possibility_count; j++) {
  9918. + possibility = possibilities[j]->pkg;
  9919. + for (k = 0; k < conflictee_provides_count; k++) {
  9920. + if (possibility == conflictee_provides[k]) {
  9921. + return 1;
  9922. + }
  9923. + }
  9924. + }
  9925. + }
  9926. + return 0;
  9927. +}
  9928. +
  9929. +static char ** merge_unresolved(char ** oldstuff, char ** newstuff)
  9930. +{
  9931. + int oldlen = 0, newlen = 0;
  9932. + char ** result;
  9933. + register int i, j;
  9934. +
  9935. + if(!newstuff)
  9936. + return oldstuff;
  9937. +
  9938. + while(oldstuff && oldstuff[oldlen]) oldlen++;
  9939. + while(newstuff && newstuff[newlen]) newlen++;
  9940. +
  9941. + result = (char **)realloc(oldstuff, sizeof(char *) * (oldlen + newlen + 1));
  9942. + if (result == NULL) {
  9943. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  9944. + return NULL;
  9945. + }
  9946. +
  9947. + for(i = oldlen, j = 0; i < (oldlen + newlen); i++, j++)
  9948. + *(result + i) = *(newstuff + j);
  9949. +
  9950. + *(result + i) = NULL;
  9951. +
  9952. + return result;
  9953. +}
  9954. +
  9955. +/*
  9956. + * a kinda kludgy way to back out depends str from two different arrays (reg'l'r 'n pre)
  9957. + * this is null terminated, no count is carried around
  9958. + */
  9959. +char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx)
  9960. +{
  9961. + int count;
  9962. + char ** resized;
  9963. + char *depend_str = pkg_depend_str(pkg, ref_ndx);
  9964. +
  9965. + count = 0;
  9966. + while(the_lost && the_lost[count]) count++;
  9967. +
  9968. + count++; /* need one to hold the null */
  9969. + resized = (char **)realloc(the_lost, sizeof(char *) * (count + 1));
  9970. + if (resized == NULL) {
  9971. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  9972. + return NULL;
  9973. + }
  9974. + resized[count - 1] = strdup(depend_str);
  9975. + resized[count] = NULL;
  9976. +
  9977. + return resized;
  9978. +}
  9979. +
  9980. +void printDepends(pkg_t * pkg)
  9981. +{
  9982. + register int i, j;
  9983. + compound_depend_t * depend;
  9984. + int count;
  9985. +
  9986. + count = pkg->pre_depends_count + pkg->depends_count;
  9987. +
  9988. + depend = pkg->depends;
  9989. + if(!depend){
  9990. + fprintf(stderr, "Depends pointer is NULL\n");
  9991. + return;
  9992. + }
  9993. + for(i = 0; i < count; i++){
  9994. + fprintf(stderr, "%s has %d possibilities:\n",
  9995. + (depend->type == GREEDY_DEPEND) ? "Greedy-Depend" : ((depend->type == DEPEND) ? "Depend" : "Pre-Depend"),
  9996. + depend->possibility_count);
  9997. + for(j = 0; j < depend->possibility_count; j++)
  9998. + fprintf(stderr, "\t%s version %s (%d)\n",
  9999. + depend->possibilities[j]->pkg->name,
  10000. + depend->possibilities[j]->version,
  10001. + depend->possibilities[j]->constraint);
  10002. + depend++;
  10003. + }
  10004. +}
  10005. +
  10006. +int buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
  10007. +{
  10008. + register int i, j;
  10009. +
  10010. + /* every pkg provides itself */
  10011. + abstract_pkg_vec_insert(ab_pkg->provided_by, ab_pkg);
  10012. +
  10013. + if (!pkg->provides_count)
  10014. + return 0;
  10015. +
  10016. + pkg->provides = (abstract_pkg_t **)malloc(sizeof(abstract_pkg_t *) * (pkg->provides_count + 1));
  10017. + if (pkg->provides == NULL) {
  10018. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10019. + return -1 ;
  10020. + }
  10021. + pkg->provides[0] = ab_pkg;
  10022. +
  10023. + // if (strcmp(ab_pkg->name, pkg->name))
  10024. + // fprintf(stderr, __FUNCTION__ ": ab_pkg=%s pkg=%s\n", ab_pkg->name, pkg->name);
  10025. +
  10026. + for(i = 0; i < pkg->provides_count; i++){
  10027. + abstract_pkg_t *provided_abpkg = ensure_abstract_pkg_by_name(hash, pkg->provides_str[i]);
  10028. +
  10029. + pkg->provides[i+1] = provided_abpkg;
  10030. +
  10031. + j = 0;
  10032. + abstract_pkg_vec_insert(provided_abpkg->provided_by, ab_pkg);
  10033. + }
  10034. + return 0;
  10035. +}
  10036. +
  10037. +/* Abhaya: added conflicts support */
  10038. +int buildConflicts(hash_table_t * hash, pkg_t * pkg)
  10039. +{
  10040. + register int i;
  10041. + compound_depend_t * conflicts;
  10042. +
  10043. + if (!pkg->conflicts_count)
  10044. + return 0;
  10045. +
  10046. + conflicts = pkg->conflicts = malloc(sizeof(compound_depend_t) *
  10047. + pkg->conflicts_count);
  10048. + if (conflicts == NULL) {
  10049. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10050. + return -1;
  10051. + }
  10052. + for (i = 0; i < pkg->conflicts_count; i++) {
  10053. + conflicts->type = CONFLICTS;
  10054. + parseDepends(conflicts, hash,
  10055. + pkg->conflicts_str[i]);
  10056. +#if 0
  10057. + for (j = 0; j < conflicts->possibility_count; j++) {
  10058. + depend_t *possibility = conflicts->possibilities[j];
  10059. + abstract_pkg_t *conflicting_apkg = possibility->pkg;
  10060. + pkg_add_conflict_pair(ab_pkg, conflicting_apkg);
  10061. + }
  10062. +#endif
  10063. + conflicts++;
  10064. + }
  10065. + return 0;
  10066. +}
  10067. +
  10068. +int buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
  10069. +{
  10070. + register int i, j;
  10071. +
  10072. + if (!pkg->replaces_count)
  10073. + return 0;
  10074. +
  10075. + pkg->replaces = (abstract_pkg_t **)malloc(sizeof(abstract_pkg_t *) * pkg->replaces_count);
  10076. + if (pkg->replaces == NULL) {
  10077. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10078. + return -1;
  10079. + }
  10080. +
  10081. + // if (strcmp(ab_pkg->name, pkg->name))
  10082. + // fprintf(stderr, __FUNCTION__ ": ab_pkg=%s pkg=%s\n", ab_pkg->name, pkg->name);
  10083. +
  10084. + for(i = 0; i < pkg->replaces_count; i++){
  10085. + abstract_pkg_t *old_abpkg = ensure_abstract_pkg_by_name(hash, pkg->replaces_str[i]);
  10086. +
  10087. + pkg->replaces[i] = old_abpkg;
  10088. +
  10089. + j = 0;
  10090. + if (!old_abpkg->replaced_by)
  10091. + old_abpkg->replaced_by = abstract_pkg_vec_alloc();
  10092. + if ( old_abpkg->replaced_by == NULL ){
  10093. + return -1;
  10094. + }
  10095. + /* if a package pkg both replaces and conflicts old_abpkg,
  10096. + * then add it to the replaced_by vector so that old_abpkg
  10097. + * will be upgraded to ab_pkg automatically */
  10098. + if (pkg_conflicts_abstract(pkg, old_abpkg))
  10099. + abstract_pkg_vec_insert(old_abpkg->replaced_by, ab_pkg);
  10100. + }
  10101. + return 0;
  10102. +}
  10103. +
  10104. +int buildDepends(hash_table_t * hash, pkg_t * pkg)
  10105. +{
  10106. + int count;
  10107. + register int i;
  10108. + compound_depend_t * depends;
  10109. +
  10110. + if(!(count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count))
  10111. + return 0;
  10112. +
  10113. + if (0 && pkg->pre_depends_count)
  10114. + fprintf(stderr, "pkg=%s pre_depends_count=%d depends_count=%d\n",
  10115. + pkg->name, pkg->pre_depends_count, pkg->depends_count);
  10116. + depends = pkg->depends = malloc(sizeof(compound_depend_t) * count);
  10117. + if (depends == NULL) {
  10118. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10119. + return -1;
  10120. + }
  10121. +
  10122. +
  10123. + for(i = 0; i < pkg->pre_depends_count; i++){
  10124. + parseDepends(depends, hash, pkg->pre_depends_str[i]);
  10125. + if (0 && pkg->pre_depends_count)
  10126. + fprintf(stderr, " pre_depends_str=%s depends=%p possibility_count=%x\n",
  10127. + pkg->pre_depends_str[i], depends, depends->possibility_count);
  10128. + depends->type = PREDEPEND;
  10129. + depends++;
  10130. + }
  10131. +
  10132. + for(i = 0; i < pkg->recommends_count; i++){
  10133. + parseDepends(depends, hash, pkg->recommends_str[i]);
  10134. + if (0 && pkg->recommends_count)
  10135. + fprintf(stderr, " recommends_str=%s depends=%p possibility_count=%x\n",
  10136. + pkg->recommends_str[i], depends, depends->possibility_count);
  10137. + depends->type = RECOMMEND;
  10138. + depends++;
  10139. + }
  10140. +
  10141. + for(i = 0; i < pkg->suggests_count; i++){
  10142. + parseDepends(depends, hash, pkg->suggests_str[i]);
  10143. + if (0 && pkg->suggests_count)
  10144. + fprintf(stderr, " suggests_str=%s depends=%p possibility_count=%x\n",
  10145. + pkg->suggests_str[i], depends, depends->possibility_count);
  10146. + depends->type = SUGGEST;
  10147. + depends++;
  10148. + }
  10149. +
  10150. + for(i = 0; i < pkg->depends_count; i++){
  10151. + parseDepends(depends, hash, pkg->depends_str[i]);
  10152. + if (0 && pkg->depends_count)
  10153. + fprintf(stderr, " depends_str=%s depends=%p possibility_count=%x\n",
  10154. + pkg->depends_str[i], depends, depends->possibility_count);
  10155. + depends++;
  10156. + }
  10157. + return 0;
  10158. +}
  10159. +
  10160. +/*
  10161. + * pkg_depend_string: returns the depends string specified by index_.
  10162. + * All 4 kinds of dependences: dependence, pre-dependence, recommend, and suggest are number starting from 0.
  10163. + * [0,npredepends) -> returns pre_depends_str[index_]
  10164. + * [npredepends,npredepends+nrecommends) -> returns recommends_str[index_]
  10165. + * [npredepends+nrecommends,npredepends+nrecommends+nsuggests) -> returns recommends_str[index_]
  10166. + * [npredepends+nrecommends+nsuggests,npredepends+nrecommends+nsuggests+ndepends) -> returns depends_str[index_]
  10167. + */
  10168. +char *pkg_depend_str(pkg_t *pkg, int index_)
  10169. +{
  10170. + if (index_ < pkg->pre_depends_count) {
  10171. + return pkg->pre_depends_str[index_];
  10172. + }
  10173. + index_ -= pkg->pre_depends_count;
  10174. +
  10175. + if (index_ < pkg->recommends_count) {
  10176. + return pkg->recommends_str[index_];
  10177. + }
  10178. + index_ -= pkg->recommends_count;
  10179. +
  10180. + if (index_ < pkg->suggests_count) {
  10181. + return pkg->suggests_str[index_];
  10182. + }
  10183. + index_ -= pkg->suggests_count;
  10184. +
  10185. + if (index_ < pkg->depends_count) {
  10186. + return pkg->depends_str[index_];
  10187. + }
  10188. + fprintf(stderr, "pkg_depend_str: index_ %d out of range for pkg=%s\n", index_, pkg->name);
  10189. + return NULL;
  10190. +}
  10191. +
  10192. +void freeDepends(pkg_t *pkg)
  10193. +{
  10194. + int i;
  10195. +
  10196. + if (pkg == NULL || pkg->depends == NULL) {
  10197. + return;
  10198. + }
  10199. +
  10200. + fprintf(stderr, "Freeing depends=%p\n", pkg->depends);
  10201. + for (i=0; i < pkg->depends->possibility_count; i++) {
  10202. + depend_deinit(pkg->depends->possibilities[i]);
  10203. + }
  10204. + free(pkg->depends->possibilities);
  10205. + free(pkg->depends);
  10206. + pkg->depends = NULL;
  10207. +}
  10208. +
  10209. +void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg)
  10210. +{
  10211. + compound_depend_t * depends;
  10212. + int count, othercount;
  10213. + register int i, j;
  10214. + abstract_pkg_t * ab_depend;
  10215. + abstract_pkg_t ** temp;
  10216. +
  10217. + count = pkg->pre_depends_count + pkg->depends_count;
  10218. + depends = pkg->depends;
  10219. +
  10220. + if (0 && pkg->pre_depends_count)
  10221. + fprintf(stderr, "pkg=%s pre_depends_count=%d depends_count=%d\n",
  10222. + pkg->name, pkg->pre_depends_count, pkg->depends_count);
  10223. + for (i = 0; i < count; i++) {
  10224. + if (0 && pkg->pre_depends_count)
  10225. + fprintf(stderr, " i=%d possibility_count=%x depends=%p\n", i, depends->possibility_count, depends);
  10226. + for (j = 0; j < depends->possibility_count; j++){
  10227. + ab_depend = depends->possibilities[j]->pkg;
  10228. + if(!ab_depend->depended_upon_by)
  10229. + ab_depend->depended_upon_by = (abstract_pkg_t **)calloc(1, sizeof(abstract_pkg_t *));
  10230. +
  10231. + temp = ab_depend->depended_upon_by;
  10232. + othercount = 1;
  10233. + while(*temp){
  10234. + temp++;
  10235. + othercount++;
  10236. + }
  10237. + *temp = ab_pkg;
  10238. +
  10239. + ab_depend->depended_upon_by = (abstract_pkg_t **)realloc(ab_depend->depended_upon_by,
  10240. + (othercount + 1) * sizeof(abstract_pkg_t *));
  10241. + /* the array may have moved */
  10242. + temp = ab_depend->depended_upon_by + othercount;
  10243. + *temp = NULL;
  10244. + }
  10245. + depends++;
  10246. + }
  10247. +}
  10248. +
  10249. +static depend_t * depend_init(void)
  10250. +{
  10251. + depend_t * d = (depend_t *)malloc(sizeof(depend_t));
  10252. + if ( d==NULL ){
  10253. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10254. + return NULL;
  10255. + }
  10256. + d->constraint = NONE;
  10257. + d->version = NULL;
  10258. + d->pkg = NULL;
  10259. +
  10260. + return d;
  10261. +}
  10262. +
  10263. +static void depend_deinit(depend_t *d)
  10264. +{
  10265. + free(d);
  10266. +}
  10267. +
  10268. +static int parseDepends(compound_depend_t *compound_depend,
  10269. + hash_table_t * hash, char * depend_str)
  10270. +{
  10271. + char * pkg_name, buffer[2048];
  10272. + int num_of_ors = 0;
  10273. + register int i;
  10274. + register char * src, * dest;
  10275. + depend_t ** possibilities;
  10276. +
  10277. + /* first count the number of ored possibilities for satisfying dependency */
  10278. + src = depend_str;
  10279. + while(*src)
  10280. + if(*src++ == '|')
  10281. + num_of_ors++;
  10282. +
  10283. + compound_depend->type = DEPEND;
  10284. +
  10285. + compound_depend->possibility_count = num_of_ors + 1;
  10286. + possibilities = (depend_t **)malloc(sizeof(depend_t *) * (num_of_ors + 1));
  10287. + if (!possibilities)
  10288. + return -ENOMEM;
  10289. + compound_depend->possibilities = possibilities;
  10290. +
  10291. + src = depend_str;
  10292. + for(i = 0; i < num_of_ors + 1; i++){
  10293. + possibilities[i] = depend_init();
  10294. + if (!possibilities[i])
  10295. + return -ENOMEM;
  10296. + /* gobble up just the name first */
  10297. + dest = buffer;
  10298. + while(*src &&
  10299. + !isspace(*src) &&
  10300. + (*src != '(') &&
  10301. + (*src != '*') &&
  10302. + (*src != '|'))
  10303. + *dest++ = *src++;
  10304. + *dest = '\0';
  10305. + pkg_name = trim_alloc(buffer);
  10306. + if (pkg_name == NULL )
  10307. + return -ENOMEM;
  10308. +
  10309. + /* now look at possible version info */
  10310. +
  10311. + /* skip to next chars */
  10312. + if(isspace(*src))
  10313. + while(*src && isspace(*src)) src++;
  10314. +
  10315. + /* extract constraint and version */
  10316. + if(*src == '('){
  10317. + src++;
  10318. + if(!strncmp(src, "<<", 2)){
  10319. + possibilities[i]->constraint = EARLIER;
  10320. + src += 2;
  10321. + }
  10322. + else if(!strncmp(src, "<=", 2)){
  10323. + possibilities[i]->constraint = EARLIER_EQUAL;
  10324. + src += 2;
  10325. + }
  10326. + else if(!strncmp(src, ">=", 2)){
  10327. + possibilities[i]->constraint = LATER_EQUAL;
  10328. + src += 2;
  10329. + }
  10330. + else if(!strncmp(src, ">>", 2)){
  10331. + possibilities[i]->constraint = LATER;
  10332. + src += 2;
  10333. + }
  10334. + else if(!strncmp(src, "=", 1)){
  10335. + possibilities[i]->constraint = EQUAL;
  10336. + src++;
  10337. + }
  10338. + /* should these be here to support deprecated designations; dpkg does */
  10339. + else if(!strncmp(src, "<", 1)){
  10340. + possibilities[i]->constraint = EARLIER_EQUAL;
  10341. + src++;
  10342. + }
  10343. + else if(!strncmp(src, ">", 1)){
  10344. + possibilities[i]->constraint = LATER_EQUAL;
  10345. + src++;
  10346. + }
  10347. +
  10348. + /* now we have any constraint, pass space to version string */
  10349. + while(isspace(*src)) src++;
  10350. +
  10351. + /* this would be the version string */
  10352. + dest = buffer;
  10353. + while(*src && *src != ')')
  10354. + *dest++ = *src++;
  10355. + *dest = '\0';
  10356. +
  10357. + possibilities[i]->version = trim_alloc(buffer);
  10358. + /* fprintf(stderr, "let's print the depends version string:");
  10359. + fprintf(stderr, "version %s\n", possibilities[i]->version);*/
  10360. + if (possibilities[i]->version == NULL )
  10361. + return -ENOMEM;
  10362. +
  10363. +
  10364. + }
  10365. + /* hook up the dependency to its abstract pkg */
  10366. + possibilities[i]->pkg = ensure_abstract_pkg_by_name(hash, pkg_name);
  10367. +
  10368. + free(pkg_name);
  10369. +
  10370. + /* now get past the ) and any possible | chars */
  10371. + while(*src &&
  10372. + (isspace(*src) ||
  10373. + (*src == ')') ||
  10374. + (*src == '|')))
  10375. + src++;
  10376. + if (*src == '*')
  10377. + {
  10378. + compound_depend->type = GREEDY_DEPEND;
  10379. + src++;
  10380. + }
  10381. + }
  10382. +
  10383. + return 0;
  10384. +}
  10385. diff -Nur busybox-1.21.1.orig/archival/libipkg/pkg_depends.h busybox-1.21.1/archival/libipkg/pkg_depends.h
  10386. --- busybox-1.21.1.orig/archival/libipkg/pkg_depends.h 1970-01-01 01:00:00.000000000 +0100
  10387. +++ busybox-1.21.1/archival/libipkg/pkg_depends.h 2014-02-17 14:25:39.862534201 +0100
  10388. @@ -0,0 +1,105 @@
  10389. +/* pkg_depends.h - the itsy package management system
  10390. +
  10391. + Steven M. Ayer
  10392. +
  10393. + Copyright (C) 2002 Compaq Computer Corporation
  10394. +
  10395. + This program is free software; you can redistribute it and/or
  10396. + modify it under the terms of the GNU General Public License as
  10397. + published by the Free Software Foundation; either version 2, or (at
  10398. + your option) any later version.
  10399. +
  10400. + This program is distributed in the hope that it will be useful, but
  10401. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10402. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10403. + General Public License for more details.
  10404. +*/
  10405. +
  10406. +#ifndef PKG_DEPENDS_H
  10407. +#define PKG_DEPENDS_H
  10408. +
  10409. +#include "pkg.h"
  10410. +#include "pkg_hash.h"
  10411. +
  10412. +enum depend_type {
  10413. + PREDEPEND,
  10414. + DEPEND,
  10415. + CONFLICTS,
  10416. + GREEDY_DEPEND,
  10417. + RECOMMEND,
  10418. + SUGGEST
  10419. +};
  10420. +typedef enum depend_type depend_type_t;
  10421. +
  10422. +enum version_constraint {
  10423. + NONE,
  10424. + EARLIER,
  10425. + EARLIER_EQUAL,
  10426. + EQUAL,
  10427. + LATER_EQUAL,
  10428. + LATER
  10429. +};
  10430. +typedef enum version_constraint version_constraint_t;
  10431. +
  10432. +struct depend{
  10433. + version_constraint_t constraint;
  10434. + char * version;
  10435. + abstract_pkg_t * pkg;
  10436. +};
  10437. +typedef struct depend depend_t;
  10438. +
  10439. +struct compound_depend{
  10440. + depend_type_t type;
  10441. + int possibility_count;
  10442. + struct depend ** possibilities;
  10443. +};
  10444. +typedef struct compound_depend compound_depend_t;
  10445. +
  10446. +#include "hash_table.h"
  10447. +
  10448. +int buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
  10449. +int buildConflicts(hash_table_t * hash, pkg_t * pkg);
  10450. +int buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
  10451. +int buildDepends(hash_table_t * hash, pkg_t * pkg);
  10452. +
  10453. +/**
  10454. + * pkg_has_common_provides returns 1 if pkg and replacee both provide
  10455. + * the same abstract package and 0 otherwise.
  10456. + */
  10457. +int pkg_has_common_provides(pkg_t *pkg, pkg_t *replacee);
  10458. +
  10459. +/**
  10460. + * pkg_provides returns 1 if pkg->provides contains providee and 0
  10461. + * otherwise.
  10462. + */
  10463. +int pkg_provides_abstract(pkg_t *pkg, abstract_pkg_t *providee);
  10464. +
  10465. +/**
  10466. + * pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0
  10467. + * otherwise.
  10468. + */
  10469. +int pkg_replaces(pkg_t *pkg, pkg_t *replacee);
  10470. +
  10471. +/**
  10472. + * pkg_conflicts_abstract returns 1 if pkg->conflicts contains conflictee provides and 0
  10473. + * otherwise.
  10474. + */
  10475. +int pkg_conflicts_abstract(pkg_t *pkg, abstract_pkg_t *conflicts);
  10476. +
  10477. +/**
  10478. + * pkg_conflicts returns 1 if pkg->conflicts contains one of conflictee's provides and 0
  10479. + * otherwise.
  10480. + */
  10481. +int pkg_conflicts(pkg_t *pkg, pkg_t *conflicts);
  10482. +
  10483. +char *pkg_depend_str(pkg_t *pkg, int index_);
  10484. +void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg);
  10485. +void freeDepends(pkg_t *pkg);
  10486. +void printDepends(pkg_t * pkg);
  10487. +int version_constraints_satisfied(depend_t * depends, pkg_t * pkg);
  10488. +int pkg_hash_fetch_unsatisfied_dependencies(ipkg_conf_t *conf, pkg_t * pkg, pkg_vec_t *depends, char *** unresolved);
  10489. +pkg_vec_t * pkg_hash_fetch_conflicts(pkg_t * pkg);
  10490. +int pkg_dependence_satisfiable(depend_t *depend);
  10491. +int pkg_dependence_satisfied(depend_t *depend);
  10492. +
  10493. +#endif
  10494. diff -Nur busybox-1.21.1.orig/archival/libipkg/pkg_dest.c busybox-1.21.1/archival/libipkg/pkg_dest.c
  10495. --- busybox-1.21.1.orig/archival/libipkg/pkg_dest.c 1970-01-01 01:00:00.000000000 +0100
  10496. +++ busybox-1.21.1/archival/libipkg/pkg_dest.c 2014-02-17 14:25:39.862534201 +0100
  10497. @@ -0,0 +1,92 @@
  10498. +/* pkg_dest.c - the itsy package management system
  10499. +
  10500. + Carl D. Worth
  10501. +
  10502. + Copyright (C) 2001 University of Southern California
  10503. +
  10504. + This program is free software; you can redistribute it and/or
  10505. + modify it under the terms of the GNU General Public License as
  10506. + published by the Free Software Foundation; either version 2, or (at
  10507. + your option) any later version.
  10508. +
  10509. + This program is distributed in the hope that it will be useful, but
  10510. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10511. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10512. + General Public License for more details.
  10513. +*/
  10514. +
  10515. +#include "ipkg.h"
  10516. +
  10517. +#include "pkg_dest.h"
  10518. +#include "file_util.h"
  10519. +#include "str_util.h"
  10520. +#include "sprintf_alloc.h"
  10521. +
  10522. +int pkg_dest_init(pkg_dest_t *dest, const char *name, const char *root_dir,const char * lists_dir)
  10523. +{
  10524. + dest->name = strdup(name);
  10525. +
  10526. + /* Guarantee that dest->root_dir ends with a '/' */
  10527. + if (str_ends_with(root_dir, "/")) {
  10528. + dest->root_dir = strdup(root_dir);
  10529. + } else {
  10530. + sprintf_alloc(&dest->root_dir, "%s/", root_dir);
  10531. + }
  10532. + file_mkdir_hier(dest->root_dir, 0755);
  10533. +
  10534. + sprintf_alloc(&dest->ipkg_dir, "%s%s",
  10535. + dest->root_dir, IPKG_STATE_DIR_PREFIX);
  10536. + file_mkdir_hier(dest->ipkg_dir, 0755);
  10537. +
  10538. + if (str_starts_with (lists_dir, "/"))
  10539. + sprintf_alloc(&dest->lists_dir, "%s", lists_dir);
  10540. + else
  10541. + sprintf_alloc(&dest->lists_dir, "/%s", lists_dir);
  10542. +
  10543. + file_mkdir_hier(dest->lists_dir, 0755);
  10544. +
  10545. + sprintf_alloc(&dest->info_dir, "%s/%s",
  10546. + dest->ipkg_dir, IPKG_INFO_DIR_SUFFIX);
  10547. + file_mkdir_hier(dest->info_dir, 0755);
  10548. +
  10549. + sprintf_alloc(&dest->status_file_name, "%s/%s",
  10550. + dest->ipkg_dir, IPKG_STATUS_FILE_SUFFIX);
  10551. +
  10552. + sprintf_alloc(&dest->status_file_tmp_name, "%s/%s.tmp",
  10553. + dest->ipkg_dir, IPKG_STATUS_FILE_SUFFIX);
  10554. +
  10555. + dest->status_file = NULL;
  10556. +
  10557. + return 0;
  10558. +}
  10559. +
  10560. +void pkg_dest_deinit(pkg_dest_t *dest)
  10561. +{
  10562. + free(dest->name);
  10563. + dest->name = NULL;
  10564. +
  10565. + free(dest->root_dir);
  10566. + dest->root_dir = NULL;
  10567. +
  10568. + free(dest->ipkg_dir);
  10569. + dest->ipkg_dir = NULL;
  10570. +
  10571. + free(dest->lists_dir);
  10572. + dest->lists_dir = NULL;
  10573. +
  10574. + free(dest->info_dir);
  10575. + dest->info_dir = NULL;
  10576. +
  10577. + free(dest->status_file_name);
  10578. + dest->status_file_name = NULL;
  10579. +
  10580. + free(dest->status_file_tmp_name);
  10581. + dest->status_file_tmp_name = NULL;
  10582. +
  10583. + if (dest->status_file) {
  10584. + fclose(dest->status_file);
  10585. + }
  10586. + dest->status_file = NULL;
  10587. +
  10588. + dest->root_dir = NULL;
  10589. +}
  10590. diff -Nur busybox-1.21.1.orig/archival/libipkg/pkg_dest.h busybox-1.21.1/archival/libipkg/pkg_dest.h
  10591. --- busybox-1.21.1.orig/archival/libipkg/pkg_dest.h 1970-01-01 01:00:00.000000000 +0100
  10592. +++ busybox-1.21.1/archival/libipkg/pkg_dest.h 2014-02-17 14:25:39.862534201 +0100
  10593. @@ -0,0 +1,38 @@
  10594. +/* pkg_dest.h - the itsy package management system
  10595. +
  10596. + Carl D. Worth
  10597. +
  10598. + Copyright (C) 2001 University of Southern California
  10599. +
  10600. + This program is free software; you can redistribute it and/or
  10601. + modify it under the terms of the GNU General Public License as
  10602. + published by the Free Software Foundation; either version 2, or (at
  10603. + your option) any later version.
  10604. +
  10605. + This program is distributed in the hope that it will be useful, but
  10606. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10607. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10608. + General Public License for more details.
  10609. +*/
  10610. +
  10611. +#ifndef PKG_DEST_H
  10612. +#define PKG_DEST_H
  10613. +
  10614. +typedef struct pkg_dest pkg_dest_t;
  10615. +struct pkg_dest
  10616. +{
  10617. + char *name;
  10618. + char *root_dir;
  10619. + char *ipkg_dir;
  10620. + char *lists_dir;
  10621. + char *info_dir;
  10622. + char *status_file_name;
  10623. + char *status_file_tmp_name;
  10624. + FILE *status_file;
  10625. +};
  10626. +
  10627. +int pkg_dest_init(pkg_dest_t *dest, const char *name, const char *root_dir,const char *lists_dir);
  10628. +void pkg_dest_deinit(pkg_dest_t *dest);
  10629. +
  10630. +#endif
  10631. +
  10632. diff -Nur busybox-1.21.1.orig/archival/libipkg/pkg_dest_list.c busybox-1.21.1/archival/libipkg/pkg_dest_list.c
  10633. --- busybox-1.21.1.orig/archival/libipkg/pkg_dest_list.c 1970-01-01 01:00:00.000000000 +0100
  10634. +++ busybox-1.21.1/archival/libipkg/pkg_dest_list.c 2014-02-17 14:25:39.862534201 +0100
  10635. @@ -0,0 +1,85 @@
  10636. +/* pkg_dest_list.c - the itsy package management system
  10637. +
  10638. + Carl D. Worth
  10639. +
  10640. + Copyright (C) 2001 University of Southern California
  10641. +
  10642. + This program is free software; you can redistribute it and/or
  10643. + modify it under the terms of the GNU General Public License as
  10644. + published by the Free Software Foundation; either version 2, or (at
  10645. + your option) any later version.
  10646. +
  10647. + This program is distributed in the hope that it will be useful, but
  10648. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10649. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10650. + General Public License for more details.
  10651. +*/
  10652. +
  10653. +#include "ipkg.h"
  10654. +
  10655. +#include "pkg_dest.h"
  10656. +#include "void_list.h"
  10657. +#include "pkg_dest_list.h"
  10658. +
  10659. +int pkg_dest_list_elt_init(pkg_dest_list_elt_t *elt, pkg_dest_t *data)
  10660. +{
  10661. + return void_list_elt_init((void_list_elt_t *) elt, data);
  10662. +}
  10663. +
  10664. +void pkg_dest_list_elt_deinit(pkg_dest_list_elt_t *elt)
  10665. +{
  10666. + void_list_elt_deinit((void_list_elt_t *) elt);
  10667. +}
  10668. +
  10669. +int pkg_dest_list_init(pkg_dest_list_t *list)
  10670. +{
  10671. + return void_list_init((void_list_t *) list);
  10672. +}
  10673. +
  10674. +void pkg_dest_list_deinit(pkg_dest_list_t *list)
  10675. +{
  10676. + pkg_dest_list_elt_t *iter;
  10677. + pkg_dest_t *pkg_dest;
  10678. +
  10679. + for (iter = list->head; iter; iter = iter->next) {
  10680. + pkg_dest = iter->data;
  10681. + pkg_dest_deinit(pkg_dest);
  10682. +
  10683. + /* malloced in pkg_dest_list_append */
  10684. + free(pkg_dest);
  10685. + iter->data = NULL;
  10686. + }
  10687. + void_list_deinit((void_list_t *) list);
  10688. +}
  10689. +
  10690. +pkg_dest_t *pkg_dest_list_append(pkg_dest_list_t *list, const char *name,
  10691. + const char *root_dir,const char *lists_dir)
  10692. +{
  10693. + int err;
  10694. + pkg_dest_t *pkg_dest;
  10695. +
  10696. + /* freed in plg_dest_list_deinit */
  10697. + pkg_dest = malloc(sizeof(pkg_dest_t));
  10698. + if (pkg_dest == NULL) {
  10699. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10700. + return NULL;
  10701. + }
  10702. +
  10703. + pkg_dest_init(pkg_dest, name, root_dir,lists_dir);
  10704. + err = void_list_append((void_list_t *) list, pkg_dest);
  10705. + if (err) {
  10706. + return NULL;
  10707. + }
  10708. +
  10709. + return pkg_dest;
  10710. +}
  10711. +
  10712. +int pkg_dest_list_push(pkg_dest_list_t *list, pkg_dest_t *data)
  10713. +{
  10714. + return void_list_push((void_list_t *) list, data);
  10715. +}
  10716. +
  10717. +pkg_dest_list_elt_t *pkg_dest_list_pop(pkg_dest_list_t *list)
  10718. +{
  10719. + return (pkg_dest_list_elt_t *) void_list_pop((void_list_t *) list);
  10720. +}
  10721. diff -Nur busybox-1.21.1.orig/archival/libipkg/pkg_dest_list.h busybox-1.21.1/archival/libipkg/pkg_dest_list.h
  10722. --- busybox-1.21.1.orig/archival/libipkg/pkg_dest_list.h 1970-01-01 01:00:00.000000000 +0100
  10723. +++ busybox-1.21.1/archival/libipkg/pkg_dest_list.h 2014-02-17 14:25:39.862534201 +0100
  10724. @@ -0,0 +1,50 @@
  10725. +/* pkg_dest_list.h - the itsy package management system
  10726. +
  10727. + Carl D. Worth
  10728. +
  10729. + Copyright (C) 2001 University of Southern California
  10730. +
  10731. + This program is free software; you can redistribute it and/or
  10732. + modify it under the terms of the GNU General Public License as
  10733. + published by the Free Software Foundation; either version 2, or (at
  10734. + your option) any later version.
  10735. +
  10736. + This program is distributed in the hope that it will be useful, but
  10737. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10738. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10739. + General Public License for more details.
  10740. +*/
  10741. +
  10742. +#ifndef PKG_DEST_LIST_H
  10743. +#define PKG_DEST_LIST_H
  10744. +
  10745. +#include "pkg_dest.h"
  10746. +
  10747. +typedef struct pkg_dest_list_elt pkg_dest_list_elt_t;
  10748. +struct pkg_dest_list_elt
  10749. +{
  10750. + pkg_dest_list_elt_t *next;
  10751. + pkg_dest_t *data;
  10752. +};
  10753. +
  10754. +typedef struct pkg_dest_list pkg_dest_list_t;
  10755. +struct pkg_dest_list
  10756. +{
  10757. + pkg_dest_list_elt_t pre_head;
  10758. + pkg_dest_list_elt_t *head;
  10759. + pkg_dest_list_elt_t *tail;
  10760. +};
  10761. +
  10762. +int pkg_dest_list_elt_init(pkg_dest_list_elt_t *elt, pkg_dest_t *data);
  10763. +void pkg_dest_list_elt_deinit(pkg_dest_list_elt_t *elt);
  10764. +
  10765. +int pkg_dest_list_init(pkg_dest_list_t *list);
  10766. +void pkg_dest_list_deinit(pkg_dest_list_t *list);
  10767. +
  10768. +pkg_dest_t *pkg_dest_list_append(pkg_dest_list_t *list, const char *name,
  10769. + const char *root_dir,const char* lists_dir);
  10770. +int pkg_dest_list_push(pkg_dest_list_t *list, pkg_dest_t *data);
  10771. +pkg_dest_list_elt_t *pkg_dest_list_pop(pkg_dest_list_t *list);
  10772. +
  10773. +#endif
  10774. +
  10775. diff -Nur busybox-1.21.1.orig/archival/libipkg/pkg_extract.c busybox-1.21.1/archival/libipkg/pkg_extract.c
  10776. --- busybox-1.21.1.orig/archival/libipkg/pkg_extract.c 1970-01-01 01:00:00.000000000 +0100
  10777. +++ busybox-1.21.1/archival/libipkg/pkg_extract.c 2014-02-17 14:25:39.862534201 +0100
  10778. @@ -0,0 +1,255 @@
  10779. +/* pkg_extract.c - the itsy package management system
  10780. +
  10781. + Carl D. Worth
  10782. +
  10783. + Copyright (C) 2001 University of Southern California
  10784. +
  10785. + This program is free software; you can redistribute it and/or
  10786. + modify it under the terms of the GNU General Public License as
  10787. + published by the Free Software Foundation; either version 2, or (at
  10788. + your option) any later version.
  10789. +
  10790. + This program is distributed in the hope that it will be useful, but
  10791. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10792. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10793. + General Public License for more details.
  10794. +*/
  10795. +
  10796. +#include "ipkg.h"
  10797. +#include <errno.h>
  10798. +#include <fcntl.h>
  10799. +#include <stdio.h>
  10800. +
  10801. +#include "pkg_extract.h"
  10802. +
  10803. +#include "libbb.h"
  10804. +#include "file_util.h"
  10805. +#include "sprintf_alloc.h"
  10806. +#include "bb_archive.h"
  10807. +
  10808. +#define IPKG_CONTROL_ARCHIVE "control.tar.gz"
  10809. +#define IPKG_DATA_ARCHIVE "data.tar.gz"
  10810. +#define IPKG_CONTROL_FILE "control"
  10811. +
  10812. +static void FAST_FUNC ipkg_data_extract_all_prefix(archive_handle_t *archive_handle)
  10813. +{
  10814. + char *name_ptr = archive_handle->file_header->name;
  10815. +
  10816. + /* Skip all leading "/" */
  10817. + while (*name_ptr == '/')
  10818. + name_ptr++;
  10819. + /* Skip all leading "./" and "../" */
  10820. + while (name_ptr[0] == '.') {
  10821. + if (name_ptr[1] == '.' && name_ptr[2] == '/')
  10822. + name_ptr++;
  10823. + if (name_ptr[1] != '/')
  10824. + break;
  10825. + name_ptr += 2;
  10826. + }
  10827. +
  10828. + if (name_ptr[0] != '\0') {
  10829. + archive_handle->file_header->name = xasprintf("%s%s", archive_handle->dpkg__buffer, name_ptr);
  10830. + data_extract_all(archive_handle);
  10831. + }
  10832. +}
  10833. +
  10834. +static void FAST_FUNC ipkg_data_extract_to_buffer(archive_handle_t *archive_handle)
  10835. +{
  10836. + unsigned size = archive_handle->file_header->size;
  10837. +
  10838. + archive_handle->dpkg__buffer = xzalloc(size + 1);
  10839. + xread(archive_handle->src_fd, archive_handle->dpkg__buffer, size);
  10840. +}
  10841. +
  10842. +static void extract_ipkg_file_to_dir(pkg_t *pkg, const char *dir, const char *filename)
  10843. +{
  10844. + archive_handle_t *archive;
  10845. + char *path;
  10846. +
  10847. + sprintf_alloc(&path, "%s/", dir);
  10848. + archive = init_handle();
  10849. + archive->src_fd = xopen(pkg->local_filename, O_RDONLY);
  10850. + archive->filter = filter_accept_list;
  10851. + llist_add_to(&(archive->accept), (char *)filename);
  10852. + archive->dpkg__buffer = path;
  10853. + archive->action_data = ipkg_data_extract_all_prefix;
  10854. + archive->ah_flags |= ARCHIVE_UNLINK_OLD;
  10855. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  10856. + close(archive->src_fd);
  10857. + free(archive->accept);
  10858. + free(archive);
  10859. + free(path);
  10860. +}
  10861. +
  10862. +static void FAST_FUNC data_extract_file_name_to_buffer(archive_handle_t *archive)
  10863. +{
  10864. + unsigned int size = strlen(archive->file_header->name) + 2;
  10865. +
  10866. + if (archive->dpkg__buffer == NULL) {
  10867. + archive->dpkg__buffer = xmalloc(size);
  10868. + strcpy(archive->dpkg__buffer, archive->file_header->name);
  10869. + } else {
  10870. + size += strlen(archive->dpkg__buffer);
  10871. + archive->dpkg__buffer = xrealloc(archive->dpkg__buffer, size);
  10872. + strcat(archive->dpkg__buffer, archive->file_header->name);
  10873. + }
  10874. + strcat(archive->dpkg__buffer, "\n");
  10875. + data_skip(archive);
  10876. +}
  10877. +
  10878. +int pkg_extract_control_file_to_stream(pkg_t *pkg, FILE *stream)
  10879. +{
  10880. + archive_handle_t *archive;
  10881. + char *name;
  10882. + const char *filename = IPKG_CONTROL_FILE;
  10883. +
  10884. + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_CONTROL_ARCHIVE);
  10885. + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_CONTROL_ARCHIVE);
  10886. + archive = init_handle();
  10887. + archive->src_fd = xopen(name, O_RDONLY);
  10888. + archive->filter = filter_accept_list;
  10889. + llist_add_to(&(archive->accept), (char *)filename);
  10890. + archive->action_data = ipkg_data_extract_to_buffer;
  10891. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  10892. + close(archive->src_fd);
  10893. + fputs(archive->dpkg__buffer, stream);
  10894. + free(archive->dpkg__buffer);
  10895. + free(archive->accept);
  10896. + free(archive);
  10897. + free(name);
  10898. +
  10899. + return 0;
  10900. +}
  10901. +
  10902. +int pkg_extract_control_files_to_dir(pkg_t *pkg, const char *dir)
  10903. +{
  10904. + return pkg_extract_control_files_to_dir_with_prefix(pkg, dir, "");
  10905. +}
  10906. +
  10907. +int pkg_extract_control_files_to_dir_with_prefix(pkg_t *pkg, const char *dir, const char *prefix)
  10908. +{
  10909. + archive_handle_t *archive;
  10910. + char *name;
  10911. + char *path;
  10912. +
  10913. + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_CONTROL_ARCHIVE);
  10914. + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_CONTROL_ARCHIVE);
  10915. + sprintf_alloc(&path, "%s/%s", dir, prefix);
  10916. + archive = init_handle();
  10917. + archive->src_fd = xopen(name, O_RDONLY);
  10918. + archive->filter = filter_accept_all;
  10919. + archive->dpkg__buffer = path;
  10920. + archive->action_data = ipkg_data_extract_all_prefix;
  10921. + archive->ah_flags |= ARCHIVE_CREATE_LEADING_DIRS | ARCHIVE_RESTORE_DATE | ARCHIVE_UNLINK_OLD;
  10922. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  10923. + close(archive->src_fd);
  10924. + free(archive);
  10925. + free(path);
  10926. + free(name);
  10927. +
  10928. + return 0;
  10929. +}
  10930. +
  10931. +int pkg_extract_data_files_to_dir(pkg_t *pkg, const char *dir)
  10932. +{
  10933. + archive_handle_t *archive;
  10934. + char *name;
  10935. + char *path;
  10936. +
  10937. + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_DATA_ARCHIVE);
  10938. + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_DATA_ARCHIVE);
  10939. + sprintf_alloc(&path, "%s/", dir);
  10940. + archive = init_handle();
  10941. + archive->src_fd = xopen(name, O_RDONLY);
  10942. + archive->filter = filter_accept_all;
  10943. + archive->dpkg__buffer = path;
  10944. + archive->action_data = ipkg_data_extract_all_prefix;
  10945. + archive->ah_flags |= ARCHIVE_CREATE_LEADING_DIRS | ARCHIVE_RESTORE_DATE | ARCHIVE_UNLINK_OLD;
  10946. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  10947. + close(archive->src_fd);
  10948. + free(archive);
  10949. + free(path);
  10950. + free(name);
  10951. +
  10952. + return 0;
  10953. +}
  10954. +
  10955. +int pkg_extract_data_file_names_to_file(pkg_t *pkg, const char *file_name)
  10956. +{
  10957. + int err=0;
  10958. + char *line, *data_file;
  10959. + FILE *file;
  10960. + FILE *tmp;
  10961. +
  10962. + file = fopen(file_name, "w");
  10963. + if (file == NULL) {
  10964. + fprintf(stderr, "%s: ERROR: Failed to open %s for writing.\n",
  10965. + __FUNCTION__, file_name);
  10966. + return EINVAL;
  10967. + }
  10968. +
  10969. + tmp = tmpfile();
  10970. + if (pkg->installed_files) {
  10971. + str_list_elt_t *elt;
  10972. + for (elt = pkg->installed_files->head; elt; elt = elt->next) {
  10973. + fprintf(file, "%s\n", elt->data);
  10974. + }
  10975. + } else {
  10976. + err = pkg_extract_data_file_names_to_stream(pkg, tmp);
  10977. + if (err) {
  10978. + fclose(file);
  10979. + fclose(tmp);
  10980. + return err;
  10981. + }
  10982. +
  10983. + /* Fixup data file names by removing the initial '.' */
  10984. + rewind(tmp);
  10985. + while (1) {
  10986. + line = file_read_line_alloc(tmp);
  10987. + if (line == NULL) {
  10988. + break;
  10989. + }
  10990. +
  10991. + data_file = line;
  10992. + if (*data_file == '.') {
  10993. + data_file++;
  10994. + }
  10995. +
  10996. + if (*data_file != '/') {
  10997. + fputs("/", file);
  10998. + }
  10999. +
  11000. + /* I have no idea why, but this is what dpkg does */
  11001. + if (strcmp(data_file, "/\n") == 0) {
  11002. + fputs("/.\n", file);
  11003. + } else {
  11004. + fputs(data_file, file);
  11005. + }
  11006. + }
  11007. + }
  11008. + fclose(tmp);
  11009. + fclose(file);
  11010. +
  11011. + return err;
  11012. +}
  11013. +
  11014. +int pkg_extract_data_file_names_to_stream(pkg_t *pkg, FILE *file)
  11015. +{
  11016. + archive_handle_t *archive;
  11017. + char *name;
  11018. +
  11019. + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_DATA_ARCHIVE);
  11020. + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_DATA_ARCHIVE);
  11021. + archive = init_handle();
  11022. + archive->src_fd = xopen(name, O_RDONLY);
  11023. + archive->filter = filter_accept_all;
  11024. + archive->action_data = data_extract_file_name_to_buffer;
  11025. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  11026. + close(archive->src_fd);
  11027. + fputs(archive->dpkg__buffer, file);
  11028. + free(archive->dpkg__buffer);
  11029. + free(archive);
  11030. + free(name);
  11031. +
  11032. + return 0;
  11033. +}
  11034. diff -Nur busybox-1.21.1.orig/archival/libipkg/pkg_extract.h busybox-1.21.1/archival/libipkg/pkg_extract.h
  11035. --- busybox-1.21.1.orig/archival/libipkg/pkg_extract.h 1970-01-01 01:00:00.000000000 +0100
  11036. +++ busybox-1.21.1/archival/libipkg/pkg_extract.h 2014-02-17 14:25:39.862534201 +0100
  11037. @@ -0,0 +1,32 @@
  11038. +/* pkg_extract.c - the itsy package management system
  11039. +
  11040. + Carl D. Worth
  11041. +
  11042. + Copyright (C) 2001 University of Southern California
  11043. +
  11044. + This program is free software; you can redistribute it and/or
  11045. + modify it under the terms of the GNU General Public License as
  11046. + published by the Free Software Foundation; either version 2, or (at
  11047. + your option) any later version.
  11048. +
  11049. + This program is distributed in the hope that it will be useful, but
  11050. + WITHOUT ANY WARRANTY; without even the implied warranty of
  11051. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11052. + General Public License for more details.
  11053. +*/
  11054. +
  11055. +#ifndef PKG_EXTRACT_H
  11056. +#define PKG_EXTRACT_H
  11057. +
  11058. +#include "pkg.h"
  11059. +
  11060. +int pkg_extract_control_file_to_stream(pkg_t *pkg, FILE *stream);
  11061. +int pkg_extract_control_files_to_dir(pkg_t *pkg, const char *dir);
  11062. +int pkg_extract_control_files_to_dir_with_prefix(pkg_t *pkg,
  11063. + const char *dir,
  11064. + const char *prefix);
  11065. +int pkg_extract_data_files_to_dir(pkg_t *pkg, const char *dir);
  11066. +int pkg_extract_data_file_names_to_file(pkg_t *pkg, const char *file_name);
  11067. +int pkg_extract_data_file_names_to_stream(pkg_t *pkg, FILE *file);
  11068. +
  11069. +#endif
  11070. diff -Nur busybox-1.21.1.orig/archival/libipkg/pkg.h busybox-1.21.1/archival/libipkg/pkg.h
  11071. --- busybox-1.21.1.orig/archival/libipkg/pkg.h 1970-01-01 01:00:00.000000000 +0100
  11072. +++ busybox-1.21.1/archival/libipkg/pkg.h 2014-02-17 14:25:39.862534201 +0100
  11073. @@ -0,0 +1,229 @@
  11074. +/* pkg.h - the itsy package management system
  11075. +
  11076. + Carl D. Worth
  11077. +
  11078. + Copyright (C) 2001 University of Southern California
  11079. +
  11080. + This program is free software; you can redistribute it and/or
  11081. + modify it under the terms of the GNU General Public License as
  11082. + published by the Free Software Foundation; either version 2, or (at
  11083. + your option) any later version.
  11084. +
  11085. + This program is distributed in the hope that it will be useful, but
  11086. + WITHOUT ANY WARRANTY; without even the implied warranty of
  11087. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11088. + General Public License for more details.
  11089. +*/
  11090. +
  11091. +#ifndef PKG_H
  11092. +#define PKG_H
  11093. +
  11094. +#include <sys/types.h>
  11095. +#include <sys/stat.h>
  11096. +#include <unistd.h>
  11097. +
  11098. +#include "pkg_vec.h"
  11099. +#include "str_list.h"
  11100. +#include "pkg_src.h"
  11101. +#include "pkg_dest.h"
  11102. +#include "ipkg_conf.h"
  11103. +#include "conffile_list.h"
  11104. +
  11105. +struct ipkg_conf;
  11106. +
  11107. +/* I think "Size" is currently the shortest field name */
  11108. +#define PKG_MINIMUM_FIELD_NAME_LEN 4
  11109. +
  11110. +enum pkg_state_want
  11111. +{
  11112. + SW_UNKNOWN = 1,
  11113. + SW_INSTALL,
  11114. + SW_DEINSTALL,
  11115. + SW_PURGE,
  11116. + SW_LAST_STATE_WANT
  11117. +};
  11118. +typedef enum pkg_state_want pkg_state_want_t;
  11119. +
  11120. +enum pkg_state_flag
  11121. +{
  11122. + SF_OK = 0,
  11123. + SF_REINSTREQ = 1,
  11124. + SF_HOLD = 2, /* do not upgrade version */
  11125. + SF_REPLACE = 4, /* replace this package */
  11126. + SF_NOPRUNE = 8, /* do not remove obsolete files */
  11127. + SF_PREFER = 16, /* prefer this version */
  11128. + SF_OBSOLETE = 32, /* old package in upgrade pair */
  11129. + SF_MARKED = 64, /* temporary mark */
  11130. + SF_FILELIST_CHANGED = 128, /* needs filelist written */
  11131. + SF_USER = 256,
  11132. + SF_LAST_STATE_FLAG
  11133. +};
  11134. +typedef enum pkg_state_flag pkg_state_flag_t;
  11135. +#define SF_NONVOLATILE_FLAGS (SF_HOLD|SF_NOPRUNE|SF_PREFER|SF_OBSOLETE|SF_USER)
  11136. +
  11137. +enum pkg_state_status
  11138. +{
  11139. + SS_NOT_INSTALLED = 1,
  11140. + SS_UNPACKED,
  11141. + SS_HALF_CONFIGURED,
  11142. + SS_INSTALLED,
  11143. + SS_HALF_INSTALLED,
  11144. + SS_CONFIG_FILES,
  11145. + SS_POST_INST_FAILED,
  11146. + SS_REMOVAL_FAILED,
  11147. + SS_LAST_STATE_STATUS
  11148. +};
  11149. +typedef enum pkg_state_status pkg_state_status_t;
  11150. +
  11151. +struct abstract_pkg{
  11152. + char * name;
  11153. + int dependencies_checked;
  11154. + pkg_vec_t * pkgs;
  11155. + pkg_state_status_t state_status;
  11156. + pkg_state_flag_t state_flag;
  11157. + struct abstract_pkg ** depended_upon_by; /* @@@@ this should be abstract_pkg_vec_t -Jamey */
  11158. + abstract_pkg_vec_t * provided_by;
  11159. + abstract_pkg_vec_t * replaced_by;
  11160. +};
  11161. +
  11162. +#include "pkg_depends.h"
  11163. +
  11164. +/* XXX: CLEANUP: I'd like to clean up pkg_t in several ways:
  11165. +
  11166. + The 3 version fields should go into a single version struct. (This
  11167. + is especially important since, currently, pkg->version can easily
  11168. + be mistaken for pkg_verson_str_alloc(pkg) although they are very
  11169. + distinct. This has been the source of multiple bugs.
  11170. +
  11171. + The 3 state fields could possibly also go into their own struct.
  11172. +
  11173. + All fields which deal with lists of packages, (Depends,
  11174. + Pre-Depends, Provides, Suggests, Recommends, Enhances), should each
  11175. + be handled by a single struct in pkg_t
  11176. +
  11177. + All string fields for which there is a small set of possible
  11178. + values, (section, maintainer, architecture, maybe version?), that
  11179. + are reused among different packages -- for all such packages we
  11180. + should move from "char *"s to some atom datatype to share data
  11181. + storage and use less memory. We might even do reference counting,
  11182. + but probably not since most often we only create new pkg_t structs,
  11183. + we don't often free them. */
  11184. +struct pkg
  11185. +{
  11186. + char *name;
  11187. + unsigned long epoch;
  11188. + char *version;
  11189. + char *revision;
  11190. + char *familiar_revision;
  11191. + pkg_src_t *src;
  11192. + pkg_dest_t *dest;
  11193. + char *architecture;
  11194. + char *section;
  11195. + char *maintainer;
  11196. + char *description;
  11197. + pkg_state_want_t state_want;
  11198. + pkg_state_flag_t state_flag;
  11199. + pkg_state_status_t state_status;
  11200. + char **depends_str;
  11201. + int depends_count;
  11202. + char **pre_depends_str;
  11203. + int pre_depends_count;
  11204. + char **recommends_str;
  11205. + int recommends_count;
  11206. + char **suggests_str;
  11207. + int suggests_count;
  11208. + compound_depend_t * depends;
  11209. +
  11210. + /* Abhaya: new conflicts */
  11211. + char **conflicts_str;
  11212. + compound_depend_t * conflicts;
  11213. + int conflicts_count;
  11214. +
  11215. + char **replaces_str;
  11216. + int replaces_count;
  11217. + abstract_pkg_t ** replaces;
  11218. +
  11219. + char **provides_str;
  11220. + int provides_count;
  11221. + abstract_pkg_t ** provides;
  11222. +
  11223. + abstract_pkg_t *parent;
  11224. +
  11225. + pkg_t *old_pkg; /* during upgrade, points from installee to previously installed */
  11226. +
  11227. + char *filename;
  11228. + char *local_filename;
  11229. + char *url;
  11230. + char *tmp_unpack_dir;
  11231. + char *md5sum;
  11232. + char *size;
  11233. + char *installed_size;
  11234. + char *priority;
  11235. + char *source;
  11236. + conffile_list_t conffiles;
  11237. + time_t installed_time;
  11238. + /* As pointer for lazy evaluation */
  11239. + str_list_t *installed_files;
  11240. + /* XXX: CLEANUP: I'd like to perhaps come up with a better
  11241. + mechanism to avoid the problem here, (which is that the
  11242. + installed_files list was being freed from an inner loop while
  11243. + still being used within an outer loop. */
  11244. + int installed_files_ref_cnt;
  11245. + int essential;
  11246. + int arch_priority;
  11247. +/* Adding this flag, to "force" ipkg to choose a "provided_by_hand" package, if there are multiple choice */
  11248. + int provided_by_hand;
  11249. +};
  11250. +
  11251. +pkg_t *pkg_new(void);
  11252. +int pkg_init(pkg_t *pkg);
  11253. +void pkg_deinit(pkg_t *pkg);
  11254. +int pkg_init_from_file(pkg_t *pkg, const char *filename);
  11255. +abstract_pkg_t *abstract_pkg_new(void);
  11256. +int abstract_pkg_init(abstract_pkg_t *ab_pkg);
  11257. +
  11258. +/*
  11259. + * merges fields from newpkg into oldpkg.
  11260. + * Forcibly sets oldpkg state_status, state_want and state_flags if set_status is nonzero
  11261. + */
  11262. +int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status);
  11263. +
  11264. +char *pkg_version_str_alloc(pkg_t *pkg);
  11265. +
  11266. +int pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg);
  11267. +int pkg_name_version_and_architecture_compare(pkg_t *a, pkg_t *b);
  11268. +int abstract_pkg_name_compare(abstract_pkg_t *a, abstract_pkg_t *b);
  11269. +
  11270. +char * pkg_formatted_info(pkg_t *pkg );
  11271. +char * pkg_formatted_field(pkg_t *pkg, const char *field );
  11272. +
  11273. +void set_flags_from_control(ipkg_conf_t *conf, pkg_t *pkg);
  11274. +
  11275. +void pkg_print_info(pkg_t *pkg, FILE *file);
  11276. +void pkg_print_status(pkg_t * pkg, FILE * file);
  11277. +void pkg_print_field(pkg_t *pkg, FILE *file, const char *field);
  11278. +str_list_t *pkg_get_installed_files(pkg_t *pkg);
  11279. +int pkg_free_installed_files(pkg_t *pkg);
  11280. +int pkg_remove_installed_files_list(ipkg_conf_t *conf, pkg_t *pkg);
  11281. +conffile_t *pkg_get_conffile(pkg_t *pkg, const char *file_name);
  11282. +int pkg_run_script(struct ipkg_conf *conf, pkg_t *pkg,
  11283. + const char *script, const char *args);
  11284. +
  11285. +/* enum mappings */
  11286. +char *pkg_state_want_to_str(pkg_state_want_t sw);
  11287. +pkg_state_want_t pkg_state_want_from_str(char *str);
  11288. +char *pkg_state_flag_to_str(pkg_state_flag_t sf);
  11289. +pkg_state_flag_t pkg_state_flag_from_str(char *str);
  11290. +char *pkg_state_status_to_str(pkg_state_status_t ss);
  11291. +pkg_state_status_t pkg_state_status_from_str(char *str);
  11292. +
  11293. +int pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op);
  11294. +
  11295. +int pkg_arch_supported(ipkg_conf_t *conf, pkg_t *pkg);
  11296. +int pkg_info_preinstall_check(ipkg_conf_t *conf);
  11297. +int pkg_free_installed_files(pkg_t *pkg);
  11298. +
  11299. +int pkg_write_filelist(ipkg_conf_t *conf, pkg_t *pkg);
  11300. +int pkg_write_changed_filelists(ipkg_conf_t *conf);
  11301. +
  11302. +#endif
  11303. diff -Nur busybox-1.21.1.orig/archival/libipkg/pkg_hash.c busybox-1.21.1/archival/libipkg/pkg_hash.c
  11304. --- busybox-1.21.1.orig/archival/libipkg/pkg_hash.c 1970-01-01 01:00:00.000000000 +0100
  11305. +++ busybox-1.21.1/archival/libipkg/pkg_hash.c 2014-02-17 14:25:39.862534201 +0100
  11306. @@ -0,0 +1,623 @@
  11307. +/* ipkg_hash.c - the itsy package management system
  11308. +
  11309. + Steven M. Ayer
  11310. +
  11311. + Copyright (C) 2002 Compaq Computer Corporation
  11312. +
  11313. + This program is free software; you can redistribute it and/or
  11314. + modify it under the terms of the GNU General Public License as
  11315. + published by the Free Software Foundation; either version 2, or (at
  11316. + your option) any later version.
  11317. +
  11318. + This program is distributed in the hope that it will be useful, but
  11319. + WITHOUT ANY WARRANTY; without even the implied warranty of
  11320. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11321. + General Public License for more details.
  11322. +*/
  11323. +
  11324. +#include "ipkg.h"
  11325. +#include <errno.h>
  11326. +#include <ctype.h>
  11327. +#include <stdlib.h>
  11328. +#include <string.h>
  11329. +
  11330. +#include "hash_table.h"
  11331. +#include "pkg.h"
  11332. +#include "ipkg_message.h"
  11333. +#include "pkg_vec.h"
  11334. +#include "pkg_hash.h"
  11335. +#include "pkg_parse.h"
  11336. +#include "ipkg_utils.h"
  11337. +
  11338. +static abstract_pkg_t * add_new_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name);
  11339. +
  11340. +/*
  11341. + * this will talk to both feeds-lists files and installed status files
  11342. + * example api:
  11343. + *
  11344. + * hash_table_t hash;
  11345. + * pkg_hash_init(name, &hash, 1000);
  11346. + * pkg_hash_add_from_file(<feed filename>);
  11347. + *
  11348. + * the query function is just there as a shell to prove to me that this
  11349. + * sort of works, but isn't far from doing something useful
  11350. + *
  11351. + * -sma, 12/21/01
  11352. + * modified: CDW 3 Jan. 2002
  11353. + */
  11354. +
  11355. +
  11356. +
  11357. +int pkg_hash_init(const char *name, hash_table_t *hash, int len)
  11358. +{
  11359. + return hash_table_init(name, hash, len);
  11360. +}
  11361. +
  11362. +void pkg_hash_deinit(hash_table_t *hash)
  11363. +{
  11364. + hash_table_deinit(hash);
  11365. +}
  11366. +
  11367. +
  11368. +/* Find the default arch for a given package status file if none is given. */
  11369. +static char *pkg_get_default_arch(ipkg_conf_t *conf)
  11370. +{
  11371. + nv_pair_list_elt_t *l;
  11372. + const char *def_arch = HOST_CPU_STR; /* Default arch */
  11373. + int def_prio = 0; /* Other archs override this */
  11374. +
  11375. + l = conf->arch_list.head;
  11376. +
  11377. + while (l) {
  11378. + nv_pair_t *nv = l->data;
  11379. + int priority = strtol(nv->value, NULL, 0);
  11380. +
  11381. + /* Check if this arch has higher priority, and is valid */
  11382. + if ((priority > def_prio) &&
  11383. + (strcmp(nv->name, "all")) && (strcmp(nv->name, "noarch"))) {
  11384. + /* Our new default */
  11385. + def_prio = priority;
  11386. + def_arch = nv->name;
  11387. + }
  11388. + l = l->next;
  11389. + }
  11390. +
  11391. + return strdup(def_arch);
  11392. +}
  11393. +
  11394. +int pkg_hash_add_from_file(ipkg_conf_t *conf, const char *file_name,
  11395. + pkg_src_t *src, pkg_dest_t *dest, int is_status_file)
  11396. +{
  11397. + hash_table_t *hash = &conf->pkg_hash;
  11398. + char **raw;
  11399. + char **raw_start;
  11400. + pkg_t *pkg;
  11401. +
  11402. + raw = raw_start = read_raw_pkgs_from_file(file_name);
  11403. + if (!raw)
  11404. + return -ENOMEM;
  11405. +
  11406. + while(*raw){ /* don't worry, we'll increment raw in the parsing function */
  11407. + pkg = pkg_new();
  11408. + if (!pkg)
  11409. + return -ENOMEM;
  11410. +
  11411. + if (pkg_parse_raw(pkg, &raw, src, dest) == 0) {
  11412. + if (!pkg->architecture) {
  11413. + char *version_str = pkg_version_str_alloc(pkg);
  11414. + pkg->architecture = pkg_get_default_arch(conf);
  11415. + ipkg_message(conf, IPKG_ERROR, "Package %s version %s has no architecture specified, defaulting to %s.\n",
  11416. + pkg->name, version_str, pkg->architecture);
  11417. + free(version_str);
  11418. + }
  11419. + hash_insert_pkg(hash, pkg, is_status_file,conf);
  11420. + } else {
  11421. + free(pkg);
  11422. + }
  11423. + }
  11424. +
  11425. + /* XXX: CLEANUP: I'd like a cleaner interface for cleaning up
  11426. + memory after read_raw_pkgs_from_file */
  11427. + raw = raw_start;
  11428. + while (*raw) {
  11429. + free(*raw++);
  11430. + }
  11431. + free(raw_start);
  11432. + return 0;
  11433. +}
  11434. +
  11435. +abstract_pkg_t * abstract_pkg_fetch_by_name(hash_table_t * hash, const char * pkg_name)
  11436. +{
  11437. + return (abstract_pkg_t *)hash_table_get(hash, pkg_name);
  11438. +}
  11439. +
  11440. +abstract_pkg_vec_t *pkg_hash_fetch_all_installation_candidates(hash_table_t *hash, const char *name)
  11441. +{
  11442. + abstract_pkg_t *apkg = abstract_pkg_fetch_by_name(hash, name);
  11443. + if (apkg)
  11444. + return NULL;
  11445. + return apkg->provided_by;
  11446. +}
  11447. +
  11448. +
  11449. +pkg_t *pkg_hash_fetch_best_installation_candidate(ipkg_conf_t *conf, abstract_pkg_t *apkg,
  11450. + int (*constraint_fcn)(pkg_t *pkg, void *cdata), void *cdata, int quiet)
  11451. +{
  11452. + int i;
  11453. + int nprovides = 0;
  11454. + int nmatching = 0;
  11455. + pkg_vec_t *matching_pkgs = pkg_vec_alloc();
  11456. + abstract_pkg_vec_t *matching_apkgs = abstract_pkg_vec_alloc();
  11457. + abstract_pkg_vec_t *provided_apkg_vec;
  11458. + abstract_pkg_t **provided_apkgs;
  11459. + abstract_pkg_vec_t *providers = abstract_pkg_vec_alloc();
  11460. + pkg_t *latest_installed_parent = NULL;
  11461. + pkg_t *latest_matching = NULL;
  11462. + pkg_t *held_pkg = NULL;
  11463. + pkg_t *good_pkg_by_name = NULL;
  11464. +
  11465. + if (matching_apkgs == NULL || providers == NULL ||
  11466. + apkg == NULL || apkg->provided_by == NULL || (apkg->provided_by->len == 0))
  11467. + return NULL;
  11468. +
  11469. + ipkg_message(conf, IPKG_DEBUG, "best installation candidate for %s\n", apkg->name);
  11470. +
  11471. + provided_apkg_vec = apkg->provided_by;
  11472. + nprovides = provided_apkg_vec->len;
  11473. + provided_apkgs = provided_apkg_vec->pkgs;
  11474. + if (nprovides > 1)
  11475. + ipkg_message(conf, IPKG_DEBUG, " apkg=%s nprovides=%d\n", apkg->name, nprovides);
  11476. +
  11477. + /* accumulate all the providers */
  11478. + for (i = 0; i < nprovides; i++) {
  11479. + abstract_pkg_t *provider_apkg = provided_apkgs[i];
  11480. + ipkg_message(conf, IPKG_DEBUG, " adding %s to providers\n", provider_apkg->name);
  11481. + abstract_pkg_vec_insert(providers, provider_apkg);
  11482. + }
  11483. + nprovides = providers->len;
  11484. +
  11485. + for (i = 0; i < nprovides; i++) {
  11486. + abstract_pkg_t *provider_apkg = abstract_pkg_vec_get(providers, i);
  11487. + abstract_pkg_t *replacement_apkg = NULL;
  11488. + pkg_vec_t *vec;
  11489. +
  11490. + if (provider_apkg->replaced_by && provider_apkg->replaced_by->len) {
  11491. + replacement_apkg = provider_apkg->replaced_by->pkgs[0];
  11492. + if (provider_apkg->replaced_by->len > 1) {
  11493. + ipkg_message(conf, IPKG_NOTICE, "Multiple replacers for %s, using first one (%s)\n",
  11494. + provider_apkg->name, replacement_apkg->name);
  11495. + }
  11496. + }
  11497. +
  11498. + if (replacement_apkg)
  11499. + ipkg_message(conf, IPKG_DEBUG, " replacement_apkg=%s for provider_apkg=%s\n",
  11500. + replacement_apkg->name, provider_apkg->name);
  11501. +
  11502. + if (replacement_apkg && (replacement_apkg != provider_apkg)) {
  11503. + if (abstract_pkg_vec_contains(providers, replacement_apkg))
  11504. + continue;
  11505. + else
  11506. + provider_apkg = replacement_apkg;
  11507. + }
  11508. +
  11509. + if (!(vec = provider_apkg->pkgs)) {
  11510. + ipkg_message(conf, IPKG_DEBUG, " no pkgs for provider_apkg %s\n", provider_apkg->name);
  11511. + continue;
  11512. + }
  11513. +
  11514. +
  11515. + /* now check for supported architecture */
  11516. + {
  11517. + int max_count = 0;
  11518. + int j;
  11519. +
  11520. + /* count packages matching max arch priority and keep track of last one */
  11521. + for (j = 0; j < vec->len; j++) {
  11522. + pkg_t *maybe = vec->pkgs[j];
  11523. + ipkg_message(conf, IPKG_DEBUG, " %s arch=%s arch_priority=%d version=%s \n",
  11524. + maybe->name, maybe->architecture, maybe->arch_priority, maybe->version);
  11525. + if (maybe->arch_priority > 0) {
  11526. + max_count++;
  11527. + abstract_pkg_vec_insert(matching_apkgs, maybe->parent);
  11528. + pkg_vec_insert(matching_pkgs, maybe);
  11529. + }
  11530. + }
  11531. + }
  11532. + }
  11533. +
  11534. + if (matching_pkgs->len > 1)
  11535. + pkg_vec_sort(matching_pkgs, pkg_name_version_and_architecture_compare);
  11536. + if (matching_apkgs->len > 1)
  11537. + abstract_pkg_vec_sort(matching_pkgs, abstract_pkg_name_compare);
  11538. +
  11539. +/* Here it is usefull, if ( matching_apkgs->len > 1 ), to test if one of this matching packages has the same name of the
  11540. + needed package. In this case, I would return it for install, otherwise I will continue with the procedure */
  11541. +/* The problem is what to do when there are more than a mathing package, with the same name and several version ?
  11542. + Until now I always got the latest, but that breaks the downgrade option.
  11543. + If I stop at the first one, I would probably miss the new ones
  11544. + Maybe the way is to have some kind of flag somewhere, to see if the package been asked to install is from a file,
  11545. + or from a Packages feed.
  11546. + 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*/
  11547. +/*Pigi*/
  11548. +
  11549. + for (i = 0; i < matching_pkgs->len; i++) {
  11550. + pkg_t *matching = matching_pkgs->pkgs[i];
  11551. + if (constraint_fcn(matching, cdata)) { /* We found it */
  11552. + ipkg_message(conf, IPKG_DEBUG, " Found a valid candidate for the install: %s %s \n", matching->name, matching->version) ;
  11553. + good_pkg_by_name = matching;
  11554. + if ( matching->provided_by_hand == 1 ) /* It has been provided by hand, so it is what user want */
  11555. + break;
  11556. + }
  11557. + }
  11558. +
  11559. +
  11560. + for (i = 0; i < matching_pkgs->len; i++) {
  11561. + pkg_t *matching = matching_pkgs->pkgs[i];
  11562. + latest_matching = matching;
  11563. + if (matching->parent->state_status == SS_INSTALLED || matching->parent->state_status == SS_UNPACKED)
  11564. + latest_installed_parent = matching;
  11565. + if (matching->state_flag & (SF_HOLD|SF_PREFER)) {
  11566. + if (held_pkg)
  11567. + ipkg_message(conf, IPKG_ERROR, "Multiple packages (%s and %s) providing same name marked HOLD or PREFER. Using latest.\n",
  11568. + held_pkg->name, matching->name);
  11569. + held_pkg = matching;
  11570. + }
  11571. + }
  11572. +
  11573. + if (!good_pkg_by_name && !held_pkg && !latest_installed_parent && matching_apkgs->len > 1 && !quiet) {
  11574. + ipkg_message(conf, IPKG_ERROR, "Package=%s, %d matching providers\n",
  11575. + apkg->name, matching_apkgs->len);
  11576. + for (i = 0; i < matching_apkgs->len; i++) {
  11577. + abstract_pkg_t *matching = matching_apkgs->pkgs[i];
  11578. + ipkg_message(conf, IPKG_ERROR, " %s\n", matching->name);
  11579. + }
  11580. + ipkg_message(conf, IPKG_ERROR, "Please select one with ipkg install or ipkg flag prefer\n");
  11581. + }
  11582. +
  11583. + if (matching_apkgs->len > 1 && conf->verbosity > 1) {
  11584. + ipkg_message(conf, IPKG_NOTICE, "%s: for apkg=%s, %d matching pkgs\n",
  11585. + __FUNCTION__, apkg->name, matching_pkgs->len);
  11586. + for (i = 0; i < matching_pkgs->len; i++) {
  11587. + pkg_t *matching = matching_pkgs->pkgs[i];
  11588. + ipkg_message(conf, IPKG_INFO, " %s %s %s\n",
  11589. + matching->name, matching->version, matching->architecture);
  11590. + }
  11591. + }
  11592. +
  11593. + nmatching = matching_apkgs->len;
  11594. +
  11595. + pkg_vec_free(matching_pkgs);
  11596. + abstract_pkg_vec_free(matching_apkgs);
  11597. + abstract_pkg_vec_free(providers);
  11598. +
  11599. + if (good_pkg_by_name) { /* We found a good candidate, we will install it */
  11600. + return good_pkg_by_name;
  11601. + }
  11602. + if (held_pkg) {
  11603. + ipkg_message(conf, IPKG_INFO, " using held package %s\n", held_pkg->name);
  11604. + return held_pkg;
  11605. + }
  11606. + if (latest_installed_parent) {
  11607. + ipkg_message(conf, IPKG_INFO, " using latest version of installed package %s\n", latest_installed_parent->name);
  11608. + return latest_installed_parent;
  11609. + }
  11610. + if (nmatching > 1) {
  11611. + ipkg_message(conf, IPKG_INFO, " no matching pkg out of matching_apkgs=%d\n", nmatching);
  11612. + return NULL;
  11613. + }
  11614. + if (latest_matching) {
  11615. + ipkg_message(conf, IPKG_INFO, " using latest matching %s %s %s\n",
  11616. + latest_matching->name, latest_matching->version, latest_matching->architecture);
  11617. + return latest_matching;
  11618. + }
  11619. + return NULL;
  11620. +}
  11621. +
  11622. +static int pkg_name_constraint_fcn(pkg_t *pkg, void *cdata)
  11623. +{
  11624. + const char *name = (const char *)cdata;
  11625. + if (strcmp(pkg->name, name) == 0)
  11626. + return 1;
  11627. + else
  11628. + return 0;
  11629. +}
  11630. +
  11631. +pkg_t *pkg_hash_fetch_best_installation_candidate_by_name(ipkg_conf_t *conf, const char *name)
  11632. +{
  11633. + hash_table_t *hash = &conf->pkg_hash;
  11634. + abstract_pkg_t *apkg = NULL;
  11635. +
  11636. + if (!(apkg = abstract_pkg_fetch_by_name(hash, name)))
  11637. + return NULL;
  11638. +
  11639. + return pkg_hash_fetch_best_installation_candidate(conf, apkg, pkg_name_constraint_fcn, apkg->name, 0);
  11640. +}
  11641. +
  11642. +
  11643. +pkg_t * pkg_hash_fetch_by_name_version(hash_table_t *hash,
  11644. + const char *pkg_name,
  11645. + const char * version)
  11646. +{
  11647. + pkg_vec_t * vec;
  11648. + register int i;
  11649. + char *version_str = NULL;
  11650. +
  11651. + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name)))
  11652. + return NULL;
  11653. +
  11654. + for(i = 0; i < vec->len; i++) {
  11655. + version_str = pkg_version_str_alloc(vec->pkgs[i]);
  11656. + if(!strcmp(version_str, version)) {
  11657. + free(version_str);
  11658. + break;
  11659. + }
  11660. + free(version_str);
  11661. + }
  11662. +
  11663. + if(i == vec->len)
  11664. + return NULL;
  11665. +
  11666. + return vec->pkgs[i];
  11667. +}
  11668. +
  11669. +pkg_t *pkg_hash_fetch_installed_by_name_dest(hash_table_t *hash,
  11670. + const char *pkg_name,
  11671. + pkg_dest_t *dest)
  11672. +{
  11673. + pkg_vec_t * vec;
  11674. + register int i;
  11675. +
  11676. + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name))) {
  11677. + return NULL;
  11678. + }
  11679. +
  11680. + for(i = 0; i < vec->len; i++)
  11681. + if((vec->pkgs[i]->state_status == SS_INSTALLED || vec->pkgs[i]->state_status == SS_UNPACKED) && vec->pkgs[i]->dest == dest) {
  11682. + return vec->pkgs[i];
  11683. + }
  11684. + return NULL;
  11685. +}
  11686. +
  11687. +pkg_t *pkg_hash_fetch_installed_by_name(hash_table_t *hash,
  11688. + const char *pkg_name)
  11689. +{
  11690. + pkg_vec_t * vec;
  11691. + register int i;
  11692. +
  11693. + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name))){
  11694. + return NULL;
  11695. + }
  11696. +
  11697. + for(i = 0; i < vec->len; i++)
  11698. + if (vec->pkgs[i]->state_status == SS_INSTALLED || vec->pkgs[i]->state_status == SS_UNPACKED){
  11699. + return vec->pkgs[i];
  11700. + }
  11701. +
  11702. + return NULL;
  11703. +}
  11704. +
  11705. +pkg_vec_t *pkg_vec_fetch_by_name(hash_table_t *hash, const char *pkg_name)
  11706. +{
  11707. + abstract_pkg_t * ab_pkg;
  11708. +
  11709. + if(!(ab_pkg = abstract_pkg_fetch_by_name(hash, pkg_name))){
  11710. + return NULL;
  11711. + }
  11712. +
  11713. + if (ab_pkg->pkgs) {
  11714. + return ab_pkg->pkgs;
  11715. + } else if (ab_pkg->provided_by) {
  11716. + abstract_pkg_t *abpkg = abstract_pkg_vec_get(ab_pkg->provided_by, 0);
  11717. + if (abpkg != NULL){
  11718. + return abpkg->pkgs;
  11719. + } else {
  11720. + return ab_pkg->pkgs;
  11721. + }
  11722. + } else {
  11723. + return NULL;
  11724. + }
  11725. +}
  11726. +
  11727. +static int pkg_compare_names(const void *p1, const void *p2)
  11728. +{
  11729. + const pkg_t *pkg1 = *(const pkg_t **)p1;
  11730. + const pkg_t *pkg2 = *(const pkg_t **)p2;
  11731. + if (pkg1->name == NULL)
  11732. + return 1;
  11733. + if (pkg2->name == NULL)
  11734. + return -1;
  11735. + return(strcmp(pkg1->name, pkg2->name));
  11736. +}
  11737. +
  11738. +
  11739. +static void pkg_hash_fetch_available_helper(const char *pkg_name, void *entry, void *data)
  11740. +{
  11741. + int j;
  11742. + const char *name;
  11743. + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
  11744. + pkg_vec_t *all = (pkg_vec_t *)data;
  11745. + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
  11746. + name = pkg_name;
  11747. + if (pkg_vec) {
  11748. + for (j = 0; j < pkg_vec->len; j++) {
  11749. + pkg_t *pkg = pkg_vec->pkgs[j];
  11750. + pkg_vec_insert(all, pkg);
  11751. + }
  11752. + }
  11753. +}
  11754. +
  11755. +void pkg_hash_fetch_available(hash_table_t *hash, pkg_vec_t *all)
  11756. +{
  11757. + hash_table_foreach(hash, pkg_hash_fetch_available_helper, all);
  11758. + qsort(all->pkgs, all->len, sizeof(pkg_t *), pkg_compare_names);
  11759. +}
  11760. +
  11761. +static void pkg_hash_fetch_all_installed_helper(const char *pkg_name, void *entry, void *data)
  11762. +{
  11763. + const char *name;
  11764. + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
  11765. + pkg_vec_t *all = (pkg_vec_t *)data;
  11766. + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
  11767. + int j;
  11768. + name = pkg_name;
  11769. + if (pkg_vec) {
  11770. + for (j = 0; j < pkg_vec->len; j++) {
  11771. + pkg_t *pkg = pkg_vec->pkgs[j];
  11772. + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) {
  11773. + pkg_vec_insert(all, pkg);
  11774. + }
  11775. + }
  11776. + }
  11777. +}
  11778. +void pkg_hash_fetch_all_installed(hash_table_t *hash, pkg_vec_t *all)
  11779. +{
  11780. + hash_table_foreach(hash, pkg_hash_fetch_all_installed_helper, all);
  11781. + qsort(all->pkgs, all->len, sizeof(void*), pkg_compare_names);
  11782. +}
  11783. +
  11784. +static void pkg_hash_dump_helper(const char *pkg_name, void *entry, void *data)
  11785. +{
  11786. + int i;
  11787. + pkg_t *pkg;
  11788. + const char *name;
  11789. + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
  11790. + ipkg_conf_t *conf = (ipkg_conf_t *)data;
  11791. + abstract_pkg_t ** dependents = ab_pkg->depended_upon_by;
  11792. + name = pkg_name;
  11793. + fprintf(stdout, "%s\n", ab_pkg->name);
  11794. + i = 0;
  11795. + if (dependents != NULL)
  11796. + while (dependents [i] != NULL)
  11797. + printf ("\tdepended upon by - %s\n", dependents [i ++]->name);
  11798. + dependents = ab_pkg->provided_by->pkgs;
  11799. + i = 0;
  11800. + if (dependents != NULL)
  11801. + while (dependents [i] != NULL && i < ab_pkg->provided_by->len)
  11802. + printf ("\tprovided by - %s\n", dependents [i ++]->name);
  11803. + pkg = pkg_hash_fetch_best_installation_candidate_by_name (conf, ab_pkg->name);
  11804. + if (pkg) {
  11805. + i = 0;
  11806. + while (i < pkg->depends_count)
  11807. + printf ("\tdepends on - %s\n", pkg->depends_str [i ++]);
  11808. + }
  11809. +}
  11810. +void pkg_hash_dump(hash_table_t *hash, void *data)
  11811. +{
  11812. +
  11813. + printf ("\n\n+=+%s+=+\n\n", __FUNCTION__);
  11814. + hash_table_foreach(hash, pkg_hash_dump_helper, data);
  11815. + printf ("\n+=+%s+=+\n\n", __FUNCTION__);
  11816. +}
  11817. +
  11818. +abstract_pkg_t * ensure_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name)
  11819. +{
  11820. + abstract_pkg_t * ab_pkg;
  11821. +
  11822. + if(!(ab_pkg = abstract_pkg_fetch_by_name(hash, pkg_name)))
  11823. + ab_pkg = add_new_abstract_pkg_by_name(hash, pkg_name);
  11824. +
  11825. + return ab_pkg;
  11826. +}
  11827. +
  11828. +pkg_t *hash_insert_pkg(hash_table_t *hash, pkg_t *pkg, int set_status,ipkg_conf_t *conf)
  11829. +{
  11830. + abstract_pkg_t * ab_pkg;
  11831. + int arch_priority;
  11832. +
  11833. + if(!pkg)
  11834. + return pkg;
  11835. +
  11836. + arch_priority = pkg->arch_priority;
  11837. +
  11838. + if (buildDepends(hash, pkg)<0){
  11839. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  11840. + return NULL;
  11841. + }
  11842. + ab_pkg = ensure_abstract_pkg_by_name(hash, pkg->name);
  11843. +
  11844. + if (set_status) {
  11845. + if (pkg->state_status == SS_INSTALLED) {
  11846. + ab_pkg->state_status = SS_INSTALLED;
  11847. + } else if (pkg->state_status == SS_UNPACKED) {
  11848. + ab_pkg->state_status = SS_UNPACKED;
  11849. + }
  11850. + }
  11851. +
  11852. + if(!ab_pkg->pkgs)
  11853. + ab_pkg->pkgs = pkg_vec_alloc();
  11854. +
  11855. + /* pkg_vec_insert_merge might munge package, but it returns an unmunged pkg */
  11856. + pkg = pkg_vec_insert_merge(ab_pkg->pkgs, pkg, set_status,conf );
  11857. + pkg->parent = ab_pkg;
  11858. +
  11859. + if (buildProvides(hash, ab_pkg, pkg)<0){
  11860. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  11861. + return NULL;
  11862. + }
  11863. + /* need to build the conflicts graph before replaces for correct calculation of replaced_by relation */
  11864. + if (buildConflicts(hash, pkg)<0){
  11865. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  11866. + return NULL;
  11867. + }
  11868. + if (buildReplaces(hash, ab_pkg, pkg)<0) {
  11869. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  11870. + return NULL;
  11871. + }
  11872. +
  11873. + buildDependedUponBy(pkg, ab_pkg);
  11874. + return pkg;
  11875. +}
  11876. +
  11877. +/*
  11878. + * this will assume that we've already determined that
  11879. + * the abstract pkg doesn't exist, 'cause we should know these things...
  11880. + */
  11881. +static abstract_pkg_t * add_new_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name)
  11882. +{
  11883. + abstract_pkg_t * ab_pkg;
  11884. +
  11885. + ab_pkg = abstract_pkg_new();
  11886. + if (ab_pkg == NULL) { return NULL; }
  11887. +
  11888. + ab_pkg->name = strdup(pkg_name);
  11889. + hash_table_insert(hash, pkg_name, ab_pkg);
  11890. +
  11891. + return ab_pkg;
  11892. +}
  11893. +
  11894. +
  11895. +pkg_t *file_hash_get_file_owner(ipkg_conf_t *conf, const char *file_name)
  11896. +{
  11897. + hash_table_t *file_hash = &conf->file_hash;
  11898. +
  11899. + return hash_table_get(file_hash, file_name);
  11900. +}
  11901. +
  11902. +int file_hash_set_file_owner(ipkg_conf_t *conf, const char *file_name, pkg_t *owning_pkg)
  11903. +{
  11904. + hash_table_t *file_hash = &conf->file_hash;
  11905. + pkg_t *old_owning_pkg = hash_table_get(file_hash, file_name);
  11906. + int file_name_len = strlen(file_name);
  11907. +
  11908. + if (file_name[file_name_len -1] == '/')
  11909. + return 0;
  11910. +
  11911. + if (conf->offline_root) {
  11912. + int len = strlen(conf->offline_root);
  11913. + if (strncmp(file_name, conf->offline_root, len) == 0) {
  11914. + file_name += len;
  11915. + }
  11916. + }
  11917. +
  11918. + // ipkg_message(conf, IPKG_DEBUG2, "owning_pkg=%s filename=%s\n", owning_pkg->name, file_name);
  11919. + hash_table_insert(file_hash, file_name, owning_pkg);
  11920. + if (old_owning_pkg) {
  11921. + str_list_remove_elt(old_owning_pkg->installed_files, file_name);
  11922. + /* mark this package to have its filelist written */
  11923. + old_owning_pkg->state_flag |= SF_FILELIST_CHANGED;
  11924. + owning_pkg->state_flag |= SF_FILELIST_CHANGED;
  11925. + }
  11926. + return 0;
  11927. +}
  11928. +
  11929. +
  11930. diff -Nur busybox-1.21.1.orig/archival/libipkg/pkg_hash.h busybox-1.21.1/archival/libipkg/pkg_hash.h
  11931. --- busybox-1.21.1.orig/archival/libipkg/pkg_hash.h 1970-01-01 01:00:00.000000000 +0100
  11932. +++ busybox-1.21.1/archival/libipkg/pkg_hash.h 2014-02-17 14:25:39.862534201 +0100
  11933. @@ -0,0 +1,61 @@
  11934. +/* pkg_hash.h - the itsy package management system
  11935. +
  11936. + Steven M. Ayer
  11937. +
  11938. + Copyright (C) 2002 Compaq Computer Corporation
  11939. +
  11940. + This program is free software; you can redistribute it and/or
  11941. + modify it under the terms of the GNU General Public License as
  11942. + published by the Free Software Foundation; either version 2, or (at
  11943. + your option) any later version.
  11944. +
  11945. + This program is distributed in the hope that it will be useful, but
  11946. + WITHOUT ANY WARRANTY; without even the implied warranty of
  11947. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11948. + General Public License for more details.
  11949. +*/
  11950. +
  11951. +#ifndef PKG_HASH_H
  11952. +#define PKG_HASH_H
  11953. +
  11954. +#include "pkg.h"
  11955. +#include "pkg_vec.h"
  11956. +#include "hash_table.h"
  11957. +
  11958. +
  11959. +int pkg_hash_init(const char *name, hash_table_t *hash, int len);
  11960. +void pkg_hash_deinit(hash_table_t *hash);
  11961. +void pkg_hash_map(hash_table_t *hash, void (*f)(void *data, void *entry), void *data);
  11962. +
  11963. +void pkg_hash_dump(hash_table_t *hash, void *data);
  11964. +void pkg_hash_fetch_available(hash_table_t *hash, pkg_vec_t *available);
  11965. +
  11966. +int pkg_hash_add_from_file(ipkg_conf_t *conf, const char *file_name,
  11967. + pkg_src_t *src, pkg_dest_t *dest, int is_status_file);
  11968. +pkg_t *hash_insert_pkg(hash_table_t *hash, pkg_t *pkg, int set_status,ipkg_conf_t *conf);
  11969. +
  11970. +abstract_pkg_t * ensure_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name);
  11971. +abstract_pkg_t * abstract_pkg_fetch_by_name(hash_table_t * hash, const char * pkg_name);
  11972. +pkg_vec_t *pkg_hash_fetch_by_name(hash_table_t *hash, const char *pkg_name);
  11973. +void pkg_hash_fetch_all_installed(hash_table_t *hash, pkg_vec_t *installed);
  11974. +pkg_t * pkg_hash_fetch_by_name_version(hash_table_t *hash,
  11975. + const char *pkg_name,
  11976. + const char * version);
  11977. +abstract_pkg_vec_t *pkg_hash_fetch_all_installation_candidates(hash_table_t *hash, const char *name);
  11978. +pkg_t *pkg_hash_fetch_best_installation_candidate(ipkg_conf_t *conf, abstract_pkg_t *apkg,
  11979. + int (*constraint_fcn)(pkg_t *pkg, void *data), void *cdata, int quiet);
  11980. +pkg_t *pkg_hash_fetch_best_installation_candidate_by_name(ipkg_conf_t *conf, const char *name);
  11981. +pkg_t *pkg_hash_fetch_installed_by_name(hash_table_t *hash,
  11982. + const char *pkg_name);
  11983. +pkg_t *pkg_hash_fetch_installed_by_name_dest(hash_table_t *hash,
  11984. + const char *pkg_name,
  11985. + pkg_dest_t *dest);
  11986. +
  11987. +pkg_t *file_hash_get_file_owner(ipkg_conf_t *conf, const char *file_name);
  11988. +int file_hash_set_file_owner(ipkg_conf_t *conf, const char *file_name, pkg_t *pkg);
  11989. +
  11990. +/* XXX: shouldn't this go in pkg_vec.[ch]? */
  11991. +pkg_vec_t *pkg_vec_fetch_by_name(hash_table_t *hash, const char *pkg_name);
  11992. +
  11993. +#endif
  11994. +
  11995. diff -Nur busybox-1.21.1.orig/archival/libipkg/pkg_parse.c busybox-1.21.1/archival/libipkg/pkg_parse.c
  11996. --- busybox-1.21.1.orig/archival/libipkg/pkg_parse.c 1970-01-01 01:00:00.000000000 +0100
  11997. +++ busybox-1.21.1/archival/libipkg/pkg_parse.c 2014-02-17 14:25:39.866534213 +0100
  11998. @@ -0,0 +1,368 @@
  11999. +/* pkg_parse.c - the itsy package management system
  12000. +
  12001. + Steven M. Ayer
  12002. +
  12003. + Copyright (C) 2002 Compaq Computer Corporation
  12004. +
  12005. + This program is free software; you can redistribute it and/or
  12006. + modify it under the terms of the GNU General Public License as
  12007. + published by the Free Software Foundation; either version 2, or (at
  12008. + your option) any later version.
  12009. +
  12010. + This program is distributed in the hope that it will be useful, but
  12011. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12012. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12013. + General Public License for more details.
  12014. +*/
  12015. +
  12016. +#include "ipkg.h"
  12017. +#include <errno.h>
  12018. +#include <ctype.h>
  12019. +
  12020. +#include "pkg.h"
  12021. +#include "ipkg_utils.h"
  12022. +#include "pkg_parse.h"
  12023. +
  12024. +int alterProvidesLine(char *raw, char *temp);
  12025. +
  12026. +int isGenericFieldType(char * type, char * line)
  12027. +{
  12028. + if(!strncmp(line, type, strlen(type)))
  12029. + return 1;
  12030. + return 0;
  12031. +}
  12032. +
  12033. +char * parseGenericFieldType(char * type, char * raw)
  12034. +{
  12035. + char * field_value = raw + (strlen(type) + 1);
  12036. + return trim_alloc(field_value);
  12037. +}
  12038. +
  12039. +void parseStatus(pkg_t *pkg, char * raw)
  12040. +{
  12041. + char sw_str[64], sf_str[64], ss_str[64];
  12042. +
  12043. + sscanf(raw, "Status: %s %s %s", sw_str, sf_str, ss_str);
  12044. + pkg->state_want = pkg_state_want_from_str(sw_str);
  12045. + pkg->state_flag = pkg_state_flag_from_str(sf_str);
  12046. + pkg->state_status = pkg_state_status_from_str(ss_str);
  12047. +}
  12048. +
  12049. +char ** parseDependsString(char * raw, int * depends_count)
  12050. +{
  12051. + char ** depends = NULL;
  12052. + int line_count = 0;
  12053. + char buff[2048], * dest;
  12054. +
  12055. + while(raw && *raw && !isspace(*raw)) {
  12056. + raw++;
  12057. + }
  12058. +
  12059. + if(line_is_blank(raw)){
  12060. + *depends_count = line_count;
  12061. + return NULL;
  12062. + }
  12063. + while(raw && *raw){
  12064. + depends = (char **)realloc(depends, sizeof(char *) * (line_count + 1));
  12065. +
  12066. + while(isspace(*raw)) raw++;
  12067. +
  12068. + dest = buff;
  12069. + while((*raw != ',') && *raw)
  12070. + *dest++ = *raw++;
  12071. +
  12072. + *dest = '\0';
  12073. + depends[line_count] = trim_alloc(buff);
  12074. + if(depends[line_count] ==NULL)
  12075. + return NULL;
  12076. + line_count++;
  12077. + if(*raw == ',')
  12078. + raw++;
  12079. + }
  12080. + *depends_count = line_count;
  12081. + return depends;
  12082. +}
  12083. +
  12084. +void parseConffiles(pkg_t * pkg, char * raw)
  12085. +{
  12086. + char file_name[1048], md5sum[1048]; /* please tell me there aren't any longer that 1k */
  12087. +
  12088. + if(!strncmp(raw, "Conffiles:", 10))
  12089. + raw += strlen("Conffiles:");
  12090. +
  12091. + while(*raw && (sscanf(raw, "%s%s", file_name, md5sum) == 2)){
  12092. + conffile_list_append(&pkg->conffiles, file_name, md5sum);
  12093. + /* fprintf(stderr, "%s %s ", file_name, md5sum);*/
  12094. + while (*raw && isspace(*raw)) {
  12095. + raw++;
  12096. + }
  12097. + raw += strlen(file_name);
  12098. + while (*raw && isspace(*raw)) {
  12099. + raw++;
  12100. + }
  12101. + raw += strlen(md5sum);
  12102. + }
  12103. +}
  12104. +
  12105. +int parseVersion(pkg_t *pkg, char *raw)
  12106. +{
  12107. + char *colon, *eepochcolon;
  12108. +#ifdef USE_DEBVERSION
  12109. + char *hyphen;
  12110. +#endif
  12111. + unsigned long epoch;
  12112. +
  12113. + if (!*raw) {
  12114. + fprintf(stderr, "%s: ERROR: version string is empty", __FUNCTION__);
  12115. + return EINVAL;
  12116. + }
  12117. +
  12118. + if (strncmp(raw, "Version:", 8) == 0) {
  12119. + raw += 8;
  12120. + }
  12121. + while (*raw && isspace(*raw)) {
  12122. + raw++;
  12123. + }
  12124. +
  12125. + colon= strchr(raw,':');
  12126. + if (colon) {
  12127. + epoch= strtoul(raw,&eepochcolon,10);
  12128. + if (colon != eepochcolon) {
  12129. + fprintf(stderr, "%s: ERROR: epoch in version is not number", __FUNCTION__);
  12130. + return EINVAL;
  12131. + }
  12132. + if (!*++colon) {
  12133. + fprintf(stderr, "%s: ERROR: nothing after colon in version number", __FUNCTION__);
  12134. + return EINVAL;
  12135. + }
  12136. + raw= colon;
  12137. + pkg->epoch= epoch;
  12138. + } else {
  12139. + pkg->epoch= 0;
  12140. + }
  12141. +
  12142. + pkg->revision = (char *)"";
  12143. + pkg->familiar_revision = (char *)"";
  12144. +
  12145. + pkg->version= malloc(strlen(raw)+1);
  12146. + if ( pkg->version == NULL ) {
  12147. + fprintf(stderr, "%s: out of memory \n", __FUNCTION__);
  12148. + return ENOMEM;
  12149. + }
  12150. + strcpy(pkg->version, raw);
  12151. +
  12152. +#ifdef USE_DEBVERSION
  12153. + hyphen= strrchr(pkg->version,'-');
  12154. +
  12155. + if (hyphen) {
  12156. + *hyphen++= 0;
  12157. + if (strncmp("fam", hyphen, 3) == 0) {
  12158. + pkg->familiar_revision=hyphen+3;
  12159. + hyphen= strrchr(pkg->version,'-');
  12160. + if (hyphen) {
  12161. + *hyphen++= 0;
  12162. + pkg->revision = hyphen;
  12163. + }
  12164. + } else {
  12165. + pkg->revision = hyphen;
  12166. + }
  12167. + }
  12168. +#endif
  12169. +
  12170. +/*
  12171. + fprintf(stderr,"Parsed version: %lu, %s, %s, %s\n",
  12172. + pkg->epoch,
  12173. + pkg->version,
  12174. + pkg->revision,
  12175. + pkg->familiar_revision);
  12176. +*/
  12177. +
  12178. + return 0;
  12179. +}
  12180. +
  12181. +
  12182. +/* This code is needed to insert in first position the keyword for the aligning bug */
  12183. +
  12184. +int alterProvidesLine(char *raw, char *temp)
  12185. +{
  12186. +
  12187. +
  12188. + if (!*raw) {
  12189. + fprintf(stderr, "%s: ERROR: Provides string is empty", __FUNCTION__);
  12190. + return -EINVAL;
  12191. + }
  12192. +
  12193. + if ( temp == NULL ) {
  12194. + fprintf(stderr, "%s: out of memory \n", __FUNCTION__);
  12195. + return -ENOMEM;
  12196. + }
  12197. +
  12198. + if (strncmp(raw, "Provides:", 9) == 0) {
  12199. + raw += 9;
  12200. + }
  12201. + while (*raw && isspace(*raw)) {
  12202. + raw++;
  12203. + }
  12204. +
  12205. + snprintf ( temp, 35, "Provides: ipkg_internal_use_only, "); /* First part of the line */
  12206. + while (*raw) {
  12207. + strncat( temp, raw++, 1);
  12208. + }
  12209. + return 0;
  12210. +
  12211. +}
  12212. +
  12213. +/* Some random thoughts from Carl:
  12214. +
  12215. + This function could be considerably simplified if we just kept
  12216. + an array of all the generic string-valued field names, and looped
  12217. + through those looking for a match. Also, these fields could perhaps
  12218. + be stored in the package as an array as well, (or, probably better,
  12219. + as an nv_pair_list_t).
  12220. +
  12221. + Fields which require special parsing or storage, (such as Depends:
  12222. + and Status:) could be handled as they are now.
  12223. +*/
  12224. +/* XXX: FEATURE: The Suggests: field needs to be changed from a string
  12225. + to a dependency list. And, since we already have
  12226. + Depends/Pre-Depends and need to add Conflicts, Recommends, and
  12227. + Enhances, perhaps we could generalize all of these and save some
  12228. + code duplication.
  12229. +*/
  12230. +int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest)
  12231. +{
  12232. + int reading_conffiles, reading_description;
  12233. + int pkg_false_provides=1;
  12234. + char ** lines;
  12235. + char * provide=NULL;
  12236. +
  12237. + pkg->src = src;
  12238. + pkg->dest = dest;
  12239. +
  12240. + reading_conffiles = reading_description = 0;
  12241. +
  12242. + for (lines = *raw; *lines; lines++) {
  12243. + /* fprintf(stderr, "PARSING %s\n", *lines);*/
  12244. + if(isGenericFieldType((char *)"Package:", *lines))
  12245. + pkg->name = parseGenericFieldType((char *)"Package", *lines);
  12246. + else if(isGenericFieldType((char *)"Architecture:", *lines))
  12247. + pkg->architecture = parseGenericFieldType((char *)"Architecture", *lines);
  12248. + else if(isGenericFieldType((char *)"Filename:", *lines))
  12249. + pkg->filename = parseGenericFieldType((char *)"Filename", *lines);
  12250. + else if(isGenericFieldType((char *)"Section:", *lines))
  12251. + pkg->section = parseGenericFieldType((char *)"Section", *lines);
  12252. + else if(isGenericFieldType((char *)"MD5sum:", *lines))
  12253. + pkg->md5sum = parseGenericFieldType((char *)"MD5sum", *lines);
  12254. + /* The old ipkg wrote out status files with the wrong case for MD5sum,
  12255. + let's parse it either way */
  12256. + else if(isGenericFieldType((char *)"MD5Sum:", *lines))
  12257. + pkg->md5sum = parseGenericFieldType((char *)"MD5Sum", *lines);
  12258. + else if(isGenericFieldType((char *)"Size:", *lines))
  12259. + pkg->size = parseGenericFieldType((char *)"Size", *lines);
  12260. + else if(isGenericFieldType((char *)"Source:", *lines))
  12261. + pkg->source = parseGenericFieldType((char *)"Source", *lines);
  12262. + else if(isGenericFieldType((char *)"Installed-Size:", *lines))
  12263. + pkg->installed_size = parseGenericFieldType((char *)"Installed-Size", *lines);
  12264. + else if(isGenericFieldType((char *)"Installed-Time:", *lines)) {
  12265. + char *time_str = parseGenericFieldType((char *)"Installed-Time", *lines);
  12266. + pkg->installed_time = strtoul(time_str, NULL, 0);
  12267. + } else if(isGenericFieldType((char *)"Priority:", *lines))
  12268. + pkg->priority = parseGenericFieldType((char *)"Priority", *lines);
  12269. + else if(isGenericFieldType((char *)"Essential:", *lines)) {
  12270. + char *essential_value;
  12271. + essential_value = parseGenericFieldType((char *)"Essential", *lines);
  12272. + if (strcmp(essential_value, "yes") == 0) {
  12273. + pkg->essential = 1;
  12274. + }
  12275. + free(essential_value);
  12276. + }
  12277. + else if(isGenericFieldType((char *)"Status", *lines))
  12278. + parseStatus(pkg, *lines);
  12279. + else if(isGenericFieldType((char *)"Version", *lines))
  12280. + parseVersion(pkg, *lines);
  12281. + else if(isGenericFieldType((char *)"Maintainer", *lines))
  12282. + pkg->maintainer = parseGenericFieldType((char *)"Maintainer", *lines);
  12283. + else if(isGenericFieldType((char *)"Conffiles", *lines)){
  12284. + parseConffiles(pkg, *lines);
  12285. + reading_conffiles = 1;
  12286. + }
  12287. + else if(isGenericFieldType((char *)"Description", *lines)) {
  12288. + pkg->description = parseGenericFieldType((char *)"Description", *lines);
  12289. + reading_conffiles = 0;
  12290. + reading_description = 1;
  12291. + }
  12292. +
  12293. + else if(isGenericFieldType((char *)"Provides", *lines)){
  12294. +/* Here we add the internal_use to align the off by one problem between provides_str and provides */
  12295. + provide = (char * ) malloc(strlen(*lines)+ 35 ); /* Preparing the space for the new ipkg_internal_use_only */
  12296. + if ( alterProvidesLine(*lines,provide) ){
  12297. + return EINVAL;
  12298. + }
  12299. + pkg->provides_str = parseDependsString( provide, &pkg->provides_count);
  12300. +/* Let's try to hack a bit here.
  12301. + The idea is that if a package has no Provides, we would add one generic, to permit the check of dependencies
  12302. + in alot of other places. We will remove it before writing down the status database */
  12303. + pkg_false_provides=0;
  12304. + free(provide);
  12305. + }
  12306. +
  12307. + else if(isGenericFieldType((char *)"Depends", *lines))
  12308. + pkg->depends_str = parseDependsString(*lines, &pkg->depends_count);
  12309. + else if(isGenericFieldType((char *)"Pre-Depends", *lines))
  12310. + pkg->pre_depends_str = parseDependsString(*lines, &pkg->pre_depends_count);
  12311. + else if(isGenericFieldType((char *)"Recommends", *lines))
  12312. + pkg->recommends_str = parseDependsString(*lines, &pkg->recommends_count);
  12313. + else if(isGenericFieldType((char *)"Suggests", *lines))
  12314. + pkg->suggests_str = parseDependsString(*lines, &pkg->suggests_count);
  12315. + /* Abhaya: support for conflicts */
  12316. + else if(isGenericFieldType((char *)"Conflicts", *lines))
  12317. + pkg->conflicts_str = parseDependsString(*lines, &pkg->conflicts_count);
  12318. + else if(isGenericFieldType((char *)"Replaces", *lines))
  12319. + pkg->replaces_str = parseDependsString(*lines, &pkg->replaces_count);
  12320. + else if(line_is_blank(*lines)) {
  12321. + lines++;
  12322. + break;
  12323. + }
  12324. + else if(**lines == ' '){
  12325. + if(reading_description) {
  12326. + /* we already know it's not blank, so the rest of description */
  12327. + pkg->description = realloc(pkg->description,
  12328. + strlen(pkg->description)
  12329. + + 1 + strlen(*lines) + 1);
  12330. + strcat(pkg->description, "\n");
  12331. + strcat(pkg->description, (*lines));
  12332. + }
  12333. + else if(reading_conffiles)
  12334. + parseConffiles(pkg, *lines);
  12335. + }
  12336. + }
  12337. + *raw = lines;
  12338. +/* If the ipk has not a Provides line, we insert our false line */
  12339. + if ( pkg_false_provides==1)
  12340. + pkg->provides_str = parseDependsString ((char *)"Provides: ipkg_internal_use_only ", &pkg->provides_count);
  12341. +
  12342. + if (pkg->name) {
  12343. + return 0;
  12344. + } else {
  12345. + return EINVAL;
  12346. + }
  12347. +}
  12348. +
  12349. +int pkg_valorize_other_field(pkg_t *pkg, char ***raw)
  12350. +{
  12351. + char ** lines;
  12352. +
  12353. + for (lines = *raw; *lines; lines++) {
  12354. + if(isGenericFieldType((char *)"Essential:", *lines)) {
  12355. + char *essential_value;
  12356. + essential_value = parseGenericFieldType((char *)"Essential", *lines);
  12357. + if (strcmp(essential_value, "yes") == 0) {
  12358. + pkg->essential = 1;
  12359. + }
  12360. + free(essential_value);
  12361. + }
  12362. + }
  12363. + *raw = lines;
  12364. +
  12365. + return 0;
  12366. +}
  12367. diff -Nur busybox-1.21.1.orig/archival/libipkg/pkg_parse.h busybox-1.21.1/archival/libipkg/pkg_parse.h
  12368. --- busybox-1.21.1.orig/archival/libipkg/pkg_parse.h 1970-01-01 01:00:00.000000000 +0100
  12369. +++ busybox-1.21.1/archival/libipkg/pkg_parse.h 2014-02-17 14:25:39.866534213 +0100
  12370. @@ -0,0 +1,31 @@
  12371. +/* pkg_parse.h - the itsy package management system
  12372. +
  12373. + Steven M. Ayer
  12374. +
  12375. + Copyright (C) 2002 Compaq Computer Corporation
  12376. +
  12377. + This program is free software; you can redistribute it and/or
  12378. + modify it under the terms of the GNU General Public License as
  12379. + published by the Free Software Foundation; either version 2, or (at
  12380. + your option) any later version.
  12381. +
  12382. + This program is distributed in the hope that it will be useful, but
  12383. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12384. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12385. + General Public License for more details.
  12386. +*/
  12387. +
  12388. +#ifndef PKG_PARSE_H
  12389. +#define PKG_PARSE_H
  12390. +
  12391. +int isGenericFieldType(char * type, char * line);
  12392. +char * parseGenericFieldType(char * type, char * raw);
  12393. +void parseStatus(pkg_t *pkg, char * raw);
  12394. +int parseVersion(pkg_t *pkg, char *raw);
  12395. +char ** parseDependsString(char * raw, int * depends_count);
  12396. +int parseVersion(pkg_t *pkg, char *raw);
  12397. +void parseConffiles(pkg_t * pkg, char * raw);
  12398. +int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest);
  12399. +int pkg_valorize_other_field(pkg_t *pkg, char ***raw);
  12400. +
  12401. +#endif
  12402. diff -Nur busybox-1.21.1.orig/archival/libipkg/pkg_src.c busybox-1.21.1/archival/libipkg/pkg_src.c
  12403. --- busybox-1.21.1.orig/archival/libipkg/pkg_src.c 1970-01-01 01:00:00.000000000 +0100
  12404. +++ busybox-1.21.1/archival/libipkg/pkg_src.c 2014-02-17 14:25:39.866534213 +0100
  12405. @@ -0,0 +1,43 @@
  12406. +/* pkg_src.c - the itsy package management system
  12407. +
  12408. + Carl D. Worth
  12409. +
  12410. + Copyright (C) 2001 University of Southern California
  12411. +
  12412. + This program is free software; you can redistribute it and/or
  12413. + modify it under the terms of the GNU General Public License as
  12414. + published by the Free Software Foundation; either version 2, or (at
  12415. + your option) any later version.
  12416. +
  12417. + This program is distributed in the hope that it will be useful, but
  12418. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12419. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12420. + General Public License for more details.
  12421. +*/
  12422. +
  12423. +#include "ipkg.h"
  12424. +
  12425. +#include "pkg_src.h"
  12426. +#include "str_util.h"
  12427. +
  12428. +int pkg_src_init(pkg_src_t *src, const char *name, const char *base_url, const char *extra_data, int gzip)
  12429. +{
  12430. + src->gzip = gzip;
  12431. + src->name = str_dup_safe (name);
  12432. + src->value = str_dup_safe (base_url);
  12433. + if (extra_data)
  12434. + src->extra_data = str_dup_safe (extra_data);
  12435. + else
  12436. + src->extra_data = NULL;
  12437. + return 0;
  12438. +}
  12439. +
  12440. +void pkg_src_deinit(pkg_src_t *src)
  12441. +{
  12442. + free (src->name);
  12443. + free (src->value);
  12444. + if (src->extra_data)
  12445. + free (src->extra_data);
  12446. +}
  12447. +
  12448. +
  12449. diff -Nur busybox-1.21.1.orig/archival/libipkg/pkg_src.h busybox-1.21.1/archival/libipkg/pkg_src.h
  12450. --- busybox-1.21.1.orig/archival/libipkg/pkg_src.h 1970-01-01 01:00:00.000000000 +0100
  12451. +++ busybox-1.21.1/archival/libipkg/pkg_src.h 2014-02-17 14:25:39.866534213 +0100
  12452. @@ -0,0 +1,34 @@
  12453. +/* pkg_src.h - the itsy package management system
  12454. +
  12455. + Carl D. Worth
  12456. +
  12457. + Copyright (C) 2001 University of Southern California
  12458. +
  12459. + This program is free software; you can redistribute it and/or
  12460. + modify it under the terms of the GNU General Public License as
  12461. + published by the Free Software Foundation; either version 2, or (at
  12462. + your option) any later version.
  12463. +
  12464. + This program is distributed in the hope that it will be useful, but
  12465. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12466. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12467. + General Public License for more details.
  12468. +*/
  12469. +
  12470. +#ifndef PKG_SRC_H
  12471. +#define PKG_SRC_H
  12472. +
  12473. +#include "nv_pair.h"
  12474. +
  12475. +typedef struct
  12476. +{
  12477. + char *name;
  12478. + char *value;
  12479. + char *extra_data;
  12480. + int gzip;
  12481. +} pkg_src_t;
  12482. +
  12483. +int pkg_src_init(pkg_src_t *src, const char *name, const char *base_url, const char *extra_data, int gzip);
  12484. +void pkg_src_deinit(pkg_src_t *src);
  12485. +
  12486. +#endif
  12487. diff -Nur busybox-1.21.1.orig/archival/libipkg/pkg_src_list.c busybox-1.21.1/archival/libipkg/pkg_src_list.c
  12488. --- busybox-1.21.1.orig/archival/libipkg/pkg_src_list.c 1970-01-01 01:00:00.000000000 +0100
  12489. +++ busybox-1.21.1/archival/libipkg/pkg_src_list.c 2014-02-17 14:25:39.866534213 +0100
  12490. @@ -0,0 +1,75 @@
  12491. +/* pkg_src_list.c - the itsy package management system
  12492. +
  12493. + Carl D. Worth
  12494. +
  12495. + Copyright (C) 2001 University of Southern California
  12496. +
  12497. + This program is free software; you can redistribute it and/or
  12498. + modify it under the terms of the GNU General Public License as
  12499. + published by the Free Software Foundation; either version 2, or (at
  12500. + your option) any later version.
  12501. +
  12502. + This program is distributed in the hope that it will be useful, but
  12503. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12504. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12505. + General Public License for more details.
  12506. +*/
  12507. +
  12508. +#include "ipkg.h"
  12509. +
  12510. +#include "pkg_src_list.h"
  12511. +#include "void_list.h"
  12512. +
  12513. +int pkg_src_list_init(pkg_src_list_t *list)
  12514. +{
  12515. + return void_list_init((void_list_t *) list);
  12516. +}
  12517. +
  12518. +void pkg_src_list_deinit(pkg_src_list_t *list)
  12519. +{
  12520. + pkg_src_list_elt_t *iter;
  12521. + pkg_src_t *pkg_src;
  12522. +
  12523. + for (iter = list->head; iter; iter = iter->next) {
  12524. + pkg_src = iter->data;
  12525. + pkg_src_deinit(pkg_src);
  12526. +
  12527. + /* malloced in pkg_src_list_append */
  12528. + free(pkg_src);
  12529. + iter->data = NULL;
  12530. + }
  12531. + void_list_deinit((void_list_t *) list);
  12532. +}
  12533. +
  12534. +pkg_src_t *pkg_src_list_append(pkg_src_list_t *list,
  12535. + const char *name, const char *base_url, const char *extra_data,
  12536. + int gzip)
  12537. +{
  12538. + int err;
  12539. +
  12540. + /* freed in pkg_src_list_deinit */
  12541. + pkg_src_t *pkg_src = malloc(sizeof(pkg_src_t));
  12542. +
  12543. + if (pkg_src == NULL) {
  12544. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  12545. + return NULL;
  12546. + }
  12547. + pkg_src_init(pkg_src, name, base_url, extra_data, gzip);
  12548. +
  12549. + err = void_list_append((void_list_t *) list, pkg_src);
  12550. + if (err) {
  12551. + return NULL;
  12552. + }
  12553. +
  12554. + return pkg_src;
  12555. +}
  12556. +
  12557. +int pkg_src_list_push(pkg_src_list_t *list, pkg_src_t *data)
  12558. +{
  12559. + return void_list_push((void_list_t *) list, data);
  12560. +}
  12561. +
  12562. +pkg_src_list_elt_t *pkg_src_list_pop(pkg_src_list_t *list)
  12563. +{
  12564. + return (pkg_src_list_elt_t *) void_list_pop((void_list_t *) list);
  12565. +}
  12566. diff -Nur busybox-1.21.1.orig/archival/libipkg/pkg_src_list.h busybox-1.21.1/archival/libipkg/pkg_src_list.h
  12567. --- busybox-1.21.1.orig/archival/libipkg/pkg_src_list.h 1970-01-01 01:00:00.000000000 +0100
  12568. +++ busybox-1.21.1/archival/libipkg/pkg_src_list.h 2014-02-17 14:25:39.866534213 +0100
  12569. @@ -0,0 +1,57 @@
  12570. +/* pkg_src_list.h - the itsy package management system
  12571. +
  12572. + Carl D. Worth
  12573. +
  12574. + Copyright (C) 2001 University of Southern California
  12575. +
  12576. + This program is free software; you can redistribute it and/or
  12577. + modify it under the terms of the GNU General Public License as
  12578. + published by the Free Software Foundation; either version 2, or (at
  12579. + your option) any later version.
  12580. +
  12581. + This program is distributed in the hope that it will be useful, but
  12582. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12583. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12584. + General Public License for more details.
  12585. +*/
  12586. +
  12587. +#ifndef PKG_SRC_LIST_H
  12588. +#define PKG_SRC_LIST_H
  12589. +
  12590. +#include "pkg_src.h"
  12591. +
  12592. +typedef struct pkg_src_list_elt pkg_src_list_elt_t;
  12593. +struct pkg_src_list_elt
  12594. +{
  12595. + pkg_src_list_elt_t *next;
  12596. + pkg_src_t *data;
  12597. +};
  12598. +
  12599. +typedef struct pkg_src_list pkg_src_list_t;
  12600. +struct pkg_src_list
  12601. +{
  12602. + pkg_src_list_elt_t pre_head;
  12603. + pkg_src_list_elt_t *head;
  12604. + pkg_src_list_elt_t *tail;
  12605. +};
  12606. +
  12607. +static inline int pkg_src_list_empty(pkg_src_list_t *list)
  12608. +{
  12609. + if (list->head == NULL)
  12610. + return 1;
  12611. + else
  12612. + return 0;
  12613. +}
  12614. +
  12615. +int pkg_src_list_elt_init(pkg_src_list_elt_t *elt, nv_pair_t *data);
  12616. +void pkg_src_list_elt_deinit(pkg_src_list_elt_t *elt);
  12617. +
  12618. +int pkg_src_list_init(pkg_src_list_t *list);
  12619. +void pkg_src_list_deinit(pkg_src_list_t *list);
  12620. +
  12621. +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);
  12622. +int pkg_src_list_push(pkg_src_list_t *list, pkg_src_t *data);
  12623. +pkg_src_list_elt_t *pkg_src_list_pop(pkg_src_list_t *list);
  12624. +
  12625. +#endif
  12626. +
  12627. diff -Nur busybox-1.21.1.orig/archival/libipkg/pkg_vec.c busybox-1.21.1/archival/libipkg/pkg_vec.c
  12628. --- busybox-1.21.1.orig/archival/libipkg/pkg_vec.c 1970-01-01 01:00:00.000000000 +0100
  12629. +++ busybox-1.21.1/archival/libipkg/pkg_vec.c 2014-02-17 14:25:39.866534213 +0100
  12630. @@ -0,0 +1,231 @@
  12631. +/* pkg_vec.c - the itsy package management system
  12632. +
  12633. + Steven M. Ayer
  12634. +
  12635. + Copyright (C) 2002 Compaq Computer Corporation
  12636. +
  12637. + This program is free software; you can redistribute it and/or
  12638. + modify it under the terms of the GNU General Public License as
  12639. + published by the Free Software Foundation; either version 2, or (at
  12640. + your option) any later version.
  12641. +
  12642. + This program is distributed in the hope that it will be useful, but
  12643. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12644. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12645. + General Public License for more details.
  12646. +*/
  12647. +
  12648. +#include <stdlib.h>
  12649. +#include <fnmatch.h>
  12650. +#include "libbb.h"
  12651. +#include "xregex.h"
  12652. +#include "ipkg.h"
  12653. +#include "pkg.h"
  12654. +
  12655. +pkg_vec_t * pkg_vec_alloc(void)
  12656. +{
  12657. + pkg_vec_t * vec = (pkg_vec_t *)malloc(sizeof(pkg_vec_t));
  12658. + if (!vec) {
  12659. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  12660. + return NULL;
  12661. + }
  12662. + vec->pkgs = NULL;
  12663. + vec->len = 0;
  12664. +
  12665. + return vec;
  12666. +}
  12667. +
  12668. +void pkg_vec_free(pkg_vec_t *vec)
  12669. +{
  12670. + free(vec->pkgs);
  12671. + free(vec);
  12672. +}
  12673. +
  12674. +/*
  12675. + * assumption: all names in a vector are identical
  12676. + * assumption: all version strings are trimmed,
  12677. + * so identical versions have identical version strings,
  12678. + * implying identical packages; let's marry these
  12679. + */
  12680. +pkg_t *pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status,ipkg_conf_t *conf)
  12681. +{
  12682. + int i;
  12683. + int found = 0;
  12684. +
  12685. + /* look for a duplicate pkg by name, version, and architecture */
  12686. + for (i = 0; i < vec->len; i++){
  12687. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Found pkg=%s version=%s arch=%s cmp=%s version=%s arch=%s \n",
  12688. + __FUNCTION__, pkg->name, pkg->version, pkg->architecture,
  12689. + vec->pkgs[i]->name, vec->pkgs[i]->version,vec->pkgs[i]->architecture );
  12690. + if ((strcmp(pkg->name, vec->pkgs[i]->name) == 0)
  12691. + && (pkg_compare_versions(pkg, vec->pkgs[i]) == 0)
  12692. + && (strcmp(pkg->architecture, vec->pkgs[i]->architecture) == 0)) {
  12693. + found = 1;
  12694. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Found duplicate for pkg=%s version=%s arch=%s\n",
  12695. + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
  12696. + break;
  12697. + }
  12698. + }
  12699. +
  12700. + /* we didn't find one, add it */
  12701. + if (!found){
  12702. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Adding new pkg=%s version=%s arch=%s\n",
  12703. + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
  12704. +
  12705. + vec->pkgs = (pkg_t **)realloc(vec->pkgs, (vec->len + 1) * sizeof(pkg_t *));
  12706. + vec->pkgs[vec->len] = pkg;
  12707. + vec->len++;
  12708. + return pkg;
  12709. + }
  12710. + /* update the one that we have */
  12711. + else {
  12712. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. calling pkg_merge for pkg=%s version=%s arch=%s",
  12713. + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
  12714. + if (set_status) {
  12715. + /* this is from the status file, so need to merge with existing database */
  12716. + ipkg_message(conf, IPKG_DEBUG2, " with set_status\n");
  12717. + pkg_merge(vec->pkgs[i], pkg, set_status);
  12718. + /* XXX: CLEANUP: It's not so polite to free something here
  12719. + that was passed in from above. */
  12720. + pkg_deinit(pkg);
  12721. + free(pkg);
  12722. + } else {
  12723. + ipkg_message(conf, IPKG_DEBUG2, " WITHOUT set_status\n");
  12724. + /* just overwrite the old one */
  12725. + pkg_deinit(vec->pkgs[i]);
  12726. + free(vec->pkgs[i]);
  12727. + vec->pkgs[i] = pkg;
  12728. + }
  12729. + return vec->pkgs[i];
  12730. + }
  12731. +}
  12732. +
  12733. +void pkg_vec_insert(pkg_vec_t *vec, const pkg_t *pkg)
  12734. +{
  12735. + int i;
  12736. + int found = 0;
  12737. +
  12738. + /* look for a duplicate pkg by name, version, and architecture */
  12739. + for (i = 0; i < vec->len; i++)
  12740. + if ((strcmp(pkg->name, vec->pkgs[i]->name) == 0)
  12741. + && (pkg_compare_versions(pkg, vec->pkgs[i]) == 0)
  12742. + && (strcmp(pkg->architecture, vec->pkgs[i]->name) == 0)) {
  12743. + found = 1;
  12744. + break;
  12745. + }
  12746. +
  12747. + /* we didn't find one, add it */
  12748. + if(!found){
  12749. + vec->pkgs = (pkg_t **)realloc(vec->pkgs, (vec->len + 1) * sizeof(pkg_t *));
  12750. + *(const pkg_t **)&vec->pkgs[vec->len] = pkg;
  12751. + vec->len++;
  12752. + }
  12753. +}
  12754. +
  12755. +int pkg_vec_contains(pkg_vec_t *vec, pkg_t *apkg)
  12756. +{
  12757. + int i;
  12758. + for (i = 0; i < vec->len; i++)
  12759. + if (vec->pkgs[i] == apkg)
  12760. + return 1;
  12761. + return 0;
  12762. +}
  12763. +
  12764. +typedef int (*compare_fcn_t)(const void *, const void *);
  12765. +void pkg_vec_sort(pkg_vec_t *vec, int (*compar)(pkg_t *, pkg_t *))
  12766. +{
  12767. + qsort(vec->pkgs, vec->len, sizeof(pkg_t *), (compare_fcn_t)compar);
  12768. +}
  12769. +
  12770. +int pkg_vec_clear_marks(pkg_vec_t *vec)
  12771. +{
  12772. + int npkgs = vec->len;
  12773. + int i;
  12774. + for (i = 0; i < npkgs; i++) {
  12775. + pkg_t *pkg = vec->pkgs[i];
  12776. + pkg->state_flag &= ~SF_MARKED;
  12777. + }
  12778. + return 0;
  12779. +}
  12780. +
  12781. +int pkg_vec_mark_if_matches(pkg_vec_t *vec, const char *pattern)
  12782. +{
  12783. + int matching_count = 0;
  12784. + pkg_t **pkgs = vec->pkgs;
  12785. + int npkgs = vec->len;
  12786. + int i;
  12787. + for (i = 0; i < npkgs; i++) {
  12788. + pkg_t *pkg = pkgs[i];
  12789. + if (fnmatch(pattern, pkg->name, 0)==0) {
  12790. + pkg->state_flag |= SF_MARKED;
  12791. + matching_count++;
  12792. + }
  12793. + }
  12794. + return matching_count;
  12795. +}
  12796. +
  12797. +
  12798. +abstract_pkg_vec_t * abstract_pkg_vec_alloc(void)
  12799. +{
  12800. + abstract_pkg_vec_t * vec ;
  12801. + vec = (abstract_pkg_vec_t *)malloc(sizeof(abstract_pkg_vec_t));
  12802. + if (!vec) {
  12803. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  12804. + return NULL;
  12805. + }
  12806. + vec->pkgs = NULL;
  12807. + vec->len = 0;
  12808. +
  12809. + return vec;
  12810. +}
  12811. +
  12812. +void abstract_pkg_vec_free(abstract_pkg_vec_t *vec)
  12813. +{
  12814. + free(vec->pkgs);
  12815. + free(vec);
  12816. +}
  12817. +
  12818. +/*
  12819. + * assumption: all names in a vector are unique
  12820. + */
  12821. +void abstract_pkg_vec_insert(abstract_pkg_vec_t *vec, abstract_pkg_t *pkg)
  12822. +{
  12823. + int i;
  12824. +
  12825. + /* look for a duplicate pkg by name */
  12826. + for(i = 0; i < vec->len; i++)
  12827. + if (strcmp(pkg->name, vec->pkgs[i]->name) == 0)
  12828. + break;
  12829. +
  12830. + /* we didn't find one, add it */
  12831. + if(i == vec->len){
  12832. + vec->pkgs =
  12833. + (abstract_pkg_t **)
  12834. + realloc(vec->pkgs, (vec->len + 1) * sizeof(abstract_pkg_t *));
  12835. + vec->pkgs[vec->len] = pkg;
  12836. + vec->len++;
  12837. + }
  12838. +}
  12839. +
  12840. +abstract_pkg_t * abstract_pkg_vec_get(abstract_pkg_vec_t *vec, int i)
  12841. +{
  12842. + if (vec->len > i)
  12843. + return vec->pkgs[i];
  12844. + else
  12845. + return NULL;
  12846. +}
  12847. +
  12848. +int abstract_pkg_vec_contains(abstract_pkg_vec_t *vec, abstract_pkg_t *apkg)
  12849. +{
  12850. + int i;
  12851. + for (i = 0; i < vec->len; i++)
  12852. + if (vec->pkgs[i] == apkg)
  12853. + return 1;
  12854. + return 0;
  12855. +}
  12856. +
  12857. +void abstract_pkg_vec_sort(pkg_vec_t *vec, int (*compar)(abstract_pkg_t *, abstract_pkg_t *))
  12858. +{
  12859. + qsort(vec->pkgs, vec->len, sizeof(pkg_t *), (compare_fcn_t)compar);
  12860. +}
  12861. +
  12862. diff -Nur busybox-1.21.1.orig/archival/libipkg/pkg_vec.h busybox-1.21.1/archival/libipkg/pkg_vec.h
  12863. --- busybox-1.21.1.orig/archival/libipkg/pkg_vec.h 1970-01-01 01:00:00.000000000 +0100
  12864. +++ busybox-1.21.1/archival/libipkg/pkg_vec.h 2014-02-17 14:25:39.866534213 +0100
  12865. @@ -0,0 +1,62 @@
  12866. +/* pkg_vec.h - the itsy package management system
  12867. +
  12868. + Steven M. Ayer
  12869. +
  12870. + Copyright (C) 2002 Compaq Computer Corporation
  12871. +
  12872. + This program is free software; you can redistribute it and/or
  12873. + modify it under the terms of the GNU General Public License as
  12874. + published by the Free Software Foundation; either version 2, or (at
  12875. + your option) any later version.
  12876. +
  12877. + This program is distributed in the hope that it will be useful, but
  12878. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12879. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12880. + General Public License for more details.
  12881. +*/
  12882. +
  12883. +#ifndef PKG_VEC_H
  12884. +#define PKG_VEC_H
  12885. +
  12886. +typedef struct pkg pkg_t;
  12887. +typedef struct abstract_pkg abstract_pkg_t;
  12888. +
  12889. +struct pkg_vec
  12890. +{
  12891. + pkg_t **pkgs;
  12892. + int len;
  12893. +};
  12894. +typedef struct pkg_vec pkg_vec_t;
  12895. +
  12896. +struct abstract_pkg_vec
  12897. +{
  12898. + abstract_pkg_t **pkgs;
  12899. + int len;
  12900. +};
  12901. +typedef struct abstract_pkg_vec abstract_pkg_vec_t;
  12902. +
  12903. +
  12904. +pkg_vec_t * pkg_vec_alloc(void);
  12905. +void pkg_vec_free(pkg_vec_t *vec);
  12906. +void marry_two_packages(pkg_t * newpkg, pkg_t * oldpkg);
  12907. +
  12908. +void pkg_vec_add(pkg_vec_t *vec, pkg_t *pkg);
  12909. +/* pkg_vec_insert_merge: might munge pkg.
  12910. +* returns the pkg that is in the pkg graph */
  12911. +pkg_t *pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status, ipkg_conf_t *conf);
  12912. +/* this one never munges pkg */
  12913. +void pkg_vec_insert(pkg_vec_t *vec, const pkg_t *pkg);
  12914. +int pkg_vec_contains(pkg_vec_t *vec, pkg_t *apkg);
  12915. +void pkg_vec_sort(pkg_vec_t *vec, int (*compar)(pkg_t *, pkg_t *));
  12916. +
  12917. +int pkg_vec_clear_marks(pkg_vec_t *vec);
  12918. +int pkg_vec_mark_if_matches(pkg_vec_t *vec, const char *pattern);
  12919. +
  12920. +abstract_pkg_vec_t * abstract_pkg_vec_alloc(void);
  12921. +void abstract_pkg_vec_free(abstract_pkg_vec_t *vec);
  12922. +void abstract_pkg_vec_insert(abstract_pkg_vec_t *vec, abstract_pkg_t *pkg);
  12923. +abstract_pkg_t * abstract_pkg_vec_get(abstract_pkg_vec_t *vec, int i);
  12924. +int abstract_pkg_vec_contains(abstract_pkg_vec_t *vec, abstract_pkg_t *apkg);
  12925. +void abstract_pkg_vec_sort(pkg_vec_t *vec, int (*compar)(abstract_pkg_t *, abstract_pkg_t *));
  12926. +#endif
  12927. +
  12928. diff -Nur busybox-1.21.1.orig/archival/libipkg/sprintf_alloc.h busybox-1.21.1/archival/libipkg/sprintf_alloc.h
  12929. --- busybox-1.21.1.orig/archival/libipkg/sprintf_alloc.h 1970-01-01 01:00:00.000000000 +0100
  12930. +++ busybox-1.21.1/archival/libipkg/sprintf_alloc.h 2014-02-17 14:25:39.866534213 +0100
  12931. @@ -0,0 +1,25 @@
  12932. +/* sprintf_alloca.c -- like sprintf with memory allocation
  12933. +
  12934. + Carl D. Worth
  12935. +
  12936. + Copyright (C) 2001 University of Southern California
  12937. +
  12938. + This program is free software; you can redistribute it and/or modify
  12939. + it under the terms of the GNU General Public License as published by
  12940. + the Free Software Foundation; either version 2, or (at your option)
  12941. + any later version.
  12942. +
  12943. + This program is distributed in the hope that it will be useful,
  12944. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  12945. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12946. + GNU General Public License for more details.
  12947. +*/
  12948. +
  12949. +#ifndef SPRINTF_ALLOC_H
  12950. +#define SPRINTF_ALLOC_H
  12951. +
  12952. +#include "libbb.h"
  12953. +
  12954. +#define sprintf_alloc(str, fmt, args...) *str = xasprintf(fmt, ## args)
  12955. +
  12956. +#endif
  12957. diff -Nur busybox-1.21.1.orig/archival/libipkg/str_list.c busybox-1.21.1/archival/libipkg/str_list.c
  12958. --- busybox-1.21.1.orig/archival/libipkg/str_list.c 1970-01-01 01:00:00.000000000 +0100
  12959. +++ busybox-1.21.1/archival/libipkg/str_list.c 2014-02-17 14:25:39.866534213 +0100
  12960. @@ -0,0 +1,76 @@
  12961. +/* str_list.c - the itsy package management system
  12962. +
  12963. + Carl D. Worth
  12964. +
  12965. + Copyright (C) 2001 University of Southern California
  12966. +
  12967. + This program is free software; you can redistribute it and/or
  12968. + modify it under the terms of the GNU General Public License as
  12969. + published by the Free Software Foundation; either version 2, or (at
  12970. + your option) any later version.
  12971. +
  12972. + This program is distributed in the hope that it will be useful, but
  12973. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12974. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12975. + General Public License for more details.
  12976. +*/
  12977. +
  12978. +#include "ipkg.h"
  12979. +
  12980. +#include "str_list.h"
  12981. +
  12982. +int str_list_elt_init(str_list_elt_t *elt, char *data)
  12983. +{
  12984. + return void_list_elt_init((void_list_elt_t *) elt, data);
  12985. +}
  12986. +
  12987. +void str_list_elt_deinit(str_list_elt_t *elt)
  12988. +{
  12989. + void_list_elt_deinit((void_list_elt_t *) elt);
  12990. +}
  12991. +
  12992. +str_list_t *str_list_alloc(void)
  12993. +{
  12994. + str_list_t *list = (str_list_t *)malloc(sizeof(str_list_t));
  12995. + if (list)
  12996. + str_list_init(list);
  12997. + return list;
  12998. +}
  12999. +
  13000. +int str_list_init(str_list_t *list)
  13001. +{
  13002. + return void_list_init((void_list_t *) list);
  13003. +}
  13004. +
  13005. +void str_list_deinit(str_list_t *list)
  13006. +{
  13007. + void_list_deinit((void_list_t *) list);
  13008. +}
  13009. +
  13010. +int str_list_append(str_list_t *list, char *data)
  13011. +{
  13012. + return void_list_append((void_list_t *) list, data);
  13013. +}
  13014. +
  13015. +int str_list_push(str_list_t *list, char *data)
  13016. +{
  13017. + return void_list_push((void_list_t *) list, data);
  13018. +}
  13019. +
  13020. +str_list_elt_t *str_list_pop(str_list_t *list)
  13021. +{
  13022. + return (str_list_elt_t *) void_list_pop((void_list_t *) list);
  13023. +}
  13024. +
  13025. +str_list_elt_t *str_list_remove(str_list_t *list, str_list_elt_t **iter)
  13026. +{
  13027. + return (str_list_elt_t *) void_list_remove((void_list_t *) list,
  13028. + (void_list_elt_t **) iter);
  13029. +}
  13030. +
  13031. +char *str_list_remove_elt(str_list_t *list, const char *target_str)
  13032. +{
  13033. + return (char *)void_list_remove_elt((void_list_t *) list,
  13034. + (void *)target_str,
  13035. + (void_list_cmp_t)strcmp);
  13036. +}
  13037. diff -Nur busybox-1.21.1.orig/archival/libipkg/str_list.h busybox-1.21.1/archival/libipkg/str_list.h
  13038. --- busybox-1.21.1.orig/archival/libipkg/str_list.h 1970-01-01 01:00:00.000000000 +0100
  13039. +++ busybox-1.21.1/archival/libipkg/str_list.h 2014-02-17 14:25:39.866534213 +0100
  13040. @@ -0,0 +1,51 @@
  13041. +/* str_list.h - the itsy package management system
  13042. +
  13043. + Carl D. Worth
  13044. +
  13045. + Copyright (C) 2001 University of Southern California
  13046. +
  13047. + This program is free software; you can redistribute it and/or
  13048. + modify it under the terms of the GNU General Public License as
  13049. + published by the Free Software Foundation; either version 2, or (at
  13050. + your option) any later version.
  13051. +
  13052. + This program is distributed in the hope that it will be useful, but
  13053. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13054. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13055. + General Public License for more details.
  13056. +*/
  13057. +
  13058. +#ifndef STR_LIST_H
  13059. +#define STR_LIST_H
  13060. +
  13061. +#include "void_list.h"
  13062. +
  13063. +typedef struct str_list_elt str_list_elt_t;
  13064. +struct str_list_elt
  13065. +{
  13066. + str_list_elt_t *next;
  13067. + char *data;
  13068. +};
  13069. +
  13070. +typedef struct xstr_list str_list_t;
  13071. +struct xstr_list
  13072. +{
  13073. + str_list_elt_t pre_head;
  13074. + str_list_elt_t *head;
  13075. + str_list_elt_t *tail;
  13076. +};
  13077. +
  13078. +int str_list_elt_init(str_list_elt_t *elt, char *data);
  13079. +void str_list_elt_deinit(str_list_elt_t *elt);
  13080. +
  13081. +str_list_t *str_list_alloc(void);
  13082. +int str_list_init(str_list_t *list);
  13083. +void str_list_deinit(str_list_t *list);
  13084. +
  13085. +int str_list_append(str_list_t *list, char *data);
  13086. +int str_list_push(str_list_t *list, char *data);
  13087. +str_list_elt_t *str_list_pop(str_list_t *list);
  13088. +str_list_elt_t *str_list_remove(str_list_t *list, str_list_elt_t **iter);
  13089. +char *str_list_remove_elt(str_list_t *list, const char *target_str);
  13090. +
  13091. +#endif
  13092. diff -Nur busybox-1.21.1.orig/archival/libipkg/str_util.c busybox-1.21.1/archival/libipkg/str_util.c
  13093. --- busybox-1.21.1.orig/archival/libipkg/str_util.c 1970-01-01 01:00:00.000000000 +0100
  13094. +++ busybox-1.21.1/archival/libipkg/str_util.c 2014-02-17 14:25:39.866534213 +0100
  13095. @@ -0,0 +1,69 @@
  13096. +/* str_utils.c - the itsy package management system
  13097. +
  13098. + Carl D. Worth
  13099. +
  13100. + Copyright (C) 2001 University of Southern California
  13101. +
  13102. + This program is free software; you can redistribute it and/or
  13103. + modify it under the terms of the GNU General Public License as
  13104. + published by the Free Software Foundation; either version 2, or (at
  13105. + your option) any later version.
  13106. +
  13107. + This program is distributed in the hope that it will be useful, but
  13108. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13109. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13110. + General Public License for more details.
  13111. +*/
  13112. +
  13113. +#include "ipkg.h"
  13114. +
  13115. +int str_starts_with(const char *str, const char *prefix);
  13116. +int str_ends_with(const char *str, const char *suffix);
  13117. +int str_chomp(char *str);
  13118. +int str_toupper(char *str);
  13119. +char *str_dup_safe(const char *str);
  13120. +
  13121. +int str_starts_with(const char *str, const char *prefix)
  13122. +{
  13123. + return (strncmp(str, prefix, strlen(prefix)) == 0);
  13124. +}
  13125. +
  13126. +int str_ends_with(const char *str, const char *suffix)
  13127. +{
  13128. + int suffix_len;
  13129. + int str_len;
  13130. +
  13131. + str_len = strlen(str);
  13132. + suffix_len = strlen(suffix);
  13133. +
  13134. + if (str_len < suffix_len) {
  13135. + return 0;
  13136. + }
  13137. +
  13138. + return (strcmp(str + str_len - suffix_len, suffix) == 0);
  13139. +}
  13140. +
  13141. +int str_chomp(char *str)
  13142. +{
  13143. + if (str[strlen(str) - 1] == '\n') {
  13144. + str[strlen(str) - 1] = '\0';
  13145. + return 1;
  13146. + }
  13147. + return 0;
  13148. +}
  13149. +
  13150. +int str_toupper(char *str)
  13151. +{
  13152. + while (*str) {
  13153. + *str = toupper(*str);
  13154. + str++;
  13155. + }
  13156. +
  13157. + return 0;
  13158. +}
  13159. +
  13160. +char *str_dup_safe(const char *str)
  13161. +{
  13162. + return str ? strdup(str) : NULL;
  13163. +}
  13164. +
  13165. diff -Nur busybox-1.21.1.orig/archival/libipkg/str_util.h busybox-1.21.1/archival/libipkg/str_util.h
  13166. --- busybox-1.21.1.orig/archival/libipkg/str_util.h 1970-01-01 01:00:00.000000000 +0100
  13167. +++ busybox-1.21.1/archival/libipkg/str_util.h 2014-02-17 14:25:39.866534213 +0100
  13168. @@ -0,0 +1,27 @@
  13169. +/* str_utils.h - the itsy package management system
  13170. +
  13171. + Carl D. Worth
  13172. +
  13173. + Copyright (C) 2001 University of Southern California
  13174. +
  13175. + This program is free software; you can redistribute it and/or
  13176. + modify it under the terms of the GNU General Public License as
  13177. + published by the Free Software Foundation; either version 2, or (at
  13178. + your option) any later version.
  13179. +
  13180. + This program is distributed in the hope that it will be useful, but
  13181. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13182. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13183. + General Public License for more details.
  13184. +*/
  13185. +
  13186. +#ifndef STR_UTILS_H
  13187. +#define STR_UTILS_H
  13188. +
  13189. +int str_starts_with(const char *str, const char *prefix);
  13190. +int str_ends_with(const char *str, const char *suffix);
  13191. +int str_chomp(char *str);
  13192. +int str_toupper(char *str);
  13193. +char *str_dup_safe(const char *str);
  13194. +
  13195. +#endif
  13196. diff -Nur busybox-1.21.1.orig/archival/libipkg/user.c busybox-1.21.1/archival/libipkg/user.c
  13197. --- busybox-1.21.1.orig/archival/libipkg/user.c 1970-01-01 01:00:00.000000000 +0100
  13198. +++ busybox-1.21.1/archival/libipkg/user.c 2014-02-17 14:25:39.866534213 +0100
  13199. @@ -0,0 +1,49 @@
  13200. +/* user.c - the itsy package management system
  13201. +
  13202. + Jamey Hicks
  13203. +
  13204. + Copyright (C) 2002 Hewlett Packard Company
  13205. + Copyright (C) 2001 University of Southern California
  13206. +
  13207. + This program is free software; you can redistribute it and/or
  13208. + modify it under the terms of the GNU General Public License as
  13209. + published by the Free Software Foundation; either version 2, or (at
  13210. + your option) any later version.
  13211. +
  13212. + This program is distributed in the hope that it will be useful, but
  13213. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13214. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13215. + General Public License for more details.
  13216. +*/
  13217. +
  13218. +#include <stdio.h>
  13219. +#include <stdarg.h>
  13220. +#include "libbb.h"
  13221. +#include "file_util.h"
  13222. +#include "str_util.h"
  13223. +#include "libipkg.h"
  13224. +
  13225. +char *get_user_response(const char *format, ...);
  13226. +static char *question = NULL;
  13227. +static int question_len = 255;
  13228. +
  13229. +char *get_user_response(const char *format, ...)
  13230. +{
  13231. + int len = question_len;
  13232. + va_list ap;
  13233. + char *response;
  13234. + va_start(ap, format);
  13235. +
  13236. + do {
  13237. + if (question == NULL || len > question_len) {
  13238. + question = realloc(question, len + 1);
  13239. + question_len = len;
  13240. + }
  13241. + len = vsnprintf(question,question_len,format,ap);
  13242. + } while (len > question_len);
  13243. + response = strdup(ipkg_cb_response(question));
  13244. + str_chomp(response);
  13245. + str_tolower(response);
  13246. +
  13247. + return response;
  13248. +}
  13249. diff -Nur busybox-1.21.1.orig/archival/libipkg/user.h busybox-1.21.1/archival/libipkg/user.h
  13250. --- busybox-1.21.1.orig/archival/libipkg/user.h 1970-01-01 01:00:00.000000000 +0100
  13251. +++ busybox-1.21.1/archival/libipkg/user.h 2014-02-17 14:25:39.866534213 +0100
  13252. @@ -0,0 +1,23 @@
  13253. +/* user.c - the itsy package management system
  13254. +
  13255. + Jamey Hicks
  13256. +
  13257. + Copyright (C) 2002 Hewlett Packard Company
  13258. + Copyright (C) 2001 University of Southern California
  13259. +
  13260. + This program is free software; you can redistribute it and/or
  13261. + modify it under the terms of the GNU General Public License as
  13262. + published by the Free Software Foundation; either version 2, or (at
  13263. + your option) any later version.
  13264. +
  13265. + This program is distributed in the hope that it will be useful, but
  13266. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13267. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13268. + General Public License for more details.
  13269. +*/
  13270. +
  13271. +#include <stdio.h>
  13272. +#include <stdarg.h>
  13273. +
  13274. +char *get_user_response(const char *format, ...);
  13275. +
  13276. diff -Nur busybox-1.21.1.orig/archival/libipkg/void_list.c busybox-1.21.1/archival/libipkg/void_list.c
  13277. --- busybox-1.21.1.orig/archival/libipkg/void_list.c 1970-01-01 01:00:00.000000000 +0100
  13278. +++ busybox-1.21.1/archival/libipkg/void_list.c 2014-02-17 14:25:39.886534275 +0100
  13279. @@ -0,0 +1,194 @@
  13280. +/* void_list.c - the itsy package management system
  13281. +
  13282. + Carl D. Worth
  13283. +
  13284. + Copyright (C) 2001 University of Southern California
  13285. +
  13286. + This program is free software; you can redistribute it and/or
  13287. + modify it under the terms of the GNU General Public License as
  13288. + published by the Free Software Foundation; either version 2, or (at
  13289. + your option) any later version.
  13290. +
  13291. + This program is distributed in the hope that it will be useful, but
  13292. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13293. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13294. + General Public License for more details.
  13295. +*/
  13296. +
  13297. +#include "ipkg.h"
  13298. +#include <errno.h>
  13299. +
  13300. +#include "void_list.h"
  13301. +
  13302. +int void_list_elt_init(void_list_elt_t *elt, void *data)
  13303. +{
  13304. + elt->next = NULL;
  13305. + elt->data = data;
  13306. +
  13307. + return 0;
  13308. +}
  13309. +
  13310. +void void_list_elt_deinit(void_list_elt_t *elt)
  13311. +{
  13312. + void_list_elt_init(elt, NULL);
  13313. +}
  13314. +
  13315. +int void_list_init(void_list_t *list)
  13316. +{
  13317. + void_list_elt_init(&list->pre_head, NULL);
  13318. + list->head = NULL;
  13319. + list->pre_head.next = list->head;
  13320. + list->tail = NULL;
  13321. +
  13322. + return 0;
  13323. +}
  13324. +
  13325. +void void_list_deinit(void_list_t *list)
  13326. +{
  13327. + void_list_elt_t *elt;
  13328. +
  13329. + while (list->head) {
  13330. + elt = void_list_pop(list);
  13331. + void_list_elt_deinit(elt);
  13332. + /* malloced in void_list_append */
  13333. + free(elt);
  13334. + }
  13335. +}
  13336. +
  13337. +int void_list_append(void_list_t *list, void *data)
  13338. +{
  13339. + void_list_elt_t *elt;
  13340. +
  13341. + /* freed in void_list_deinit */
  13342. + elt = malloc(sizeof(void_list_elt_t));
  13343. + if (elt == NULL) {
  13344. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  13345. + return ENOMEM;
  13346. + }
  13347. +
  13348. + void_list_elt_init(elt, data);
  13349. +
  13350. + if (list->tail) {
  13351. + list->tail->next = elt;
  13352. + list->tail = elt;
  13353. + } else {
  13354. + list->head = elt;
  13355. + list->pre_head.next = list->head;
  13356. + list->tail = elt;
  13357. + }
  13358. +
  13359. + return 0;
  13360. +}
  13361. +
  13362. +int void_list_push(void_list_t *list, void *data)
  13363. +{
  13364. + void_list_elt_t *elt;
  13365. +
  13366. + elt = malloc(sizeof(void_list_elt_t));
  13367. + if (elt == NULL) {
  13368. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  13369. + return ENOMEM;
  13370. + }
  13371. +
  13372. + void_list_elt_init(elt, data);
  13373. +
  13374. + elt->next = list->head;
  13375. + list->head->next = elt;
  13376. + if (list->tail == NULL) {
  13377. + list->tail = list->head;
  13378. + }
  13379. +
  13380. + return 0;
  13381. +}
  13382. +
  13383. +void_list_elt_t *void_list_pop(void_list_t *list)
  13384. +{
  13385. + void_list_elt_t *elt;
  13386. +
  13387. + elt = list->head;
  13388. +
  13389. + if (list->head) {
  13390. + list->head = list->head->next;
  13391. + list->pre_head.next = list->head;
  13392. + if (list->head == NULL) {
  13393. + list->tail = NULL;
  13394. + }
  13395. + }
  13396. +
  13397. + return elt;
  13398. +}
  13399. +
  13400. +void *void_list_remove(void_list_t *list, void_list_elt_t **iter)
  13401. +{
  13402. + void_list_elt_t *prior;
  13403. + void_list_elt_t *old_elt;
  13404. + void *old_data;
  13405. +
  13406. + old_elt = *iter;
  13407. + old_data = old_elt->data;
  13408. +
  13409. + if (old_elt == list->head) {
  13410. + prior = &list->pre_head;
  13411. + void_list_pop(list);
  13412. + } else {
  13413. + for (prior = list->head; prior; prior = prior->next) {
  13414. + if (prior->next == old_elt) {
  13415. + break;
  13416. + }
  13417. + }
  13418. + if (prior == NULL || prior->next != old_elt) {
  13419. + fprintf(stderr, "%s: ERROR: element not found in list\n", __FUNCTION__);
  13420. + return NULL;
  13421. + }
  13422. + prior->next = old_elt->next;
  13423. +
  13424. + if (old_elt == list->tail) {
  13425. + list->tail = prior;
  13426. + }
  13427. + }
  13428. +
  13429. + void_list_elt_deinit(old_elt);
  13430. + *iter = prior;
  13431. +
  13432. + return old_data;
  13433. +}
  13434. +
  13435. +/* remove element containing elt data, using cmp(elt->data, target_data) == 0. */
  13436. +void *void_list_remove_elt(void_list_t *list, const void *target_data, void_list_cmp_t cmp)
  13437. +{
  13438. + void_list_elt_t *prior;
  13439. + void_list_elt_t *old_elt = NULL;
  13440. + void *old_data = NULL;
  13441. +
  13442. + /* first element */
  13443. + if (list->head && list->head->data && (cmp(list->head->data, target_data) == 0)) {
  13444. + old_elt = list->head;
  13445. + old_data = list->head->data;
  13446. + void_list_pop(list);
  13447. + } else {
  13448. + int found = 0;
  13449. + for (prior = list->head; prior && prior->next; prior = prior->next) {
  13450. + if (prior->next->data && (cmp(prior->next->data, target_data) == 0)) {
  13451. + old_elt = prior->next;
  13452. + old_data = old_elt->data;
  13453. + found = 1;
  13454. + break;
  13455. + }
  13456. + }
  13457. + if (!found) {
  13458. + return NULL;
  13459. + }
  13460. + prior->next = old_elt->next;
  13461. +
  13462. + if (old_elt == list->tail) {
  13463. + list->tail = prior;
  13464. + }
  13465. + }
  13466. + if (old_elt)
  13467. + void_list_elt_deinit(old_elt);
  13468. +
  13469. + if (old_data)
  13470. + return old_data;
  13471. + else
  13472. + return NULL;
  13473. +}
  13474. diff -Nur busybox-1.21.1.orig/archival/libipkg/void_list.h busybox-1.21.1/archival/libipkg/void_list.h
  13475. --- busybox-1.21.1.orig/archival/libipkg/void_list.h 1970-01-01 01:00:00.000000000 +0100
  13476. +++ busybox-1.21.1/archival/libipkg/void_list.h 2014-02-17 14:25:39.886534275 +0100
  13477. @@ -0,0 +1,59 @@
  13478. +/* void_list.h - the itsy package management system
  13479. +
  13480. + Carl D. Worth
  13481. +
  13482. + Copyright (C) 2001 University of Southern California
  13483. +
  13484. + This program is free software; you can redistribute it and/or
  13485. + modify it under the terms of the GNU General Public License as
  13486. + published by the Free Software Foundation; either version 2, or (at
  13487. + your option) any later version.
  13488. +
  13489. + This program is distributed in the hope that it will be useful, but
  13490. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13491. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13492. + General Public License for more details.
  13493. +*/
  13494. +
  13495. +#ifndef VOID_LIST_H
  13496. +#define VOID_LIST_H
  13497. +
  13498. +typedef struct void_list_elt void_list_elt_t;
  13499. +struct void_list_elt
  13500. +{
  13501. + void_list_elt_t *next;
  13502. + void *data;
  13503. +};
  13504. +
  13505. +typedef struct void_list void_list_t;
  13506. +struct void_list
  13507. +{
  13508. + void_list_elt_t pre_head;
  13509. + void_list_elt_t *head;
  13510. + void_list_elt_t *tail;
  13511. +};
  13512. +
  13513. +static inline int void_list_empty(void_list_t *list)
  13514. +{
  13515. + if (list->head == NULL)
  13516. + return 1;
  13517. + else
  13518. + return 0;
  13519. +}
  13520. +
  13521. +int void_list_elt_init(void_list_elt_t *elt, void *data);
  13522. +void void_list_elt_deinit(void_list_elt_t *elt);
  13523. +
  13524. +int void_list_init(void_list_t *list);
  13525. +void void_list_deinit(void_list_t *list);
  13526. +
  13527. +int void_list_append(void_list_t *list, void *data);
  13528. +int void_list_push(void_list_t *list, void *data);
  13529. +void_list_elt_t *void_list_pop(void_list_t *list);
  13530. +
  13531. +void *void_list_remove(void_list_t *list, void_list_elt_t **iter);
  13532. +/* remove element containing elt data, using cmp(elt->data, target_data) == 0. */
  13533. +typedef int (*void_list_cmp_t)(const void *, const void *);
  13534. +void *void_list_remove_elt(void_list_t *list, const void *target_data, void_list_cmp_t cmp);
  13535. +
  13536. +#endif
  13537. diff -Nur busybox-1.21.1.orig/archival/libipkg/xsystem.c busybox-1.21.1/archival/libipkg/xsystem.c
  13538. --- busybox-1.21.1.orig/archival/libipkg/xsystem.c 1970-01-01 01:00:00.000000000 +0100
  13539. +++ busybox-1.21.1/archival/libipkg/xsystem.c 2014-02-17 14:25:39.886534275 +0100
  13540. @@ -0,0 +1,64 @@
  13541. +/* xsystem.c - system(3) with error messages
  13542. +
  13543. + Carl D. Worth
  13544. +
  13545. + Copyright (C) 2001 University of Southern California
  13546. +
  13547. + This program is free software; you can redistribute it and/or
  13548. + modify it under the terms of the GNU General Public License as
  13549. + published by the Free Software Foundation; either version 2, or (at
  13550. + your option) any later version.
  13551. +
  13552. + This program is distributed in the hope that it will be useful, but
  13553. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13554. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13555. + General Public License for more details.
  13556. +*/
  13557. +
  13558. +#include "ipkg.h"
  13559. +#include <sys/wait.h>
  13560. +
  13561. +#include "xsystem.h"
  13562. +
  13563. +/* XXX: FEATURE: I shouldn't actually use system(3) at all. I don't
  13564. + really need the /bin/sh invocation which takes resources and
  13565. + introduces security problems. I should switch all of this to a sort
  13566. + of execl() or execv() interface/implementation.
  13567. +*/
  13568. +
  13569. +/* Like system(3), but with error messages printed if the fork fails
  13570. + or if the child process dies due to an uncaught signal. Also, the
  13571. + return value is a bit simpler:
  13572. +
  13573. + -1 if there was any problem
  13574. + Otherwise, the 8-bit return value of the program ala WEXITSTATUS
  13575. + as defined in <sys/wait.h>.
  13576. +*/
  13577. +int xsystem(const char *cmd)
  13578. +{
  13579. + int err;
  13580. +
  13581. + err = system(cmd);
  13582. +
  13583. + if (err == -1) {
  13584. + fprintf(stderr, "%s: ERROR: fork failed before execution: `%s'\n",
  13585. + __FUNCTION__, cmd);
  13586. + return -1;
  13587. + }
  13588. +
  13589. + if (WIFSIGNALED(err)) {
  13590. + fprintf(stderr, "%s: ERROR: Child process died due to signal %d: `%s'\n",
  13591. + __FUNCTION__, WTERMSIG(err), cmd);
  13592. + return -1;
  13593. + }
  13594. +
  13595. + if (WIFEXITED(err)) {
  13596. + /* Normal child exit */
  13597. + return WEXITSTATUS(err);
  13598. + }
  13599. +
  13600. + fprintf(stderr, "%s: ERROR: Received unintelligible return value from system: %d",
  13601. + __FUNCTION__, err);
  13602. + return -1;
  13603. +}
  13604. +
  13605. diff -Nur busybox-1.21.1.orig/archival/libipkg/xsystem.h busybox-1.21.1/archival/libipkg/xsystem.h
  13606. --- busybox-1.21.1.orig/archival/libipkg/xsystem.h 1970-01-01 01:00:00.000000000 +0100
  13607. +++ busybox-1.21.1/archival/libipkg/xsystem.h 2014-02-17 14:25:39.890534287 +0100
  13608. @@ -0,0 +1,34 @@
  13609. +/* xsystem.h - system(3) with error messages
  13610. +
  13611. + Carl D. Worth
  13612. +
  13613. + Copyright (C) 2001 University of Southern California
  13614. +
  13615. + This program is free software; you can redistribute it and/or
  13616. + modify it under the terms of the GNU General Public License as
  13617. + published by the Free Software Foundation; either version 2, or (at
  13618. + your option) any later version.
  13619. +
  13620. + This program is distributed in the hope that it will be useful, but
  13621. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13622. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13623. + General Public License for more details.
  13624. +*/
  13625. +
  13626. +#ifndef XSYSTEM_H
  13627. +#define XSYSTEM_H
  13628. +
  13629. +#include <stdlib.h>
  13630. +
  13631. +/* Like system(3), but with error messages printed if the fork fails
  13632. + or if the child process dies due to an uncaught signal. Also, the
  13633. + return value is a bit simpler:
  13634. +
  13635. + -1 if there was any problem
  13636. + Otherwise, the 8-bit return value of the program ala WEXITSTATUS
  13637. + as defined in <sys/wait.h>.
  13638. +*/
  13639. +int xsystem(const char *cmd);
  13640. +
  13641. +#endif
  13642. +
  13643. diff -Nur busybox-1.21.1.orig/include/applets.src.h busybox-1.21.1/include/applets.src.h
  13644. --- busybox-1.21.1.orig/include/applets.src.h 2013-06-29 16:58:06.000000000 +0200
  13645. +++ busybox-1.21.1/include/applets.src.h 2014-02-17 14:25:39.890534287 +0100
  13646. @@ -199,6 +199,7 @@
  13647. IF_IPCALC(APPLET(ipcalc, BB_DIR_BIN, BB_SUID_DROP))
  13648. IF_IPCRM(APPLET(ipcrm, BB_DIR_USR_BIN, BB_SUID_DROP))
  13649. IF_IPCS(APPLET(ipcs, BB_DIR_USR_BIN, BB_SUID_DROP))
  13650. +IF_IPKG(APPLET(ipkg, BB_DIR_USR_BIN, BB_SUID_DROP))
  13651. IF_IPLINK(APPLET(iplink, BB_DIR_SBIN, BB_SUID_DROP))
  13652. IF_IPROUTE(APPLET(iproute, BB_DIR_SBIN, BB_SUID_DROP))
  13653. IF_IPRULE(APPLET(iprule, BB_DIR_SBIN, BB_SUID_DROP))
  13654. diff -Nur busybox-1.21.1.orig/include/bb_archive.h busybox-1.21.1/include/bb_archive.h
  13655. --- busybox-1.21.1.orig/include/bb_archive.h 2013-06-29 16:58:06.000000000 +0200
  13656. +++ busybox-1.21.1/include/bb_archive.h 2014-02-17 14:25:39.890534287 +0100
  13657. @@ -79,7 +79,7 @@
  13658. /* Archiver specific. Can make it a union if it ever gets big */
  13659. #define PAX_NEXT_FILE 0
  13660. #define PAX_GLOBAL 1
  13661. -#if ENABLE_TAR || ENABLE_DPKG || ENABLE_DPKG_DEB
  13662. +#if ENABLE_TAR || ENABLE_DPKG || ENABLE_DPKG_DEB || ENABLE_IPKG
  13663. smallint tar__end;
  13664. # if ENABLE_FEATURE_TAR_GNU_EXTENSIONS
  13665. char* tar__longname;
  13666. @@ -98,7 +98,7 @@
  13667. struct hardlinks_t *cpio__hardlinks_to_create;
  13668. struct hardlinks_t *cpio__created_hardlinks;
  13669. #endif
  13670. -#if ENABLE_DPKG || ENABLE_DPKG_DEB
  13671. +#if ENABLE_DPKG || ENABLE_DPKG_DEB || ENABLE_IPKG
  13672. /* Temporary storage */
  13673. char *dpkg__buffer;
  13674. /* How to process any sub archive, e.g. get_header_tar_gz */
  13675. diff -Nur busybox-1.21.1.orig/include/usage.src.h busybox-1.21.1/include/usage.src.h
  13676. --- busybox-1.21.1.orig/include/usage.src.h 2013-05-12 01:30:43.000000000 +0200
  13677. +++ busybox-1.21.1/include/usage.src.h 2014-02-17 14:25:39.890534287 +0100
  13678. @@ -19,4 +19,80 @@
  13679. #define busybox_notes_usage \
  13680. "Hello world!\n"
  13681. +#define ipkg_trivial_usage \
  13682. + "[options]... sub-command [arguments]..."
  13683. +#define ipkg_full_usage \
  13684. + "ipkg is an utility to install, remove and manage .ipk packages.\n" \
  13685. + "\n" \
  13686. + "Sub-commands:\n" \
  13687. + "\nPackage Manipulation:\n" \
  13688. + "\tupdate Update list of available packages\n" \
  13689. + "\tupgrade Upgrade all installed packages to latest version\n" \
  13690. + "\tinstall <pkg> Download and install <pkg> (and dependencies)\n" \
  13691. + "\tinstall <file.ipk> Install package <file.ipk>\n" \
  13692. + "\tconfigure [<pkg>] Configure unpacked packages\n" \
  13693. + "\tremove <pkg|regexp> Remove package <pkg|packages following regexp>\n" \
  13694. + "\tflag <flag> <pkg> ... Flag package(s) <pkg>\n" \
  13695. + "\t <flag>=hold|noprune|user|ok|installed|unpacked (one per invocation) \n" \
  13696. + "\n" \
  13697. + "Informational Commands:\n" \
  13698. + "\tlist List available packages and descriptions\n" \
  13699. + "\tlist_installed List all and only the installed packages and description \n" \
  13700. + "\tfiles <pkg> List all files belonging to <pkg>\n" \
  13701. + "\tsearch <file|regexp> Search for a package providing <file>\n" \
  13702. + "\tinfo [pkg|regexp [<field>]] Display all/some info fields for <pkg> or all\n" \
  13703. + "\tstatus [pkg|regexp [<field>]] Display all/some status fields for <pkg> or all\n" \
  13704. + "\tdownload <pkg> Download <pkg> to current directory.\n" \
  13705. + "\tcompare_versions <v1> <op> <v2>\n" \
  13706. + "\t compare versions using <= < > >= = << >>\n" \
  13707. + "\tprint_architecture prints the architecture.\n" \
  13708. + "\tprint_installation_architecture\n" \
  13709. + "\twhatdepends [-A] [pkgname|pat]+\n" \
  13710. + "\twhatdependsrec [-A] [pkgname|pat]+\n" \
  13711. + "\twhatprovides [-A] [pkgname|pat]+\n" \
  13712. + "\twhatconflicts [-A] [pkgname|pat]+\n" \
  13713. + "\twhatreplaces [-A] [pkgname|pat]+\n" \
  13714. + "\t prints the installation architecture.\n" \
  13715. + "\n" \
  13716. + "\nOptions:\n" \
  13717. + "\t-A Query all packages with whatdepends, whatprovides, whatreplaces, whatconflicts\n" \
  13718. + "\t-V <level> Set verbosity level to <level>. If no value is\n" \
  13719. + "\t--verbosity <level> provided increase verbosity by one. Verbosity levels:\n" \
  13720. + "\t 0 errors only\n" \
  13721. + "\t 1 normal messages (default)\n" \
  13722. + "\t 2 informative messages\n" \
  13723. + "\t 3 debug output\n" \
  13724. + "\t-f <conf_file> Use <conf_file> as the ipkg configuration file\n" \
  13725. + "\t-conf <conf_file> Default configuration file location\n" \
  13726. + " is /etc/ipkg.conf\n" \
  13727. + "\t-d <dest_name> Use <dest_name> as the the root directory for\n" \
  13728. + "\t-dest <dest_name> package installation, removal, upgrading.\n" \
  13729. + " <dest_name> should be a defined dest name from\n" \
  13730. + " the configuration file, (but can also be a\n" \
  13731. + " directory name in a pinch).\n" \
  13732. + "\t-o <offline_root> Use <offline_root> as the root directory for\n" \
  13733. + "\t-offline <offline_root> offline installation of packages.\n" \
  13734. + "\t-verbose_wget more wget messages\n" \
  13735. + "\n" \
  13736. + "Force Options (use when ipkg is too smart for its own good):\n" \
  13737. + "\t-force-depends Make dependency checks warnings instead of errors\n" \
  13738. + "\t Install/remove package in spite of failed dependences\n" \
  13739. + "\t-force-defaults Use default options for questions asked by ipkg.\n" \
  13740. + " (no prompts). Note that this will not prevent\n" \
  13741. + " package installation scripts from prompting.\n" \
  13742. + "\t-force-reinstall Allow ipkg to reinstall a package.\n" \
  13743. + "\t-force-overwrite Allow ipkg to overwrite files from another package during an install.\n" \
  13744. + "\t-force-downgrade Allow ipkg to downgrade packages.\n" \
  13745. + "\t-force_space Install even if there does not seem to be enough space.\n" \
  13746. + "\t-noaction No action -- test only\n" \
  13747. + "\t-nodeps Do not follow dependences\n" \
  13748. + "\t-force-removal-of-dependent-packages\n" \
  13749. + "\t-recursive Allow ipkg to remove package and all that depend on it.\n" \
  13750. + "\t-test No action -- test only\n" \
  13751. + "\t-t Specify tmp-dir.\n" \
  13752. + "\t--tmp-dir Specify tmp-dir.\n" \
  13753. + "\n" \
  13754. + "\tregexp could be something like 'pkgname*' '*file*' or similar\n" \
  13755. + "\teg: ipkg info 'libstd*' or ipkg search '*libop*' or ipkg remove 'libncur*'\n"
  13756. +
  13757. #endif
  13758. diff -Nur busybox-1.21.1.orig/Makefile busybox-1.21.1/Makefile
  13759. --- busybox-1.21.1.orig/Makefile 2013-06-29 17:00:18.000000000 +0200
  13760. +++ busybox-1.21.1/Makefile 2014-02-17 14:25:39.890534287 +0100
  13761. @@ -466,6 +466,7 @@
  13762. libs-y := \
  13763. archival/ \
  13764. archival/libarchive/ \
  13765. + archival/libipkg/ \
  13766. console-tools/ \
  13767. coreutils/ \
  13768. coreutils/libcoreutils/ \