001-ipkg.patch 423 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689
  1. diff -Nur busybox-1.16.1.orig/archival/Config.in busybox-1.16.1/archival/Config.in
  2. --- busybox-1.16.1.orig/archival/Config.in 2010-03-28 19:43:35.000000000 +0200
  3. +++ busybox-1.16.1/archival/Config.in 2010-04-22 19:18:12.000000000 +0200
  4. @@ -187,6 +187,14 @@
  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. + select MD5SUM
  11. + select WGET
  12. + help
  13. + ipkg is the itsy package management system.
  14. +
  15. config RPM2CPIO
  16. bool "rpm2cpio"
  17. default n
  18. diff -Nur busybox-1.16.1.orig/archival/ipkg.c busybox-1.16.1/archival/ipkg.c
  19. --- busybox-1.16.1.orig/archival/ipkg.c 1970-01-01 01:00:00.000000000 +0100
  20. +++ busybox-1.16.1/archival/ipkg.c 2010-04-22 19:18:12.000000000 +0200
  21. @@ -0,0 +1,28 @@
  22. +/* ipkg.c - the itsy package management system
  23. +
  24. + Florina Boor
  25. +
  26. + Copyright (C) 2003 kernel concepts
  27. +
  28. + This program is free software; you can redistribute it and/or
  29. + modify it under the terms of the GNU General Public License as
  30. + published by the Free Software Foundation; either version 2, or (at
  31. + your option) any later version.
  32. +
  33. + This program is distributed in the hope that it will be useful, but
  34. + WITHOUT ANY WARRANTY; without even the implied warranty of
  35. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  36. + General Public License for more details.
  37. +
  38. + ipkg command line frontend using libipkg
  39. +
  40. +*/
  41. +
  42. +#include "libbb.h"
  43. +#include "libipkg/libipkg.h"
  44. +
  45. +int ipkg_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  46. +int ipkg_main(int argc, char **argv)
  47. +{
  48. + return ipkg_op(argc, argv);
  49. +}
  50. diff -Nur busybox-1.16.1.orig/archival/Kbuild busybox-1.16.1/archival/Kbuild
  51. --- busybox-1.16.1.orig/archival/Kbuild 2010-03-20 03:58:07.000000000 +0100
  52. +++ busybox-1.16.1/archival/Kbuild 2010-04-22 19:18:12.000000000 +0200
  53. @@ -16,6 +16,7 @@
  54. lib-$(CONFIG_DPKG_DEB) += dpkg_deb.o
  55. lib-$(CONFIG_GUNZIP) += bbunzip.o
  56. lib-$(CONFIG_GZIP) += gzip.o bbunzip.o
  57. +lib-$(CONFIG_IPKG) += ipkg.o
  58. lib-$(CONFIG_LZOP) += lzop.o lzo1x_1.o lzo1x_1o.o lzo1x_d.o bbunzip.o
  59. lib-$(CONFIG_LZOP_COMPR_HIGH) += lzo1x_9x.o
  60. lib-$(CONFIG_RPM2CPIO) += rpm2cpio.o
  61. diff -Nur busybox-1.16.1.orig/archival/libipkg/args.c busybox-1.16.1/archival/libipkg/args.c
  62. --- busybox-1.16.1.orig/archival/libipkg/args.c 1970-01-01 01:00:00.000000000 +0100
  63. +++ busybox-1.16.1/archival/libipkg/args.c 2010-04-22 19:18:12.000000000 +0200
  64. @@ -0,0 +1,242 @@
  65. +/* args.c - parse command-line args
  66. +
  67. + Carl D. Worth
  68. +
  69. + Copyright 2001 University of Southern California
  70. +
  71. + This program is free software; you can redistribute it and/or modify
  72. + it under the terms of the GNU General Public License as published by
  73. + the Free Software Foundation; either version 2, or (at your option)
  74. + any later version.
  75. +
  76. + This program is distributed in the hope that it will be useful,
  77. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  78. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  79. + GNU General Public License for more details.
  80. + */
  81. +
  82. +#include <getopt.h>
  83. +#include <stdlib.h>
  84. +#include <string.h>
  85. +#include <unistd.h>
  86. +
  87. +#include "ipkg.h"
  88. +#include "ipkg_message.h"
  89. +
  90. +#include "args.h"
  91. +#include "sprintf_alloc.h"
  92. +
  93. +#include "libbb.h"
  94. +
  95. +
  96. +static void print_version(void);
  97. +
  98. +enum long_args_opt
  99. +{
  100. + ARGS_OPT_FORCE_DEFAULTS = 129,
  101. + ARGS_OPT_FORCE_DEPENDS,
  102. + ARGS_OPT_FORCE_OVERWRITE,
  103. + ARGS_OPT_FORCE_DOWNGRADE,
  104. + ARGS_OPT_FORCE_REINSTALL,
  105. + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES,
  106. + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES,
  107. + ARGS_OPT_FORCE_SPACE,
  108. + ARGS_OPT_NOACTION,
  109. + ARGS_OPT_NODEPS,
  110. + ARGS_OPT_VERBOSE_WGET,
  111. + ARGS_OPT_VERBOSITY,
  112. + ARGS_OPT_MULTIPLE_PROVIDERS
  113. +};
  114. +
  115. +int args_init(args_t *args)
  116. +{
  117. + const char *conf_file_dir;
  118. +
  119. + memset(args, 0, sizeof(args_t));
  120. +
  121. + args->dest = ARGS_DEFAULT_DEST;
  122. +
  123. + conf_file_dir = getenv("IPKG_CONF_DIR");
  124. + if (conf_file_dir == NULL || conf_file_dir[0] == '\0') {
  125. + conf_file_dir = ARGS_DEFAULT_CONF_FILE_DIR;
  126. + }
  127. + sprintf_alloc(&args->conf_file, "%s/%s", conf_file_dir,
  128. + ARGS_DEFAULT_CONF_FILE_NAME);
  129. +
  130. + args->force_defaults = ARGS_DEFAULT_FORCE_DEFAULTS;
  131. + args->force_depends = ARGS_DEFAULT_FORCE_DEPENDS;
  132. + args->force_overwrite = ARGS_DEFAULT_FORCE_OVERWRITE;
  133. + args->force_downgrade = ARGS_DEFAULT_FORCE_DOWNGRADE;
  134. + args->force_reinstall = ARGS_DEFAULT_FORCE_REINSTALL;
  135. + args->force_removal_of_dependent_packages = ARGS_DEFAULT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES;
  136. + args->force_removal_of_essential_packages = ARGS_DEFAULT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES;
  137. + args->noaction = ARGS_DEFAULT_NOACTION;
  138. + args->nodeps = ARGS_DEFAULT_NODEPS;
  139. + args->verbose_wget = ARGS_DEFAULT_VERBOSE_WGET;
  140. + args->verbosity = ARGS_DEFAULT_VERBOSITY;
  141. + args->offline_root = ARGS_DEFAULT_OFFLINE_ROOT;
  142. + args->offline_root_pre_script_cmd = ARGS_DEFAULT_OFFLINE_ROOT_PRE_SCRIPT_CMD;
  143. + args->offline_root_post_script_cmd = ARGS_DEFAULT_OFFLINE_ROOT_POST_SCRIPT_CMD;
  144. + args->multiple_providers = 0;
  145. + args->nocheckfordirorfile = 0;
  146. + args->noreadfeedsfile = 0;
  147. +
  148. + return 1;
  149. +}
  150. +
  151. +void args_deinit(args_t *args)
  152. +{
  153. + free(args->conf_file);
  154. + args->conf_file = NULL;
  155. +}
  156. +
  157. +int args_parse(args_t *args, int argc, char *argv[])
  158. +{
  159. + int c;
  160. + int option_index = 0;
  161. + int parse_err = 0;
  162. + static struct option long_options[] = {
  163. + {"query-all", 0, 0, 'A'},
  164. + {"conf-file", 1, 0, 'f'},
  165. + {"conf", 1, 0, 'f'},
  166. + {"dest", 1, 0, 'd'},
  167. + {"force-defaults", 0, 0, ARGS_OPT_FORCE_DEFAULTS},
  168. + {"force_defaults", 0, 0, ARGS_OPT_FORCE_DEFAULTS},
  169. + {"force-depends", 0, 0, ARGS_OPT_FORCE_DEPENDS},
  170. + {"force_depends", 0, 0, ARGS_OPT_FORCE_DEPENDS},
  171. + {"force-overwrite", 0, 0, ARGS_OPT_FORCE_OVERWRITE},
  172. + {"force_overwrite", 0, 0, ARGS_OPT_FORCE_OVERWRITE},
  173. + {"force_downgrade", 0, 0, ARGS_OPT_FORCE_DOWNGRADE},
  174. + {"force-downgrade", 0, 0, ARGS_OPT_FORCE_DOWNGRADE},
  175. + {"force-reinstall", 0, 0, ARGS_OPT_FORCE_REINSTALL},
  176. + {"force_reinstall", 0, 0, ARGS_OPT_FORCE_REINSTALL},
  177. + {"force-space", 0, 0, ARGS_OPT_FORCE_SPACE},
  178. + {"force_space", 0, 0, ARGS_OPT_FORCE_SPACE},
  179. + {"recursive", 0, 0,
  180. + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
  181. + {"force-removal-of-dependent-packages", 0, 0,
  182. + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
  183. + {"force_removal_of_dependent_packages", 0, 0,
  184. + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
  185. + {"force-removal-of-essential-packages", 0, 0,
  186. + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES},
  187. + {"force_removal_of_essential_packages", 0, 0,
  188. + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES},
  189. + {"multiple-providers", 0, 0, ARGS_OPT_MULTIPLE_PROVIDERS},
  190. + {"multiple_providers", 0, 0, ARGS_OPT_MULTIPLE_PROVIDERS},
  191. + {"noaction", 0, 0, ARGS_OPT_NOACTION},
  192. + {"nodeps", 0, 0, ARGS_OPT_NODEPS},
  193. + {"offline", 1, 0, 'o'},
  194. + {"offline-root", 1, 0, 'o'},
  195. + {"test", 0, 0, ARGS_OPT_NOACTION},
  196. + {"tmp-dir", 1, 0, 't'},
  197. + {"verbose-wget", 0, 0, ARGS_OPT_VERBOSE_WGET},
  198. + {"verbose_wget", 0, 0, ARGS_OPT_VERBOSE_WGET},
  199. + {"verbosity", 2, 0, 'V'},
  200. + {"version", 0, 0, 'v'},
  201. + {0, 0, 0, 0}
  202. + };
  203. +
  204. + while (1) {
  205. + c = getopt_long_only(argc, argv, "Ad:f:no:t:vV:", long_options, &option_index);
  206. + if (c == -1)
  207. + break;
  208. +
  209. + switch (c) {
  210. + case 'A':
  211. + args->query_all = 1;
  212. + break;
  213. + case 'd':
  214. + args->dest = optarg;
  215. + break;
  216. + case 'f':
  217. + free(args->conf_file);
  218. + args->conf_file = strdup(optarg);
  219. + break;
  220. + case 'o':
  221. + args->offline_root = optarg;
  222. + break;
  223. + case 'n':
  224. + args->noaction = 1;
  225. + break;
  226. + case 't':
  227. + args->tmp_dir = strdup(optarg);
  228. + break;
  229. + case 'v':
  230. + print_version();
  231. + exit(0);
  232. + case 'V':
  233. + case ARGS_OPT_VERBOSITY:
  234. + if (optarg)
  235. + args->verbosity = atoi(optarg);
  236. + else
  237. + args->verbosity += 1;
  238. + break;
  239. + case ARGS_OPT_FORCE_DEFAULTS:
  240. + args->force_defaults = 1;
  241. + break;
  242. + case ARGS_OPT_FORCE_DEPENDS:
  243. + args->force_depends = 1;
  244. + break;
  245. + case ARGS_OPT_FORCE_OVERWRITE:
  246. + args->force_overwrite = 1;
  247. + break;
  248. + case ARGS_OPT_FORCE_DOWNGRADE:
  249. + args->force_downgrade = 1;
  250. + break;
  251. + case ARGS_OPT_FORCE_REINSTALL:
  252. + args->force_reinstall = 1;
  253. + break;
  254. + case ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES:
  255. + args->force_removal_of_essential_packages = 1;
  256. + break;
  257. + case ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES:
  258. + args->force_removal_of_dependent_packages = 1;
  259. + break;
  260. + case ARGS_OPT_FORCE_SPACE:
  261. + args->force_space = 1;
  262. + break;
  263. + case ARGS_OPT_VERBOSE_WGET:
  264. + args->verbose_wget = 1;
  265. + break;
  266. + case ARGS_OPT_MULTIPLE_PROVIDERS:
  267. + args->multiple_providers = 1;
  268. + break;
  269. + case ARGS_OPT_NODEPS:
  270. + args->nodeps = 1;
  271. + break;
  272. + case ARGS_OPT_NOACTION:
  273. + args->noaction = 1;
  274. + break;
  275. + case ':':
  276. + parse_err++;
  277. + break;
  278. + case '?':
  279. + parse_err++;
  280. + break;
  281. + default:
  282. + bb_error_msg("Confusion: getopt_long returned %d\n", c);
  283. + }
  284. + }
  285. +
  286. + if (parse_err) {
  287. + return -parse_err;
  288. + } else {
  289. + return optind;
  290. + }
  291. +}
  292. +
  293. +void args_usage(const char *complaint)
  294. +{
  295. + if (complaint) {
  296. + bb_error_msg("%s\n", complaint);
  297. + }
  298. + print_version();
  299. + bb_show_usage();
  300. + exit(1);
  301. +}
  302. +
  303. +static void print_version(void)
  304. +{
  305. + bb_error_msg("version %s\n", IPKG_VERSION);
  306. +}
  307. diff -Nur busybox-1.16.1.orig/archival/libipkg/args.h busybox-1.16.1/archival/libipkg/args.h
  308. --- busybox-1.16.1.orig/archival/libipkg/args.h 1970-01-01 01:00:00.000000000 +0100
  309. +++ busybox-1.16.1/archival/libipkg/args.h 2010-04-22 19:18:12.000000000 +0200
  310. @@ -0,0 +1,72 @@
  311. +/* args.h - parse command-line args
  312. +
  313. + Carl D. Worth
  314. +
  315. + Copyright 2001 University of Southern California
  316. +
  317. + This program is free software; you can redistribute it and/or modify
  318. + it under the terms of the GNU General Public License as published by
  319. + the Free Software Foundation; either version 2, or (at your option)
  320. + any later version.
  321. +
  322. + This program is distributed in the hope that it will be useful,
  323. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  324. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  325. + GNU General Public License for more details.
  326. +*/
  327. +
  328. +#ifndef ARGS_H
  329. +#define ARGS_H
  330. +
  331. +struct args
  332. +{
  333. + char *conf_file;
  334. + char *dest;
  335. + char *tmp_dir;
  336. + int force_defaults;
  337. + int force_depends;
  338. + int force_overwrite;
  339. + int force_downgrade;
  340. + int force_reinstall;
  341. + int force_removal_of_essential_packages;
  342. + int force_removal_of_dependent_packages;
  343. + int force_space;
  344. + int noaction;
  345. + int nodeps;
  346. + int multiple_providers;
  347. + int query_all;
  348. + int verbose_wget;
  349. + int verbosity;
  350. + int nocheckfordirorfile;
  351. + int noreadfeedsfile;
  352. + char *offline_root;
  353. + char *offline_root_pre_script_cmd;
  354. + char *offline_root_post_script_cmd;
  355. +};
  356. +typedef struct args args_t;
  357. +
  358. +#define ARGS_DEFAULT_CONF_FILE_DIR "/etc"
  359. +#define ARGS_DEFAULT_CONF_FILE_NAME "ipkg.conf"
  360. +#define ARGS_DEFAULT_DEST NULL
  361. +#define ARGS_DEFAULT_FORCE_DEFAULTS 0
  362. +#define ARGS_DEFAULT_FORCE_DEPENDS 0
  363. +#define ARGS_DEFAULT_FORCE_OVERWRITE 0
  364. +#define ARGS_DEFAULT_FORCE_DOWNGRADE 0
  365. +#define ARGS_DEFAULT_FORCE_REINSTALL 0
  366. +#define ARGS_DEFAULT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES 0
  367. +#define ARGS_DEFAULT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES 0
  368. +#define ARGS_DEFAULT_FORCE_SPACE 0
  369. +#define ARGS_DEFAULT_OFFLINE_ROOT NULL
  370. +#define ARGS_DEFAULT_OFFLINE_ROOT_PRE_SCRIPT_CMD NULL
  371. +#define ARGS_DEFAULT_OFFLINE_ROOT_POST_SCRIPT_CMD NULL
  372. +#define ARGS_DEFAULT_NOACTION 0
  373. +#define ARGS_DEFAULT_NODEPS 0
  374. +#define ARGS_DEFAULT_VERBOSE_WGET 0
  375. +#define ARGS_DEFAULT_VERBOSITY 1
  376. +
  377. +int args_init(args_t *args);
  378. +void args_deinit(args_t *args);
  379. +int args_parse(args_t *args, int argc, char *argv[]);
  380. +void args_usage(const char *complaint);
  381. +
  382. +#endif
  383. diff -Nur busybox-1.16.1.orig/archival/libipkg/conffile.c busybox-1.16.1/archival/libipkg/conffile.c
  384. --- busybox-1.16.1.orig/archival/libipkg/conffile.c 1970-01-01 01:00:00.000000000 +0100
  385. +++ busybox-1.16.1/archival/libipkg/conffile.c 2010-04-22 19:18:12.000000000 +0200
  386. @@ -0,0 +1,65 @@
  387. +/* conffile.c - the itsy package management system
  388. +
  389. + Carl D. Worth
  390. +
  391. + Copyright (C) 2001 University of Southern California
  392. +
  393. + This program is free software; you can redistribute it and/or
  394. + modify it under the terms of the GNU General Public License as
  395. + published by the Free Software Foundation; either version 2, or (at
  396. + your option) any later version.
  397. +
  398. + This program is distributed in the hope that it will be useful, but
  399. + WITHOUT ANY WARRANTY; without even the implied warranty of
  400. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  401. + General Public License for more details.
  402. +*/
  403. +
  404. +#include <string.h>
  405. +#include <stdlib.h>
  406. +
  407. +#include "libbb.h"
  408. +#include "ipkg.h"
  409. +#include "ipkg_message.h"
  410. +
  411. +#include "conffile.h"
  412. +#include "file_util.h"
  413. +#include "sprintf_alloc.h"
  414. +
  415. +int conffile_init(conffile_t *conffile, const char *file_name, const uint8_t *md5sum)
  416. +{
  417. + return nv_pair_init(conffile, file_name, (char *)md5sum);
  418. +}
  419. +
  420. +void conffile_deinit(conffile_t *conffile)
  421. +{
  422. + nv_pair_deinit(conffile);
  423. +}
  424. +
  425. +int conffile_has_been_modified(ipkg_conf_t *conf, conffile_t *conffile)
  426. +{
  427. + uint8_t *md5sum;
  428. + char *filename = conffile->name;
  429. + char *root_filename;
  430. + int ret;
  431. +
  432. + if (conffile->value == NULL) {
  433. + ipkg_message(conf, IPKG_NOTICE, "%s: conffile %s has no md5sum\n", __FUNCTION__, conffile->name);
  434. + return 1;
  435. + }
  436. +
  437. + root_filename = root_filename_alloc(conf, filename);
  438. +
  439. + md5sum = file_md5sum_alloc(root_filename);
  440. +
  441. + ret = strcmp((char *)md5sum, conffile->value);
  442. + if (ret) {
  443. + ipkg_message(conf, IPKG_NOTICE, "%s: conffile %s: \t\nold md5=%s \t\nnew md5=%s\n", __FUNCTION__,
  444. + conffile->name, md5sum, conffile->value);
  445. + }
  446. +
  447. + free(root_filename);
  448. + free(md5sum);
  449. +
  450. + return ret;
  451. +}
  452. diff -Nur busybox-1.16.1.orig/archival/libipkg/conffile.h busybox-1.16.1/archival/libipkg/conffile.h
  453. --- busybox-1.16.1.orig/archival/libipkg/conffile.h 1970-01-01 01:00:00.000000000 +0100
  454. +++ busybox-1.16.1/archival/libipkg/conffile.h 2010-04-22 19:18:12.000000000 +0200
  455. @@ -0,0 +1,30 @@
  456. +/* conffile.h - the itsy package management system
  457. +
  458. + Carl D. Worth
  459. +
  460. + Copyright (C) 2001 University of Southern California
  461. +
  462. + This program is free software; you can redistribute it and/or
  463. + modify it under the terms of the GNU General Public License as
  464. + published by the Free Software Foundation; either version 2, or (at
  465. + your option) any later version.
  466. +
  467. + This program is distributed in the hope that it will be useful, but
  468. + WITHOUT ANY WARRANTY; without even the implied warranty of
  469. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  470. + General Public License for more details.
  471. +*/
  472. +
  473. +#ifndef CONFFILE_H
  474. +#define CONFFILE_H
  475. +
  476. +#include "nv_pair.h"
  477. +
  478. +typedef struct nv_pair conffile_t;
  479. +
  480. +int conffile_init(conffile_t *conffile, const char *file_name, const uint8_t *md5sum);
  481. +void conffile_deinit(conffile_t *conffile);
  482. +int conffile_has_been_modified(struct ipkg_conf *conf, conffile_t *conffile);
  483. +
  484. +#endif
  485. +
  486. diff -Nur busybox-1.16.1.orig/archival/libipkg/conffile_list.c busybox-1.16.1/archival/libipkg/conffile_list.c
  487. --- busybox-1.16.1.orig/archival/libipkg/conffile_list.c 1970-01-01 01:00:00.000000000 +0100
  488. +++ busybox-1.16.1/archival/libipkg/conffile_list.c 2010-04-22 19:18:12.000000000 +0200
  489. @@ -0,0 +1,47 @@
  490. +/* conffile_list.c - the itsy package management system
  491. +
  492. + Carl D. Worth
  493. +
  494. + Copyright (C) 2001 University of Southern California
  495. +
  496. + This program is free software; you can redistribute it and/or
  497. + modify it under the terms of the GNU General Public License as
  498. + published by the Free Software Foundation; either version 2, or (at
  499. + your option) any later version.
  500. +
  501. + This program is distributed in the hope that it will be useful, but
  502. + WITHOUT ANY WARRANTY; without even the implied warranty of
  503. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  504. + General Public License for more details.
  505. +*/
  506. +
  507. +#include "ipkg.h"
  508. +
  509. +#include "conffile_list.h"
  510. +
  511. +int conffile_list_init(conffile_list_t *list)
  512. +{
  513. + return nv_pair_list_init(list);
  514. +}
  515. +
  516. +void conffile_list_deinit(conffile_list_t *list)
  517. +{
  518. + nv_pair_list_deinit(list);
  519. +}
  520. +
  521. +conffile_t *conffile_list_append(conffile_list_t *list, const char *file_name,
  522. + const char *md5sum)
  523. +{
  524. + return nv_pair_list_append(list, file_name, md5sum);
  525. +}
  526. +
  527. +int conffile_list_push(conffile_list_t *list, conffile_t *data)
  528. +{
  529. + return nv_pair_list_push(list, data);
  530. +}
  531. +
  532. +conffile_list_elt_t *conffile_list_pop(conffile_list_t *list)
  533. +{
  534. + return nv_pair_list_pop(list);
  535. +}
  536. +
  537. diff -Nur busybox-1.16.1.orig/archival/libipkg/conffile_list.h busybox-1.16.1/archival/libipkg/conffile_list.h
  538. --- busybox-1.16.1.orig/archival/libipkg/conffile_list.h 1970-01-01 01:00:00.000000000 +0100
  539. +++ busybox-1.16.1/archival/libipkg/conffile_list.h 2010-04-22 19:18:12.000000000 +0200
  540. @@ -0,0 +1,36 @@
  541. +/* conffile_list.h - the itsy package management system
  542. +
  543. + Carl D. Worth
  544. +
  545. + Copyright (C) 2001 University of Southern California
  546. +
  547. + This program is free software; you can redistribute it and/or
  548. + modify it under the terms of the GNU General Public License as
  549. + published by the Free Software Foundation; either version 2, or (at
  550. + your option) any later version.
  551. +
  552. + This program is distributed in the hope that it will be useful, but
  553. + WITHOUT ANY WARRANTY; without even the implied warranty of
  554. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  555. + General Public License for more details.
  556. +*/
  557. +
  558. +#ifndef CONFFILE_LIST_H
  559. +#define CONFFILE_LIST_H
  560. +
  561. +#include "conffile.h"
  562. +#include "nv_pair_list.h"
  563. +
  564. +typedef struct nv_pair_list_elt conffile_list_elt_t;
  565. +typedef struct nv_pair_list conffile_list_t;
  566. +
  567. +int conffile_list_init(conffile_list_t *list);
  568. +void conffile_list_deinit(conffile_list_t *list);
  569. +
  570. +conffile_t *conffile_list_append(conffile_list_t *list, const char *name,
  571. + const char *root_dir);
  572. +int conffile_list_push(conffile_list_t *list, conffile_t *data);
  573. +conffile_list_elt_t *conffile_list_pop(conffile_list_t *list);
  574. +
  575. +#endif
  576. +
  577. diff -Nur busybox-1.16.1.orig/archival/libipkg/file_util.c busybox-1.16.1/archival/libipkg/file_util.c
  578. --- busybox-1.16.1.orig/archival/libipkg/file_util.c 1970-01-01 01:00:00.000000000 +0100
  579. +++ busybox-1.16.1/archival/libipkg/file_util.c 2010-04-22 19:18:12.000000000 +0200
  580. @@ -0,0 +1,186 @@
  581. +/* file_util.c - convenience routines for common stat operations
  582. +
  583. + Carl D. Worth
  584. +
  585. + Copyright (C) 2001 University of Southern California
  586. +
  587. + This program is free software; you can redistribute it and/or
  588. + modify it under the terms of the GNU General Public License as
  589. + published by the Free Software Foundation; either version 2, or (at
  590. + your option) any later version.
  591. +
  592. + This program is distributed in the hope that it will be useful, but
  593. + WITHOUT ANY WARRANTY; without even the implied warranty of
  594. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  595. + General Public License for more details.
  596. +*/
  597. +
  598. +#include "ipkg.h"
  599. +#include <sys/types.h>
  600. +#include <sys/stat.h>
  601. +
  602. +#include "sprintf_alloc.h"
  603. +#include "file_util.h"
  604. +#include "libbb.h"
  605. +#undef strlen
  606. +
  607. +int file_exists(const char *file_name)
  608. +{
  609. + int err;
  610. + struct stat stat_buf;
  611. +
  612. + err = stat(file_name, &stat_buf);
  613. + if (err == 0) {
  614. + return 1;
  615. + } else {
  616. + return 0;
  617. + }
  618. +}
  619. +
  620. +int file_is_dir(const char *file_name)
  621. +{
  622. + int err;
  623. + struct stat stat_buf;
  624. +
  625. + err = stat(file_name, &stat_buf);
  626. + if (err) {
  627. + return 0;
  628. + }
  629. +
  630. + return S_ISDIR(stat_buf.st_mode);
  631. +}
  632. +
  633. +/* read a single line from a file, stopping at a newline or EOF.
  634. + If a newline is read, it will appear in the resulting string.
  635. + Return value is a malloc'ed char * which should be freed at
  636. + some point by the caller.
  637. +
  638. + Return value is NULL if the file is at EOF when called.
  639. +*/
  640. +#define FILE_READ_LINE_BUF_SIZE 1024
  641. +char *file_read_line_alloc(FILE *file)
  642. +{
  643. + char buf[FILE_READ_LINE_BUF_SIZE];
  644. + int buf_len;
  645. + char *line = NULL;
  646. + int line_size = 0;
  647. +
  648. + memset(buf, 0, FILE_READ_LINE_BUF_SIZE);
  649. + while (fgets(buf, FILE_READ_LINE_BUF_SIZE, file)) {
  650. + buf_len = strlen(buf);
  651. + if (line) {
  652. + line_size += buf_len;
  653. + line = realloc(line, line_size);
  654. + if (line == NULL) {
  655. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  656. + break;
  657. + }
  658. + strcat(line, buf);
  659. + } else {
  660. + line_size = buf_len + 1;
  661. + line = strdup(buf);
  662. + }
  663. + if (buf[buf_len - 1] == '\n') {
  664. + break;
  665. + }
  666. + }
  667. +
  668. + return line;
  669. +}
  670. +
  671. +int file_move(const char *src, const char *dest)
  672. +{
  673. + int err;
  674. +
  675. + err = rename(src, dest);
  676. +
  677. + if (err && errno == EXDEV) {
  678. + err = file_copy(src, dest);
  679. + unlink(src);
  680. + } else if (err) {
  681. + fprintf(stderr, "%s: ERROR: failed to rename %s to %s: %s\n",
  682. + __FUNCTION__, src, dest, strerror(errno));
  683. + }
  684. +
  685. + return err;
  686. +}
  687. +
  688. +/* I put these here to keep libbb dependencies from creeping all over
  689. + the ipkg code */
  690. +int file_copy(const char *src, const char *dest)
  691. +{
  692. + int err;
  693. +
  694. + err = copy_file(src, dest, FILEUTILS_FORCE | FILEUTILS_PRESERVE_STATUS);
  695. + if (err) {
  696. + fprintf(stderr, "%s: ERROR: failed to copy %s to %s\n",
  697. + __FUNCTION__, src, dest);
  698. + }
  699. +
  700. + return err;
  701. +}
  702. +
  703. +int file_mkdir_hier(char *path, long mode)
  704. +{
  705. + return bb_make_directory(path, mode, FILEUTILS_RECUR);
  706. +}
  707. +
  708. +static unsigned char *hash_bin_to_hex(unsigned char *hash_value,
  709. + unsigned hash_length)
  710. +{
  711. + /* xzalloc zero-terminates */
  712. + char *hex_value = xzalloc((hash_length * 2) + 1);
  713. + bin2hex(hex_value, (char*)hash_value, hash_length);
  714. + return (unsigned char *)hex_value;
  715. +}
  716. +
  717. +static uint8_t *hash_file(const char *filename, hash_algo_t hash_algo)
  718. +{
  719. + int src_fd, hash_len, count;
  720. + union _ctx_ {
  721. + sha1_ctx_t sha1;
  722. + md5_ctx_t md5;
  723. + } context;
  724. + uint8_t *hash_value = NULL;
  725. + RESERVE_CONFIG_UBUFFER(in_buf, 4096);
  726. + void FAST_FUNC (*update)(const void*, size_t, void*);
  727. + void FAST_FUNC (*final)(void*, void*);
  728. +
  729. + src_fd = open_or_warn_stdin(filename);
  730. + if (src_fd < 0) {
  731. + return NULL;
  732. + }
  733. +
  734. + /* figure specific hash algorithims */
  735. + if (ENABLE_MD5SUM && hash_algo == HASH_MD5) {
  736. + md5_begin(&context.md5);
  737. + update = (void*)md5_hash;
  738. + final = (void*)md5_end;
  739. + hash_len = 16;
  740. + } else {
  741. + bb_error_msg_and_die("algorithm not supported");
  742. + }
  743. +
  744. + while (0 < (count = safe_read(src_fd, in_buf, 4096))) {
  745. + update(in_buf, count, &context);
  746. + }
  747. +
  748. + if (count == 0) {
  749. + final(in_buf, &context);
  750. + hash_value = hash_bin_to_hex(in_buf, hash_len);
  751. + }
  752. +
  753. + RELEASE_CONFIG_BUFFER(in_buf);
  754. +
  755. + if (src_fd != STDIN_FILENO) {
  756. + close(src_fd);
  757. + }
  758. +
  759. + return hash_value;
  760. +}
  761. +
  762. +uint8_t *file_md5sum_alloc(const char *file_name)
  763. +{
  764. + return hash_file(file_name, HASH_MD5);
  765. +}
  766. +
  767. diff -Nur busybox-1.16.1.orig/archival/libipkg/file_util.h busybox-1.16.1/archival/libipkg/file_util.h
  768. --- busybox-1.16.1.orig/archival/libipkg/file_util.h 1970-01-01 01:00:00.000000000 +0100
  769. +++ busybox-1.16.1/archival/libipkg/file_util.h 2010-04-22 19:18:12.000000000 +0200
  770. @@ -0,0 +1,29 @@
  771. +/* file_util.h - convenience routines for common file operations
  772. +
  773. + Carl D. Worth
  774. +
  775. + Copyright (C) 2001 University of Southern California
  776. +
  777. + This program is free software; you can redistribute it and/or
  778. + modify it under the terms of the GNU General Public License as
  779. + published by the Free Software Foundation; either version 2, or (at
  780. + your option) any later version.
  781. +
  782. + This program is distributed in the hope that it will be useful, but
  783. + WITHOUT ANY WARRANTY; without even the implied warranty of
  784. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  785. + General Public License for more details.
  786. +*/
  787. +
  788. +#ifndef FILE_UTIL_H
  789. +#define FILE_UTIL_H
  790. +
  791. +int file_exists(const char *file_name);
  792. +int file_is_dir(const char *file_name);
  793. +char *file_read_line_alloc(FILE *file);
  794. +int file_move(const char *src, const char *dest);
  795. +int file_copy(const char *src, const char *dest);
  796. +int file_mkdir_hier(char *path, long mode);
  797. +uint8_t *file_md5sum_alloc(const char *file_name);
  798. +
  799. +#endif
  800. diff -Nur busybox-1.16.1.orig/archival/libipkg/hash_table.c busybox-1.16.1/archival/libipkg/hash_table.c
  801. --- busybox-1.16.1.orig/archival/libipkg/hash_table.c 1970-01-01 01:00:00.000000000 +0100
  802. +++ busybox-1.16.1/archival/libipkg/hash_table.c 2010-04-22 19:18:12.000000000 +0200
  803. @@ -0,0 +1,155 @@
  804. +/* hash.c - hash tables for ipkg
  805. +
  806. + Steven M. Ayer, Jamey Hicks
  807. +
  808. + Copyright (C) 2002 Compaq Computer Corporation
  809. +
  810. + This program is free software; you can redistribute it and/or
  811. + modify it under the terms of the GNU General Public License as
  812. + published by the Free Software Foundation; either version 2, or (at
  813. + your option) any later version.
  814. +
  815. + This program is distributed in the hope that it will be useful, but
  816. + WITHOUT ANY WARRANTY; without even the implied warranty of
  817. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  818. + General Public License for more details.
  819. +*/
  820. +
  821. +#include <errno.h>
  822. +#include <stdio.h>
  823. +#include <stdlib.h>
  824. +#include <string.h>
  825. +#include "hash_table.h"
  826. +#include "ipkg_message.h"
  827. +
  828. +
  829. +static int hash_index(hash_table_t *hash, const char *pkg_name);
  830. +static int rotating(const char *key, int len, int prime);
  831. +
  832. +static int hash_index(hash_table_t *hash, const char *pkg_name)
  833. +{
  834. + return rotating(pkg_name, strlen(pkg_name), hash->n_entries);
  835. +}
  836. +
  837. +static int rotating(const char *key, int len, int prime)
  838. +{
  839. + unsigned int hash, i;
  840. + for (hash=len, i=0; i<len; ++i)
  841. + hash = (hash<<4)^(hash>>28)^key[i];
  842. + return (hash % prime);
  843. +}
  844. +
  845. +
  846. +/*
  847. + * this is an open table keyed by strings
  848. + */
  849. +int hash_table_init(const char *name, hash_table_t *hash, int len)
  850. +{
  851. + static int primes_table[] = {
  852. + 379, 761, 983, 1423, 2711, 3361, 3931, 4679, 5519, 6701, 9587,
  853. + 19471, 23143, 33961, 46499, 49727, 99529, 0
  854. + };
  855. + int *picker;
  856. +
  857. + if (hash->entries != NULL) {
  858. + /* we have been here already */
  859. + return 0;
  860. + }
  861. +
  862. + hash->name = name;
  863. + hash->entries = NULL;
  864. + hash->n_entries = 0;
  865. + hash->hash_entry_key = NULL;
  866. +
  867. + picker = primes_table;
  868. + while(*picker && (*picker++ < len));
  869. + if(!*picker)
  870. + fprintf(stderr, "%s: primes table might not be big enough (! << %d)\n", __FUNCTION__, len);
  871. + --picker;
  872. +
  873. + hash->n_entries = *picker;
  874. + hash->entries = (hash_entry_t *)calloc(hash->n_entries, sizeof(hash_entry_t));
  875. + if (hash->entries == NULL) {
  876. + fprintf(stderr, "%s: Out of memory.\n", __FUNCTION__);
  877. + return ENOMEM;
  878. + }
  879. + return 0;
  880. +}
  881. +
  882. +void hash_table_deinit(hash_table_t *hash)
  883. +{
  884. + free(hash->entries);
  885. + hash->entries = NULL;
  886. + hash->n_entries = 0;
  887. +}
  888. +
  889. +void *hash_table_get(hash_table_t *hash, const char *key)
  890. +{
  891. + int ndx= hash_index(hash, key);
  892. + hash_entry_t *hash_entry = hash->entries + ndx;
  893. + while (hash_entry)
  894. + {
  895. + if (hash_entry->key)
  896. + {
  897. + if (strcmp(key, hash_entry->key) == 0) {
  898. + // ipkg_message(NULL, IPKG_DEBUG, "Function: %s. Key found for '%s' \n", __FUNCTION__, key);
  899. + return hash_entry->data;
  900. + }
  901. + }
  902. + hash_entry = hash_entry->next;
  903. + }
  904. + return NULL;
  905. +}
  906. +
  907. +int hash_table_insert(hash_table_t *hash, const char *key, void *value)
  908. +{
  909. + int ndx= hash_index(hash, key);
  910. + hash_entry_t *hash_entry = hash->entries + ndx;
  911. + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Inserting in hash for '%s' \n", __FUNCTION__, key);
  912. + if (hash_entry->key) {
  913. + if (strcmp(hash_entry->key, key) == 0) {
  914. + /* alread in table, update the value */
  915. + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Value already in hash for '%s' \n", __FUNCTION__, key);
  916. + hash_entry->data = value;
  917. + return 0;
  918. + } else {
  919. + /*
  920. + * if this is a collision, we have to go to the end of the ll,
  921. + * then add a new entry
  922. + * before we can hook up the value
  923. + */
  924. + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Value already in hash by collision for '%s' \n", __FUNCTION__, key);
  925. + while (hash_entry->next)
  926. + hash_entry = hash_entry->next;
  927. + hash_entry->next = (hash_entry_t *)malloc(sizeof(hash_entry_t));
  928. + if (!hash_entry->next) {
  929. + return -ENOMEM;
  930. + }
  931. + hash_entry = hash_entry->next;
  932. + hash_entry->next = NULL;
  933. + }
  934. + }
  935. + hash->n_elements++;
  936. + hash_entry->key = strdup(key);
  937. + hash_entry->data = value;
  938. +
  939. + return 0;
  940. +}
  941. +
  942. +
  943. +void hash_table_foreach(hash_table_t *hash, void (*f)(const char *key, void *entry, void *data), void *data)
  944. +{
  945. + int i;
  946. + if (!hash || !f)
  947. + return;
  948. +
  949. + for (i = 0; i < hash->n_entries; i++) {
  950. + hash_entry_t *hash_entry = (hash->entries + i);
  951. + do {
  952. + if(hash_entry->key) {
  953. + f(hash_entry->key, hash_entry->data, data);
  954. + }
  955. + } while((hash_entry = hash_entry->next));
  956. + }
  957. +}
  958. +
  959. diff -Nur busybox-1.16.1.orig/archival/libipkg/hash_table.h busybox-1.16.1/archival/libipkg/hash_table.h
  960. --- busybox-1.16.1.orig/archival/libipkg/hash_table.h 1970-01-01 01:00:00.000000000 +0100
  961. +++ busybox-1.16.1/archival/libipkg/hash_table.h 2010-04-22 19:18:12.000000000 +0200
  962. @@ -0,0 +1,44 @@
  963. +/* hash.h - hash tables for ipkg
  964. +
  965. + Steven M. Ayer, Jamey Hicks
  966. +
  967. + Copyright (C) 2002 Compaq Computer Corporation
  968. +
  969. + This program is free software; you can redistribute it and/or
  970. + modify it under the terms of the GNU General Public License as
  971. + published by the Free Software Foundation; either version 2, or (at
  972. + your option) any later version.
  973. +
  974. + This program is distributed in the hope that it will be useful, but
  975. + WITHOUT ANY WARRANTY; without even the implied warranty of
  976. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  977. + General Public License for more details.
  978. +*/
  979. +
  980. +#ifndef _HASH_TABLE_H_
  981. +#define _HASH_TABLE_H_
  982. +
  983. +typedef struct hash_entry hash_entry_t;
  984. +typedef struct hash_table hash_table_t;
  985. +
  986. +struct hash_entry {
  987. + const char * key;
  988. + void * data;
  989. + struct hash_entry * next;
  990. +};
  991. +
  992. +struct hash_table {
  993. + const char *name;
  994. + hash_entry_t * entries;
  995. + int n_entries; /* number of buckets */
  996. + int n_elements;
  997. + const char * (*hash_entry_key)(void * data);
  998. +};
  999. +
  1000. +int hash_table_init(const char *name, hash_table_t *hash, int len);
  1001. +void hash_table_deinit(hash_table_t *hash);
  1002. +void *hash_table_get(hash_table_t *hash, const char *key);
  1003. +int hash_table_insert(hash_table_t *hash, const char *key, void *value);
  1004. +void hash_table_foreach(hash_table_t *hash, void (*f)(const char *key, void *entry, void *data), void *data);
  1005. +
  1006. +#endif /* _HASH_TABLE_H_ */
  1007. diff -Nur busybox-1.16.1.orig/archival/libipkg/ipkg_cmd.c busybox-1.16.1/archival/libipkg/ipkg_cmd.c
  1008. --- busybox-1.16.1.orig/archival/libipkg/ipkg_cmd.c 1970-01-01 01:00:00.000000000 +0100
  1009. +++ busybox-1.16.1/archival/libipkg/ipkg_cmd.c 2010-04-22 19:18:12.000000000 +0200
  1010. @@ -0,0 +1,1386 @@
  1011. +/* ipkg_cmd.c - the itsy package management system
  1012. +
  1013. + Carl D. Worth
  1014. +
  1015. + Copyright (C) 2001 University of Southern California
  1016. +
  1017. + This program is free software; you can redistribute it and/or
  1018. + modify it under the terms of the GNU General Public License as
  1019. + published by the Free Software Foundation; either version 2, or (at
  1020. + your option) any later version.
  1021. +
  1022. + This program is distributed in the hope that it will be useful, but
  1023. + WITHOUT ANY WARRANTY; without even the implied warranty of
  1024. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  1025. + General Public License for more details.
  1026. +*/
  1027. +
  1028. +#include <string.h>
  1029. +
  1030. +#include "ipkg.h"
  1031. +#include <libgen.h>
  1032. +#include <glob.h>
  1033. +#include <errno.h>
  1034. +#include <stdlib.h>
  1035. +#include <unistd.h>
  1036. +#include <signal.h>
  1037. +#include <stdio.h>
  1038. +#include <dirent.h>
  1039. +
  1040. +#include "ipkg_conf.h"
  1041. +#include "ipkg_cmd.h"
  1042. +#include "ipkg_message.h"
  1043. +#include "pkg.h"
  1044. +#include "pkg_dest.h"
  1045. +#include "pkg_parse.h"
  1046. +#include "sprintf_alloc.h"
  1047. +#include "pkg.h"
  1048. +#include "file_util.h"
  1049. +#include "str_util.h"
  1050. +#include "unarchive.h"
  1051. +
  1052. +#include <fnmatch.h>
  1053. +
  1054. +
  1055. +#include "ipkg_download.h"
  1056. +#include "ipkg_install.h"
  1057. +#include "ipkg_upgrade.h"
  1058. +#include "ipkg_remove.h"
  1059. +#include "ipkg_configure.h"
  1060. +#include "ipkg_message.h"
  1061. +
  1062. +#include "libipkg.h"
  1063. +static void *p_userdata = NULL;
  1064. +
  1065. +static int ipkg_update_cmd(ipkg_conf_t *conf);
  1066. +static int ipkg_upgrade_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1067. +static int ipkg_list_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1068. +static int ipkg_info_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1069. +static int ipkg_status_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1070. +static int ipkg_install_pending_cmd(ipkg_conf_t *conf);
  1071. +static int ipkg_install_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1072. +static int ipkg_list_installed_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1073. +static int ipkg_remove_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1074. +static int ipkg_purge_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1075. +static int ipkg_flag_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1076. +static int ipkg_files_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1077. +static int ipkg_search_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1078. +static int ipkg_download_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1079. +static int ipkg_depends_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1080. +static int ipkg_whatdepends_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1081. +static int ipkg_whatdepends_recursively_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1082. +static int ipkg_whatsuggests_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1083. +static int ipkg_whatrecommends_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1084. +static int ipkg_whatprovides_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1085. +static int ipkg_whatconflicts_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1086. +static int ipkg_whatreplaces_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1087. +static int ipkg_compare_versions_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1088. +static int ipkg_print_architecture_cmd(ipkg_conf_t *conf);
  1089. +static int ipkg_configure_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1090. +
  1091. +/* XXX: CLEANUP: The usage strings should be incorporated into this
  1092. + array for easier maintenance */
  1093. +static ipkg_cmd_t cmds[] = {
  1094. + {"update", 0, (ipkg_cmd_fun_t)ipkg_update_cmd},
  1095. + {"upgrade", 0, (ipkg_cmd_fun_t)ipkg_upgrade_cmd},
  1096. + {"list", 0, (ipkg_cmd_fun_t)ipkg_list_cmd},
  1097. + {"list_installed", 0, (ipkg_cmd_fun_t)ipkg_list_installed_cmd},
  1098. + {"info", 0, (ipkg_cmd_fun_t)ipkg_info_cmd},
  1099. + {"flag", 1, (ipkg_cmd_fun_t)ipkg_flag_cmd},
  1100. + {"status", 0, (ipkg_cmd_fun_t)ipkg_status_cmd},
  1101. + {"install_pending", 0, (ipkg_cmd_fun_t)ipkg_install_pending_cmd},
  1102. + {"install", 1, (ipkg_cmd_fun_t)ipkg_install_cmd},
  1103. + {"remove", 1, (ipkg_cmd_fun_t)ipkg_remove_cmd},
  1104. + {"purge", 1, (ipkg_cmd_fun_t)ipkg_purge_cmd},
  1105. + {"configure", 0, (ipkg_cmd_fun_t)ipkg_configure_cmd},
  1106. + {"files", 1, (ipkg_cmd_fun_t)ipkg_files_cmd},
  1107. + {"search", 1, (ipkg_cmd_fun_t)ipkg_search_cmd},
  1108. + {"download", 1, (ipkg_cmd_fun_t)ipkg_download_cmd},
  1109. + {"compare_versions", 1, (ipkg_cmd_fun_t)ipkg_compare_versions_cmd},
  1110. + {"compare-versions", 1, (ipkg_cmd_fun_t)ipkg_compare_versions_cmd},
  1111. + {"print-architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
  1112. + {"print_architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
  1113. + {"print-installation-architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
  1114. + {"print_installation_architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
  1115. + {"depends", 1, (ipkg_cmd_fun_t)ipkg_depends_cmd},
  1116. + {"whatdepends", 1, (ipkg_cmd_fun_t)ipkg_whatdepends_cmd},
  1117. + {"whatdependsrec", 1, (ipkg_cmd_fun_t)ipkg_whatdepends_recursively_cmd},
  1118. + {"whatrecommends", 1, (ipkg_cmd_fun_t)ipkg_whatrecommends_cmd},
  1119. + {"whatsuggests", 1, (ipkg_cmd_fun_t)ipkg_whatsuggests_cmd},
  1120. + {"whatprovides", 1, (ipkg_cmd_fun_t)ipkg_whatprovides_cmd},
  1121. + {"whatreplaces", 1, (ipkg_cmd_fun_t)ipkg_whatreplaces_cmd},
  1122. + {"whatconflicts", 1, (ipkg_cmd_fun_t)ipkg_whatconflicts_cmd},
  1123. +};
  1124. +
  1125. +int ipkg_state_changed;
  1126. +static void write_status_files_if_changed(ipkg_conf_t *conf)
  1127. +{
  1128. + if (ipkg_state_changed && !conf->noaction) {
  1129. + ipkg_message(conf, IPKG_INFO,
  1130. + " writing status file\n");
  1131. + ipkg_conf_write_status_files(conf);
  1132. + pkg_write_changed_filelists(conf);
  1133. + } else {
  1134. + ipkg_message(conf, IPKG_NOTICE, "Nothing to be done\n");
  1135. + }
  1136. +}
  1137. +
  1138. +
  1139. +static int num_cmds = sizeof(cmds) / sizeof(ipkg_cmd_t);
  1140. +
  1141. +ipkg_cmd_t *ipkg_cmd_find(const char *name)
  1142. +{
  1143. + int i;
  1144. + ipkg_cmd_t *cmd;
  1145. +
  1146. + for (i=0; i < num_cmds; i++) {
  1147. + cmd = &cmds[i];
  1148. + if (strcmp(name, cmd->name) == 0) {
  1149. + return cmd;
  1150. + }
  1151. + }
  1152. +
  1153. + return NULL;
  1154. +}
  1155. +
  1156. +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc, const char **argv, void *userdata)
  1157. +{
  1158. + int result;
  1159. + p_userdata = userdata;
  1160. +
  1161. +
  1162. + result = (cmd->fun)(conf, argc, argv);
  1163. + if ( result == 0 ) {
  1164. + ipkg_message(conf, IPKG_NOTICE, "Done.\n");
  1165. + } else {
  1166. + ipkg_message(conf, IPKG_NOTICE, "An error ocurred, return value: %d.\n", result);
  1167. +
  1168. + }
  1169. + if ( error_list ) {
  1170. + reverse_error_list(&error_list);
  1171. +
  1172. + ipkg_message(conf, IPKG_NOTICE, "Collected errors:\n");
  1173. + /* Here we print the errors collected and free the list */
  1174. + while (error_list != NULL) {
  1175. + ipkg_message(conf, IPKG_NOTICE, "%s",error_list->errmsg);
  1176. + error_list = error_list->next;
  1177. +
  1178. + }
  1179. + free_error_list(&error_list);
  1180. +
  1181. + }
  1182. +
  1183. + p_userdata = NULL;
  1184. + return result;
  1185. +}
  1186. +
  1187. +static int ipkg_update_cmd(ipkg_conf_t *conf)
  1188. +{
  1189. + int err;
  1190. + int failures;
  1191. + char *lists_dir;
  1192. + pkg_src_list_elt_t *iter;
  1193. + pkg_src_t *src;
  1194. +
  1195. +
  1196. + sprintf_alloc(&lists_dir, "%s", conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir);
  1197. +
  1198. + if (! file_is_dir(lists_dir)) {
  1199. + if (file_exists(lists_dir)) {
  1200. + ipkg_message(conf, IPKG_ERROR,
  1201. + "%s: ERROR: %s exists, but is not a directory\n",
  1202. + __FUNCTION__, lists_dir);
  1203. + free(lists_dir);
  1204. + return EINVAL;
  1205. + }
  1206. + err = file_mkdir_hier(lists_dir, 0755);
  1207. + if (err) {
  1208. + ipkg_message(conf, IPKG_ERROR,
  1209. + "%s: ERROR: failed to make directory %s: %s\n",
  1210. + __FUNCTION__, lists_dir, strerror(errno));
  1211. + free(lists_dir);
  1212. + return EINVAL;
  1213. + }
  1214. + }
  1215. +
  1216. + failures = 0;
  1217. + for (iter = conf->pkg_src_list.head; iter; iter = iter->next) {
  1218. + char *url, *list_file_name;
  1219. +
  1220. + src = iter->data;
  1221. +
  1222. + if (src->extra_data) /* debian style? */
  1223. + sprintf_alloc(&url, "%s/%s/%s", src->value, src->extra_data,
  1224. + src->gzip ? "Packages.gz" : "Packages");
  1225. + else
  1226. + sprintf_alloc(&url, "%s/%s", src->value, src->gzip ? "Packages.gz" : "Packages");
  1227. +
  1228. + sprintf_alloc(&list_file_name, "%s/%s", lists_dir, src->name);
  1229. + if (src->gzip) {
  1230. + char *tmp;
  1231. + char *tmp_file_name;
  1232. + FILE *in, *out;
  1233. +
  1234. + tmp = strdup ("/tmp/ipkg.XXXXXX");
  1235. +
  1236. + if (mkdtemp (tmp) == NULL) {
  1237. + perror ("mkdtemp");
  1238. + failures++;
  1239. + continue;
  1240. + }
  1241. +
  1242. + sprintf_alloc (&tmp_file_name, "%s/%s.gz", tmp, src->name);
  1243. + err = ipkg_download(conf, url, tmp_file_name);
  1244. + if (err == 0) {
  1245. + ipkg_message (conf, IPKG_NOTICE, "Inflating %s\n", url);
  1246. + in = fopen (tmp_file_name, "r");
  1247. + out = fopen (list_file_name, "w");
  1248. + if (in && out) {
  1249. + inflate_unzip_result res;
  1250. + inflate_unzip (&res, 0x8000, fileno(in), fileno(out));
  1251. + } else
  1252. + err = 1;
  1253. + if (in)
  1254. + fclose (in);
  1255. + if (out)
  1256. + fclose (out);
  1257. + unlink (tmp_file_name);
  1258. + rmdir (tmp);
  1259. + free (tmp);
  1260. + }
  1261. + } else
  1262. + err = ipkg_download(conf, url, list_file_name);
  1263. + if (err) {
  1264. + failures++;
  1265. + } else {
  1266. + ipkg_message(conf, IPKG_NOTICE,
  1267. + "Updated list of available packages in %s\n",
  1268. + list_file_name);
  1269. + }
  1270. + free(url);
  1271. + free(list_file_name);
  1272. + }
  1273. + free(lists_dir);
  1274. +
  1275. +#ifdef CONFIG_CLEAR_SW_INSTALL_FLAG
  1276. +#warning here
  1277. + /* clear SW_INSTALL on any package where state is SS_NOT_INSTALLED.
  1278. + * this is a hack to work around poor bookkeeping in old ipkg upgrade code
  1279. + * -Jamey 3/1/03
  1280. + */
  1281. + {
  1282. + int i;
  1283. + int changed = 0;
  1284. + pkg_vec_t *available = pkg_vec_alloc();
  1285. + pkg_hash_fetch_available(&conf->pkg_hash, available);
  1286. + ipkg_message(conf, IPKG_DEBUG, "Clearing SW_INSTALL for SS_NOT_INSTALLED packages.\n");
  1287. + for (i = 0; i < available->len; i++) {
  1288. + pkg_t *pkg = available->pkgs[i];
  1289. + if (pkg->state_want == SW_INSTALL && pkg->state_status == SS_NOT_INSTALLED) {
  1290. + ipkg_message(conf, IPKG_DEBUG, "Clearing SW_INSTALL on package %s.\n", pkg->name);
  1291. + pkg->state_want = SW_UNKNOWN;
  1292. + changed = 1;
  1293. + }
  1294. + }
  1295. + pkg_vec_free(available);
  1296. + if (changed) {
  1297. + write_status_files_if_changed(conf);
  1298. + }
  1299. + }
  1300. +#endif
  1301. +
  1302. + return failures;
  1303. +}
  1304. +
  1305. +
  1306. +/* scan the args passed and cache the local filenames of the packages */
  1307. +int ipkg_multiple_files_scan(ipkg_conf_t *conf, int argc, char **argv)
  1308. +{
  1309. + int i;
  1310. + int err;
  1311. +
  1312. + /*
  1313. + * First scan through package names/urls
  1314. + * For any urls, download the packages and install in database.
  1315. + * For any files, install package info in database.
  1316. + */
  1317. + for (i = 0; i < argc; i ++) {
  1318. + char *filename = argv [i];
  1319. + //char *tmp = basename (tmp);
  1320. + //int tmplen = strlen (tmp);
  1321. +
  1322. + //if (strcmp (tmp + (tmplen - strlen (IPKG_PKG_EXTENSION)), IPKG_PKG_EXTENSION) != 0)
  1323. + // continue;
  1324. + //if (strcmp (tmp + (tmplen - strlen (DPKG_PKG_EXTENSION)), DPKG_PKG_EXTENSION) != 0)
  1325. + // continue;
  1326. +
  1327. + ipkg_message(conf, IPKG_DEBUG2, "Debug mfs: %s \n",filename );
  1328. +
  1329. + err = ipkg_prepare_url_for_install(conf, filename, &argv[i]);
  1330. + if (err)
  1331. + return err;
  1332. + }
  1333. + return 0;
  1334. +}
  1335. +
  1336. +struct ipkg_intercept
  1337. +{
  1338. + char *oldpath;
  1339. + char *statedir;
  1340. +};
  1341. +
  1342. +typedef struct ipkg_intercept *ipkg_intercept_t;
  1343. +ipkg_intercept_t ipkg_prep_intercepts(void);
  1344. +
  1345. +ipkg_intercept_t ipkg_prep_intercepts(void)
  1346. +{
  1347. + ipkg_intercept_t ctx;
  1348. + char *newpath;
  1349. + int gen;
  1350. +
  1351. + ctx = malloc (sizeof (*ctx));
  1352. + ctx->oldpath = strdup (getenv ("PATH"));
  1353. +
  1354. + sprintf_alloc (&newpath, "%s/ipkg/intercept:%s", IPKGLIBDIR, ctx->oldpath);
  1355. + setenv ("PATH", newpath, 1);
  1356. + free (newpath);
  1357. +
  1358. + gen = 0;
  1359. + retry:
  1360. + sprintf_alloc (&ctx->statedir, "/tmp/ipkg-intercept-%d-%d", getpid (), gen);
  1361. + if (mkdir (ctx->statedir, 0770) < 0) {
  1362. + if (errno == EEXIST) {
  1363. + free (ctx->statedir);
  1364. + gen++;
  1365. + goto retry;
  1366. + }
  1367. + perror (ctx->statedir);
  1368. + return NULL;
  1369. + }
  1370. + setenv ("IPKG_INTERCEPT_DIR", ctx->statedir, 1);
  1371. + return ctx;
  1372. +}
  1373. +
  1374. +int ipkg_finalize_intercepts(ipkg_intercept_t ctx);
  1375. +
  1376. +int ipkg_finalize_intercepts(ipkg_intercept_t ctx)
  1377. +{
  1378. + char *cmd;
  1379. + DIR *dir;
  1380. + int err = 0;
  1381. +
  1382. + setenv ("PATH", ctx->oldpath, 1);
  1383. + free (ctx->oldpath);
  1384. +
  1385. + dir = opendir (ctx->statedir);
  1386. + if (dir) {
  1387. + struct dirent *de;
  1388. + while (de = readdir (dir), de != NULL) {
  1389. + char *path;
  1390. +
  1391. + if (de->d_name[0] == '.')
  1392. + continue;
  1393. +
  1394. + sprintf_alloc (&path, "%s/%s", ctx->statedir, de->d_name);
  1395. + if (access (path, X_OK) == 0) {
  1396. + if (system (path)) {
  1397. + err = errno;
  1398. + perror (de->d_name);
  1399. + }
  1400. + }
  1401. + free (path);
  1402. + }
  1403. + } else
  1404. + perror (ctx->statedir);
  1405. +
  1406. + sprintf_alloc (&cmd, "rm -rf %s", ctx->statedir);
  1407. + system (cmd);
  1408. + free (cmd);
  1409. +
  1410. + free (ctx->statedir);
  1411. + free (ctx);
  1412. +
  1413. + return err;
  1414. +}
  1415. +
  1416. +int ipkg_configure_packages(ipkg_conf_t *conf, char *pkg_name)
  1417. +{
  1418. + pkg_vec_t *all;
  1419. + int i;
  1420. + pkg_t *pkg;
  1421. + ipkg_intercept_t ic;
  1422. + int r, err = 0;
  1423. +
  1424. + ipkg_message(conf, IPKG_INFO,
  1425. + "Configuring unpacked packages\n");
  1426. + fflush( stdout );
  1427. +
  1428. + all = pkg_vec_alloc();
  1429. + pkg_hash_fetch_available(&conf->pkg_hash, all);
  1430. +
  1431. + ic = ipkg_prep_intercepts();
  1432. +
  1433. + for(i = 0; i < all->len; i++) {
  1434. + pkg = all->pkgs[i];
  1435. +
  1436. + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
  1437. + continue;
  1438. +
  1439. + if (pkg->state_status == SS_UNPACKED) {
  1440. + ipkg_message(conf, IPKG_NOTICE,
  1441. + "Configuring %s\n", pkg->name);
  1442. + fflush( stdout );
  1443. + r = ipkg_configure(conf, pkg);
  1444. + if (r == 0) {
  1445. + pkg->state_status = SS_INSTALLED;
  1446. + pkg->parent->state_status = SS_INSTALLED;
  1447. + pkg->state_flag &= ~SF_PREFER;
  1448. + } else {
  1449. + if (!err)
  1450. + err = r;
  1451. + }
  1452. + }
  1453. + }
  1454. +
  1455. + r = ipkg_finalize_intercepts (ic);
  1456. + if (r && !err)
  1457. + err = r;
  1458. +
  1459. + pkg_vec_free(all);
  1460. + return err;
  1461. +}
  1462. +
  1463. +static void sigint_handler(int sig)
  1464. +{
  1465. + signal(sig, SIG_DFL);
  1466. + ipkg_message(NULL, IPKG_NOTICE,
  1467. + "ipkg: interrupted. writing out status database\n");
  1468. + write_status_files_if_changed(global_conf);
  1469. + exit(128 + sig);
  1470. +}
  1471. +
  1472. +static int ipkg_install_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1473. +{
  1474. + int i;
  1475. + char *arg;
  1476. + int err=0;
  1477. +
  1478. + global_conf = conf;
  1479. + signal(SIGINT, sigint_handler);
  1480. +
  1481. + /*
  1482. + * Now scan through package names and install
  1483. + */
  1484. + for (i=0; i < argc; i++) {
  1485. + arg = argv[i];
  1486. +
  1487. + ipkg_message(conf, IPKG_DEBUG2, "Debug install_cmd: %s \n",arg );
  1488. + err = ipkg_prepare_url_for_install(conf, arg, &argv[i]);
  1489. + if (err != EINVAL && err != 0)
  1490. + return err;
  1491. + }
  1492. + pkg_info_preinstall_check(conf);
  1493. +
  1494. + for (i=0; i < argc; i++) {
  1495. + arg = argv[i];
  1496. + if (conf->multiple_providers)
  1497. + err = ipkg_install_multi_by_name(conf, arg);
  1498. + else{
  1499. + err = ipkg_install_by_name(conf, arg);
  1500. + }
  1501. + if (err == IPKG_PKG_HAS_NO_CANDIDATE) {
  1502. + ipkg_message(conf, IPKG_ERROR,
  1503. + "Cannot find package %s.\n"
  1504. + "Check the spelling or perhaps run 'ipkg update'\n",
  1505. + arg);
  1506. + }
  1507. + }
  1508. +
  1509. + /* recheck to verify that all dependences are satisfied */
  1510. + if (0) ipkg_satisfy_all_dependences(conf);
  1511. +
  1512. + ipkg_configure_packages(conf, NULL);
  1513. +
  1514. + write_status_files_if_changed(conf);
  1515. +
  1516. + return err;
  1517. +}
  1518. +
  1519. +static int ipkg_upgrade_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1520. +{
  1521. + int i;
  1522. + pkg_t *pkg;
  1523. + int err;
  1524. +
  1525. + global_conf = conf;
  1526. + signal(SIGINT, sigint_handler);
  1527. +
  1528. + if (argc) {
  1529. + for (i=0; i < argc; i++) {
  1530. + char *arg = argv[i];
  1531. +
  1532. + err = ipkg_prepare_url_for_install(conf, arg, &arg);
  1533. + if (err != EINVAL && err != 0)
  1534. + return err;
  1535. + }
  1536. + pkg_info_preinstall_check(conf);
  1537. +
  1538. + for (i=0; i < argc; i++) {
  1539. + char *arg = argv[i];
  1540. + if (conf->restrict_to_default_dest) {
  1541. + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
  1542. + argv[i],
  1543. + conf->default_dest);
  1544. + if (pkg == NULL) {
  1545. + ipkg_message(conf, IPKG_NOTICE,
  1546. + "Package %s not installed in %s\n",
  1547. + argv[i], conf->default_dest->name);
  1548. + continue;
  1549. + }
  1550. + } else {
  1551. + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash,
  1552. + argv[i]);
  1553. + }
  1554. + if (pkg)
  1555. + ipkg_upgrade_pkg(conf, pkg);
  1556. + else {
  1557. + ipkg_install_by_name(conf, arg);
  1558. + }
  1559. + }
  1560. + } else {
  1561. + pkg_vec_t *installed = pkg_vec_alloc();
  1562. +
  1563. + pkg_info_preinstall_check(conf);
  1564. +
  1565. + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
  1566. + for (i = 0; i < installed->len; i++) {
  1567. + pkg = installed->pkgs[i];
  1568. + ipkg_upgrade_pkg(conf, pkg);
  1569. + }
  1570. + pkg_vec_free(installed);
  1571. + }
  1572. +
  1573. + /* recheck to verify that all dependences are satisfied */
  1574. + if (0) ipkg_satisfy_all_dependences(conf);
  1575. +
  1576. + ipkg_configure_packages(conf, NULL);
  1577. +
  1578. + write_status_files_if_changed(conf);
  1579. +
  1580. + return 0;
  1581. +}
  1582. +
  1583. +static int ipkg_download_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1584. +{
  1585. + int i, err;
  1586. + char *arg;
  1587. + pkg_t *pkg;
  1588. +
  1589. + pkg_info_preinstall_check(conf);
  1590. + for (i = 0; i < argc; i++) {
  1591. + arg = argv[i];
  1592. +
  1593. + pkg = pkg_hash_fetch_best_installation_candidate_by_name(conf, arg);
  1594. + if (pkg == NULL) {
  1595. + ipkg_message(conf, IPKG_ERROR,
  1596. + "Cannot find package %s.\n"
  1597. + "Check the spelling or perhaps run 'ipkg update'\n",
  1598. + arg);
  1599. + continue;
  1600. + }
  1601. +
  1602. + err = ipkg_download_pkg(conf, pkg, ".");
  1603. +
  1604. + if (err) {
  1605. + ipkg_message(conf, IPKG_ERROR,
  1606. + "Failed to download %s\n", pkg->name);
  1607. + } else {
  1608. + ipkg_message(conf, IPKG_NOTICE,
  1609. + "Downloaded %s as %s\n",
  1610. + pkg->name, pkg->local_filename);
  1611. + }
  1612. + }
  1613. +
  1614. + return 0;
  1615. +}
  1616. +
  1617. +
  1618. +static int ipkg_list_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1619. +{
  1620. + int i ;
  1621. + pkg_vec_t *available;
  1622. + pkg_t *pkg;
  1623. + char desc_short[IPKG_LIST_DESCRIPTION_LENGTH];
  1624. + char *newline;
  1625. + char *pkg_name = NULL;
  1626. + char *version_str;
  1627. +
  1628. + if (argc > 0) {
  1629. + pkg_name = argv[0];
  1630. + }
  1631. + available = pkg_vec_alloc();
  1632. + pkg_hash_fetch_available(&conf->pkg_hash, available);
  1633. + for (i=0; i < available->len; i++) {
  1634. + pkg = available->pkgs[i];
  1635. + /* if we have package name or pattern and pkg does not match, then skip it */
  1636. + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
  1637. + continue;
  1638. + if (pkg->description) {
  1639. + strncpy(desc_short, pkg->description, IPKG_LIST_DESCRIPTION_LENGTH);
  1640. + } else {
  1641. + desc_short[0] = '\0';
  1642. + }
  1643. + desc_short[IPKG_LIST_DESCRIPTION_LENGTH - 1] = '\0';
  1644. + newline = strchr(desc_short, '\n');
  1645. + if (newline) {
  1646. + *newline = '\0';
  1647. + }
  1648. + if (ipkg_cb_list) {
  1649. + version_str = pkg_version_str_alloc(pkg);
  1650. + ipkg_cb_list(pkg->name,desc_short,
  1651. + version_str,
  1652. + pkg->state_status,
  1653. + p_userdata);
  1654. + free(version_str);
  1655. + }
  1656. + }
  1657. + pkg_vec_free(available);
  1658. +
  1659. + return 0;
  1660. +}
  1661. +
  1662. +
  1663. +static int ipkg_list_installed_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1664. +{
  1665. + int i ;
  1666. + pkg_vec_t *available;
  1667. + pkg_t *pkg;
  1668. + char desc_short[IPKG_LIST_DESCRIPTION_LENGTH];
  1669. + char *newline;
  1670. + char *pkg_name = NULL;
  1671. + char *version_str;
  1672. +
  1673. + if (argc > 0) {
  1674. + pkg_name = argv[0];
  1675. + }
  1676. + available = pkg_vec_alloc();
  1677. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
  1678. + for (i=0; i < available->len; i++) {
  1679. + pkg = available->pkgs[i];
  1680. + /* if we have package name or pattern and pkg does not match, then skip it */
  1681. + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
  1682. + continue;
  1683. + if (pkg->description) {
  1684. + strncpy(desc_short, pkg->description, IPKG_LIST_DESCRIPTION_LENGTH);
  1685. + } else {
  1686. + desc_short[0] = '\0';
  1687. + }
  1688. + desc_short[IPKG_LIST_DESCRIPTION_LENGTH - 1] = '\0';
  1689. + newline = strchr(desc_short, '\n');
  1690. + if (newline) {
  1691. + *newline = '\0';
  1692. + }
  1693. + if (ipkg_cb_list) {
  1694. + version_str = pkg_version_str_alloc(pkg);
  1695. + ipkg_cb_list(pkg->name,desc_short,
  1696. + version_str,
  1697. + pkg->state_status,
  1698. + p_userdata);
  1699. + free(version_str);
  1700. + }
  1701. + }
  1702. +
  1703. + return 0;
  1704. +}
  1705. +
  1706. +static int ipkg_info_status_cmd(ipkg_conf_t *conf, int argc, char **argv, int installed_only)
  1707. +{
  1708. + int i;
  1709. + pkg_vec_t *available;
  1710. + pkg_t *pkg;
  1711. + char *pkg_name = NULL;
  1712. + char **pkg_fields = NULL;
  1713. + int n_fields = 0;
  1714. + char *buff ; // = (char *)malloc(1);
  1715. +
  1716. + if (argc > 0) {
  1717. + pkg_name = argv[0];
  1718. + }
  1719. + if (argc > 1) {
  1720. + pkg_fields = &argv[1];
  1721. + n_fields = argc - 1;
  1722. + }
  1723. +
  1724. + available = pkg_vec_alloc();
  1725. + if (installed_only)
  1726. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
  1727. + else
  1728. + pkg_hash_fetch_available(&conf->pkg_hash, available);
  1729. + for (i=0; i < available->len; i++) {
  1730. + pkg = available->pkgs[i];
  1731. + if (pkg_name && fnmatch(pkg_name, pkg->name, 0)) {
  1732. + continue;
  1733. + }
  1734. + buff = pkg_formatted_info(pkg);
  1735. + if ( buff ) {
  1736. + if (ipkg_cb_status) ipkg_cb_status(pkg->name,
  1737. + pkg->state_status,
  1738. + buff,
  1739. + p_userdata);
  1740. + free(buff);
  1741. + }
  1742. + if (conf->verbosity > 1) {
  1743. + conffile_list_elt_t *iter;
  1744. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  1745. + conffile_t *cf = iter->data;
  1746. + int modified = conffile_has_been_modified(conf, cf);
  1747. + ipkg_message(conf, IPKG_NOTICE, "conffile=%s md5sum=%s modified=%d\n",
  1748. + cf->name, cf->value, modified);
  1749. + }
  1750. + }
  1751. + }
  1752. + pkg_vec_free(available);
  1753. +
  1754. + return 0;
  1755. +}
  1756. +
  1757. +static int ipkg_info_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1758. +{
  1759. + return ipkg_info_status_cmd(conf, argc, argv, 0);
  1760. +}
  1761. +
  1762. +static int ipkg_status_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1763. +{
  1764. + return ipkg_info_status_cmd(conf, argc, argv, 1);
  1765. +}
  1766. +
  1767. +static int ipkg_configure_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1768. +{
  1769. +
  1770. + int err;
  1771. + if (argc > 0) {
  1772. + char *pkg_name = NULL;
  1773. +
  1774. + pkg_name = argv[0];
  1775. +
  1776. + err = ipkg_configure_packages (conf, pkg_name);
  1777. +
  1778. + } else {
  1779. + err = ipkg_configure_packages (conf, NULL);
  1780. + }
  1781. +
  1782. + write_status_files_if_changed(conf);
  1783. +
  1784. + return err;
  1785. +}
  1786. +
  1787. +static int ipkg_install_pending_cmd(ipkg_conf_t *conf)
  1788. +{
  1789. + int i, err;
  1790. + char *globpattern;
  1791. + glob_t globbuf;
  1792. +
  1793. + sprintf_alloc(&globpattern, "%s/*" IPKG_PKG_EXTENSION, conf->pending_dir);
  1794. + err = glob(globpattern, 0, NULL, &globbuf);
  1795. + free(globpattern);
  1796. + if (err) {
  1797. + return 0;
  1798. + }
  1799. +
  1800. + ipkg_message(conf, IPKG_NOTICE,
  1801. + "The following packages in %s will now be installed.\n",
  1802. + conf->pending_dir);
  1803. + for (i = 0; i < globbuf.gl_pathc; i++) {
  1804. + ipkg_message(conf, IPKG_NOTICE,
  1805. + "%s%s", i == 0 ? "" : " ", globbuf.gl_pathv[i]);
  1806. + }
  1807. + ipkg_message(conf, IPKG_NOTICE, "\n");
  1808. + for (i = 0; i < globbuf.gl_pathc; i++) {
  1809. + err = ipkg_install_from_file(conf, globbuf.gl_pathv[i]);
  1810. + if (err == 0) {
  1811. + err = unlink(globbuf.gl_pathv[i]);
  1812. + if (err) {
  1813. + ipkg_message(conf, IPKG_ERROR,
  1814. + "%s: ERROR: failed to unlink %s: %s\n",
  1815. + __FUNCTION__, globbuf.gl_pathv[i], strerror(err));
  1816. + return err;
  1817. + }
  1818. + }
  1819. + }
  1820. + globfree(&globbuf);
  1821. +
  1822. + return err;
  1823. +}
  1824. +
  1825. +static int ipkg_remove_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1826. +{
  1827. + int i,a,done;
  1828. + pkg_t *pkg;
  1829. + pkg_t *pkg_to_remove;
  1830. + pkg_vec_t *available;
  1831. + char *pkg_name = NULL;
  1832. + global_conf = conf;
  1833. + signal(SIGINT, sigint_handler);
  1834. +
  1835. +// ENH: Add the "no pkg removed" just in case.
  1836. +
  1837. + done = 0;
  1838. +
  1839. + available = pkg_vec_alloc();
  1840. + pkg_info_preinstall_check(conf);
  1841. + if ( argc > 0 ) {
  1842. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
  1843. + for (i=0; i < argc; i++) {
  1844. + pkg_name = malloc(strlen(argv[i])+2);
  1845. + strcpy(pkg_name,argv[i]);
  1846. + for (a=0; a < available->len; a++) {
  1847. + pkg = available->pkgs[a];
  1848. + if (pkg_name && fnmatch(pkg_name, pkg->name, 0)) {
  1849. + continue;
  1850. + }
  1851. + if (conf->restrict_to_default_dest) {
  1852. + pkg_to_remove = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
  1853. + pkg->name,
  1854. + conf->default_dest);
  1855. + } else {
  1856. + pkg_to_remove = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name );
  1857. + }
  1858. +
  1859. + if (pkg == NULL) {
  1860. + ipkg_message(conf, IPKG_ERROR, "Package %s is not installed.\n", pkg->name);
  1861. + continue;
  1862. + }
  1863. + if (pkg->state_status == SS_NOT_INSTALLED) { // Added the control, so every already removed package could be skipped
  1864. + ipkg_message(conf, IPKG_ERROR, "Package seems to be %s not installed (STATUS = NOT_INSTALLED).\n", pkg->name);
  1865. + continue;
  1866. + }
  1867. + ipkg_remove_pkg(conf, pkg_to_remove,0);
  1868. + done = 1;
  1869. + }
  1870. + free (pkg_name);
  1871. + }
  1872. + pkg_vec_free(available);
  1873. + } else {
  1874. + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
  1875. + int flagged_pkg_count = 0;
  1876. + int removed;
  1877. +
  1878. + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed_pkgs);
  1879. +
  1880. + for (i = 0; i < installed_pkgs->len; i++) {
  1881. + pkg = installed_pkgs->pkgs[i];
  1882. + if (pkg->state_flag & SF_USER) {
  1883. + flagged_pkg_count++;
  1884. + } else {
  1885. + if (!pkg_has_installed_dependents(pkg, NULL))
  1886. + ipkg_message(conf, IPKG_NOTICE, "Non-user leaf package: %s\n", pkg->name);
  1887. + }
  1888. + }
  1889. + if (!flagged_pkg_count) {
  1890. + ipkg_message(conf, IPKG_NOTICE, "No packages flagged as installed by user, \n"
  1891. + "so refusing to uninstall unflagged non-leaf packages\n");
  1892. + return 0;
  1893. + }
  1894. +
  1895. + /* find packages not flagged SF_USER (i.e., installed to
  1896. + * satisfy a dependence) and not having any dependents, and
  1897. + * remove them */
  1898. + do {
  1899. + removed = 0;
  1900. + for (i = 0; i < installed_pkgs->len; i++) {
  1901. + pkg = installed_pkgs->pkgs[i];
  1902. + if (!(pkg->state_flag & SF_USER)
  1903. + && !pkg_has_installed_dependents(pkg, NULL)) {
  1904. + removed++;
  1905. + ipkg_message(conf, IPKG_NOTICE, "Removing non-user leaf package %s\n");
  1906. + ipkg_remove_pkg(conf, pkg,0);
  1907. + done = 1;
  1908. + }
  1909. + }
  1910. + } while (removed);
  1911. + pkg_vec_free(installed_pkgs);
  1912. + }
  1913. +
  1914. + if ( done == 0 )
  1915. + ipkg_message(conf, IPKG_NOTICE, "No packages removed.\n");
  1916. +
  1917. + write_status_files_if_changed(conf);
  1918. + return 0;
  1919. +}
  1920. +
  1921. +static int ipkg_purge_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1922. +{
  1923. + int i;
  1924. + pkg_t *pkg;
  1925. +
  1926. + global_conf = conf;
  1927. + signal(SIGINT, sigint_handler);
  1928. +
  1929. + pkg_info_preinstall_check(conf);
  1930. +
  1931. + for (i=0; i < argc; i++) {
  1932. + if (conf->restrict_to_default_dest) {
  1933. + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
  1934. + argv[i],
  1935. + conf->default_dest);
  1936. + } else {
  1937. + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, argv[i]);
  1938. + }
  1939. +
  1940. + if (pkg == NULL) {
  1941. + ipkg_message(conf, IPKG_ERROR,
  1942. + "Package %s is not installed.\n", argv[i]);
  1943. + continue;
  1944. + }
  1945. + ipkg_purge_pkg(conf, pkg);
  1946. + }
  1947. +
  1948. + write_status_files_if_changed(conf);
  1949. + return 0;
  1950. +}
  1951. +
  1952. +static int ipkg_flag_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1953. +{
  1954. + int i;
  1955. + pkg_t *pkg;
  1956. + char *flags = argv[0];
  1957. +
  1958. + global_conf = conf;
  1959. + signal(SIGINT, sigint_handler);
  1960. +
  1961. + for (i=1; i < argc; i++) {
  1962. + if (conf->restrict_to_default_dest) {
  1963. + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
  1964. + argv[i],
  1965. + conf->default_dest);
  1966. + } else {
  1967. + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, argv[i]);
  1968. + }
  1969. +
  1970. + if (pkg == NULL) {
  1971. + ipkg_message(conf, IPKG_ERROR,
  1972. + "Package %s is not installed.\n", argv[i]);
  1973. + continue;
  1974. + }
  1975. + if (( strcmp(flags,"hold")==0)||( strcmp(flags,"noprune")==0)||
  1976. + ( strcmp(flags,"user")==0)||( strcmp(flags,"ok")==0)) {
  1977. + pkg->state_flag = pkg_state_flag_from_str(flags);
  1978. + }
  1979. +/* pb_ asked this feature 03292004 */
  1980. +/* Actually I will use only this two, but this is an open for various status */
  1981. + if (( strcmp(flags,"installed")==0)||( strcmp(flags,"unpacked")==0)){
  1982. + pkg->state_status = pkg_state_status_from_str(flags);
  1983. + }
  1984. + ipkg_state_changed++;
  1985. + ipkg_message(conf, IPKG_NOTICE,
  1986. + "Setting flags for package %s to %s\n",
  1987. + pkg->name, flags);
  1988. + }
  1989. +
  1990. + write_status_files_if_changed(conf);
  1991. + return 0;
  1992. +}
  1993. +
  1994. +static int ipkg_files_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1995. +{
  1996. + pkg_t *pkg;
  1997. + str_list_t *installed_files;
  1998. + str_list_elt_t *iter;
  1999. + char *pkg_version;
  2000. + size_t buff_len = 8192;
  2001. + size_t used_len;
  2002. + char *buff ;
  2003. +
  2004. + buff = (char *)malloc(buff_len);
  2005. + if ( buff == NULL ) {
  2006. + fprintf( stderr,"%s: Unable to allocate memory \n",__FUNCTION__);
  2007. + return ENOMEM;
  2008. + }
  2009. +
  2010. + if (argc < 1) {
  2011. + return EINVAL;
  2012. + }
  2013. +
  2014. + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash,
  2015. + argv[0]);
  2016. + if (pkg == NULL) {
  2017. + ipkg_message(conf, IPKG_ERROR,
  2018. + "Package %s not installed.\n", argv[0]);
  2019. + return 0;
  2020. + }
  2021. +
  2022. + installed_files = pkg_get_installed_files(pkg);
  2023. + pkg_version = pkg_version_str_alloc(pkg);
  2024. +
  2025. + if (buff) {
  2026. + try_again:
  2027. + used_len = snprintf(buff, buff_len, "Package %s (%s) is installed on %s and has the following files:\n",
  2028. + pkg->name, pkg_version, pkg->dest->name) + 1;
  2029. + if (used_len > buff_len) {
  2030. + buff_len *= 2;
  2031. + buff = realloc (buff, buff_len);
  2032. + goto try_again;
  2033. + }
  2034. + for (iter = installed_files->head; iter; iter = iter->next) {
  2035. + used_len += strlen (iter->data) + 1;
  2036. + while (buff_len <= used_len) {
  2037. + buff_len *= 2;
  2038. + buff = realloc (buff, buff_len);
  2039. + }
  2040. + strncat(buff, iter->data, buff_len);
  2041. + strncat(buff, "\n", buff_len);
  2042. + }
  2043. + if (ipkg_cb_list) ipkg_cb_list(pkg->name,
  2044. + buff,
  2045. + pkg_version_str_alloc(pkg),
  2046. + pkg->state_status,
  2047. + p_userdata);
  2048. + free(buff);
  2049. + }
  2050. +
  2051. + free(pkg_version);
  2052. + pkg_free_installed_files(pkg);
  2053. +
  2054. + return 0;
  2055. +}
  2056. +
  2057. +static int ipkg_depends_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2058. +{
  2059. +
  2060. + if (argc > 0) {
  2061. + pkg_vec_t *available_pkgs = pkg_vec_alloc();
  2062. + const char *rel_str = "depends on";
  2063. + int i;
  2064. +
  2065. + pkg_info_preinstall_check(conf);
  2066. +
  2067. + if (conf->query_all)
  2068. + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
  2069. + else
  2070. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
  2071. + for (i = 0; i < argc; i++) {
  2072. + const char *target = argv[i];
  2073. + int j;
  2074. +
  2075. + ipkg_message(conf, IPKG_ERROR, "target=%s\n", target);
  2076. +
  2077. + for (j = 0; j < available_pkgs->len; j++) {
  2078. + pkg_t *pkg = available_pkgs->pkgs[j];
  2079. + if (fnmatch(target, pkg->name, 0) == 0) {
  2080. + int k;
  2081. + int count = pkg->depends_count + pkg->pre_depends_count;
  2082. + ipkg_message(conf, IPKG_ERROR, "What %s (arch=%s) %s\n",
  2083. + target, pkg->architecture, rel_str);
  2084. + for (k = 0; k < count; k++) {
  2085. + compound_depend_t *cdepend = &pkg->depends[k];
  2086. + int l;
  2087. + for (l = 0; l < cdepend->possibility_count; l++) {
  2088. + depend_t *possibility = cdepend->possibilities[l];
  2089. + ipkg_message(conf, IPKG_ERROR, " %s", possibility->pkg->name);
  2090. + if (conf->verbosity > 0) {
  2091. + // char *ver = abstract_pkg_version_str_alloc(possibility->pkg);
  2092. + ipkg_message(conf, IPKG_NOTICE, " %s", possibility->version);
  2093. + if (possibility->version) {
  2094. + const char *typestr = NULL;
  2095. + switch (possibility->constraint) {
  2096. + case NONE: typestr = "none"; break;
  2097. + case EARLIER: typestr = "<"; break;
  2098. + case EARLIER_EQUAL: typestr = "<="; break;
  2099. + case EQUAL: typestr = "="; break;
  2100. + case LATER_EQUAL: typestr = ">="; break;
  2101. + case LATER: typestr = ">"; break;
  2102. + }
  2103. + ipkg_message(conf, IPKG_NOTICE, " (%s %s)", typestr, possibility->version);
  2104. + }
  2105. + // free(ver);
  2106. + }
  2107. + ipkg_message(conf, IPKG_ERROR, "\n");
  2108. + }
  2109. + }
  2110. + }
  2111. + }
  2112. + }
  2113. + pkg_vec_free(available_pkgs);
  2114. + }
  2115. + return 0;
  2116. +}
  2117. +
  2118. +enum what_field_type {
  2119. + WHATDEPENDS,
  2120. + WHATCONFLICTS,
  2121. + WHATPROVIDES,
  2122. + WHATREPLACES,
  2123. + WHATRECOMMENDS,
  2124. + WHATSUGGESTS
  2125. +};
  2126. +
  2127. +static int ipkg_what_depends_conflicts_cmd(ipkg_conf_t *conf, enum what_field_type what_field_type, int recursive, int argc, char **argv)
  2128. +{
  2129. +
  2130. + if (argc > 0) {
  2131. + pkg_vec_t *available_pkgs = pkg_vec_alloc();
  2132. + const char *rel_str = NULL;
  2133. + int i;
  2134. + int changed;
  2135. +
  2136. + switch (what_field_type) {
  2137. + case WHATDEPENDS: rel_str = "depends on"; break;
  2138. + case WHATCONFLICTS: rel_str = "conflicts with"; break;
  2139. + case WHATSUGGESTS: rel_str = "suggests"; break;
  2140. + case WHATRECOMMENDS: rel_str = "recommends"; break;
  2141. + case WHATPROVIDES: rel_str = "provides"; break;
  2142. + case WHATREPLACES: rel_str = "replaces"; break;
  2143. + }
  2144. +
  2145. + if (conf->query_all)
  2146. + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
  2147. + else
  2148. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
  2149. +
  2150. + /* mark the root set */
  2151. + pkg_vec_clear_marks(available_pkgs);
  2152. + ipkg_message(conf, IPKG_NOTICE, "Root set:\n");
  2153. + for (i = 0; i < argc; i++) {
  2154. + const char *dependee_pattern = argv[i];
  2155. + pkg_vec_mark_if_matches(available_pkgs, dependee_pattern);
  2156. + }
  2157. + for (i = 0; i < available_pkgs->len; i++) {
  2158. + pkg_t *pkg = available_pkgs->pkgs[i];
  2159. + if (pkg->state_flag & SF_MARKED) {
  2160. + /* mark the parent (abstract) package */
  2161. + pkg_mark_provides(pkg);
  2162. + ipkg_message(conf, IPKG_NOTICE, " %s\n", pkg->name);
  2163. + }
  2164. + }
  2165. +
  2166. + ipkg_message(conf, IPKG_NOTICE, "What %s root set\n", rel_str);
  2167. + do {
  2168. + int j;
  2169. + changed = 0;
  2170. +
  2171. + for (j = 0; j < available_pkgs->len; j++) {
  2172. + pkg_t *pkg = available_pkgs->pkgs[j];
  2173. + int k;
  2174. + int count = ((what_field_type == WHATCONFLICTS)
  2175. + ? pkg->conflicts_count
  2176. + : pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count);
  2177. + /* skip this package if it is already marked */
  2178. + if (pkg->parent->state_flag & SF_MARKED) {
  2179. + continue;
  2180. + }
  2181. + for (k = 0; k < count; k++) {
  2182. + compound_depend_t *cdepend =
  2183. + (what_field_type == WHATCONFLICTS) ? &pkg->conflicts[k] : &pkg->depends[k];
  2184. + int l;
  2185. + for (l = 0; l < cdepend->possibility_count; l++) {
  2186. + depend_t *possibility = cdepend->possibilities[l];
  2187. + if (possibility->pkg->state_flag & SF_MARKED) {
  2188. + /* mark the depending package so we won't visit it again */
  2189. + pkg->state_flag |= SF_MARKED;
  2190. + pkg_mark_provides(pkg);
  2191. + changed++;
  2192. +
  2193. + ipkg_message(conf, IPKG_NOTICE, " %s", pkg->name);
  2194. + if (conf->verbosity > 0) {
  2195. + char *ver = pkg_version_str_alloc(pkg);
  2196. + ipkg_message(conf, IPKG_NOTICE, " %s", ver);
  2197. + ipkg_message(conf, IPKG_NOTICE, "\t%s %s", rel_str, possibility->pkg->name);
  2198. + if (possibility->version) {
  2199. + const char *typestr = NULL;
  2200. + switch (possibility->constraint) {
  2201. + case NONE: typestr = "none"; break;
  2202. + case EARLIER: typestr = "<"; break;
  2203. + case EARLIER_EQUAL: typestr = "<="; break;
  2204. + case EQUAL: typestr = "="; break;
  2205. + case LATER_EQUAL: typestr = ">="; break;
  2206. + case LATER: typestr = ">"; break;
  2207. + }
  2208. + ipkg_message(conf, IPKG_NOTICE, " (%s %s)", typestr, possibility->version);
  2209. + }
  2210. + free(ver);
  2211. + if (!pkg_dependence_satisfiable(possibility))
  2212. + ipkg_message(conf, IPKG_NOTICE, " unsatisfiable");
  2213. + }
  2214. + ipkg_message(conf, IPKG_NOTICE, "\n");
  2215. + goto next_package;
  2216. + }
  2217. + }
  2218. + }
  2219. + next_package:
  2220. + ;
  2221. + }
  2222. + } while (changed && recursive);
  2223. + pkg_vec_free(available_pkgs);
  2224. + }
  2225. +
  2226. + return 0;
  2227. +}
  2228. +
  2229. +int pkg_mark_provides(pkg_t *pkg)
  2230. +{
  2231. + int provides_count = pkg->provides_count;
  2232. + abstract_pkg_t **provides = pkg->provides;
  2233. + int i;
  2234. + pkg->parent->state_flag |= SF_MARKED;
  2235. + for (i = 0; i < provides_count; i++) {
  2236. + provides[i]->state_flag |= SF_MARKED;
  2237. + }
  2238. + return 0;
  2239. +}
  2240. +
  2241. +static int ipkg_whatdepends_recursively_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2242. +{
  2243. + return ipkg_what_depends_conflicts_cmd(conf, WHATDEPENDS, 1, argc, argv);
  2244. +}
  2245. +static int ipkg_whatdepends_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2246. +{
  2247. + return ipkg_what_depends_conflicts_cmd(conf, WHATDEPENDS, 0, argc, argv);
  2248. +}
  2249. +
  2250. +static int ipkg_whatsuggests_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2251. +{
  2252. + return ipkg_what_depends_conflicts_cmd(conf, WHATSUGGESTS, 0, argc, argv);
  2253. +}
  2254. +
  2255. +static int ipkg_whatrecommends_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2256. +{
  2257. + return ipkg_what_depends_conflicts_cmd(conf, WHATRECOMMENDS, 0, argc, argv);
  2258. +}
  2259. +
  2260. +static int ipkg_whatconflicts_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2261. +{
  2262. + return ipkg_what_depends_conflicts_cmd(conf, WHATCONFLICTS, 0, argc, argv);
  2263. +}
  2264. +
  2265. +static int ipkg_what_provides_replaces_cmd(ipkg_conf_t *conf, enum what_field_type what_field_type, int argc, char **argv)
  2266. +{
  2267. +
  2268. + if (argc > 0) {
  2269. + pkg_vec_t *available_pkgs = pkg_vec_alloc();
  2270. + const char *rel_str = (what_field_type == WHATPROVIDES ? "provides" : "replaces");
  2271. + int i;
  2272. +
  2273. + pkg_info_preinstall_check(conf);
  2274. +
  2275. + if (conf->query_all)
  2276. + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
  2277. + else
  2278. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
  2279. + for (i = 0; i < argc; i++) {
  2280. + const char *target = argv[i];
  2281. + int j;
  2282. +
  2283. + ipkg_message(conf, IPKG_ERROR, "What %s %s\n",
  2284. + rel_str, target);
  2285. + for (j = 0; j < available_pkgs->len; j++) {
  2286. + pkg_t *pkg = available_pkgs->pkgs[j];
  2287. + int k;
  2288. + int count = (what_field_type == WHATPROVIDES) ? pkg->provides_count : pkg->replaces_count;
  2289. + for (k = 0; k < count; k++) {
  2290. + abstract_pkg_t *apkg =
  2291. + ((what_field_type == WHATPROVIDES)
  2292. + ? pkg->provides[k]
  2293. + : pkg->replaces[k]);
  2294. + if (fnmatch(target, apkg->name, 0) == 0) {
  2295. + ipkg_message(conf, IPKG_ERROR, " %s", pkg->name);
  2296. + if (strcmp(target, apkg->name) != 0)
  2297. + ipkg_message(conf, IPKG_ERROR, "\t%s %s\n", rel_str, apkg->name);
  2298. + ipkg_message(conf, IPKG_ERROR, "\n");
  2299. + }
  2300. + }
  2301. + }
  2302. + }
  2303. + pkg_vec_free(available_pkgs);
  2304. + }
  2305. + return 0;
  2306. +}
  2307. +
  2308. +static int ipkg_whatprovides_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2309. +{
  2310. + return ipkg_what_provides_replaces_cmd(conf, WHATPROVIDES, argc, argv);
  2311. +}
  2312. +
  2313. +static int ipkg_whatreplaces_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2314. +{
  2315. + return ipkg_what_provides_replaces_cmd(conf, WHATREPLACES, argc, argv);
  2316. +}
  2317. +
  2318. +static int ipkg_search_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2319. +{
  2320. + int i;
  2321. +
  2322. + pkg_vec_t *installed;
  2323. + pkg_t *pkg;
  2324. + str_list_t *installed_files;
  2325. + str_list_elt_t *iter;
  2326. + char *installed_file;
  2327. +
  2328. + if (argc < 1) {
  2329. + return EINVAL;
  2330. + }
  2331. +
  2332. + installed = pkg_vec_alloc();
  2333. + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
  2334. +
  2335. + for (i=0; i < installed->len; i++) {
  2336. + pkg = installed->pkgs[i];
  2337. +
  2338. + installed_files = pkg_get_installed_files(pkg);
  2339. +
  2340. + for (iter = installed_files->head; iter; iter = iter->next) {
  2341. + installed_file = iter->data;
  2342. + if (fnmatch(argv[0], installed_file, 0)==0) {
  2343. + if (ipkg_cb_list) ipkg_cb_list(pkg->name,
  2344. + installed_file,
  2345. + pkg_version_str_alloc(pkg),
  2346. + pkg->state_status, p_userdata);
  2347. + }
  2348. + }
  2349. +
  2350. + pkg_free_installed_files(pkg);
  2351. + }
  2352. +
  2353. + /* XXX: CLEANUP: It's not obvious from the name of
  2354. + pkg_hash_fetch_all_installed that we need to call
  2355. + pkg_vec_free to avoid a memory leak. */
  2356. + pkg_vec_free(installed);
  2357. +
  2358. + return 0;
  2359. +}
  2360. +
  2361. +static int ipkg_compare_versions_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2362. +{
  2363. + if (argc == 3) {
  2364. + /* this is a bit gross */
  2365. + struct pkg p1, p2;
  2366. + parseVersion(&p1, argv[0]);
  2367. + parseVersion(&p2, argv[2]);
  2368. + return pkg_version_satisfied(&p1, &p2, argv[1]);
  2369. + } else {
  2370. + ipkg_message(conf, IPKG_ERROR,
  2371. + "ipkg compare_versions <v1> <op> <v2>\n"
  2372. + "<op> is one of <= >= << >> =\n");
  2373. + return -1;
  2374. + }
  2375. +}
  2376. +
  2377. +#ifndef HOST_CPU_STR
  2378. +#define HOST_CPU_STR__(X) #X
  2379. +#define HOST_CPU_STR_(X) HOST_CPU_STR__(X)
  2380. +#define HOST_CPU_STR HOST_CPU_STR_(HOST_CPU_FOO)
  2381. +#endif
  2382. +
  2383. +static int ipkg_print_architecture_cmd(ipkg_conf_t *conf)
  2384. +{
  2385. + nv_pair_list_elt_t *l;
  2386. +
  2387. + l = conf->arch_list.head;
  2388. + while (l) {
  2389. + nv_pair_t *nv = l->data;
  2390. + printf("arch %s %s\n", nv->name, nv->value);
  2391. + l = l->next;
  2392. + }
  2393. + return 0;
  2394. +}
  2395. +
  2396. +
  2397. diff -Nur busybox-1.16.1.orig/archival/libipkg/ipkg_cmd.h busybox-1.16.1/archival/libipkg/ipkg_cmd.h
  2398. --- busybox-1.16.1.orig/archival/libipkg/ipkg_cmd.h 1970-01-01 01:00:00.000000000 +0100
  2399. +++ busybox-1.16.1/archival/libipkg/ipkg_cmd.h 2010-04-22 19:18:12.000000000 +0200
  2400. @@ -0,0 +1,41 @@
  2401. +/* ipkg_cmd.h - the itsy package management system
  2402. +
  2403. + Carl D. Worth
  2404. +
  2405. + Copyright (C) 2001 University of Southern California
  2406. +
  2407. + This program is free software; you can redistribute it and/or
  2408. + modify it under the terms of the GNU General Public License as
  2409. + published by the Free Software Foundation; either version 2, or (at
  2410. + your option) any later version.
  2411. +
  2412. + This program is distributed in the hope that it will be useful, but
  2413. + WITHOUT ANY WARRANTY; without even the implied warranty of
  2414. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  2415. + General Public License for more details.
  2416. +*/
  2417. +
  2418. +#ifndef IPKG_CMD_H
  2419. +#define IPKG_CMD_H
  2420. +
  2421. +typedef int (*ipkg_cmd_fun_t)(ipkg_conf_t *conf, int argc, const char **argv);
  2422. +
  2423. +struct ipkg_cmd
  2424. +{
  2425. + const char *name;
  2426. + int requires_args;
  2427. + ipkg_cmd_fun_t fun;
  2428. +};
  2429. +typedef struct ipkg_cmd ipkg_cmd_t;
  2430. +
  2431. +ipkg_cmd_t *ipkg_cmd_find(const char *name);
  2432. +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc,
  2433. + const char **argv, void *userdata);
  2434. +int ipkg_multiple_files_scan (ipkg_conf_t *conf, int argc, char *argv[]);
  2435. +/* install any packges with state_want == SW_INSTALL */
  2436. +int ipkg_install_wanted_packages(ipkg_conf_t *conf);
  2437. +/* ensure that all dependences are satisfied */
  2438. +int ipkg_configure_packages(ipkg_conf_t *conf, char *pkg_name);
  2439. +int pkg_mark_provides(pkg_t *pkg);
  2440. +
  2441. +#endif
  2442. diff -Nur busybox-1.16.1.orig/archival/libipkg/ipkg_conf.c busybox-1.16.1/archival/libipkg/ipkg_conf.c
  2443. --- busybox-1.16.1.orig/archival/libipkg/ipkg_conf.c 1970-01-01 01:00:00.000000000 +0100
  2444. +++ busybox-1.16.1/archival/libipkg/ipkg_conf.c 2010-04-22 19:18:12.000000000 +0200
  2445. @@ -0,0 +1,711 @@
  2446. +/* ipkg_conf.c - the itsy package management system
  2447. +
  2448. + Carl D. Worth
  2449. +
  2450. + Copyright (C) 2001 University of Southern California
  2451. +
  2452. + This program is free software; you can redistribute it and/or
  2453. + modify it under the terms of the GNU General Public License as
  2454. + published by the Free Software Foundation; either version 2, or (at
  2455. + your option) any later version.
  2456. +
  2457. + This program is distributed in the hope that it will be useful, but
  2458. + WITHOUT ANY WARRANTY; without even the implied warranty of
  2459. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  2460. + General Public License for more details.
  2461. +*/
  2462. +
  2463. +#include <glob.h>
  2464. +
  2465. +#include "ipkg.h"
  2466. +#include "ipkg_conf.h"
  2467. +
  2468. +#include "xregex.h"
  2469. +#include "sprintf_alloc.h"
  2470. +#include "ipkg_conf.h"
  2471. +#include "ipkg_message.h"
  2472. +#include "file_util.h"
  2473. +#include "str_util.h"
  2474. +#include "xsystem.h"
  2475. +
  2476. +
  2477. +ipkg_conf_t *global_conf;
  2478. +
  2479. +static int ipkg_conf_parse_file(ipkg_conf_t *conf, const char *filename,
  2480. + pkg_src_list_t *pkg_src_list,
  2481. + nv_pair_list_t *tmp_dest_nv_pair_list,
  2482. + char **tmp_lists_dir);
  2483. +static int ipkg_init_options_array(const ipkg_conf_t *conf, ipkg_option_t **options);
  2484. +static int ipkg_conf_set_option(const ipkg_option_t *options,
  2485. + const char *name, const char *value);
  2486. +static int ipkg_conf_set_default_dest(ipkg_conf_t *conf,
  2487. + const char *default_dest_name);
  2488. +static int set_and_load_pkg_src_list(ipkg_conf_t *conf,
  2489. + pkg_src_list_t *nv_pair_list);
  2490. +static int set_and_load_pkg_dest_list(ipkg_conf_t *conf,
  2491. + nv_pair_list_t *nv_pair_list, char * lists_dir);
  2492. +
  2493. +int ipkg_init_options_array(const ipkg_conf_t *conf, ipkg_option_t **options)
  2494. +{
  2495. + ipkg_option_t tmp[] = {
  2496. + { "force_defaults", IPKG_OPT_TYPE_BOOL, &conf->force_defaults },
  2497. + { "force_depends", IPKG_OPT_TYPE_BOOL, &conf->force_depends },
  2498. + { "force_overwrite", IPKG_OPT_TYPE_BOOL, &conf->force_overwrite },
  2499. + { "force_downgrade", IPKG_OPT_TYPE_BOOL, &conf->force_downgrade },
  2500. + { "force_reinstall", IPKG_OPT_TYPE_BOOL, &conf->force_reinstall },
  2501. + { "force_space", IPKG_OPT_TYPE_BOOL, &conf->force_space },
  2502. + { "ftp_proxy", IPKG_OPT_TYPE_STRING, &conf->ftp_proxy },
  2503. + { "http_proxy", IPKG_OPT_TYPE_STRING, &conf->http_proxy },
  2504. + { "multiple_providers", IPKG_OPT_TYPE_BOOL, &conf->multiple_providers },
  2505. + { "no_proxy", IPKG_OPT_TYPE_STRING, &conf->no_proxy },
  2506. + { "test", IPKG_OPT_TYPE_INT, &conf->noaction },
  2507. + { "noaction", IPKG_OPT_TYPE_INT, &conf->noaction },
  2508. + { "nodeps", IPKG_OPT_TYPE_BOOL, &conf->nodeps },
  2509. + { "offline_root", IPKG_OPT_TYPE_STRING, &conf->offline_root },
  2510. + { "offline_root_post_script_cmd", IPKG_OPT_TYPE_STRING, &conf->offline_root_post_script_cmd },
  2511. + { "offline_root_pre_script_cmd", IPKG_OPT_TYPE_STRING, &conf->offline_root_pre_script_cmd },
  2512. + { "proxy_passwd", IPKG_OPT_TYPE_STRING, &conf->proxy_passwd },
  2513. + { "proxy_user", IPKG_OPT_TYPE_STRING, &conf->proxy_user },
  2514. + { "query-all", IPKG_OPT_TYPE_BOOL, &conf->query_all },
  2515. + { "verbose-wget", IPKG_OPT_TYPE_BOOL, &conf->verbose_wget },
  2516. + { "verbosity", IPKG_OPT_TYPE_BOOL, &conf->verbosity },
  2517. + { NULL }
  2518. + };
  2519. +
  2520. + *options = (ipkg_option_t *)malloc(sizeof(tmp));
  2521. + if ( options == NULL ){
  2522. + fprintf(stderr,"%s: Unable to allocate memory\n",__FUNCTION__);
  2523. + return -1;
  2524. + }
  2525. +
  2526. + memcpy(*options, tmp, sizeof(tmp));
  2527. + return 0;
  2528. +};
  2529. +
  2530. +static void ipkg_conf_override_string(char **conf_str, char *arg_str)
  2531. +{
  2532. + if (arg_str) {
  2533. + if (*conf_str) {
  2534. + free(*conf_str);
  2535. + }
  2536. + *conf_str = strdup(arg_str);
  2537. + }
  2538. +}
  2539. +
  2540. +static void ipkg_conf_free_string(char **conf_str)
  2541. +{
  2542. + if (*conf_str) {
  2543. + free(*conf_str);
  2544. + *conf_str = NULL;
  2545. + }
  2546. +}
  2547. +
  2548. +int ipkg_conf_init(ipkg_conf_t *conf, const args_t *args)
  2549. +{
  2550. + int err;
  2551. + char *tmp_dir_base;
  2552. + nv_pair_list_t tmp_dest_nv_pair_list;
  2553. + char * lists_dir =NULL;
  2554. + glob_t globbuf;
  2555. + const char *etc_ipkg_conf_pattern = "/etc/ipkg/*.conf";
  2556. + char *pending_dir =NULL;
  2557. +
  2558. + memset(conf, 0, sizeof(ipkg_conf_t));
  2559. +
  2560. + pkg_src_list_init(&conf->pkg_src_list);
  2561. +
  2562. + nv_pair_list_init(&tmp_dest_nv_pair_list);
  2563. + pkg_dest_list_init(&conf->pkg_dest_list);
  2564. +
  2565. + nv_pair_list_init(&conf->arch_list);
  2566. +
  2567. + conf->restrict_to_default_dest = 0;
  2568. + conf->default_dest = NULL;
  2569. +
  2570. +
  2571. + if (args->tmp_dir)
  2572. + tmp_dir_base = args->tmp_dir;
  2573. + else
  2574. + tmp_dir_base = getenv("TMPDIR");
  2575. + sprintf_alloc(&conf->tmp_dir, "%s/%s",
  2576. + tmp_dir_base ? tmp_dir_base : IPKG_CONF_DEFAULT_TMP_DIR_BASE,
  2577. + IPKG_CONF_TMP_DIR_SUFFIX);
  2578. + conf->tmp_dir = mkdtemp(conf->tmp_dir);
  2579. + if (conf->tmp_dir == NULL) {
  2580. + fprintf(stderr, "%s: Failed to create temporary directory `%s': %s\n",
  2581. + __FUNCTION__, conf->tmp_dir, strerror(errno));
  2582. + return errno;
  2583. + }
  2584. +
  2585. + conf->force_depends = 0;
  2586. + conf->force_defaults = 0;
  2587. + conf->force_overwrite = 0;
  2588. + conf->force_downgrade = 0;
  2589. + conf->force_reinstall = 0;
  2590. + conf->force_space = 0;
  2591. + conf->force_removal_of_essential_packages = 0;
  2592. + conf->force_removal_of_dependent_packages = 0;
  2593. + conf->nodeps = 0;
  2594. + conf->verbose_wget = 0;
  2595. + conf->offline_root = NULL;
  2596. + conf->offline_root_pre_script_cmd = NULL;
  2597. + conf->offline_root_post_script_cmd = NULL;
  2598. + conf->multiple_providers = 0;
  2599. + conf->verbosity = 1;
  2600. + conf->noaction = 0;
  2601. +
  2602. + conf->http_proxy = NULL;
  2603. + conf->ftp_proxy = NULL;
  2604. + conf->no_proxy = NULL;
  2605. + conf->proxy_user = NULL;
  2606. + conf->proxy_passwd = NULL;
  2607. +
  2608. + pkg_hash_init("pkg-hash", &conf->pkg_hash, IPKG_CONF_DEFAULT_HASH_LEN);
  2609. + hash_table_init("file-hash", &conf->file_hash, IPKG_CONF_DEFAULT_HASH_LEN);
  2610. + hash_table_init("obs-file-hash", &conf->obs_file_hash, IPKG_CONF_DEFAULT_HASH_LEN);
  2611. + lists_dir=(char *)malloc(1);
  2612. + lists_dir[0]='\0';
  2613. + if (args->conf_file) {
  2614. + struct stat stat_buf;
  2615. + err = stat(args->conf_file, &stat_buf);
  2616. + if (err == 0)
  2617. + if (ipkg_conf_parse_file(conf, args->conf_file,
  2618. + &conf->pkg_src_list, &tmp_dest_nv_pair_list,&lists_dir)<0) {
  2619. + /* Memory leakage from ipkg_conf_parse-file */
  2620. + return -1;
  2621. + }
  2622. +
  2623. + }
  2624. +
  2625. + /* if (!lists_dir ){*/
  2626. + if (strlen(lists_dir)<=1 ){
  2627. + lists_dir = realloc(lists_dir,strlen(IPKG_CONF_LISTS_DIR)+2);
  2628. + sprintf (lists_dir,"%s",IPKG_CONF_LISTS_DIR);
  2629. + }
  2630. +
  2631. + if (args->offline_root) {
  2632. + char *tmp = malloc(strlen(lists_dir) + strlen(args->offline_root) + 1);
  2633. + sprintf_alloc(&tmp, "%s/%s",args->offline_root,lists_dir);
  2634. + free(lists_dir);
  2635. + lists_dir = tmp;
  2636. + }
  2637. +
  2638. + pending_dir = malloc(strlen(lists_dir)+strlen("/pending")+5);
  2639. + snprintf(pending_dir,strlen(lists_dir)+strlen("/pending") ,"%s%s",lists_dir,"/pending");
  2640. +
  2641. + conf->lists_dir = strdup(lists_dir);
  2642. + conf->pending_dir = strdup(pending_dir);
  2643. +
  2644. + if (args->offline_root)
  2645. + sprintf_alloc(&etc_ipkg_conf_pattern, "%s/etc/ipkg/*.conf", args->offline_root);
  2646. + memset(&globbuf, 0, sizeof(globbuf));
  2647. + err = glob(etc_ipkg_conf_pattern, 0, NULL, &globbuf);
  2648. + if (!err) {
  2649. + int i;
  2650. + for (i = 0; i < globbuf.gl_pathc; i++) {
  2651. + if (globbuf.gl_pathv[i])
  2652. + if ( ipkg_conf_parse_file(conf, globbuf.gl_pathv[i],
  2653. + &conf->pkg_src_list, &tmp_dest_nv_pair_list,&lists_dir)<0) {
  2654. + /* Memory leakage from ipkg_conf_parse-file */
  2655. + return -1;
  2656. + }
  2657. + }
  2658. + }
  2659. + globfree(&globbuf);
  2660. +
  2661. + /* if no architectures were defined, then default all, noarch, and host architecture */
  2662. + if (nv_pair_list_empty(&conf->arch_list)) {
  2663. + nv_pair_list_append(&conf->arch_list, "all", "1");
  2664. + nv_pair_list_append(&conf->arch_list, "noarch", "1");
  2665. + nv_pair_list_append(&conf->arch_list, HOST_CPU_STR, "10");
  2666. + }
  2667. +
  2668. + /* Even if there is no conf file, we'll need at least one dest. */
  2669. + if (tmp_dest_nv_pair_list.head == NULL) {
  2670. + nv_pair_list_append(&tmp_dest_nv_pair_list,
  2671. + IPKG_CONF_DEFAULT_DEST_NAME,
  2672. + IPKG_CONF_DEFAULT_DEST_ROOT_DIR);
  2673. + }
  2674. +
  2675. + /* After parsing the file, set options from command-line, (so that
  2676. + command-line arguments take precedence) */
  2677. + /* XXX: CLEANUP: The interaction between args.c and ipkg_conf.c
  2678. + really needs to be cleaned up. There is so much duplication
  2679. + right now it is ridiculous. Maybe ipkg_conf_t should just save
  2680. + a pointer to args_t (which could then not be freed), rather
  2681. + than duplicating every field here? */
  2682. + if (args->force_depends) {
  2683. + conf->force_depends = 1;
  2684. + }
  2685. + if (args->force_defaults) {
  2686. + conf->force_defaults = 1;
  2687. + }
  2688. + if (args->force_overwrite) {
  2689. + conf->force_overwrite = 1;
  2690. + }
  2691. + if (args->force_downgrade) {
  2692. + conf->force_downgrade = 1;
  2693. + }
  2694. + if (args->force_reinstall) {
  2695. + conf->force_reinstall = 1;
  2696. + }
  2697. + if (args->force_removal_of_dependent_packages) {
  2698. + conf->force_removal_of_dependent_packages = 1;
  2699. + }
  2700. + if (args->force_removal_of_essential_packages) {
  2701. + conf->force_removal_of_essential_packages = 1;
  2702. + }
  2703. + if (args->nodeps) {
  2704. + conf->nodeps = 1;
  2705. + }
  2706. + if (args->noaction) {
  2707. + conf->noaction = 1;
  2708. + }
  2709. + if (args->query_all) {
  2710. + conf->query_all = 1;
  2711. + }
  2712. + if (args->verbose_wget) {
  2713. + conf->verbose_wget = 1;
  2714. + }
  2715. + if (args->multiple_providers) {
  2716. + conf->multiple_providers = 1;
  2717. + }
  2718. + if (args->verbosity != conf->verbosity) {
  2719. + conf->verbosity = args->verbosity;
  2720. + }
  2721. +
  2722. + ipkg_conf_override_string(&conf->offline_root,
  2723. + args->offline_root);
  2724. + ipkg_conf_override_string(&conf->offline_root_pre_script_cmd,
  2725. + args->offline_root_pre_script_cmd);
  2726. + ipkg_conf_override_string(&conf->offline_root_post_script_cmd,
  2727. + args->offline_root_post_script_cmd);
  2728. +
  2729. +/* Pigi: added a flag to disable the checking of structures if the command does not need to
  2730. + read anything from there.
  2731. +*/
  2732. + if ( !(args->nocheckfordirorfile)){
  2733. + /* need to run load the source list before dest list -Jamey */
  2734. + if ( !(args->noreadfeedsfile))
  2735. + set_and_load_pkg_src_list(conf, &conf->pkg_src_list);
  2736. +
  2737. + /* Now that we have resolved conf->offline_root, we can commit to
  2738. + the directory names for the dests and load in all the package
  2739. + lists. */
  2740. + set_and_load_pkg_dest_list(conf, &tmp_dest_nv_pair_list,lists_dir);
  2741. +
  2742. + if (args->dest) {
  2743. + err = ipkg_conf_set_default_dest(conf, args->dest);
  2744. + if (err) {
  2745. + return err;
  2746. + }
  2747. + }
  2748. + }
  2749. + nv_pair_list_deinit(&tmp_dest_nv_pair_list);
  2750. + free(lists_dir);
  2751. + free(pending_dir);
  2752. +
  2753. + return 0;
  2754. +}
  2755. +
  2756. +void ipkg_conf_deinit(ipkg_conf_t *conf)
  2757. +{
  2758. +#ifdef IPKG_DEBUG_NO_TMP_CLEANUP
  2759. +#error
  2760. + fprintf(stderr, "%s: Not cleaning up %s since ipkg compiled "
  2761. + "with IPKG_DEBUG_NO_TMP_CLEANUP\n",
  2762. + __FUNCTION__, conf->tmp_dir);
  2763. +#else
  2764. + int err;
  2765. +
  2766. + err = rmdir(conf->tmp_dir);
  2767. + if (err) {
  2768. + if (errno == ENOTEMPTY) {
  2769. + char *cmd;
  2770. + sprintf_alloc(&cmd, "rm -fr %s\n", conf->tmp_dir);
  2771. + err = xsystem(cmd);
  2772. + free(cmd);
  2773. + }
  2774. + if (err)
  2775. + fprintf(stderr, "WARNING: Unable to remove temporary directory: %s: %s\n", conf->tmp_dir, strerror(errno));
  2776. + }
  2777. +#endif /* IPKG_DEBUG_NO_TMP_CLEANUP */
  2778. +
  2779. + free(conf->tmp_dir); /*XXX*/
  2780. +
  2781. + pkg_src_list_deinit(&conf->pkg_src_list);
  2782. + pkg_dest_list_deinit(&conf->pkg_dest_list);
  2783. + nv_pair_list_deinit(&conf->arch_list);
  2784. + if (&conf->pkg_hash)
  2785. + pkg_hash_deinit(&conf->pkg_hash);
  2786. + if (&conf->file_hash)
  2787. + hash_table_deinit(&conf->file_hash);
  2788. + if (&conf->obs_file_hash)
  2789. + hash_table_deinit(&conf->obs_file_hash);
  2790. +
  2791. + ipkg_conf_free_string(&conf->offline_root);
  2792. + ipkg_conf_free_string(&conf->offline_root_pre_script_cmd);
  2793. + ipkg_conf_free_string(&conf->offline_root_post_script_cmd);
  2794. +
  2795. + if (conf->verbosity > 1) {
  2796. + int i;
  2797. + hash_table_t *hashes[] = {
  2798. + &conf->pkg_hash,
  2799. + &conf->file_hash,
  2800. + &conf->obs_file_hash };
  2801. + for (i = 0; i < 3; i++) {
  2802. + hash_table_t *hash = hashes[i];
  2803. + int c = 0;
  2804. + int n_conflicts = 0;
  2805. + int j;
  2806. + for (j = 0; j < hash->n_entries; j++) {
  2807. + int len = 0;
  2808. + hash_entry_t *e = &hash->entries[j];
  2809. + if (e->next)
  2810. + n_conflicts++;
  2811. + while (e && e->key) {
  2812. + len++;
  2813. + e = e->next;
  2814. + }
  2815. + if (len > c)
  2816. + c = len;
  2817. + }
  2818. + ipkg_message(conf, IPKG_DEBUG, "hash_table[%s] n_buckets=%d n_elements=%d max_conflicts=%d n_conflicts=%d\n",
  2819. + hash->name, hash->n_entries, hash->n_elements, c, n_conflicts);
  2820. + hash_table_deinit(hash);
  2821. + }
  2822. + }
  2823. +}
  2824. +
  2825. +static int ipkg_conf_set_default_dest(ipkg_conf_t *conf,
  2826. + const char *default_dest_name)
  2827. +{
  2828. + pkg_dest_list_elt_t *iter;
  2829. + pkg_dest_t *dest;
  2830. +
  2831. + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
  2832. + dest = iter->data;
  2833. + if (strcmp(dest->name, default_dest_name) == 0) {
  2834. + conf->default_dest = dest;
  2835. + conf->restrict_to_default_dest = 1;
  2836. + return 0;
  2837. + }
  2838. + }
  2839. +
  2840. + fprintf(stderr, "ERROR: Unknown dest name: `%s'\n", default_dest_name);
  2841. +
  2842. + return 1;
  2843. +}
  2844. +
  2845. +static int set_and_load_pkg_src_list(ipkg_conf_t *conf, pkg_src_list_t *pkg_src_list)
  2846. +{
  2847. + pkg_src_list_elt_t *iter;
  2848. + pkg_src_t *src;
  2849. + char *list_file;
  2850. +
  2851. + for (iter = pkg_src_list->head; iter; iter = iter->next) {
  2852. + src = iter->data;
  2853. + if (src == NULL) {
  2854. + continue;
  2855. + }
  2856. +
  2857. + sprintf_alloc(&list_file, "%s/%s",
  2858. + conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir,
  2859. + src->name);
  2860. +
  2861. + if (file_exists(list_file)) {
  2862. + pkg_hash_add_from_file(conf, list_file, src, NULL, 0);
  2863. + }
  2864. + free(list_file);
  2865. + }
  2866. +
  2867. + return 0;
  2868. +}
  2869. +
  2870. +static int set_and_load_pkg_dest_list(ipkg_conf_t *conf, nv_pair_list_t *nv_pair_list, char *lists_dir )
  2871. +{
  2872. + nv_pair_list_elt_t *iter;
  2873. + nv_pair_t *nv_pair;
  2874. + pkg_dest_t *dest;
  2875. + char *root_dir;
  2876. +
  2877. + for (iter = nv_pair_list->head; iter; iter = iter->next) {
  2878. + nv_pair = iter->data;
  2879. +
  2880. + if (conf->offline_root) {
  2881. + sprintf_alloc(&root_dir, "%s%s", conf->offline_root, nv_pair->value);
  2882. + } else {
  2883. + root_dir = strdup(nv_pair->value);
  2884. + }
  2885. + dest = pkg_dest_list_append(&conf->pkg_dest_list, nv_pair->name, root_dir, lists_dir);
  2886. + free(root_dir);
  2887. + if (dest == NULL) {
  2888. + continue;
  2889. + }
  2890. + if (conf->default_dest == NULL) {
  2891. + conf->default_dest = dest;
  2892. + }
  2893. + if (file_exists(dest->status_file_name)) {
  2894. + pkg_hash_add_from_file(conf, dest->status_file_name,
  2895. + NULL, dest, 1);
  2896. + }
  2897. + }
  2898. +
  2899. + return 0;
  2900. +}
  2901. +
  2902. +static int ipkg_conf_parse_file(ipkg_conf_t *conf, const char *filename,
  2903. + pkg_src_list_t *pkg_src_list,
  2904. + nv_pair_list_t *tmp_dest_nv_pair_list,
  2905. + char **lists_dir)
  2906. +{
  2907. + ipkg_option_t * options;
  2908. + FILE *file = fopen(filename, "r");
  2909. + regex_t valid_line_re, comment_re;
  2910. +#define regmatch_size 12
  2911. + regmatch_t regmatch[regmatch_size];
  2912. +
  2913. + if (ipkg_init_options_array(conf, &options)<0)
  2914. + return ENOMEM;
  2915. +
  2916. + if (file == NULL) {
  2917. + fprintf(stderr, "%s: failed to open %s: %s\n",
  2918. + __FUNCTION__, filename, strerror(errno));
  2919. + free(options);
  2920. + return errno;
  2921. + }
  2922. + ipkg_message(conf, IPKG_NOTICE, "loading conf file %s\n", filename);
  2923. +
  2924. + xregcomp(&comment_re,
  2925. + "^[[:space:]]*(#.*|[[:space:]]*)$",
  2926. + REG_EXTENDED);
  2927. + xregcomp(&valid_line_re, "^[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))([[:space:]]+([^[:space:]]+))?[[:space:]]*$", REG_EXTENDED);
  2928. +
  2929. + while(1) {
  2930. + int line_num = 0;
  2931. + char *line;
  2932. + char *type, *name, *value, *extra;
  2933. +
  2934. + line = file_read_line_alloc(file);
  2935. + line_num++;
  2936. + if (line == NULL) {
  2937. + break;
  2938. + }
  2939. +
  2940. + str_chomp(line);
  2941. +
  2942. + if (regexec(&comment_re, line, 0, 0, 0) == 0) {
  2943. + goto NEXT_LINE;
  2944. + }
  2945. +
  2946. + if (regexec(&valid_line_re, line, regmatch_size, regmatch, 0) == REG_NOMATCH) {
  2947. + str_chomp(line);
  2948. + fprintf(stderr, "%s:%d: Ignoring invalid line: `%s'\n",
  2949. + filename, line_num, line);
  2950. + goto NEXT_LINE;
  2951. + }
  2952. +
  2953. + /* This has to be so ugly to deal with optional quotation marks */
  2954. + if (regmatch[2].rm_so > 0) {
  2955. + type = strndup(line + regmatch[2].rm_so,
  2956. + regmatch[2].rm_eo - regmatch[2].rm_so);
  2957. + } else {
  2958. + type = strndup(line + regmatch[3].rm_so,
  2959. + regmatch[3].rm_eo - regmatch[3].rm_so);
  2960. + }
  2961. + if (regmatch[5].rm_so > 0) {
  2962. + name = strndup(line + regmatch[5].rm_so,
  2963. + regmatch[5].rm_eo - regmatch[5].rm_so);
  2964. + } else {
  2965. + name = strndup(line + regmatch[6].rm_so,
  2966. + regmatch[6].rm_eo - regmatch[6].rm_so);
  2967. + }
  2968. + if (regmatch[8].rm_so > 0) {
  2969. + value = strndup(line + regmatch[8].rm_so,
  2970. + regmatch[8].rm_eo - regmatch[8].rm_so);
  2971. + } else {
  2972. + value = strndup(line + regmatch[9].rm_so,
  2973. + regmatch[9].rm_eo - regmatch[9].rm_so);
  2974. + }
  2975. + extra = NULL;
  2976. + if (regmatch[11].rm_so > 0) {
  2977. + extra = strndup (line + regmatch[11].rm_so,
  2978. + regmatch[11].rm_eo - regmatch[11].rm_so);
  2979. + }
  2980. +
  2981. + /* We use the tmp_dest_nv_pair_list below instead of
  2982. + conf->pkg_dest_list because we might encounter an
  2983. + offline_root option later and that would invalidate the
  2984. + directories we would have computed in
  2985. + pkg_dest_list_init. (We do a similar thing with
  2986. + tmp_src_nv_pair_list for sake of symmetry.) */
  2987. + if (strcmp(type, "option") == 0) {
  2988. + ipkg_conf_set_option(options, name, value);
  2989. + } else if (strcmp(type, "src") == 0) {
  2990. + if (!nv_pair_list_find((nv_pair_list_t *)pkg_src_list, name)) {
  2991. + pkg_src_list_append (pkg_src_list, name, value, extra, 0);
  2992. + } else {
  2993. + ipkg_message(conf, IPKG_ERROR, "ERROR: duplicate src declaration. Skipping:\n\t src %s %s\n",
  2994. + name, value);
  2995. + }
  2996. + } else if (strcmp(type, "src/gz") == 0) {
  2997. + if (!nv_pair_list_find((nv_pair_list_t *)pkg_src_list, name)) {
  2998. + pkg_src_list_append (pkg_src_list, name, value, extra, 1);
  2999. + } else {
  3000. + ipkg_message(conf, IPKG_ERROR, "ERROR: duplicate src declaration. Skipping:\n\t src %s %s\n",
  3001. + name, value);
  3002. + }
  3003. + } else if (strcmp(type, "dest") == 0) {
  3004. + nv_pair_list_append(tmp_dest_nv_pair_list, name, value);
  3005. + } else if (strcmp(type, "lists_dir") == 0) {
  3006. + *lists_dir = realloc(*lists_dir,strlen(value)+1);
  3007. + if (*lists_dir == NULL) {
  3008. + ipkg_message(conf, IPKG_ERROR, "ERROR: Not enough memory\n");
  3009. + free(options);
  3010. + return EINVAL;
  3011. + }
  3012. + sprintf (*lists_dir,"%s",value);
  3013. + } else if (strcmp(type, "arch") == 0) {
  3014. + ipkg_message(conf, IPKG_INFO, "supported arch %s priority (%s)\n", name, value);
  3015. + if (!value) {
  3016. + ipkg_message(conf, IPKG_NOTICE, "defaulting architecture %s priority to 10\n", name);
  3017. + value = strdup("10");
  3018. + }
  3019. + nv_pair_list_append(&conf->arch_list, strdup(name), strdup(value));
  3020. + } else {
  3021. + fprintf(stderr, "WARNING: Ignoring unknown configuration "
  3022. + "parameter: %s %s %s\n", type, name, value);
  3023. + free(options);
  3024. + return EINVAL;
  3025. + }
  3026. +
  3027. + free(type);
  3028. + free(name);
  3029. + free(value);
  3030. + if (extra)
  3031. + free (extra);
  3032. +
  3033. + NEXT_LINE:
  3034. + free(line);
  3035. + }
  3036. +
  3037. + free(options);
  3038. + regfree(&comment_re);
  3039. + regfree(&valid_line_re);
  3040. + fclose(file);
  3041. +
  3042. + return 0;
  3043. +}
  3044. +
  3045. +static int ipkg_conf_set_option(const ipkg_option_t *options,
  3046. + const char *name, const char *value)
  3047. +{
  3048. + int i = 0;
  3049. + while (options[i].name) {
  3050. + if (strcmp(options[i].name, name) == 0) {
  3051. + switch (options[i].type) {
  3052. + case IPKG_OPT_TYPE_BOOL:
  3053. + *((int *)options[i].value) = 1;
  3054. + return 0;
  3055. + case IPKG_OPT_TYPE_INT:
  3056. + if (value) {
  3057. + *((int *)options[i].value) = atoi(value);
  3058. + return 0;
  3059. + } else {
  3060. + printf("%s: Option %s need an argument\n",
  3061. + __FUNCTION__, name);
  3062. + return EINVAL;
  3063. + }
  3064. + case IPKG_OPT_TYPE_STRING:
  3065. + if (value) {
  3066. + *((char **)options[i].value) = strdup(value);
  3067. + return 0;
  3068. + } else {
  3069. + printf("%s: Option %s need an argument\n",
  3070. + __FUNCTION__, name);
  3071. + return EINVAL;
  3072. + }
  3073. + }
  3074. + }
  3075. + i++;
  3076. + }
  3077. +
  3078. + fprintf(stderr, "%s: Unrecognized option: %s=%s\n",
  3079. + __FUNCTION__, name, value);
  3080. + return EINVAL;
  3081. +}
  3082. +
  3083. +int ipkg_conf_write_status_files(ipkg_conf_t *conf)
  3084. +{
  3085. + pkg_dest_list_elt_t *iter;
  3086. + pkg_dest_t *dest;
  3087. + pkg_vec_t *all;
  3088. + pkg_t *pkg;
  3089. + register int i;
  3090. + int err;
  3091. +
  3092. + if (conf->noaction)
  3093. + return 0;
  3094. + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
  3095. + dest = iter->data;
  3096. + dest->status_file = fopen(dest->status_file_tmp_name, "w");
  3097. + if (dest->status_file == NULL) {
  3098. + fprintf(stderr, "%s: Can't open status file: %s for writing: %s\n",
  3099. + __FUNCTION__, dest->status_file_name, strerror(errno));
  3100. + }
  3101. + }
  3102. +
  3103. + all = pkg_vec_alloc();
  3104. + pkg_hash_fetch_available(&conf->pkg_hash, all);
  3105. +
  3106. + for(i = 0; i < all->len; i++) {
  3107. + pkg = all->pkgs[i];
  3108. + /* We don't need most uninstalled packages in the status file */
  3109. + if (pkg->state_status == SS_NOT_INSTALLED
  3110. + && (pkg->state_want == SW_UNKNOWN
  3111. + || pkg->state_want == SW_DEINSTALL
  3112. + || pkg->state_want == SW_PURGE)) {
  3113. + continue;
  3114. + }
  3115. + if (!pkg) {
  3116. + fprintf(stderr, "Null package\n");
  3117. + }
  3118. + if (pkg->dest == NULL) {
  3119. + fprintf(stderr, "%s: ERROR: Can't write status for "
  3120. + "package %s since it has a NULL dest\n",
  3121. + __FUNCTION__, pkg->name);
  3122. + continue;
  3123. + }
  3124. + if (pkg->dest->status_file) {
  3125. + pkg_print_status(pkg, pkg->dest->status_file);
  3126. + }
  3127. + }
  3128. +
  3129. + pkg_vec_free(all);
  3130. +
  3131. + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
  3132. + dest = iter->data;
  3133. + if (dest->status_file) {
  3134. + err = ferror(dest->status_file);
  3135. + fclose(dest->status_file);
  3136. + dest->status_file = NULL;
  3137. + if (!err) {
  3138. + file_move(dest->status_file_tmp_name, dest->status_file_name);
  3139. + } else {
  3140. + fprintf(stderr, "%s: ERROR: An error has occurred writing %s, "
  3141. + "retaining old %s\n", __FUNCTION__,
  3142. + dest->status_file_tmp_name, dest->status_file_name);
  3143. + }
  3144. + }
  3145. + }
  3146. +
  3147. + return 0;
  3148. +}
  3149. +
  3150. +
  3151. +char *root_filename_alloc(ipkg_conf_t *conf, char *filename)
  3152. +{
  3153. + char *root_filename;
  3154. + sprintf_alloc(&root_filename, "%s%s", (conf->offline_root ? conf->offline_root : ""), filename);
  3155. + return root_filename;
  3156. +}
  3157. diff -Nur busybox-1.16.1.orig/archival/libipkg/ipkg_conf.h busybox-1.16.1/archival/libipkg/ipkg_conf.h
  3158. --- busybox-1.16.1.orig/archival/libipkg/ipkg_conf.h 1970-01-01 01:00:00.000000000 +0100
  3159. +++ busybox-1.16.1/archival/libipkg/ipkg_conf.h 2010-04-22 19:18:12.000000000 +0200
  3160. @@ -0,0 +1,107 @@
  3161. +/* ipkg_conf.h - the itsy package management system
  3162. +
  3163. + Carl D. Worth
  3164. +
  3165. + Copyright (C) 2001 University of Southern California
  3166. +
  3167. + This program is free software; you can redistribute it and/or
  3168. + modify it under the terms of the GNU General Public License as
  3169. + published by the Free Software Foundation; either version 2, or (at
  3170. + your option) any later version.
  3171. +
  3172. + This program is distributed in the hope that it will be useful, but
  3173. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3174. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3175. + General Public License for more details.
  3176. +*/
  3177. +
  3178. +#ifndef IPKG_CONF_H
  3179. +#define IPKG_CONF_H
  3180. +
  3181. +typedef struct ipkg_conf ipkg_conf_t;
  3182. +
  3183. +#include "hash_table.h"
  3184. +#include "ipkg.h"
  3185. +#include "args.h"
  3186. +#include "pkg.h"
  3187. +#include "pkg_hash.h"
  3188. +#include "pkg_src_list.h"
  3189. +#include "pkg_dest_list.h"
  3190. +#include "nv_pair_list.h"
  3191. +
  3192. +#define IPKG_CONF_DEFAULT_TMP_DIR_BASE "/tmp"
  3193. +#define IPKG_CONF_TMP_DIR_SUFFIX "ipkg-XXXXXX"
  3194. +#define IPKG_CONF_LISTS_DIR IPKG_STATE_DIR_PREFIX "/lists"
  3195. +#define IPKG_CONF_PENDING_DIR IPKG_STATE_DIR_PREFIX "/pending"
  3196. +
  3197. +/* In case the config file defines no dest */
  3198. +#define IPKG_CONF_DEFAULT_DEST_NAME "root"
  3199. +#define IPKG_CONF_DEFAULT_DEST_ROOT_DIR "/"
  3200. +
  3201. +#define IPKG_CONF_DEFAULT_HASH_LEN 1024
  3202. +
  3203. +struct ipkg_conf
  3204. +{
  3205. + pkg_src_list_t pkg_src_list;
  3206. + pkg_dest_list_t pkg_dest_list;
  3207. + nv_pair_list_t arch_list;
  3208. +
  3209. + int restrict_to_default_dest;
  3210. + pkg_dest_t *default_dest;
  3211. +
  3212. + char *tmp_dir;
  3213. + char *lists_dir;
  3214. + char *pending_dir;
  3215. +
  3216. + /* options */
  3217. + int force_depends;
  3218. + int force_defaults;
  3219. + int force_overwrite;
  3220. + int force_downgrade;
  3221. + int force_reinstall;
  3222. + int force_space;
  3223. + int force_removal_of_dependent_packages;
  3224. + int force_removal_of_essential_packages;
  3225. + int nodeps; /* do not follow dependences */
  3226. + int verbose_wget;
  3227. + int multiple_providers;
  3228. + char *offline_root;
  3229. + char *offline_root_pre_script_cmd;
  3230. + char *offline_root_post_script_cmd;
  3231. + int query_all;
  3232. + int verbosity;
  3233. + int noaction;
  3234. +
  3235. + /* proxy options */
  3236. + char *http_proxy;
  3237. + char *ftp_proxy;
  3238. + char *no_proxy;
  3239. + char *proxy_user;
  3240. + char *proxy_passwd;
  3241. +
  3242. + hash_table_t pkg_hash;
  3243. + hash_table_t file_hash;
  3244. + hash_table_t obs_file_hash;
  3245. +};
  3246. +
  3247. +enum ipkg_option_type {
  3248. + IPKG_OPT_TYPE_BOOL,
  3249. + IPKG_OPT_TYPE_INT,
  3250. + IPKG_OPT_TYPE_STRING
  3251. +};
  3252. +typedef enum ipkg_option_type ipkg_option_type_t;
  3253. +
  3254. +typedef struct ipkg_option ipkg_option_t;
  3255. +struct ipkg_option {
  3256. + const char *name;
  3257. + const ipkg_option_type_t type;
  3258. + const void *value;
  3259. +};
  3260. +
  3261. +int ipkg_conf_init(ipkg_conf_t *conf, const args_t *args);
  3262. +void ipkg_conf_deinit(ipkg_conf_t *conf);
  3263. +
  3264. +int ipkg_conf_write_status_files(ipkg_conf_t *conf);
  3265. +char *root_filename_alloc(ipkg_conf_t *conf, char *filename);
  3266. +
  3267. +#endif
  3268. diff -Nur busybox-1.16.1.orig/archival/libipkg/ipkg_configure.c busybox-1.16.1/archival/libipkg/ipkg_configure.c
  3269. --- busybox-1.16.1.orig/archival/libipkg/ipkg_configure.c 1970-01-01 01:00:00.000000000 +0100
  3270. +++ busybox-1.16.1/archival/libipkg/ipkg_configure.c 2010-04-22 19:18:12.000000000 +0200
  3271. @@ -0,0 +1,40 @@
  3272. +/* ipkg_configure.c - the itsy package management system
  3273. +
  3274. + Carl D. Worth
  3275. +
  3276. + Copyright (C) 2001 University of Southern California
  3277. +
  3278. + This program is free software; you can redistribute it and/or
  3279. + modify it under the terms of the GNU General Public License as
  3280. + published by the Free Software Foundation; either version 2, or (at
  3281. + your option) any later version.
  3282. +
  3283. + This program is distributed in the hope that it will be useful, but
  3284. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3285. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3286. + General Public License for more details.
  3287. +*/
  3288. +
  3289. +#include "ipkg.h"
  3290. +
  3291. +#include "ipkg_configure.h"
  3292. +
  3293. +int ipkg_configure(ipkg_conf_t *conf, pkg_t *pkg)
  3294. +{
  3295. + int err;
  3296. +
  3297. + /* DPKG_INCOMPATIBILITY:
  3298. + dpkg actually does some conffile handling here, rather than at the
  3299. + end of ipkg_install(). Do we care? */
  3300. + /* DPKG_INCOMPATIBILITY:
  3301. + dpkg actually includes a version number to this script call */
  3302. + err = pkg_run_script(conf, pkg, "postinst", "configure");
  3303. + if (err) {
  3304. + printf("ERROR: %s.postinst returned %d\n", pkg->name, err);
  3305. + return err;
  3306. + }
  3307. +
  3308. + ipkg_state_changed++;
  3309. + return 0;
  3310. +}
  3311. +
  3312. diff -Nur busybox-1.16.1.orig/archival/libipkg/ipkg_configure.h busybox-1.16.1/archival/libipkg/ipkg_configure.h
  3313. --- busybox-1.16.1.orig/archival/libipkg/ipkg_configure.h 1970-01-01 01:00:00.000000000 +0100
  3314. +++ busybox-1.16.1/archival/libipkg/ipkg_configure.h 2010-04-22 19:18:12.000000000 +0200
  3315. @@ -0,0 +1,25 @@
  3316. +/* ipkg_configure.h - the itsy package management system
  3317. +
  3318. + Carl D. Worth
  3319. +
  3320. + Copyright (C) 2001 University of Southern California
  3321. +
  3322. + This program is free software; you can redistribute it and/or
  3323. + modify it under the terms of the GNU General Public License as
  3324. + published by the Free Software Foundation; either version 2, or (at
  3325. + your option) any later version.
  3326. +
  3327. + This program is distributed in the hope that it will be useful, but
  3328. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3329. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3330. + General Public License for more details.
  3331. +*/
  3332. +
  3333. +#ifndef IPKG_CONFIGURE_H
  3334. +#define IPKG_CONFIGURE_H
  3335. +
  3336. +#include "ipkg_conf.h"
  3337. +
  3338. +int ipkg_configure(ipkg_conf_t *ipkg_conf, pkg_t *pkg);
  3339. +
  3340. +#endif
  3341. diff -Nur busybox-1.16.1.orig/archival/libipkg/ipkg_download.c busybox-1.16.1/archival/libipkg/ipkg_download.c
  3342. --- busybox-1.16.1.orig/archival/libipkg/ipkg_download.c 1970-01-01 01:00:00.000000000 +0100
  3343. +++ busybox-1.16.1/archival/libipkg/ipkg_download.c 2010-04-22 19:18:12.000000000 +0200
  3344. @@ -0,0 +1,195 @@
  3345. +/* ipkg_download.c - the itsy package management system
  3346. +
  3347. + Carl D. Worth
  3348. +
  3349. + Copyright (C) 2001 University of Southern California
  3350. +
  3351. + This program is free software; you can redistribute it and/or
  3352. + modify it under the terms of the GNU General Public License as
  3353. + published by the Free Software Foundation; either version 2, or (at
  3354. + your option) any later version.
  3355. +
  3356. + This program is distributed in the hope that it will be useful, but
  3357. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3358. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3359. + General Public License for more details.
  3360. +*/
  3361. +
  3362. +#include "ipkg.h"
  3363. +#include "ipkg_download.h"
  3364. +#include "ipkg_message.h"
  3365. +
  3366. +#include "sprintf_alloc.h"
  3367. +#include "xsystem.h"
  3368. +#include "file_util.h"
  3369. +#include "str_util.h"
  3370. +
  3371. +int ipkg_download(ipkg_conf_t *conf, const char *src, const char *dest_file_name)
  3372. +{
  3373. + int err = 0;
  3374. +
  3375. + char *src_basec = strdup(src);
  3376. + char *src_base = basename(src_basec);
  3377. + char *tmp_file_location;
  3378. + char *cmd;
  3379. +
  3380. + ipkg_message(conf,IPKG_NOTICE,"Downloading %s\n", src);
  3381. +
  3382. + fflush(stdout);
  3383. +
  3384. + if (str_starts_with(src, "file:")) {
  3385. + int ret;
  3386. + const char *file_src = src + 5;
  3387. + ipkg_message(conf,IPKG_INFO,"Copying %s to %s...", file_src, dest_file_name);
  3388. + ret = file_copy(src + 5, dest_file_name);
  3389. + ipkg_message(conf,IPKG_INFO,"Done.\n");
  3390. + return ret;
  3391. + }
  3392. +
  3393. + sprintf_alloc(&tmp_file_location, "%s/%s", conf->tmp_dir, src_base);
  3394. + err = unlink(tmp_file_location);
  3395. + if (err && errno != ENOENT) {
  3396. + ipkg_message(conf,IPKG_ERROR, "%s: ERROR: failed to unlink %s: %s\n",
  3397. + __FUNCTION__, tmp_file_location, strerror(errno));
  3398. + free(tmp_file_location);
  3399. + return errno;
  3400. + }
  3401. +
  3402. + if (conf->http_proxy) {
  3403. + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: http_proxy = %s\n", conf->http_proxy);
  3404. + setenv("http_proxy", conf->http_proxy, 1);
  3405. + }
  3406. + if (conf->ftp_proxy) {
  3407. + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: ftp_proxy = %s\n", conf->ftp_proxy);
  3408. + setenv("ftp_proxy", conf->ftp_proxy, 1);
  3409. + }
  3410. + if (conf->no_proxy) {
  3411. + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: no_proxy = %s\n", conf->no_proxy);
  3412. + setenv("no_proxy", conf->no_proxy, 1);
  3413. + }
  3414. +
  3415. + /* XXX: BUG rewrite to use execvp or else busybox's internal wget -Jamey 7/23/2002 */
  3416. + sprintf_alloc(&cmd, "wget %s %s%s %s%s %s -P %s %s",
  3417. + (conf->http_proxy || conf->ftp_proxy) ? "-Y on" : "",
  3418. + conf->proxy_user ? "--proxy-user=" : "",
  3419. + conf->proxy_user ? conf->proxy_user : "",
  3420. + conf->proxy_passwd ? "--proxy-passwd=" : "",
  3421. + conf->proxy_passwd ? conf->proxy_passwd : "",
  3422. + conf->verbose_wget ? "" : "-q",
  3423. + conf->tmp_dir,
  3424. + src);
  3425. + err = xsystem(cmd);
  3426. + if (err) {
  3427. + if (err != -1) {
  3428. + ipkg_message(conf,IPKG_ERROR, "%s: ERROR: Command failed with return value %d: `%s'\n",
  3429. + __FUNCTION__, err, cmd);
  3430. + }
  3431. + unlink(tmp_file_location);
  3432. + free(tmp_file_location);
  3433. + free(src_basec);
  3434. + free(cmd);
  3435. + return EINVAL;
  3436. + }
  3437. + free(cmd);
  3438. +
  3439. + err = file_move(tmp_file_location, dest_file_name);
  3440. +
  3441. + free(tmp_file_location);
  3442. + free(src_basec);
  3443. +
  3444. + if (err) {
  3445. + return err;
  3446. + }
  3447. +
  3448. + return 0;
  3449. +}
  3450. +
  3451. +int ipkg_download_pkg(ipkg_conf_t *conf, pkg_t *pkg, const char *dir)
  3452. +{
  3453. + int err;
  3454. + char *url;
  3455. +
  3456. + if (pkg->src == NULL) {
  3457. + ipkg_message(conf,IPKG_ERROR, "ERROR: Package %s (parent %s) is not available from any configured src.\n",
  3458. + pkg->name, pkg->parent->name);
  3459. + return -1;
  3460. + }
  3461. +
  3462. + sprintf_alloc(&url, "%s/%s", pkg->src->value, pkg->filename);
  3463. +
  3464. + /* XXX: BUG: The pkg->filename might be something like
  3465. + "../../foo.ipk". While this is correct, and exactly what we
  3466. + want to use to construct url above, here we actually need to
  3467. + use just the filename part, without any directory. */
  3468. + sprintf_alloc(&pkg->local_filename, "%s/%s", dir, pkg->filename);
  3469. +
  3470. + err = ipkg_download(conf, url, pkg->local_filename);
  3471. + free(url);
  3472. +
  3473. + return err;
  3474. +}
  3475. +
  3476. +/*
  3477. + * Downloads file from url, installs in package database, return package name.
  3478. + */
  3479. +int ipkg_prepare_url_for_install(ipkg_conf_t *conf, const char *url, char **namep)
  3480. +{
  3481. + int err = 0;
  3482. + pkg_t *pkg;
  3483. + pkg = pkg_new();
  3484. + if (pkg == NULL)
  3485. + return ENOMEM;
  3486. +
  3487. + if (str_starts_with(url, "http://")
  3488. + || str_starts_with(url, "ftp://")) {
  3489. + char *tmp_file;
  3490. + char *file_basec = strdup(url);
  3491. + char *file_base = basename(file_basec);
  3492. +
  3493. + sprintf_alloc(&tmp_file, "%s/%s", conf->tmp_dir, file_base);
  3494. + err = ipkg_download(conf, url, tmp_file);
  3495. + if (err)
  3496. + return err;
  3497. +
  3498. + err = pkg_init_from_file(pkg, tmp_file);
  3499. + if (err)
  3500. + return err;
  3501. + pkg->local_filename = strdup(tmp_file);
  3502. +
  3503. + free(tmp_file);
  3504. + free(file_basec);
  3505. +
  3506. + } else if (strcmp(&url[strlen(url) - 4], IPKG_PKG_EXTENSION) == 0
  3507. + || strcmp(&url[strlen(url) - 4], DPKG_PKG_EXTENSION) == 0) {
  3508. +
  3509. + err = pkg_init_from_file(pkg, url);
  3510. + if (err)
  3511. + return err;
  3512. + pkg->local_filename = strdup(url);
  3513. + ipkg_message(conf, IPKG_DEBUG2, "Package %s provided by hand (%s).\n", pkg->name,pkg->local_filename);
  3514. + pkg->provided_by_hand = 1;
  3515. +
  3516. + } else {
  3517. + pkg_deinit(pkg);
  3518. + free(pkg);
  3519. + return 0;
  3520. + }
  3521. +
  3522. + if (!pkg->architecture) {
  3523. + ipkg_message(conf, IPKG_ERROR, "Package %s has no Architecture defined.\n", pkg->name);
  3524. + return -EINVAL;
  3525. + }
  3526. +
  3527. + pkg->dest = conf->default_dest;
  3528. + pkg->state_want = SW_INSTALL;
  3529. + pkg->state_flag |= SF_PREFER;
  3530. + pkg = hash_insert_pkg(&conf->pkg_hash, pkg, 1,conf);
  3531. + if ( pkg == NULL ){
  3532. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  3533. + return 0;
  3534. + }
  3535. + if (namep) {
  3536. + *namep = strdup(pkg->name);
  3537. + }
  3538. + return 0;
  3539. +}
  3540. diff -Nur busybox-1.16.1.orig/archival/libipkg/ipkg_download.h busybox-1.16.1/archival/libipkg/ipkg_download.h
  3541. --- busybox-1.16.1.orig/archival/libipkg/ipkg_download.h 1970-01-01 01:00:00.000000000 +0100
  3542. +++ busybox-1.16.1/archival/libipkg/ipkg_download.h 2010-04-22 19:18:12.000000000 +0200
  3543. @@ -0,0 +1,30 @@
  3544. +/* ipkg_download.h - the itsy package management system
  3545. +
  3546. + Carl D. Worth
  3547. +
  3548. + Copyright (C) 2001 University of Southern California
  3549. +
  3550. + This program is free software; you can redistribute it and/or
  3551. + modify it under the terms of the GNU General Public License as
  3552. + published by the Free Software Foundation; either version 2, or (at
  3553. + your option) any later version.
  3554. +
  3555. + This program is distributed in the hope that it will be useful, but
  3556. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3557. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3558. + General Public License for more details.
  3559. +*/
  3560. +
  3561. +#ifndef IPKG_DOWNLOAD_H
  3562. +#define IPKG_DOWNLOAD_H
  3563. +
  3564. +#include "ipkg_conf.h"
  3565. +
  3566. +int ipkg_download(ipkg_conf_t *conf, const char *src, const char *dest_file_name);
  3567. +int ipkg_download_pkg(ipkg_conf_t *conf, pkg_t *pkg, const char *dir);
  3568. +/*
  3569. + * Downloads file from url, installs in package database, return package name.
  3570. + */
  3571. +int ipkg_prepare_url_for_install(ipkg_conf_t *conf, const char *url, char **namep);
  3572. +
  3573. +#endif
  3574. diff -Nur busybox-1.16.1.orig/archival/libipkg/ipkg.h busybox-1.16.1/archival/libipkg/ipkg.h
  3575. --- busybox-1.16.1.orig/archival/libipkg/ipkg.h 1970-01-01 01:00:00.000000000 +0100
  3576. +++ busybox-1.16.1/archival/libipkg/ipkg.h 2010-04-22 19:18:12.000000000 +0200
  3577. @@ -0,0 +1,68 @@
  3578. +/* ipkg.h - the itsy package management system
  3579. +
  3580. + Carl D. Worth
  3581. +
  3582. + Copyright (C) 2001 University of Southern California
  3583. +
  3584. + This program is free software; you can redistribute it and/or
  3585. + modify it under the terms of the GNU General Public License as
  3586. + published by the Free Software Foundation; either version 2, or (at
  3587. + your option) any later version.
  3588. +
  3589. + This program is distributed in the hope that it will be useful, but
  3590. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3591. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3592. + General Public License for more details.
  3593. +*/
  3594. +
  3595. +#ifndef IPKG_H
  3596. +#define IPKG_H
  3597. +
  3598. +#include "libbb.h"
  3599. +
  3600. +#include "ipkg_includes.h"
  3601. +#include "ipkg_conf.h"
  3602. +#include "ipkg_message.h"
  3603. +
  3604. +#define IPKG_PKG_EXTENSION ".ipk"
  3605. +#define DPKG_PKG_EXTENSION ".deb"
  3606. +
  3607. +#define IPKG_LEGAL_PKG_NAME_CHARS "abcdefghijklmnopqrstuvwxyz0123456789.+-"
  3608. +#define IPKG_PKG_VERSION_SEP_CHAR '_'
  3609. +
  3610. +#define IPKG_STATE_DIR_PREFIX IPKGLIBDIR"/ipkg"
  3611. +#define IPKG_LISTS_DIR_SUFFIX "lists"
  3612. +#define IPKG_INFO_DIR_SUFFIX "info"
  3613. +#define IPKG_STATUS_FILE_SUFFIX "status"
  3614. +
  3615. +#define IPKG_BACKUP_SUFFIX "-ipkg.backup"
  3616. +
  3617. +#define IPKG_LIST_DESCRIPTION_LENGTH 128
  3618. +
  3619. +#define IPKG_VERSION "1.00"
  3620. +
  3621. +
  3622. +enum ipkg_error {
  3623. + IPKG_SUCCESS = 0,
  3624. + IPKG_PKG_DEPS_UNSATISFIED,
  3625. + IPKG_PKG_IS_ESSENTIAL,
  3626. + IPKG_PKG_HAS_DEPENDENTS,
  3627. + IPKG_PKG_HAS_NO_CANDIDATE
  3628. +};
  3629. +typedef enum ipkg_error ipkg_error_t;
  3630. +
  3631. +extern int ipkg_state_changed;
  3632. +
  3633. +
  3634. +struct errlist {
  3635. + char * errmsg;
  3636. + struct errlist * next;
  3637. +} ;
  3638. +
  3639. +extern struct errlist* error_list;
  3640. +
  3641. +extern ipkg_conf_t *global_conf;
  3642. +
  3643. +typedef enum { HASH_SHA1, HASH_MD5 } hash_algo_t;
  3644. +
  3645. +#endif
  3646. diff -Nur busybox-1.16.1.orig/archival/libipkg/ipkg_includes.h busybox-1.16.1/archival/libipkg/ipkg_includes.h
  3647. --- busybox-1.16.1.orig/archival/libipkg/ipkg_includes.h 1970-01-01 01:00:00.000000000 +0100
  3648. +++ busybox-1.16.1/archival/libipkg/ipkg_includes.h 2010-04-22 19:18:12.000000000 +0200
  3649. @@ -0,0 +1,79 @@
  3650. +#ifndef IPKG_INCLUDES_H
  3651. +#define IPKG_INCLUDES_H
  3652. +
  3653. +/* Define to 1 if you have the <memory.h> header file. */
  3654. +#define HAVE_MEMORY_H 1
  3655. +
  3656. +/* Define to 1 if you have the <regex.h> header file. */
  3657. +#define HAVE_REGEX_H 1
  3658. +
  3659. +/* Define to 1 if you have the <stdlib.h> header file. */
  3660. +#define HAVE_STDLIB_H 1
  3661. +
  3662. +/* Define to 1 if you have the <strings.h> header file. */
  3663. +#define HAVE_STRINGS_H 1
  3664. +
  3665. +/* Define to 1 if you have the <string.h> header file. */
  3666. +#define HAVE_STRING_H 1
  3667. +
  3668. +/* Define to 1 if you have the <sys/stat.h> header file. */
  3669. +#define HAVE_SYS_STAT_H 1
  3670. +
  3671. +/* Define to 1 if you have <sys/wait.h> that is POSIX.1 compatible. */
  3672. +#define HAVE_SYS_WAIT_H 1
  3673. +
  3674. +/* Define to 1 if you have the <unistd.h> header file. */
  3675. +#define HAVE_UNISTD_H 1
  3676. +
  3677. +/* Define to 1 if you have the ANSI C header files. */
  3678. +#define STDC_HEADERS 1
  3679. +
  3680. +
  3681. +#include <stdio.h>
  3682. +
  3683. +#if STDC_HEADERS
  3684. +# include <stdlib.h>
  3685. +# include <stdarg.h>
  3686. +# include <stddef.h>
  3687. +# include <ctype.h>
  3688. +# include <errno.h>
  3689. +#else
  3690. +# if HAVE_STDLIB_H
  3691. +# include <stdlib.h>
  3692. +# endif
  3693. +#endif
  3694. +
  3695. +#if HAVE_REGEX_H
  3696. +# include <regex.h>
  3697. +#endif
  3698. +
  3699. +#if HAVE_STRING_H
  3700. +# if !STDC_HEADERS && HAVE_MEMORY_H
  3701. +# include <memory.h>
  3702. +# endif
  3703. +/* XXX: What's the right way to pick up GNU's strndup declaration? */
  3704. +# if __GNUC__
  3705. +# define __USE_GNU 1
  3706. +# endif
  3707. +# include <string.h>
  3708. +# undef __USE_GNU
  3709. +#endif
  3710. +
  3711. +#if HAVE_STRINGS_H
  3712. +# include <strings.h>
  3713. +#endif
  3714. +
  3715. +#if HAVE_SYS_STAT_H
  3716. +# include <sys/stat.h>
  3717. +#endif
  3718. +
  3719. +#if HAVE_SYS_WAIT_H
  3720. +# include <sys/wait.h>
  3721. +#endif
  3722. +
  3723. +#if HAVE_UNISTD_H
  3724. +# include <sys/types.h>
  3725. +# include <unistd.h>
  3726. +#endif
  3727. +
  3728. +#endif /* IPKG_INCLUDES_H */
  3729. diff -Nur busybox-1.16.1.orig/archival/libipkg/ipkg_install.c busybox-1.16.1/archival/libipkg/ipkg_install.c
  3730. --- busybox-1.16.1.orig/archival/libipkg/ipkg_install.c 1970-01-01 01:00:00.000000000 +0100
  3731. +++ busybox-1.16.1/archival/libipkg/ipkg_install.c 2010-04-22 19:18:12.000000000 +0200
  3732. @@ -0,0 +1,1982 @@
  3733. +/* ipkg_install.c - the itsy package management system
  3734. +
  3735. + Carl D. Worth
  3736. +
  3737. + Copyright (C) 2001 University of Southern California
  3738. +
  3739. + This program is free software; you can redistribute it and/or
  3740. + modify it under the terms of the GNU General Public License as
  3741. + published by the Free Software Foundation; either version 2, or (at
  3742. + your option) any later version.
  3743. +
  3744. + This program is distributed in the hope that it will be useful, but
  3745. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3746. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3747. + General Public License for more details.
  3748. +*/
  3749. +
  3750. +#include "ipkg.h"
  3751. +#include <errno.h>
  3752. +#include <dirent.h>
  3753. +#include <glob.h>
  3754. +#include <time.h>
  3755. +#include <signal.h>
  3756. +typedef void (*sighandler_t)(int);
  3757. +
  3758. +#include "pkg.h"
  3759. +#include "pkg_hash.h"
  3760. +#include "pkg_extract.h"
  3761. +
  3762. +#include "ipkg_install.h"
  3763. +#include "ipkg_configure.h"
  3764. +#include "ipkg_download.h"
  3765. +#include "ipkg_remove.h"
  3766. +
  3767. +#include "ipkg_utils.h"
  3768. +#include "ipkg_message.h"
  3769. +
  3770. +#include "sprintf_alloc.h"
  3771. +#include "file_util.h"
  3772. +#include "str_util.h"
  3773. +#include "xsystem.h"
  3774. +#include "user.h"
  3775. +
  3776. +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg);
  3777. +static int verify_pkg_installable(ipkg_conf_t *conf, pkg_t *pkg);
  3778. +static int unpack_pkg_control_files(ipkg_conf_t *conf, pkg_t *pkg);
  3779. +
  3780. +/*
  3781. +static int prerm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3782. +static int prerm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3783. +static int prerm_deconfigure_conflictors(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors);
  3784. +static int prerm_deconfigure_conflictors_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors);
  3785. +static int preinst_configure_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3786. +static int check_data_file_clashes_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3787. +static int postrm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3788. +static int remove_disappeared(ipkg_conf_t *conf, pkg_t *pkg);
  3789. +static int postrm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3790. +*/
  3791. +static int preinst_configure(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3792. +static int check_data_file_clashes(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3793. +static int check_data_file_clashes_change(ipkg_conf_t *conf, pkg_t *pkg);
  3794. +static int backup_modified_conffiles(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3795. +static int backup_modified_conffiles_unwind(pkg_t *pkg, pkg_t *old_pkg);
  3796. +
  3797. +static int remove_obsolesced_files(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3798. +static int install_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3799. +static int install_data_files(ipkg_conf_t *conf, pkg_t *pkg);
  3800. +static int resolve_conffiles(ipkg_conf_t *conf, pkg_t *pkg);
  3801. +
  3802. +static int cleanup_temporary_files(ipkg_conf_t *conf, pkg_t *pkg);
  3803. +
  3804. +static int user_prefers_old_conffile(const char *file, const char *backup);
  3805. +
  3806. +static char *backup_filename_alloc(const char *file_name);
  3807. +static int backup_make_backup(ipkg_conf_t *conf, const char *file_name);
  3808. +static int backup_exists_for(const char *file_name);
  3809. +static int backup_remove(const char *file_name);
  3810. +
  3811. +int pkg_get_installed_replacees(pkg_t *pkg, pkg_vec_t *installed_replacees);
  3812. +int pkg_remove_installed_replacees(ipkg_conf_t *conf, pkg_vec_t *replacees);
  3813. +int pkg_remove_installed_replacees_unwind(ipkg_conf_t *conf, pkg_vec_t *replacees);
  3814. +
  3815. +int ipkg_install_from_file(ipkg_conf_t *conf, const char *filename)
  3816. +{
  3817. + int err, cmp;
  3818. + pkg_t *pkg, *old;
  3819. + char *old_version, *new_version;
  3820. +
  3821. + pkg = pkg_new();
  3822. + if (pkg == NULL) {
  3823. + return ENOMEM;
  3824. + }
  3825. +
  3826. + err = pkg_init_from_file(pkg, filename);
  3827. + if (err) {
  3828. + return err;
  3829. + }
  3830. +
  3831. + if (!pkg->architecture) {
  3832. + ipkg_message(conf, IPKG_ERROR, "Package %s has no Architecture defined.\n", pkg->name);
  3833. + return -EINVAL;
  3834. + }
  3835. +
  3836. + /* XXX: CLEANUP: hash_insert_pkg has a nasty side effect of possibly
  3837. + freeing the pkg that we pass in. It might be nice to clean this up
  3838. + if possible. */
  3839. + pkg = hash_insert_pkg(&conf->pkg_hash, pkg, 1,conf);
  3840. + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name);
  3841. +
  3842. + pkg->local_filename = strdup(filename);
  3843. +
  3844. + if (old) {
  3845. + old_version = pkg_version_str_alloc(old);
  3846. + new_version = pkg_version_str_alloc(pkg);
  3847. +
  3848. + cmp = pkg_compare_versions(old, pkg);
  3849. + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
  3850. + cmp = -1 ; /* then we force ipkg to downgrade */
  3851. + /* We need to use a value < 0 because in the 0 case we are asking to */
  3852. + /* reinstall, and some check could fail asking the "force-reinstall" option */
  3853. + }
  3854. + if (cmp > 0) {
  3855. + ipkg_message(conf, IPKG_NOTICE,
  3856. + "Not downgrading package %s on %s from %s to %s.\n",
  3857. + old->name, old->dest->name, old_version, new_version);
  3858. + pkg->state_want = SW_DEINSTALL;
  3859. + pkg->state_flag |= SF_OBSOLETE;
  3860. + free(old_version);
  3861. + free(new_version);
  3862. + return 0;
  3863. + } else {
  3864. + free(old_version);
  3865. + free(new_version);
  3866. + }
  3867. + }
  3868. +
  3869. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
  3870. + return ipkg_install_pkg(conf, pkg,0);
  3871. +}
  3872. +
  3873. +ipkg_error_t ipkg_install_by_name(ipkg_conf_t *conf, const char *pkg_name)
  3874. +{
  3875. + int cmp;
  3876. + pkg_t *old, *new;
  3877. + char *old_version, *new_version;
  3878. +
  3879. + ipkg_message(conf, IPKG_DEBUG2, " Getting old from pkg_hash_fetch \n" );
  3880. + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg_name);
  3881. + if ( old )
  3882. + ipkg_message(conf, IPKG_DEBUG2, " Old versions from pkg_hash_fetch %s \n", old->version );
  3883. +
  3884. + ipkg_message(conf, IPKG_DEBUG2, " Getting new from pkg_hash_fetch \n" );
  3885. + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, pkg_name);
  3886. + if ( new )
  3887. + ipkg_message(conf, IPKG_DEBUG2, " New versions from pkg_hash_fetch %s \n", new->version );
  3888. +
  3889. +/* Pigi Basically here is broken the version stuff.
  3890. + What's happening is that nothing provide the version to differents
  3891. + functions, so the returned struct is always the latest.
  3892. + That's why the install by name don't work.
  3893. +*/
  3894. + ipkg_message(conf, IPKG_DEBUG2, " Versions from pkg_hash_fetch in %s ", __FUNCTION__ );
  3895. +
  3896. + if ( old )
  3897. + ipkg_message(conf, IPKG_DEBUG2, " old %s ", old->version );
  3898. + if ( new )
  3899. + ipkg_message(conf, IPKG_DEBUG2, " new %s ", new->version );
  3900. + ipkg_message(conf, IPKG_DEBUG2, " \n");
  3901. +
  3902. + if (new == NULL) {
  3903. + return IPKG_PKG_HAS_NO_CANDIDATE;
  3904. + }
  3905. +
  3906. + new->state_flag |= SF_USER;
  3907. + if (old) {
  3908. + old_version = pkg_version_str_alloc(old);
  3909. + new_version = pkg_version_str_alloc(new);
  3910. +
  3911. + cmp = pkg_compare_versions(old, new);
  3912. + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
  3913. + ipkg_message(conf, IPKG_DEBUG, " Forcing downgrade \n");
  3914. + cmp = -1 ; /* then we force ipkg to downgrade */
  3915. + /* We need to use a value < 0 because in the 0 case we are asking to */
  3916. + /* reinstall, and some check could fail asking the "force-reinstall" option */
  3917. + }
  3918. + ipkg_message(conf, IPKG_DEBUG,
  3919. + "Comparing visible versions of pkg %s:"
  3920. + "\n\t%s is installed "
  3921. + "\n\t%s is available "
  3922. + "\n\t%d was comparison result\n",
  3923. + pkg_name, old_version, new_version, cmp);
  3924. + if (cmp == 0 && !conf->force_reinstall) {
  3925. + ipkg_message(conf, IPKG_NOTICE,
  3926. + "Package %s (%s) installed in %s is up to date.\n",
  3927. + old->name, old_version, old->dest->name);
  3928. + free(old_version);
  3929. + free(new_version);
  3930. + return 0;
  3931. + } else if (cmp > 0) {
  3932. + ipkg_message(conf, IPKG_NOTICE,
  3933. + "Not downgrading package %s on %s from %s to %s.\n",
  3934. + old->name, old->dest->name, old_version, new_version);
  3935. + free(old_version);
  3936. + free(new_version);
  3937. + return 0;
  3938. + } else if (cmp < 0) {
  3939. + new->dest = old->dest;
  3940. + old->state_want = SW_DEINSTALL; /* Here probably the problem for bug 1277 */
  3941. + }
  3942. + }
  3943. +
  3944. + /* XXX: CLEANUP: The error code of ipkg_install_by_name is really
  3945. + supposed to be an ipkg_error_t, but ipkg_install_pkg could
  3946. + return any kind of integer, (might be errno from a syscall,
  3947. + etc.). This is a real mess and will need to be cleaned up if
  3948. + anyone ever wants to make a nice libipkg. */
  3949. +
  3950. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
  3951. + return ipkg_install_pkg(conf, new,0);
  3952. +}
  3953. +
  3954. +ipkg_error_t ipkg_install_multi_by_name(ipkg_conf_t *conf, const char *pkg_name)
  3955. +{
  3956. + abstract_pkg_vec_t *providers = pkg_hash_fetch_all_installation_candidates (&conf->pkg_hash, pkg_name);
  3957. + int i;
  3958. + ipkg_error_t err;
  3959. + abstract_pkg_t *ppkg ;
  3960. +
  3961. + if (providers == NULL)
  3962. + return IPKG_PKG_HAS_NO_CANDIDATE;
  3963. +
  3964. + for (i = 0; i < providers->len; i++) {
  3965. + ppkg = abstract_pkg_vec_get(providers, i);
  3966. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_by_name %d \n",__FUNCTION__, i);
  3967. + err = ipkg_install_by_name(conf, ppkg->name);
  3968. + if (err)
  3969. + return err;
  3970. +/* XXX Maybe ppkg should be freed ? */
  3971. + }
  3972. + return 0;
  3973. +}
  3974. +
  3975. +/*
  3976. + * Walk dependence graph starting with pkg, collect packages to be
  3977. + * installed into pkgs_needed, in dependence order.
  3978. + */
  3979. +int pkg_mark_dependencies_for_installation(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *pkgs_needed)
  3980. +{
  3981. + int i, err;
  3982. + pkg_vec_t *depends = pkg_vec_alloc();
  3983. + char **unresolved = NULL;
  3984. + int ndepends;
  3985. +
  3986. + ndepends = pkg_hash_fetch_unsatisfied_dependencies(conf,
  3987. + pkg, depends,
  3988. + &unresolved);
  3989. +
  3990. + if (unresolved) {
  3991. + ipkg_message(conf, IPKG_ERROR,
  3992. + "%s: Cannot satisfy the following dependencies for %s:\n\t",
  3993. + conf->force_depends ? "Warning" : "ERROR", pkg->name);
  3994. + while (*unresolved) {
  3995. + ipkg_message(conf, IPKG_ERROR, " %s", *unresolved);
  3996. + unresolved++;
  3997. + }
  3998. + ipkg_message(conf, IPKG_ERROR, "\n");
  3999. + if (! conf->force_depends) {
  4000. + ipkg_message(conf, IPKG_INFO,
  4001. + "This could mean that your package list is out of date or that the packages\n"
  4002. + "mentioned above do not yet exist (try 'ipkg update'). To proceed in spite\n"
  4003. + "of this problem try again with the '-force-depends' option.\n");
  4004. + pkg_vec_free(depends);
  4005. + return IPKG_PKG_DEPS_UNSATISFIED;
  4006. + }
  4007. + }
  4008. +
  4009. + if (ndepends <= 0) {
  4010. + pkg_vec_free(depends);
  4011. + return 0;
  4012. + }
  4013. +
  4014. + for (i = 0; i < depends->len; i++) {
  4015. + pkg_t *dep = depends->pkgs[i];
  4016. + /* The package was uninstalled when we started, but another
  4017. + dep earlier in this loop may have depended on it and pulled
  4018. + it in, so check first. */
  4019. + if ((dep->state_status != SS_INSTALLED)
  4020. + && (dep->state_status != SS_UNPACKED)
  4021. + && (dep->state_want != SW_INSTALL)) {
  4022. +
  4023. + /* Mark packages as to-be-installed */
  4024. + dep->state_want = SW_INSTALL;
  4025. +
  4026. + /* Dependencies should be installed the same place as pkg */
  4027. + if (dep->dest == NULL) {
  4028. + dep->dest = pkg->dest;
  4029. + }
  4030. +
  4031. + err = pkg_mark_dependencies_for_installation(conf, dep, pkgs_needed);
  4032. + if (err) {
  4033. + pkg_vec_free(depends);
  4034. + return err;
  4035. + }
  4036. + }
  4037. + }
  4038. + if (pkgs_needed)
  4039. + pkg_vec_insert(pkgs_needed, pkg);
  4040. +
  4041. + pkg_vec_free(depends);
  4042. +
  4043. + return 0;
  4044. +}
  4045. +
  4046. +int name_mark_dependencies_for_installation(ipkg_conf_t *conf, const char *pkg_name, pkg_vec_t *pkgs_needed)
  4047. +{
  4048. + int cmp;
  4049. + pkg_t *old, *new;
  4050. + char *old_version, *new_version;
  4051. +
  4052. + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg_name);
  4053. +
  4054. + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, pkg_name);
  4055. + if (new == NULL) {
  4056. + return IPKG_PKG_HAS_NO_CANDIDATE;
  4057. + }
  4058. + if (old) {
  4059. + old_version = pkg_version_str_alloc(old);
  4060. + new_version = pkg_version_str_alloc(new);
  4061. +
  4062. + cmp = pkg_compare_versions(old, new);
  4063. + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
  4064. + ipkg_message(conf, IPKG_DEBUG, " Forcing downgrade ");
  4065. + cmp = -1 ; /* then we force ipkg to downgrade */
  4066. + /* We need to use a value < 0 because in the 0 case we are asking to */
  4067. + /* reinstall, and some check could fail asking the "force-reinstall" option */
  4068. + }
  4069. + ipkg_message(conf, IPKG_DEBUG,
  4070. + "comparing visible versions of pkg %s:"
  4071. + "\n\t%s is installed "
  4072. + "\n\t%s is available "
  4073. + "\n\t%d was comparison result\n",
  4074. + pkg_name, old_version, new_version, cmp);
  4075. + if (cmp == 0 && !conf->force_reinstall) {
  4076. + ipkg_message(conf, IPKG_NOTICE,
  4077. + "Package %s (%s) installed in %s is up to date.\n",
  4078. + old->name, old_version, old->dest->name);
  4079. + free(old_version);
  4080. + free(new_version);
  4081. + return 0;
  4082. + } else if (cmp > 0) {
  4083. + ipkg_message(conf, IPKG_NOTICE,
  4084. + "Not downgrading package %s on %s from %s to %s.\n",
  4085. + old->name, old->dest->name, old_version, new_version);
  4086. + free(old_version);
  4087. + free(new_version);
  4088. + return 0;
  4089. + } else if (cmp < 0) {
  4090. + new->dest = old->dest;
  4091. + old->state_want = SW_DEINSTALL;
  4092. + old->state_flag |= SF_OBSOLETE;
  4093. + }
  4094. + }
  4095. + return pkg_mark_dependencies_for_installation(conf, new, pkgs_needed);
  4096. +}
  4097. +
  4098. +
  4099. +
  4100. +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg)
  4101. +{
  4102. + int i, err;
  4103. + pkg_vec_t *depends = pkg_vec_alloc();
  4104. + pkg_t *dep;
  4105. + char **unresolved = NULL;
  4106. + int ndepends;
  4107. +
  4108. + ndepends = pkg_hash_fetch_unsatisfied_dependencies(conf,
  4109. + pkg, depends,
  4110. + &unresolved);
  4111. +
  4112. + if (unresolved) {
  4113. + ipkg_message(conf, IPKG_ERROR,
  4114. + "%s: Cannot satisfy the following dependencies for %s:\n\t",
  4115. + conf->force_depends ? "Warning" : "ERROR", pkg->name);
  4116. + while (*unresolved) {
  4117. + ipkg_message(conf, IPKG_ERROR, " %s", *unresolved);
  4118. + unresolved++;
  4119. + }
  4120. + ipkg_message(conf, IPKG_ERROR, "\n");
  4121. + if (! conf->force_depends) {
  4122. + ipkg_message(conf, IPKG_INFO,
  4123. + "This could mean that your package list is out of date or that the packages\n"
  4124. + "mentioned above do not yet exist (try 'ipkg update'). To proceed in spite\n"
  4125. + "of this problem try again with the '-force-depends' option.\n");
  4126. + pkg_vec_free(depends);
  4127. + return IPKG_PKG_DEPS_UNSATISFIED;
  4128. + }
  4129. + }
  4130. +
  4131. + if (ndepends <= 0) {
  4132. + return 0;
  4133. + }
  4134. +
  4135. + /* Mark packages as to-be-installed */
  4136. + for (i=0; i < depends->len; i++) {
  4137. + /* Dependencies should be installed the same place as pkg */
  4138. + if (depends->pkgs[i]->dest == NULL) {
  4139. + depends->pkgs[i]->dest = pkg->dest;
  4140. + }
  4141. + depends->pkgs[i]->state_want = SW_INSTALL;
  4142. + }
  4143. +
  4144. + for (i = 0; i < depends->len; i++) {
  4145. + dep = depends->pkgs[i];
  4146. + /* The package was uninstalled when we started, but another
  4147. + dep earlier in this loop may have depended on it and pulled
  4148. + it in, so check first. */
  4149. + if ((dep->state_status != SS_INSTALLED)
  4150. + && (dep->state_status != SS_UNPACKED)) {
  4151. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
  4152. + err = ipkg_install_pkg(conf, dep,0);
  4153. + if (err) {
  4154. + pkg_vec_free(depends);
  4155. + return err;
  4156. + }
  4157. + }
  4158. + }
  4159. +
  4160. + pkg_vec_free(depends);
  4161. +
  4162. + return 0;
  4163. +}
  4164. +
  4165. +
  4166. +/* check all packages have their dependences satisfied, e.g., in case an upgraded package split */
  4167. +int ipkg_satisfy_all_dependences(ipkg_conf_t *conf)
  4168. +{
  4169. + if (conf->nodeps == 0) {
  4170. + int i;
  4171. + pkg_vec_t *installed = pkg_vec_alloc();
  4172. + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
  4173. + for (i = 0; i < installed->len; i++) {
  4174. + pkg_t *pkg = installed->pkgs[i];
  4175. + satisfy_dependencies_for(conf, pkg);
  4176. + }
  4177. + pkg_vec_free(installed);
  4178. + }
  4179. + return 0;
  4180. +}
  4181. +
  4182. +
  4183. +
  4184. +static int check_conflicts_for(ipkg_conf_t *conf, pkg_t *pkg)
  4185. +{
  4186. + int i;
  4187. + pkg_vec_t *conflicts = NULL;
  4188. + int level;
  4189. + const char *prefix;
  4190. + if (conf->force_depends) {
  4191. + level = IPKG_NOTICE;
  4192. + prefix = "Warning";
  4193. + } else {
  4194. + level = IPKG_ERROR;
  4195. + prefix = "ERROR";
  4196. + }
  4197. +
  4198. + if (!conf->force_depends)
  4199. + conflicts = (pkg_vec_t *)pkg_hash_fetch_conflicts(pkg);
  4200. +
  4201. + if (conflicts) {
  4202. + ipkg_message(conf, level,
  4203. + "%s: The following packages conflict with %s:\n\t", prefix, pkg->name);
  4204. + i = 0;
  4205. + while (i < conflicts->len)
  4206. + ipkg_message(conf, level, " %s", conflicts->pkgs[i++]->name);
  4207. + ipkg_message(conf, level, "\n");
  4208. + pkg_vec_free(conflicts);
  4209. + return IPKG_PKG_DEPS_UNSATISFIED;
  4210. + }
  4211. + return 0;
  4212. +}
  4213. +
  4214. +static int update_file_ownership(ipkg_conf_t *conf, pkg_t *new_pkg, pkg_t *old_pkg)
  4215. +{
  4216. + str_list_t *new_list = pkg_get_installed_files(new_pkg);
  4217. + str_list_elt_t *iter;
  4218. +
  4219. + for (iter = new_list->head; iter; iter = iter->next) {
  4220. + char *new_file = iter->data;
  4221. + pkg_t *owner = file_hash_get_file_owner(conf, new_file);
  4222. + if (!new_file)
  4223. + ipkg_message(conf, IPKG_ERROR, "Null new_file for new_pkg=%s\n", new_pkg->name);
  4224. + if (!owner || (owner == old_pkg))
  4225. + file_hash_set_file_owner(conf, new_file, new_pkg);
  4226. + }
  4227. + if (old_pkg) {
  4228. + str_list_t *old_list = pkg_get_installed_files(old_pkg);
  4229. + for (iter = old_list->head; iter; iter = iter->next) {
  4230. + char *old_file = iter->data;
  4231. + pkg_t *owner = file_hash_get_file_owner(conf, old_file);
  4232. + if (owner == old_pkg) {
  4233. + /* obsolete */
  4234. + hash_table_insert(&conf->obs_file_hash, old_file, old_pkg);
  4235. + }
  4236. + }
  4237. + }
  4238. + return 0;
  4239. +}
  4240. +
  4241. +static int verify_pkg_installable(ipkg_conf_t *conf, pkg_t *pkg)
  4242. +{
  4243. + /* XXX: FEATURE: Anything else needed here? Maybe a check on free space? */
  4244. +
  4245. + /* sma 6.20.02: yup; here's the first bit */
  4246. + /*
  4247. + * XXX: BUG easy for cworth
  4248. + * 1) please point the call below to the correct current root destination
  4249. + * 2) we need to resolve how to check the required space for a pending pkg,
  4250. + * my diddling with the .ipk file size below isn't going to cut it.
  4251. + * 3) return a proper error code instead of 1
  4252. + */
  4253. + int comp_size, blocks_available;
  4254. +
  4255. + if (!conf->force_space && pkg->installed_size != NULL) {
  4256. + blocks_available = get_available_blocks(conf->default_dest->root_dir);
  4257. +
  4258. + comp_size = strtoul(pkg->installed_size, NULL, 0);
  4259. + /* round up a blocks count without doing fancy-but-slow casting jazz */
  4260. + comp_size = (int)((comp_size + 1023) / 1024);
  4261. +
  4262. + if (comp_size >= blocks_available) {
  4263. + ipkg_message(conf, IPKG_ERROR,
  4264. + "Only have %d available blocks on filesystem %s, pkg %s needs %d\n",
  4265. + blocks_available, conf->default_dest->root_dir, pkg->name, comp_size);
  4266. + return ENOSPC;
  4267. + }
  4268. + }
  4269. + return 0;
  4270. +}
  4271. +
  4272. +static int unpack_pkg_control_files(ipkg_conf_t *conf, pkg_t *pkg)
  4273. +{
  4274. + int err;
  4275. + char *conffiles_file_name;
  4276. + char *root_dir;
  4277. + FILE *conffiles_file;
  4278. +
  4279. + sprintf_alloc(&pkg->tmp_unpack_dir, "%s/%s-XXXXXX", conf->tmp_dir, pkg->name);
  4280. +
  4281. + pkg->tmp_unpack_dir = mkdtemp(pkg->tmp_unpack_dir);
  4282. + if (pkg->tmp_unpack_dir == NULL) {
  4283. + ipkg_message(conf, IPKG_ERROR,
  4284. + "%s: Failed to create temporary directory '%s': %s\n",
  4285. + __FUNCTION__, pkg->tmp_unpack_dir, strerror(errno));
  4286. + return errno;
  4287. + }
  4288. +
  4289. + err = pkg_extract_control_files_to_dir(pkg, pkg->tmp_unpack_dir);
  4290. + if (err) {
  4291. + return err;
  4292. + }
  4293. +
  4294. + /* XXX: CLEANUP: There might be a cleaner place to read in the
  4295. + conffiles. Seems like I should be able to get everything to go
  4296. + through pkg_init_from_file. If so, maybe it would make sense to
  4297. + move all of unpack_pkg_control_files to that function. */
  4298. +
  4299. + /* Don't need to re-read conffiles if we already have it */
  4300. + if (pkg->conffiles.head) {
  4301. + return 0;
  4302. + }
  4303. +
  4304. + sprintf_alloc(&conffiles_file_name, "%s/conffiles", pkg->tmp_unpack_dir);
  4305. + if (! file_exists(conffiles_file_name)) {
  4306. + free(conffiles_file_name);
  4307. + return 0;
  4308. + }
  4309. +
  4310. + conffiles_file = fopen(conffiles_file_name, "r");
  4311. + if (conffiles_file == NULL) {
  4312. + fprintf(stderr, "%s: failed to open %s: %s\n",
  4313. + __FUNCTION__, conffiles_file_name, strerror(errno));
  4314. + free(conffiles_file_name);
  4315. + return errno;
  4316. + }
  4317. + free(conffiles_file_name);
  4318. +
  4319. + while (1) {
  4320. + char *cf_name;
  4321. + char *cf_name_in_dest;
  4322. +
  4323. + cf_name = file_read_line_alloc(conffiles_file);
  4324. + if (cf_name == NULL) {
  4325. + break;
  4326. + }
  4327. + str_chomp(cf_name);
  4328. + if (cf_name[0] == '\0') {
  4329. + continue;
  4330. + }
  4331. +
  4332. + /* Prepend dest->root_dir to conffile name.
  4333. + Take pains to avoid multiple slashes. */
  4334. + root_dir = pkg->dest->root_dir;
  4335. + if (conf->offline_root)
  4336. + /* skip the offline_root prefix */
  4337. + root_dir = pkg->dest->root_dir + strlen(conf->offline_root);
  4338. + sprintf_alloc(&cf_name_in_dest, "%s%s", root_dir,
  4339. + cf_name[0] == '/' ? (cf_name + 1) : cf_name);
  4340. +
  4341. + /* Can't get an md5sum now, (file isn't extracted yet).
  4342. + We'll wait until resolve_conffiles */
  4343. + conffile_list_append(&pkg->conffiles, cf_name_in_dest, NULL);
  4344. +
  4345. + free(cf_name);
  4346. + free(cf_name_in_dest);
  4347. + }
  4348. +
  4349. + fclose(conffiles_file);
  4350. +
  4351. + return 0;
  4352. +}
  4353. +
  4354. +/* returns number of installed replacees */
  4355. +int pkg_get_installed_replacees(pkg_t *pkg, pkg_vec_t *installed_replacees)
  4356. +{
  4357. + abstract_pkg_t **replaces = pkg->replaces;
  4358. + int replaces_count = pkg->replaces_count;
  4359. + int i, j;
  4360. + for (i = 0; i < replaces_count; i++) {
  4361. + abstract_pkg_t *ab_pkg = replaces[i];
  4362. + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
  4363. + if (pkg_vec) {
  4364. + for (j = 0; j < pkg_vec->len; j++) {
  4365. + pkg_t *replacee = pkg_vec->pkgs[j];
  4366. + if (!pkg_conflicts(pkg, replacee))
  4367. + continue;
  4368. + if (replacee->state_status == SS_INSTALLED) {
  4369. + pkg_vec_insert(installed_replacees, replacee);
  4370. + }
  4371. + }
  4372. + }
  4373. + }
  4374. + return installed_replacees->len;
  4375. +}
  4376. +
  4377. +int pkg_remove_installed_replacees(ipkg_conf_t *conf, pkg_vec_t *replacees)
  4378. +{
  4379. + int i;
  4380. + int replaces_count = replacees->len;
  4381. + for (i = 0; i < replaces_count; i++) {
  4382. + pkg_t *replacee = replacees->pkgs[i];
  4383. + int err;
  4384. + replacee->state_flag |= SF_REPLACE; /* flag it so remove won't complain */
  4385. + err = ipkg_remove_pkg(conf, replacee,0);
  4386. + if (err)
  4387. + return err;
  4388. + }
  4389. + return 0;
  4390. +}
  4391. +
  4392. +/* to unwind the removal: make sure they are installed */
  4393. +int pkg_remove_installed_replacees_unwind(ipkg_conf_t *conf, pkg_vec_t *replacees)
  4394. +{
  4395. + int i, err;
  4396. + int replaces_count = replacees->len;
  4397. + for (i = 0; i < replaces_count; i++) {
  4398. + pkg_t *replacee = replacees->pkgs[i];
  4399. + if (replacee->state_status != SS_INSTALLED) {
  4400. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
  4401. + err = ipkg_install_pkg(conf, replacee,0);
  4402. + if (err)
  4403. + return err;
  4404. + }
  4405. + }
  4406. + return 0;
  4407. +}
  4408. +
  4409. +int caught_sigint = 0;
  4410. +static void ipkg_install_pkg_sigint_handler(int sig)
  4411. +{
  4412. + caught_sigint = sig;
  4413. +}
  4414. +
  4415. +/* compares versions of pkg and old_pkg, returns 0 if OK to proceed with installation of pkg, 1 otherwise */
  4416. +static int ipkg_install_check_downgrade(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg, int message)
  4417. +{
  4418. + if (old_pkg) {
  4419. + char message_out[15];
  4420. + char *old_version = pkg_version_str_alloc(old_pkg);
  4421. + char *new_version = pkg_version_str_alloc(pkg);
  4422. + int cmp = pkg_compare_versions(old_pkg, pkg);
  4423. + int rc = 0;
  4424. +
  4425. + memset(message_out,'\x0',15);
  4426. + strncpy (message_out,"Upgrading ",strlen("Upgrading "));
  4427. + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
  4428. + cmp = -1 ; /* then we force ipkg to downgrade */
  4429. + strncpy (message_out,"Downgrading ",strlen("Downgrading ")); /* We need to use a value < 0 because in the 0 case we are asking to */
  4430. + /* reinstall, and some check could fail asking the "force-reinstall" option */
  4431. + }
  4432. +
  4433. + if (cmp > 0) {
  4434. + ipkg_message(conf, IPKG_NOTICE,
  4435. + "Not downgrading package %s on %s from %s to %s.\n",
  4436. + old_pkg->name, old_pkg->dest->name, old_version, new_version);
  4437. + rc = 1;
  4438. + } else if (cmp < 0) {
  4439. + ipkg_message(conf, IPKG_NOTICE,
  4440. + "%s%s on %s from %s to %s...\n",
  4441. + message_out, pkg->name, old_pkg->dest->name, old_version, new_version);
  4442. + pkg->dest = old_pkg->dest;
  4443. + rc = 0;
  4444. + } else /* cmp == 0 */ {
  4445. + if (conf->force_reinstall) {
  4446. + ipkg_message(conf, IPKG_NOTICE,
  4447. + "Reinstalling %s (%s) on %s...\n",
  4448. + pkg->name, new_version, old_pkg->dest->name);
  4449. + pkg->dest = old_pkg->dest;
  4450. + rc = 0;
  4451. + } else {
  4452. + ipkg_message(conf, IPKG_NOTICE,
  4453. + "Not installing %s (%s) on %s -- already installed.\n",
  4454. + pkg->name, new_version, old_pkg->dest->name);
  4455. + rc = 1;
  4456. + }
  4457. + }
  4458. + free(old_version);
  4459. + free(new_version);
  4460. + return rc;
  4461. + } else {
  4462. + char message_out[15], *version ;
  4463. + memset(message_out,'\x0',15);
  4464. + if ( message )
  4465. + strncpy( message_out,"Upgrading ",strlen("Upgrading ") );
  4466. + else
  4467. + strncpy( message_out,"Installing ",strlen("Installing ") );
  4468. + version = pkg_version_str_alloc(pkg);
  4469. +
  4470. + ipkg_message(conf, IPKG_NOTICE,
  4471. + "%s%s (%s) to %s...\n", message_out,
  4472. + pkg->name, version, pkg->dest->name);
  4473. + free(version);
  4474. + return 0;
  4475. + }
  4476. +}
  4477. +
  4478. +/* and now the meat... */
  4479. +int ipkg_install_pkg(ipkg_conf_t *conf, pkg_t *pkg, int from_upgrade)
  4480. +{
  4481. + int err = 0;
  4482. + int message = 0;
  4483. + pkg_t *old_pkg = NULL;
  4484. + pkg_vec_t *replacees;
  4485. + abstract_pkg_t *ab_pkg = NULL;
  4486. + int old_state_flag;
  4487. + uint8_t *file_md5;
  4488. +
  4489. +
  4490. + if ( from_upgrade )
  4491. + message = 1; /* Coming from an upgrade, and should change the output message */
  4492. +
  4493. + if (!pkg) {
  4494. + ipkg_message(conf, IPKG_ERROR,
  4495. + "INTERNAL ERROR: null pkg passed to ipkg_install_pkg\n");
  4496. + return -EINVAL;
  4497. + }
  4498. +
  4499. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s calling pkg_arch_supported %s \n", __FUNCTION__, __FUNCTION__);
  4500. +
  4501. + if (!pkg_arch_supported(conf, pkg)) {
  4502. + ipkg_message(conf, IPKG_ERROR, "INTERNAL ERROR: architecture %s for pkg %s is unsupported.\n",
  4503. + pkg->architecture, pkg->name);
  4504. + return -EINVAL;
  4505. + }
  4506. + if (pkg->state_status == SS_INSTALLED && conf->force_reinstall == 0 && conf->nodeps == 0) {
  4507. + err = satisfy_dependencies_for(conf, pkg);
  4508. + if (err) { return err; }
  4509. +
  4510. + ipkg_message(conf, IPKG_NOTICE,
  4511. + "Package %s is already installed in %s.\n",
  4512. + pkg->name, pkg->dest->name);
  4513. + return 0;
  4514. + }
  4515. +
  4516. + if (pkg->dest == NULL) {
  4517. + pkg->dest = conf->default_dest;
  4518. + }
  4519. +
  4520. + old_pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name);
  4521. +
  4522. + err = ipkg_install_check_downgrade(conf, pkg, old_pkg, message);
  4523. + if (err) { return err; }
  4524. +
  4525. + pkg->state_want = SW_INSTALL;
  4526. + if (old_pkg){
  4527. + old_pkg->state_want = SW_DEINSTALL; /* needed for check_data_file_clashes of dependences */
  4528. + }
  4529. +
  4530. +
  4531. + /* Abhaya: conflicts check */
  4532. + err = check_conflicts_for(conf, pkg);
  4533. + if (err) { return err; }
  4534. +
  4535. + /* this setup is to remove the upgrade scenario in the end when
  4536. + installing pkg A, A deps B & B deps on A. So both B and A are
  4537. + installed. Then A's installation is started resulting in an
  4538. + uncecessary upgrade */
  4539. + if (pkg->state_status == SS_INSTALLED
  4540. + && conf->force_reinstall == 0) return 0;
  4541. +
  4542. + err = verify_pkg_installable(conf, pkg);
  4543. + if (err) { return err; }
  4544. +
  4545. + if (pkg->local_filename == NULL) {
  4546. + err = ipkg_download_pkg(conf, pkg, conf->tmp_dir);
  4547. + if (err) {
  4548. + ipkg_message(conf, IPKG_ERROR,
  4549. + "Failed to download %s. Perhaps you need to run 'ipkg update'?\n",
  4550. + pkg->name);
  4551. + return err;
  4552. + }
  4553. + }
  4554. +
  4555. +/* Check for md5 values */
  4556. + if (pkg->md5sum)
  4557. + {
  4558. + file_md5 = file_md5sum_alloc(pkg->local_filename);
  4559. + if (strcmp((char *)file_md5, pkg->md5sum))
  4560. + {
  4561. + ipkg_message(conf, IPKG_ERROR,
  4562. + "Package %s md5sum mismatch. Either the ipkg or the package index are corrupt. Try 'ipkg update'.\n",
  4563. + pkg->name);
  4564. + free(file_md5);
  4565. + return err;
  4566. + }
  4567. + free(file_md5);
  4568. + }
  4569. +
  4570. + if (pkg->tmp_unpack_dir == NULL) {
  4571. + unpack_pkg_control_files(conf, pkg);
  4572. + }
  4573. +
  4574. + /* We should update the filelist here, so that upgrades of packages that split will not fail. -Jamey 27-MAR-03 */
  4575. +/* Pigi: check if it will pass from here when replacing. It seems to fail */
  4576. +/* That's rather strange that files don't change owner. Investigate !!!!!!*/
  4577. + err = update_file_ownership(conf, pkg, old_pkg);
  4578. + if (err) { return err; }
  4579. +
  4580. + if (conf->nodeps == 0) {
  4581. + err = satisfy_dependencies_for(conf, pkg);
  4582. + if (err) { return err; }
  4583. + }
  4584. +
  4585. + replacees = pkg_vec_alloc();
  4586. + pkg_get_installed_replacees(pkg, replacees);
  4587. +
  4588. + /* this next section we do with SIGINT blocked to prevent inconsistency between ipkg database and filesystem */
  4589. + {
  4590. + sigset_t newset, oldset;
  4591. + sighandler_t old_handler = NULL;
  4592. + int use_signal = 0;
  4593. + caught_sigint = 0;
  4594. + if (use_signal) {
  4595. + old_handler = signal(SIGINT, ipkg_install_pkg_sigint_handler);
  4596. + } else {
  4597. + sigemptyset(&newset);
  4598. + sigaddset(&newset, SIGINT);
  4599. + sigprocmask(SIG_BLOCK, &newset, &oldset);
  4600. + }
  4601. +
  4602. + ipkg_state_changed++;
  4603. + pkg->state_flag |= SF_FILELIST_CHANGED;
  4604. +
  4605. + /* XXX: BUG: we really should treat replacement more like an upgrade
  4606. + * Instead, we're going to remove the replacees
  4607. + */
  4608. + err = pkg_remove_installed_replacees(conf, replacees);
  4609. + if (err) goto UNWIND_REMOVE_INSTALLED_REPLACEES;
  4610. +
  4611. + /*
  4612. + err = prerm_upgrade_old_pkg(conf, pkg, old_pkg);
  4613. + if (err) goto UNWIND_PRERM_UPGRADE_OLD_PKG;
  4614. +
  4615. + err = prerm_deconfigure_conflictors(conf, pkg, replacees);
  4616. + if (err) goto UNWIND_PRERM_DECONFIGURE_CONFLICTORS;
  4617. + */
  4618. +
  4619. + err = preinst_configure(conf, pkg, old_pkg);
  4620. + /*
  4621. + if (err) goto UNWIND_PREINST_CONFIGURE;
  4622. + */
  4623. +
  4624. + err = backup_modified_conffiles(conf, pkg, old_pkg);
  4625. + if (err) goto UNWIND_BACKUP_MODIFIED_CONFFILES;
  4626. +
  4627. + err = check_data_file_clashes(conf, pkg, old_pkg);
  4628. + /*
  4629. + if (err) goto UNWIND_CHECK_DATA_FILE_CLASHES;
  4630. +
  4631. + err = postrm_upgrade_old_pkg(conf, pkg, old_pkg);
  4632. + if (err) goto UNWIND_POSTRM_UPGRADE_OLD_PKG;
  4633. + */
  4634. +
  4635. + if (conf->noaction) return 0;
  4636. +
  4637. + /* point of no return: no unwinding after this */
  4638. + if (old_pkg && !conf->force_reinstall) {
  4639. + old_pkg->state_want = SW_DEINSTALL;
  4640. +
  4641. + if (old_pkg->state_flag & SF_NOPRUNE) {
  4642. + ipkg_message(conf, IPKG_INFO,
  4643. + " not removing obsolesced files because package marked noprune\n");
  4644. + } else {
  4645. + ipkg_message(conf, IPKG_INFO,
  4646. + " removing obsolesced files\n");
  4647. + remove_obsolesced_files(conf, pkg, old_pkg);
  4648. + }
  4649. + /* removing files from old package, to avoid ghost files */
  4650. + remove_data_files_and_list(conf, old_pkg);
  4651. +/* Pigi : It should be better to remove also maintainer and postrem scripts here, just in case*/
  4652. + remove_maintainer_scripts_except_postrm(conf, old_pkg);
  4653. + remove_postrm(conf, old_pkg);
  4654. +/* Pigi */
  4655. +
  4656. + }
  4657. +
  4658. +
  4659. + ipkg_message(conf, IPKG_INFO,
  4660. + " installing maintainer scripts\n");
  4661. + install_maintainer_scripts(conf, pkg, old_pkg);
  4662. +
  4663. + /* the following just returns 0
  4664. + remove_disappeared(conf, pkg);
  4665. + */
  4666. +
  4667. + ipkg_message(conf, IPKG_INFO,
  4668. + " installing data files\n");
  4669. + install_data_files(conf, pkg);
  4670. +
  4671. +/* read comments from function for detail but I will execute this here as all other tests are ok.*/
  4672. + err = check_data_file_clashes_change(conf, pkg);
  4673. +
  4674. + ipkg_message(conf, IPKG_INFO,
  4675. + " resolving conf files\n");
  4676. + resolve_conffiles(conf, pkg);
  4677. +
  4678. + pkg->state_status = SS_UNPACKED;
  4679. + old_state_flag = pkg->state_flag;
  4680. + pkg->state_flag &= ~SF_PREFER;
  4681. + ipkg_message(conf, IPKG_DEBUG, " pkg=%s old_state_flag=%x state_flag=%x\n", pkg->name, old_state_flag, pkg->state_flag);
  4682. +
  4683. + if (old_pkg && !conf->force_reinstall) {
  4684. + old_pkg->state_status = SS_NOT_INSTALLED;
  4685. + }
  4686. +
  4687. + time(&pkg->installed_time);
  4688. +
  4689. + ipkg_message(conf, IPKG_INFO,
  4690. + " cleanup temp files\n");
  4691. + cleanup_temporary_files(conf, pkg);
  4692. +
  4693. + ab_pkg = pkg->parent;
  4694. + if (ab_pkg)
  4695. + ab_pkg->state_status = pkg->state_status;
  4696. +
  4697. + ipkg_message(conf, IPKG_INFO, "Done.\n");
  4698. +
  4699. + if (use_signal)
  4700. + signal(SIGINT, old_handler);
  4701. + else
  4702. + sigprocmask(SIG_UNBLOCK, &newset, &oldset);
  4703. +
  4704. + return 0;
  4705. +
  4706. +
  4707. + /*
  4708. + UNWIND_POSTRM_UPGRADE_OLD_PKG:
  4709. + postrm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
  4710. + UNWIND_CHECK_DATA_FILE_CLASHES:
  4711. + check_data_file_clashes_unwind(conf, pkg, old_pkg);
  4712. + */
  4713. + UNWIND_BACKUP_MODIFIED_CONFFILES:
  4714. + backup_modified_conffiles_unwind(pkg, old_pkg);
  4715. + /*
  4716. + UNWIND_PREINST_CONFIGURE:
  4717. + preinst_configure_unwind(conf, pkg, old_pkg);
  4718. + UNWIND_PRERM_DECONFIGURE_CONFLICTORS:
  4719. + prerm_deconfigure_conflictors_unwind(conf, pkg, replacees);
  4720. + UNWIND_PRERM_UPGRADE_OLD_PKG:
  4721. + prerm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
  4722. + */
  4723. + UNWIND_REMOVE_INSTALLED_REPLACEES:
  4724. + pkg_remove_installed_replacees_unwind(conf, replacees);
  4725. +
  4726. + ipkg_message(conf, IPKG_INFO,
  4727. + " cleanup temp files\n");
  4728. + cleanup_temporary_files(conf, pkg);
  4729. +
  4730. + ipkg_message(conf, IPKG_INFO,
  4731. + "Failed.\n");
  4732. + if (use_signal)
  4733. + signal(SIGINT, old_handler);
  4734. + else
  4735. + sigprocmask(SIG_UNBLOCK, &newset, &oldset);
  4736. +
  4737. + return err;
  4738. + }
  4739. +}
  4740. +
  4741. +/*
  4742. +static int prerm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4743. +{
  4744. + DPKG_INCOMPATIBILITY:
  4745. + dpkg does some things here that we don't do yet. Do we care?
  4746. +
  4747. + 1. If a version of the package is already installed, call
  4748. + old-prerm upgrade new-version
  4749. + 2. If the script runs but exits with a non-zero exit status
  4750. + new-prerm failed-upgrade old-version
  4751. + Error unwind, for both the above cases:
  4752. + old-postinst abort-upgrade new-version
  4753. + return 0;
  4754. +}
  4755. +*/
  4756. +
  4757. +/*
  4758. +static int prerm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4759. +{
  4760. + DPKG_INCOMPATIBILITY:
  4761. + dpkg does some things here that we don't do yet. Do we care?
  4762. + (See prerm_upgrade_old_package for details)
  4763. +
  4764. + return 0;
  4765. +}
  4766. +*/
  4767. +
  4768. +/*
  4769. +static int prerm_deconfigure_conflictors(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors)
  4770. +{
  4771. + DPKG_INCOMPATIBILITY:
  4772. + dpkg does some things here that we don't do yet. Do we care?
  4773. + 2. If a 'conflicting' package is being removed at the same time:
  4774. + 1. If any packages depended on that conflicting package and
  4775. + --auto-deconfigure is specified, call, for each such package:
  4776. + deconfigured's-prerm deconfigure \
  4777. + in-favour package-being-installed version \
  4778. + removing conflicting-package version
  4779. + Error unwind:
  4780. + deconfigured's-postinst abort-deconfigure \
  4781. + in-favour package-being-installed-but-failed version \
  4782. + removing conflicting-package version
  4783. +
  4784. + The deconfigured packages are marked as requiring
  4785. + configuration, so that if --install is used they will be
  4786. + configured again if possible.
  4787. + 2. To prepare for removal of the conflicting package, call:
  4788. + conflictor's-prerm remove in-favour package new-version
  4789. + Error unwind:
  4790. + conflictor's-postinst abort-remove in-favour package new-version
  4791. + return 0;
  4792. +}
  4793. +*/
  4794. +
  4795. +/*
  4796. +static int prerm_deconfigure_conflictors_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors)
  4797. +{
  4798. + DPKG_INCOMPATIBILITY: dpkg does some things here that we don't
  4799. + do yet. Do we care? (See prerm_deconfigure_conflictors for
  4800. + details)
  4801. + return 0;
  4802. +}
  4803. +*/
  4804. +
  4805. +static int preinst_configure(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4806. +{
  4807. + int err;
  4808. + char *preinst_args;
  4809. +
  4810. + if (old_pkg) {
  4811. + char *old_version = pkg_version_str_alloc(old_pkg);
  4812. + sprintf_alloc(&preinst_args, "upgrade %s", old_version);
  4813. + free(old_version);
  4814. + } else if (pkg->state_status == SS_CONFIG_FILES) {
  4815. + char *pkg_version = pkg_version_str_alloc(pkg);
  4816. + sprintf_alloc(&preinst_args, "install %s", pkg_version);
  4817. + free(pkg_version);
  4818. + } else {
  4819. + preinst_args = strdup("install");
  4820. + }
  4821. +
  4822. + err = pkg_run_script(conf, pkg, "preinst", preinst_args);
  4823. + if (err) {
  4824. + ipkg_message(conf, IPKG_ERROR,
  4825. + "Aborting installation of %s\n", pkg->name);
  4826. + return 1;
  4827. + }
  4828. +
  4829. + free(preinst_args);
  4830. +
  4831. + return 0;
  4832. +}
  4833. +
  4834. +/*
  4835. +static int preinst_configure_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4836. +{
  4837. + DPKG_INCOMPATIBILITY:
  4838. + dpkg does the following error unwind, should we?
  4839. + pkg->postrm abort-upgrade old-version
  4840. + OR pkg->postrm abort-install old-version
  4841. + OR pkg->postrm abort-install
  4842. + return 0;
  4843. +}
  4844. +*/
  4845. +
  4846. +static int backup_modified_conffiles(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4847. +{
  4848. + int err;
  4849. + conffile_list_elt_t *iter;
  4850. + conffile_t *cf;
  4851. +
  4852. + if (conf->noaction) return 0;
  4853. +
  4854. + /* Backup all modified conffiles */
  4855. + if (old_pkg) {
  4856. + for (iter = old_pkg->conffiles.head; iter; iter = iter->next) {
  4857. + char *cf_name;
  4858. +
  4859. + cf = iter->data;
  4860. + cf_name = root_filename_alloc(conf, cf->name);
  4861. +
  4862. + /* Don't worry if the conffile is just plain gone */
  4863. + if (file_exists(cf_name) && conffile_has_been_modified(conf, cf)) {
  4864. + err = backup_make_backup(conf, cf_name);
  4865. + if (err) {
  4866. + return err;
  4867. + }
  4868. + }
  4869. + free(cf_name);
  4870. + }
  4871. + }
  4872. +
  4873. + /* Backup all conffiles that were not conffiles in old_pkg */
  4874. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  4875. + char *cf_name;
  4876. + cf = iter->data;
  4877. + cf_name = root_filename_alloc(conf, cf->name);
  4878. + /* Ignore if this was a conffile in old_pkg as well */
  4879. + if (pkg_get_conffile(old_pkg, cf->name)) {
  4880. + continue;
  4881. + }
  4882. +
  4883. + if (file_exists(cf_name) && (! backup_exists_for(cf_name))) {
  4884. + err = backup_make_backup(conf, cf_name);
  4885. + if (err) {
  4886. + return err;
  4887. + }
  4888. + }
  4889. + free(cf_name);
  4890. + }
  4891. +
  4892. + return 0;
  4893. +}
  4894. +
  4895. +static int backup_modified_conffiles_unwind(pkg_t *pkg, pkg_t *old_pkg)
  4896. +{
  4897. + conffile_list_elt_t *iter;
  4898. +
  4899. + if (old_pkg) {
  4900. + for (iter = old_pkg->conffiles.head; iter; iter = iter->next) {
  4901. + backup_remove(iter->data->name);
  4902. + }
  4903. + }
  4904. +
  4905. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  4906. + backup_remove(iter->data->name);
  4907. + }
  4908. +
  4909. + return 0;
  4910. +}
  4911. +
  4912. +
  4913. +static int check_data_file_clashes(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4914. +{
  4915. + /* DPKG_INCOMPATIBILITY:
  4916. + ipkg takes a slightly different approach than dpkg at this
  4917. + point. dpkg installs each file in the new package while
  4918. + creating a backup for any file that is replaced, (so that it
  4919. + can unwind if necessary). To avoid complexity and redundant
  4920. + storage, ipkg doesn't do any installation until later, (at the
  4921. + point at which dpkg removes the backups.
  4922. +
  4923. + But, we do have to check for data file clashes, since after
  4924. + installing a package with a file clash, removing either of the
  4925. + packages involved in the clash has the potential to break the
  4926. + other package.
  4927. + */
  4928. + str_list_t *files_list;
  4929. + str_list_elt_t *iter;
  4930. +
  4931. + int clashes = 0;
  4932. +
  4933. + files_list = pkg_get_installed_files(pkg);
  4934. + for (iter = files_list->head; iter; iter = iter->next) {
  4935. + char *root_filename;
  4936. + char *filename = iter->data;
  4937. + root_filename = root_filename_alloc(conf, filename);
  4938. + if (file_exists(root_filename) && (! file_is_dir(root_filename))) {
  4939. + pkg_t *owner;
  4940. + pkg_t *obs;
  4941. + /* Pre-existing conffiles are OK */
  4942. + /* @@@@ should have way to check that it is a conffile -Jamey */
  4943. + if (backup_exists_for(root_filename)) {
  4944. + continue;
  4945. + }
  4946. +
  4947. + /* Pre-existing files are OK if force-overwrite was asserted. */
  4948. + if (conf->force_overwrite) {
  4949. + /* but we need to change who owns this file */
  4950. + file_hash_set_file_owner(conf, filename, pkg);
  4951. + continue;
  4952. + }
  4953. +
  4954. + owner = file_hash_get_file_owner(conf, filename);
  4955. +
  4956. + /* Pre-existing files are OK if owned by the pkg being upgraded. */
  4957. + if (owner && old_pkg) {
  4958. + if (strcmp(owner->name, old_pkg->name) == 0) {
  4959. + continue;
  4960. + }
  4961. + }
  4962. +
  4963. + /* Pre-existing files are OK if owned by a package replaced by new pkg. */
  4964. + if (owner) {
  4965. + ipkg_message(conf, IPKG_DEBUG2, "Checking for replaces for %s in package %s\n", filename, owner->name);
  4966. + if (pkg_replaces(pkg, owner)) {
  4967. + continue;
  4968. + }
  4969. +/* If the file that would be installed is owned by the same package, ( as per a reinstall or similar )
  4970. + then it's ok to overwrite. */
  4971. + if (strcmp(owner->name,pkg->name)==0){
  4972. + ipkg_message(conf, IPKG_INFO, "Replacing pre-existing file %s owned by package %s\n", filename, owner->name);
  4973. + continue;
  4974. + }
  4975. + }
  4976. +
  4977. + /* Pre-existing files are OK if they are obsolete */
  4978. + obs = hash_table_get(&conf->obs_file_hash, filename);
  4979. + if (obs) {
  4980. + ipkg_message(conf, IPKG_INFO, "Pre-exiting file %s is obsolete. obs_pkg=%s\n", filename, obs->name);
  4981. + continue;
  4982. + }
  4983. +
  4984. + /* We have found a clash. */
  4985. + ipkg_message(conf, IPKG_ERROR,
  4986. + "Package %s wants to install file %s\n"
  4987. + "\tBut that file is already provided by package ",
  4988. + pkg->name, filename);
  4989. + if (owner) {
  4990. + ipkg_message(conf, IPKG_ERROR,
  4991. + "%s\n", owner->name);
  4992. + } else {
  4993. + ipkg_message(conf, IPKG_ERROR,
  4994. + "<no package>\nPlease move this file out of the way and try again.\n");
  4995. + }
  4996. + clashes++;
  4997. + }
  4998. + free(root_filename);
  4999. + }
  5000. + pkg_free_installed_files(pkg);
  5001. +
  5002. + return clashes;
  5003. +}
  5004. +
  5005. +static int check_data_file_clashes_change(ipkg_conf_t *conf, pkg_t *pkg)
  5006. +{
  5007. + /* Basically that's the worst hack I could do to be able to change ownership of
  5008. + file list, but, being that we have no way to unwind the mods, due to structure
  5009. + of hash table, probably is the quickest hack too, whishing it would not slow-up thing too much.
  5010. + What we do here is change the ownership of file in hash if a replace ( or similar events
  5011. + happens )
  5012. + Only the action that are needed to change name should be considered.
  5013. + @@@ To change after 1.0 release.
  5014. + */
  5015. + str_list_t *files_list;
  5016. + str_list_elt_t *iter;
  5017. +
  5018. + int clashes = 0;
  5019. +
  5020. + files_list = pkg_get_installed_files(pkg);
  5021. + for (iter = files_list->head; iter; iter = iter->next) {
  5022. + char *root_filename;
  5023. + char *filename = iter->data;
  5024. + root_filename = root_filename_alloc(conf, filename);
  5025. + if (file_exists(root_filename) && (! file_is_dir(root_filename))) {
  5026. + pkg_t *owner;
  5027. +
  5028. + if (conf->force_overwrite) {
  5029. + /* but we need to change who owns this file */
  5030. + file_hash_set_file_owner(conf, filename, pkg);
  5031. + continue;
  5032. + }
  5033. +
  5034. + owner = file_hash_get_file_owner(conf, filename);
  5035. +
  5036. + /* Pre-existing files are OK if owned by a package replaced by new pkg. */
  5037. + if (owner) {
  5038. + if (pkg_replaces(pkg, owner)) {
  5039. +/* It's now time to change the owner of that file.
  5040. + It has been "replaced" from the new "Replaces", then I need to inform lists file about that. */
  5041. + ipkg_message(conf, IPKG_INFO, "Replacing pre-existing file %s owned by package %s\n", filename, owner->name);
  5042. + file_hash_set_file_owner(conf, filename, pkg);
  5043. + continue;
  5044. + }
  5045. + }
  5046. +
  5047. + }
  5048. + free(root_filename);
  5049. + }
  5050. + pkg_free_installed_files(pkg);
  5051. +
  5052. + return clashes;
  5053. +}
  5054. +
  5055. +/*
  5056. +static int check_data_file_clashes_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5057. +{
  5058. + Nothing to do since check_data_file_clashes doesn't change state
  5059. + return 0;
  5060. +}
  5061. +*/
  5062. +
  5063. +/*
  5064. +static int postrm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5065. +{
  5066. + DPKG_INCOMPATIBILITY: dpkg does the following here, should we?
  5067. + 1. If the package is being upgraded, call
  5068. + old-postrm upgrade new-version
  5069. + 2. If this fails, attempt:
  5070. + new-postrm failed-upgrade old-version
  5071. + Error unwind, for both cases:
  5072. + old-preinst abort-upgrade new-version
  5073. + return 0;
  5074. +}
  5075. +*/
  5076. +
  5077. +/*
  5078. +static int postrm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5079. +{
  5080. + DPKG_INCOMPATIBILITY:
  5081. + dpkg does some things here that we don't do yet. Do we care?
  5082. + (See postrm_upgrade_old_pkg for details)
  5083. + return 0;
  5084. +}
  5085. +*/
  5086. +
  5087. +static int remove_obsolesced_files(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5088. +{
  5089. + int err;
  5090. + str_list_t *old_files;
  5091. + str_list_elt_t *of;
  5092. + str_list_t *new_files;
  5093. + str_list_elt_t *nf;
  5094. +
  5095. + if (old_pkg == NULL) {
  5096. + return 0;
  5097. + }
  5098. +
  5099. + old_files = pkg_get_installed_files(old_pkg);
  5100. + new_files = pkg_get_installed_files(pkg);
  5101. +
  5102. + for (of = old_files->head; of; of = of->next) {
  5103. + pkg_t *owner;
  5104. + char *old, *new;
  5105. + old = of->data;
  5106. + for (nf = new_files->head; nf; nf = nf->next) {
  5107. + new = nf->data;
  5108. + if (strcmp(old, new) == 0) {
  5109. + goto NOT_OBSOLETE;
  5110. + }
  5111. + }
  5112. + if (file_is_dir(old)) {
  5113. + continue;
  5114. + }
  5115. + owner = file_hash_get_file_owner(conf, old);
  5116. + if (owner != old_pkg) {
  5117. + /* in case obsolete file no longer belongs to old_pkg */
  5118. + continue;
  5119. + }
  5120. +
  5121. + /* old file is obsolete */
  5122. + ipkg_message(conf, IPKG_INFO,
  5123. + " removing obsolete file %s\n", old);
  5124. + if (!conf->noaction) {
  5125. + err = unlink(old);
  5126. + if (err) {
  5127. + ipkg_message(conf, IPKG_ERROR, " Warning: remove %s failed: %s\n", old,
  5128. + strerror(errno));
  5129. + }
  5130. + }
  5131. +
  5132. + NOT_OBSOLETE:
  5133. + ;
  5134. + }
  5135. +
  5136. + pkg_free_installed_files(old_pkg);
  5137. + pkg_free_installed_files(pkg);
  5138. +
  5139. + return 0;
  5140. +}
  5141. +
  5142. +static int remove_obsolete_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5143. +{
  5144. + int i;
  5145. + int err = 0;
  5146. + char *globpattern;
  5147. + glob_t globbuf;
  5148. + if (0) {
  5149. + if (!pkg->dest) {
  5150. + ipkg_message(conf, IPKG_ERROR, "%s: no dest for package %s\n", __FUNCTION__, pkg->name);
  5151. + return -1;
  5152. + }
  5153. + sprintf_alloc(&globpattern, "%s/%s.*", pkg->dest->info_dir, pkg->name);
  5154. + err = glob(globpattern, 0, NULL, &globbuf);
  5155. + free(globpattern);
  5156. + if (err) {
  5157. + return err;
  5158. + }
  5159. + /* XXXX this should perhaps only remove the ones that are not overwritten in new package. Jamey 11/11/2003 */
  5160. + for (i = 0; i < globbuf.gl_pathc; i++) {
  5161. + ipkg_message(conf, IPKG_DEBUG, "Removing control file %s from old_pkg %s\n",
  5162. + globbuf.gl_pathv[i], old_pkg->name);
  5163. + if (!conf->noaction)
  5164. + unlink(globbuf.gl_pathv[i]);
  5165. + }
  5166. + globfree(&globbuf);
  5167. + }
  5168. + return err;
  5169. +}
  5170. +
  5171. +static int install_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5172. +{
  5173. + int ret;
  5174. + char *prefix;
  5175. +
  5176. + if (old_pkg)
  5177. + remove_obsolete_maintainer_scripts(conf, pkg, old_pkg);
  5178. + sprintf_alloc(&prefix, "%s.", pkg->name);
  5179. + ret = pkg_extract_control_files_to_dir_with_prefix(pkg,
  5180. + pkg->dest->info_dir,
  5181. + prefix);
  5182. + free(prefix);
  5183. + return ret;
  5184. +}
  5185. +
  5186. +/*
  5187. +static int remove_disappeared(ipkg_conf_t *conf, pkg_t *pkg)
  5188. +{
  5189. + DPKG_INCOMPATIBILITY:
  5190. + This is a fairly sophisticated dpkg operation. Shall we
  5191. + skip it?
  5192. +
  5193. + Any packages all of whose files have been overwritten during the
  5194. + installation, and which aren't required for dependencies, are
  5195. + considered to have been removed. For each such package
  5196. + 1. disappearer's-postrm disappear overwriter overwriter-version
  5197. + 2. The package's maintainer scripts are removed
  5198. + 3. It is noted in the status database as being in a sane state,
  5199. + namely not installed (any conffiles it may have are ignored,
  5200. + rather than being removed by dpkg). Note that disappearing
  5201. + packages do not have their prerm called, because dpkg doesn't
  5202. + know in advance that the package is going to vanish.
  5203. +
  5204. +
  5205. + return 0;
  5206. +}
  5207. +*/
  5208. +
  5209. +static int install_data_files(ipkg_conf_t *conf, pkg_t *pkg)
  5210. +{
  5211. + int err;
  5212. +
  5213. + /* ipkg takes a slightly different approach to data file backups
  5214. + than dpkg. Rather than removing backups at this point, we
  5215. + actually do the data file installation now. See comments in
  5216. + check_data_file_clashes() for more details. */
  5217. +
  5218. + ipkg_message(conf, IPKG_INFO,
  5219. + " extracting data files to %s\n", pkg->dest->root_dir);
  5220. + err = pkg_extract_data_files_to_dir(pkg, pkg->dest->root_dir);
  5221. + if (err) {
  5222. + return err;
  5223. + }
  5224. +
  5225. + /* XXX: BUG or FEATURE : We are actually loosing the Essential flag,
  5226. + so we can't save ourself from removing important packages
  5227. + At this point we (should) have extracted the .control file, so it
  5228. + would be a good idea to reload the data in it, and set the Essential
  5229. + state in *pkg. From now on the Essential is back in status file and
  5230. + we can protect again.
  5231. + We should operate this way:
  5232. + fopen the file ( pkg->dest->root_dir/pkg->name.control )
  5233. + check for "Essential" in it
  5234. + set the value in pkg->essential.
  5235. + This new routine could be useful also for every other flag
  5236. + Pigi: 16/03/2004 */
  5237. + set_flags_from_control(conf, pkg) ;
  5238. +
  5239. + ipkg_message(conf, IPKG_DEBUG, " Calling pkg_write_filelist from %s\n", __FUNCTION__);
  5240. + err = pkg_write_filelist(conf, pkg);
  5241. + if (err)
  5242. + return err;
  5243. +
  5244. + /* XXX: FEATURE: ipkg should identify any files which existed
  5245. + before installation and which were overwritten, (see
  5246. + check_data_file_clashes()). What it must do is remove any such
  5247. + files from the filelist of the old package which provided the
  5248. + file. Otherwise, if the old package were removed at some point
  5249. + it would break the new package. Removing the new package will
  5250. + also break the old one, but this cannot be helped since the old
  5251. + package's file has already been deleted. This is the importance
  5252. + of check_data_file_clashes(), and only allowing ipkg to install
  5253. + a clashing package with a user force. */
  5254. +
  5255. + return 0;
  5256. +}
  5257. +
  5258. +static int resolve_conffiles(ipkg_conf_t *conf, pkg_t *pkg)
  5259. +{
  5260. + conffile_list_elt_t *iter;
  5261. + conffile_t *cf;
  5262. + char *cf_backup;
  5263. + uint8_t *md5sum;
  5264. +
  5265. +
  5266. + if (conf->noaction) return 0;
  5267. +
  5268. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  5269. + char *root_filename;
  5270. + cf = iter->data;
  5271. + root_filename = root_filename_alloc(conf, cf->name);
  5272. +
  5273. + /* Might need to initialize the md5sum for each conffile */
  5274. + if (cf->value == NULL) {
  5275. + cf->value = (char *)file_md5sum_alloc(root_filename);
  5276. + }
  5277. +
  5278. + if (!file_exists(root_filename)) {
  5279. + free(root_filename);
  5280. + continue;
  5281. + }
  5282. +
  5283. + cf_backup = backup_filename_alloc(root_filename);
  5284. +
  5285. +
  5286. + if (file_exists(cf_backup)) {
  5287. + /* Let's compute md5 to test if files are changed */
  5288. + md5sum = file_md5sum_alloc(cf_backup);
  5289. + if (strcmp( cf->value, (char *)md5sum) != 0 ) {
  5290. + if (conf->force_defaults
  5291. + || user_prefers_old_conffile(cf->name, cf_backup) ) {
  5292. + rename(cf_backup, root_filename);
  5293. + }
  5294. + }
  5295. + unlink(cf_backup);
  5296. + free(md5sum);
  5297. + }
  5298. +
  5299. + free(cf_backup);
  5300. + free(root_filename);
  5301. + }
  5302. +
  5303. + return 0;
  5304. +}
  5305. +
  5306. +static int user_prefers_old_conffile(const char *file_name, const char *backup)
  5307. +{
  5308. + char *response;
  5309. + const char *short_file_name;
  5310. +
  5311. + short_file_name = strrchr(file_name, '/');
  5312. + if (short_file_name) {
  5313. + short_file_name++;
  5314. + } else {
  5315. + short_file_name = file_name;
  5316. + }
  5317. +
  5318. + while (1) {
  5319. + response = get_user_response(" Configuration file '%s'\n"
  5320. + " ==> File on system created by you or by a script.\n"
  5321. + " ==> File also in package provided by package maintainer.\n"
  5322. + " What would you like to do about it ? Your options are:\n"
  5323. + " Y or I : install the package maintainer's version\n"
  5324. + " N or O : keep your currently-installed version\n"
  5325. +#ifdef CONFIG_DIFF
  5326. + " D : show the differences between the versions\n"
  5327. +#endif
  5328. + " The default action is to keep your current version.\n"
  5329. + " *** %s (Y/I/N/O"
  5330. +#ifdef CONFIG_DIFF
  5331. + "/D"
  5332. +#endif
  5333. + ") [default=N] ? ", file_name, short_file_name);
  5334. + if (strcmp(response, "y") == 0
  5335. + || strcmp(response, "i") == 0
  5336. + || strcmp(response, "yes") == 0) {
  5337. + free(response);
  5338. + return 0;
  5339. + }
  5340. +
  5341. +#ifdef CONFIG_DIFF
  5342. + if (strcmp(response, "d") == 0) {
  5343. + char *cmd;
  5344. +
  5345. + free(response);
  5346. + /* XXX: BUG rewrite to use exec or busybox's internal diff */
  5347. + sprintf_alloc(&cmd, "diff -u %s %s", backup, file_name);
  5348. + xsystem(cmd);
  5349. + free(cmd);
  5350. + printf(" [Press ENTER to continue]\n");
  5351. + response = file_read_line_alloc(stdin);
  5352. + free(response);
  5353. + continue;
  5354. + }
  5355. +#endif
  5356. +
  5357. + free(response);
  5358. + return 1;
  5359. + }
  5360. +}
  5361. +
  5362. +/* XXX: CLEANUP: I'd like to move all of the code for
  5363. + creating/cleaning pkg->tmp_unpack_dir directly into pkg.c. (Then,
  5364. + it would make sense to cleanup pkg->tmp_unpack_dir directly from
  5365. + pkg_deinit for example). */
  5366. +static int cleanup_temporary_files(ipkg_conf_t *conf, pkg_t *pkg)
  5367. +{
  5368. + DIR *tmp_dir;
  5369. + struct dirent *dirent;
  5370. + char *tmp_file;
  5371. +
  5372. +#ifdef IPKG_DEBUG_NO_TMP_CLEANUP
  5373. +#error
  5374. + ipkg_message(conf, IPKG_DEBUG,
  5375. + "%s: Not cleaning up %s since ipkg compiled with IPKG_DEBUG_NO_TMP_CLEANUP\n",
  5376. + __FUNCTION__, pkg->tmp_unpack_dir);
  5377. + return 0;
  5378. +#endif
  5379. +
  5380. + if (pkg->tmp_unpack_dir && file_is_dir(pkg->tmp_unpack_dir)) {
  5381. + tmp_dir = opendir(pkg->tmp_unpack_dir);
  5382. + if (tmp_dir) {
  5383. + while (1) {
  5384. + dirent = readdir(tmp_dir);
  5385. + if (dirent == NULL) {
  5386. + break;
  5387. + }
  5388. + sprintf_alloc(&tmp_file, "%s/%s",
  5389. + pkg->tmp_unpack_dir, dirent->d_name);
  5390. + if (! file_is_dir(tmp_file)) {
  5391. + unlink(tmp_file);
  5392. + }
  5393. + free(tmp_file);
  5394. + }
  5395. + closedir(tmp_dir);
  5396. + rmdir(pkg->tmp_unpack_dir);
  5397. + free(pkg->tmp_unpack_dir);
  5398. + pkg->tmp_unpack_dir = NULL;
  5399. + }
  5400. + }
  5401. +
  5402. + ipkg_message(conf, IPKG_INFO, "cleanup_temporary_files: pkg=%s local_filename=%s tmp_dir=%s\n",
  5403. + pkg->name, pkg->local_filename, conf->tmp_dir);
  5404. + if (pkg->local_filename && strncmp(pkg->local_filename, conf->tmp_dir, strlen(conf->tmp_dir)) == 0) {
  5405. + unlink(pkg->local_filename);
  5406. + free(pkg->local_filename);
  5407. + pkg->local_filename = NULL;
  5408. + }
  5409. +
  5410. + return 0;
  5411. +}
  5412. +
  5413. +static char *backup_filename_alloc(const char *file_name)
  5414. +{
  5415. + char *backup;
  5416. +
  5417. + sprintf_alloc(&backup, "%s%s", file_name, IPKG_BACKUP_SUFFIX);
  5418. +
  5419. + return backup;
  5420. +}
  5421. +
  5422. +int backup_make_backup(ipkg_conf_t *conf, const char *file_name)
  5423. +{
  5424. + int err;
  5425. + char *backup;
  5426. +
  5427. + backup = backup_filename_alloc(file_name);
  5428. + err = file_copy(file_name, backup);
  5429. + if (err) {
  5430. + ipkg_message(conf, IPKG_ERROR,
  5431. + "%s: Failed to copy %s to %s\n",
  5432. + __FUNCTION__, file_name, backup);
  5433. + }
  5434. +
  5435. + free(backup);
  5436. +
  5437. + return err;
  5438. +}
  5439. +
  5440. +static int backup_exists_for(const char *file_name)
  5441. +{
  5442. + int ret;
  5443. + char *backup;
  5444. +
  5445. + backup = backup_filename_alloc(file_name);
  5446. +
  5447. + ret = file_exists(backup);
  5448. +
  5449. + free(backup);
  5450. +
  5451. + return ret;
  5452. +}
  5453. +
  5454. +static int backup_remove(const char *file_name)
  5455. +{
  5456. + char *backup;
  5457. +
  5458. + backup = backup_filename_alloc(file_name);
  5459. + unlink(backup);
  5460. + free(backup);
  5461. +
  5462. + return 0;
  5463. +}
  5464. +
  5465. +
  5466. +
  5467. +#ifdef CONFIG_IPKG_PROCESS_ACTIONS
  5468. +
  5469. +int ipkg_remove_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove)
  5470. +{
  5471. + /* first, remove the packages that need removing */
  5472. + for (i = 0 ; i < pkgs_to_remove->len; i++ ) {
  5473. + pkg_t *pkg = pkgs_to_remove->pkgs[i];
  5474. + err = ipkg_remove_pkg(conf, pkg,0);
  5475. + if (err) return err;
  5476. + }
  5477. + return 0;
  5478. +}
  5479. +
  5480. +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)
  5481. +{
  5482. + int i;
  5483. + /* now one more pass checking on the ones that need to be installed */
  5484. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5485. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5486. + if (pkg->dest == NULL)
  5487. + pkg->dest = conf->default_dest;
  5488. +
  5489. + pkg->state_want = SW_INSTALL;
  5490. +
  5491. + /* Abhaya: conflicts check */
  5492. + err = check_conflicts_for(conf, pkg);
  5493. + if (err) { return err; }
  5494. + }
  5495. + return 0;
  5496. +}
  5497. +
  5498. +int ipkg_process_actions_unpack_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_to_install)
  5499. +{
  5500. + int i;
  5501. + /* now one more pass checking on the ones that need to be installed */
  5502. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5503. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5504. +
  5505. + /* XXX: FEATURE: Need to really support Provides/Replaces: here at some point */
  5506. + pkg_vec_t *replacees = pkg_vec_alloc();
  5507. + pkg_get_installed_replacees(pkg, replacees);
  5508. +
  5509. + /* XXX: BUG: we really should treat replacement more like an upgrade
  5510. + * Instead, we're going to remove the replacees
  5511. + */
  5512. + err = pkg_remove_installed_replacees(conf, replacees);
  5513. + if (err) return err;
  5514. + pkg->state_flag |= SF_REMOVED_REPLACEES;
  5515. + }
  5516. + return 0;
  5517. +}
  5518. +
  5519. +int ipkg_process_actions_unpack_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_to_install)
  5520. +{
  5521. + int i;
  5522. + /* now one more pass checking on the ones that need to be installed */
  5523. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5524. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5525. + if (pkg->local_filename == NULL) {
  5526. + err = ipkg_download_pkg(conf, pkg, conf->tmp_dir);
  5527. + if (err) {
  5528. + ipkg_message(conf, IPKG_ERROR,
  5529. + "Failed to download %s. Perhaps you need to run 'ipkg update'?\n",
  5530. + pkg->name);
  5531. + return err;
  5532. + }
  5533. + }
  5534. + if (pkg->tmp_unpack_dir == NULL) {
  5535. + err = unpack_pkg_control_files(conf, pkg);
  5536. + if (err) return err;
  5537. + }
  5538. + }
  5539. + return 0;
  5540. +}
  5541. +
  5542. +int ipkg_process_actions_prerm(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
  5543. +{
  5544. + int i;
  5545. + /* now one more pass checking on the ones that need to be installed */
  5546. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5547. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5548. + pkg_t *old_pkg = pkg->old_pkg;
  5549. +
  5550. + err = prerm_upgrade_old_pkg(conf, pkg, old_pkg);
  5551. + if (err) return err;
  5552. +
  5553. + err = prerm_deconfigure_conflictors(conf, pkg, replacees);
  5554. + if (err) return err;
  5555. +
  5556. + err = preinst_configure(conf, pkg, old_pkg);
  5557. + if (err) return err;
  5558. +
  5559. + err = backup_modified_conffiles(conf, pkg, old_pkg);
  5560. + if (err) return err;
  5561. +
  5562. + err = postrm_upgrade_old_pkg(conf, pkg, old_pkg);
  5563. + if (err) return err;
  5564. + }
  5565. + return 0;
  5566. +}
  5567. +
  5568. +int ipkg_process_actions_install(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
  5569. +{
  5570. + int i;
  5571. + /* now one more pass checking on the ones that need to be installed */
  5572. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5573. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5574. + pkg_t *old_pkg = pkg->old_pkg;
  5575. +
  5576. + if (old_pkg) {
  5577. + old_pkg->state_want = SW_DEINSTALL;
  5578. +
  5579. + if (old_pkg->state_flag & SF_NOPRUNE) {
  5580. + ipkg_message(conf, IPKG_INFO,
  5581. + " not removing obsolesced files because package marked noprune\n");
  5582. + } else {
  5583. + ipkg_message(conf, IPKG_INFO,
  5584. + " removing obsolesced files\n");
  5585. + remove_obsolesced_files(conf, pkg, old_pkg);
  5586. + }
  5587. + }
  5588. +
  5589. + ipkg_message(conf, IPKG_INFO,
  5590. + " installing maintainer scripts\n");
  5591. + install_maintainer_scripts(conf, pkg, old_pkg);
  5592. +
  5593. + /* the following just returns 0 */
  5594. + remove_disappeared(conf, pkg);
  5595. +
  5596. + ipkg_message(conf, IPKG_INFO,
  5597. + " installing data files\n");
  5598. + install_data_files(conf, pkg);
  5599. +
  5600. + ipkg_message(conf, IPKG_INFO,
  5601. + " resolving conf files\n");
  5602. + resolve_conffiles(conf, pkg);
  5603. +
  5604. + pkg->state_status = SS_UNPACKED;
  5605. +
  5606. + if (old_pkg) {
  5607. + old_pkg->state_status = SS_NOT_INSTALLED;
  5608. + }
  5609. +
  5610. + time(&pkg->installed_time);
  5611. +
  5612. + ipkg_message(conf, IPKG_INFO,
  5613. + " cleanup temp files\n");
  5614. + cleanup_temporary_files(conf, pkg);
  5615. +
  5616. + if (pkg->parent)
  5617. + pkg->parent->state_status = pkg->state_status;
  5618. + }
  5619. + return 0;
  5620. +}
  5621. +
  5622. +int ipkg_process_actions_unwind_prerm(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
  5623. +{
  5624. + int i;
  5625. + /* now one more pass checking on the ones that need to be installed */
  5626. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5627. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5628. + pkg_t *old_pkg = pkg->old_pkg;
  5629. +
  5630. + if (old_pkg) {
  5631. + if (old_pkg->state_flags & SF_POSTRM_UPGRADE)
  5632. + postrm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
  5633. + if (old_pkg->state_flags & SF_CHECK_DATA_FILE_CLASHES)
  5634. + check_data_file_clashes_unwind(conf, pkg, old_pkg);
  5635. + if (old_pkg->state_flags & SF_BACKUP_MODIFIED_CONFFILES)
  5636. + backup_modified_conffiles_unwind(pkg, old_pkg);
  5637. + */
  5638. + if (old_pkg->state_flags & SF_PREINST_CONFIGURE)
  5639. + preinst_configure_unwind(conf, pkg, old_pkg);
  5640. + if (old_pkg->state_flags & SF_DECONFIGURE_CONFLICTORS)
  5641. + prerm_deconfigure_conflictors_unwind(conf, pkg, replacees);
  5642. + if (old_pkg->state_flags & SF_PRERM_UPGRADE)
  5643. + prerm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
  5644. + */
  5645. +
  5646. + if (old_pkg->state_flags & SF_REMOVED_REPLACEES)
  5647. + remove_installed_replacees_unwind(conf, pkg, old_pkg);
  5648. +
  5649. + }
  5650. + }
  5651. + return 0;
  5652. +}
  5653. +
  5654. +/*
  5655. + * Perform all the actions.
  5656. + *
  5657. + * pkgs_to_remove are packages marked for removal.
  5658. + * pkgs_superseded are the old packages being replaced by upgrades.
  5659. + *
  5660. + * Assumes pkgs_to_install includes all dependences, recursively, sorted in installable order.
  5661. + */
  5662. +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)
  5663. +{
  5664. + int err;
  5665. + int i;
  5666. +
  5667. + err = ipkg_remove_packages(conf, pkgs_to_remove);
  5668. + if (err) return err;
  5669. +
  5670. + err = ipkg_process_actions_sanity_check(conf, pkgs_superseded, pkgs_to_install);
  5671. + if (err) return err;
  5672. +
  5673. + err = ipkg_process_actions_remove_replacees(conf, pkgs_to_install);
  5674. + if (err) goto UNWIND;
  5675. +
  5676. + /* @@@@ look at ipkg_install_pkg for handling replacements */
  5677. + err = ipkg_process_actions_unpack_packages(conf, pkgs_to_install);
  5678. + if (err) goto UNWIND;
  5679. +
  5680. + /*
  5681. + * Now that we have the packages unpacked, we can look for data
  5682. + * file clashes. First, we mark the files from the superseded
  5683. + * packages as obsolete. Then we scan the files in
  5684. + * pkgs_to_install, and only complain about clashes with
  5685. + * non-obsolete files.
  5686. + */
  5687. +
  5688. + err = ipkg_process_actions_check_data_file_clashes(conf, pkgs_superseded, pkgs_to_install);
  5689. + if (err) goto UNWIND;
  5690. +
  5691. + /* this was before checking data file clashes */
  5692. + err = ipkg_process_actions_prerm(conf, pkgs_superseded, pkgs_to_install);
  5693. + if (err) goto UNWIND;
  5694. +
  5695. + /* point of no return: no unwinding after this */
  5696. + err = ipkg_process_actions_install(conf, pkgs_to_install);
  5697. + if (err) return err;
  5698. +
  5699. + ipkg_message(conf, IPKG_INFO, "Done.\n");
  5700. + return 0;
  5701. +
  5702. + UNWIND:
  5703. + ipkg_process_actions_unwind(conf, pkgs_to_install);
  5704. +
  5705. + ipkg_message(conf, IPKG_INFO,
  5706. + " cleanup temp files\n");
  5707. + cleanup_temporary_files(conf, pkg);
  5708. +
  5709. + ipkg_message(conf, IPKG_INFO,
  5710. + "Failed.\n");
  5711. + return err;
  5712. +}
  5713. +
  5714. +#endif
  5715. diff -Nur busybox-1.16.1.orig/archival/libipkg/ipkg_install.h busybox-1.16.1/archival/libipkg/ipkg_install.h
  5716. --- busybox-1.16.1.orig/archival/libipkg/ipkg_install.h 1970-01-01 01:00:00.000000000 +0100
  5717. +++ busybox-1.16.1/archival/libipkg/ipkg_install.h 2010-04-22 19:18:12.000000000 +0200
  5718. @@ -0,0 +1,35 @@
  5719. +/* ipkg_install.h - the itsy package management system
  5720. +
  5721. + Carl D. Worth
  5722. +
  5723. + Copyright (C) 2001 University of Southern California
  5724. +
  5725. + This program is free software; you can redistribute it and/or
  5726. + modify it under the terms of the GNU General Public License as
  5727. + published by the Free Software Foundation; either version 2, or (at
  5728. + your option) any later version.
  5729. +
  5730. + This program is distributed in the hope that it will be useful, but
  5731. + WITHOUT ANY WARRANTY; without even the implied warranty of
  5732. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  5733. + General Public License for more details.
  5734. +*/
  5735. +
  5736. +#ifndef IPKG_INSTALL_H
  5737. +#define IPKG_INSTALL_H
  5738. +
  5739. +#include "pkg.h"
  5740. +#include "ipkg_conf.h"
  5741. +
  5742. +ipkg_error_t ipkg_install_by_name(ipkg_conf_t *conf, const char *pkg_name);
  5743. +ipkg_error_t ipkg_install_multi_by_name(ipkg_conf_t *conf, const char *pkg_name);
  5744. +int ipkg_install_from_file(ipkg_conf_t *conf, const char *filename);
  5745. +int ipkg_install_pkg(ipkg_conf_t *conf, pkg_t *pkg,int from_upgrading);
  5746. +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg);
  5747. +
  5748. +int ipkg_satisfy_all_dependences(ipkg_conf_t *conf);
  5749. +
  5750. +int pkg_mark_dependencies_for_installation(ipkg_conf_t *conf, pkg_t *pkg_name, pkg_vec_t *pkgs_needed);
  5751. +int name_mark_dependencies_for_installation(ipkg_conf_t *conf, const char *pkg_name, pkg_vec_t *pkgs_needed);
  5752. +
  5753. +#endif
  5754. diff -Nur busybox-1.16.1.orig/archival/libipkg/ipkg_message.c busybox-1.16.1/archival/libipkg/ipkg_message.c
  5755. --- busybox-1.16.1.orig/archival/libipkg/ipkg_message.c 1970-01-01 01:00:00.000000000 +0100
  5756. +++ busybox-1.16.1/archival/libipkg/ipkg_message.c 2010-04-22 19:18:12.000000000 +0200
  5757. @@ -0,0 +1,35 @@
  5758. +/* ipkg_message.c - the itsy package management system
  5759. +
  5760. + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
  5761. +
  5762. + This program is free software; you can redistribute it and/or
  5763. + modify it under the terms of the GNU General Public License as
  5764. + published by the Free Software Foundation; either version 2, or (at
  5765. + your option) any later version.
  5766. +
  5767. + This program is distributed in the hope that it will be useful, but
  5768. + WITHOUT ANY WARRANTY; without even the implied warranty of
  5769. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  5770. + General Public License for more details.
  5771. +*/
  5772. +
  5773. +
  5774. +#include "ipkg.h"
  5775. +#include "ipkg_conf.h"
  5776. +#include "ipkg_message.h"
  5777. +#include "libipkg.h"
  5778. +
  5779. +void
  5780. +ipkg_message (ipkg_conf_t * conf, message_level_t level, const char *fmt, ...)
  5781. +{
  5782. + va_list ap;
  5783. + char ts[256];
  5784. +
  5785. + if (ipkg_cb_message)
  5786. + {
  5787. + va_start (ap, fmt);
  5788. + vsnprintf (ts,256,fmt, ap);
  5789. + va_end (ap);
  5790. + ipkg_cb_message(conf,level,ts);
  5791. + }
  5792. +}
  5793. diff -Nur busybox-1.16.1.orig/archival/libipkg/ipkg_message.h busybox-1.16.1/archival/libipkg/ipkg_message.h
  5794. --- busybox-1.16.1.orig/archival/libipkg/ipkg_message.h 1970-01-01 01:00:00.000000000 +0100
  5795. +++ busybox-1.16.1/archival/libipkg/ipkg_message.h 2010-04-22 19:18:12.000000000 +0200
  5796. @@ -0,0 +1,32 @@
  5797. +/* ipkg_message.h - the itsy package management system
  5798. +
  5799. + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
  5800. +
  5801. + This program is free software; you can redistribute it and/or
  5802. + modify it under the terms of the GNU General Public License as
  5803. + published by the Free Software Foundation; either version 2, or (at
  5804. + your option) any later version.
  5805. +
  5806. + This program is distributed in the hope that it will be useful, but
  5807. + WITHOUT ANY WARRANTY; without even the implied warranty of
  5808. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  5809. + General Public License for more details.
  5810. +*/
  5811. +
  5812. +#ifndef _IPKG_MESSAGE_H_
  5813. +#define _IPKG_MESSAGE_H_
  5814. +
  5815. +#include "ipkg.h"
  5816. +#include "ipkg_conf.h"
  5817. +
  5818. +typedef enum {
  5819. + IPKG_ERROR, /* error conditions */
  5820. + IPKG_NOTICE, /* normal but significant condition */
  5821. + IPKG_INFO, /* informational message */
  5822. + IPKG_DEBUG, /* debug level message */
  5823. + IPKG_DEBUG2, /* more debug level message */
  5824. +} message_level_t;
  5825. +
  5826. +extern void ipkg_message(ipkg_conf_t *conf, message_level_t level, const char *fmt, ...);
  5827. +
  5828. +#endif /* _IPKG_MESSAGE_H_ */
  5829. diff -Nur busybox-1.16.1.orig/archival/libipkg/ipkg_remove.c busybox-1.16.1/archival/libipkg/ipkg_remove.c
  5830. --- busybox-1.16.1.orig/archival/libipkg/ipkg_remove.c 1970-01-01 01:00:00.000000000 +0100
  5831. +++ busybox-1.16.1/archival/libipkg/ipkg_remove.c 2010-04-22 19:18:12.000000000 +0200
  5832. @@ -0,0 +1,385 @@
  5833. +/* ipkg_remove.c - the itsy package management system
  5834. +
  5835. + Carl D. Worth
  5836. +
  5837. + Copyright (C) 2001 University of Southern California
  5838. +
  5839. + This program is free software; you can redistribute it and/or
  5840. + modify it under the terms of the GNU General Public License as
  5841. + published by the Free Software Foundation; either version 2, or (at
  5842. + your option) any later version.
  5843. +
  5844. + This program is distributed in the hope that it will be useful, but
  5845. + WITHOUT ANY WARRANTY; without even the implied warranty of
  5846. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  5847. + General Public License for more details.
  5848. +*/
  5849. +
  5850. +#include "ipkg.h"
  5851. +#include "ipkg_message.h"
  5852. +
  5853. +#include <glob.h>
  5854. +
  5855. +#include "ipkg_remove.h"
  5856. +
  5857. +#include "file_util.h"
  5858. +#include "sprintf_alloc.h"
  5859. +#include "str_util.h"
  5860. +
  5861. +#include "ipkg_cmd.h"
  5862. +
  5863. +int ipkg_remove_dependent_pkgs (ipkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **dependents);
  5864. +
  5865. +/*
  5866. + * Returns number of the number of packages depending on the packages provided by this package.
  5867. + * Every package implicitly provides itself.
  5868. + */
  5869. +int pkg_has_installed_dependents(pkg_t *pkg, abstract_pkg_t *** pdependents)
  5870. +{
  5871. + int nprovides = pkg->provides_count;
  5872. + abstract_pkg_t **provides = pkg->provides;
  5873. + int n_installed_dependents = 0;
  5874. + int i;
  5875. + for (i = 0; i <= nprovides; i++) {
  5876. + abstract_pkg_t *providee = provides[i];
  5877. + abstract_pkg_t **dependers = providee->depended_upon_by;
  5878. + abstract_pkg_t *dep_ab_pkg;
  5879. + if (dependers == NULL)
  5880. + continue;
  5881. + while ((dep_ab_pkg = *dependers++) != NULL) {
  5882. + if (dep_ab_pkg->state_status == SS_INSTALLED){
  5883. + n_installed_dependents++;
  5884. + }
  5885. + }
  5886. +
  5887. + }
  5888. + /* if caller requested the set of installed dependents */
  5889. + if (pdependents) {
  5890. + int p = 0;
  5891. + abstract_pkg_t **dependents = (abstract_pkg_t **)malloc((n_installed_dependents+1)*sizeof(abstract_pkg_t *));
  5892. +
  5893. + if ( dependents == NULL ){
  5894. + fprintf(stderr,"%s Unable to allocate memory. REPORT THIS BUG IN BUGZILLA PLEASE\n", __FUNCTION__);
  5895. + return -1;
  5896. + }
  5897. +
  5898. + *pdependents = dependents;
  5899. + for (i = 0; i <= nprovides; i++) {
  5900. + abstract_pkg_t *providee = provides[i];
  5901. + abstract_pkg_t **dependers = providee->depended_upon_by;
  5902. + abstract_pkg_t *dep_ab_pkg;
  5903. + if (dependers == NULL)
  5904. + continue;
  5905. + while ((dep_ab_pkg = *dependers++) != NULL) {
  5906. + if (dep_ab_pkg->state_status == SS_INSTALLED && !(dep_ab_pkg->state_flag & SF_MARKED)) {
  5907. + dependents[p++] = dep_ab_pkg;
  5908. + dep_ab_pkg->state_flag |= SF_MARKED;
  5909. + }
  5910. + }
  5911. + }
  5912. + dependents[p] = NULL;
  5913. + /* now clear the marks */
  5914. + for (i = 0; i < p; i++) {
  5915. + abstract_pkg_t *dep_ab_pkg = dependents[i];
  5916. + dep_ab_pkg->state_flag &= ~SF_MARKED;
  5917. + }
  5918. + }
  5919. + return n_installed_dependents;
  5920. +}
  5921. +
  5922. +int ipkg_remove_dependent_pkgs (ipkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **dependents)
  5923. +{
  5924. + int i;
  5925. + int a;
  5926. + int count;
  5927. + pkg_vec_t *dependent_pkgs = pkg_vec_alloc();
  5928. + abstract_pkg_t * ab_pkg;
  5929. +
  5930. + if((ab_pkg = pkg->parent) == NULL){
  5931. + fprintf(stderr, "%s: unable to get dependent pkgs. pkg %s isn't in hash table\n",
  5932. + __FUNCTION__, pkg->name);
  5933. + return 0;
  5934. + }
  5935. +
  5936. + if (dependents == NULL)
  5937. + return 0;
  5938. +
  5939. + // here i am using the dependencies_checked
  5940. + if (ab_pkg->dependencies_checked == 2) // variable to make out whether this package
  5941. + return 0; // has already been encountered in the process
  5942. + // of marking packages for removal - Karthik
  5943. + ab_pkg->dependencies_checked = 2;
  5944. +
  5945. + i = 0;
  5946. + count = 1;
  5947. + while (dependents [i] != NULL) {
  5948. + abstract_pkg_t *dep_ab_pkg = dependents[i];
  5949. +
  5950. + if (dep_ab_pkg->dependencies_checked == 2){
  5951. + i++;
  5952. + continue;
  5953. + }
  5954. + if (dep_ab_pkg->state_status == SS_INSTALLED) {
  5955. + for (a = 0; a < dep_ab_pkg->pkgs->len; a++) {
  5956. + pkg_t *dep_pkg = dep_ab_pkg->pkgs->pkgs[a];
  5957. + if (dep_pkg->state_status == SS_INSTALLED) {
  5958. + pkg_vec_insert(dependent_pkgs, dep_pkg);
  5959. + count++;
  5960. + }
  5961. + }
  5962. + }
  5963. + i++;
  5964. + /* 1 - to keep track of visited ab_pkgs when checking for possiblility of a broken removal of pkgs.
  5965. + * 2 - to keep track of pkgs whose deps have been checked alrdy - Karthik */
  5966. + }
  5967. +
  5968. + if (count == 1)
  5969. + return 0;
  5970. +
  5971. +
  5972. + for (i = 0; i < dependent_pkgs->len; i++) {
  5973. + int err = ipkg_remove_pkg(conf, dependent_pkgs->pkgs[i],0);
  5974. + if (err)
  5975. + return err;
  5976. + }
  5977. + return 0;
  5978. +}
  5979. +
  5980. +static int user_prefers_removing_dependents(ipkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **dependents)
  5981. +{
  5982. + abstract_pkg_t *dep_ab_pkg;
  5983. + ipkg_message(conf, IPKG_ERROR, "Package %s is depended upon by packages:\n", pkg->name);
  5984. + while ((dep_ab_pkg = *dependents++) != NULL) {
  5985. + if (dep_ab_pkg->state_status == SS_INSTALLED)
  5986. + ipkg_message(conf, IPKG_ERROR, "\t%s\n", dep_ab_pkg->name);
  5987. + }
  5988. + ipkg_message(conf, IPKG_ERROR, "These might cease to work if package %s is removed.\n\n", pkg->name);
  5989. + ipkg_message(conf, IPKG_ERROR, "");
  5990. + ipkg_message(conf, IPKG_ERROR, "You can force removal of this package with -force-depends.\n");
  5991. + ipkg_message(conf, IPKG_ERROR, "You can force removal of this package and its dependents\n");
  5992. + ipkg_message(conf, IPKG_ERROR, "with -force-removal-of-dependent-packages or -recursive\n");
  5993. + ipkg_message(conf, IPKG_ERROR, "or by setting option force_removal_of_dependent_packages\n");
  5994. + ipkg_message(conf, IPKG_ERROR, "in ipkg.conf.\n");
  5995. + return 0;
  5996. +}
  5997. +
  5998. +int ipkg_remove_pkg(ipkg_conf_t *conf, pkg_t *pkg,int message)
  5999. +{
  6000. +/* Actually, when "message == 1" I have been called from an upgrade, and not from a normal remove
  6001. + thus I wan't check for essential, as I'm upgrading.
  6002. + I hope it won't break anything :)
  6003. +*/
  6004. + int err;
  6005. + abstract_pkg_t *parent_pkg = NULL;
  6006. +
  6007. + if (pkg->essential && !message) {
  6008. + if (conf->force_removal_of_essential_packages) {
  6009. + fprintf(stderr, "WARNING: Removing essential package %s under your coercion.\n"
  6010. + "\tIf your system breaks, you get to keep both pieces\n",
  6011. + pkg->name);
  6012. + } else {
  6013. + fprintf(stderr, "ERROR: Refusing to remove essential package %s.\n"
  6014. + "\tRemoving an essential package may lead to an unusable system, but if\n"
  6015. + "\tyou enjoy that kind of pain, you can force ipkg to proceed against\n"
  6016. + "\tits will with the option: -force-removal-of-essential-packages\n",
  6017. + pkg->name);
  6018. + return IPKG_PKG_IS_ESSENTIAL;
  6019. + }
  6020. + }
  6021. +
  6022. + if ((parent_pkg = pkg->parent) == NULL)
  6023. + return 0;
  6024. +
  6025. + /* only attempt to remove dependent installed packages if
  6026. + * force_depends is not specified or the package is being
  6027. + * replaced.
  6028. + */
  6029. + if (!conf->force_depends
  6030. + && !(pkg->state_flag & SF_REPLACE)) {
  6031. + abstract_pkg_t **dependents;
  6032. + int has_installed_dependents =
  6033. + pkg_has_installed_dependents(pkg, &dependents);
  6034. +
  6035. + if (has_installed_dependents) {
  6036. + /*
  6037. + * if this package is depended up by others, then either we should
  6038. + * not remove it or we should remove it and all of its dependents
  6039. + */
  6040. +
  6041. + if (!conf->force_removal_of_dependent_packages
  6042. + && !user_prefers_removing_dependents(conf, pkg, dependents)) {
  6043. + return IPKG_PKG_HAS_DEPENDENTS;
  6044. + }
  6045. +
  6046. + /* remove packages depending on this package - Karthik */
  6047. + err = ipkg_remove_dependent_pkgs (conf, pkg, dependents);
  6048. + free(dependents);
  6049. + if (err) return err;
  6050. + }
  6051. + }
  6052. +
  6053. + if ( message==0 ){
  6054. + printf("Removing package %s from %s...\n", pkg->name, pkg->dest->name);
  6055. + fflush(stdout);
  6056. + }
  6057. + pkg->state_flag |= SF_FILELIST_CHANGED;
  6058. +
  6059. + pkg->state_want = SW_DEINSTALL;
  6060. + ipkg_state_changed++;
  6061. +
  6062. + pkg_run_script(conf, pkg, "prerm", "remove");
  6063. +
  6064. + /* DPKG_INCOMPATIBILITY: dpkg is slightly different here. It
  6065. + maintains an empty filelist rather than deleting it. That seems
  6066. + like a big pain, and I don't see that that should make a big
  6067. + difference, but for anyone who wants tighter compatibility,
  6068. + feel free to fix this. */
  6069. + remove_data_files_and_list(conf, pkg);
  6070. +
  6071. + pkg_run_script(conf, pkg, "postrm", "remove");
  6072. +
  6073. + remove_maintainer_scripts_except_postrm(conf, pkg);
  6074. +
  6075. + /* Aman Gupta - Since ipkg is made for handheld devices with limited
  6076. + * space, it doesn't make sense to leave extra configurations, files,
  6077. + * and maintainer scripts left around. So, we make remove like purge,
  6078. + * and take out all the crap :) */
  6079. +
  6080. + remove_postrm(conf, pkg);
  6081. + pkg->state_status = SS_NOT_INSTALLED;
  6082. +
  6083. + if (parent_pkg)
  6084. + parent_pkg->state_status = SS_NOT_INSTALLED;
  6085. +
  6086. + return 0;
  6087. +}
  6088. +
  6089. +int ipkg_purge_pkg(ipkg_conf_t *conf, pkg_t *pkg)
  6090. +{
  6091. + ipkg_remove_pkg(conf, pkg,0);
  6092. + return 0;
  6093. +}
  6094. +
  6095. +int remove_data_files_and_list(ipkg_conf_t *conf, pkg_t *pkg)
  6096. +{
  6097. + str_list_t installed_dirs;
  6098. + str_list_t *installed_files;
  6099. + str_list_elt_t *iter;
  6100. + char *file_name;
  6101. + conffile_t *conffile;
  6102. + int removed_a_dir;
  6103. + pkg_t *owner;
  6104. +
  6105. + str_list_init(&installed_dirs);
  6106. + installed_files = pkg_get_installed_files(pkg);
  6107. +
  6108. + for (iter = installed_files->head; iter; iter = iter->next) {
  6109. + file_name = iter->data;
  6110. +
  6111. + if (file_is_dir(file_name)) {
  6112. + str_list_append(&installed_dirs, strdup(file_name));
  6113. + continue;
  6114. + }
  6115. +
  6116. + conffile = pkg_get_conffile(pkg, file_name);
  6117. + if (conffile) {
  6118. + /* XXX: QUESTION: Is this right? I figure we only need to
  6119. + save the conffile if it has been modified. Is that what
  6120. + dpkg does? Or does dpkg preserve all conffiles? If so,
  6121. + this seems like a better thing to do to conserve
  6122. + space. */
  6123. + if (conffile_has_been_modified(conf, conffile)) {
  6124. + printf(" not deleting modified conffile %s\n", file_name);
  6125. + fflush(stdout);
  6126. + continue;
  6127. + }
  6128. + }
  6129. +
  6130. + ipkg_message(conf, IPKG_INFO, " deleting %s (noaction=%d)\n", file_name, conf->noaction);
  6131. + if (!conf->noaction)
  6132. + unlink(file_name);
  6133. + }
  6134. +
  6135. + if (!conf->noaction) {
  6136. + do {
  6137. + removed_a_dir = 0;
  6138. + for (iter = installed_dirs.head; iter; iter = iter->next) {
  6139. + file_name = iter->data;
  6140. +
  6141. + if (rmdir(file_name) == 0) {
  6142. + ipkg_message(conf, IPKG_INFO, " deleting %s\n", file_name);
  6143. + removed_a_dir = 1;
  6144. + str_list_remove(&installed_dirs, &iter);
  6145. + }
  6146. + }
  6147. + } while (removed_a_dir);
  6148. + }
  6149. +
  6150. + pkg_free_installed_files(pkg);
  6151. + /* We have to remove the file list now, so that
  6152. + find_pkg_owning_file does not always just report this package */
  6153. + pkg_remove_installed_files_list(conf, pkg);
  6154. +
  6155. + /* Don't print warning for dirs that are provided by other packages */
  6156. + for (iter = installed_dirs.head; iter; iter = iter->next) {
  6157. + file_name = iter->data;
  6158. +
  6159. + owner = file_hash_get_file_owner(conf, file_name);
  6160. + if (owner) {
  6161. + free(iter->data);
  6162. + iter->data = NULL;
  6163. + str_list_remove(&installed_dirs, &iter);
  6164. + }
  6165. + }
  6166. +
  6167. + /* cleanup */
  6168. + for (iter = installed_dirs.head; iter; iter = iter->next) {
  6169. + free(iter->data);
  6170. + iter->data = NULL;
  6171. + }
  6172. + str_list_deinit(&installed_dirs);
  6173. +
  6174. + return 0;
  6175. +}
  6176. +
  6177. +int remove_maintainer_scripts_except_postrm(ipkg_conf_t *conf, pkg_t *pkg)
  6178. +{
  6179. + int i, err;
  6180. + char *globpattern;
  6181. + glob_t globbuf;
  6182. +
  6183. + if (conf->noaction) return 0;
  6184. +
  6185. + sprintf_alloc(&globpattern, "%s/%s.*",
  6186. + pkg->dest->info_dir, pkg->name);
  6187. + err = glob(globpattern, 0, NULL, &globbuf);
  6188. + free(globpattern);
  6189. + if (err) {
  6190. + return 0;
  6191. + }
  6192. +
  6193. + for (i = 0; i < globbuf.gl_pathc; i++) {
  6194. + if (str_ends_with(globbuf.gl_pathv[i], ".postrm")) {
  6195. + continue;
  6196. + }
  6197. + ipkg_message(conf, IPKG_INFO, " deleting %s\n", globbuf.gl_pathv[i]);
  6198. + unlink(globbuf.gl_pathv[i]);
  6199. + }
  6200. + globfree(&globbuf);
  6201. +
  6202. + return 0;
  6203. +}
  6204. +
  6205. +int remove_postrm(ipkg_conf_t *conf, pkg_t *pkg)
  6206. +{
  6207. + char *postrm_file_name;
  6208. +
  6209. + if (conf->noaction) return 0;
  6210. +
  6211. + sprintf_alloc(&postrm_file_name, "%s/%s.postrm",
  6212. + pkg->dest->info_dir, pkg->name);
  6213. + unlink(postrm_file_name);
  6214. + free(postrm_file_name);
  6215. +
  6216. + return 0;
  6217. +}
  6218. diff -Nur busybox-1.16.1.orig/archival/libipkg/ipkg_remove.h busybox-1.16.1/archival/libipkg/ipkg_remove.h
  6219. --- busybox-1.16.1.orig/archival/libipkg/ipkg_remove.h 1970-01-01 01:00:00.000000000 +0100
  6220. +++ busybox-1.16.1/archival/libipkg/ipkg_remove.h 2010-04-22 19:18:12.000000000 +0200
  6221. @@ -0,0 +1,33 @@
  6222. +/* ipkg_remove.h - the itsy package management system
  6223. +
  6224. + Carl D. Worth
  6225. +
  6226. + Copyright (C) 2001 University of Southern California
  6227. +
  6228. + This program is free software; you can redistribute it and/or
  6229. + modify it under the terms of the GNU General Public License as
  6230. + published by the Free Software Foundation; either version 2, or (at
  6231. + your option) any later version.
  6232. +
  6233. + This program is distributed in the hope that it will be useful, but
  6234. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6235. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6236. + General Public License for more details.
  6237. +*/
  6238. +
  6239. +#ifndef IPKG_REMOVE_H
  6240. +#define IPKG_REMOVE_H
  6241. +
  6242. +#include "pkg.h"
  6243. +#include "ipkg_conf.h"
  6244. +
  6245. +int ipkg_remove_pkg(ipkg_conf_t *conf, pkg_t *pkg,int message);
  6246. +int ipkg_purge_pkg(ipkg_conf_t *conf, pkg_t *pkg);
  6247. +int possible_broken_removal_of_packages (ipkg_conf_t *conf, pkg_t *pkg);
  6248. +int pkg_has_installed_dependents(pkg_t *pkg, abstract_pkg_t *** pdependents);
  6249. +int remove_data_files_and_list(ipkg_conf_t *conf, pkg_t *pkg);
  6250. +int remove_maintainer_scripts_except_postrm (ipkg_conf_t *conf, pkg_t *pkg);
  6251. +int remove_postrm (ipkg_conf_t *conf, pkg_t *pkg);
  6252. +
  6253. +
  6254. +#endif
  6255. diff -Nur busybox-1.16.1.orig/archival/libipkg/ipkg_upgrade.c busybox-1.16.1/archival/libipkg/ipkg_upgrade.c
  6256. --- busybox-1.16.1.orig/archival/libipkg/ipkg_upgrade.c 1970-01-01 01:00:00.000000000 +0100
  6257. +++ busybox-1.16.1/archival/libipkg/ipkg_upgrade.c 2010-04-22 19:18:12.000000000 +0200
  6258. @@ -0,0 +1,79 @@
  6259. +/* ipkg_upgrade.c - the itsy package management system
  6260. +
  6261. + Carl D. Worth
  6262. + Copyright (C) 2001 University of Southern California
  6263. +
  6264. + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
  6265. +
  6266. + This program is free software; you can redistribute it and/or
  6267. + modify it under the terms of the GNU General Public License as
  6268. + published by the Free Software Foundation; either version 2, or (at
  6269. + your option) any later version.
  6270. +
  6271. + This program is distributed in the hope that it will be useful, but
  6272. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6273. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6274. + General Public License for more details.
  6275. +*/
  6276. +
  6277. +#include "ipkg.h"
  6278. +#include "ipkg_install.h"
  6279. +#include "ipkg_message.h"
  6280. +
  6281. +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old);
  6282. +
  6283. +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old)
  6284. +{
  6285. + pkg_t *new;
  6286. + int cmp;
  6287. + char *old_version, *new_version;
  6288. +
  6289. + if (old->state_flag & SF_HOLD) {
  6290. + ipkg_message(conf, IPKG_NOTICE,
  6291. + "Not upgrading package %s which is marked "
  6292. + "hold (flags=%#x)\n", old->name, old->state_flag);
  6293. + return 0;
  6294. + }
  6295. +
  6296. + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, old->name);
  6297. + if (new == NULL) {
  6298. + old_version = pkg_version_str_alloc(old);
  6299. + ipkg_message(conf, IPKG_NOTICE,
  6300. + "Assuming locally installed package %s (%s) "
  6301. + "is up to date.\n", old->name, old_version);
  6302. + free(old_version);
  6303. + return 0;
  6304. + }
  6305. +
  6306. + old_version = pkg_version_str_alloc(old);
  6307. + new_version = pkg_version_str_alloc(new);
  6308. +
  6309. + cmp = pkg_compare_versions(old, new);
  6310. + ipkg_message(conf, IPKG_DEBUG,
  6311. + "comparing visible versions of pkg %s:"
  6312. + "\n\t%s is installed "
  6313. + "\n\t%s is available "
  6314. + "\n\t%d was comparison result\n",
  6315. + old->name, old_version, new_version, cmp);
  6316. + if (cmp == 0) {
  6317. + ipkg_message(conf, IPKG_INFO,
  6318. + "Package %s (%s) installed in %s is up to date.\n",
  6319. + old->name, old_version, old->dest->name);
  6320. + free(old_version);
  6321. + free(new_version);
  6322. + return 0;
  6323. + } else if (cmp > 0) {
  6324. + ipkg_message(conf, IPKG_NOTICE,
  6325. + "Not downgrading package %s on %s from %s to %s.\n",
  6326. + old->name, old->dest->name, old_version, new_version);
  6327. + free(old_version);
  6328. + free(new_version);
  6329. + return 0;
  6330. + } else if (cmp < 0) {
  6331. + new->dest = old->dest;
  6332. + old->state_want = SW_DEINSTALL;
  6333. + }
  6334. +
  6335. + new->state_flag |= SF_USER;
  6336. + return ipkg_install_pkg(conf, new,1);
  6337. +}
  6338. diff -Nur busybox-1.16.1.orig/archival/libipkg/ipkg_upgrade.h busybox-1.16.1/archival/libipkg/ipkg_upgrade.h
  6339. --- busybox-1.16.1.orig/archival/libipkg/ipkg_upgrade.h 1970-01-01 01:00:00.000000000 +0100
  6340. +++ busybox-1.16.1/archival/libipkg/ipkg_upgrade.h 2010-04-22 19:18:12.000000000 +0200
  6341. @@ -0,0 +1,18 @@
  6342. +/* ipkg_upgrade.c - the itsy package management system
  6343. +
  6344. + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
  6345. +
  6346. + This program is free software; you can redistribute it and/or
  6347. + modify it under the terms of the GNU General Public License as
  6348. + published by the Free Software Foundation; either version 2, or (at
  6349. + your option) any later version.
  6350. +
  6351. + This program is distributed in the hope that it will be useful, but
  6352. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6353. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6354. + General Public License for more details.
  6355. +*/
  6356. +
  6357. +#include "ipkg.h"
  6358. +
  6359. +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old);
  6360. diff -Nur busybox-1.16.1.orig/archival/libipkg/ipkg_utils.c busybox-1.16.1/archival/libipkg/ipkg_utils.c
  6361. --- busybox-1.16.1.orig/archival/libipkg/ipkg_utils.c 1970-01-01 01:00:00.000000000 +0100
  6362. +++ busybox-1.16.1/archival/libipkg/ipkg_utils.c 2010-04-22 19:18:12.000000000 +0200
  6363. @@ -0,0 +1,185 @@
  6364. +/* ipkg_utils.c - the itsy package management system
  6365. +
  6366. + Steven M. Ayer
  6367. +
  6368. + Copyright (C) 2002 Compaq Computer Corporation
  6369. +
  6370. + This program is free software; you can redistribute it and/or
  6371. + modify it under the terms of the GNU General Public License as
  6372. + published by the Free Software Foundation; either version 2, or (at
  6373. + your option) any later version.
  6374. +
  6375. + This program is distributed in the hope that it will be useful, but
  6376. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6377. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6378. + General Public License for more details.
  6379. +*/
  6380. +
  6381. +#include "ipkg.h"
  6382. +#include <errno.h>
  6383. +#include <ctype.h>
  6384. +#include <sys/vfs.h>
  6385. +
  6386. +#include "ipkg_utils.h"
  6387. +#include "pkg.h"
  6388. +#include "pkg_hash.h"
  6389. +
  6390. +void push_error_list(struct errlist ** errors, char * msg);
  6391. +void reverse_error_list(struct errlist **errors);
  6392. +void free_error_list(struct errlist **errors);
  6393. +
  6394. +struct errlist* error_list;
  6395. +
  6396. +int get_available_blocks(char * filesystem)
  6397. +{
  6398. + struct statfs sfs;
  6399. +
  6400. + if(statfs(filesystem, &sfs)){
  6401. + fprintf(stderr, "bad statfs\n");
  6402. + return 0;
  6403. + }
  6404. + /* fprintf(stderr, "reported fs type %x\n", sfs.f_type); */
  6405. + return ((sfs.f_bavail * sfs.f_bsize) / 1024);
  6406. +}
  6407. +
  6408. +char **read_raw_pkgs_from_file(const char *file_name)
  6409. +{
  6410. + FILE *fp;
  6411. + char **ret;
  6412. +
  6413. + if(!(fp = fopen(file_name, "r"))){
  6414. + fprintf(stderr, "can't get %s open for read\n", file_name);
  6415. + return NULL;
  6416. + }
  6417. +
  6418. + ret = read_raw_pkgs_from_stream(fp);
  6419. +
  6420. + fclose(fp);
  6421. +
  6422. + return ret;
  6423. +}
  6424. +
  6425. +char **read_raw_pkgs_from_stream(FILE *fp)
  6426. +{
  6427. + char **raw = NULL, *buf, *scout;
  6428. + int count = 0;
  6429. + size_t size = 512;
  6430. +
  6431. + buf = malloc (size);
  6432. +
  6433. + while (fgets(buf, size, fp)) {
  6434. + while (strlen (buf) == (size - 1)
  6435. + && buf[size-2] != '\n') {
  6436. + size_t o = size - 1;
  6437. + size *= 2;
  6438. + buf = realloc (buf, size);
  6439. + if (fgets (buf + o, size - o, fp) == NULL)
  6440. + break;
  6441. + }
  6442. +
  6443. + if(!(count % 50))
  6444. + raw = realloc(raw, (count + 50) * sizeof(char *));
  6445. +
  6446. + if((scout = strchr(buf, '\n')))
  6447. + *scout = '\0';
  6448. +
  6449. + raw[count++] = strdup(buf);
  6450. + }
  6451. +
  6452. + raw = realloc(raw, (count + 1) * sizeof(char *));
  6453. + raw[count] = NULL;
  6454. +
  6455. + free (buf);
  6456. +
  6457. + return raw;
  6458. +}
  6459. +
  6460. +/* something to remove whitespace, a hash pooper */
  6461. +char *trim_alloc(char *line)
  6462. +{
  6463. + char *new;
  6464. + char *dest, *src, *end;
  6465. +
  6466. + new = malloc(strlen(line) + 1);
  6467. + if ( new == NULL ){
  6468. + fprintf(stderr,"%s: Unable to allocate memory\n",__FUNCTION__);
  6469. + return NULL;
  6470. + }
  6471. + dest = new, src = line, end = line + (strlen(line) - 1);
  6472. +
  6473. + /* remove it from the front */
  6474. + while(src &&
  6475. + isspace(*src) &&
  6476. + *src)
  6477. + src++;
  6478. + /* and now from the back */
  6479. + while((end > src) &&
  6480. + isspace(*end))
  6481. + end--;
  6482. + end++;
  6483. + *end = '\0';
  6484. + strcpy(new, src);
  6485. + /* this does from the first space
  6486. + * blasting away any versions stuff in depends
  6487. + while(src &&
  6488. + !isspace(*src) &&
  6489. + *src)
  6490. + *dest++ = *src++;
  6491. + *dest = '\0';
  6492. + */
  6493. +
  6494. + return new;
  6495. +}
  6496. +
  6497. +int line_is_blank(const char *line)
  6498. +{
  6499. + const char *s;
  6500. +
  6501. + for (s = line; *s; s++) {
  6502. + if (!isspace(*s))
  6503. + return 0;
  6504. + }
  6505. + return 1;
  6506. +}
  6507. +
  6508. +void push_error_list(struct errlist ** errors, char * msg){
  6509. + struct errlist *err_lst_tmp;
  6510. +
  6511. +
  6512. + err_lst_tmp = malloc ( sizeof (err_lst_tmp) );
  6513. + err_lst_tmp->errmsg=strdup(msg) ;
  6514. + err_lst_tmp->next = *errors;
  6515. + *errors = err_lst_tmp;
  6516. +}
  6517. +
  6518. +
  6519. +void reverse_error_list(struct errlist **errors){
  6520. + struct errlist *result=NULL;
  6521. + struct errlist *current= *errors;
  6522. + struct errlist *next;
  6523. +
  6524. + while ( current != NULL ) {
  6525. + next = current->next;
  6526. + current->next=result;
  6527. + result=current;
  6528. + current=next;
  6529. + }
  6530. + *errors=result;
  6531. +
  6532. +}
  6533. +
  6534. +
  6535. +void free_error_list(struct errlist **errors){
  6536. + struct errlist *current = *errors;
  6537. +
  6538. + while (current != NULL) {
  6539. + free(current->errmsg);
  6540. + current = (*errors)->next;
  6541. + free(*errors);
  6542. + *errors = current;
  6543. + }
  6544. +
  6545. +
  6546. +}
  6547. +
  6548. +
  6549. diff -Nur busybox-1.16.1.orig/archival/libipkg/ipkg_utils.h busybox-1.16.1/archival/libipkg/ipkg_utils.h
  6550. --- busybox-1.16.1.orig/archival/libipkg/ipkg_utils.h 1970-01-01 01:00:00.000000000 +0100
  6551. +++ busybox-1.16.1/archival/libipkg/ipkg_utils.h 2010-04-22 19:18:12.000000000 +0200
  6552. @@ -0,0 +1,29 @@
  6553. +/* ipkg_utils.h - the itsy package management system
  6554. +
  6555. + Steven M. Ayer
  6556. +
  6557. + Copyright (C) 2002 Compaq Computer Corporation
  6558. +
  6559. + This program is free software; you can redistribute it and/or
  6560. + modify it under the terms of the GNU General Public License as
  6561. + published by the Free Software Foundation; either version 2, or (at
  6562. + your option) any later version.
  6563. +
  6564. + This program is distributed in the hope that it will be useful, but
  6565. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6566. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6567. + General Public License for more details.
  6568. +*/
  6569. +
  6570. +#ifndef IPKG_UTILS_H
  6571. +#define IPKG_UTILS_H
  6572. +
  6573. +#include "pkg.h"
  6574. +
  6575. +int get_available_blocks(char * filesystem);
  6576. +char **read_raw_pkgs_from_file(const char *file_name);
  6577. +char **read_raw_pkgs_from_stream(FILE *fp);
  6578. +char *trim_alloc(char * line);
  6579. +int line_is_blank(const char *line);
  6580. +
  6581. +#endif
  6582. diff -Nur busybox-1.16.1.orig/archival/libipkg/Kbuild busybox-1.16.1/archival/libipkg/Kbuild
  6583. --- busybox-1.16.1.orig/archival/libipkg/Kbuild 1970-01-01 01:00:00.000000000 +0100
  6584. +++ busybox-1.16.1/archival/libipkg/Kbuild 2010-04-22 19:18:12.000000000 +0200
  6585. @@ -0,0 +1,60 @@
  6586. +# Makefile for busybox
  6587. +#
  6588. +# Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
  6589. +# Copyright (C) 2006 OpenWrt.org
  6590. +#
  6591. +# Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
  6592. +
  6593. +LIBIPKG_CORE_OBJS:= \
  6594. + args.o \
  6595. + libipkg.o \
  6596. + user.o \
  6597. +
  6598. +LIBIPKG_CMD_OBJS:= \
  6599. + ipkg_cmd.o \
  6600. + ipkg_configure.o \
  6601. + ipkg_download.o \
  6602. + ipkg_install.o \
  6603. + ipkg_remove.o \
  6604. + ipkg_upgrade.o \
  6605. +
  6606. +LIBIPKG_DB_OBJS:= \
  6607. + hash_table.o \
  6608. + ipkg_conf.o \
  6609. + ipkg_utils.o \
  6610. + pkg.o \
  6611. + pkg_depends.o \
  6612. + pkg_extract.o \
  6613. + pkg_hash.o \
  6614. + pkg_parse.o \
  6615. + pkg_vec.o \
  6616. +
  6617. +LIBIPKG_LIST_OBJS:= \
  6618. + conffile.o \
  6619. + conffile_list.o \
  6620. + nv_pair.o \
  6621. + nv_pair_list.o \
  6622. + pkg_dest.o \
  6623. + pkg_dest_list.o \
  6624. + pkg_src.o \
  6625. + pkg_src_list.o \
  6626. + str_list.o \
  6627. + void_list.o \
  6628. +
  6629. +LIBIPKG_UTIL_OBJS:= \
  6630. + file_util.o \
  6631. + ipkg_message.o \
  6632. + str_util.o \
  6633. + xsystem.o \
  6634. +
  6635. +lib-y :=
  6636. +lib-$(CONFIG_IPKG) += $(LIBIPKG_CORE_OBJS)
  6637. +lib-$(CONFIG_IPKG) += $(LIBIPKG_CMD_OBJS)
  6638. +lib-$(CONFIG_IPKG) += $(LIBIPKG_DB_OBJS)
  6639. +lib-$(CONFIG_IPKG) += $(LIBIPKG_LIST_OBJS)
  6640. +lib-$(CONFIG_IPKG) += $(LIBIPKG_UTIL_OBJS)
  6641. +
  6642. +ifeq ($(strip $(IPKG_ARCH)),)
  6643. +IPKG_ARCH:=$(TARGET_ARCH)
  6644. +endif
  6645. +CFLAGS += -DIPKGLIBDIR="\"/usr/lib\"" -DHOST_CPU_STR="\"$(IPKG_ARCH)\""
  6646. diff -Nur busybox-1.16.1.orig/archival/libipkg/libipkg.c busybox-1.16.1/archival/libipkg/libipkg.c
  6647. --- busybox-1.16.1.orig/archival/libipkg/libipkg.c 1970-01-01 01:00:00.000000000 +0100
  6648. +++ busybox-1.16.1/archival/libipkg/libipkg.c 2010-04-22 19:18:12.000000000 +0200
  6649. @@ -0,0 +1,525 @@
  6650. +/* ipkglib.c - the itsy package management system
  6651. +
  6652. + Florina Boor
  6653. +
  6654. + Copyright (C) 2003 kernel concepts
  6655. +
  6656. + This program is free software; you can redistribute it and/or
  6657. + modify it under the terms of the GNU General Public License as
  6658. + published by the Free Software Foundation; either version 2, or (at
  6659. + your option) any later version.
  6660. +
  6661. + This program is distributed in the hope that it will be useful, but
  6662. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6663. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6664. + General Public License for more details.
  6665. +*/
  6666. +
  6667. +#include "ipkg.h"
  6668. +#include "ipkg_includes.h"
  6669. +#include "libipkg.h"
  6670. +
  6671. +#include "args.h"
  6672. +#include "ipkg_conf.h"
  6673. +#include "ipkg_cmd.h"
  6674. +#include "file_util.h"
  6675. +
  6676. +int ipkg_file_what(args_t *args, const char *file, const char* command);
  6677. +int default_ipkg_message_callback(ipkg_conf_t *conf, message_level_t level,
  6678. + char *msg);
  6679. +int default_ipkg_list_callback(char *name, char *desc, char *version);
  6680. +int default_ipkg_files_callback(char *desc);
  6681. +int default_ipkg_status_callback(char *desc);
  6682. +char* default_ipkg_response_callback(char *question);
  6683. +
  6684. +
  6685. +ipkg_message_callback ipkg_cb_message = NULL;
  6686. +ipkg_response_callback ipkg_cb_response = NULL;
  6687. +ipkg_status_callback ipkg_cb_status = NULL;
  6688. +ipkg_list_callback ipkg_cb_list = NULL;
  6689. +
  6690. +
  6691. +int
  6692. +ipkg_init (ipkg_message_callback mcall,
  6693. + ipkg_response_callback rcall,
  6694. + args_t * args)
  6695. +{
  6696. + ipkg_cb_message = mcall;
  6697. + ipkg_cb_response = rcall;
  6698. +
  6699. + args_init (args);
  6700. +
  6701. + return 0;
  6702. +}
  6703. +
  6704. +
  6705. +int
  6706. +ipkg_deinit (args_t * args)
  6707. +{
  6708. + args_deinit (args);
  6709. + ipkg_cb_message = NULL;
  6710. + ipkg_cb_response = NULL;
  6711. +
  6712. + /* place other cleanup stuff here */
  6713. +
  6714. + return 0;
  6715. +}
  6716. +
  6717. +
  6718. +int
  6719. +ipkg_packages_list(args_t *args,
  6720. + const char *packages,
  6721. + ipkg_list_callback cblist,
  6722. + void *userdata)
  6723. +{
  6724. + ipkg_cmd_t *cmd;
  6725. + ipkg_conf_t ipkg_conf;
  6726. + int err;
  6727. +
  6728. + err = ipkg_conf_init (&ipkg_conf, args);
  6729. + if (err)
  6730. + {
  6731. + return err;
  6732. + }
  6733. +
  6734. + ipkg_cb_list = cblist;
  6735. + /* we need to do this because of static declarations,
  6736. + * maybe a good idea to change */
  6737. + cmd = ipkg_cmd_find ("list");
  6738. + if (packages)
  6739. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
  6740. + else
  6741. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
  6742. + ipkg_cb_list = NULL;
  6743. + ipkg_conf_deinit (&ipkg_conf);
  6744. + return (err);
  6745. +}
  6746. +
  6747. +
  6748. +int
  6749. +ipkg_packages_status(args_t *args,
  6750. + const char *packages,
  6751. + ipkg_status_callback cbstatus,
  6752. + void *userdata)
  6753. +{
  6754. + ipkg_cmd_t *cmd;
  6755. + ipkg_conf_t ipkg_conf;
  6756. + int err;
  6757. +
  6758. + err = ipkg_conf_init (&ipkg_conf, args);
  6759. + if (err)
  6760. + {
  6761. + return err;
  6762. + }
  6763. +
  6764. + ipkg_cb_status = cbstatus;
  6765. +
  6766. + /* we need to do this because of static declarations,
  6767. + * maybe a good idea to change */
  6768. + cmd = ipkg_cmd_find ("status");
  6769. + if (packages)
  6770. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
  6771. + else
  6772. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
  6773. +
  6774. + ipkg_cb_status = NULL;
  6775. + ipkg_conf_deinit (&ipkg_conf);
  6776. + return (err);
  6777. +}
  6778. +
  6779. +
  6780. +int
  6781. +ipkg_packages_info(args_t *args,
  6782. + const char *packages,
  6783. + ipkg_status_callback cbstatus,
  6784. + void *userdata)
  6785. +{
  6786. + ipkg_cmd_t *cmd;
  6787. + ipkg_conf_t ipkg_conf;
  6788. + int err;
  6789. +
  6790. + err = ipkg_conf_init (&ipkg_conf, args);
  6791. + if (err)
  6792. + {
  6793. + return err;
  6794. + }
  6795. +
  6796. + ipkg_cb_status = cbstatus;
  6797. +
  6798. + /* we need to do this because of static declarations,
  6799. + * maybe a good idea to change */
  6800. + cmd = ipkg_cmd_find ("info");
  6801. + if (packages)
  6802. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
  6803. + else
  6804. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
  6805. +
  6806. + ipkg_cb_status = NULL;
  6807. + ipkg_conf_deinit (&ipkg_conf);
  6808. + return (err);
  6809. +}
  6810. +
  6811. +
  6812. +int
  6813. +ipkg_packages_install (args_t * args, const char *name)
  6814. +{
  6815. + ipkg_cmd_t *cmd;
  6816. + ipkg_conf_t ipkg_conf;
  6817. + int err;
  6818. +
  6819. + /* this error should be handled in application */
  6820. + if (!name || !strlen (name))
  6821. + return (-1);
  6822. +
  6823. + err = ipkg_conf_init (&ipkg_conf, args);
  6824. + if (err)
  6825. + {
  6826. + return err;
  6827. + }
  6828. +
  6829. + /* we need to do this because of static declarations,
  6830. + * maybe a good idea to change */
  6831. + cmd = ipkg_cmd_find ("install");
  6832. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
  6833. +
  6834. + ipkg_conf_deinit(&ipkg_conf);
  6835. + return (err);
  6836. +}
  6837. +
  6838. +
  6839. +int
  6840. +ipkg_packages_remove(args_t *args, const char *name, int purge)
  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. + if (purge)
  6859. + cmd = ipkg_cmd_find ("purge");
  6860. + else
  6861. + cmd = ipkg_cmd_find ("remove");
  6862. +
  6863. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
  6864. +
  6865. + ipkg_conf_deinit(&ipkg_conf);
  6866. + return (err);
  6867. +}
  6868. +
  6869. +
  6870. +int
  6871. +ipkg_lists_update(args_t *args)
  6872. +{
  6873. + ipkg_cmd_t *cmd;
  6874. + ipkg_conf_t ipkg_conf;
  6875. + int err;
  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. + cmd = ipkg_cmd_find ("update");
  6886. +
  6887. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, NULL);
  6888. +
  6889. + ipkg_conf_deinit(&ipkg_conf);
  6890. + return (err);
  6891. +}
  6892. +
  6893. +
  6894. +int
  6895. +ipkg_packages_upgrade(args_t *args)
  6896. +{
  6897. + ipkg_cmd_t *cmd;
  6898. + ipkg_conf_t ipkg_conf;
  6899. + int err;
  6900. +
  6901. + err = ipkg_conf_init (&ipkg_conf, args);
  6902. + if (err)
  6903. + {
  6904. + return err;
  6905. + }
  6906. +
  6907. + /* we need to do this because of static declarations,
  6908. + * maybe a good idea to change */
  6909. + cmd = ipkg_cmd_find ("upgrade");
  6910. +
  6911. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, NULL);
  6912. +
  6913. + ipkg_conf_deinit(&ipkg_conf);
  6914. + return (err);
  6915. +}
  6916. +
  6917. +
  6918. +int
  6919. +ipkg_packages_download (args_t * args, const char *name)
  6920. +{
  6921. + ipkg_cmd_t *cmd;
  6922. + ipkg_conf_t ipkg_conf;
  6923. + int err;
  6924. +
  6925. + /* this error should be handled in application */
  6926. + if (!name || !strlen (name))
  6927. + return (-1);
  6928. +
  6929. + err = ipkg_conf_init (&ipkg_conf, args);
  6930. + if (err)
  6931. + {
  6932. + return err;
  6933. + }
  6934. +
  6935. + /* we need to do this because of static declarations,
  6936. + * maybe a good idea to change */
  6937. + cmd = ipkg_cmd_find ("download");
  6938. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
  6939. +
  6940. + ipkg_conf_deinit(&ipkg_conf);
  6941. + return (err);
  6942. +}
  6943. +
  6944. +
  6945. +int
  6946. +ipkg_package_files(args_t *args,
  6947. + const char *name,
  6948. + ipkg_list_callback cblist,
  6949. + void *userdata)
  6950. +{
  6951. + ipkg_cmd_t *cmd;
  6952. + ipkg_conf_t ipkg_conf;
  6953. + int err;
  6954. +
  6955. + /* this error should be handled in application */
  6956. + if (!name || !strlen (name))
  6957. + return (-1);
  6958. +
  6959. + err = ipkg_conf_init (&ipkg_conf, args);
  6960. + if (err)
  6961. + {
  6962. + return err;
  6963. + }
  6964. +
  6965. + ipkg_cb_list = cblist;
  6966. +
  6967. + /* we need to do this because of static declarations,
  6968. + * maybe a good idea to change */
  6969. + cmd = ipkg_cmd_find ("files");
  6970. +
  6971. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, userdata);
  6972. +
  6973. + ipkg_cb_list = NULL;
  6974. + ipkg_conf_deinit(&ipkg_conf);
  6975. + return (err);
  6976. +}
  6977. +
  6978. +
  6979. +int
  6980. +ipkg_file_search(args_t *args,
  6981. + const char *file,
  6982. + ipkg_list_callback cblist,
  6983. + void *userdata)
  6984. +{
  6985. + ipkg_cmd_t *cmd;
  6986. + ipkg_conf_t ipkg_conf;
  6987. + int err;
  6988. +
  6989. + /* this error should be handled in application */
  6990. + if (!file || !strlen (file))
  6991. + return (-1);
  6992. +
  6993. + err = ipkg_conf_init (&ipkg_conf, args);
  6994. + if (err)
  6995. + {
  6996. + return err;
  6997. + }
  6998. +
  6999. + ipkg_cb_list = cblist;
  7000. +
  7001. + /* we need to do this because of static declarations,
  7002. + * maybe a good idea to change */
  7003. + cmd = ipkg_cmd_find ("search");
  7004. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &file, userdata);
  7005. +
  7006. + ipkg_cb_list = NULL;
  7007. + ipkg_conf_deinit(&ipkg_conf);
  7008. + return(err);
  7009. +}
  7010. +
  7011. +
  7012. +int
  7013. +ipkg_file_what(args_t *args, const char *file, const char* command)
  7014. +{
  7015. + ipkg_cmd_t *cmd;
  7016. + ipkg_conf_t ipkg_conf;
  7017. + int err;
  7018. +
  7019. + /* this error should be handled in application */
  7020. + if (!file || !strlen (file))
  7021. + return (-1);
  7022. +
  7023. + err = ipkg_conf_init (&ipkg_conf, args);
  7024. + if (err)
  7025. + {
  7026. + return err;
  7027. + }
  7028. +
  7029. + /* we need to do this because of static declarations,
  7030. + * maybe a good idea to change */
  7031. + cmd = ipkg_cmd_find (command);
  7032. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &file, NULL);
  7033. +
  7034. + ipkg_conf_deinit(&ipkg_conf);
  7035. + return(err);
  7036. +}
  7037. +
  7038. +#define ipkg_package_whatdepends(args,file) ipkg_file_what(args,file,"whatdepends")
  7039. +#define ipkg_package_whatrecommends(args, file) ipkg_file_what(args,file,"whatrecommends")
  7040. +#define ipkg_package_whatprovides(args, file) ipkg_file_what(args,file,"whatprovides")
  7041. +#define ipkg_package_whatconflicts(args, file) ipkg_file_what(args,file,"whatconflicts")
  7042. +#define ipkg_package_whatreplaces(args, file) ipkg_file_what(args,file,"whatreplaces")
  7043. +
  7044. +
  7045. +int default_ipkg_message_callback(ipkg_conf_t *conf, message_level_t level,
  7046. + char *msg)
  7047. +{
  7048. + if (conf && (conf->verbosity < level)) {
  7049. + return 0;
  7050. + } else {
  7051. + if ( level == IPKG_ERROR )
  7052. + push_error_list(&error_list, msg);
  7053. + else
  7054. + printf(msg);
  7055. + }
  7056. + return 0;
  7057. +}
  7058. +
  7059. +int default_ipkg_list_callback(char *name, char *desc, char *version)
  7060. +{
  7061. + if (desc)
  7062. + printf("%s - %s - %s\n", name, version, desc);
  7063. + else
  7064. + printf("%s - %s\n", name, version);
  7065. + return 0;
  7066. +}
  7067. +
  7068. +int default_ipkg_files_callback(char *desc)
  7069. +{
  7070. + if (desc)
  7071. + printf("%s\n", desc);
  7072. + return 0;
  7073. +}
  7074. +
  7075. +int default_ipkg_status_callback(char *desc)
  7076. +{
  7077. + printf("%s\n", desc);
  7078. + return 0;
  7079. +}
  7080. +
  7081. +char* default_ipkg_response_callback(char *question)
  7082. +{
  7083. + char *response = NULL;
  7084. + printf(question);
  7085. + fflush(stdout);
  7086. + do {
  7087. + response = (char *)file_read_line_alloc(stdin);
  7088. + } while (response == NULL);
  7089. + return response;
  7090. +}
  7091. +
  7092. +/* This is used for backward compatibility */
  7093. +int
  7094. +ipkg_op (int argc, char *argv[])
  7095. +{
  7096. + int err, optind_;
  7097. + args_t args;
  7098. + char *cmd_name;
  7099. + ipkg_cmd_t *cmd;
  7100. + ipkg_conf_t ipkg_conf;
  7101. + const char *message = "ipkg must have one sub-command argument";
  7102. +
  7103. + args_init (&args);
  7104. +
  7105. + optind_ = args_parse (&args, argc, argv);
  7106. + if (optind_ == argc || optind_ < 0)
  7107. + {
  7108. + args_usage(message);
  7109. + }
  7110. +
  7111. + cmd_name = argv[optind_++];
  7112. +/* Pigi: added a flag to disable the checking of structures if the command does not need to
  7113. + read anything from there.
  7114. +*/
  7115. + if ( !strcmp(cmd_name,"print-architecture") ||
  7116. + !strcmp(cmd_name,"print_architecture") ||
  7117. + !strcmp(cmd_name,"print-installation-architecture") ||
  7118. + !strcmp(cmd_name,"print_installation_architecture") )
  7119. + args.nocheckfordirorfile = 1;
  7120. +
  7121. +/* Pigi: added a flag to disable the reading of feed files if the command does not need to
  7122. + read anything from there.
  7123. +*/
  7124. + if ( !strcmp(cmd_name,"flag") ||
  7125. + !strcmp(cmd_name,"configure") ||
  7126. + !strcmp(cmd_name,"remove") ||
  7127. + !strcmp(cmd_name,"files") ||
  7128. + !strcmp(cmd_name,"search") ||
  7129. + !strcmp(cmd_name,"compare_versions") ||
  7130. + !strcmp(cmd_name,"compare-versions") ||
  7131. + !strcmp(cmd_name,"list_installed") ||
  7132. + !strcmp(cmd_name,"list-installed") ||
  7133. + !strcmp(cmd_name,"status") )
  7134. + args.noreadfeedsfile = 1;
  7135. +
  7136. +
  7137. + err = ipkg_conf_init (&ipkg_conf, &args);
  7138. + if (err)
  7139. + {
  7140. + return err;
  7141. + }
  7142. +
  7143. + args_deinit (&args);
  7144. +
  7145. + ipkg_cb_message = default_ipkg_message_callback;
  7146. + ipkg_cb_response = default_ipkg_response_callback;
  7147. + ipkg_cb_status = (ipkg_status_callback)default_ipkg_status_callback;
  7148. + if ( strcmp(cmd_name, "files")==0)
  7149. + ipkg_cb_list = (ipkg_list_callback)default_ipkg_files_callback;
  7150. + else
  7151. + ipkg_cb_list = (ipkg_list_callback)default_ipkg_list_callback;
  7152. +
  7153. + cmd = ipkg_cmd_find (cmd_name);
  7154. + if (cmd == NULL)
  7155. + {
  7156. + fprintf (stderr, "%s: unknown sub-command %s\n", argv[0],
  7157. + cmd_name);
  7158. + args_usage (NULL);
  7159. + }
  7160. +
  7161. + if (cmd->requires_args && optind_ == argc)
  7162. + {
  7163. + fprintf (stderr,
  7164. + "%s: the ``%s'' command requires at least one argument\n",
  7165. + __FUNCTION__, cmd_name);
  7166. + args_usage (NULL);
  7167. + }
  7168. +
  7169. + err = ipkg_cmd_exec (cmd, &ipkg_conf, argc - optind_, (const char **) (argv + optind_), NULL);
  7170. +
  7171. + ipkg_conf_deinit (&ipkg_conf);
  7172. +
  7173. + return err;
  7174. +}
  7175. diff -Nur busybox-1.16.1.orig/archival/libipkg/libipkg.h busybox-1.16.1/archival/libipkg/libipkg.h
  7176. --- busybox-1.16.1.orig/archival/libipkg/libipkg.h 1970-01-01 01:00:00.000000000 +0100
  7177. +++ busybox-1.16.1/archival/libipkg/libipkg.h 2010-04-22 19:18:12.000000000 +0200
  7178. @@ -0,0 +1,78 @@
  7179. +/* ipkglib.h - the itsy package management system
  7180. +
  7181. + Florian Boor <florian.boor@kernelconcepts.de>
  7182. +
  7183. + This program is free software; you can redistribute it and/or
  7184. + modify it under the terms of the GNU General Public License as
  7185. + published by the Free Software Foundation; either version 2, or (at
  7186. + your option) any later version.
  7187. +
  7188. + This program is distributed in the hope that it will be useful, but
  7189. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7190. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7191. + General Public License for more details.
  7192. +*/
  7193. +
  7194. +#ifndef IPKGLIB_H
  7195. +#define IPKGLIB_H
  7196. +
  7197. +#include "ipkg_conf.h"
  7198. +#include "ipkg_message.h"
  7199. +
  7200. +#include "args.h"
  7201. +#include "pkg.h"
  7202. +
  7203. +typedef int (*ipkg_message_callback)(ipkg_conf_t *conf, message_level_t level,
  7204. + char *msg);
  7205. +typedef int (*ipkg_list_callback)(char *name, char *desc, char *version,
  7206. + pkg_state_status_t status, void *userdata);
  7207. +typedef int (*ipkg_status_callback)(char *name, int istatus, char *desc,
  7208. + void *userdata);
  7209. +typedef char* (*ipkg_response_callback)(char *question);
  7210. +
  7211. +extern int ipkg_op(int argc, char *argv[]); /* ipkglib.c */
  7212. +extern int ipkg_init (ipkg_message_callback mcall,
  7213. + ipkg_response_callback rcall,
  7214. + args_t * args);
  7215. +
  7216. +extern int ipkg_deinit (args_t *args);
  7217. +extern int ipkg_packages_list(args_t *args,
  7218. + const char *packages,
  7219. + ipkg_list_callback cblist,
  7220. + void *userdata);
  7221. +extern int ipkg_packages_status(args_t *args,
  7222. + const char *packages,
  7223. + ipkg_status_callback cbstatus,
  7224. + void *userdata);
  7225. +extern int ipkg_packages_info(args_t *args,
  7226. + const char *packages,
  7227. + ipkg_status_callback cbstatus,
  7228. + void *userdata);
  7229. +extern int ipkg_packages_install(args_t *args, const char *name);
  7230. +extern int ipkg_packages_remove(args_t *args, const char *name, int purge);
  7231. +extern int ipkg_lists_update(args_t *args);
  7232. +extern int ipkg_packages_upgrade(args_t *args);
  7233. +extern int ipkg_packages_download(args_t *args, const char *name);
  7234. +extern int ipkg_package_files(args_t *args,
  7235. + const char *name,
  7236. + ipkg_list_callback cblist,
  7237. + void *userdata);
  7238. +extern int ipkg_file_search(args_t *args,
  7239. + const char *file,
  7240. + ipkg_list_callback cblist,
  7241. + void *userdata);
  7242. +extern int ipkg_package_whatdepends(args_t *args, const char *file);
  7243. +extern int ipkg_package_whatrecommends(args_t *args, const char *file);
  7244. +extern int ipkg_package_whatprovides(args_t *args, const char *file);
  7245. +extern int ipkg_package_whatconflicts(args_t *args, const char *file);
  7246. +extern int ipkg_package_whatreplaces(args_t *args, const char *file);
  7247. +
  7248. +extern ipkg_message_callback ipkg_cb_message; /* ipkglib.c */
  7249. +extern ipkg_response_callback ipkg_cb_response;
  7250. +extern ipkg_status_callback ipkg_cb_status;
  7251. +extern ipkg_list_callback ipkg_cb_list;
  7252. +extern void push_error_list(struct errlist **errors,char * msg);
  7253. +extern void reverse_error_list(struct errlist **errors);
  7254. +extern void free_error_list(struct errlist **errors);
  7255. +
  7256. +#endif
  7257. diff -Nur busybox-1.16.1.orig/archival/libipkg/nv_pair.c busybox-1.16.1/archival/libipkg/nv_pair.c
  7258. --- busybox-1.16.1.orig/archival/libipkg/nv_pair.c 1970-01-01 01:00:00.000000000 +0100
  7259. +++ busybox-1.16.1/archival/libipkg/nv_pair.c 2010-04-22 19:18:12.000000000 +0200
  7260. @@ -0,0 +1,40 @@
  7261. +/* nv_pair.c - the itsy package management system
  7262. +
  7263. + Carl D. Worth
  7264. +
  7265. + Copyright (C) 2001 University of Southern California
  7266. +
  7267. + This program is free software; you can redistribute it and/or
  7268. + modify it under the terms of the GNU General Public License as
  7269. + published by the Free Software Foundation; either version 2, or (at
  7270. + your option) any later version.
  7271. +
  7272. + This program is distributed in the hope that it will be useful, but
  7273. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7274. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7275. + General Public License for more details.
  7276. +*/
  7277. +
  7278. +#include "ipkg.h"
  7279. +
  7280. +#include "nv_pair.h"
  7281. +#include "str_util.h"
  7282. +
  7283. +int nv_pair_init(nv_pair_t *nv_pair, const char *name, const char *value)
  7284. +{
  7285. + nv_pair->name = str_dup_safe(name);
  7286. + nv_pair->value = str_dup_safe(value);
  7287. +
  7288. + return 0;
  7289. +}
  7290. +
  7291. +void nv_pair_deinit(nv_pair_t *nv_pair)
  7292. +{
  7293. + free(nv_pair->name);
  7294. + nv_pair->name = NULL;
  7295. +
  7296. + free(nv_pair->value);
  7297. + nv_pair->value = NULL;
  7298. +}
  7299. +
  7300. +
  7301. diff -Nur busybox-1.16.1.orig/archival/libipkg/nv_pair.h busybox-1.16.1/archival/libipkg/nv_pair.h
  7302. --- busybox-1.16.1.orig/archival/libipkg/nv_pair.h 1970-01-01 01:00:00.000000000 +0100
  7303. +++ busybox-1.16.1/archival/libipkg/nv_pair.h 2010-04-22 19:18:12.000000000 +0200
  7304. @@ -0,0 +1,32 @@
  7305. +/* nv_pair.h - the itsy package management system
  7306. +
  7307. + Carl D. Worth
  7308. +
  7309. + Copyright (C) 2001 University of Southern California
  7310. +
  7311. + This program is free software; you can redistribute it and/or
  7312. + modify it under the terms of the GNU General Public License as
  7313. + published by the Free Software Foundation; either version 2, or (at
  7314. + your option) any later version.
  7315. +
  7316. + This program is distributed in the hope that it will be useful, but
  7317. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7318. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7319. + General Public License for more details.
  7320. +*/
  7321. +
  7322. +#ifndef NV_PAIR_H
  7323. +#define NV_PAIR_H
  7324. +
  7325. +typedef struct nv_pair nv_pair_t;
  7326. +struct nv_pair
  7327. +{
  7328. + char *name;
  7329. + char *value;
  7330. +};
  7331. +
  7332. +int nv_pair_init(nv_pair_t *nv_pair, const char *name, const char *value);
  7333. +void nv_pair_deinit(nv_pair_t *nv_pair);
  7334. +
  7335. +#endif
  7336. +
  7337. diff -Nur busybox-1.16.1.orig/archival/libipkg/nv_pair_list.c busybox-1.16.1/archival/libipkg/nv_pair_list.c
  7338. --- busybox-1.16.1.orig/archival/libipkg/nv_pair_list.c 1970-01-01 01:00:00.000000000 +0100
  7339. +++ busybox-1.16.1/archival/libipkg/nv_pair_list.c 2010-04-22 19:18:12.000000000 +0200
  7340. @@ -0,0 +1,98 @@
  7341. +/* nv_pair_list.c - the itsy package management system
  7342. +
  7343. + Carl D. Worth
  7344. +
  7345. + Copyright (C) 2001 University of Southern California
  7346. +
  7347. + This program is free software; you can redistribute it and/or
  7348. + modify it under the terms of the GNU General Public License as
  7349. + published by the Free Software Foundation; either version 2, or (at
  7350. + your option) any later version.
  7351. +
  7352. + This program is distributed in the hope that it will be useful, but
  7353. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7354. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7355. + General Public License for more details.
  7356. +*/
  7357. +
  7358. +#include "ipkg.h"
  7359. +
  7360. +#include "nv_pair.h"
  7361. +#include "void_list.h"
  7362. +#include "nv_pair_list.h"
  7363. +
  7364. +int nv_pair_list_elt_init(nv_pair_list_elt_t *elt, nv_pair_t *data)
  7365. +{
  7366. + return void_list_elt_init((void_list_elt_t *) elt, data);
  7367. +}
  7368. +
  7369. +void nv_pair_list_elt_deinit(nv_pair_list_elt_t *elt)
  7370. +{
  7371. + void_list_elt_deinit((void_list_elt_t *) elt);
  7372. +}
  7373. +
  7374. +int nv_pair_list_init(nv_pair_list_t *list)
  7375. +{
  7376. + return void_list_init((void_list_t *) list);
  7377. +}
  7378. +
  7379. +void nv_pair_list_deinit(nv_pair_list_t *list)
  7380. +{
  7381. + nv_pair_list_elt_t *iter;
  7382. + nv_pair_t *nv_pair;
  7383. +
  7384. + for (iter = list->head; iter; iter = iter->next) {
  7385. + nv_pair = iter->data;
  7386. + nv_pair_deinit(nv_pair);
  7387. +
  7388. + /* malloced in nv_pair_list_append */
  7389. + free(nv_pair);
  7390. + iter->data = NULL;
  7391. + }
  7392. + void_list_deinit((void_list_t *) list);
  7393. +}
  7394. +
  7395. +nv_pair_t *nv_pair_list_append(nv_pair_list_t *list, const char *name, const char *value)
  7396. +{
  7397. + int err;
  7398. +
  7399. + /* freed in nv_pair_list_deinit */
  7400. + nv_pair_t *nv_pair = malloc(sizeof(nv_pair_t));
  7401. +
  7402. + if (nv_pair == NULL) {
  7403. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  7404. + return NULL;
  7405. + }
  7406. + nv_pair_init(nv_pair, name, value);
  7407. +
  7408. + err = void_list_append((void_list_t *) list, nv_pair);
  7409. + if (err) {
  7410. + return NULL;
  7411. + }
  7412. +
  7413. + return nv_pair;
  7414. +}
  7415. +
  7416. +int nv_pair_list_push(nv_pair_list_t *list, nv_pair_t *data)
  7417. +{
  7418. + return void_list_push((void_list_t *) list, data);
  7419. +}
  7420. +
  7421. +nv_pair_list_elt_t *nv_pair_list_pop(nv_pair_list_t *list)
  7422. +{
  7423. + return (nv_pair_list_elt_t *) void_list_pop((void_list_t *) list);
  7424. +}
  7425. +
  7426. +char *nv_pair_list_find(nv_pair_list_t *list, char *name)
  7427. +{
  7428. + nv_pair_list_elt_t *iter;
  7429. + nv_pair_t *nv_pair;
  7430. +
  7431. + for (iter = list->head; iter; iter = iter->next) {
  7432. + nv_pair = iter->data;
  7433. + if (strcmp(nv_pair->name, name) == 0) {
  7434. + return nv_pair->value;
  7435. + }
  7436. + }
  7437. + return NULL;
  7438. +}
  7439. diff -Nur busybox-1.16.1.orig/archival/libipkg/nv_pair_list.h busybox-1.16.1/archival/libipkg/nv_pair_list.h
  7440. --- busybox-1.16.1.orig/archival/libipkg/nv_pair_list.h 1970-01-01 01:00:00.000000000 +0100
  7441. +++ busybox-1.16.1/archival/libipkg/nv_pair_list.h 2010-04-22 19:18:12.000000000 +0200
  7442. @@ -0,0 +1,60 @@
  7443. +/* nv_pair_list.h - the itsy package management system
  7444. +
  7445. + Carl D. Worth
  7446. +
  7447. + Copyright (C) 2001 University of Southern California
  7448. +
  7449. + This program is free software; you can redistribute it and/or
  7450. + modify it under the terms of the GNU General Public License as
  7451. + published by the Free Software Foundation; either version 2, or (at
  7452. + your option) any later version.
  7453. +
  7454. + This program is distributed in the hope that it will be useful, but
  7455. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7456. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7457. + General Public License for more details.
  7458. +*/
  7459. +
  7460. +#ifndef NV_PAIR_LIST_H
  7461. +#define NV_PAIR_LIST_H
  7462. +
  7463. +#include "nv_pair.h"
  7464. +#include "void_list.h"
  7465. +
  7466. +typedef struct nv_pair_list_elt nv_pair_list_elt_t;
  7467. +struct nv_pair_list_elt
  7468. +{
  7469. + nv_pair_list_elt_t *next;
  7470. + nv_pair_t *data;
  7471. +};
  7472. +
  7473. +typedef struct nv_pair_list nv_pair_list_t;
  7474. +struct nv_pair_list
  7475. +{
  7476. + nv_pair_list_elt_t pre_head;
  7477. + nv_pair_list_elt_t *head;
  7478. + nv_pair_list_elt_t *tail;
  7479. +};
  7480. +
  7481. +static inline int nv_pair_list_empty(nv_pair_list_t *list)
  7482. +{
  7483. + if (list->head == NULL)
  7484. + return 1;
  7485. + else
  7486. + return 0;
  7487. +}
  7488. +
  7489. +int nv_pair_list_elt_init(nv_pair_list_elt_t *elt, nv_pair_t *data);
  7490. +void nv_pair_list_elt_deinit(nv_pair_list_elt_t *elt);
  7491. +
  7492. +int nv_pair_list_init(nv_pair_list_t *list);
  7493. +void nv_pair_list_deinit(nv_pair_list_t *list);
  7494. +
  7495. +nv_pair_t *nv_pair_list_append(nv_pair_list_t *list,
  7496. + const char *name, const char *value);
  7497. +int nv_pair_list_push(nv_pair_list_t *list, nv_pair_t *data);
  7498. +nv_pair_list_elt_t *nv_pair_list_pop(nv_pair_list_t *list);
  7499. +char *nv_pair_list_find(nv_pair_list_t *list, char *name);
  7500. +
  7501. +#endif
  7502. +
  7503. diff -Nur busybox-1.16.1.orig/archival/libipkg/pkg.c busybox-1.16.1/archival/libipkg/pkg.c
  7504. --- busybox-1.16.1.orig/archival/libipkg/pkg.c 1970-01-01 01:00:00.000000000 +0100
  7505. +++ busybox-1.16.1/archival/libipkg/pkg.c 2010-04-22 19:18:12.000000000 +0200
  7506. @@ -0,0 +1,1757 @@
  7507. +/* pkg.c - the itsy package management system
  7508. +
  7509. + Carl D. Worth
  7510. +
  7511. + Copyright (C) 2001 University of Southern California
  7512. +
  7513. + This program is free software; you can redistribute it and/or
  7514. + modify it under the terms of the GNU General Public License as
  7515. + published by the Free Software Foundation; either version 2, or (at
  7516. + your option) any later version.
  7517. +
  7518. + This program is distributed in the hope that it will be useful, but
  7519. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7520. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7521. + General Public License for more details.
  7522. +*/
  7523. +
  7524. +#include "ipkg.h"
  7525. +#include <ctype.h>
  7526. +#include <string.h>
  7527. +#include <errno.h>
  7528. +
  7529. +#include "pkg.h"
  7530. +
  7531. +#include "pkg_parse.h"
  7532. +#include "pkg_extract.h"
  7533. +#include "ipkg_message.h"
  7534. +#include "ipkg_utils.h"
  7535. +
  7536. +#include "sprintf_alloc.h"
  7537. +#include "file_util.h"
  7538. +#include "str_util.h"
  7539. +#include "xsystem.h"
  7540. +#include "ipkg_conf.h"
  7541. +
  7542. +int pkg_get_arch_priority(ipkg_conf_t *conf, const char *archname);
  7543. +void pkg_write_filelist_helper(const char *key, void *entry_, void *data_);
  7544. +
  7545. +typedef struct enum_map enum_map_t;
  7546. +struct enum_map
  7547. +{
  7548. + int value;
  7549. + const char *str;
  7550. +};
  7551. +
  7552. +static const enum_map_t pkg_state_want_map[] = {
  7553. + { SW_UNKNOWN, "unknown"},
  7554. + { SW_INSTALL, "install"},
  7555. + { SW_DEINSTALL, "deinstall"},
  7556. + { SW_PURGE, "purge"}
  7557. +};
  7558. +
  7559. +static const enum_map_t pkg_state_flag_map[] = {
  7560. + { SF_OK, "ok"},
  7561. + { SF_REINSTREQ, "reinstreq"},
  7562. + { SF_HOLD, "hold"},
  7563. + { SF_REPLACE, "replace"},
  7564. + { SF_NOPRUNE, "noprune"},
  7565. + { SF_PREFER, "prefer"},
  7566. + { SF_OBSOLETE, "obsolete"},
  7567. + { SF_USER, "user"},
  7568. +};
  7569. +
  7570. +static const enum_map_t pkg_state_status_map[] = {
  7571. + { SS_NOT_INSTALLED, "not-installed" },
  7572. + { SS_UNPACKED, "unpacked" },
  7573. + { SS_HALF_CONFIGURED, "half-configured" },
  7574. + { SS_INSTALLED, "installed" },
  7575. + { SS_HALF_INSTALLED, "half-installed" },
  7576. + { SS_CONFIG_FILES, "config-files" },
  7577. + { SS_POST_INST_FAILED, "post-inst-failed" },
  7578. + { SS_REMOVAL_FAILED, "removal-failed" }
  7579. +};
  7580. +
  7581. +static int verrevcmp(const char *val, const char *ref);
  7582. +
  7583. +
  7584. +pkg_t *pkg_new(void)
  7585. +{
  7586. + pkg_t *pkg;
  7587. +
  7588. + pkg = malloc(sizeof(pkg_t));
  7589. + if (pkg == NULL) {
  7590. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  7591. + return NULL;
  7592. + }
  7593. +
  7594. + pkg_init(pkg);
  7595. +
  7596. + return pkg;
  7597. +}
  7598. +
  7599. +int pkg_init(pkg_t *pkg)
  7600. +{
  7601. + memset(pkg, 0, sizeof(pkg_t));
  7602. + pkg->name = NULL;
  7603. + pkg->epoch = 0;
  7604. + pkg->version = NULL;
  7605. + pkg->revision = NULL;
  7606. + pkg->familiar_revision = NULL;
  7607. + pkg->dest = NULL;
  7608. + pkg->src = NULL;
  7609. + pkg->architecture = NULL;
  7610. + pkg->maintainer = NULL;
  7611. + pkg->section = NULL;
  7612. + pkg->description = NULL;
  7613. + pkg->state_want = SW_UNKNOWN;
  7614. + pkg->state_flag = SF_OK;
  7615. + pkg->state_status = SS_NOT_INSTALLED;
  7616. + pkg->depends_str = NULL;
  7617. + pkg->provides_str = NULL;
  7618. + pkg->depends_count = 0;
  7619. + pkg->depends = NULL;
  7620. + pkg->suggests_str = NULL;
  7621. + pkg->recommends_str = NULL;
  7622. + pkg->suggests_count = 0;
  7623. + pkg->recommends_count = 0;
  7624. +
  7625. + /* Abhaya: added init for conflicts fields */
  7626. + pkg->conflicts = NULL;
  7627. + pkg->conflicts_count = 0;
  7628. +
  7629. + /* added for replaces. Jamey 7/23/2002 */
  7630. + pkg->replaces = NULL;
  7631. + pkg->replaces_count = 0;
  7632. +
  7633. + pkg->pre_depends_count = 0;
  7634. + pkg->pre_depends_str = NULL;
  7635. + pkg->provides_count = 0;
  7636. + pkg->provides = NULL;
  7637. + pkg->filename = NULL;
  7638. + pkg->local_filename = NULL;
  7639. + pkg->tmp_unpack_dir = NULL;
  7640. + pkg->md5sum = NULL;
  7641. + pkg->size = NULL;
  7642. + pkg->installed_size = NULL;
  7643. + pkg->priority = NULL;
  7644. + pkg->source = NULL;
  7645. + conffile_list_init(&pkg->conffiles);
  7646. + pkg->installed_files = NULL;
  7647. + pkg->installed_files_ref_cnt = 0;
  7648. + pkg->essential = 0;
  7649. + pkg->provided_by_hand = 0;
  7650. +
  7651. + return 0;
  7652. +}
  7653. +
  7654. +void pkg_deinit(pkg_t *pkg)
  7655. +{
  7656. + free(pkg->name);
  7657. + pkg->name = NULL;
  7658. + pkg->epoch = 0;
  7659. + free(pkg->version);
  7660. + pkg->version = NULL;
  7661. + /* revision and familiar_revision share storage with version, so
  7662. + don't free */
  7663. + pkg->revision = NULL;
  7664. + pkg->familiar_revision = NULL;
  7665. + /* owned by ipkg_conf_t */
  7666. + pkg->dest = NULL;
  7667. + /* owned by ipkg_conf_t */
  7668. + pkg->src = NULL;
  7669. + free(pkg->architecture);
  7670. + pkg->architecture = NULL;
  7671. + free(pkg->maintainer);
  7672. + pkg->maintainer = NULL;
  7673. + free(pkg->section);
  7674. + pkg->section = NULL;
  7675. + free(pkg->description);
  7676. + pkg->description = NULL;
  7677. + pkg->state_want = SW_UNKNOWN;
  7678. + pkg->state_flag = SF_OK;
  7679. + pkg->state_status = SS_NOT_INSTALLED;
  7680. + free(pkg->depends_str);
  7681. + pkg->depends_str = NULL;
  7682. + free(pkg->provides_str);
  7683. + pkg->provides_str = NULL;
  7684. + pkg->depends_count = 0;
  7685. + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->depends ? */
  7686. + pkg->pre_depends_count = 0;
  7687. + free(pkg->pre_depends_str);
  7688. + pkg->pre_depends_str = NULL;
  7689. + pkg->provides_count = 0;
  7690. + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->provides ? */
  7691. + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->suggests ? */
  7692. + free(pkg->filename);
  7693. + pkg->filename = NULL;
  7694. + free(pkg->local_filename);
  7695. + pkg->local_filename = NULL;
  7696. + /* CLEANUP: It'd be nice to pullin the cleanup function from
  7697. + ipkg_install.c here. See comment in
  7698. + ipkg_install.c:cleanup_temporary_files */
  7699. + free(pkg->tmp_unpack_dir);
  7700. + pkg->tmp_unpack_dir = NULL;
  7701. + free(pkg->md5sum);
  7702. + pkg->md5sum = NULL;
  7703. + free(pkg->size);
  7704. + pkg->size = NULL;
  7705. + free(pkg->installed_size);
  7706. + pkg->installed_size = NULL;
  7707. + free(pkg->priority);
  7708. + pkg->priority = NULL;
  7709. + free(pkg->source);
  7710. + pkg->source = NULL;
  7711. + conffile_list_deinit(&pkg->conffiles);
  7712. + /* XXX: QUESTION: Is forcing this to 1 correct? I suppose so,
  7713. + since if they are calling deinit, they should know. Maybe do an
  7714. + assertion here instead? */
  7715. + pkg->installed_files_ref_cnt = 1;
  7716. + pkg_free_installed_files(pkg);
  7717. + pkg->essential = 0;
  7718. +}
  7719. +
  7720. +int pkg_init_from_file(pkg_t *pkg, const char *filename)
  7721. +{
  7722. + int err;
  7723. + char **raw;
  7724. + FILE *control_file;
  7725. +
  7726. + err = pkg_init(pkg);
  7727. + if (err) { return err; }
  7728. +
  7729. + pkg->local_filename = strdup(filename);
  7730. +
  7731. + control_file = tmpfile();
  7732. + err = pkg_extract_control_file_to_stream(pkg, control_file);
  7733. + if (err) { return err; }
  7734. +
  7735. + rewind(control_file);
  7736. + raw = read_raw_pkgs_from_stream(control_file);
  7737. + pkg_parse_raw(pkg, &raw, NULL, NULL);
  7738. +
  7739. + fclose(control_file);
  7740. +
  7741. + return 0;
  7742. +}
  7743. +
  7744. +/* Merge any new information in newpkg into oldpkg */
  7745. +/* XXX: CLEANUP: This function shouldn't actually modify anything in
  7746. + newpkg, but should leave it usable. This rework is so that
  7747. + pkg_hash_insert doesn't clobber the pkg that you pass into it. */
  7748. +/*
  7749. + * uh, i thought that i had originally written this so that it took
  7750. + * two pkgs and returned a new one? we can do that again... -sma
  7751. + */
  7752. +int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status)
  7753. +{
  7754. + if (oldpkg == newpkg) {
  7755. + return 0;
  7756. + }
  7757. +
  7758. + if (!oldpkg->src)
  7759. + oldpkg->src = newpkg->src;
  7760. + if (!oldpkg->dest)
  7761. + oldpkg->dest = newpkg->dest;
  7762. + if (!oldpkg->architecture)
  7763. + oldpkg->architecture = str_dup_safe(newpkg->architecture);
  7764. + if (!oldpkg->arch_priority)
  7765. + oldpkg->arch_priority = newpkg->arch_priority;
  7766. + if (!oldpkg->section)
  7767. + oldpkg->section = str_dup_safe(newpkg->section);
  7768. + if(!oldpkg->maintainer)
  7769. + oldpkg->maintainer = str_dup_safe(newpkg->maintainer);
  7770. + if(!oldpkg->description)
  7771. + oldpkg->description = str_dup_safe(newpkg->description);
  7772. + if (set_status) {
  7773. + /* merge the state_flags from the new package */
  7774. + oldpkg->state_want = newpkg->state_want;
  7775. + oldpkg->state_status = newpkg->state_status;
  7776. + oldpkg->state_flag = newpkg->state_flag;
  7777. + } else {
  7778. + if (oldpkg->state_want == SW_UNKNOWN)
  7779. + oldpkg->state_want = newpkg->state_want;
  7780. + if (oldpkg->state_status == SS_NOT_INSTALLED)
  7781. + oldpkg->state_status = newpkg->state_status;
  7782. + oldpkg->state_flag |= newpkg->state_flag;
  7783. + }
  7784. +
  7785. + if (!oldpkg->depends_str && !oldpkg->pre_depends_str && !oldpkg->recommends_str && !oldpkg->suggests_str) {
  7786. + oldpkg->depends_str = newpkg->depends_str;
  7787. + newpkg->depends_str = NULL;
  7788. + oldpkg->depends_count = newpkg->depends_count;
  7789. + newpkg->depends_count = 0;
  7790. +
  7791. + oldpkg->depends = newpkg->depends;
  7792. + newpkg->depends = NULL;
  7793. +
  7794. + oldpkg->pre_depends_str = newpkg->pre_depends_str;
  7795. + newpkg->pre_depends_str = NULL;
  7796. + oldpkg->pre_depends_count = newpkg->pre_depends_count;
  7797. + newpkg->pre_depends_count = 0;
  7798. +
  7799. + oldpkg->recommends_str = newpkg->recommends_str;
  7800. + newpkg->recommends_str = NULL;
  7801. + oldpkg->recommends_count = newpkg->recommends_count;
  7802. + newpkg->recommends_count = 0;
  7803. +
  7804. + oldpkg->suggests_str = newpkg->suggests_str;
  7805. + newpkg->suggests_str = NULL;
  7806. + oldpkg->suggests_count = newpkg->suggests_count;
  7807. + newpkg->suggests_count = 0;
  7808. + }
  7809. +
  7810. + if (!oldpkg->provides_str) {
  7811. + oldpkg->provides_str = newpkg->provides_str;
  7812. + newpkg->provides_str = NULL;
  7813. + oldpkg->provides_count = newpkg->provides_count;
  7814. + newpkg->provides_count = 0;
  7815. +
  7816. + oldpkg->provides = newpkg->provides;
  7817. + newpkg->provides = NULL;
  7818. + }
  7819. +
  7820. + if (!oldpkg->conflicts_str) {
  7821. + oldpkg->conflicts_str = newpkg->conflicts_str;
  7822. + newpkg->conflicts_str = NULL;
  7823. + oldpkg->conflicts_count = newpkg->conflicts_count;
  7824. + newpkg->conflicts_count = 0;
  7825. +
  7826. + oldpkg->conflicts = newpkg->conflicts;
  7827. + newpkg->conflicts = NULL;
  7828. + }
  7829. +
  7830. + if (!oldpkg->replaces_str) {
  7831. + oldpkg->replaces_str = newpkg->replaces_str;
  7832. + newpkg->replaces_str = NULL;
  7833. + oldpkg->replaces_count = newpkg->replaces_count;
  7834. + newpkg->replaces_count = 0;
  7835. +
  7836. + oldpkg->replaces = newpkg->replaces;
  7837. + newpkg->replaces = NULL;
  7838. + }
  7839. +
  7840. + if (!oldpkg->filename)
  7841. + oldpkg->filename = str_dup_safe(newpkg->filename);
  7842. + if (0)
  7843. + fprintf(stdout, "pkg=%s old local_filename=%s new local_filename=%s\n",
  7844. + oldpkg->name, oldpkg->local_filename, newpkg->local_filename);
  7845. + if (!oldpkg->local_filename)
  7846. + oldpkg->local_filename = str_dup_safe(newpkg->local_filename);
  7847. + if (!oldpkg->tmp_unpack_dir)
  7848. + oldpkg->tmp_unpack_dir = str_dup_safe(newpkg->tmp_unpack_dir);
  7849. + if (!oldpkg->md5sum)
  7850. + oldpkg->md5sum = str_dup_safe(newpkg->md5sum);
  7851. + if (!oldpkg->size)
  7852. + oldpkg->size = str_dup_safe(newpkg->size);
  7853. + if (!oldpkg->installed_size)
  7854. + oldpkg->installed_size = str_dup_safe(newpkg->installed_size);
  7855. + if (!oldpkg->priority)
  7856. + oldpkg->priority = str_dup_safe(newpkg->priority);
  7857. + if (!oldpkg->source)
  7858. + oldpkg->source = str_dup_safe(newpkg->source);
  7859. + if (oldpkg->conffiles.head == NULL){
  7860. + oldpkg->conffiles = newpkg->conffiles;
  7861. + conffile_list_init(&newpkg->conffiles);
  7862. + }
  7863. + if (!oldpkg->installed_files){
  7864. + oldpkg->installed_files = newpkg->installed_files;
  7865. + oldpkg->installed_files_ref_cnt = newpkg->installed_files_ref_cnt;
  7866. + newpkg->installed_files = NULL;
  7867. + }
  7868. + if (!oldpkg->essential)
  7869. + oldpkg->essential = newpkg->essential;
  7870. +
  7871. + return 0;
  7872. +}
  7873. +
  7874. +abstract_pkg_t *abstract_pkg_new(void)
  7875. +{
  7876. + abstract_pkg_t * ab_pkg;
  7877. +
  7878. + ab_pkg = malloc(sizeof(abstract_pkg_t));
  7879. +
  7880. + if (ab_pkg == NULL) {
  7881. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  7882. + return NULL;
  7883. + }
  7884. +
  7885. + if ( abstract_pkg_init(ab_pkg) < 0 )
  7886. + return NULL;
  7887. +
  7888. + return ab_pkg;
  7889. +}
  7890. +
  7891. +int abstract_pkg_init(abstract_pkg_t *ab_pkg)
  7892. +{
  7893. + memset(ab_pkg, 0, sizeof(abstract_pkg_t));
  7894. +
  7895. + ab_pkg->provided_by = abstract_pkg_vec_alloc();
  7896. + if (ab_pkg->provided_by==NULL){
  7897. + return -1;
  7898. + }
  7899. + ab_pkg->dependencies_checked = 0;
  7900. + ab_pkg->state_status = SS_NOT_INSTALLED;
  7901. +
  7902. + return 0;
  7903. +}
  7904. +
  7905. +void set_flags_from_control(ipkg_conf_t *conf, pkg_t *pkg){
  7906. + char * temp_str;
  7907. + char **raw =NULL;
  7908. + char **raw_start=NULL;
  7909. +
  7910. + temp_str = (char *) malloc (strlen(pkg->dest->info_dir)+strlen(pkg->name)+12);
  7911. + if (temp_str == NULL ){
  7912. + ipkg_message(conf, IPKG_INFO, "Out of memory in %s\n", __FUNCTION__);
  7913. + return;
  7914. + }
  7915. + sprintf( temp_str,"%s/%s.control",pkg->dest->info_dir,pkg->name);
  7916. +
  7917. + raw = raw_start = read_raw_pkgs_from_file(temp_str);
  7918. + if (raw == NULL ){
  7919. + ipkg_message(conf, IPKG_ERROR, "Unable to open the control file in %s\n", __FUNCTION__);
  7920. + return;
  7921. + }
  7922. +
  7923. + while(*raw){
  7924. + if (!pkg_valorize_other_field(pkg, &raw ) == 0) {
  7925. + ipkg_message(conf, IPKG_DEBUG, "unable to read control file for %s. May be empty\n", pkg->name);
  7926. + }
  7927. + }
  7928. + raw = raw_start;
  7929. + while (*raw) {
  7930. + if (raw!=NULL)
  7931. + free(*raw++);
  7932. + }
  7933. +
  7934. + free(raw_start);
  7935. + free(temp_str);
  7936. +
  7937. + return ;
  7938. +
  7939. +}
  7940. +
  7941. +char * pkg_formatted_info(pkg_t *pkg )
  7942. +{
  7943. + char *line;
  7944. + char * buff;
  7945. +
  7946. + buff = malloc(8192);
  7947. + if (buff == NULL) {
  7948. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  7949. + return NULL;
  7950. + }
  7951. +
  7952. + buff[0] = '\0';
  7953. +
  7954. + line = pkg_formatted_field(pkg, "Package");
  7955. + strncat(buff ,line, strlen(line));
  7956. + free(line);
  7957. +
  7958. + line = pkg_formatted_field(pkg, "Version");
  7959. + strncat(buff ,line, strlen(line));
  7960. + free(line);
  7961. +
  7962. + line = pkg_formatted_field(pkg, "Depends");
  7963. + strncat(buff ,line, strlen(line));
  7964. + free(line);
  7965. +
  7966. + line = pkg_formatted_field(pkg, "Recommends");
  7967. + strncat(buff ,line, strlen(line));
  7968. + free(line);
  7969. +
  7970. + line = pkg_formatted_field(pkg, "Suggests");
  7971. + strncat(buff ,line, strlen(line));
  7972. + free(line);
  7973. +
  7974. + line = pkg_formatted_field(pkg, "Provides");
  7975. + strncat(buff ,line, strlen(line));
  7976. + free(line);
  7977. +
  7978. + line = pkg_formatted_field(pkg, "Replaces");
  7979. + strncat(buff ,line, strlen(line));
  7980. + free(line);
  7981. +
  7982. + line = pkg_formatted_field(pkg, "Conflicts");
  7983. + strncat(buff ,line, strlen(line));
  7984. + free(line);
  7985. +
  7986. + line = pkg_formatted_field(pkg, "Status");
  7987. + strncat(buff ,line, strlen(line));
  7988. + free(line);
  7989. +
  7990. + line = pkg_formatted_field(pkg, "Section");
  7991. + strncat(buff ,line, strlen(line));
  7992. + free(line);
  7993. +
  7994. + line = pkg_formatted_field(pkg, "Essential"); /* @@@@ should be removed in future release. *//* I do not agree with this Pigi*/
  7995. + strncat(buff ,line, strlen(line));
  7996. + free(line);
  7997. +
  7998. + line = pkg_formatted_field(pkg, "Architecture");
  7999. + strncat(buff ,line, strlen(line));
  8000. + free(line);
  8001. +
  8002. + line = pkg_formatted_field(pkg, "Maintainer");
  8003. + strncat(buff ,line, strlen(line));
  8004. + free(line);
  8005. +
  8006. + line = pkg_formatted_field(pkg, "MD5sum");
  8007. + strncat(buff ,line, strlen(line));
  8008. + free(line);
  8009. +
  8010. + line = pkg_formatted_field(pkg, "Size");
  8011. + strncat(buff ,line, strlen(line));
  8012. + free(line);
  8013. +
  8014. + line = pkg_formatted_field(pkg, "Filename");
  8015. + strncat(buff ,line, strlen(line));
  8016. + free(line);
  8017. +
  8018. + line = pkg_formatted_field(pkg, "Conffiles");
  8019. + strncat(buff ,line, strlen(line));
  8020. + free(line);
  8021. +
  8022. + line = pkg_formatted_field(pkg, "Source");
  8023. + strncat(buff ,line, strlen(line));
  8024. + free(line);
  8025. +
  8026. + line = pkg_formatted_field(pkg, "Description");
  8027. + strncat(buff ,line, strlen(line));
  8028. + free(line);
  8029. +
  8030. + line = pkg_formatted_field(pkg, "Installed-Time");
  8031. + strncat(buff ,line, strlen(line));
  8032. + free(line);
  8033. +
  8034. + return buff;
  8035. +}
  8036. +
  8037. +char * pkg_formatted_field(pkg_t *pkg, const char *field )
  8038. +{
  8039. + static size_t LINE_LEN = 128;
  8040. + char * temp = (char *)malloc(1);
  8041. + int len = 0;
  8042. + int flag_provide_false = 0;
  8043. +
  8044. +/*
  8045. + Pigi: After some discussion with Florian we decided to modify the full procedure in
  8046. + dynamic memory allocation. This should avoid any other segv in this area ( except for bugs )
  8047. +*/
  8048. +
  8049. + if (strlen(field) < PKG_MINIMUM_FIELD_NAME_LEN) {
  8050. + goto UNKNOWN_FMT_FIELD;
  8051. + }
  8052. +
  8053. + temp[0]='\0';
  8054. +
  8055. + switch (field[0])
  8056. + {
  8057. + case 'a':
  8058. + case 'A':
  8059. + if (strcasecmp(field, "Architecture") == 0) {
  8060. + /* Architecture */
  8061. + if (pkg->architecture) {
  8062. + temp = (char *)realloc(temp,strlen(pkg->architecture)+17);
  8063. + if ( temp == NULL ){
  8064. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8065. + return NULL;
  8066. + }
  8067. + temp[0]='\0';
  8068. + snprintf(temp, (strlen(pkg->architecture)+17), "Architecture: %s\n", pkg->architecture);
  8069. + }
  8070. + } else {
  8071. + goto UNKNOWN_FMT_FIELD;
  8072. + }
  8073. + break;
  8074. + case 'c':
  8075. + case 'C':
  8076. + if (strcasecmp(field, "Conffiles") == 0) {
  8077. + /* Conffiles */
  8078. + conffile_list_elt_t *iter;
  8079. + char confstr_[LINE_LEN];
  8080. +
  8081. + if (pkg->conffiles.head == NULL) {
  8082. + return temp;
  8083. + }
  8084. +
  8085. + len = 14 ;
  8086. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  8087. + if (iter->data->name && iter->data->value) {
  8088. + len = len + (strlen(iter->data->name)+strlen(iter->data->value)+5);
  8089. + }
  8090. + }
  8091. + temp = (char *)realloc(temp,len);
  8092. + if ( temp == NULL ){
  8093. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8094. + return NULL;
  8095. + }
  8096. + temp[0]='\0';
  8097. + strncpy(temp, "Conffiles:\n", 12);
  8098. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  8099. + if (iter->data->name && iter->data->value) {
  8100. + snprintf(confstr_, LINE_LEN, "%s %s\n", iter->data->name, iter->data->value);
  8101. + strncat(temp, confstr_, strlen(confstr_));
  8102. + }
  8103. + }
  8104. + } else if (strcasecmp(field, "Conflicts") == 0) {
  8105. + int i;
  8106. +
  8107. + if (pkg->conflicts_count) {
  8108. + char conflictstr[LINE_LEN];
  8109. + len = 14 ;
  8110. + for(i = 0; i < pkg->conflicts_count; i++) {
  8111. + len = len + (strlen(pkg->conflicts_str[i])+5);
  8112. + }
  8113. + temp = (char *)realloc(temp,len);
  8114. + if ( temp == NULL ){
  8115. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8116. + return NULL;
  8117. + }
  8118. + temp[0]='\0';
  8119. + strncpy(temp, "Conflicts:", 11);
  8120. + for(i = 0; i < pkg->conflicts_count; i++) {
  8121. + snprintf(conflictstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->conflicts_str[i]);
  8122. + strncat(temp, conflictstr, strlen(conflictstr));
  8123. + }
  8124. + strncat(temp, "\n", strlen("\n"));
  8125. + }
  8126. + } else {
  8127. + goto UNKNOWN_FMT_FIELD;
  8128. + }
  8129. + break;
  8130. + case 'd':
  8131. + case 'D':
  8132. + if (strcasecmp(field, "Depends") == 0) {
  8133. + /* Depends */
  8134. + int i;
  8135. +
  8136. + if (pkg->depends_count) {
  8137. + char depstr[LINE_LEN];
  8138. + len = 14 ;
  8139. + for(i = 0; i < pkg->depends_count; i++) {
  8140. + len = len + (strlen(pkg->depends_str[i])+4);
  8141. + }
  8142. + temp = (char *)realloc(temp,len);
  8143. + if ( temp == NULL ){
  8144. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8145. + return NULL;
  8146. + }
  8147. + temp[0]='\0';
  8148. + strncpy(temp, "Depends:", 10);
  8149. + for(i = 0; i < pkg->depends_count; i++) {
  8150. + snprintf(depstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->depends_str[i]);
  8151. + strncat(temp, depstr, strlen(depstr));
  8152. + }
  8153. + strncat(temp, "\n", strlen("\n"));
  8154. + }
  8155. + } else if (strcasecmp(field, "Description") == 0) {
  8156. + /* Description */
  8157. + if (pkg->description) {
  8158. + temp = (char *)realloc(temp,strlen(pkg->description)+16);
  8159. + if ( temp == NULL ){
  8160. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8161. + return NULL;
  8162. + }
  8163. + temp[0]='\0';
  8164. + snprintf(temp, (strlen(pkg->description)+16), "Description: %s\n", pkg->description);
  8165. + }
  8166. + } else {
  8167. + goto UNKNOWN_FMT_FIELD;
  8168. + }
  8169. + break;
  8170. + case 'e':
  8171. + case 'E': {
  8172. + /* Essential */
  8173. + if (pkg->essential) {
  8174. + temp = (char *)realloc(temp,16);
  8175. + if ( temp == NULL ){
  8176. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8177. + return NULL;
  8178. + }
  8179. + temp[0]='\0';
  8180. + snprintf(temp, (16), "Essential: yes\n");
  8181. + }
  8182. + }
  8183. + break;
  8184. + case 'f':
  8185. + case 'F': {
  8186. + /* Filename */
  8187. + if (pkg->filename) {
  8188. + temp = (char *)realloc(temp,strlen(pkg->filename)+12);
  8189. + if ( temp == NULL ){
  8190. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8191. + return NULL;
  8192. + }
  8193. + temp[0]='\0';
  8194. + snprintf(temp, (strlen(pkg->filename)+12), "Filename: %s\n", pkg->filename);
  8195. + }
  8196. + }
  8197. + break;
  8198. + case 'i':
  8199. + case 'I': {
  8200. + if (strcasecmp(field, "Installed-Size") == 0) {
  8201. + /* Installed-Size */
  8202. + temp = (char *)realloc(temp,strlen(pkg->installed_size)+17);
  8203. + if ( temp == NULL ){
  8204. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8205. + return NULL;
  8206. + }
  8207. + temp[0]='\0';
  8208. + snprintf(temp, (strlen(pkg->installed_size)+17), "Installed-Size: %s\n", pkg->installed_size);
  8209. + } else if (strcasecmp(field, "Installed-Time") == 0 && pkg->installed_time) {
  8210. + temp = (char *)realloc(temp,29);
  8211. + if ( temp == NULL ){
  8212. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8213. + return NULL;
  8214. + }
  8215. + temp[0]='\0';
  8216. + snprintf(temp, 29, "Installed-Time: %lu\n", pkg->installed_time);
  8217. + }
  8218. + }
  8219. + break;
  8220. + case 'm':
  8221. + case 'M': {
  8222. + /* Maintainer | MD5sum */
  8223. + if (strcasecmp(field, "Maintainer") == 0) {
  8224. + /* Maintainer */
  8225. + if (pkg->maintainer) {
  8226. + temp = (char *)realloc(temp,strlen(pkg->maintainer)+14);
  8227. + if ( temp == NULL ){
  8228. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8229. + return NULL;
  8230. + }
  8231. + temp[0]='\0';
  8232. + snprintf(temp, (strlen(pkg->maintainer)+14), "maintainer: %s\n", pkg->maintainer);
  8233. + }
  8234. + } else if (strcasecmp(field, "MD5sum") == 0) {
  8235. + /* MD5sum */
  8236. + if (pkg->md5sum) {
  8237. + temp = (char *)realloc(temp,strlen(pkg->md5sum)+11);
  8238. + if ( temp == NULL ){
  8239. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8240. + return NULL;
  8241. + }
  8242. + temp[0]='\0';
  8243. + snprintf(temp, (strlen(pkg->md5sum)+11), "MD5Sum: %s\n", pkg->md5sum);
  8244. + }
  8245. + } else {
  8246. + goto UNKNOWN_FMT_FIELD;
  8247. + }
  8248. + }
  8249. + break;
  8250. + case 'p':
  8251. + case 'P': {
  8252. + if (strcasecmp(field, "Package") == 0) {
  8253. + /* Package */
  8254. + temp = (char *)realloc(temp,strlen(pkg->name)+11);
  8255. + if ( temp == NULL ){
  8256. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8257. + return NULL;
  8258. + }
  8259. + temp[0]='\0';
  8260. + snprintf(temp, (strlen(pkg->name)+11), "Package: %s\n", pkg->name);
  8261. + } else if (strcasecmp(field, "Priority") == 0) {
  8262. + /* Priority */
  8263. + temp = (char *)realloc(temp,strlen(pkg->priority)+12);
  8264. + if ( temp == NULL ){
  8265. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8266. + return NULL;
  8267. + }
  8268. + temp[0]='\0';
  8269. + snprintf(temp, (strlen(pkg->priority)+12), "Priority: %s\n", pkg->priority);
  8270. + } else if (strcasecmp(field, "Provides") == 0) {
  8271. + /* Provides */
  8272. + int i;
  8273. +
  8274. + if (pkg->provides_count) {
  8275. + /* Here we check if the ipkg_internal_use_only is used, and we discard it.*/
  8276. + for ( i=0; i < pkg->provides_count; i++ ){
  8277. + if (strstr(pkg->provides_str[i],"ipkg_internal_use_only")!=NULL) {
  8278. + memset (pkg->provides_str[i],'\x0',strlen(pkg->provides_str[i])); /* Pigi clear my trick flag, just in case */
  8279. + flag_provide_false = 1;
  8280. + }
  8281. + }
  8282. + if ( !flag_provide_false || /* Pigi there is not my trick flag */
  8283. + ((flag_provide_false) && (pkg->provides_count > 1))){ /* Pigi There is, but we also have others Provides */
  8284. + char provstr[LINE_LEN];
  8285. + len = 15;
  8286. + for(i = 0; i < pkg->provides_count; i++) {
  8287. + len = len + (strlen(pkg->provides_str[i])+5);
  8288. + }
  8289. + temp = (char *)realloc(temp,len);
  8290. + if ( temp == NULL ){
  8291. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8292. + return NULL;
  8293. + }
  8294. + temp[0]='\0';
  8295. + strncpy(temp, "Provides:", 12);
  8296. + for(i = 0; i < pkg->provides_count; i++) {
  8297. + if (strlen(pkg->provides_str[i])>0){;
  8298. + snprintf(provstr, LINE_LEN, "%s %s", i == 1 ? "" : ",", pkg->provides_str[i]);
  8299. + strncat(temp, provstr, strlen(provstr));
  8300. + }
  8301. + }
  8302. + strncat(temp, "\n", strlen("\n"));
  8303. + }
  8304. + }
  8305. + } else {
  8306. + goto UNKNOWN_FMT_FIELD;
  8307. + }
  8308. + }
  8309. + break;
  8310. + case 'r':
  8311. + case 'R': {
  8312. + int i;
  8313. + /* Replaces | Recommends*/
  8314. + if (strcasecmp (field, "Replaces") == 0) {
  8315. + if (pkg->replaces_count) {
  8316. + char replstr[LINE_LEN];
  8317. + len = 14;
  8318. + for (i = 0; i < pkg->replaces_count; i++) {
  8319. + len = len + (strlen(pkg->replaces_str[i])+5);
  8320. + }
  8321. + temp = (char *)realloc(temp,len);
  8322. + if ( temp == NULL ){
  8323. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8324. + return NULL;
  8325. + }
  8326. + temp[0]='\0';
  8327. + strncpy(temp, "Replaces:", 12);
  8328. + for (i = 0; i < pkg->replaces_count; i++) {
  8329. + snprintf(replstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->replaces_str[i]);
  8330. + strncat(temp, replstr, strlen(replstr));
  8331. + }
  8332. + strncat(temp, "\n", strlen("\n"));
  8333. + }
  8334. + } else if (strcasecmp (field, "Recommends") == 0) {
  8335. + if (pkg->recommends_count) {
  8336. + char recstr[LINE_LEN];
  8337. + len = 15;
  8338. + for(i = 0; i < pkg->recommends_count; i++) {
  8339. + len = len + (strlen( pkg->recommends_str[i])+5);
  8340. + }
  8341. + temp = (char *)realloc(temp,len);
  8342. + if ( temp == NULL ){
  8343. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8344. + return NULL;
  8345. + }
  8346. + temp[0]='\0';
  8347. + strncpy(temp, "Recommends:", 13);
  8348. + for(i = 0; i < pkg->recommends_count; i++) {
  8349. + snprintf(recstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->recommends_str[i]);
  8350. + strncat(temp, recstr, strlen(recstr));
  8351. + }
  8352. + strncat(temp, "\n", strlen("\n"));
  8353. + }
  8354. + } else {
  8355. + goto UNKNOWN_FMT_FIELD;
  8356. + }
  8357. + }
  8358. + break;
  8359. + case 's':
  8360. + case 'S': {
  8361. + /* Section | Size | Source | Status | Suggests */
  8362. + if (strcasecmp(field, "Section") == 0) {
  8363. + /* Section */
  8364. + if (pkg->section) {
  8365. + temp = (char *)realloc(temp,strlen(pkg->section)+11);
  8366. + if ( temp == NULL ){
  8367. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8368. + return NULL;
  8369. + }
  8370. + temp[0]='\0';
  8371. + snprintf(temp, (strlen(pkg->section)+11), "Section: %s\n", pkg->section);
  8372. + }
  8373. + } else if (strcasecmp(field, "Size") == 0) {
  8374. + /* Size */
  8375. + if (pkg->size) {
  8376. + temp = (char *)realloc(temp,strlen(pkg->size)+8);
  8377. + if ( temp == NULL ){
  8378. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8379. + return NULL;
  8380. + }
  8381. + temp[0]='\0';
  8382. + snprintf(temp, (strlen(pkg->size)+8), "Size: %s\n", pkg->size);
  8383. + }
  8384. + } else if (strcasecmp(field, "Source") == 0) {
  8385. + /* Source */
  8386. + if (pkg->source) {
  8387. + temp = (char *)realloc(temp,strlen(pkg->source)+10);
  8388. + if ( temp == NULL ){
  8389. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8390. + return NULL;
  8391. + }
  8392. + temp[0]='\0';
  8393. + snprintf(temp, (strlen(pkg->source)+10), "Source: %s\n", pkg->source);
  8394. + }
  8395. + } else if (strcasecmp(field, "Status") == 0) {
  8396. + /* Status */
  8397. + /* Benjamin Pineau note: we should avoid direct usage of
  8398. + * strlen(arg) without keeping "arg" for later free()
  8399. + */
  8400. + char *pflag=pkg_state_flag_to_str(pkg->state_flag);
  8401. + char *pstat=pkg_state_status_to_str(pkg->state_status);
  8402. + char *pwant=pkg_state_want_to_str(pkg->state_want);
  8403. +
  8404. + size_t sum_of_sizes = (size_t) ( strlen(pwant)+ strlen(pflag)+ strlen(pstat) + 12 );
  8405. + temp = (char *)realloc(temp,sum_of_sizes);
  8406. + if ( temp == NULL ){
  8407. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8408. + return NULL;
  8409. + }
  8410. + temp[0]='\0';
  8411. + snprintf(temp, sum_of_sizes , "Status: %s %s %s\n", pwant, pflag, pstat);
  8412. + free(pflag);
  8413. + free(pwant);
  8414. + if(pstat) /* pfstat can be NULL if ENOMEM */
  8415. + free(pstat);
  8416. + } else if (strcasecmp(field, "Suggests") == 0) {
  8417. + if (pkg->suggests_count) {
  8418. + int i;
  8419. + char sugstr[LINE_LEN];
  8420. + len = 13;
  8421. + for(i = 0; i < pkg->suggests_count; i++) {
  8422. + len = len + (strlen(pkg->suggests_str[i])+5);
  8423. + }
  8424. + temp = (char *)realloc(temp,len);
  8425. + if ( temp == NULL ){
  8426. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8427. + return NULL;
  8428. + }
  8429. + temp[0]='\0';
  8430. + strncpy(temp, "Suggests:", 10);
  8431. + for(i = 0; i < pkg->suggests_count; i++) {
  8432. + snprintf(sugstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->suggests_str[i]);
  8433. + strncat(temp, sugstr, strlen(sugstr));
  8434. + }
  8435. + strncat(temp, "\n", strlen("\n"));
  8436. + }
  8437. + } else {
  8438. + goto UNKNOWN_FMT_FIELD;
  8439. + }
  8440. + }
  8441. + break;
  8442. + case 'v':
  8443. + case 'V': {
  8444. + /* Version */
  8445. + char *version = pkg_version_str_alloc(pkg);
  8446. + temp = (char *)realloc(temp,strlen(version)+14);
  8447. + if ( temp == NULL ){
  8448. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8449. + return NULL;
  8450. + }
  8451. + temp[0]='\0';
  8452. + snprintf(temp, (strlen(version)+12), "Version: %s\n", version);
  8453. + free(version);
  8454. + }
  8455. + break;
  8456. + default:
  8457. + goto UNKNOWN_FMT_FIELD;
  8458. + }
  8459. +
  8460. + if ( strlen(temp)<2 ) {
  8461. + temp[0]='\0';
  8462. + }
  8463. + return temp;
  8464. +
  8465. + UNKNOWN_FMT_FIELD:
  8466. + fprintf(stderr, "%s: ERROR: Unknown field name: %s\n", __FUNCTION__, field);
  8467. + if ( strlen(temp)<2 ) {
  8468. + temp[0]='\0';
  8469. + }
  8470. +
  8471. + return temp;
  8472. +}
  8473. +
  8474. +void pkg_print_info(pkg_t *pkg, FILE *file)
  8475. +{
  8476. + char * buff;
  8477. + if (pkg == NULL) {
  8478. + return;
  8479. + }
  8480. +
  8481. + buff = pkg_formatted_info(pkg);
  8482. + if ( buff == NULL )
  8483. + return;
  8484. + if (strlen(buff)>2){
  8485. + fwrite(buff, 1, strlen(buff), file);
  8486. + }
  8487. + free(buff);
  8488. +}
  8489. +
  8490. +void pkg_print_status(pkg_t * pkg, FILE * file)
  8491. +{
  8492. + if (pkg == NULL) {
  8493. + return;
  8494. + }
  8495. +
  8496. + /* XXX: QUESTION: Do we actually want more fields here? The
  8497. + original idea was to save space by installing only what was
  8498. + needed for actual computation, (package, version, status,
  8499. + essential, conffiles). The assumption is that all other fields
  8500. + can be found in th available file.
  8501. +
  8502. + But, someone proposed the idea to make it possible to
  8503. + reconstruct a .ipk from an installed package, (ie. for beaming
  8504. + from one handheld to another). So, maybe we actually want a few
  8505. + more fields here, (depends, suggests, etc.), so that that would
  8506. + be guaranteed to work even in the absence of more information
  8507. + from the available file.
  8508. +
  8509. + 28-MAR-03: kergoth and I discussed this yesterday. We think
  8510. + the essential info needs to be here for all installed packages
  8511. + because they may not appear in the Packages files on various
  8512. + feeds. Furthermore, one should be able to install from URL or
  8513. + local storage without requiring a Packages file from any feed.
  8514. + -Jamey
  8515. + */
  8516. + pkg_print_field(pkg, file, "Package");
  8517. + pkg_print_field(pkg, file, "Version");
  8518. + pkg_print_field(pkg, file, "Depends");
  8519. + pkg_print_field(pkg, file, "Recommends");
  8520. + pkg_print_field(pkg, file, "Suggests");
  8521. + pkg_print_field(pkg, file, "Provides");
  8522. + pkg_print_field(pkg, file, "Replaces");
  8523. + pkg_print_field(pkg, file, "Conflicts");
  8524. + pkg_print_field(pkg, file, "Status");
  8525. + pkg_print_field(pkg, file, "Essential"); /* @@@@ should be removed in future release. */
  8526. + pkg_print_field(pkg, file, "Architecture");
  8527. + pkg_print_field(pkg, file, "Conffiles");
  8528. + pkg_print_field(pkg, file, "Installed-Time");
  8529. + fputs("\n", file);
  8530. +}
  8531. +
  8532. +void pkg_print_field(pkg_t *pkg, FILE *file, const char *field)
  8533. +{
  8534. + char *buff;
  8535. + if (strlen(field) < PKG_MINIMUM_FIELD_NAME_LEN) {
  8536. + fprintf(stderr, "%s: ERROR: Unknown field name: %s\n",
  8537. + __FUNCTION__, field);
  8538. + }
  8539. + buff = pkg_formatted_field(pkg, field);
  8540. + if (strlen(buff)>2) {
  8541. + fprintf(file, "%s", buff);
  8542. + fflush(file);
  8543. + }
  8544. + free(buff);
  8545. + return;
  8546. +}
  8547. +
  8548. +/*
  8549. + * libdpkg - Debian packaging suite library routines
  8550. + * vercmp.c - comparison of version numbers
  8551. + *
  8552. + * Copyright (C) 1995 Ian Jackson <iwj10@cus.cam.ac.uk>
  8553. + */
  8554. +int pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg)
  8555. +{
  8556. + int r;
  8557. +
  8558. + if (pkg->epoch > ref_pkg->epoch) {
  8559. + return 1;
  8560. + }
  8561. +
  8562. + if (pkg->epoch < ref_pkg->epoch) {
  8563. + return -1;
  8564. + }
  8565. +
  8566. + r = verrevcmp(pkg->version, ref_pkg->version);
  8567. + if (r) {
  8568. + return r;
  8569. + }
  8570. +
  8571. +#ifdef USE_DEBVERSION
  8572. + r = verrevcmp(pkg->revision, ref_pkg->revision);
  8573. + if (r) {
  8574. + return r;
  8575. + }
  8576. +
  8577. + r = verrevcmp(pkg->familiar_revision, ref_pkg->familiar_revision);
  8578. +#endif
  8579. +
  8580. + return r;
  8581. +}
  8582. +
  8583. +int verrevcmp(const char *val, const char *ref)
  8584. +{
  8585. + int vc, rc;
  8586. + long vl, rl;
  8587. + const char *vp, *rp;
  8588. + const char *vsep, *rsep;
  8589. +
  8590. + if (!val) val= "";
  8591. + if (!ref) ref= "";
  8592. + for (;;) {
  8593. + vp= val; while (*vp && !isdigit(*vp)) vp++;
  8594. + rp= ref; while (*rp && !isdigit(*rp)) rp++;
  8595. + for (;;) {
  8596. + vc= (val == vp) ? 0 : *val++;
  8597. + rc= (ref == rp) ? 0 : *ref++;
  8598. + if (!rc && !vc) break;
  8599. + if (vc && !isalpha(vc)) vc += 256; /* assumes ASCII character set */
  8600. + if (rc && !isalpha(rc)) rc += 256;
  8601. + if (vc != rc) return vc - rc;
  8602. + }
  8603. + val= vp;
  8604. + ref= rp;
  8605. + vl=0; if (isdigit(*vp)) vl= strtol(val,(char**)&val,10);
  8606. + rl=0; if (isdigit(*rp)) rl= strtol(ref,(char**)&ref,10);
  8607. + if (vl != rl) return vl - rl;
  8608. +
  8609. + vc = *val;
  8610. + rc = *ref;
  8611. + vsep = strchr(".-", vc);
  8612. + rsep = strchr(".-", rc);
  8613. + if (vsep && !rsep) return -1;
  8614. + if (!vsep && rsep) return +1;
  8615. +
  8616. + if (!*val && !*ref) return 0;
  8617. + if (!*val) return -1;
  8618. + if (!*ref) return +1;
  8619. + }
  8620. +}
  8621. +
  8622. +int pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op)
  8623. +{
  8624. + int r;
  8625. +
  8626. + r = pkg_compare_versions(it, ref);
  8627. +
  8628. + if (strcmp(op, "<=") == 0 || strcmp(op, "<") == 0) {
  8629. + return r <= 0;
  8630. + }
  8631. +
  8632. + if (strcmp(op, ">=") == 0 || strcmp(op, ">") == 0) {
  8633. + return r >= 0;
  8634. + }
  8635. +
  8636. + if (strcmp(op, "<<") == 0) {
  8637. + return r < 0;
  8638. + }
  8639. +
  8640. + if (strcmp(op, ">>") == 0) {
  8641. + return r > 0;
  8642. + }
  8643. +
  8644. + if (strcmp(op, "=") == 0) {
  8645. + return r == 0;
  8646. + }
  8647. +
  8648. + fprintf(stderr, "unknown operator: %s", op);
  8649. + return 0;
  8650. +}
  8651. +
  8652. +int pkg_name_version_and_architecture_compare(pkg_t *p1, pkg_t *p2)
  8653. +{
  8654. + const pkg_t *a = *(const pkg_t **)p1;
  8655. + const pkg_t *b = *(const pkg_t **)p2;
  8656. + int namecmp;
  8657. + int vercmp;
  8658. + if (!a->name || !b->name) {
  8659. + fprintf(stderr, "pkg_name_version_and_architecture_compare: a=%p a->name=%p b=%p b->name=%p\n",
  8660. + a, a->name, b, b->name);
  8661. + return 0;
  8662. + }
  8663. +
  8664. + namecmp = strcmp(a->name, b->name);
  8665. + if (namecmp)
  8666. + return namecmp;
  8667. + vercmp = pkg_compare_versions(a, b);
  8668. + if (vercmp)
  8669. + return vercmp;
  8670. + if (!a->arch_priority || !b->arch_priority) {
  8671. + fprintf(stderr, "pkg_name_version_and_architecture_compare: a=%p a->arch_priority=%i b=%p b->arch_priority=%i\n",
  8672. + a, a->arch_priority, b, b->arch_priority);
  8673. + return 0;
  8674. + }
  8675. + if (a->arch_priority > b->arch_priority)
  8676. + return 1;
  8677. + if (a->arch_priority < b->arch_priority)
  8678. + return -1;
  8679. + return 0;
  8680. +}
  8681. +
  8682. +int abstract_pkg_name_compare(abstract_pkg_t *p1, abstract_pkg_t *p2)
  8683. +{
  8684. + const abstract_pkg_t *a = *(const abstract_pkg_t **)p1;
  8685. + const abstract_pkg_t *b = *(const abstract_pkg_t **)p2;
  8686. + if (!a->name || !b->name) {
  8687. + fprintf(stderr, "abstract_pkg_name_compare: a=%p a->name=%p b=%p b->name=%p\n",
  8688. + a, a->name, b, b->name);
  8689. + return 0;
  8690. + }
  8691. + return strcmp(a->name, b->name);
  8692. +}
  8693. +
  8694. +
  8695. +char *pkg_version_str_alloc(pkg_t *pkg)
  8696. +{
  8697. + char *complete_version;
  8698. + char *epoch_str;
  8699. +#ifdef USE_DEBVERSION
  8700. + char *revision_str;
  8701. + char *familiar_revision_str;
  8702. +#endif
  8703. +
  8704. + if (pkg->epoch) {
  8705. + sprintf_alloc(&epoch_str, "%lu:", (unsigned long)pkg->epoch);
  8706. + } else {
  8707. + epoch_str = strdup("");
  8708. + }
  8709. +
  8710. +#ifdef USE_DEBVERSION
  8711. + if (pkg->revision && strlen(pkg->revision)) {
  8712. + sprintf_alloc(&revision_str, "-%s", pkg->revision);
  8713. + } else {
  8714. + revision_str = strdup("");
  8715. + }
  8716. +
  8717. + if (pkg->familiar_revision && strlen(pkg->familiar_revision)) {
  8718. + sprintf_alloc(&familiar_revision_str, "-fam%s", pkg->familiar_revision);
  8719. + } else {
  8720. + familiar_revision_str = strdup("");
  8721. + }
  8722. +#endif
  8723. +
  8724. +#ifdef USE_DEBVERSION
  8725. + sprintf_alloc(&complete_version, "%s%s%s%s",
  8726. + epoch_str, pkg->version, revision_str, familiar_revision_str);
  8727. +#else
  8728. + sprintf_alloc(&complete_version, "%s%s",
  8729. + epoch_str, pkg->version);
  8730. +#endif
  8731. +
  8732. + free(epoch_str);
  8733. +#ifdef USE_DEBVERSION
  8734. + free(revision_str);
  8735. + free(familiar_revision_str);
  8736. +#endif
  8737. +
  8738. + return complete_version;
  8739. +}
  8740. +
  8741. +str_list_t *pkg_get_installed_files(pkg_t *pkg)
  8742. +{
  8743. + int err;
  8744. + char *list_file_name = NULL;
  8745. + FILE *list_file = NULL;
  8746. + char *line;
  8747. + char *installed_file_name;
  8748. + int rootdirlen;
  8749. +
  8750. + pkg->installed_files_ref_cnt++;
  8751. +
  8752. + if (pkg->installed_files) {
  8753. + return pkg->installed_files;
  8754. + }
  8755. +
  8756. + pkg->installed_files = str_list_alloc();
  8757. + if (pkg->installed_files == NULL) {
  8758. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8759. + return NULL;
  8760. + }
  8761. +
  8762. + /* For uninstalled packages, get the file list firectly from the package.
  8763. + For installed packages, look at the package.list file in the database.
  8764. + */
  8765. + if (pkg->state_status == SS_NOT_INSTALLED || pkg->dest == NULL) {
  8766. + if (pkg->local_filename == NULL) {
  8767. + return pkg->installed_files;
  8768. + }
  8769. + /* XXX: CLEANUP: Maybe rewrite this to avoid using a temporary
  8770. + file. In other words, change deb_extract so that it can
  8771. + simply return the file list as a char *[] rather than
  8772. + insisting on writing in to a FILE * as it does now. */
  8773. + list_file = tmpfile();
  8774. + err = pkg_extract_data_file_names_to_stream(pkg, list_file);
  8775. + if (err) {
  8776. + fclose(list_file);
  8777. + fprintf(stderr, "%s: Error extracting file list from %s: %s\n",
  8778. + __FUNCTION__, pkg->local_filename, strerror(err));
  8779. + return pkg->installed_files;
  8780. + }
  8781. + rewind(list_file);
  8782. + } else {
  8783. + sprintf_alloc(&list_file_name, "%s/%s.list",
  8784. + pkg->dest->info_dir, pkg->name);
  8785. + if (! file_exists(list_file_name)) {
  8786. + free(list_file_name);
  8787. + return pkg->installed_files;
  8788. + }
  8789. +
  8790. + list_file = fopen(list_file_name, "r");
  8791. + if (list_file == NULL) {
  8792. + fprintf(stderr, "WARNING: Cannot open %s: %s\n",
  8793. + list_file_name, strerror(errno));
  8794. + free(list_file_name);
  8795. + return pkg->installed_files;
  8796. + }
  8797. + free(list_file_name);
  8798. + }
  8799. +
  8800. + rootdirlen = strlen( pkg->dest->root_dir );
  8801. + while (1) {
  8802. + char *file_name;
  8803. +
  8804. + line = file_read_line_alloc(list_file);
  8805. + if (line == NULL) {
  8806. + break;
  8807. + }
  8808. + str_chomp(line);
  8809. + file_name = line;
  8810. +
  8811. + /* Take pains to avoid uglies like "/./" in the middle of file_name. */
  8812. + if( strncmp( pkg->dest->root_dir,
  8813. + file_name,
  8814. + rootdirlen ) ) {
  8815. + if (*file_name == '.') {
  8816. + file_name++;
  8817. + }
  8818. + if (*file_name == '/') {
  8819. + file_name++;
  8820. + }
  8821. +
  8822. + /* Freed in pkg_free_installed_files */
  8823. + sprintf_alloc(&installed_file_name, "%s%s", pkg->dest->root_dir, file_name);
  8824. + } else {
  8825. + // already contains root_dir as header -> ABSOLUTE
  8826. + sprintf_alloc(&installed_file_name, "%s", file_name);
  8827. + }
  8828. + str_list_append(pkg->installed_files, installed_file_name);
  8829. + free(line);
  8830. + }
  8831. +
  8832. + fclose(list_file);
  8833. +
  8834. + return pkg->installed_files;
  8835. +}
  8836. +
  8837. +/* XXX: CLEANUP: This function and it's counterpart,
  8838. + (pkg_get_installed_files), do not match our init/deinit naming
  8839. + convention. Nor the alloc/free convention. But, then again, neither
  8840. + of these conventions currrently fit the way these two functions
  8841. + work. */
  8842. +int pkg_free_installed_files(pkg_t *pkg)
  8843. +{
  8844. + str_list_elt_t *iter;
  8845. +
  8846. + pkg->installed_files_ref_cnt--;
  8847. + if (pkg->installed_files_ref_cnt > 0) {
  8848. + return 0;
  8849. + }
  8850. +
  8851. + if (pkg->installed_files) {
  8852. +
  8853. + for (iter = pkg->installed_files->head; iter; iter = iter->next) {
  8854. + /* malloced in pkg_get_installed_files */
  8855. + free (iter->data);
  8856. + iter->data = NULL;
  8857. + }
  8858. +
  8859. + str_list_deinit(pkg->installed_files);
  8860. + }
  8861. +
  8862. + pkg->installed_files = NULL;
  8863. +
  8864. + return 0;
  8865. +}
  8866. +
  8867. +int pkg_remove_installed_files_list(ipkg_conf_t *conf, pkg_t *pkg)
  8868. +{
  8869. + int err;
  8870. + char *list_file_name;
  8871. +
  8872. + //I don't think pkg_free_installed_files should be called here. Jamey
  8873. + //pkg_free_installed_files(pkg);
  8874. +
  8875. + sprintf_alloc(&list_file_name, "%s/%s.list",
  8876. + pkg->dest->info_dir, pkg->name);
  8877. + if (!conf->noaction) {
  8878. + err = unlink(list_file_name);
  8879. + free(list_file_name);
  8880. +
  8881. + if (err) {
  8882. + return errno;
  8883. + }
  8884. + }
  8885. + return 0;
  8886. +}
  8887. +
  8888. +conffile_t *pkg_get_conffile(pkg_t *pkg, const char *file_name)
  8889. +{
  8890. + conffile_list_elt_t *iter;
  8891. + conffile_t *conffile;
  8892. +
  8893. + if (pkg == NULL) {
  8894. + return NULL;
  8895. + }
  8896. +
  8897. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  8898. + conffile = iter->data;
  8899. +
  8900. + if (strcmp(conffile->name, file_name) == 0) {
  8901. + return conffile;
  8902. + }
  8903. + }
  8904. +
  8905. + return NULL;
  8906. +}
  8907. +
  8908. +int pkg_run_script(ipkg_conf_t *conf, pkg_t *pkg,
  8909. + const char *script, const char *args)
  8910. +{
  8911. + int err;
  8912. + char *path;
  8913. + char *cmd;
  8914. +
  8915. + /* XXX: FEATURE: When conf->offline_root is set, we should run the
  8916. + maintainer script within a chroot environment. */
  8917. +
  8918. + /* Installed packages have scripts in pkg->dest->info_dir, uninstalled packages
  8919. + have scripts in pkg->tmp_unpack_dir. */
  8920. + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) {
  8921. + if (pkg->dest == NULL) {
  8922. + fprintf(stderr, "%s: ERROR: installed package %s has a NULL dest\n",
  8923. + __FUNCTION__, pkg->name);
  8924. + return EINVAL;
  8925. + }
  8926. + sprintf_alloc(&path, "%s/%s.%s", pkg->dest->info_dir, pkg->name, script);
  8927. + } else {
  8928. + if (pkg->tmp_unpack_dir == NULL) {
  8929. + fprintf(stderr, "%s: ERROR: uninstalled package %s has a NULL tmp_unpack_dir\n",
  8930. + __FUNCTION__, pkg->name);
  8931. + return EINVAL;
  8932. + }
  8933. + sprintf_alloc(&path, "%s/%s", pkg->tmp_unpack_dir, script);
  8934. + }
  8935. +
  8936. + ipkg_message(conf, IPKG_INFO, "Running script %s\n", path);
  8937. + if (conf->noaction) return 0;
  8938. +
  8939. + /* XXX: CLEANUP: There must be a better way to handle maintainer
  8940. + scripts when running with offline_root mode and/or a dest other
  8941. + than '/'. I've been playing around with some clever chroot
  8942. + tricks and I might come up with something workable. */
  8943. + if (conf->offline_root) {
  8944. + setenv("IPKG_OFFLINE_ROOT", conf->offline_root, 1);
  8945. + }
  8946. +
  8947. + setenv("PKG_ROOT",
  8948. + pkg->dest ? pkg->dest->root_dir : conf->default_dest->root_dir, 1);
  8949. +
  8950. + if (! file_exists(path)) {
  8951. + free(path);
  8952. + return 0;
  8953. + }
  8954. +
  8955. + if (conf->offline_root) {
  8956. + fprintf(stderr, "(offline root mode: not running %s.%s)\n", pkg->name, script);
  8957. + free(path);
  8958. + return 0;
  8959. + }
  8960. +
  8961. + sprintf_alloc(&cmd, "%s %s", path, args);
  8962. + free(path);
  8963. +
  8964. + err = xsystem(cmd);
  8965. + free(cmd);
  8966. +
  8967. + if (err) {
  8968. + fprintf(stderr, "%s script returned status %d\n", script, err);
  8969. + return err;
  8970. + }
  8971. +
  8972. + return 0;
  8973. +}
  8974. +
  8975. +char *pkg_state_want_to_str(pkg_state_want_t sw)
  8976. +{
  8977. + int i;
  8978. +
  8979. + for (i=0; i < ARRAY_SIZE(pkg_state_want_map); i++) {
  8980. + if (pkg_state_want_map[i].value == sw) {
  8981. + return strdup(pkg_state_want_map[i].str);
  8982. + }
  8983. + }
  8984. +
  8985. + fprintf(stderr, "%s: ERROR: Illegal value for state_want: %d\n",
  8986. + __FUNCTION__, sw);
  8987. + return strdup("<STATE_WANT_UNKNOWN>");
  8988. +}
  8989. +
  8990. +pkg_state_want_t pkg_state_want_from_str(char *str)
  8991. +{
  8992. + int i;
  8993. +
  8994. + for (i=0; i < ARRAY_SIZE(pkg_state_want_map); i++) {
  8995. + if (strcmp(str, pkg_state_want_map[i].str) == 0) {
  8996. + return pkg_state_want_map[i].value;
  8997. + }
  8998. + }
  8999. +
  9000. + fprintf(stderr, "%s: ERROR: Illegal value for state_want string: %s\n",
  9001. + __FUNCTION__, str);
  9002. + return SW_UNKNOWN;
  9003. +}
  9004. +
  9005. +char *pkg_state_flag_to_str(pkg_state_flag_t sf)
  9006. +{
  9007. + int i;
  9008. + int len = 3; /* ok\000 is minimum */
  9009. + char *str = NULL;
  9010. +
  9011. + /* clear the temporary flags before converting to string */
  9012. + sf &= SF_NONVOLATILE_FLAGS;
  9013. +
  9014. + if (sf == 0) {
  9015. + return strdup("ok");
  9016. + } else {
  9017. +
  9018. + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
  9019. + if (sf & pkg_state_flag_map[i].value) {
  9020. + len += strlen(pkg_state_flag_map[i].str) + 1;
  9021. + }
  9022. + }
  9023. + str = malloc(len);
  9024. + if ( str == NULL ) {
  9025. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  9026. + return NULL;
  9027. + }
  9028. + str[0] = 0;
  9029. + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
  9030. + if (sf & pkg_state_flag_map[i].value) {
  9031. + strcat(str, pkg_state_flag_map[i].str);
  9032. + strcat(str, ",");
  9033. + }
  9034. + }
  9035. + len = strlen(str);
  9036. + str[len-1] = 0; /* squash last comma */
  9037. + return str;
  9038. + }
  9039. +}
  9040. +
  9041. +pkg_state_flag_t pkg_state_flag_from_str(char *str)
  9042. +{
  9043. + int i;
  9044. + int sf = SF_OK;
  9045. +
  9046. + if (strcmp(str, "ok") == 0) {
  9047. + return SF_OK;
  9048. + }
  9049. + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
  9050. + const char *sfname = pkg_state_flag_map[i].str;
  9051. + int sfname_len = strlen(sfname);
  9052. + if (strncmp(str, sfname, sfname_len) == 0) {
  9053. + sf |= pkg_state_flag_map[i].value;
  9054. + str += sfname_len;
  9055. + if (str[0] == ',') {
  9056. + str++;
  9057. + } else {
  9058. + break;
  9059. + }
  9060. + }
  9061. + }
  9062. +
  9063. + return sf;
  9064. +}
  9065. +
  9066. +char *pkg_state_status_to_str(pkg_state_status_t ss)
  9067. +{
  9068. + int i;
  9069. +
  9070. + for (i=0; i < ARRAY_SIZE(pkg_state_status_map); i++) {
  9071. + if (pkg_state_status_map[i].value == ss) {
  9072. + return strdup(pkg_state_status_map[i].str);
  9073. + }
  9074. + }
  9075. +
  9076. + fprintf(stderr, "%s: ERROR: Illegal value for state_status: %d\n",
  9077. + __FUNCTION__, ss);
  9078. + return strdup("<STATE_STATUS_UNKNOWN>");
  9079. +}
  9080. +
  9081. +pkg_state_status_t pkg_state_status_from_str(char *str)
  9082. +{
  9083. + int i;
  9084. +
  9085. + for (i=0; i < ARRAY_SIZE(pkg_state_status_map); i++) {
  9086. + if (strcmp(str, pkg_state_status_map[i].str) == 0) {
  9087. + return pkg_state_status_map[i].value;
  9088. + }
  9089. + }
  9090. +
  9091. + fprintf(stderr, "%s: ERROR: Illegal value for state_status string: %s\n",
  9092. + __FUNCTION__, str);
  9093. + return SS_NOT_INSTALLED;
  9094. +}
  9095. +
  9096. +int pkg_arch_supported(ipkg_conf_t *conf, pkg_t *pkg)
  9097. +{
  9098. + nv_pair_list_elt_t *l;
  9099. +
  9100. + if (!pkg->architecture)
  9101. + return 1;
  9102. +
  9103. + l = conf->arch_list.head;
  9104. +
  9105. + while (l) {
  9106. + nv_pair_t *nv = l->data;
  9107. + if (strcmp(nv->name, pkg->architecture) == 0) {
  9108. + ipkg_message(conf, IPKG_DEBUG, "arch %s (priority %s) supported for pkg %s\n", nv->name, nv->value, pkg->name);
  9109. + return 1;
  9110. + }
  9111. + l = l->next;
  9112. + }
  9113. +
  9114. + ipkg_message(conf, IPKG_DEBUG, "arch %s unsupported for pkg %s\n", pkg->architecture, pkg->name);
  9115. + return 0;
  9116. +}
  9117. +
  9118. +int pkg_get_arch_priority(ipkg_conf_t *conf, const char *archname)
  9119. +{
  9120. + nv_pair_list_elt_t *l;
  9121. +
  9122. + l = conf->arch_list.head;
  9123. +
  9124. + while (l) {
  9125. + nv_pair_t *nv = l->data;
  9126. + if (strcmp(nv->name, archname) == 0) {
  9127. + int priority = strtol(nv->value, NULL, 0);
  9128. + return priority;
  9129. + }
  9130. + l = l->next;
  9131. + }
  9132. + return 0;
  9133. +}
  9134. +
  9135. +int pkg_info_preinstall_check(ipkg_conf_t *conf)
  9136. +{
  9137. + int i;
  9138. + hash_table_t *pkg_hash = &conf->pkg_hash;
  9139. + pkg_vec_t *available_pkgs = pkg_vec_alloc();
  9140. + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
  9141. +
  9142. + ipkg_message(conf, IPKG_INFO, "pkg_info_preinstall_check: updating arch priority for each package\n");
  9143. + pkg_hash_fetch_available(pkg_hash, available_pkgs);
  9144. + /* update arch_priority for each package */
  9145. + for (i = 0; i < available_pkgs->len; i++) {
  9146. + pkg_t *pkg = available_pkgs->pkgs[i];
  9147. + int arch_priority = 1;
  9148. + if (!pkg)
  9149. + continue;
  9150. + // ipkg_message(conf, IPKG_DEBUG2, " package %s version=%s arch=%p:", pkg->name, pkg->version, pkg->architecture);
  9151. + if (pkg->architecture)
  9152. + arch_priority = pkg_get_arch_priority(conf, pkg->architecture);
  9153. + else
  9154. + ipkg_message(conf, IPKG_ERROR, "pkg_info_preinstall_check: no architecture for package %s\n", pkg->name);
  9155. + // ipkg_message(conf, IPKG_DEBUG2, "%s arch_priority=%d\n", pkg->architecture, arch_priority);
  9156. + pkg->arch_priority = arch_priority;
  9157. + }
  9158. +
  9159. + for (i = 0; i < available_pkgs->len; i++) {
  9160. + pkg_t *pkg = available_pkgs->pkgs[i];
  9161. + if (!pkg->arch_priority && (pkg->state_flag || (pkg->state_want != SW_UNKNOWN))) {
  9162. + /* clear flags and want for any uninstallable package */
  9163. + ipkg_message(conf, IPKG_NOTICE, "Clearing state_want and state_flag for pkg=%s (arch_priority=%d flag=%d want=%d)\n",
  9164. + pkg->name, pkg->arch_priority, pkg->state_flag, pkg->state_want);
  9165. + pkg->state_want = SW_UNKNOWN;
  9166. + pkg->state_flag = 0;
  9167. + }
  9168. + }
  9169. + pkg_vec_free(available_pkgs);
  9170. +
  9171. + /* update the file owner data structure */
  9172. + ipkg_message(conf, IPKG_INFO, "pkg_info_preinstall_check: update file owner list\n");
  9173. + pkg_hash_fetch_all_installed(pkg_hash, installed_pkgs);
  9174. + for (i = 0; i < installed_pkgs->len; i++) {
  9175. + pkg_t *pkg = installed_pkgs->pkgs[i];
  9176. + str_list_t *installed_files = pkg_get_installed_files(pkg); /* this causes installed_files to be cached */
  9177. + str_list_elt_t *iter;
  9178. + if (installed_files == NULL) {
  9179. + ipkg_message(conf, IPKG_ERROR, "No installed files for pkg %s\n", pkg->name);
  9180. + break;
  9181. + }
  9182. + for (iter = installed_files->head; iter; iter = iter->next) {
  9183. + char *installed_file = iter->data;
  9184. + // ipkg_message(conf, IPKG_DEBUG2, "pkg %s: file=%s\n", pkg->name, installed_file);
  9185. + file_hash_set_file_owner(conf, installed_file, pkg);
  9186. + }
  9187. + }
  9188. + pkg_vec_free(installed_pkgs);
  9189. +
  9190. + return 0;
  9191. +}
  9192. +
  9193. +struct pkg_write_filelist_data {
  9194. + ipkg_conf_t *conf;
  9195. + pkg_t *pkg;
  9196. + FILE *stream;
  9197. +};
  9198. +
  9199. +void pkg_write_filelist_helper(const char *key, void *entry_, void *data_)
  9200. +{
  9201. + struct pkg_write_filelist_data *data = data_;
  9202. + pkg_t *entry = entry_;
  9203. + if (entry == data->pkg) {
  9204. + fprintf(data->stream, "%s\n", key);
  9205. + }
  9206. +}
  9207. +
  9208. +int pkg_write_filelist(ipkg_conf_t *conf, pkg_t *pkg)
  9209. +{
  9210. + struct pkg_write_filelist_data data;
  9211. + char *list_file_name = NULL;
  9212. + int err = 0;
  9213. +
  9214. + if (!pkg) {
  9215. + ipkg_message(conf, IPKG_ERROR, "Null pkg\n");
  9216. + return -EINVAL;
  9217. + }
  9218. + ipkg_message(conf, IPKG_INFO,
  9219. + " creating %s.list file\n", pkg->name);
  9220. + sprintf_alloc(&list_file_name, "%s/%s.list", pkg->dest->info_dir, pkg->name);
  9221. + if (!list_file_name) {
  9222. + ipkg_message(conf, IPKG_ERROR, "Failed to alloc list_file_name\n");
  9223. + return -ENOMEM;
  9224. + }
  9225. + ipkg_message(conf, IPKG_INFO,
  9226. + " creating %s file for pkg %s\n", list_file_name, pkg->name);
  9227. + data.stream = fopen(list_file_name, "w");
  9228. + if (!data.stream) {
  9229. + ipkg_message(conf, IPKG_ERROR, "Could not open %s for writing: %s\n",
  9230. + list_file_name, strerror(errno));
  9231. + return errno;
  9232. + }
  9233. + data.pkg = pkg;
  9234. + data.conf = conf;
  9235. + hash_table_foreach(&conf->file_hash, pkg_write_filelist_helper, &data);
  9236. + fclose(data.stream);
  9237. + free(list_file_name);
  9238. +
  9239. + return err;
  9240. +}
  9241. +
  9242. +int pkg_write_changed_filelists(ipkg_conf_t *conf)
  9243. +{
  9244. + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
  9245. + hash_table_t *pkg_hash = &conf->pkg_hash;
  9246. + int i;
  9247. + int err;
  9248. + if (conf->noaction)
  9249. + return 0;
  9250. +
  9251. + ipkg_message(conf, IPKG_INFO, "%s: saving changed filelists\n", __FUNCTION__);
  9252. + pkg_hash_fetch_all_installed(pkg_hash, installed_pkgs);
  9253. + for (i = 0; i < installed_pkgs->len; i++) {
  9254. + pkg_t *pkg = installed_pkgs->pkgs[i];
  9255. + if (pkg->state_flag & SF_FILELIST_CHANGED) {
  9256. + ipkg_message(conf, IPKG_DEBUG, "Calling pkg_write_filelist for pkg=%s from %s\n", pkg->name, __FUNCTION__);
  9257. + err = pkg_write_filelist(conf, pkg);
  9258. + if (err)
  9259. + ipkg_message(conf, IPKG_NOTICE, "pkg_write_filelist pkg=%s returned %d\n", pkg->name, err);
  9260. + }
  9261. + }
  9262. + return 0;
  9263. +}
  9264. diff -Nur busybox-1.16.1.orig/archival/libipkg/pkg_depends.c busybox-1.16.1/archival/libipkg/pkg_depends.c
  9265. --- busybox-1.16.1.orig/archival/libipkg/pkg_depends.c 1970-01-01 01:00:00.000000000 +0100
  9266. +++ busybox-1.16.1/archival/libipkg/pkg_depends.c 2010-04-22 19:18:12.000000000 +0200
  9267. @@ -0,0 +1,1032 @@
  9268. +/* pkg_depends.c - the itsy package management system
  9269. +
  9270. + Steven M. Ayer
  9271. +
  9272. + Copyright (C) 2002 Compaq Computer Corporation
  9273. +
  9274. + This program is free software; you can redistribute it and/or
  9275. + modify it under the terms of the GNU General Public License as
  9276. + published by the Free Software Foundation; either version 2, or (at
  9277. + your option) any later version.
  9278. +
  9279. + This program is distributed in the hope that it will be useful, but
  9280. + WITHOUT ANY WARRANTY; without even the implied warranty of
  9281. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  9282. + General Public License for more details.
  9283. +*/
  9284. +
  9285. +#include "ipkg.h"
  9286. +#include <errno.h>
  9287. +#include <ctype.h>
  9288. +
  9289. +#include "pkg.h"
  9290. +#include "ipkg_utils.h"
  9291. +#include "pkg_hash.h"
  9292. +#include "ipkg_message.h"
  9293. +#include "pkg_parse.h"
  9294. +#include "hash_table.h"
  9295. +
  9296. +static int parseDepends(compound_depend_t *compound_depend, hash_table_t * hash, char * depend_str);
  9297. +static depend_t * depend_init(void);
  9298. +static void depend_deinit(depend_t *d);
  9299. +static char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx);
  9300. +static char ** merge_unresolved(char ** oldstuff, char ** newstuff);
  9301. +static int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg);
  9302. +int is_pkg_a_replaces(pkg_t *pkg_scout,pkg_t *pkg);
  9303. +
  9304. +static int pkg_installed_and_constraint_satisfied(pkg_t *pkg, void *cdata)
  9305. +{
  9306. + depend_t *depend = (depend_t *)cdata;
  9307. + if ((pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) && version_constraints_satisfied(depend, pkg))
  9308. + return 1;
  9309. + else
  9310. + return 0;
  9311. +}
  9312. +
  9313. +static int pkg_constraint_satisfied(pkg_t *pkg, void *cdata)
  9314. +{
  9315. + depend_t *depend = (depend_t *)cdata;
  9316. +#if 0
  9317. + pkg_t * temp = pkg_new();
  9318. + int comparison;
  9319. + parseVersion(temp, depend->version);
  9320. + comparison = pkg_compare_versions(pkg, temp);
  9321. + free(temp);
  9322. +
  9323. + fprintf(stderr, "%s: pkg=%s pkg->version=%s constraint=%p type=%d version=%s comparison=%d satisfied=%d\n",
  9324. + __FUNCTION__, pkg->name, pkg->version,
  9325. + depend, depend->constraint, depend->version,
  9326. + comparison, version_constraints_satisfied(depend, pkg));
  9327. +#endif
  9328. + if (version_constraints_satisfied(depend, pkg))
  9329. + return 1;
  9330. + else
  9331. + return 0;
  9332. +}
  9333. +
  9334. +/* returns ndependences or negative error value */
  9335. +int pkg_hash_fetch_unsatisfied_dependencies(ipkg_conf_t *conf, pkg_t * pkg,
  9336. + pkg_vec_t *unsatisfied, char *** unresolved)
  9337. +{
  9338. + pkg_t * satisfier_entry_pkg;
  9339. + register int i, j, k, l;
  9340. + int count, found;
  9341. + char ** the_lost;
  9342. + abstract_pkg_t * ab_pkg;
  9343. +
  9344. + /*
  9345. + * this is a setup to check for redundant/cyclic dependency checks,
  9346. + * which are marked at the abstract_pkg level
  9347. + */
  9348. + if (!(ab_pkg = pkg->parent)) {
  9349. + fprintf(stderr, "%s:%d: something terribly wrong with pkg %s\n", __FUNCTION__, __LINE__, pkg->name);
  9350. + *unresolved = NULL;
  9351. + return 0;
  9352. + }
  9353. + if (ab_pkg->dependencies_checked) { /* avoid duplicate or cyclic checks */
  9354. + *unresolved = NULL;
  9355. + return 0;
  9356. + } else {
  9357. + ab_pkg->dependencies_checked = 1; /* mark it for subsequent visits */
  9358. + }
  9359. + /**/
  9360. +
  9361. + count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count;
  9362. + if (!count){
  9363. + *unresolved = NULL;
  9364. + return 0;
  9365. + }
  9366. +
  9367. + the_lost = NULL;
  9368. +
  9369. + /* foreach dependency */
  9370. + for (i = 0; i < count; i++) {
  9371. + compound_depend_t * compound_depend = &pkg->depends[i];
  9372. + depend_t ** possible_satisfiers = compound_depend->possibilities;;
  9373. + found = 0;
  9374. + satisfier_entry_pkg = NULL;
  9375. +
  9376. + if (compound_depend->type == GREEDY_DEPEND) {
  9377. + /* foreach possible satisfier */
  9378. + for (j = 0; j < compound_depend->possibility_count; j++) {
  9379. + /* foreach provided_by, which includes the abstract_pkg itself */
  9380. + abstract_pkg_t *abpkg = possible_satisfiers[j]->pkg;
  9381. + abstract_pkg_vec_t *ab_provider_vec = abpkg->provided_by;
  9382. + int nposs = ab_provider_vec->len;
  9383. + abstract_pkg_t **ab_providers = ab_provider_vec->pkgs;
  9384. + for (l = 0; l < nposs; l++) {
  9385. + pkg_vec_t *test_vec = ab_providers[l]->pkgs;
  9386. + /* if no depends on this one, try the first package that Provides this one */
  9387. + if (!test_vec){ /* no pkg_vec hooked up to the abstract_pkg! (need another feed?) */
  9388. + continue;
  9389. + }
  9390. +
  9391. + /* cruise this possiblity's pkg_vec looking for an installed version */
  9392. + for (k = 0; k < test_vec->len; k++) {
  9393. + pkg_t *pkg_scout = test_vec->pkgs[k];
  9394. + /* not installed, and not already known about? */
  9395. + if ((pkg_scout->state_want != SW_INSTALL)
  9396. + && !pkg_scout->parent->dependencies_checked
  9397. + && !is_pkg_in_pkg_vec(unsatisfied, pkg_scout)) {
  9398. + char ** newstuff = NULL;
  9399. + int rc;
  9400. + pkg_vec_t *tmp_vec = pkg_vec_alloc ();
  9401. + /* check for not-already-installed dependencies */
  9402. + rc = pkg_hash_fetch_unsatisfied_dependencies(conf,
  9403. + pkg_scout,
  9404. + tmp_vec,
  9405. + &newstuff);
  9406. + if (newstuff == NULL) {
  9407. + int ok = 1;
  9408. + for (i = 0; i < rc; i++) {
  9409. + pkg_t *p = tmp_vec->pkgs[i];
  9410. + if (p->state_want == SW_INSTALL)
  9411. + continue;
  9412. + ipkg_message(conf, IPKG_DEBUG, "not installing %s due to requirement for %s\n", pkg_scout->name, p->name);
  9413. + ok = 0;
  9414. + break;
  9415. + }
  9416. + pkg_vec_free (tmp_vec);
  9417. + if (ok) {
  9418. + /* mark this one for installation */
  9419. + ipkg_message(conf, IPKG_NOTICE, "Adding satisfier for greedy dependence: %s\n", pkg_scout->name);
  9420. + pkg_vec_insert(unsatisfied, pkg_scout);
  9421. + }
  9422. + } else {
  9423. + ipkg_message(conf, IPKG_DEBUG, "not installing %s due to broken depends \n", pkg_scout->name);
  9424. + free (newstuff);
  9425. + }
  9426. + }
  9427. + }
  9428. + }
  9429. + }
  9430. +
  9431. + continue;
  9432. + }
  9433. +
  9434. + /* foreach possible satisfier, look for installed package */
  9435. + for (j = 0; j < compound_depend->possibility_count; j++) {
  9436. + /* foreach provided_by, which includes the abstract_pkg itself */
  9437. + depend_t *dependence_to_satisfy = possible_satisfiers[j];
  9438. + abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg;
  9439. + pkg_t *satisfying_pkg =
  9440. + pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg,
  9441. + pkg_installed_and_constraint_satisfied,
  9442. + dependence_to_satisfy, 1);
  9443. + /* Being that I can't test constraing in pkg_hash, I will test it here */
  9444. + if (satisfying_pkg != NULL) {
  9445. + if (!pkg_installed_and_constraint_satisfied ( satisfying_pkg,dependence_to_satisfy)) {
  9446. + satisfying_pkg = NULL;
  9447. + }
  9448. + }
  9449. + ipkg_message(conf, IPKG_DEBUG, "%s:%d: satisfying_pkg=%p \n", __FILE__, __LINE__, satisfying_pkg);
  9450. + if (satisfying_pkg != NULL) {
  9451. + found = 1;
  9452. + break;
  9453. + }
  9454. +
  9455. + }
  9456. + /* if nothing installed matches, then look for uninstalled satisfier */
  9457. + if (!found) {
  9458. + /* foreach possible satisfier, look for installed package */
  9459. + for (j = 0; j < compound_depend->possibility_count; j++) {
  9460. + /* foreach provided_by, which includes the abstract_pkg itself */
  9461. + depend_t *dependence_to_satisfy = possible_satisfiers[j];
  9462. + abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg;
  9463. + pkg_t *satisfying_pkg =
  9464. + pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg,
  9465. + pkg_constraint_satisfied,
  9466. + dependence_to_satisfy, 1);
  9467. + /* Being that I can't test constraing in pkg_hash, I will test it here too */
  9468. + if (satisfying_pkg != NULL) {
  9469. + if (!pkg_constraint_satisfied ( satisfying_pkg,dependence_to_satisfy)) {
  9470. + satisfying_pkg = NULL;
  9471. + }
  9472. + }
  9473. +
  9474. + /* user request overrides package recommendation */
  9475. + if (satisfying_pkg != NULL
  9476. + && (compound_depend->type == RECOMMEND || compound_depend->type == SUGGEST)
  9477. + && (satisfying_pkg->state_want == SW_DEINSTALL || satisfying_pkg->state_want == SW_PURGE)) {
  9478. + ipkg_message (conf, IPKG_NOTICE, "%s: ignoring recommendation for %s at user request\n",
  9479. + pkg->name, satisfying_pkg->name);
  9480. + continue;
  9481. + }
  9482. +
  9483. + ipkg_message(conf, IPKG_DEBUG, "%s:%d: satisfying_pkg=%p\n", __FILE__, __LINE__, satisfying_pkg);
  9484. + if (satisfying_pkg != NULL) {
  9485. + satisfier_entry_pkg = satisfying_pkg;
  9486. + break;
  9487. + }
  9488. + }
  9489. + }
  9490. +
  9491. + /* we didn't find one, add something to the unsatisfied vector */
  9492. + if (!found) {
  9493. + if (!satisfier_entry_pkg) {
  9494. + /* failure to meet recommendations is not an error */
  9495. + if (compound_depend->type != RECOMMEND && compound_depend->type != SUGGEST)
  9496. + the_lost = add_unresolved_dep(pkg, the_lost, i);
  9497. + else
  9498. + ipkg_message (conf, IPKG_NOTICE, "%s: unsatisfied recommendation for %s\n",
  9499. + pkg->name, compound_depend->possibilities[0]->pkg->name);
  9500. + }
  9501. + else {
  9502. + if (compound_depend->type == SUGGEST) {
  9503. + /* just mention it politely */
  9504. + ipkg_message (conf, IPKG_NOTICE, "package %s suggests installing %s\n",
  9505. + pkg->name, satisfier_entry_pkg->name);
  9506. + } else {
  9507. + char ** newstuff = NULL;
  9508. +
  9509. + if (satisfier_entry_pkg != pkg &&
  9510. + !is_pkg_in_pkg_vec(unsatisfied, satisfier_entry_pkg)) {
  9511. + pkg_vec_insert(unsatisfied, satisfier_entry_pkg);
  9512. + pkg_hash_fetch_unsatisfied_dependencies(conf,
  9513. + satisfier_entry_pkg,
  9514. + unsatisfied,
  9515. + &newstuff);
  9516. + the_lost = merge_unresolved(the_lost, newstuff);
  9517. + }
  9518. + }
  9519. + }
  9520. + }
  9521. + }
  9522. + *unresolved = the_lost;
  9523. +
  9524. + return unsatisfied->len;
  9525. +}
  9526. +
  9527. +/*checking for conflicts !in replaces
  9528. + If a packages conflicts with another but is also replacing it, I should not consider it a
  9529. + really conflicts
  9530. + returns 0 if conflicts <> replaces or 1 if conflicts == replaces
  9531. +*/
  9532. +int is_pkg_a_replaces(pkg_t *pkg_scout,pkg_t *pkg)
  9533. +{
  9534. + int i ;
  9535. + int replaces_count = pkg->replaces_count;
  9536. + abstract_pkg_t **replaces;
  9537. +
  9538. + if (pkg->replaces_count==0) // No replaces, it's surely a conflict
  9539. + return 0;
  9540. +
  9541. + replaces = pkg->replaces;
  9542. +
  9543. + for (i = 0; i < replaces_count; i++) {
  9544. + if (strcmp(pkg_scout->name,pkg->replaces[i]->name)==0) { // Found
  9545. + ipkg_message(NULL, IPKG_DEBUG2, "Seems I've found a replace %s %s \n",pkg_scout->name,pkg->replaces[i]->name);
  9546. + return 1;
  9547. + }
  9548. + }
  9549. + return 0;
  9550. +
  9551. +}
  9552. +
  9553. +
  9554. +/* Abhaya: added support for conflicts */
  9555. +pkg_vec_t * pkg_hash_fetch_conflicts(pkg_t * pkg)
  9556. +{
  9557. + pkg_vec_t * installed_conflicts, * test_vec;
  9558. + compound_depend_t * conflicts;
  9559. + depend_t ** possible_satisfiers;
  9560. + depend_t * possible_satisfier;
  9561. + register int i, j, k;
  9562. + int count;
  9563. + abstract_pkg_t * ab_pkg;
  9564. + pkg_t **pkg_scouts;
  9565. + pkg_t *pkg_scout;
  9566. +
  9567. + /*
  9568. + * this is a setup to check for redundant/cyclic dependency checks,
  9569. + * which are marked at the abstract_pkg level
  9570. + */
  9571. + if(!(ab_pkg = pkg->parent)){
  9572. + fprintf(stderr, "dependency check error. pkg %s isn't in hash table\n", pkg->name);
  9573. + return (pkg_vec_t *)NULL;
  9574. + }
  9575. +
  9576. + conflicts = pkg->conflicts;
  9577. + if(!conflicts){
  9578. + return (pkg_vec_t *)NULL;
  9579. + }
  9580. + installed_conflicts = pkg_vec_alloc();
  9581. +
  9582. + count = pkg->conflicts_count;
  9583. +
  9584. +
  9585. +
  9586. + /* foreach conflict */
  9587. + for(i = 0; i < pkg->conflicts_count; i++){
  9588. +
  9589. + possible_satisfiers = conflicts->possibilities;
  9590. +
  9591. + /* foreach possible satisfier */
  9592. + for(j = 0; j < conflicts->possibility_count; j++){
  9593. + possible_satisfier = possible_satisfiers[j];
  9594. + if (!possible_satisfier)
  9595. + fprintf(stderr, "%s:%d: possible_satisfier is null\n", __FUNCTION__, __LINE__);
  9596. + if (!possible_satisfier->pkg)
  9597. + fprintf(stderr, "%s:%d: possible_satisfier->pkg is null\n", __FUNCTION__, __LINE__);
  9598. + test_vec = possible_satisfier->pkg->pkgs;
  9599. + if (test_vec) {
  9600. + /* pkg_vec found, it is an actual package conflict
  9601. + * cruise this possiblity's pkg_vec looking for an installed version */
  9602. + pkg_scouts = test_vec->pkgs;
  9603. + for(k = 0; k < test_vec->len; k++){
  9604. + pkg_scout = pkg_scouts[k];
  9605. + if (!pkg_scout) {
  9606. + fprintf(stderr, "%s: null pkg scout\n", __FUNCTION__);
  9607. + continue;
  9608. + }
  9609. + if ((pkg_scout->state_status == SS_INSTALLED || pkg_scout->state_want == SW_INSTALL) &&
  9610. + version_constraints_satisfied(possible_satisfier, pkg_scout) && !is_pkg_a_replaces(pkg_scout,pkg)){
  9611. + if (!is_pkg_in_pkg_vec(installed_conflicts, pkg_scout)){
  9612. + pkg_vec_insert(installed_conflicts, pkg_scout);
  9613. + }
  9614. + }
  9615. + }
  9616. + }
  9617. + }
  9618. + conflicts++;
  9619. + }
  9620. +
  9621. + if (installed_conflicts->len)
  9622. + return installed_conflicts;
  9623. + pkg_vec_free(installed_conflicts);
  9624. + return (pkg_vec_t *)NULL;
  9625. +}
  9626. +
  9627. +int version_constraints_satisfied(depend_t * depends, pkg_t * pkg)
  9628. +{
  9629. + pkg_t * temp;
  9630. + int comparison;
  9631. +
  9632. + if(depends->constraint == NONE)
  9633. + return 1;
  9634. +
  9635. + temp = pkg_new();
  9636. +
  9637. + parseVersion(temp, depends->version);
  9638. +
  9639. + comparison = pkg_compare_versions(pkg, temp);
  9640. +
  9641. + free(temp);
  9642. +
  9643. + if((depends->constraint == EARLIER) &&
  9644. + (comparison < 0))
  9645. + return 1;
  9646. + else if((depends->constraint == LATER) &&
  9647. + (comparison > 0))
  9648. + return 1;
  9649. + else if(comparison == 0)
  9650. + return 1;
  9651. + else if((depends->constraint == LATER_EQUAL) &&
  9652. + (comparison >= 0))
  9653. + return 1;
  9654. + else if((depends->constraint == EARLIER_EQUAL) &&
  9655. + (comparison <= 0))
  9656. + return 1;
  9657. +
  9658. + return 0;
  9659. +}
  9660. +
  9661. +int pkg_dependence_satisfiable(depend_t *depend)
  9662. +{
  9663. + abstract_pkg_t *apkg = depend->pkg;
  9664. + abstract_pkg_vec_t *provider_apkgs = apkg->provided_by;
  9665. + int n_providers = provider_apkgs->len;
  9666. + abstract_pkg_t **apkgs = provider_apkgs->pkgs;
  9667. + pkg_vec_t *pkg_vec;
  9668. + int n_pkgs ;
  9669. + int i;
  9670. + int j;
  9671. +
  9672. + for (i = 0; i < n_providers; i++) {
  9673. + abstract_pkg_t *papkg = apkgs[i];
  9674. + pkg_vec = papkg->pkgs;
  9675. + if (pkg_vec) {
  9676. + n_pkgs = pkg_vec->len;
  9677. + for (j = 0; j < n_pkgs; j++) {
  9678. + pkg_t *pkg = pkg_vec->pkgs[j];
  9679. + if (version_constraints_satisfied(depend, pkg)) {
  9680. + return 1;
  9681. + }
  9682. + }
  9683. + }
  9684. + }
  9685. + return 0;
  9686. +}
  9687. +
  9688. +int pkg_dependence_satisfied(depend_t *depend)
  9689. +{
  9690. + abstract_pkg_t *apkg = depend->pkg;
  9691. + abstract_pkg_vec_t *provider_apkgs = apkg->provided_by;
  9692. + int n_providers = provider_apkgs->len;
  9693. + abstract_pkg_t **apkgs = provider_apkgs->pkgs;
  9694. + int i;
  9695. + int n_pkgs;
  9696. + int j;
  9697. +
  9698. + for (i = 0; i < n_providers; i++) {
  9699. + abstract_pkg_t *papkg = apkgs[i];
  9700. + pkg_vec_t *pkg_vec = papkg->pkgs;
  9701. + if (pkg_vec) {
  9702. + n_pkgs = pkg_vec->len;
  9703. + for (j = 0; j < n_pkgs; j++) {
  9704. + pkg_t *pkg = pkg_vec->pkgs[j];
  9705. + if (version_constraints_satisfied(depend, pkg)) {
  9706. + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED)
  9707. + return 1;
  9708. + }
  9709. + }
  9710. + }
  9711. + }
  9712. + return 0;
  9713. +}
  9714. +
  9715. +static int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg)
  9716. +{
  9717. + register int i;
  9718. + pkg_t ** pkgs = vec->pkgs;
  9719. +
  9720. + for(i = 0; i < vec->len; i++)
  9721. + if((strcmp(pkg->name, (*(pkgs + i))->name) == 0)
  9722. + && (pkg_compare_versions(pkg, *(pkgs + i)) == 0)
  9723. + && (strcmp(pkg->architecture, (*(pkgs + i))->architecture) == 0))
  9724. + return 1;
  9725. + return 0;
  9726. +}
  9727. +
  9728. +
  9729. +#ifdef DeadCode
  9730. +/**
  9731. + * pkg_has_common_provides returns 1 if pkg and replacee both provide
  9732. + * the same abstract package and 0 otherwise.
  9733. + */
  9734. +int pkg_has_common_provides(pkg_t *pkg, pkg_t *replacee)
  9735. +{
  9736. + abstract_pkg_t **provides = pkg->provides;
  9737. + int provides_count = pkg->provides_count;
  9738. + abstract_pkg_t **replacee_provides = replacee->provides;
  9739. + int replacee_provides_count = replacee->provides_count;
  9740. + int i, j;
  9741. + for (i = 0; i < provides_count; i++) {
  9742. + abstract_pkg_t *apkg = provides[i];
  9743. + for (j = 0; j < replacee_provides_count; j++) {
  9744. + abstract_pkg_t *replacee_apkg = replacee_provides[i];
  9745. + if (apkg == replacee_apkg)
  9746. + return 1;
  9747. + }
  9748. + }
  9749. + return 0;
  9750. +}
  9751. +#endif
  9752. +
  9753. +/**
  9754. + * pkg_provides_abstract returns 1 if pkg->provides contains providee
  9755. + * and 0 otherwise.
  9756. + */
  9757. +int pkg_provides_abstract(pkg_t *pkg, abstract_pkg_t *providee)
  9758. +{
  9759. + abstract_pkg_t **provides = pkg->provides;
  9760. + int provides_count = pkg->provides_count;
  9761. + int i;
  9762. + for (i = 0; i < provides_count; i++) {
  9763. + if (provides[i] == providee)
  9764. + return 1;
  9765. + }
  9766. + return 0;
  9767. +}
  9768. +
  9769. +/**
  9770. + * pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0
  9771. + * otherwise.
  9772. + */
  9773. +int pkg_replaces(pkg_t *pkg, pkg_t *replacee)
  9774. +{
  9775. + abstract_pkg_t **replaces = pkg->replaces;
  9776. + int replaces_count = pkg->replaces_count;
  9777. + /* abstract_pkg_t **replacee_provides = pkg->provides;
  9778. + int replacee_provides_count = pkg->provides_count; */
  9779. + int i, j;
  9780. + for (i = 0; i < replaces_count; i++) {
  9781. + abstract_pkg_t *abstract_replacee = replaces[i];
  9782. + for (j = 0; j < replaces_count; j++) {
  9783. + /* ipkg_message(NULL, IPKG_DEBUG2, "Searching pkg-name %s repprovname %s absrepname %s \n",
  9784. + pkg->name,replacee->provides[j]->name, abstract_replacee->name); */
  9785. + if (replacee->provides[j] == abstract_replacee)
  9786. + return 1;
  9787. + }
  9788. + }
  9789. + return 0;
  9790. +}
  9791. +
  9792. +
  9793. +/**
  9794. + * pkg_conflicts_abstract returns 1 if pkg->conflicts contains conflictee and 0
  9795. + * otherwise.
  9796. + */
  9797. +int pkg_conflicts_abstract(pkg_t *pkg, abstract_pkg_t *conflictee)
  9798. +{
  9799. + compound_depend_t *conflicts = pkg->conflicts;
  9800. + int conflicts_count = pkg->conflicts_count;
  9801. + int i, j;
  9802. + for (i = 0; i < conflicts_count; i++) {
  9803. + int possibility_count = conflicts[i].possibility_count;
  9804. + struct depend **possibilities = conflicts[i].possibilities;
  9805. + for (j = 0; j < possibility_count; j++) {
  9806. + if (possibilities[j]->pkg == conflictee) {
  9807. + return 1;
  9808. + }
  9809. + }
  9810. + }
  9811. + return 0;
  9812. +}
  9813. +
  9814. +/**
  9815. + * pkg_conflicts returns 1 if pkg->conflicts contains one of
  9816. + * conflictee's provides and 0 otherwise.
  9817. + */
  9818. +int pkg_conflicts(pkg_t *pkg, pkg_t *conflictee)
  9819. +{
  9820. + compound_depend_t *conflicts = pkg->conflicts;
  9821. + int conflicts_count = pkg->conflicts_count;
  9822. + abstract_pkg_t **conflictee_provides = conflictee->provides;
  9823. + int conflictee_provides_count = conflictee->provides_count;
  9824. + int i, j, k;
  9825. + int possibility_count;
  9826. + struct depend **possibilities;
  9827. + abstract_pkg_t *possibility ;
  9828. +
  9829. + for (i = 0; i < conflicts_count; i++) {
  9830. + possibility_count = conflicts[i].possibility_count;
  9831. + possibilities = conflicts[i].possibilities;
  9832. + for (j = 0; j < possibility_count; j++) {
  9833. + possibility = possibilities[j]->pkg;
  9834. + for (k = 0; k < conflictee_provides_count; k++) {
  9835. + if (possibility == conflictee_provides[k]) {
  9836. + return 1;
  9837. + }
  9838. + }
  9839. + }
  9840. + }
  9841. + return 0;
  9842. +}
  9843. +
  9844. +static char ** merge_unresolved(char ** oldstuff, char ** newstuff)
  9845. +{
  9846. + int oldlen = 0, newlen = 0;
  9847. + char ** result;
  9848. + register int i, j;
  9849. +
  9850. + if(!newstuff)
  9851. + return oldstuff;
  9852. +
  9853. + while(oldstuff && oldstuff[oldlen]) oldlen++;
  9854. + while(newstuff && newstuff[newlen]) newlen++;
  9855. +
  9856. + result = (char **)realloc(oldstuff, sizeof(char *) * (oldlen + newlen + 1));
  9857. + if (result == NULL) {
  9858. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  9859. + return NULL;
  9860. + }
  9861. +
  9862. + for(i = oldlen, j = 0; i < (oldlen + newlen); i++, j++)
  9863. + *(result + i) = *(newstuff + j);
  9864. +
  9865. + *(result + i) = NULL;
  9866. +
  9867. + return result;
  9868. +}
  9869. +
  9870. +/*
  9871. + * a kinda kludgy way to back out depends str from two different arrays (reg'l'r 'n pre)
  9872. + * this is null terminated, no count is carried around
  9873. + */
  9874. +char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx)
  9875. +{
  9876. + int count;
  9877. + char ** resized;
  9878. + char *depend_str = pkg_depend_str(pkg, ref_ndx);
  9879. +
  9880. + count = 0;
  9881. + while(the_lost && the_lost[count]) count++;
  9882. +
  9883. + count++; /* need one to hold the null */
  9884. + resized = (char **)realloc(the_lost, sizeof(char *) * (count + 1));
  9885. + if (resized == NULL) {
  9886. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  9887. + return NULL;
  9888. + }
  9889. + resized[count - 1] = strdup(depend_str);
  9890. + resized[count] = NULL;
  9891. +
  9892. + return resized;
  9893. +}
  9894. +
  9895. +void printDepends(pkg_t * pkg)
  9896. +{
  9897. + register int i, j;
  9898. + compound_depend_t * depend;
  9899. + int count;
  9900. +
  9901. + count = pkg->pre_depends_count + pkg->depends_count;
  9902. +
  9903. + depend = pkg->depends;
  9904. + if(!depend){
  9905. + fprintf(stderr, "Depends pointer is NULL\n");
  9906. + return;
  9907. + }
  9908. + for(i = 0; i < count; i++){
  9909. + fprintf(stderr, "%s has %d possibilities:\n",
  9910. + (depend->type == GREEDY_DEPEND) ? "Greedy-Depend" : ((depend->type == DEPEND) ? "Depend" : "Pre-Depend"),
  9911. + depend->possibility_count);
  9912. + for(j = 0; j < depend->possibility_count; j++)
  9913. + fprintf(stderr, "\t%s version %s (%d)\n",
  9914. + depend->possibilities[j]->pkg->name,
  9915. + depend->possibilities[j]->version,
  9916. + depend->possibilities[j]->constraint);
  9917. + depend++;
  9918. + }
  9919. +}
  9920. +
  9921. +int buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
  9922. +{
  9923. + register int i, j;
  9924. +
  9925. + /* every pkg provides itself */
  9926. + abstract_pkg_vec_insert(ab_pkg->provided_by, ab_pkg);
  9927. +
  9928. + if (!pkg->provides_count)
  9929. + return 0;
  9930. +
  9931. + pkg->provides = (abstract_pkg_t **)malloc(sizeof(abstract_pkg_t *) * (pkg->provides_count + 1));
  9932. + if (pkg->provides == NULL) {
  9933. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  9934. + return -1 ;
  9935. + }
  9936. + pkg->provides[0] = ab_pkg;
  9937. +
  9938. + // if (strcmp(ab_pkg->name, pkg->name))
  9939. + // fprintf(stderr, __FUNCTION__ ": ab_pkg=%s pkg=%s\n", ab_pkg->name, pkg->name);
  9940. +
  9941. + for(i = 0; i < pkg->provides_count; i++){
  9942. + abstract_pkg_t *provided_abpkg = ensure_abstract_pkg_by_name(hash, pkg->provides_str[i]);
  9943. +
  9944. + pkg->provides[i+1] = provided_abpkg;
  9945. +
  9946. + j = 0;
  9947. + abstract_pkg_vec_insert(provided_abpkg->provided_by, ab_pkg);
  9948. + }
  9949. + return 0;
  9950. +}
  9951. +
  9952. +/* Abhaya: added conflicts support */
  9953. +int buildConflicts(hash_table_t * hash, pkg_t * pkg)
  9954. +{
  9955. + register int i;
  9956. + compound_depend_t * conflicts;
  9957. +
  9958. + if (!pkg->conflicts_count)
  9959. + return 0;
  9960. +
  9961. + conflicts = pkg->conflicts = malloc(sizeof(compound_depend_t) *
  9962. + pkg->conflicts_count);
  9963. + if (conflicts == NULL) {
  9964. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  9965. + return -1;
  9966. + }
  9967. + for (i = 0; i < pkg->conflicts_count; i++) {
  9968. + conflicts->type = CONFLICTS;
  9969. + parseDepends(conflicts, hash,
  9970. + pkg->conflicts_str[i]);
  9971. +#if 0
  9972. + for (j = 0; j < conflicts->possibility_count; j++) {
  9973. + depend_t *possibility = conflicts->possibilities[j];
  9974. + abstract_pkg_t *conflicting_apkg = possibility->pkg;
  9975. + pkg_add_conflict_pair(ab_pkg, conflicting_apkg);
  9976. + }
  9977. +#endif
  9978. + conflicts++;
  9979. + }
  9980. + return 0;
  9981. +}
  9982. +
  9983. +int buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
  9984. +{
  9985. + register int i, j;
  9986. +
  9987. + if (!pkg->replaces_count)
  9988. + return 0;
  9989. +
  9990. + pkg->replaces = (abstract_pkg_t **)malloc(sizeof(abstract_pkg_t *) * pkg->replaces_count);
  9991. + if (pkg->replaces == NULL) {
  9992. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  9993. + return -1;
  9994. + }
  9995. +
  9996. + // if (strcmp(ab_pkg->name, pkg->name))
  9997. + // fprintf(stderr, __FUNCTION__ ": ab_pkg=%s pkg=%s\n", ab_pkg->name, pkg->name);
  9998. +
  9999. + for(i = 0; i < pkg->replaces_count; i++){
  10000. + abstract_pkg_t *old_abpkg = ensure_abstract_pkg_by_name(hash, pkg->replaces_str[i]);
  10001. +
  10002. + pkg->replaces[i] = old_abpkg;
  10003. +
  10004. + j = 0;
  10005. + if (!old_abpkg->replaced_by)
  10006. + old_abpkg->replaced_by = abstract_pkg_vec_alloc();
  10007. + if ( old_abpkg->replaced_by == NULL ){
  10008. + return -1;
  10009. + }
  10010. + /* if a package pkg both replaces and conflicts old_abpkg,
  10011. + * then add it to the replaced_by vector so that old_abpkg
  10012. + * will be upgraded to ab_pkg automatically */
  10013. + if (pkg_conflicts_abstract(pkg, old_abpkg))
  10014. + abstract_pkg_vec_insert(old_abpkg->replaced_by, ab_pkg);
  10015. + }
  10016. + return 0;
  10017. +}
  10018. +
  10019. +int buildDepends(hash_table_t * hash, pkg_t * pkg)
  10020. +{
  10021. + int count;
  10022. + register int i;
  10023. + compound_depend_t * depends;
  10024. +
  10025. + if(!(count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count))
  10026. + return 0;
  10027. +
  10028. + if (0 && pkg->pre_depends_count)
  10029. + fprintf(stderr, "pkg=%s pre_depends_count=%d depends_count=%d\n",
  10030. + pkg->name, pkg->pre_depends_count, pkg->depends_count);
  10031. + depends = pkg->depends = malloc(sizeof(compound_depend_t) * count);
  10032. + if (depends == NULL) {
  10033. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10034. + return -1;
  10035. + }
  10036. +
  10037. +
  10038. + for(i = 0; i < pkg->pre_depends_count; i++){
  10039. + parseDepends(depends, hash, pkg->pre_depends_str[i]);
  10040. + if (0 && pkg->pre_depends_count)
  10041. + fprintf(stderr, " pre_depends_str=%s depends=%p possibility_count=%x\n",
  10042. + pkg->pre_depends_str[i], depends, depends->possibility_count);
  10043. + depends->type = PREDEPEND;
  10044. + depends++;
  10045. + }
  10046. +
  10047. + for(i = 0; i < pkg->recommends_count; i++){
  10048. + parseDepends(depends, hash, pkg->recommends_str[i]);
  10049. + if (0 && pkg->recommends_count)
  10050. + fprintf(stderr, " recommends_str=%s depends=%p possibility_count=%x\n",
  10051. + pkg->recommends_str[i], depends, depends->possibility_count);
  10052. + depends->type = RECOMMEND;
  10053. + depends++;
  10054. + }
  10055. +
  10056. + for(i = 0; i < pkg->suggests_count; i++){
  10057. + parseDepends(depends, hash, pkg->suggests_str[i]);
  10058. + if (0 && pkg->suggests_count)
  10059. + fprintf(stderr, " suggests_str=%s depends=%p possibility_count=%x\n",
  10060. + pkg->suggests_str[i], depends, depends->possibility_count);
  10061. + depends->type = SUGGEST;
  10062. + depends++;
  10063. + }
  10064. +
  10065. + for(i = 0; i < pkg->depends_count; i++){
  10066. + parseDepends(depends, hash, pkg->depends_str[i]);
  10067. + if (0 && pkg->depends_count)
  10068. + fprintf(stderr, " depends_str=%s depends=%p possibility_count=%x\n",
  10069. + pkg->depends_str[i], depends, depends->possibility_count);
  10070. + depends++;
  10071. + }
  10072. + return 0;
  10073. +}
  10074. +
  10075. +/*
  10076. + * pkg_depend_string: returns the depends string specified by index_.
  10077. + * All 4 kinds of dependences: dependence, pre-dependence, recommend, and suggest are number starting from 0.
  10078. + * [0,npredepends) -> returns pre_depends_str[index_]
  10079. + * [npredepends,npredepends+nrecommends) -> returns recommends_str[index_]
  10080. + * [npredepends+nrecommends,npredepends+nrecommends+nsuggests) -> returns recommends_str[index_]
  10081. + * [npredepends+nrecommends+nsuggests,npredepends+nrecommends+nsuggests+ndepends) -> returns depends_str[index_]
  10082. + */
  10083. +char *pkg_depend_str(pkg_t *pkg, int index_)
  10084. +{
  10085. + if (index_ < pkg->pre_depends_count) {
  10086. + return pkg->pre_depends_str[index_];
  10087. + }
  10088. + index_ -= pkg->pre_depends_count;
  10089. +
  10090. + if (index_ < pkg->recommends_count) {
  10091. + return pkg->recommends_str[index_];
  10092. + }
  10093. + index_ -= pkg->recommends_count;
  10094. +
  10095. + if (index_ < pkg->suggests_count) {
  10096. + return pkg->suggests_str[index_];
  10097. + }
  10098. + index_ -= pkg->suggests_count;
  10099. +
  10100. + if (index_ < pkg->depends_count) {
  10101. + return pkg->depends_str[index_];
  10102. + }
  10103. + fprintf(stderr, "pkg_depend_str: index_ %d out of range for pkg=%s\n", index_, pkg->name);
  10104. + return NULL;
  10105. +}
  10106. +
  10107. +void freeDepends(pkg_t *pkg)
  10108. +{
  10109. + int i;
  10110. +
  10111. + if (pkg == NULL || pkg->depends == NULL) {
  10112. + return;
  10113. + }
  10114. +
  10115. + fprintf(stderr, "Freeing depends=%p\n", pkg->depends);
  10116. + for (i=0; i < pkg->depends->possibility_count; i++) {
  10117. + depend_deinit(pkg->depends->possibilities[i]);
  10118. + }
  10119. + free(pkg->depends->possibilities);
  10120. + free(pkg->depends);
  10121. + pkg->depends = NULL;
  10122. +}
  10123. +
  10124. +void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg)
  10125. +{
  10126. + compound_depend_t * depends;
  10127. + int count, othercount;
  10128. + register int i, j;
  10129. + abstract_pkg_t * ab_depend;
  10130. + abstract_pkg_t ** temp;
  10131. +
  10132. + count = pkg->pre_depends_count + pkg->depends_count;
  10133. + depends = pkg->depends;
  10134. +
  10135. + if (0 && pkg->pre_depends_count)
  10136. + fprintf(stderr, "pkg=%s pre_depends_count=%d depends_count=%d\n",
  10137. + pkg->name, pkg->pre_depends_count, pkg->depends_count);
  10138. + for (i = 0; i < count; i++) {
  10139. + if (0 && pkg->pre_depends_count)
  10140. + fprintf(stderr, " i=%d possibility_count=%x depends=%p\n", i, depends->possibility_count, depends);
  10141. + for (j = 0; j < depends->possibility_count; j++){
  10142. + ab_depend = depends->possibilities[j]->pkg;
  10143. + if(!ab_depend->depended_upon_by)
  10144. + ab_depend->depended_upon_by = (abstract_pkg_t **)calloc(1, sizeof(abstract_pkg_t *));
  10145. +
  10146. + temp = ab_depend->depended_upon_by;
  10147. + othercount = 1;
  10148. + while(*temp){
  10149. + temp++;
  10150. + othercount++;
  10151. + }
  10152. + *temp = ab_pkg;
  10153. +
  10154. + ab_depend->depended_upon_by = (abstract_pkg_t **)realloc(ab_depend->depended_upon_by,
  10155. + (othercount + 1) * sizeof(abstract_pkg_t *));
  10156. + /* the array may have moved */
  10157. + temp = ab_depend->depended_upon_by + othercount;
  10158. + *temp = NULL;
  10159. + }
  10160. + depends++;
  10161. + }
  10162. +}
  10163. +
  10164. +static depend_t * depend_init(void)
  10165. +{
  10166. + depend_t * d = (depend_t *)malloc(sizeof(depend_t));
  10167. + if ( d==NULL ){
  10168. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10169. + return NULL;
  10170. + }
  10171. + d->constraint = NONE;
  10172. + d->version = NULL;
  10173. + d->pkg = NULL;
  10174. +
  10175. + return d;
  10176. +}
  10177. +
  10178. +static void depend_deinit(depend_t *d)
  10179. +{
  10180. + free(d);
  10181. +}
  10182. +
  10183. +static int parseDepends(compound_depend_t *compound_depend,
  10184. + hash_table_t * hash, char * depend_str)
  10185. +{
  10186. + char * pkg_name, buffer[2048];
  10187. + int num_of_ors = 0;
  10188. + register int i;
  10189. + register char * src, * dest;
  10190. + depend_t ** possibilities;
  10191. +
  10192. + /* first count the number of ored possibilities for satisfying dependency */
  10193. + src = depend_str;
  10194. + while(*src)
  10195. + if(*src++ == '|')
  10196. + num_of_ors++;
  10197. +
  10198. + compound_depend->type = DEPEND;
  10199. +
  10200. + compound_depend->possibility_count = num_of_ors + 1;
  10201. + possibilities = (depend_t **)malloc(sizeof(depend_t *) * (num_of_ors + 1));
  10202. + if (!possibilities)
  10203. + return -ENOMEM;
  10204. + compound_depend->possibilities = possibilities;
  10205. +
  10206. + src = depend_str;
  10207. + for(i = 0; i < num_of_ors + 1; i++){
  10208. + possibilities[i] = depend_init();
  10209. + if (!possibilities[i])
  10210. + return -ENOMEM;
  10211. + /* gobble up just the name first */
  10212. + dest = buffer;
  10213. + while(*src &&
  10214. + !isspace(*src) &&
  10215. + (*src != '(') &&
  10216. + (*src != '*') &&
  10217. + (*src != '|'))
  10218. + *dest++ = *src++;
  10219. + *dest = '\0';
  10220. + pkg_name = trim_alloc(buffer);
  10221. + if (pkg_name == NULL )
  10222. + return -ENOMEM;
  10223. +
  10224. + /* now look at possible version info */
  10225. +
  10226. + /* skip to next chars */
  10227. + if(isspace(*src))
  10228. + while(*src && isspace(*src)) src++;
  10229. +
  10230. + /* extract constraint and version */
  10231. + if(*src == '('){
  10232. + src++;
  10233. + if(!strncmp(src, "<<", 2)){
  10234. + possibilities[i]->constraint = EARLIER;
  10235. + src += 2;
  10236. + }
  10237. + else if(!strncmp(src, "<=", 2)){
  10238. + possibilities[i]->constraint = EARLIER_EQUAL;
  10239. + src += 2;
  10240. + }
  10241. + else if(!strncmp(src, ">=", 2)){
  10242. + possibilities[i]->constraint = LATER_EQUAL;
  10243. + src += 2;
  10244. + }
  10245. + else if(!strncmp(src, ">>", 2)){
  10246. + possibilities[i]->constraint = LATER;
  10247. + src += 2;
  10248. + }
  10249. + else if(!strncmp(src, "=", 1)){
  10250. + possibilities[i]->constraint = EQUAL;
  10251. + src++;
  10252. + }
  10253. + /* should these be here to support deprecated designations; dpkg does */
  10254. + else if(!strncmp(src, "<", 1)){
  10255. + possibilities[i]->constraint = EARLIER_EQUAL;
  10256. + src++;
  10257. + }
  10258. + else if(!strncmp(src, ">", 1)){
  10259. + possibilities[i]->constraint = LATER_EQUAL;
  10260. + src++;
  10261. + }
  10262. +
  10263. + /* now we have any constraint, pass space to version string */
  10264. + while(isspace(*src)) src++;
  10265. +
  10266. + /* this would be the version string */
  10267. + dest = buffer;
  10268. + while(*src && *src != ')')
  10269. + *dest++ = *src++;
  10270. + *dest = '\0';
  10271. +
  10272. + possibilities[i]->version = trim_alloc(buffer);
  10273. + /* fprintf(stderr, "let's print the depends version string:");
  10274. + fprintf(stderr, "version %s\n", possibilities[i]->version);*/
  10275. + if (possibilities[i]->version == NULL )
  10276. + return -ENOMEM;
  10277. +
  10278. +
  10279. + }
  10280. + /* hook up the dependency to its abstract pkg */
  10281. + possibilities[i]->pkg = ensure_abstract_pkg_by_name(hash, pkg_name);
  10282. +
  10283. + free(pkg_name);
  10284. +
  10285. + /* now get past the ) and any possible | chars */
  10286. + while(*src &&
  10287. + (isspace(*src) ||
  10288. + (*src == ')') ||
  10289. + (*src == '|')))
  10290. + src++;
  10291. + if (*src == '*')
  10292. + {
  10293. + compound_depend->type = GREEDY_DEPEND;
  10294. + src++;
  10295. + }
  10296. + }
  10297. +
  10298. + return 0;
  10299. +}
  10300. diff -Nur busybox-1.16.1.orig/archival/libipkg/pkg_depends.h busybox-1.16.1/archival/libipkg/pkg_depends.h
  10301. --- busybox-1.16.1.orig/archival/libipkg/pkg_depends.h 1970-01-01 01:00:00.000000000 +0100
  10302. +++ busybox-1.16.1/archival/libipkg/pkg_depends.h 2010-04-22 19:18:12.000000000 +0200
  10303. @@ -0,0 +1,105 @@
  10304. +/* pkg_depends.h - the itsy package management system
  10305. +
  10306. + Steven M. Ayer
  10307. +
  10308. + Copyright (C) 2002 Compaq Computer Corporation
  10309. +
  10310. + This program is free software; you can redistribute it and/or
  10311. + modify it under the terms of the GNU General Public License as
  10312. + published by the Free Software Foundation; either version 2, or (at
  10313. + your option) any later version.
  10314. +
  10315. + This program is distributed in the hope that it will be useful, but
  10316. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10317. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10318. + General Public License for more details.
  10319. +*/
  10320. +
  10321. +#ifndef PKG_DEPENDS_H
  10322. +#define PKG_DEPENDS_H
  10323. +
  10324. +#include "pkg.h"
  10325. +#include "pkg_hash.h"
  10326. +
  10327. +enum depend_type {
  10328. + PREDEPEND,
  10329. + DEPEND,
  10330. + CONFLICTS,
  10331. + GREEDY_DEPEND,
  10332. + RECOMMEND,
  10333. + SUGGEST
  10334. +};
  10335. +typedef enum depend_type depend_type_t;
  10336. +
  10337. +enum version_constraint {
  10338. + NONE,
  10339. + EARLIER,
  10340. + EARLIER_EQUAL,
  10341. + EQUAL,
  10342. + LATER_EQUAL,
  10343. + LATER
  10344. +};
  10345. +typedef enum version_constraint version_constraint_t;
  10346. +
  10347. +struct depend{
  10348. + version_constraint_t constraint;
  10349. + char * version;
  10350. + abstract_pkg_t * pkg;
  10351. +};
  10352. +typedef struct depend depend_t;
  10353. +
  10354. +struct compound_depend{
  10355. + depend_type_t type;
  10356. + int possibility_count;
  10357. + struct depend ** possibilities;
  10358. +};
  10359. +typedef struct compound_depend compound_depend_t;
  10360. +
  10361. +#include "hash_table.h"
  10362. +
  10363. +int buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
  10364. +int buildConflicts(hash_table_t * hash, pkg_t * pkg);
  10365. +int buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
  10366. +int buildDepends(hash_table_t * hash, pkg_t * pkg);
  10367. +
  10368. +/**
  10369. + * pkg_has_common_provides returns 1 if pkg and replacee both provide
  10370. + * the same abstract package and 0 otherwise.
  10371. + */
  10372. +int pkg_has_common_provides(pkg_t *pkg, pkg_t *replacee);
  10373. +
  10374. +/**
  10375. + * pkg_provides returns 1 if pkg->provides contains providee and 0
  10376. + * otherwise.
  10377. + */
  10378. +int pkg_provides_abstract(pkg_t *pkg, abstract_pkg_t *providee);
  10379. +
  10380. +/**
  10381. + * pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0
  10382. + * otherwise.
  10383. + */
  10384. +int pkg_replaces(pkg_t *pkg, pkg_t *replacee);
  10385. +
  10386. +/**
  10387. + * pkg_conflicts_abstract returns 1 if pkg->conflicts contains conflictee provides and 0
  10388. + * otherwise.
  10389. + */
  10390. +int pkg_conflicts_abstract(pkg_t *pkg, abstract_pkg_t *conflicts);
  10391. +
  10392. +/**
  10393. + * pkg_conflicts returns 1 if pkg->conflicts contains one of conflictee's provides and 0
  10394. + * otherwise.
  10395. + */
  10396. +int pkg_conflicts(pkg_t *pkg, pkg_t *conflicts);
  10397. +
  10398. +char *pkg_depend_str(pkg_t *pkg, int index_);
  10399. +void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg);
  10400. +void freeDepends(pkg_t *pkg);
  10401. +void printDepends(pkg_t * pkg);
  10402. +int version_constraints_satisfied(depend_t * depends, pkg_t * pkg);
  10403. +int pkg_hash_fetch_unsatisfied_dependencies(ipkg_conf_t *conf, pkg_t * pkg, pkg_vec_t *depends, char *** unresolved);
  10404. +pkg_vec_t * pkg_hash_fetch_conflicts(pkg_t * pkg);
  10405. +int pkg_dependence_satisfiable(depend_t *depend);
  10406. +int pkg_dependence_satisfied(depend_t *depend);
  10407. +
  10408. +#endif
  10409. diff -Nur busybox-1.16.1.orig/archival/libipkg/pkg_dest.c busybox-1.16.1/archival/libipkg/pkg_dest.c
  10410. --- busybox-1.16.1.orig/archival/libipkg/pkg_dest.c 1970-01-01 01:00:00.000000000 +0100
  10411. +++ busybox-1.16.1/archival/libipkg/pkg_dest.c 2010-04-22 19:18:12.000000000 +0200
  10412. @@ -0,0 +1,92 @@
  10413. +/* pkg_dest.c - the itsy package management system
  10414. +
  10415. + Carl D. Worth
  10416. +
  10417. + Copyright (C) 2001 University of Southern California
  10418. +
  10419. + This program is free software; you can redistribute it and/or
  10420. + modify it under the terms of the GNU General Public License as
  10421. + published by the Free Software Foundation; either version 2, or (at
  10422. + your option) any later version.
  10423. +
  10424. + This program is distributed in the hope that it will be useful, but
  10425. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10426. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10427. + General Public License for more details.
  10428. +*/
  10429. +
  10430. +#include "ipkg.h"
  10431. +
  10432. +#include "pkg_dest.h"
  10433. +#include "file_util.h"
  10434. +#include "str_util.h"
  10435. +#include "sprintf_alloc.h"
  10436. +
  10437. +int pkg_dest_init(pkg_dest_t *dest, const char *name, const char *root_dir,const char * lists_dir)
  10438. +{
  10439. + dest->name = strdup(name);
  10440. +
  10441. + /* Guarantee that dest->root_dir ends with a '/' */
  10442. + if (str_ends_with(root_dir, "/")) {
  10443. + dest->root_dir = strdup(root_dir);
  10444. + } else {
  10445. + sprintf_alloc(&dest->root_dir, "%s/", root_dir);
  10446. + }
  10447. + file_mkdir_hier(dest->root_dir, 0755);
  10448. +
  10449. + sprintf_alloc(&dest->ipkg_dir, "%s%s",
  10450. + dest->root_dir, IPKG_STATE_DIR_PREFIX);
  10451. + file_mkdir_hier(dest->ipkg_dir, 0755);
  10452. +
  10453. + if (str_starts_with (lists_dir, "/"))
  10454. + sprintf_alloc(&dest->lists_dir, "%s", lists_dir);
  10455. + else
  10456. + sprintf_alloc(&dest->lists_dir, "/%s", lists_dir);
  10457. +
  10458. + file_mkdir_hier(dest->lists_dir, 0755);
  10459. +
  10460. + sprintf_alloc(&dest->info_dir, "%s/%s",
  10461. + dest->ipkg_dir, IPKG_INFO_DIR_SUFFIX);
  10462. + file_mkdir_hier(dest->info_dir, 0755);
  10463. +
  10464. + sprintf_alloc(&dest->status_file_name, "%s/%s",
  10465. + dest->ipkg_dir, IPKG_STATUS_FILE_SUFFIX);
  10466. +
  10467. + sprintf_alloc(&dest->status_file_tmp_name, "%s/%s.tmp",
  10468. + dest->ipkg_dir, IPKG_STATUS_FILE_SUFFIX);
  10469. +
  10470. + dest->status_file = NULL;
  10471. +
  10472. + return 0;
  10473. +}
  10474. +
  10475. +void pkg_dest_deinit(pkg_dest_t *dest)
  10476. +{
  10477. + free(dest->name);
  10478. + dest->name = NULL;
  10479. +
  10480. + free(dest->root_dir);
  10481. + dest->root_dir = NULL;
  10482. +
  10483. + free(dest->ipkg_dir);
  10484. + dest->ipkg_dir = NULL;
  10485. +
  10486. + free(dest->lists_dir);
  10487. + dest->lists_dir = NULL;
  10488. +
  10489. + free(dest->info_dir);
  10490. + dest->info_dir = NULL;
  10491. +
  10492. + free(dest->status_file_name);
  10493. + dest->status_file_name = NULL;
  10494. +
  10495. + free(dest->status_file_tmp_name);
  10496. + dest->status_file_tmp_name = NULL;
  10497. +
  10498. + if (dest->status_file) {
  10499. + fclose(dest->status_file);
  10500. + }
  10501. + dest->status_file = NULL;
  10502. +
  10503. + dest->root_dir = NULL;
  10504. +}
  10505. diff -Nur busybox-1.16.1.orig/archival/libipkg/pkg_dest.h busybox-1.16.1/archival/libipkg/pkg_dest.h
  10506. --- busybox-1.16.1.orig/archival/libipkg/pkg_dest.h 1970-01-01 01:00:00.000000000 +0100
  10507. +++ busybox-1.16.1/archival/libipkg/pkg_dest.h 2010-04-22 19:18:12.000000000 +0200
  10508. @@ -0,0 +1,38 @@
  10509. +/* pkg_dest.h - the itsy package management system
  10510. +
  10511. + Carl D. Worth
  10512. +
  10513. + Copyright (C) 2001 University of Southern California
  10514. +
  10515. + This program is free software; you can redistribute it and/or
  10516. + modify it under the terms of the GNU General Public License as
  10517. + published by the Free Software Foundation; either version 2, or (at
  10518. + your option) any later version.
  10519. +
  10520. + This program is distributed in the hope that it will be useful, but
  10521. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10522. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10523. + General Public License for more details.
  10524. +*/
  10525. +
  10526. +#ifndef PKG_DEST_H
  10527. +#define PKG_DEST_H
  10528. +
  10529. +typedef struct pkg_dest pkg_dest_t;
  10530. +struct pkg_dest
  10531. +{
  10532. + char *name;
  10533. + char *root_dir;
  10534. + char *ipkg_dir;
  10535. + char *lists_dir;
  10536. + char *info_dir;
  10537. + char *status_file_name;
  10538. + char *status_file_tmp_name;
  10539. + FILE *status_file;
  10540. +};
  10541. +
  10542. +int pkg_dest_init(pkg_dest_t *dest, const char *name, const char *root_dir,const char *lists_dir);
  10543. +void pkg_dest_deinit(pkg_dest_t *dest);
  10544. +
  10545. +#endif
  10546. +
  10547. diff -Nur busybox-1.16.1.orig/archival/libipkg/pkg_dest_list.c busybox-1.16.1/archival/libipkg/pkg_dest_list.c
  10548. --- busybox-1.16.1.orig/archival/libipkg/pkg_dest_list.c 1970-01-01 01:00:00.000000000 +0100
  10549. +++ busybox-1.16.1/archival/libipkg/pkg_dest_list.c 2010-04-22 19:18:12.000000000 +0200
  10550. @@ -0,0 +1,85 @@
  10551. +/* pkg_dest_list.c - the itsy package management system
  10552. +
  10553. + Carl D. Worth
  10554. +
  10555. + Copyright (C) 2001 University of Southern California
  10556. +
  10557. + This program is free software; you can redistribute it and/or
  10558. + modify it under the terms of the GNU General Public License as
  10559. + published by the Free Software Foundation; either version 2, or (at
  10560. + your option) any later version.
  10561. +
  10562. + This program is distributed in the hope that it will be useful, but
  10563. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10564. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10565. + General Public License for more details.
  10566. +*/
  10567. +
  10568. +#include "ipkg.h"
  10569. +
  10570. +#include "pkg_dest.h"
  10571. +#include "void_list.h"
  10572. +#include "pkg_dest_list.h"
  10573. +
  10574. +int pkg_dest_list_elt_init(pkg_dest_list_elt_t *elt, pkg_dest_t *data)
  10575. +{
  10576. + return void_list_elt_init((void_list_elt_t *) elt, data);
  10577. +}
  10578. +
  10579. +void pkg_dest_list_elt_deinit(pkg_dest_list_elt_t *elt)
  10580. +{
  10581. + void_list_elt_deinit((void_list_elt_t *) elt);
  10582. +}
  10583. +
  10584. +int pkg_dest_list_init(pkg_dest_list_t *list)
  10585. +{
  10586. + return void_list_init((void_list_t *) list);
  10587. +}
  10588. +
  10589. +void pkg_dest_list_deinit(pkg_dest_list_t *list)
  10590. +{
  10591. + pkg_dest_list_elt_t *iter;
  10592. + pkg_dest_t *pkg_dest;
  10593. +
  10594. + for (iter = list->head; iter; iter = iter->next) {
  10595. + pkg_dest = iter->data;
  10596. + pkg_dest_deinit(pkg_dest);
  10597. +
  10598. + /* malloced in pkg_dest_list_append */
  10599. + free(pkg_dest);
  10600. + iter->data = NULL;
  10601. + }
  10602. + void_list_deinit((void_list_t *) list);
  10603. +}
  10604. +
  10605. +pkg_dest_t *pkg_dest_list_append(pkg_dest_list_t *list, const char *name,
  10606. + const char *root_dir,const char *lists_dir)
  10607. +{
  10608. + int err;
  10609. + pkg_dest_t *pkg_dest;
  10610. +
  10611. + /* freed in plg_dest_list_deinit */
  10612. + pkg_dest = malloc(sizeof(pkg_dest_t));
  10613. + if (pkg_dest == NULL) {
  10614. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10615. + return NULL;
  10616. + }
  10617. +
  10618. + pkg_dest_init(pkg_dest, name, root_dir,lists_dir);
  10619. + err = void_list_append((void_list_t *) list, pkg_dest);
  10620. + if (err) {
  10621. + return NULL;
  10622. + }
  10623. +
  10624. + return pkg_dest;
  10625. +}
  10626. +
  10627. +int pkg_dest_list_push(pkg_dest_list_t *list, pkg_dest_t *data)
  10628. +{
  10629. + return void_list_push((void_list_t *) list, data);
  10630. +}
  10631. +
  10632. +pkg_dest_list_elt_t *pkg_dest_list_pop(pkg_dest_list_t *list)
  10633. +{
  10634. + return (pkg_dest_list_elt_t *) void_list_pop((void_list_t *) list);
  10635. +}
  10636. diff -Nur busybox-1.16.1.orig/archival/libipkg/pkg_dest_list.h busybox-1.16.1/archival/libipkg/pkg_dest_list.h
  10637. --- busybox-1.16.1.orig/archival/libipkg/pkg_dest_list.h 1970-01-01 01:00:00.000000000 +0100
  10638. +++ busybox-1.16.1/archival/libipkg/pkg_dest_list.h 2010-04-22 19:18:12.000000000 +0200
  10639. @@ -0,0 +1,50 @@
  10640. +/* pkg_dest_list.h - the itsy package management system
  10641. +
  10642. + Carl D. Worth
  10643. +
  10644. + Copyright (C) 2001 University of Southern California
  10645. +
  10646. + This program is free software; you can redistribute it and/or
  10647. + modify it under the terms of the GNU General Public License as
  10648. + published by the Free Software Foundation; either version 2, or (at
  10649. + your option) any later version.
  10650. +
  10651. + This program is distributed in the hope that it will be useful, but
  10652. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10653. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10654. + General Public License for more details.
  10655. +*/
  10656. +
  10657. +#ifndef PKG_DEST_LIST_H
  10658. +#define PKG_DEST_LIST_H
  10659. +
  10660. +#include "pkg_dest.h"
  10661. +
  10662. +typedef struct pkg_dest_list_elt pkg_dest_list_elt_t;
  10663. +struct pkg_dest_list_elt
  10664. +{
  10665. + pkg_dest_list_elt_t *next;
  10666. + pkg_dest_t *data;
  10667. +};
  10668. +
  10669. +typedef struct pkg_dest_list pkg_dest_list_t;
  10670. +struct pkg_dest_list
  10671. +{
  10672. + pkg_dest_list_elt_t pre_head;
  10673. + pkg_dest_list_elt_t *head;
  10674. + pkg_dest_list_elt_t *tail;
  10675. +};
  10676. +
  10677. +int pkg_dest_list_elt_init(pkg_dest_list_elt_t *elt, pkg_dest_t *data);
  10678. +void pkg_dest_list_elt_deinit(pkg_dest_list_elt_t *elt);
  10679. +
  10680. +int pkg_dest_list_init(pkg_dest_list_t *list);
  10681. +void pkg_dest_list_deinit(pkg_dest_list_t *list);
  10682. +
  10683. +pkg_dest_t *pkg_dest_list_append(pkg_dest_list_t *list, const char *name,
  10684. + const char *root_dir,const char* lists_dir);
  10685. +int pkg_dest_list_push(pkg_dest_list_t *list, pkg_dest_t *data);
  10686. +pkg_dest_list_elt_t *pkg_dest_list_pop(pkg_dest_list_t *list);
  10687. +
  10688. +#endif
  10689. +
  10690. diff -Nur busybox-1.16.1.orig/archival/libipkg/pkg_extract.c busybox-1.16.1/archival/libipkg/pkg_extract.c
  10691. --- busybox-1.16.1.orig/archival/libipkg/pkg_extract.c 1970-01-01 01:00:00.000000000 +0100
  10692. +++ busybox-1.16.1/archival/libipkg/pkg_extract.c 2010-04-22 19:33:49.000000000 +0200
  10693. @@ -0,0 +1,255 @@
  10694. +/* pkg_extract.c - the itsy package management system
  10695. +
  10696. + Carl D. Worth
  10697. +
  10698. + Copyright (C) 2001 University of Southern California
  10699. +
  10700. + This program is free software; you can redistribute it and/or
  10701. + modify it under the terms of the GNU General Public License as
  10702. + published by the Free Software Foundation; either version 2, or (at
  10703. + your option) any later version.
  10704. +
  10705. + This program is distributed in the hope that it will be useful, but
  10706. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10707. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10708. + General Public License for more details.
  10709. +*/
  10710. +
  10711. +#include "ipkg.h"
  10712. +#include <errno.h>
  10713. +#include <fcntl.h>
  10714. +#include <stdio.h>
  10715. +
  10716. +#include "pkg_extract.h"
  10717. +
  10718. +#include "libbb.h"
  10719. +#include "file_util.h"
  10720. +#include "sprintf_alloc.h"
  10721. +#include "unarchive.h"
  10722. +
  10723. +#define IPKG_CONTROL_ARCHIVE "control.tar.gz"
  10724. +#define IPKG_DATA_ARCHIVE "data.tar.gz"
  10725. +#define IPKG_CONTROL_FILE "control"
  10726. +
  10727. +static void FAST_FUNC ipkg_data_extract_all_prefix(archive_handle_t *archive_handle)
  10728. +{
  10729. + char *name_ptr = archive_handle->file_header->name;
  10730. +
  10731. + /* Skip all leading "/" */
  10732. + while (*name_ptr == '/')
  10733. + name_ptr++;
  10734. + /* Skip all leading "./" and "../" */
  10735. + while (name_ptr[0] == '.') {
  10736. + if (name_ptr[1] == '.' && name_ptr[2] == '/')
  10737. + name_ptr++;
  10738. + if (name_ptr[1] != '/')
  10739. + break;
  10740. + name_ptr += 2;
  10741. + }
  10742. +
  10743. + if (name_ptr[0] != '\0') {
  10744. + archive_handle->file_header->name = xasprintf("%s%s", archive_handle->dpkg__buffer, name_ptr);
  10745. + data_extract_all(archive_handle);
  10746. + }
  10747. +}
  10748. +
  10749. +static void FAST_FUNC ipkg_data_extract_to_buffer(archive_handle_t *archive_handle)
  10750. +{
  10751. + unsigned size = archive_handle->file_header->size;
  10752. +
  10753. + archive_handle->dpkg__buffer = xzalloc(size + 1);
  10754. + xread(archive_handle->src_fd, archive_handle->dpkg__buffer, size);
  10755. +}
  10756. +
  10757. +static void extract_ipkg_file_to_dir(pkg_t *pkg, const char *dir, const char *filename)
  10758. +{
  10759. + archive_handle_t *archive;
  10760. + char *path;
  10761. +
  10762. + sprintf_alloc(&path, "%s/", dir);
  10763. + archive = init_handle();
  10764. + archive->src_fd = xopen(pkg->local_filename, O_RDONLY);
  10765. + archive->filter = filter_accept_list;
  10766. + llist_add_to(&(archive->accept), (char *)filename);
  10767. + archive->dpkg__buffer = path;
  10768. + archive->action_data = ipkg_data_extract_all_prefix;
  10769. + archive->ah_flags |= ARCHIVE_UNLINK_OLD;
  10770. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  10771. + close(archive->src_fd);
  10772. + free(archive->accept);
  10773. + free(archive);
  10774. + free(path);
  10775. +}
  10776. +
  10777. +static void FAST_FUNC data_extract_file_name_to_buffer(archive_handle_t *archive)
  10778. +{
  10779. + unsigned int size = strlen(archive->file_header->name) + 2;
  10780. +
  10781. + if (archive->dpkg__buffer == NULL) {
  10782. + archive->dpkg__buffer = xmalloc(size);
  10783. + strcpy(archive->dpkg__buffer, archive->file_header->name);
  10784. + } else {
  10785. + size += strlen(archive->dpkg__buffer);
  10786. + archive->dpkg__buffer = xrealloc(archive->dpkg__buffer, size);
  10787. + strcat(archive->dpkg__buffer, archive->file_header->name);
  10788. + }
  10789. + strcat(archive->dpkg__buffer, "\n");
  10790. + data_skip(archive);
  10791. +}
  10792. +
  10793. +int pkg_extract_control_file_to_stream(pkg_t *pkg, FILE *stream)
  10794. +{
  10795. + archive_handle_t *archive;
  10796. + char *name;
  10797. + const char *filename = "./" IPKG_CONTROL_FILE;
  10798. +
  10799. + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_CONTROL_ARCHIVE);
  10800. + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_CONTROL_ARCHIVE);
  10801. + archive = init_handle();
  10802. + archive->src_fd = xopen(name, O_RDONLY);
  10803. + archive->filter = filter_accept_list;
  10804. + llist_add_to(&(archive->accept), (char *)filename);
  10805. + archive->action_data = ipkg_data_extract_to_buffer;
  10806. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  10807. + close(archive->src_fd);
  10808. + fputs(archive->dpkg__buffer, stream);
  10809. + free(archive->dpkg__buffer);
  10810. + free(archive->accept);
  10811. + free(archive);
  10812. + free(name);
  10813. +
  10814. + return 0;
  10815. +}
  10816. +
  10817. +int pkg_extract_control_files_to_dir(pkg_t *pkg, const char *dir)
  10818. +{
  10819. + return pkg_extract_control_files_to_dir_with_prefix(pkg, dir, "");
  10820. +}
  10821. +
  10822. +int pkg_extract_control_files_to_dir_with_prefix(pkg_t *pkg, const char *dir, const char *prefix)
  10823. +{
  10824. + archive_handle_t *archive;
  10825. + char *name;
  10826. + char *path;
  10827. +
  10828. + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_CONTROL_ARCHIVE);
  10829. + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_CONTROL_ARCHIVE);
  10830. + sprintf_alloc(&path, "%s/%s", dir, prefix);
  10831. + archive = init_handle();
  10832. + archive->src_fd = xopen(name, O_RDONLY);
  10833. + archive->filter = filter_accept_all;
  10834. + archive->dpkg__buffer = path;
  10835. + archive->action_data = ipkg_data_extract_all_prefix;
  10836. + archive->ah_flags |= ARCHIVE_CREATE_LEADING_DIRS | ARCHIVE_RESTORE_DATE | ARCHIVE_UNLINK_OLD;
  10837. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  10838. + close(archive->src_fd);
  10839. + free(archive);
  10840. + free(path);
  10841. + free(name);
  10842. +
  10843. + return 0;
  10844. +}
  10845. +
  10846. +int pkg_extract_data_files_to_dir(pkg_t *pkg, const char *dir)
  10847. +{
  10848. + archive_handle_t *archive;
  10849. + char *name;
  10850. + char *path;
  10851. +
  10852. + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_DATA_ARCHIVE);
  10853. + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_DATA_ARCHIVE);
  10854. + sprintf_alloc(&path, "%s/", dir);
  10855. + archive = init_handle();
  10856. + archive->src_fd = xopen(name, O_RDONLY);
  10857. + archive->filter = filter_accept_all;
  10858. + archive->dpkg__buffer = path;
  10859. + archive->action_data = ipkg_data_extract_all_prefix;
  10860. + archive->ah_flags |= ARCHIVE_CREATE_LEADING_DIRS | ARCHIVE_RESTORE_DATE | ARCHIVE_UNLINK_OLD;
  10861. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  10862. + close(archive->src_fd);
  10863. + free(archive);
  10864. + free(path);
  10865. + free(name);
  10866. +
  10867. + return 0;
  10868. +}
  10869. +
  10870. +int pkg_extract_data_file_names_to_file(pkg_t *pkg, const char *file_name)
  10871. +{
  10872. + int err=0;
  10873. + char *line, *data_file;
  10874. + FILE *file;
  10875. + FILE *tmp;
  10876. +
  10877. + file = fopen(file_name, "w");
  10878. + if (file == NULL) {
  10879. + fprintf(stderr, "%s: ERROR: Failed to open %s for writing.\n",
  10880. + __FUNCTION__, file_name);
  10881. + return EINVAL;
  10882. + }
  10883. +
  10884. + tmp = tmpfile();
  10885. + if (pkg->installed_files) {
  10886. + str_list_elt_t *elt;
  10887. + for (elt = pkg->installed_files->head; elt; elt = elt->next) {
  10888. + fprintf(file, "%s\n", elt->data);
  10889. + }
  10890. + } else {
  10891. + err = pkg_extract_data_file_names_to_stream(pkg, tmp);
  10892. + if (err) {
  10893. + fclose(file);
  10894. + fclose(tmp);
  10895. + return err;
  10896. + }
  10897. +
  10898. + /* Fixup data file names by removing the initial '.' */
  10899. + rewind(tmp);
  10900. + while (1) {
  10901. + line = file_read_line_alloc(tmp);
  10902. + if (line == NULL) {
  10903. + break;
  10904. + }
  10905. +
  10906. + data_file = line;
  10907. + if (*data_file == '.') {
  10908. + data_file++;
  10909. + }
  10910. +
  10911. + if (*data_file != '/') {
  10912. + fputs("/", file);
  10913. + }
  10914. +
  10915. + /* I have no idea why, but this is what dpkg does */
  10916. + if (strcmp(data_file, "/\n") == 0) {
  10917. + fputs("/.\n", file);
  10918. + } else {
  10919. + fputs(data_file, file);
  10920. + }
  10921. + }
  10922. + }
  10923. + fclose(tmp);
  10924. + fclose(file);
  10925. +
  10926. + return err;
  10927. +}
  10928. +
  10929. +int pkg_extract_data_file_names_to_stream(pkg_t *pkg, FILE *file)
  10930. +{
  10931. + archive_handle_t *archive;
  10932. + char *name;
  10933. +
  10934. + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_DATA_ARCHIVE);
  10935. + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_DATA_ARCHIVE);
  10936. + archive = init_handle();
  10937. + archive->src_fd = xopen(name, O_RDONLY);
  10938. + archive->filter = filter_accept_all;
  10939. + archive->action_data = data_extract_file_name_to_buffer;
  10940. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  10941. + close(archive->src_fd);
  10942. + fputs(archive->dpkg__buffer, file);
  10943. + free(archive->dpkg__buffer);
  10944. + free(archive);
  10945. + free(name);
  10946. +
  10947. + return 0;
  10948. +}
  10949. diff -Nur busybox-1.16.1.orig/archival/libipkg/pkg_extract.h busybox-1.16.1/archival/libipkg/pkg_extract.h
  10950. --- busybox-1.16.1.orig/archival/libipkg/pkg_extract.h 1970-01-01 01:00:00.000000000 +0100
  10951. +++ busybox-1.16.1/archival/libipkg/pkg_extract.h 2010-04-22 19:18:12.000000000 +0200
  10952. @@ -0,0 +1,32 @@
  10953. +/* pkg_extract.c - the itsy package management system
  10954. +
  10955. + Carl D. Worth
  10956. +
  10957. + Copyright (C) 2001 University of Southern California
  10958. +
  10959. + This program is free software; you can redistribute it and/or
  10960. + modify it under the terms of the GNU General Public License as
  10961. + published by the Free Software Foundation; either version 2, or (at
  10962. + your option) any later version.
  10963. +
  10964. + This program is distributed in the hope that it will be useful, but
  10965. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10966. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10967. + General Public License for more details.
  10968. +*/
  10969. +
  10970. +#ifndef PKG_EXTRACT_H
  10971. +#define PKG_EXTRACT_H
  10972. +
  10973. +#include "pkg.h"
  10974. +
  10975. +int pkg_extract_control_file_to_stream(pkg_t *pkg, FILE *stream);
  10976. +int pkg_extract_control_files_to_dir(pkg_t *pkg, const char *dir);
  10977. +int pkg_extract_control_files_to_dir_with_prefix(pkg_t *pkg,
  10978. + const char *dir,
  10979. + const char *prefix);
  10980. +int pkg_extract_data_files_to_dir(pkg_t *pkg, const char *dir);
  10981. +int pkg_extract_data_file_names_to_file(pkg_t *pkg, const char *file_name);
  10982. +int pkg_extract_data_file_names_to_stream(pkg_t *pkg, FILE *file);
  10983. +
  10984. +#endif
  10985. diff -Nur busybox-1.16.1.orig/archival/libipkg/pkg.h busybox-1.16.1/archival/libipkg/pkg.h
  10986. --- busybox-1.16.1.orig/archival/libipkg/pkg.h 1970-01-01 01:00:00.000000000 +0100
  10987. +++ busybox-1.16.1/archival/libipkg/pkg.h 2010-04-22 19:18:12.000000000 +0200
  10988. @@ -0,0 +1,229 @@
  10989. +/* pkg.h - the itsy package management system
  10990. +
  10991. + Carl D. Worth
  10992. +
  10993. + Copyright (C) 2001 University of Southern California
  10994. +
  10995. + This program is free software; you can redistribute it and/or
  10996. + modify it under the terms of the GNU General Public License as
  10997. + published by the Free Software Foundation; either version 2, or (at
  10998. + your option) any later version.
  10999. +
  11000. + This program is distributed in the hope that it will be useful, but
  11001. + WITHOUT ANY WARRANTY; without even the implied warranty of
  11002. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11003. + General Public License for more details.
  11004. +*/
  11005. +
  11006. +#ifndef PKG_H
  11007. +#define PKG_H
  11008. +
  11009. +#include <sys/types.h>
  11010. +#include <sys/stat.h>
  11011. +#include <unistd.h>
  11012. +
  11013. +#include "pkg_vec.h"
  11014. +#include "str_list.h"
  11015. +#include "pkg_src.h"
  11016. +#include "pkg_dest.h"
  11017. +#include "ipkg_conf.h"
  11018. +#include "conffile_list.h"
  11019. +
  11020. +struct ipkg_conf;
  11021. +
  11022. +/* I think "Size" is currently the shortest field name */
  11023. +#define PKG_MINIMUM_FIELD_NAME_LEN 4
  11024. +
  11025. +enum pkg_state_want
  11026. +{
  11027. + SW_UNKNOWN = 1,
  11028. + SW_INSTALL,
  11029. + SW_DEINSTALL,
  11030. + SW_PURGE,
  11031. + SW_LAST_STATE_WANT
  11032. +};
  11033. +typedef enum pkg_state_want pkg_state_want_t;
  11034. +
  11035. +enum pkg_state_flag
  11036. +{
  11037. + SF_OK = 0,
  11038. + SF_REINSTREQ = 1,
  11039. + SF_HOLD = 2, /* do not upgrade version */
  11040. + SF_REPLACE = 4, /* replace this package */
  11041. + SF_NOPRUNE = 8, /* do not remove obsolete files */
  11042. + SF_PREFER = 16, /* prefer this version */
  11043. + SF_OBSOLETE = 32, /* old package in upgrade pair */
  11044. + SF_MARKED = 64, /* temporary mark */
  11045. + SF_FILELIST_CHANGED = 128, /* needs filelist written */
  11046. + SF_USER = 256,
  11047. + SF_LAST_STATE_FLAG
  11048. +};
  11049. +typedef enum pkg_state_flag pkg_state_flag_t;
  11050. +#define SF_NONVOLATILE_FLAGS (SF_HOLD|SF_NOPRUNE|SF_PREFER|SF_OBSOLETE|SF_USER)
  11051. +
  11052. +enum pkg_state_status
  11053. +{
  11054. + SS_NOT_INSTALLED = 1,
  11055. + SS_UNPACKED,
  11056. + SS_HALF_CONFIGURED,
  11057. + SS_INSTALLED,
  11058. + SS_HALF_INSTALLED,
  11059. + SS_CONFIG_FILES,
  11060. + SS_POST_INST_FAILED,
  11061. + SS_REMOVAL_FAILED,
  11062. + SS_LAST_STATE_STATUS
  11063. +};
  11064. +typedef enum pkg_state_status pkg_state_status_t;
  11065. +
  11066. +struct abstract_pkg{
  11067. + char * name;
  11068. + int dependencies_checked;
  11069. + pkg_vec_t * pkgs;
  11070. + pkg_state_status_t state_status;
  11071. + pkg_state_flag_t state_flag;
  11072. + struct abstract_pkg ** depended_upon_by; /* @@@@ this should be abstract_pkg_vec_t -Jamey */
  11073. + abstract_pkg_vec_t * provided_by;
  11074. + abstract_pkg_vec_t * replaced_by;
  11075. +};
  11076. +
  11077. +#include "pkg_depends.h"
  11078. +
  11079. +/* XXX: CLEANUP: I'd like to clean up pkg_t in several ways:
  11080. +
  11081. + The 3 version fields should go into a single version struct. (This
  11082. + is especially important since, currently, pkg->version can easily
  11083. + be mistaken for pkg_verson_str_alloc(pkg) although they are very
  11084. + distinct. This has been the source of multiple bugs.
  11085. +
  11086. + The 3 state fields could possibly also go into their own struct.
  11087. +
  11088. + All fields which deal with lists of packages, (Depends,
  11089. + Pre-Depends, Provides, Suggests, Recommends, Enhances), should each
  11090. + be handled by a single struct in pkg_t
  11091. +
  11092. + All string fields for which there is a small set of possible
  11093. + values, (section, maintainer, architecture, maybe version?), that
  11094. + are reused among different packages -- for all such packages we
  11095. + should move from "char *"s to some atom datatype to share data
  11096. + storage and use less memory. We might even do reference counting,
  11097. + but probably not since most often we only create new pkg_t structs,
  11098. + we don't often free them. */
  11099. +struct pkg
  11100. +{
  11101. + char *name;
  11102. + unsigned long epoch;
  11103. + char *version;
  11104. + char *revision;
  11105. + char *familiar_revision;
  11106. + pkg_src_t *src;
  11107. + pkg_dest_t *dest;
  11108. + char *architecture;
  11109. + char *section;
  11110. + char *maintainer;
  11111. + char *description;
  11112. + pkg_state_want_t state_want;
  11113. + pkg_state_flag_t state_flag;
  11114. + pkg_state_status_t state_status;
  11115. + char **depends_str;
  11116. + int depends_count;
  11117. + char **pre_depends_str;
  11118. + int pre_depends_count;
  11119. + char **recommends_str;
  11120. + int recommends_count;
  11121. + char **suggests_str;
  11122. + int suggests_count;
  11123. + compound_depend_t * depends;
  11124. +
  11125. + /* Abhaya: new conflicts */
  11126. + char **conflicts_str;
  11127. + compound_depend_t * conflicts;
  11128. + int conflicts_count;
  11129. +
  11130. + char **replaces_str;
  11131. + int replaces_count;
  11132. + abstract_pkg_t ** replaces;
  11133. +
  11134. + char **provides_str;
  11135. + int provides_count;
  11136. + abstract_pkg_t ** provides;
  11137. +
  11138. + abstract_pkg_t *parent;
  11139. +
  11140. + pkg_t *old_pkg; /* during upgrade, points from installee to previously installed */
  11141. +
  11142. + char *filename;
  11143. + char *local_filename;
  11144. + char *url;
  11145. + char *tmp_unpack_dir;
  11146. + char *md5sum;
  11147. + char *size;
  11148. + char *installed_size;
  11149. + char *priority;
  11150. + char *source;
  11151. + conffile_list_t conffiles;
  11152. + time_t installed_time;
  11153. + /* As pointer for lazy evaluation */
  11154. + str_list_t *installed_files;
  11155. + /* XXX: CLEANUP: I'd like to perhaps come up with a better
  11156. + mechanism to avoid the problem here, (which is that the
  11157. + installed_files list was being freed from an inner loop while
  11158. + still being used within an outer loop. */
  11159. + int installed_files_ref_cnt;
  11160. + int essential;
  11161. + int arch_priority;
  11162. +/* Adding this flag, to "force" ipkg to choose a "provided_by_hand" package, if there are multiple choice */
  11163. + int provided_by_hand;
  11164. +};
  11165. +
  11166. +pkg_t *pkg_new(void);
  11167. +int pkg_init(pkg_t *pkg);
  11168. +void pkg_deinit(pkg_t *pkg);
  11169. +int pkg_init_from_file(pkg_t *pkg, const char *filename);
  11170. +abstract_pkg_t *abstract_pkg_new(void);
  11171. +int abstract_pkg_init(abstract_pkg_t *ab_pkg);
  11172. +
  11173. +/*
  11174. + * merges fields from newpkg into oldpkg.
  11175. + * Forcibly sets oldpkg state_status, state_want and state_flags if set_status is nonzero
  11176. + */
  11177. +int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status);
  11178. +
  11179. +char *pkg_version_str_alloc(pkg_t *pkg);
  11180. +
  11181. +int pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg);
  11182. +int pkg_name_version_and_architecture_compare(pkg_t *a, pkg_t *b);
  11183. +int abstract_pkg_name_compare(abstract_pkg_t *a, abstract_pkg_t *b);
  11184. +
  11185. +char * pkg_formatted_info(pkg_t *pkg );
  11186. +char * pkg_formatted_field(pkg_t *pkg, const char *field );
  11187. +
  11188. +void set_flags_from_control(ipkg_conf_t *conf, pkg_t *pkg);
  11189. +
  11190. +void pkg_print_info(pkg_t *pkg, FILE *file);
  11191. +void pkg_print_status(pkg_t * pkg, FILE * file);
  11192. +void pkg_print_field(pkg_t *pkg, FILE *file, const char *field);
  11193. +str_list_t *pkg_get_installed_files(pkg_t *pkg);
  11194. +int pkg_free_installed_files(pkg_t *pkg);
  11195. +int pkg_remove_installed_files_list(ipkg_conf_t *conf, pkg_t *pkg);
  11196. +conffile_t *pkg_get_conffile(pkg_t *pkg, const char *file_name);
  11197. +int pkg_run_script(struct ipkg_conf *conf, pkg_t *pkg,
  11198. + const char *script, const char *args);
  11199. +
  11200. +/* enum mappings */
  11201. +char *pkg_state_want_to_str(pkg_state_want_t sw);
  11202. +pkg_state_want_t pkg_state_want_from_str(char *str);
  11203. +char *pkg_state_flag_to_str(pkg_state_flag_t sf);
  11204. +pkg_state_flag_t pkg_state_flag_from_str(char *str);
  11205. +char *pkg_state_status_to_str(pkg_state_status_t ss);
  11206. +pkg_state_status_t pkg_state_status_from_str(char *str);
  11207. +
  11208. +int pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op);
  11209. +
  11210. +int pkg_arch_supported(ipkg_conf_t *conf, pkg_t *pkg);
  11211. +int pkg_info_preinstall_check(ipkg_conf_t *conf);
  11212. +int pkg_free_installed_files(pkg_t *pkg);
  11213. +
  11214. +int pkg_write_filelist(ipkg_conf_t *conf, pkg_t *pkg);
  11215. +int pkg_write_changed_filelists(ipkg_conf_t *conf);
  11216. +
  11217. +#endif
  11218. diff -Nur busybox-1.16.1.orig/archival/libipkg/pkg_hash.c busybox-1.16.1/archival/libipkg/pkg_hash.c
  11219. --- busybox-1.16.1.orig/archival/libipkg/pkg_hash.c 1970-01-01 01:00:00.000000000 +0100
  11220. +++ busybox-1.16.1/archival/libipkg/pkg_hash.c 2010-04-22 19:18:12.000000000 +0200
  11221. @@ -0,0 +1,623 @@
  11222. +/* ipkg_hash.c - the itsy package management system
  11223. +
  11224. + Steven M. Ayer
  11225. +
  11226. + Copyright (C) 2002 Compaq Computer Corporation
  11227. +
  11228. + This program is free software; you can redistribute it and/or
  11229. + modify it under the terms of the GNU General Public License as
  11230. + published by the Free Software Foundation; either version 2, or (at
  11231. + your option) any later version.
  11232. +
  11233. + This program is distributed in the hope that it will be useful, but
  11234. + WITHOUT ANY WARRANTY; without even the implied warranty of
  11235. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11236. + General Public License for more details.
  11237. +*/
  11238. +
  11239. +#include "ipkg.h"
  11240. +#include <errno.h>
  11241. +#include <ctype.h>
  11242. +#include <stdlib.h>
  11243. +#include <string.h>
  11244. +
  11245. +#include "hash_table.h"
  11246. +#include "pkg.h"
  11247. +#include "ipkg_message.h"
  11248. +#include "pkg_vec.h"
  11249. +#include "pkg_hash.h"
  11250. +#include "pkg_parse.h"
  11251. +#include "ipkg_utils.h"
  11252. +
  11253. +static abstract_pkg_t * add_new_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name);
  11254. +
  11255. +/*
  11256. + * this will talk to both feeds-lists files and installed status files
  11257. + * example api:
  11258. + *
  11259. + * hash_table_t hash;
  11260. + * pkg_hash_init(name, &hash, 1000);
  11261. + * pkg_hash_add_from_file(<feed filename>);
  11262. + *
  11263. + * the query function is just there as a shell to prove to me that this
  11264. + * sort of works, but isn't far from doing something useful
  11265. + *
  11266. + * -sma, 12/21/01
  11267. + * modified: CDW 3 Jan. 2002
  11268. + */
  11269. +
  11270. +
  11271. +
  11272. +int pkg_hash_init(const char *name, hash_table_t *hash, int len)
  11273. +{
  11274. + return hash_table_init(name, hash, len);
  11275. +}
  11276. +
  11277. +void pkg_hash_deinit(hash_table_t *hash)
  11278. +{
  11279. + hash_table_deinit(hash);
  11280. +}
  11281. +
  11282. +
  11283. +/* Find the default arch for a given package status file if none is given. */
  11284. +static char *pkg_get_default_arch(ipkg_conf_t *conf)
  11285. +{
  11286. + nv_pair_list_elt_t *l;
  11287. + const char *def_arch = HOST_CPU_STR; /* Default arch */
  11288. + int def_prio = 0; /* Other archs override this */
  11289. +
  11290. + l = conf->arch_list.head;
  11291. +
  11292. + while (l) {
  11293. + nv_pair_t *nv = l->data;
  11294. + int priority = strtol(nv->value, NULL, 0);
  11295. +
  11296. + /* Check if this arch has higher priority, and is valid */
  11297. + if ((priority > def_prio) &&
  11298. + (strcmp(nv->name, "all")) && (strcmp(nv->name, "noarch"))) {
  11299. + /* Our new default */
  11300. + def_prio = priority;
  11301. + def_arch = nv->name;
  11302. + }
  11303. + l = l->next;
  11304. + }
  11305. +
  11306. + return strdup(def_arch);
  11307. +}
  11308. +
  11309. +int pkg_hash_add_from_file(ipkg_conf_t *conf, const char *file_name,
  11310. + pkg_src_t *src, pkg_dest_t *dest, int is_status_file)
  11311. +{
  11312. + hash_table_t *hash = &conf->pkg_hash;
  11313. + char **raw;
  11314. + char **raw_start;
  11315. + pkg_t *pkg;
  11316. +
  11317. + raw = raw_start = read_raw_pkgs_from_file(file_name);
  11318. + if (!raw)
  11319. + return -ENOMEM;
  11320. +
  11321. + while(*raw){ /* don't worry, we'll increment raw in the parsing function */
  11322. + pkg = pkg_new();
  11323. + if (!pkg)
  11324. + return -ENOMEM;
  11325. +
  11326. + if (pkg_parse_raw(pkg, &raw, src, dest) == 0) {
  11327. + if (!pkg->architecture) {
  11328. + char *version_str = pkg_version_str_alloc(pkg);
  11329. + pkg->architecture = pkg_get_default_arch(conf);
  11330. + ipkg_message(conf, IPKG_ERROR, "Package %s version %s has no architecture specified, defaulting to %s.\n",
  11331. + pkg->name, version_str, pkg->architecture);
  11332. + free(version_str);
  11333. + }
  11334. + hash_insert_pkg(hash, pkg, is_status_file,conf);
  11335. + } else {
  11336. + free(pkg);
  11337. + }
  11338. + }
  11339. +
  11340. + /* XXX: CLEANUP: I'd like a cleaner interface for cleaning up
  11341. + memory after read_raw_pkgs_from_file */
  11342. + raw = raw_start;
  11343. + while (*raw) {
  11344. + free(*raw++);
  11345. + }
  11346. + free(raw_start);
  11347. + return 0;
  11348. +}
  11349. +
  11350. +abstract_pkg_t * abstract_pkg_fetch_by_name(hash_table_t * hash, const char * pkg_name)
  11351. +{
  11352. + return (abstract_pkg_t *)hash_table_get(hash, pkg_name);
  11353. +}
  11354. +
  11355. +abstract_pkg_vec_t *pkg_hash_fetch_all_installation_candidates(hash_table_t *hash, const char *name)
  11356. +{
  11357. + abstract_pkg_t *apkg = abstract_pkg_fetch_by_name(hash, name);
  11358. + if (apkg)
  11359. + return NULL;
  11360. + return apkg->provided_by;
  11361. +}
  11362. +
  11363. +
  11364. +pkg_t *pkg_hash_fetch_best_installation_candidate(ipkg_conf_t *conf, abstract_pkg_t *apkg,
  11365. + int (*constraint_fcn)(pkg_t *pkg, void *cdata), void *cdata, int quiet)
  11366. +{
  11367. + int i;
  11368. + int nprovides = 0;
  11369. + int nmatching = 0;
  11370. + pkg_vec_t *matching_pkgs = pkg_vec_alloc();
  11371. + abstract_pkg_vec_t *matching_apkgs = abstract_pkg_vec_alloc();
  11372. + abstract_pkg_vec_t *provided_apkg_vec;
  11373. + abstract_pkg_t **provided_apkgs;
  11374. + abstract_pkg_vec_t *providers = abstract_pkg_vec_alloc();
  11375. + pkg_t *latest_installed_parent = NULL;
  11376. + pkg_t *latest_matching = NULL;
  11377. + pkg_t *held_pkg = NULL;
  11378. + pkg_t *good_pkg_by_name = NULL;
  11379. +
  11380. + if (matching_apkgs == NULL || providers == NULL ||
  11381. + apkg == NULL || apkg->provided_by == NULL || (apkg->provided_by->len == 0))
  11382. + return NULL;
  11383. +
  11384. + ipkg_message(conf, IPKG_DEBUG, "best installation candidate for %s\n", apkg->name);
  11385. +
  11386. + provided_apkg_vec = apkg->provided_by;
  11387. + nprovides = provided_apkg_vec->len;
  11388. + provided_apkgs = provided_apkg_vec->pkgs;
  11389. + if (nprovides > 1)
  11390. + ipkg_message(conf, IPKG_DEBUG, " apkg=%s nprovides=%d\n", apkg->name, nprovides);
  11391. +
  11392. + /* accumulate all the providers */
  11393. + for (i = 0; i < nprovides; i++) {
  11394. + abstract_pkg_t *provider_apkg = provided_apkgs[i];
  11395. + ipkg_message(conf, IPKG_DEBUG, " adding %s to providers\n", provider_apkg->name);
  11396. + abstract_pkg_vec_insert(providers, provider_apkg);
  11397. + }
  11398. + nprovides = providers->len;
  11399. +
  11400. + for (i = 0; i < nprovides; i++) {
  11401. + abstract_pkg_t *provider_apkg = abstract_pkg_vec_get(providers, i);
  11402. + abstract_pkg_t *replacement_apkg = NULL;
  11403. + pkg_vec_t *vec;
  11404. +
  11405. + if (provider_apkg->replaced_by && provider_apkg->replaced_by->len) {
  11406. + replacement_apkg = provider_apkg->replaced_by->pkgs[0];
  11407. + if (provider_apkg->replaced_by->len > 1) {
  11408. + ipkg_message(conf, IPKG_NOTICE, "Multiple replacers for %s, using first one (%s)\n",
  11409. + provider_apkg->name, replacement_apkg->name);
  11410. + }
  11411. + }
  11412. +
  11413. + if (replacement_apkg)
  11414. + ipkg_message(conf, IPKG_DEBUG, " replacement_apkg=%s for provider_apkg=%s\n",
  11415. + replacement_apkg->name, provider_apkg->name);
  11416. +
  11417. + if (replacement_apkg && (replacement_apkg != provider_apkg)) {
  11418. + if (abstract_pkg_vec_contains(providers, replacement_apkg))
  11419. + continue;
  11420. + else
  11421. + provider_apkg = replacement_apkg;
  11422. + }
  11423. +
  11424. + if (!(vec = provider_apkg->pkgs)) {
  11425. + ipkg_message(conf, IPKG_DEBUG, " no pkgs for provider_apkg %s\n", provider_apkg->name);
  11426. + continue;
  11427. + }
  11428. +
  11429. +
  11430. + /* now check for supported architecture */
  11431. + {
  11432. + int max_count = 0;
  11433. + int j;
  11434. +
  11435. + /* count packages matching max arch priority and keep track of last one */
  11436. + for (j = 0; j < vec->len; j++) {
  11437. + pkg_t *maybe = vec->pkgs[j];
  11438. + ipkg_message(conf, IPKG_DEBUG, " %s arch=%s arch_priority=%d version=%s \n",
  11439. + maybe->name, maybe->architecture, maybe->arch_priority, maybe->version);
  11440. + if (maybe->arch_priority > 0) {
  11441. + max_count++;
  11442. + abstract_pkg_vec_insert(matching_apkgs, maybe->parent);
  11443. + pkg_vec_insert(matching_pkgs, maybe);
  11444. + }
  11445. + }
  11446. + }
  11447. + }
  11448. +
  11449. + if (matching_pkgs->len > 1)
  11450. + pkg_vec_sort(matching_pkgs, pkg_name_version_and_architecture_compare);
  11451. + if (matching_apkgs->len > 1)
  11452. + abstract_pkg_vec_sort(matching_pkgs, abstract_pkg_name_compare);
  11453. +
  11454. +/* Here it is usefull, if ( matching_apkgs->len > 1 ), to test if one of this matching packages has the same name of the
  11455. + needed package. In this case, I would return it for install, otherwise I will continue with the procedure */
  11456. +/* The problem is what to do when there are more than a mathing package, with the same name and several version ?
  11457. + Until now I always got the latest, but that breaks the downgrade option.
  11458. + If I stop at the first one, I would probably miss the new ones
  11459. + Maybe the way is to have some kind of flag somewhere, to see if the package been asked to install is from a file,
  11460. + or from a Packages feed.
  11461. + 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*/
  11462. +/*Pigi*/
  11463. +
  11464. + for (i = 0; i < matching_pkgs->len; i++) {
  11465. + pkg_t *matching = matching_pkgs->pkgs[i];
  11466. + if (constraint_fcn(matching, cdata)) { /* We found it */
  11467. + ipkg_message(conf, IPKG_DEBUG, " Found a valid candidate for the install: %s %s \n", matching->name, matching->version) ;
  11468. + good_pkg_by_name = matching;
  11469. + if ( matching->provided_by_hand == 1 ) /* It has been provided by hand, so it is what user want */
  11470. + break;
  11471. + }
  11472. + }
  11473. +
  11474. +
  11475. + for (i = 0; i < matching_pkgs->len; i++) {
  11476. + pkg_t *matching = matching_pkgs->pkgs[i];
  11477. + latest_matching = matching;
  11478. + if (matching->parent->state_status == SS_INSTALLED || matching->parent->state_status == SS_UNPACKED)
  11479. + latest_installed_parent = matching;
  11480. + if (matching->state_flag & (SF_HOLD|SF_PREFER)) {
  11481. + if (held_pkg)
  11482. + ipkg_message(conf, IPKG_ERROR, "Multiple packages (%s and %s) providing same name marked HOLD or PREFER. Using latest.\n",
  11483. + held_pkg->name, matching->name);
  11484. + held_pkg = matching;
  11485. + }
  11486. + }
  11487. +
  11488. + if (!good_pkg_by_name && !held_pkg && !latest_installed_parent && matching_apkgs->len > 1 && !quiet) {
  11489. + ipkg_message(conf, IPKG_ERROR, "Package=%s, %d matching providers\n",
  11490. + apkg->name, matching_apkgs->len);
  11491. + for (i = 0; i < matching_apkgs->len; i++) {
  11492. + abstract_pkg_t *matching = matching_apkgs->pkgs[i];
  11493. + ipkg_message(conf, IPKG_ERROR, " %s\n", matching->name);
  11494. + }
  11495. + ipkg_message(conf, IPKG_ERROR, "Please select one with ipkg install or ipkg flag prefer\n");
  11496. + }
  11497. +
  11498. + if (matching_apkgs->len > 1 && conf->verbosity > 1) {
  11499. + ipkg_message(conf, IPKG_NOTICE, "%s: for apkg=%s, %d matching pkgs\n",
  11500. + __FUNCTION__, apkg->name, matching_pkgs->len);
  11501. + for (i = 0; i < matching_pkgs->len; i++) {
  11502. + pkg_t *matching = matching_pkgs->pkgs[i];
  11503. + ipkg_message(conf, IPKG_INFO, " %s %s %s\n",
  11504. + matching->name, matching->version, matching->architecture);
  11505. + }
  11506. + }
  11507. +
  11508. + nmatching = matching_apkgs->len;
  11509. +
  11510. + pkg_vec_free(matching_pkgs);
  11511. + abstract_pkg_vec_free(matching_apkgs);
  11512. + abstract_pkg_vec_free(providers);
  11513. +
  11514. + if (good_pkg_by_name) { /* We found a good candidate, we will install it */
  11515. + return good_pkg_by_name;
  11516. + }
  11517. + if (held_pkg) {
  11518. + ipkg_message(conf, IPKG_INFO, " using held package %s\n", held_pkg->name);
  11519. + return held_pkg;
  11520. + }
  11521. + if (latest_installed_parent) {
  11522. + ipkg_message(conf, IPKG_INFO, " using latest version of installed package %s\n", latest_installed_parent->name);
  11523. + return latest_installed_parent;
  11524. + }
  11525. + if (nmatching > 1) {
  11526. + ipkg_message(conf, IPKG_INFO, " no matching pkg out of matching_apkgs=%d\n", nmatching);
  11527. + return NULL;
  11528. + }
  11529. + if (latest_matching) {
  11530. + ipkg_message(conf, IPKG_INFO, " using latest matching %s %s %s\n",
  11531. + latest_matching->name, latest_matching->version, latest_matching->architecture);
  11532. + return latest_matching;
  11533. + }
  11534. + return NULL;
  11535. +}
  11536. +
  11537. +static int pkg_name_constraint_fcn(pkg_t *pkg, void *cdata)
  11538. +{
  11539. + const char *name = (const char *)cdata;
  11540. + if (strcmp(pkg->name, name) == 0)
  11541. + return 1;
  11542. + else
  11543. + return 0;
  11544. +}
  11545. +
  11546. +pkg_t *pkg_hash_fetch_best_installation_candidate_by_name(ipkg_conf_t *conf, const char *name)
  11547. +{
  11548. + hash_table_t *hash = &conf->pkg_hash;
  11549. + abstract_pkg_t *apkg = NULL;
  11550. +
  11551. + if (!(apkg = abstract_pkg_fetch_by_name(hash, name)))
  11552. + return NULL;
  11553. +
  11554. + return pkg_hash_fetch_best_installation_candidate(conf, apkg, pkg_name_constraint_fcn, apkg->name, 0);
  11555. +}
  11556. +
  11557. +
  11558. +pkg_t * pkg_hash_fetch_by_name_version(hash_table_t *hash,
  11559. + const char *pkg_name,
  11560. + const char * version)
  11561. +{
  11562. + pkg_vec_t * vec;
  11563. + register int i;
  11564. + char *version_str = NULL;
  11565. +
  11566. + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name)))
  11567. + return NULL;
  11568. +
  11569. + for(i = 0; i < vec->len; i++) {
  11570. + version_str = pkg_version_str_alloc(vec->pkgs[i]);
  11571. + if(!strcmp(version_str, version)) {
  11572. + free(version_str);
  11573. + break;
  11574. + }
  11575. + free(version_str);
  11576. + }
  11577. +
  11578. + if(i == vec->len)
  11579. + return NULL;
  11580. +
  11581. + return vec->pkgs[i];
  11582. +}
  11583. +
  11584. +pkg_t *pkg_hash_fetch_installed_by_name_dest(hash_table_t *hash,
  11585. + const char *pkg_name,
  11586. + pkg_dest_t *dest)
  11587. +{
  11588. + pkg_vec_t * vec;
  11589. + register int i;
  11590. +
  11591. + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name))) {
  11592. + return NULL;
  11593. + }
  11594. +
  11595. + for(i = 0; i < vec->len; i++)
  11596. + if((vec->pkgs[i]->state_status == SS_INSTALLED || vec->pkgs[i]->state_status == SS_UNPACKED) && vec->pkgs[i]->dest == dest) {
  11597. + return vec->pkgs[i];
  11598. + }
  11599. + return NULL;
  11600. +}
  11601. +
  11602. +pkg_t *pkg_hash_fetch_installed_by_name(hash_table_t *hash,
  11603. + const char *pkg_name)
  11604. +{
  11605. + pkg_vec_t * vec;
  11606. + register int i;
  11607. +
  11608. + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name))){
  11609. + return NULL;
  11610. + }
  11611. +
  11612. + for(i = 0; i < vec->len; i++)
  11613. + if (vec->pkgs[i]->state_status == SS_INSTALLED || vec->pkgs[i]->state_status == SS_UNPACKED){
  11614. + return vec->pkgs[i];
  11615. + }
  11616. +
  11617. + return NULL;
  11618. +}
  11619. +
  11620. +pkg_vec_t *pkg_vec_fetch_by_name(hash_table_t *hash, const char *pkg_name)
  11621. +{
  11622. + abstract_pkg_t * ab_pkg;
  11623. +
  11624. + if(!(ab_pkg = abstract_pkg_fetch_by_name(hash, pkg_name))){
  11625. + return NULL;
  11626. + }
  11627. +
  11628. + if (ab_pkg->pkgs) {
  11629. + return ab_pkg->pkgs;
  11630. + } else if (ab_pkg->provided_by) {
  11631. + abstract_pkg_t *abpkg = abstract_pkg_vec_get(ab_pkg->provided_by, 0);
  11632. + if (abpkg != NULL){
  11633. + return abpkg->pkgs;
  11634. + } else {
  11635. + return ab_pkg->pkgs;
  11636. + }
  11637. + } else {
  11638. + return NULL;
  11639. + }
  11640. +}
  11641. +
  11642. +static int pkg_compare_names(const void *p1, const void *p2)
  11643. +{
  11644. + const pkg_t *pkg1 = *(const pkg_t **)p1;
  11645. + const pkg_t *pkg2 = *(const pkg_t **)p2;
  11646. + if (pkg1->name == NULL)
  11647. + return 1;
  11648. + if (pkg2->name == NULL)
  11649. + return -1;
  11650. + return(strcmp(pkg1->name, pkg2->name));
  11651. +}
  11652. +
  11653. +
  11654. +static void pkg_hash_fetch_available_helper(const char *pkg_name, void *entry, void *data)
  11655. +{
  11656. + int j;
  11657. + const char *name;
  11658. + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
  11659. + pkg_vec_t *all = (pkg_vec_t *)data;
  11660. + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
  11661. + name = pkg_name;
  11662. + if (pkg_vec) {
  11663. + for (j = 0; j < pkg_vec->len; j++) {
  11664. + pkg_t *pkg = pkg_vec->pkgs[j];
  11665. + pkg_vec_insert(all, pkg);
  11666. + }
  11667. + }
  11668. +}
  11669. +
  11670. +void pkg_hash_fetch_available(hash_table_t *hash, pkg_vec_t *all)
  11671. +{
  11672. + hash_table_foreach(hash, pkg_hash_fetch_available_helper, all);
  11673. + qsort(all->pkgs, all->len, sizeof(pkg_t *), pkg_compare_names);
  11674. +}
  11675. +
  11676. +static void pkg_hash_fetch_all_installed_helper(const char *pkg_name, void *entry, void *data)
  11677. +{
  11678. + const char *name;
  11679. + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
  11680. + pkg_vec_t *all = (pkg_vec_t *)data;
  11681. + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
  11682. + int j;
  11683. + name = pkg_name;
  11684. + if (pkg_vec) {
  11685. + for (j = 0; j < pkg_vec->len; j++) {
  11686. + pkg_t *pkg = pkg_vec->pkgs[j];
  11687. + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) {
  11688. + pkg_vec_insert(all, pkg);
  11689. + }
  11690. + }
  11691. + }
  11692. +}
  11693. +void pkg_hash_fetch_all_installed(hash_table_t *hash, pkg_vec_t *all)
  11694. +{
  11695. + hash_table_foreach(hash, pkg_hash_fetch_all_installed_helper, all);
  11696. + qsort(all->pkgs, all->len, sizeof(void*), pkg_compare_names);
  11697. +}
  11698. +
  11699. +static void pkg_hash_dump_helper(const char *pkg_name, void *entry, void *data)
  11700. +{
  11701. + int i;
  11702. + pkg_t *pkg;
  11703. + const char *name;
  11704. + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
  11705. + ipkg_conf_t *conf = (ipkg_conf_t *)data;
  11706. + abstract_pkg_t ** dependents = ab_pkg->depended_upon_by;
  11707. + name = pkg_name;
  11708. + fprintf(stdout, "%s\n", ab_pkg->name);
  11709. + i = 0;
  11710. + if (dependents != NULL)
  11711. + while (dependents [i] != NULL)
  11712. + printf ("\tdepended upon by - %s\n", dependents [i ++]->name);
  11713. + dependents = ab_pkg->provided_by->pkgs;
  11714. + i = 0;
  11715. + if (dependents != NULL)
  11716. + while (dependents [i] != NULL && i < ab_pkg->provided_by->len)
  11717. + printf ("\tprovided by - %s\n", dependents [i ++]->name);
  11718. + pkg = pkg_hash_fetch_best_installation_candidate_by_name (conf, ab_pkg->name);
  11719. + if (pkg) {
  11720. + i = 0;
  11721. + while (i < pkg->depends_count)
  11722. + printf ("\tdepends on - %s\n", pkg->depends_str [i ++]);
  11723. + }
  11724. +}
  11725. +void pkg_hash_dump(hash_table_t *hash, void *data)
  11726. +{
  11727. +
  11728. + printf ("\n\n+=+%s+=+\n\n", __FUNCTION__);
  11729. + hash_table_foreach(hash, pkg_hash_dump_helper, data);
  11730. + printf ("\n+=+%s+=+\n\n", __FUNCTION__);
  11731. +}
  11732. +
  11733. +abstract_pkg_t * ensure_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name)
  11734. +{
  11735. + abstract_pkg_t * ab_pkg;
  11736. +
  11737. + if(!(ab_pkg = abstract_pkg_fetch_by_name(hash, pkg_name)))
  11738. + ab_pkg = add_new_abstract_pkg_by_name(hash, pkg_name);
  11739. +
  11740. + return ab_pkg;
  11741. +}
  11742. +
  11743. +pkg_t *hash_insert_pkg(hash_table_t *hash, pkg_t *pkg, int set_status,ipkg_conf_t *conf)
  11744. +{
  11745. + abstract_pkg_t * ab_pkg;
  11746. + int arch_priority;
  11747. +
  11748. + if(!pkg)
  11749. + return pkg;
  11750. +
  11751. + arch_priority = pkg->arch_priority;
  11752. +
  11753. + if (buildDepends(hash, pkg)<0){
  11754. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  11755. + return NULL;
  11756. + }
  11757. + ab_pkg = ensure_abstract_pkg_by_name(hash, pkg->name);
  11758. +
  11759. + if (set_status) {
  11760. + if (pkg->state_status == SS_INSTALLED) {
  11761. + ab_pkg->state_status = SS_INSTALLED;
  11762. + } else if (pkg->state_status == SS_UNPACKED) {
  11763. + ab_pkg->state_status = SS_UNPACKED;
  11764. + }
  11765. + }
  11766. +
  11767. + if(!ab_pkg->pkgs)
  11768. + ab_pkg->pkgs = pkg_vec_alloc();
  11769. +
  11770. + /* pkg_vec_insert_merge might munge package, but it returns an unmunged pkg */
  11771. + pkg = pkg_vec_insert_merge(ab_pkg->pkgs, pkg, set_status,conf );
  11772. + pkg->parent = ab_pkg;
  11773. +
  11774. + if (buildProvides(hash, ab_pkg, pkg)<0){
  11775. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  11776. + return NULL;
  11777. + }
  11778. + /* need to build the conflicts graph before replaces for correct calculation of replaced_by relation */
  11779. + if (buildConflicts(hash, pkg)<0){
  11780. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  11781. + return NULL;
  11782. + }
  11783. + if (buildReplaces(hash, ab_pkg, pkg)<0) {
  11784. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  11785. + return NULL;
  11786. + }
  11787. +
  11788. + buildDependedUponBy(pkg, ab_pkg);
  11789. + return pkg;
  11790. +}
  11791. +
  11792. +/*
  11793. + * this will assume that we've already determined that
  11794. + * the abstract pkg doesn't exist, 'cause we should know these things...
  11795. + */
  11796. +static abstract_pkg_t * add_new_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name)
  11797. +{
  11798. + abstract_pkg_t * ab_pkg;
  11799. +
  11800. + ab_pkg = abstract_pkg_new();
  11801. + if (ab_pkg == NULL) { return NULL; }
  11802. +
  11803. + ab_pkg->name = strdup(pkg_name);
  11804. + hash_table_insert(hash, pkg_name, ab_pkg);
  11805. +
  11806. + return ab_pkg;
  11807. +}
  11808. +
  11809. +
  11810. +pkg_t *file_hash_get_file_owner(ipkg_conf_t *conf, const char *file_name)
  11811. +{
  11812. + hash_table_t *file_hash = &conf->file_hash;
  11813. +
  11814. + return hash_table_get(file_hash, file_name);
  11815. +}
  11816. +
  11817. +int file_hash_set_file_owner(ipkg_conf_t *conf, const char *file_name, pkg_t *owning_pkg)
  11818. +{
  11819. + hash_table_t *file_hash = &conf->file_hash;
  11820. + pkg_t *old_owning_pkg = hash_table_get(file_hash, file_name);
  11821. + int file_name_len = strlen(file_name);
  11822. +
  11823. + if (file_name[file_name_len -1] == '/')
  11824. + return 0;
  11825. +
  11826. + if (conf->offline_root) {
  11827. + int len = strlen(conf->offline_root);
  11828. + if (strncmp(file_name, conf->offline_root, len) == 0) {
  11829. + file_name += len;
  11830. + }
  11831. + }
  11832. +
  11833. + // ipkg_message(conf, IPKG_DEBUG2, "owning_pkg=%s filename=%s\n", owning_pkg->name, file_name);
  11834. + hash_table_insert(file_hash, file_name, owning_pkg);
  11835. + if (old_owning_pkg) {
  11836. + str_list_remove_elt(old_owning_pkg->installed_files, file_name);
  11837. + /* mark this package to have its filelist written */
  11838. + old_owning_pkg->state_flag |= SF_FILELIST_CHANGED;
  11839. + owning_pkg->state_flag |= SF_FILELIST_CHANGED;
  11840. + }
  11841. + return 0;
  11842. +}
  11843. +
  11844. +
  11845. diff -Nur busybox-1.16.1.orig/archival/libipkg/pkg_hash.h busybox-1.16.1/archival/libipkg/pkg_hash.h
  11846. --- busybox-1.16.1.orig/archival/libipkg/pkg_hash.h 1970-01-01 01:00:00.000000000 +0100
  11847. +++ busybox-1.16.1/archival/libipkg/pkg_hash.h 2010-04-22 19:18:12.000000000 +0200
  11848. @@ -0,0 +1,61 @@
  11849. +/* pkg_hash.h - the itsy package management system
  11850. +
  11851. + Steven M. Ayer
  11852. +
  11853. + Copyright (C) 2002 Compaq Computer Corporation
  11854. +
  11855. + This program is free software; you can redistribute it and/or
  11856. + modify it under the terms of the GNU General Public License as
  11857. + published by the Free Software Foundation; either version 2, or (at
  11858. + your option) any later version.
  11859. +
  11860. + This program is distributed in the hope that it will be useful, but
  11861. + WITHOUT ANY WARRANTY; without even the implied warranty of
  11862. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11863. + General Public License for more details.
  11864. +*/
  11865. +
  11866. +#ifndef PKG_HASH_H
  11867. +#define PKG_HASH_H
  11868. +
  11869. +#include "pkg.h"
  11870. +#include "pkg_vec.h"
  11871. +#include "hash_table.h"
  11872. +
  11873. +
  11874. +int pkg_hash_init(const char *name, hash_table_t *hash, int len);
  11875. +void pkg_hash_deinit(hash_table_t *hash);
  11876. +void pkg_hash_map(hash_table_t *hash, void (*f)(void *data, void *entry), void *data);
  11877. +
  11878. +void pkg_hash_dump(hash_table_t *hash, void *data);
  11879. +void pkg_hash_fetch_available(hash_table_t *hash, pkg_vec_t *available);
  11880. +
  11881. +int pkg_hash_add_from_file(ipkg_conf_t *conf, const char *file_name,
  11882. + pkg_src_t *src, pkg_dest_t *dest, int is_status_file);
  11883. +pkg_t *hash_insert_pkg(hash_table_t *hash, pkg_t *pkg, int set_status,ipkg_conf_t *conf);
  11884. +
  11885. +abstract_pkg_t * ensure_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name);
  11886. +abstract_pkg_t * abstract_pkg_fetch_by_name(hash_table_t * hash, const char * pkg_name);
  11887. +pkg_vec_t *pkg_hash_fetch_by_name(hash_table_t *hash, const char *pkg_name);
  11888. +void pkg_hash_fetch_all_installed(hash_table_t *hash, pkg_vec_t *installed);
  11889. +pkg_t * pkg_hash_fetch_by_name_version(hash_table_t *hash,
  11890. + const char *pkg_name,
  11891. + const char * version);
  11892. +abstract_pkg_vec_t *pkg_hash_fetch_all_installation_candidates(hash_table_t *hash, const char *name);
  11893. +pkg_t *pkg_hash_fetch_best_installation_candidate(ipkg_conf_t *conf, abstract_pkg_t *apkg,
  11894. + int (*constraint_fcn)(pkg_t *pkg, void *data), void *cdata, int quiet);
  11895. +pkg_t *pkg_hash_fetch_best_installation_candidate_by_name(ipkg_conf_t *conf, const char *name);
  11896. +pkg_t *pkg_hash_fetch_installed_by_name(hash_table_t *hash,
  11897. + const char *pkg_name);
  11898. +pkg_t *pkg_hash_fetch_installed_by_name_dest(hash_table_t *hash,
  11899. + const char *pkg_name,
  11900. + pkg_dest_t *dest);
  11901. +
  11902. +pkg_t *file_hash_get_file_owner(ipkg_conf_t *conf, const char *file_name);
  11903. +int file_hash_set_file_owner(ipkg_conf_t *conf, const char *file_name, pkg_t *pkg);
  11904. +
  11905. +/* XXX: shouldn't this go in pkg_vec.[ch]? */
  11906. +pkg_vec_t *pkg_vec_fetch_by_name(hash_table_t *hash, const char *pkg_name);
  11907. +
  11908. +#endif
  11909. +
  11910. diff -Nur busybox-1.16.1.orig/archival/libipkg/pkg_parse.c busybox-1.16.1/archival/libipkg/pkg_parse.c
  11911. --- busybox-1.16.1.orig/archival/libipkg/pkg_parse.c 1970-01-01 01:00:00.000000000 +0100
  11912. +++ busybox-1.16.1/archival/libipkg/pkg_parse.c 2010-04-22 19:18:12.000000000 +0200
  11913. @@ -0,0 +1,368 @@
  11914. +/* pkg_parse.c - the itsy package management system
  11915. +
  11916. + Steven M. Ayer
  11917. +
  11918. + Copyright (C) 2002 Compaq Computer Corporation
  11919. +
  11920. + This program is free software; you can redistribute it and/or
  11921. + modify it under the terms of the GNU General Public License as
  11922. + published by the Free Software Foundation; either version 2, or (at
  11923. + your option) any later version.
  11924. +
  11925. + This program is distributed in the hope that it will be useful, but
  11926. + WITHOUT ANY WARRANTY; without even the implied warranty of
  11927. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11928. + General Public License for more details.
  11929. +*/
  11930. +
  11931. +#include "ipkg.h"
  11932. +#include <errno.h>
  11933. +#include <ctype.h>
  11934. +
  11935. +#include "pkg.h"
  11936. +#include "ipkg_utils.h"
  11937. +#include "pkg_parse.h"
  11938. +
  11939. +int alterProvidesLine(char *raw, char *temp);
  11940. +
  11941. +int isGenericFieldType(char * type, char * line)
  11942. +{
  11943. + if(!strncmp(line, type, strlen(type)))
  11944. + return 1;
  11945. + return 0;
  11946. +}
  11947. +
  11948. +char * parseGenericFieldType(char * type, char * raw)
  11949. +{
  11950. + char * field_value = raw + (strlen(type) + 1);
  11951. + return trim_alloc(field_value);
  11952. +}
  11953. +
  11954. +void parseStatus(pkg_t *pkg, char * raw)
  11955. +{
  11956. + char sw_str[64], sf_str[64], ss_str[64];
  11957. +
  11958. + sscanf(raw, "Status: %s %s %s", sw_str, sf_str, ss_str);
  11959. + pkg->state_want = pkg_state_want_from_str(sw_str);
  11960. + pkg->state_flag = pkg_state_flag_from_str(sf_str);
  11961. + pkg->state_status = pkg_state_status_from_str(ss_str);
  11962. +}
  11963. +
  11964. +char ** parseDependsString(char * raw, int * depends_count)
  11965. +{
  11966. + char ** depends = NULL;
  11967. + int line_count = 0;
  11968. + char buff[2048], * dest;
  11969. +
  11970. + while(raw && *raw && !isspace(*raw)) {
  11971. + raw++;
  11972. + }
  11973. +
  11974. + if(line_is_blank(raw)){
  11975. + *depends_count = line_count;
  11976. + return NULL;
  11977. + }
  11978. + while(raw && *raw){
  11979. + depends = (char **)realloc(depends, sizeof(char *) * (line_count + 1));
  11980. +
  11981. + while(isspace(*raw)) raw++;
  11982. +
  11983. + dest = buff;
  11984. + while((*raw != ',') && *raw)
  11985. + *dest++ = *raw++;
  11986. +
  11987. + *dest = '\0';
  11988. + depends[line_count] = trim_alloc(buff);
  11989. + if(depends[line_count] ==NULL)
  11990. + return NULL;
  11991. + line_count++;
  11992. + if(*raw == ',')
  11993. + raw++;
  11994. + }
  11995. + *depends_count = line_count;
  11996. + return depends;
  11997. +}
  11998. +
  11999. +void parseConffiles(pkg_t * pkg, char * raw)
  12000. +{
  12001. + char file_name[1048], md5sum[1048]; /* please tell me there aren't any longer that 1k */
  12002. +
  12003. + if(!strncmp(raw, "Conffiles:", 10))
  12004. + raw += strlen("Conffiles:");
  12005. +
  12006. + while(*raw && (sscanf(raw, "%s%s", file_name, md5sum) == 2)){
  12007. + conffile_list_append(&pkg->conffiles, file_name, md5sum);
  12008. + /* fprintf(stderr, "%s %s ", file_name, md5sum);*/
  12009. + while (*raw && isspace(*raw)) {
  12010. + raw++;
  12011. + }
  12012. + raw += strlen(file_name);
  12013. + while (*raw && isspace(*raw)) {
  12014. + raw++;
  12015. + }
  12016. + raw += strlen(md5sum);
  12017. + }
  12018. +}
  12019. +
  12020. +int parseVersion(pkg_t *pkg, char *raw)
  12021. +{
  12022. + char *colon, *eepochcolon;
  12023. +#ifdef USE_DEBVERSION
  12024. + char *hyphen;
  12025. +#endif
  12026. + unsigned long epoch;
  12027. +
  12028. + if (!*raw) {
  12029. + fprintf(stderr, "%s: ERROR: version string is empty", __FUNCTION__);
  12030. + return EINVAL;
  12031. + }
  12032. +
  12033. + if (strncmp(raw, "Version:", 8) == 0) {
  12034. + raw += 8;
  12035. + }
  12036. + while (*raw && isspace(*raw)) {
  12037. + raw++;
  12038. + }
  12039. +
  12040. + colon= strchr(raw,':');
  12041. + if (colon) {
  12042. + epoch= strtoul(raw,&eepochcolon,10);
  12043. + if (colon != eepochcolon) {
  12044. + fprintf(stderr, "%s: ERROR: epoch in version is not number", __FUNCTION__);
  12045. + return EINVAL;
  12046. + }
  12047. + if (!*++colon) {
  12048. + fprintf(stderr, "%s: ERROR: nothing after colon in version number", __FUNCTION__);
  12049. + return EINVAL;
  12050. + }
  12051. + raw= colon;
  12052. + pkg->epoch= epoch;
  12053. + } else {
  12054. + pkg->epoch= 0;
  12055. + }
  12056. +
  12057. + pkg->revision = (char *)"";
  12058. + pkg->familiar_revision = (char *)"";
  12059. +
  12060. + pkg->version= malloc(strlen(raw)+1);
  12061. + if ( pkg->version == NULL ) {
  12062. + fprintf(stderr, "%s: out of memory \n", __FUNCTION__);
  12063. + return ENOMEM;
  12064. + }
  12065. + strcpy(pkg->version, raw);
  12066. +
  12067. +#ifdef USE_DEBVERSION
  12068. + hyphen= strrchr(pkg->version,'-');
  12069. +
  12070. + if (hyphen) {
  12071. + *hyphen++= 0;
  12072. + if (strncmp("fam", hyphen, 3) == 0) {
  12073. + pkg->familiar_revision=hyphen+3;
  12074. + hyphen= strrchr(pkg->version,'-');
  12075. + if (hyphen) {
  12076. + *hyphen++= 0;
  12077. + pkg->revision = hyphen;
  12078. + }
  12079. + } else {
  12080. + pkg->revision = hyphen;
  12081. + }
  12082. + }
  12083. +#endif
  12084. +
  12085. +/*
  12086. + fprintf(stderr,"Parsed version: %lu, %s, %s, %s\n",
  12087. + pkg->epoch,
  12088. + pkg->version,
  12089. + pkg->revision,
  12090. + pkg->familiar_revision);
  12091. +*/
  12092. +
  12093. + return 0;
  12094. +}
  12095. +
  12096. +
  12097. +/* This code is needed to insert in first position the keyword for the aligning bug */
  12098. +
  12099. +int alterProvidesLine(char *raw, char *temp)
  12100. +{
  12101. +
  12102. +
  12103. + if (!*raw) {
  12104. + fprintf(stderr, "%s: ERROR: Provides string is empty", __FUNCTION__);
  12105. + return -EINVAL;
  12106. + }
  12107. +
  12108. + if ( temp == NULL ) {
  12109. + fprintf(stderr, "%s: out of memory \n", __FUNCTION__);
  12110. + return -ENOMEM;
  12111. + }
  12112. +
  12113. + if (strncmp(raw, "Provides:", 9) == 0) {
  12114. + raw += 9;
  12115. + }
  12116. + while (*raw && isspace(*raw)) {
  12117. + raw++;
  12118. + }
  12119. +
  12120. + snprintf ( temp, 35, "Provides: ipkg_internal_use_only, "); /* First part of the line */
  12121. + while (*raw) {
  12122. + strncat( temp, raw++, 1);
  12123. + }
  12124. + return 0;
  12125. +
  12126. +}
  12127. +
  12128. +/* Some random thoughts from Carl:
  12129. +
  12130. + This function could be considerably simplified if we just kept
  12131. + an array of all the generic string-valued field names, and looped
  12132. + through those looking for a match. Also, these fields could perhaps
  12133. + be stored in the package as an array as well, (or, probably better,
  12134. + as an nv_pair_list_t).
  12135. +
  12136. + Fields which require special parsing or storage, (such as Depends:
  12137. + and Status:) could be handled as they are now.
  12138. +*/
  12139. +/* XXX: FEATURE: The Suggests: field needs to be changed from a string
  12140. + to a dependency list. And, since we already have
  12141. + Depends/Pre-Depends and need to add Conflicts, Recommends, and
  12142. + Enhances, perhaps we could generalize all of these and save some
  12143. + code duplication.
  12144. +*/
  12145. +int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest)
  12146. +{
  12147. + int reading_conffiles, reading_description;
  12148. + int pkg_false_provides=1;
  12149. + char ** lines;
  12150. + char * provide=NULL;
  12151. +
  12152. + pkg->src = src;
  12153. + pkg->dest = dest;
  12154. +
  12155. + reading_conffiles = reading_description = 0;
  12156. +
  12157. + for (lines = *raw; *lines; lines++) {
  12158. + /* fprintf(stderr, "PARSING %s\n", *lines);*/
  12159. + if(isGenericFieldType((char *)"Package:", *lines))
  12160. + pkg->name = parseGenericFieldType((char *)"Package", *lines);
  12161. + else if(isGenericFieldType((char *)"Architecture:", *lines))
  12162. + pkg->architecture = parseGenericFieldType((char *)"Architecture", *lines);
  12163. + else if(isGenericFieldType((char *)"Filename:", *lines))
  12164. + pkg->filename = parseGenericFieldType((char *)"Filename", *lines);
  12165. + else if(isGenericFieldType((char *)"Section:", *lines))
  12166. + pkg->section = parseGenericFieldType((char *)"Section", *lines);
  12167. + else if(isGenericFieldType((char *)"MD5sum:", *lines))
  12168. + pkg->md5sum = parseGenericFieldType((char *)"MD5sum", *lines);
  12169. + /* The old ipkg wrote out status files with the wrong case for MD5sum,
  12170. + let's parse it either way */
  12171. + else if(isGenericFieldType((char *)"MD5Sum:", *lines))
  12172. + pkg->md5sum = parseGenericFieldType((char *)"MD5Sum", *lines);
  12173. + else if(isGenericFieldType((char *)"Size:", *lines))
  12174. + pkg->size = parseGenericFieldType((char *)"Size", *lines);
  12175. + else if(isGenericFieldType((char *)"Source:", *lines))
  12176. + pkg->source = parseGenericFieldType((char *)"Source", *lines);
  12177. + else if(isGenericFieldType((char *)"Installed-Size:", *lines))
  12178. + pkg->installed_size = parseGenericFieldType((char *)"Installed-Size", *lines);
  12179. + else if(isGenericFieldType((char *)"Installed-Time:", *lines)) {
  12180. + char *time_str = parseGenericFieldType((char *)"Installed-Time", *lines);
  12181. + pkg->installed_time = strtoul(time_str, NULL, 0);
  12182. + } else if(isGenericFieldType((char *)"Priority:", *lines))
  12183. + pkg->priority = parseGenericFieldType((char *)"Priority", *lines);
  12184. + else if(isGenericFieldType((char *)"Essential:", *lines)) {
  12185. + char *essential_value;
  12186. + essential_value = parseGenericFieldType((char *)"Essential", *lines);
  12187. + if (strcmp(essential_value, "yes") == 0) {
  12188. + pkg->essential = 1;
  12189. + }
  12190. + free(essential_value);
  12191. + }
  12192. + else if(isGenericFieldType((char *)"Status", *lines))
  12193. + parseStatus(pkg, *lines);
  12194. + else if(isGenericFieldType((char *)"Version", *lines))
  12195. + parseVersion(pkg, *lines);
  12196. + else if(isGenericFieldType((char *)"Maintainer", *lines))
  12197. + pkg->maintainer = parseGenericFieldType((char *)"Maintainer", *lines);
  12198. + else if(isGenericFieldType((char *)"Conffiles", *lines)){
  12199. + parseConffiles(pkg, *lines);
  12200. + reading_conffiles = 1;
  12201. + }
  12202. + else if(isGenericFieldType((char *)"Description", *lines)) {
  12203. + pkg->description = parseGenericFieldType((char *)"Description", *lines);
  12204. + reading_conffiles = 0;
  12205. + reading_description = 1;
  12206. + }
  12207. +
  12208. + else if(isGenericFieldType((char *)"Provides", *lines)){
  12209. +/* Here we add the internal_use to align the off by one problem between provides_str and provides */
  12210. + provide = (char * ) malloc(strlen(*lines)+ 35 ); /* Preparing the space for the new ipkg_internal_use_only */
  12211. + if ( alterProvidesLine(*lines,provide) ){
  12212. + return EINVAL;
  12213. + }
  12214. + pkg->provides_str = parseDependsString( provide, &pkg->provides_count);
  12215. +/* Let's try to hack a bit here.
  12216. + The idea is that if a package has no Provides, we would add one generic, to permit the check of dependencies
  12217. + in alot of other places. We will remove it before writing down the status database */
  12218. + pkg_false_provides=0;
  12219. + free(provide);
  12220. + }
  12221. +
  12222. + else if(isGenericFieldType((char *)"Depends", *lines))
  12223. + pkg->depends_str = parseDependsString(*lines, &pkg->depends_count);
  12224. + else if(isGenericFieldType((char *)"Pre-Depends", *lines))
  12225. + pkg->pre_depends_str = parseDependsString(*lines, &pkg->pre_depends_count);
  12226. + else if(isGenericFieldType((char *)"Recommends", *lines))
  12227. + pkg->recommends_str = parseDependsString(*lines, &pkg->recommends_count);
  12228. + else if(isGenericFieldType((char *)"Suggests", *lines))
  12229. + pkg->suggests_str = parseDependsString(*lines, &pkg->suggests_count);
  12230. + /* Abhaya: support for conflicts */
  12231. + else if(isGenericFieldType((char *)"Conflicts", *lines))
  12232. + pkg->conflicts_str = parseDependsString(*lines, &pkg->conflicts_count);
  12233. + else if(isGenericFieldType((char *)"Replaces", *lines))
  12234. + pkg->replaces_str = parseDependsString(*lines, &pkg->replaces_count);
  12235. + else if(line_is_blank(*lines)) {
  12236. + lines++;
  12237. + break;
  12238. + }
  12239. + else if(**lines == ' '){
  12240. + if(reading_description) {
  12241. + /* we already know it's not blank, so the rest of description */
  12242. + pkg->description = realloc(pkg->description,
  12243. + strlen(pkg->description)
  12244. + + 1 + strlen(*lines) + 1);
  12245. + strcat(pkg->description, "\n");
  12246. + strcat(pkg->description, (*lines));
  12247. + }
  12248. + else if(reading_conffiles)
  12249. + parseConffiles(pkg, *lines);
  12250. + }
  12251. + }
  12252. + *raw = lines;
  12253. +/* If the ipk has not a Provides line, we insert our false line */
  12254. + if ( pkg_false_provides==1)
  12255. + pkg->provides_str = parseDependsString ((char *)"Provides: ipkg_internal_use_only ", &pkg->provides_count);
  12256. +
  12257. + if (pkg->name) {
  12258. + return 0;
  12259. + } else {
  12260. + return EINVAL;
  12261. + }
  12262. +}
  12263. +
  12264. +int pkg_valorize_other_field(pkg_t *pkg, char ***raw)
  12265. +{
  12266. + char ** lines;
  12267. +
  12268. + for (lines = *raw; *lines; lines++) {
  12269. + 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. + }
  12278. + *raw = lines;
  12279. +
  12280. + return 0;
  12281. +}
  12282. diff -Nur busybox-1.16.1.orig/archival/libipkg/pkg_parse.h busybox-1.16.1/archival/libipkg/pkg_parse.h
  12283. --- busybox-1.16.1.orig/archival/libipkg/pkg_parse.h 1970-01-01 01:00:00.000000000 +0100
  12284. +++ busybox-1.16.1/archival/libipkg/pkg_parse.h 2010-04-22 19:18:12.000000000 +0200
  12285. @@ -0,0 +1,31 @@
  12286. +/* pkg_parse.h - the itsy package management system
  12287. +
  12288. + Steven M. Ayer
  12289. +
  12290. + Copyright (C) 2002 Compaq Computer Corporation
  12291. +
  12292. + This program is free software; you can redistribute it and/or
  12293. + modify it under the terms of the GNU General Public License as
  12294. + published by the Free Software Foundation; either version 2, or (at
  12295. + your option) any later version.
  12296. +
  12297. + This program is distributed in the hope that it will be useful, but
  12298. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12299. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12300. + General Public License for more details.
  12301. +*/
  12302. +
  12303. +#ifndef PKG_PARSE_H
  12304. +#define PKG_PARSE_H
  12305. +
  12306. +int isGenericFieldType(char * type, char * line);
  12307. +char * parseGenericFieldType(char * type, char * raw);
  12308. +void parseStatus(pkg_t *pkg, char * raw);
  12309. +int parseVersion(pkg_t *pkg, char *raw);
  12310. +char ** parseDependsString(char * raw, int * depends_count);
  12311. +int parseVersion(pkg_t *pkg, char *raw);
  12312. +void parseConffiles(pkg_t * pkg, char * raw);
  12313. +int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest);
  12314. +int pkg_valorize_other_field(pkg_t *pkg, char ***raw);
  12315. +
  12316. +#endif
  12317. diff -Nur busybox-1.16.1.orig/archival/libipkg/pkg_src.c busybox-1.16.1/archival/libipkg/pkg_src.c
  12318. --- busybox-1.16.1.orig/archival/libipkg/pkg_src.c 1970-01-01 01:00:00.000000000 +0100
  12319. +++ busybox-1.16.1/archival/libipkg/pkg_src.c 2010-04-22 19:18:12.000000000 +0200
  12320. @@ -0,0 +1,43 @@
  12321. +/* pkg_src.c - the itsy package management system
  12322. +
  12323. + Carl D. Worth
  12324. +
  12325. + Copyright (C) 2001 University of Southern California
  12326. +
  12327. + This program is free software; you can redistribute it and/or
  12328. + modify it under the terms of the GNU General Public License as
  12329. + published by the Free Software Foundation; either version 2, or (at
  12330. + your option) any later version.
  12331. +
  12332. + This program is distributed in the hope that it will be useful, but
  12333. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12334. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12335. + General Public License for more details.
  12336. +*/
  12337. +
  12338. +#include "ipkg.h"
  12339. +
  12340. +#include "pkg_src.h"
  12341. +#include "str_util.h"
  12342. +
  12343. +int pkg_src_init(pkg_src_t *src, const char *name, const char *base_url, const char *extra_data, int gzip)
  12344. +{
  12345. + src->gzip = gzip;
  12346. + src->name = str_dup_safe (name);
  12347. + src->value = str_dup_safe (base_url);
  12348. + if (extra_data)
  12349. + src->extra_data = str_dup_safe (extra_data);
  12350. + else
  12351. + src->extra_data = NULL;
  12352. + return 0;
  12353. +}
  12354. +
  12355. +void pkg_src_deinit(pkg_src_t *src)
  12356. +{
  12357. + free (src->name);
  12358. + free (src->value);
  12359. + if (src->extra_data)
  12360. + free (src->extra_data);
  12361. +}
  12362. +
  12363. +
  12364. diff -Nur busybox-1.16.1.orig/archival/libipkg/pkg_src.h busybox-1.16.1/archival/libipkg/pkg_src.h
  12365. --- busybox-1.16.1.orig/archival/libipkg/pkg_src.h 1970-01-01 01:00:00.000000000 +0100
  12366. +++ busybox-1.16.1/archival/libipkg/pkg_src.h 2010-04-22 19:18:12.000000000 +0200
  12367. @@ -0,0 +1,34 @@
  12368. +/* pkg_src.h - the itsy package management system
  12369. +
  12370. + Carl D. Worth
  12371. +
  12372. + Copyright (C) 2001 University of Southern California
  12373. +
  12374. + This program is free software; you can redistribute it and/or
  12375. + modify it under the terms of the GNU General Public License as
  12376. + published by the Free Software Foundation; either version 2, or (at
  12377. + your option) any later version.
  12378. +
  12379. + This program is distributed in the hope that it will be useful, but
  12380. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12381. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12382. + General Public License for more details.
  12383. +*/
  12384. +
  12385. +#ifndef PKG_SRC_H
  12386. +#define PKG_SRC_H
  12387. +
  12388. +#include "nv_pair.h"
  12389. +
  12390. +typedef struct
  12391. +{
  12392. + char *name;
  12393. + char *value;
  12394. + char *extra_data;
  12395. + int gzip;
  12396. +} pkg_src_t;
  12397. +
  12398. +int pkg_src_init(pkg_src_t *src, const char *name, const char *base_url, const char *extra_data, int gzip);
  12399. +void pkg_src_deinit(pkg_src_t *src);
  12400. +
  12401. +#endif
  12402. diff -Nur busybox-1.16.1.orig/archival/libipkg/pkg_src_list.c busybox-1.16.1/archival/libipkg/pkg_src_list.c
  12403. --- busybox-1.16.1.orig/archival/libipkg/pkg_src_list.c 1970-01-01 01:00:00.000000000 +0100
  12404. +++ busybox-1.16.1/archival/libipkg/pkg_src_list.c 2010-04-22 19:18:12.000000000 +0200
  12405. @@ -0,0 +1,75 @@
  12406. +/* pkg_src_list.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_list.h"
  12426. +#include "void_list.h"
  12427. +
  12428. +int pkg_src_list_init(pkg_src_list_t *list)
  12429. +{
  12430. + return void_list_init((void_list_t *) list);
  12431. +}
  12432. +
  12433. +void pkg_src_list_deinit(pkg_src_list_t *list)
  12434. +{
  12435. + pkg_src_list_elt_t *iter;
  12436. + pkg_src_t *pkg_src;
  12437. +
  12438. + for (iter = list->head; iter; iter = iter->next) {
  12439. + pkg_src = iter->data;
  12440. + pkg_src_deinit(pkg_src);
  12441. +
  12442. + /* malloced in pkg_src_list_append */
  12443. + free(pkg_src);
  12444. + iter->data = NULL;
  12445. + }
  12446. + void_list_deinit((void_list_t *) list);
  12447. +}
  12448. +
  12449. +pkg_src_t *pkg_src_list_append(pkg_src_list_t *list,
  12450. + const char *name, const char *base_url, const char *extra_data,
  12451. + int gzip)
  12452. +{
  12453. + int err;
  12454. +
  12455. + /* freed in pkg_src_list_deinit */
  12456. + pkg_src_t *pkg_src = malloc(sizeof(pkg_src_t));
  12457. +
  12458. + if (pkg_src == NULL) {
  12459. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  12460. + return NULL;
  12461. + }
  12462. + pkg_src_init(pkg_src, name, base_url, extra_data, gzip);
  12463. +
  12464. + err = void_list_append((void_list_t *) list, pkg_src);
  12465. + if (err) {
  12466. + return NULL;
  12467. + }
  12468. +
  12469. + return pkg_src;
  12470. +}
  12471. +
  12472. +int pkg_src_list_push(pkg_src_list_t *list, pkg_src_t *data)
  12473. +{
  12474. + return void_list_push((void_list_t *) list, data);
  12475. +}
  12476. +
  12477. +pkg_src_list_elt_t *pkg_src_list_pop(pkg_src_list_t *list)
  12478. +{
  12479. + return (pkg_src_list_elt_t *) void_list_pop((void_list_t *) list);
  12480. +}
  12481. diff -Nur busybox-1.16.1.orig/archival/libipkg/pkg_src_list.h busybox-1.16.1/archival/libipkg/pkg_src_list.h
  12482. --- busybox-1.16.1.orig/archival/libipkg/pkg_src_list.h 1970-01-01 01:00:00.000000000 +0100
  12483. +++ busybox-1.16.1/archival/libipkg/pkg_src_list.h 2010-04-22 19:18:12.000000000 +0200
  12484. @@ -0,0 +1,57 @@
  12485. +/* pkg_src_list.h - the itsy package management system
  12486. +
  12487. + Carl D. Worth
  12488. +
  12489. + Copyright (C) 2001 University of Southern California
  12490. +
  12491. + This program is free software; you can redistribute it and/or
  12492. + modify it under the terms of the GNU General Public License as
  12493. + published by the Free Software Foundation; either version 2, or (at
  12494. + your option) any later version.
  12495. +
  12496. + This program is distributed in the hope that it will be useful, but
  12497. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12498. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12499. + General Public License for more details.
  12500. +*/
  12501. +
  12502. +#ifndef PKG_SRC_LIST_H
  12503. +#define PKG_SRC_LIST_H
  12504. +
  12505. +#include "pkg_src.h"
  12506. +
  12507. +typedef struct pkg_src_list_elt pkg_src_list_elt_t;
  12508. +struct pkg_src_list_elt
  12509. +{
  12510. + pkg_src_list_elt_t *next;
  12511. + pkg_src_t *data;
  12512. +};
  12513. +
  12514. +typedef struct pkg_src_list pkg_src_list_t;
  12515. +struct pkg_src_list
  12516. +{
  12517. + pkg_src_list_elt_t pre_head;
  12518. + pkg_src_list_elt_t *head;
  12519. + pkg_src_list_elt_t *tail;
  12520. +};
  12521. +
  12522. +static inline int pkg_src_list_empty(pkg_src_list_t *list)
  12523. +{
  12524. + if (list->head == NULL)
  12525. + return 1;
  12526. + else
  12527. + return 0;
  12528. +}
  12529. +
  12530. +int pkg_src_list_elt_init(pkg_src_list_elt_t *elt, nv_pair_t *data);
  12531. +void pkg_src_list_elt_deinit(pkg_src_list_elt_t *elt);
  12532. +
  12533. +int pkg_src_list_init(pkg_src_list_t *list);
  12534. +void pkg_src_list_deinit(pkg_src_list_t *list);
  12535. +
  12536. +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);
  12537. +int pkg_src_list_push(pkg_src_list_t *list, pkg_src_t *data);
  12538. +pkg_src_list_elt_t *pkg_src_list_pop(pkg_src_list_t *list);
  12539. +
  12540. +#endif
  12541. +
  12542. diff -Nur busybox-1.16.1.orig/archival/libipkg/pkg_vec.c busybox-1.16.1/archival/libipkg/pkg_vec.c
  12543. --- busybox-1.16.1.orig/archival/libipkg/pkg_vec.c 1970-01-01 01:00:00.000000000 +0100
  12544. +++ busybox-1.16.1/archival/libipkg/pkg_vec.c 2010-04-22 19:18:12.000000000 +0200
  12545. @@ -0,0 +1,231 @@
  12546. +/* pkg_vec.c - the itsy package management system
  12547. +
  12548. + Steven M. Ayer
  12549. +
  12550. + Copyright (C) 2002 Compaq Computer Corporation
  12551. +
  12552. + This program is free software; you can redistribute it and/or
  12553. + modify it under the terms of the GNU General Public License as
  12554. + published by the Free Software Foundation; either version 2, or (at
  12555. + your option) any later version.
  12556. +
  12557. + This program is distributed in the hope that it will be useful, but
  12558. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12559. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12560. + General Public License for more details.
  12561. +*/
  12562. +
  12563. +#include <stdlib.h>
  12564. +#include <fnmatch.h>
  12565. +#include "libbb.h"
  12566. +#include "xregex.h"
  12567. +#include "ipkg.h"
  12568. +#include "pkg.h"
  12569. +
  12570. +pkg_vec_t * pkg_vec_alloc(void)
  12571. +{
  12572. + pkg_vec_t * vec = (pkg_vec_t *)malloc(sizeof(pkg_vec_t));
  12573. + if (!vec) {
  12574. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  12575. + return NULL;
  12576. + }
  12577. + vec->pkgs = NULL;
  12578. + vec->len = 0;
  12579. +
  12580. + return vec;
  12581. +}
  12582. +
  12583. +void pkg_vec_free(pkg_vec_t *vec)
  12584. +{
  12585. + free(vec->pkgs);
  12586. + free(vec);
  12587. +}
  12588. +
  12589. +/*
  12590. + * assumption: all names in a vector are identical
  12591. + * assumption: all version strings are trimmed,
  12592. + * so identical versions have identical version strings,
  12593. + * implying identical packages; let's marry these
  12594. + */
  12595. +pkg_t *pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status,ipkg_conf_t *conf)
  12596. +{
  12597. + int i;
  12598. + int found = 0;
  12599. +
  12600. + /* look for a duplicate pkg by name, version, and architecture */
  12601. + for (i = 0; i < vec->len; i++){
  12602. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Found pkg=%s version=%s arch=%s cmp=%s version=%s arch=%s \n",
  12603. + __FUNCTION__, pkg->name, pkg->version, pkg->architecture,
  12604. + vec->pkgs[i]->name, vec->pkgs[i]->version,vec->pkgs[i]->architecture );
  12605. + if ((strcmp(pkg->name, vec->pkgs[i]->name) == 0)
  12606. + && (pkg_compare_versions(pkg, vec->pkgs[i]) == 0)
  12607. + && (strcmp(pkg->architecture, vec->pkgs[i]->architecture) == 0)) {
  12608. + found = 1;
  12609. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Found duplicate for pkg=%s version=%s arch=%s\n",
  12610. + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
  12611. + break;
  12612. + }
  12613. + }
  12614. +
  12615. + /* we didn't find one, add it */
  12616. + if (!found){
  12617. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Adding new pkg=%s version=%s arch=%s\n",
  12618. + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
  12619. +
  12620. + vec->pkgs = (pkg_t **)realloc(vec->pkgs, (vec->len + 1) * sizeof(pkg_t *));
  12621. + vec->pkgs[vec->len] = pkg;
  12622. + vec->len++;
  12623. + return pkg;
  12624. + }
  12625. + /* update the one that we have */
  12626. + else {
  12627. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. calling pkg_merge for pkg=%s version=%s arch=%s",
  12628. + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
  12629. + if (set_status) {
  12630. + /* this is from the status file, so need to merge with existing database */
  12631. + ipkg_message(conf, IPKG_DEBUG2, " with set_status\n");
  12632. + pkg_merge(vec->pkgs[i], pkg, set_status);
  12633. + /* XXX: CLEANUP: It's not so polite to free something here
  12634. + that was passed in from above. */
  12635. + pkg_deinit(pkg);
  12636. + free(pkg);
  12637. + } else {
  12638. + ipkg_message(conf, IPKG_DEBUG2, " WITHOUT set_status\n");
  12639. + /* just overwrite the old one */
  12640. + pkg_deinit(vec->pkgs[i]);
  12641. + free(vec->pkgs[i]);
  12642. + vec->pkgs[i] = pkg;
  12643. + }
  12644. + return vec->pkgs[i];
  12645. + }
  12646. +}
  12647. +
  12648. +void pkg_vec_insert(pkg_vec_t *vec, const pkg_t *pkg)
  12649. +{
  12650. + int i;
  12651. + int found = 0;
  12652. +
  12653. + /* look for a duplicate pkg by name, version, and architecture */
  12654. + for (i = 0; i < vec->len; i++)
  12655. + if ((strcmp(pkg->name, vec->pkgs[i]->name) == 0)
  12656. + && (pkg_compare_versions(pkg, vec->pkgs[i]) == 0)
  12657. + && (strcmp(pkg->architecture, vec->pkgs[i]->name) == 0)) {
  12658. + found = 1;
  12659. + break;
  12660. + }
  12661. +
  12662. + /* we didn't find one, add it */
  12663. + if(!found){
  12664. + vec->pkgs = (pkg_t **)realloc(vec->pkgs, (vec->len + 1) * sizeof(pkg_t *));
  12665. + *(const pkg_t **)&vec->pkgs[vec->len] = pkg;
  12666. + vec->len++;
  12667. + }
  12668. +}
  12669. +
  12670. +int pkg_vec_contains(pkg_vec_t *vec, pkg_t *apkg)
  12671. +{
  12672. + int i;
  12673. + for (i = 0; i < vec->len; i++)
  12674. + if (vec->pkgs[i] == apkg)
  12675. + return 1;
  12676. + return 0;
  12677. +}
  12678. +
  12679. +typedef int (*compare_fcn_t)(const void *, const void *);
  12680. +void pkg_vec_sort(pkg_vec_t *vec, int (*compar)(pkg_t *, pkg_t *))
  12681. +{
  12682. + qsort(vec->pkgs, vec->len, sizeof(pkg_t *), (compare_fcn_t)compar);
  12683. +}
  12684. +
  12685. +int pkg_vec_clear_marks(pkg_vec_t *vec)
  12686. +{
  12687. + int npkgs = vec->len;
  12688. + int i;
  12689. + for (i = 0; i < npkgs; i++) {
  12690. + pkg_t *pkg = vec->pkgs[i];
  12691. + pkg->state_flag &= ~SF_MARKED;
  12692. + }
  12693. + return 0;
  12694. +}
  12695. +
  12696. +int pkg_vec_mark_if_matches(pkg_vec_t *vec, const char *pattern)
  12697. +{
  12698. + int matching_count = 0;
  12699. + pkg_t **pkgs = vec->pkgs;
  12700. + int npkgs = vec->len;
  12701. + int i;
  12702. + for (i = 0; i < npkgs; i++) {
  12703. + pkg_t *pkg = pkgs[i];
  12704. + if (fnmatch(pattern, pkg->name, 0)==0) {
  12705. + pkg->state_flag |= SF_MARKED;
  12706. + matching_count++;
  12707. + }
  12708. + }
  12709. + return matching_count;
  12710. +}
  12711. +
  12712. +
  12713. +abstract_pkg_vec_t * abstract_pkg_vec_alloc(void)
  12714. +{
  12715. + abstract_pkg_vec_t * vec ;
  12716. + vec = (abstract_pkg_vec_t *)malloc(sizeof(abstract_pkg_vec_t));
  12717. + if (!vec) {
  12718. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  12719. + return NULL;
  12720. + }
  12721. + vec->pkgs = NULL;
  12722. + vec->len = 0;
  12723. +
  12724. + return vec;
  12725. +}
  12726. +
  12727. +void abstract_pkg_vec_free(abstract_pkg_vec_t *vec)
  12728. +{
  12729. + free(vec->pkgs);
  12730. + free(vec);
  12731. +}
  12732. +
  12733. +/*
  12734. + * assumption: all names in a vector are unique
  12735. + */
  12736. +void abstract_pkg_vec_insert(abstract_pkg_vec_t *vec, abstract_pkg_t *pkg)
  12737. +{
  12738. + int i;
  12739. +
  12740. + /* look for a duplicate pkg by name */
  12741. + for(i = 0; i < vec->len; i++)
  12742. + if (strcmp(pkg->name, vec->pkgs[i]->name) == 0)
  12743. + break;
  12744. +
  12745. + /* we didn't find one, add it */
  12746. + if(i == vec->len){
  12747. + vec->pkgs =
  12748. + (abstract_pkg_t **)
  12749. + realloc(vec->pkgs, (vec->len + 1) * sizeof(abstract_pkg_t *));
  12750. + vec->pkgs[vec->len] = pkg;
  12751. + vec->len++;
  12752. + }
  12753. +}
  12754. +
  12755. +abstract_pkg_t * abstract_pkg_vec_get(abstract_pkg_vec_t *vec, int i)
  12756. +{
  12757. + if (vec->len > i)
  12758. + return vec->pkgs[i];
  12759. + else
  12760. + return NULL;
  12761. +}
  12762. +
  12763. +int abstract_pkg_vec_contains(abstract_pkg_vec_t *vec, abstract_pkg_t *apkg)
  12764. +{
  12765. + int i;
  12766. + for (i = 0; i < vec->len; i++)
  12767. + if (vec->pkgs[i] == apkg)
  12768. + return 1;
  12769. + return 0;
  12770. +}
  12771. +
  12772. +void abstract_pkg_vec_sort(pkg_vec_t *vec, int (*compar)(abstract_pkg_t *, abstract_pkg_t *))
  12773. +{
  12774. + qsort(vec->pkgs, vec->len, sizeof(pkg_t *), (compare_fcn_t)compar);
  12775. +}
  12776. +
  12777. diff -Nur busybox-1.16.1.orig/archival/libipkg/pkg_vec.h busybox-1.16.1/archival/libipkg/pkg_vec.h
  12778. --- busybox-1.16.1.orig/archival/libipkg/pkg_vec.h 1970-01-01 01:00:00.000000000 +0100
  12779. +++ busybox-1.16.1/archival/libipkg/pkg_vec.h 2010-04-22 19:18:12.000000000 +0200
  12780. @@ -0,0 +1,62 @@
  12781. +/* pkg_vec.h - the itsy package management system
  12782. +
  12783. + Steven M. Ayer
  12784. +
  12785. + Copyright (C) 2002 Compaq Computer Corporation
  12786. +
  12787. + This program is free software; you can redistribute it and/or
  12788. + modify it under the terms of the GNU General Public License as
  12789. + published by the Free Software Foundation; either version 2, or (at
  12790. + your option) any later version.
  12791. +
  12792. + This program is distributed in the hope that it will be useful, but
  12793. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12794. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12795. + General Public License for more details.
  12796. +*/
  12797. +
  12798. +#ifndef PKG_VEC_H
  12799. +#define PKG_VEC_H
  12800. +
  12801. +typedef struct pkg pkg_t;
  12802. +typedef struct abstract_pkg abstract_pkg_t;
  12803. +
  12804. +struct pkg_vec
  12805. +{
  12806. + pkg_t **pkgs;
  12807. + int len;
  12808. +};
  12809. +typedef struct pkg_vec pkg_vec_t;
  12810. +
  12811. +struct abstract_pkg_vec
  12812. +{
  12813. + abstract_pkg_t **pkgs;
  12814. + int len;
  12815. +};
  12816. +typedef struct abstract_pkg_vec abstract_pkg_vec_t;
  12817. +
  12818. +
  12819. +pkg_vec_t * pkg_vec_alloc(void);
  12820. +void pkg_vec_free(pkg_vec_t *vec);
  12821. +void marry_two_packages(pkg_t * newpkg, pkg_t * oldpkg);
  12822. +
  12823. +void pkg_vec_add(pkg_vec_t *vec, pkg_t *pkg);
  12824. +/* pkg_vec_insert_merge: might munge pkg.
  12825. +* returns the pkg that is in the pkg graph */
  12826. +pkg_t *pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status, ipkg_conf_t *conf);
  12827. +/* this one never munges pkg */
  12828. +void pkg_vec_insert(pkg_vec_t *vec, const pkg_t *pkg);
  12829. +int pkg_vec_contains(pkg_vec_t *vec, pkg_t *apkg);
  12830. +void pkg_vec_sort(pkg_vec_t *vec, int (*compar)(pkg_t *, pkg_t *));
  12831. +
  12832. +int pkg_vec_clear_marks(pkg_vec_t *vec);
  12833. +int pkg_vec_mark_if_matches(pkg_vec_t *vec, const char *pattern);
  12834. +
  12835. +abstract_pkg_vec_t * abstract_pkg_vec_alloc(void);
  12836. +void abstract_pkg_vec_free(abstract_pkg_vec_t *vec);
  12837. +void abstract_pkg_vec_insert(abstract_pkg_vec_t *vec, abstract_pkg_t *pkg);
  12838. +abstract_pkg_t * abstract_pkg_vec_get(abstract_pkg_vec_t *vec, int i);
  12839. +int abstract_pkg_vec_contains(abstract_pkg_vec_t *vec, abstract_pkg_t *apkg);
  12840. +void abstract_pkg_vec_sort(pkg_vec_t *vec, int (*compar)(abstract_pkg_t *, abstract_pkg_t *));
  12841. +#endif
  12842. +
  12843. diff -Nur busybox-1.16.1.orig/archival/libipkg/sprintf_alloc.h busybox-1.16.1/archival/libipkg/sprintf_alloc.h
  12844. --- busybox-1.16.1.orig/archival/libipkg/sprintf_alloc.h 1970-01-01 01:00:00.000000000 +0100
  12845. +++ busybox-1.16.1/archival/libipkg/sprintf_alloc.h 2010-04-22 19:18:12.000000000 +0200
  12846. @@ -0,0 +1,25 @@
  12847. +/* sprintf_alloca.c -- like sprintf with memory allocation
  12848. +
  12849. + Carl D. Worth
  12850. +
  12851. + Copyright (C) 2001 University of Southern California
  12852. +
  12853. + This program is free software; you can redistribute it and/or modify
  12854. + it under the terms of the GNU General Public License as published by
  12855. + the Free Software Foundation; either version 2, or (at your option)
  12856. + any later version.
  12857. +
  12858. + This program is distributed in the hope that it will be useful,
  12859. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  12860. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12861. + GNU General Public License for more details.
  12862. +*/
  12863. +
  12864. +#ifndef SPRINTF_ALLOC_H
  12865. +#define SPRINTF_ALLOC_H
  12866. +
  12867. +#include "libbb.h"
  12868. +
  12869. +#define sprintf_alloc(str, fmt, args...) *str = xasprintf(fmt, ## args)
  12870. +
  12871. +#endif
  12872. diff -Nur busybox-1.16.1.orig/archival/libipkg/str_list.c busybox-1.16.1/archival/libipkg/str_list.c
  12873. --- busybox-1.16.1.orig/archival/libipkg/str_list.c 1970-01-01 01:00:00.000000000 +0100
  12874. +++ busybox-1.16.1/archival/libipkg/str_list.c 2010-04-22 19:18:12.000000000 +0200
  12875. @@ -0,0 +1,76 @@
  12876. +/* str_list.c - the itsy package management system
  12877. +
  12878. + Carl D. Worth
  12879. +
  12880. + Copyright (C) 2001 University of Southern California
  12881. +
  12882. + This program is free software; you can redistribute it and/or
  12883. + modify it under the terms of the GNU General Public License as
  12884. + published by the Free Software Foundation; either version 2, or (at
  12885. + your option) any later version.
  12886. +
  12887. + This program is distributed in the hope that it will be useful, but
  12888. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12889. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12890. + General Public License for more details.
  12891. +*/
  12892. +
  12893. +#include "ipkg.h"
  12894. +
  12895. +#include "str_list.h"
  12896. +
  12897. +int str_list_elt_init(str_list_elt_t *elt, char *data)
  12898. +{
  12899. + return void_list_elt_init((void_list_elt_t *) elt, data);
  12900. +}
  12901. +
  12902. +void str_list_elt_deinit(str_list_elt_t *elt)
  12903. +{
  12904. + void_list_elt_deinit((void_list_elt_t *) elt);
  12905. +}
  12906. +
  12907. +str_list_t *str_list_alloc(void)
  12908. +{
  12909. + str_list_t *list = (str_list_t *)malloc(sizeof(str_list_t));
  12910. + if (list)
  12911. + str_list_init(list);
  12912. + return list;
  12913. +}
  12914. +
  12915. +int str_list_init(str_list_t *list)
  12916. +{
  12917. + return void_list_init((void_list_t *) list);
  12918. +}
  12919. +
  12920. +void str_list_deinit(str_list_t *list)
  12921. +{
  12922. + void_list_deinit((void_list_t *) list);
  12923. +}
  12924. +
  12925. +int str_list_append(str_list_t *list, char *data)
  12926. +{
  12927. + return void_list_append((void_list_t *) list, data);
  12928. +}
  12929. +
  12930. +int str_list_push(str_list_t *list, char *data)
  12931. +{
  12932. + return void_list_push((void_list_t *) list, data);
  12933. +}
  12934. +
  12935. +str_list_elt_t *str_list_pop(str_list_t *list)
  12936. +{
  12937. + return (str_list_elt_t *) void_list_pop((void_list_t *) list);
  12938. +}
  12939. +
  12940. +str_list_elt_t *str_list_remove(str_list_t *list, str_list_elt_t **iter)
  12941. +{
  12942. + return (str_list_elt_t *) void_list_remove((void_list_t *) list,
  12943. + (void_list_elt_t **) iter);
  12944. +}
  12945. +
  12946. +char *str_list_remove_elt(str_list_t *list, const char *target_str)
  12947. +{
  12948. + return (char *)void_list_remove_elt((void_list_t *) list,
  12949. + (void *)target_str,
  12950. + (void_list_cmp_t)strcmp);
  12951. +}
  12952. diff -Nur busybox-1.16.1.orig/archival/libipkg/str_list.h busybox-1.16.1/archival/libipkg/str_list.h
  12953. --- busybox-1.16.1.orig/archival/libipkg/str_list.h 1970-01-01 01:00:00.000000000 +0100
  12954. +++ busybox-1.16.1/archival/libipkg/str_list.h 2010-04-22 19:18:12.000000000 +0200
  12955. @@ -0,0 +1,51 @@
  12956. +/* str_list.h - the itsy package management system
  12957. +
  12958. + Carl D. Worth
  12959. +
  12960. + Copyright (C) 2001 University of Southern California
  12961. +
  12962. + This program is free software; you can redistribute it and/or
  12963. + modify it under the terms of the GNU General Public License as
  12964. + published by the Free Software Foundation; either version 2, or (at
  12965. + your option) any later version.
  12966. +
  12967. + This program is distributed in the hope that it will be useful, but
  12968. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12969. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12970. + General Public License for more details.
  12971. +*/
  12972. +
  12973. +#ifndef STR_LIST_H
  12974. +#define STR_LIST_H
  12975. +
  12976. +#include "void_list.h"
  12977. +
  12978. +typedef struct str_list_elt str_list_elt_t;
  12979. +struct str_list_elt
  12980. +{
  12981. + str_list_elt_t *next;
  12982. + char *data;
  12983. +};
  12984. +
  12985. +typedef struct xstr_list str_list_t;
  12986. +struct xstr_list
  12987. +{
  12988. + str_list_elt_t pre_head;
  12989. + str_list_elt_t *head;
  12990. + str_list_elt_t *tail;
  12991. +};
  12992. +
  12993. +int str_list_elt_init(str_list_elt_t *elt, char *data);
  12994. +void str_list_elt_deinit(str_list_elt_t *elt);
  12995. +
  12996. +str_list_t *str_list_alloc(void);
  12997. +int str_list_init(str_list_t *list);
  12998. +void str_list_deinit(str_list_t *list);
  12999. +
  13000. +int str_list_append(str_list_t *list, char *data);
  13001. +int str_list_push(str_list_t *list, char *data);
  13002. +str_list_elt_t *str_list_pop(str_list_t *list);
  13003. +str_list_elt_t *str_list_remove(str_list_t *list, str_list_elt_t **iter);
  13004. +char *str_list_remove_elt(str_list_t *list, const char *target_str);
  13005. +
  13006. +#endif
  13007. diff -Nur busybox-1.16.1.orig/archival/libipkg/str_util.c busybox-1.16.1/archival/libipkg/str_util.c
  13008. --- busybox-1.16.1.orig/archival/libipkg/str_util.c 1970-01-01 01:00:00.000000000 +0100
  13009. +++ busybox-1.16.1/archival/libipkg/str_util.c 2010-04-22 19:18:12.000000000 +0200
  13010. @@ -0,0 +1,69 @@
  13011. +/* str_utils.c - the itsy package management system
  13012. +
  13013. + Carl D. Worth
  13014. +
  13015. + Copyright (C) 2001 University of Southern California
  13016. +
  13017. + This program is free software; you can redistribute it and/or
  13018. + modify it under the terms of the GNU General Public License as
  13019. + published by the Free Software Foundation; either version 2, or (at
  13020. + your option) any later version.
  13021. +
  13022. + This program is distributed in the hope that it will be useful, but
  13023. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13024. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13025. + General Public License for more details.
  13026. +*/
  13027. +
  13028. +#include "ipkg.h"
  13029. +
  13030. +int str_starts_with(const char *str, const char *prefix);
  13031. +int str_ends_with(const char *str, const char *suffix);
  13032. +int str_chomp(char *str);
  13033. +int str_toupper(char *str);
  13034. +char *str_dup_safe(const char *str);
  13035. +
  13036. +int str_starts_with(const char *str, const char *prefix)
  13037. +{
  13038. + return (strncmp(str, prefix, strlen(prefix)) == 0);
  13039. +}
  13040. +
  13041. +int str_ends_with(const char *str, const char *suffix)
  13042. +{
  13043. + int suffix_len;
  13044. + int str_len;
  13045. +
  13046. + str_len = strlen(str);
  13047. + suffix_len = strlen(suffix);
  13048. +
  13049. + if (str_len < suffix_len) {
  13050. + return 0;
  13051. + }
  13052. +
  13053. + return (strcmp(str + str_len - suffix_len, suffix) == 0);
  13054. +}
  13055. +
  13056. +int str_chomp(char *str)
  13057. +{
  13058. + if (str[strlen(str) - 1] == '\n') {
  13059. + str[strlen(str) - 1] = '\0';
  13060. + return 1;
  13061. + }
  13062. + return 0;
  13063. +}
  13064. +
  13065. +int str_toupper(char *str)
  13066. +{
  13067. + while (*str) {
  13068. + *str = toupper(*str);
  13069. + str++;
  13070. + }
  13071. +
  13072. + return 0;
  13073. +}
  13074. +
  13075. +char *str_dup_safe(const char *str)
  13076. +{
  13077. + return str ? strdup(str) : NULL;
  13078. +}
  13079. +
  13080. diff -Nur busybox-1.16.1.orig/archival/libipkg/str_util.h busybox-1.16.1/archival/libipkg/str_util.h
  13081. --- busybox-1.16.1.orig/archival/libipkg/str_util.h 1970-01-01 01:00:00.000000000 +0100
  13082. +++ busybox-1.16.1/archival/libipkg/str_util.h 2010-04-22 19:18:12.000000000 +0200
  13083. @@ -0,0 +1,27 @@
  13084. +/* str_utils.h - the itsy package management system
  13085. +
  13086. + Carl D. Worth
  13087. +
  13088. + Copyright (C) 2001 University of Southern California
  13089. +
  13090. + This program is free software; you can redistribute it and/or
  13091. + modify it under the terms of the GNU General Public License as
  13092. + published by the Free Software Foundation; either version 2, or (at
  13093. + your option) any later version.
  13094. +
  13095. + This program is distributed in the hope that it will be useful, but
  13096. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13097. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13098. + General Public License for more details.
  13099. +*/
  13100. +
  13101. +#ifndef STR_UTILS_H
  13102. +#define STR_UTILS_H
  13103. +
  13104. +int str_starts_with(const char *str, const char *prefix);
  13105. +int str_ends_with(const char *str, const char *suffix);
  13106. +int str_chomp(char *str);
  13107. +int str_toupper(char *str);
  13108. +char *str_dup_safe(const char *str);
  13109. +
  13110. +#endif
  13111. diff -Nur busybox-1.16.1.orig/archival/libipkg/user.c busybox-1.16.1/archival/libipkg/user.c
  13112. --- busybox-1.16.1.orig/archival/libipkg/user.c 1970-01-01 01:00:00.000000000 +0100
  13113. +++ busybox-1.16.1/archival/libipkg/user.c 2010-04-22 19:18:12.000000000 +0200
  13114. @@ -0,0 +1,49 @@
  13115. +/* user.c - the itsy package management system
  13116. +
  13117. + Jamey Hicks
  13118. +
  13119. + Copyright (C) 2002 Hewlett Packard Company
  13120. + Copyright (C) 2001 University of Southern California
  13121. +
  13122. + This program is free software; you can redistribute it and/or
  13123. + modify it under the terms of the GNU General Public License as
  13124. + published by the Free Software Foundation; either version 2, or (at
  13125. + your option) any later version.
  13126. +
  13127. + This program is distributed in the hope that it will be useful, but
  13128. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13129. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13130. + General Public License for more details.
  13131. +*/
  13132. +
  13133. +#include <stdio.h>
  13134. +#include <stdarg.h>
  13135. +#include "libbb.h"
  13136. +#include "file_util.h"
  13137. +#include "str_util.h"
  13138. +#include "libipkg.h"
  13139. +
  13140. +char *get_user_response(const char *format, ...);
  13141. +static char *question = NULL;
  13142. +static int question_len = 255;
  13143. +
  13144. +char *get_user_response(const char *format, ...)
  13145. +{
  13146. + int len = question_len;
  13147. + va_list ap;
  13148. + char *response;
  13149. + va_start(ap, format);
  13150. +
  13151. + do {
  13152. + if (question == NULL || len > question_len) {
  13153. + question = realloc(question, len + 1);
  13154. + question_len = len;
  13155. + }
  13156. + len = vsnprintf(question,question_len,format,ap);
  13157. + } while (len > question_len);
  13158. + response = strdup(ipkg_cb_response(question));
  13159. + str_chomp(response);
  13160. + str_tolower(response);
  13161. +
  13162. + return response;
  13163. +}
  13164. diff -Nur busybox-1.16.1.orig/archival/libipkg/user.h busybox-1.16.1/archival/libipkg/user.h
  13165. --- busybox-1.16.1.orig/archival/libipkg/user.h 1970-01-01 01:00:00.000000000 +0100
  13166. +++ busybox-1.16.1/archival/libipkg/user.h 2010-04-22 19:18:12.000000000 +0200
  13167. @@ -0,0 +1,23 @@
  13168. +/* user.c - the itsy package management system
  13169. +
  13170. + Jamey Hicks
  13171. +
  13172. + Copyright (C) 2002 Hewlett Packard Company
  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. +#include <stdio.h>
  13187. +#include <stdarg.h>
  13188. +
  13189. +char *get_user_response(const char *format, ...);
  13190. +
  13191. diff -Nur busybox-1.16.1.orig/archival/libipkg/void_list.c busybox-1.16.1/archival/libipkg/void_list.c
  13192. --- busybox-1.16.1.orig/archival/libipkg/void_list.c 1970-01-01 01:00:00.000000000 +0100
  13193. +++ busybox-1.16.1/archival/libipkg/void_list.c 2010-04-22 19:18:12.000000000 +0200
  13194. @@ -0,0 +1,194 @@
  13195. +/* void_list.c - the itsy package management system
  13196. +
  13197. + Carl D. Worth
  13198. +
  13199. + Copyright (C) 2001 University of Southern California
  13200. +
  13201. + This program is free software; you can redistribute it and/or
  13202. + modify it under the terms of the GNU General Public License as
  13203. + published by the Free Software Foundation; either version 2, or (at
  13204. + your option) any later version.
  13205. +
  13206. + This program is distributed in the hope that it will be useful, but
  13207. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13208. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13209. + General Public License for more details.
  13210. +*/
  13211. +
  13212. +#include "ipkg.h"
  13213. +#include <errno.h>
  13214. +
  13215. +#include "void_list.h"
  13216. +
  13217. +int void_list_elt_init(void_list_elt_t *elt, void *data)
  13218. +{
  13219. + elt->next = NULL;
  13220. + elt->data = data;
  13221. +
  13222. + return 0;
  13223. +}
  13224. +
  13225. +void void_list_elt_deinit(void_list_elt_t *elt)
  13226. +{
  13227. + void_list_elt_init(elt, NULL);
  13228. +}
  13229. +
  13230. +int void_list_init(void_list_t *list)
  13231. +{
  13232. + void_list_elt_init(&list->pre_head, NULL);
  13233. + list->head = NULL;
  13234. + list->pre_head.next = list->head;
  13235. + list->tail = NULL;
  13236. +
  13237. + return 0;
  13238. +}
  13239. +
  13240. +void void_list_deinit(void_list_t *list)
  13241. +{
  13242. + void_list_elt_t *elt;
  13243. +
  13244. + while (list->head) {
  13245. + elt = void_list_pop(list);
  13246. + void_list_elt_deinit(elt);
  13247. + /* malloced in void_list_append */
  13248. + free(elt);
  13249. + }
  13250. +}
  13251. +
  13252. +int void_list_append(void_list_t *list, void *data)
  13253. +{
  13254. + void_list_elt_t *elt;
  13255. +
  13256. + /* freed in void_list_deinit */
  13257. + elt = malloc(sizeof(void_list_elt_t));
  13258. + if (elt == NULL) {
  13259. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  13260. + return ENOMEM;
  13261. + }
  13262. +
  13263. + void_list_elt_init(elt, data);
  13264. +
  13265. + if (list->tail) {
  13266. + list->tail->next = elt;
  13267. + list->tail = elt;
  13268. + } else {
  13269. + list->head = elt;
  13270. + list->pre_head.next = list->head;
  13271. + list->tail = elt;
  13272. + }
  13273. +
  13274. + return 0;
  13275. +}
  13276. +
  13277. +int void_list_push(void_list_t *list, void *data)
  13278. +{
  13279. + void_list_elt_t *elt;
  13280. +
  13281. + elt = malloc(sizeof(void_list_elt_t));
  13282. + if (elt == NULL) {
  13283. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  13284. + return ENOMEM;
  13285. + }
  13286. +
  13287. + void_list_elt_init(elt, data);
  13288. +
  13289. + elt->next = list->head;
  13290. + list->head->next = elt;
  13291. + if (list->tail == NULL) {
  13292. + list->tail = list->head;
  13293. + }
  13294. +
  13295. + return 0;
  13296. +}
  13297. +
  13298. +void_list_elt_t *void_list_pop(void_list_t *list)
  13299. +{
  13300. + void_list_elt_t *elt;
  13301. +
  13302. + elt = list->head;
  13303. +
  13304. + if (list->head) {
  13305. + list->head = list->head->next;
  13306. + list->pre_head.next = list->head;
  13307. + if (list->head == NULL) {
  13308. + list->tail = NULL;
  13309. + }
  13310. + }
  13311. +
  13312. + return elt;
  13313. +}
  13314. +
  13315. +void *void_list_remove(void_list_t *list, void_list_elt_t **iter)
  13316. +{
  13317. + void_list_elt_t *prior;
  13318. + void_list_elt_t *old_elt;
  13319. + void *old_data;
  13320. +
  13321. + old_elt = *iter;
  13322. + old_data = old_elt->data;
  13323. +
  13324. + if (old_elt == list->head) {
  13325. + prior = &list->pre_head;
  13326. + void_list_pop(list);
  13327. + } else {
  13328. + for (prior = list->head; prior; prior = prior->next) {
  13329. + if (prior->next == old_elt) {
  13330. + break;
  13331. + }
  13332. + }
  13333. + if (prior == NULL || prior->next != old_elt) {
  13334. + fprintf(stderr, "%s: ERROR: element not found in list\n", __FUNCTION__);
  13335. + return NULL;
  13336. + }
  13337. + prior->next = old_elt->next;
  13338. +
  13339. + if (old_elt == list->tail) {
  13340. + list->tail = prior;
  13341. + }
  13342. + }
  13343. +
  13344. + void_list_elt_deinit(old_elt);
  13345. + *iter = prior;
  13346. +
  13347. + return old_data;
  13348. +}
  13349. +
  13350. +/* remove element containing elt data, using cmp(elt->data, target_data) == 0. */
  13351. +void *void_list_remove_elt(void_list_t *list, const void *target_data, void_list_cmp_t cmp)
  13352. +{
  13353. + void_list_elt_t *prior;
  13354. + void_list_elt_t *old_elt = NULL;
  13355. + void *old_data = NULL;
  13356. +
  13357. + /* first element */
  13358. + if (list->head && list->head->data && (cmp(list->head->data, target_data) == 0)) {
  13359. + old_elt = list->head;
  13360. + old_data = list->head->data;
  13361. + void_list_pop(list);
  13362. + } else {
  13363. + int found = 0;
  13364. + for (prior = list->head; prior && prior->next; prior = prior->next) {
  13365. + if (prior->next->data && (cmp(prior->next->data, target_data) == 0)) {
  13366. + old_elt = prior->next;
  13367. + old_data = old_elt->data;
  13368. + found = 1;
  13369. + break;
  13370. + }
  13371. + }
  13372. + if (!found) {
  13373. + return NULL;
  13374. + }
  13375. + prior->next = old_elt->next;
  13376. +
  13377. + if (old_elt == list->tail) {
  13378. + list->tail = prior;
  13379. + }
  13380. + }
  13381. + if (old_elt)
  13382. + void_list_elt_deinit(old_elt);
  13383. +
  13384. + if (old_data)
  13385. + return old_data;
  13386. + else
  13387. + return NULL;
  13388. +}
  13389. diff -Nur busybox-1.16.1.orig/archival/libipkg/void_list.h busybox-1.16.1/archival/libipkg/void_list.h
  13390. --- busybox-1.16.1.orig/archival/libipkg/void_list.h 1970-01-01 01:00:00.000000000 +0100
  13391. +++ busybox-1.16.1/archival/libipkg/void_list.h 2010-04-22 19:18:12.000000000 +0200
  13392. @@ -0,0 +1,59 @@
  13393. +/* void_list.h - the itsy package management system
  13394. +
  13395. + Carl D. Worth
  13396. +
  13397. + Copyright (C) 2001 University of Southern California
  13398. +
  13399. + This program is free software; you can redistribute it and/or
  13400. + modify it under the terms of the GNU General Public License as
  13401. + published by the Free Software Foundation; either version 2, or (at
  13402. + your option) any later version.
  13403. +
  13404. + This program is distributed in the hope that it will be useful, but
  13405. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13406. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13407. + General Public License for more details.
  13408. +*/
  13409. +
  13410. +#ifndef VOID_LIST_H
  13411. +#define VOID_LIST_H
  13412. +
  13413. +typedef struct void_list_elt void_list_elt_t;
  13414. +struct void_list_elt
  13415. +{
  13416. + void_list_elt_t *next;
  13417. + void *data;
  13418. +};
  13419. +
  13420. +typedef struct void_list void_list_t;
  13421. +struct void_list
  13422. +{
  13423. + void_list_elt_t pre_head;
  13424. + void_list_elt_t *head;
  13425. + void_list_elt_t *tail;
  13426. +};
  13427. +
  13428. +static inline int void_list_empty(void_list_t *list)
  13429. +{
  13430. + if (list->head == NULL)
  13431. + return 1;
  13432. + else
  13433. + return 0;
  13434. +}
  13435. +
  13436. +int void_list_elt_init(void_list_elt_t *elt, void *data);
  13437. +void void_list_elt_deinit(void_list_elt_t *elt);
  13438. +
  13439. +int void_list_init(void_list_t *list);
  13440. +void void_list_deinit(void_list_t *list);
  13441. +
  13442. +int void_list_append(void_list_t *list, void *data);
  13443. +int void_list_push(void_list_t *list, void *data);
  13444. +void_list_elt_t *void_list_pop(void_list_t *list);
  13445. +
  13446. +void *void_list_remove(void_list_t *list, void_list_elt_t **iter);
  13447. +/* remove element containing elt data, using cmp(elt->data, target_data) == 0. */
  13448. +typedef int (*void_list_cmp_t)(const void *, const void *);
  13449. +void *void_list_remove_elt(void_list_t *list, const void *target_data, void_list_cmp_t cmp);
  13450. +
  13451. +#endif
  13452. diff -Nur busybox-1.16.1.orig/archival/libipkg/xsystem.c busybox-1.16.1/archival/libipkg/xsystem.c
  13453. --- busybox-1.16.1.orig/archival/libipkg/xsystem.c 1970-01-01 01:00:00.000000000 +0100
  13454. +++ busybox-1.16.1/archival/libipkg/xsystem.c 2010-04-22 19:18:12.000000000 +0200
  13455. @@ -0,0 +1,64 @@
  13456. +/* xsystem.c - system(3) with error messages
  13457. +
  13458. + Carl D. Worth
  13459. +
  13460. + Copyright (C) 2001 University of Southern California
  13461. +
  13462. + This program is free software; you can redistribute it and/or
  13463. + modify it under the terms of the GNU General Public License as
  13464. + published by the Free Software Foundation; either version 2, or (at
  13465. + your option) any later version.
  13466. +
  13467. + This program is distributed in the hope that it will be useful, but
  13468. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13469. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13470. + General Public License for more details.
  13471. +*/
  13472. +
  13473. +#include "ipkg.h"
  13474. +#include <sys/wait.h>
  13475. +
  13476. +#include "xsystem.h"
  13477. +
  13478. +/* XXX: FEATURE: I shouldn't actually use system(3) at all. I don't
  13479. + really need the /bin/sh invocation which takes resources and
  13480. + introduces security problems. I should switch all of this to a sort
  13481. + of execl() or execv() interface/implementation.
  13482. +*/
  13483. +
  13484. +/* Like system(3), but with error messages printed if the fork fails
  13485. + or if the child process dies due to an uncaught signal. Also, the
  13486. + return value is a bit simpler:
  13487. +
  13488. + -1 if there was any problem
  13489. + Otherwise, the 8-bit return value of the program ala WEXITSTATUS
  13490. + as defined in <sys/wait.h>.
  13491. +*/
  13492. +int xsystem(const char *cmd)
  13493. +{
  13494. + int err;
  13495. +
  13496. + err = system(cmd);
  13497. +
  13498. + if (err == -1) {
  13499. + fprintf(stderr, "%s: ERROR: fork failed before execution: `%s'\n",
  13500. + __FUNCTION__, cmd);
  13501. + return -1;
  13502. + }
  13503. +
  13504. + if (WIFSIGNALED(err)) {
  13505. + fprintf(stderr, "%s: ERROR: Child process died due to signal %d: `%s'\n",
  13506. + __FUNCTION__, WTERMSIG(err), cmd);
  13507. + return -1;
  13508. + }
  13509. +
  13510. + if (WIFEXITED(err)) {
  13511. + /* Normal child exit */
  13512. + return WEXITSTATUS(err);
  13513. + }
  13514. +
  13515. + fprintf(stderr, "%s: ERROR: Received unintelligible return value from system: %d",
  13516. + __FUNCTION__, err);
  13517. + return -1;
  13518. +}
  13519. +
  13520. diff -Nur busybox-1.16.1.orig/archival/libipkg/xsystem.h busybox-1.16.1/archival/libipkg/xsystem.h
  13521. --- busybox-1.16.1.orig/archival/libipkg/xsystem.h 1970-01-01 01:00:00.000000000 +0100
  13522. +++ busybox-1.16.1/archival/libipkg/xsystem.h 2010-04-22 19:18:12.000000000 +0200
  13523. @@ -0,0 +1,34 @@
  13524. +/* xsystem.h - system(3) with error messages
  13525. +
  13526. + Carl D. Worth
  13527. +
  13528. + Copyright (C) 2001 University of Southern California
  13529. +
  13530. + This program is free software; you can redistribute it and/or
  13531. + modify it under the terms of the GNU General Public License as
  13532. + published by the Free Software Foundation; either version 2, or (at
  13533. + your option) any later version.
  13534. +
  13535. + This program is distributed in the hope that it will be useful, but
  13536. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13537. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13538. + General Public License for more details.
  13539. +*/
  13540. +
  13541. +#ifndef XSYSTEM_H
  13542. +#define XSYSTEM_H
  13543. +
  13544. +#include <stdlib.h>
  13545. +
  13546. +/* Like system(3), but with error messages printed if the fork fails
  13547. + or if the child process dies due to an uncaught signal. Also, the
  13548. + return value is a bit simpler:
  13549. +
  13550. + -1 if there was any problem
  13551. + Otherwise, the 8-bit return value of the program ala WEXITSTATUS
  13552. + as defined in <sys/wait.h>.
  13553. +*/
  13554. +int xsystem(const char *cmd);
  13555. +
  13556. +#endif
  13557. +
  13558. diff -Nur busybox-1.16.1.orig/archival/libunarchive/Kbuild busybox-1.16.1/archival/libunarchive/Kbuild
  13559. --- busybox-1.16.1.orig/archival/libunarchive/Kbuild 2010-03-20 03:58:07.000000000 +0100
  13560. +++ busybox-1.16.1/archival/libunarchive/Kbuild 2010-04-22 19:18:12.000000000 +0200
  13561. @@ -40,6 +40,7 @@
  13562. lib-$(CONFIG_DPKG) += $(DPKG_FILES)
  13563. lib-$(CONFIG_DPKG_DEB) += $(DPKG_FILES)
  13564. lib-$(CONFIG_GUNZIP) += decompress_unzip.o
  13565. +lib-$(CONFIG_IPKG) += open_transformer.o get_header_tar.o get_header_tar_gz.o
  13566. lib-$(CONFIG_RPM2CPIO) += decompress_unzip.o get_header_cpio.o
  13567. lib-$(CONFIG_RPM) += open_transformer.o decompress_unzip.o get_header_cpio.o
  13568. lib-$(CONFIG_TAR) += get_header_tar.o
  13569. diff -Nur busybox-1.16.1.orig/include/applets.h busybox-1.16.1/include/applets.h
  13570. --- busybox-1.16.1.orig/include/applets.h 2010-03-28 19:43:35.000000000 +0200
  13571. +++ busybox-1.16.1/include/applets.h 2010-04-22 19:18:12.000000000 +0200
  13572. @@ -214,6 +214,7 @@
  13573. IF_IPCALC(APPLET(ipcalc, _BB_DIR_BIN, _BB_SUID_DROP))
  13574. IF_IPCRM(APPLET(ipcrm, _BB_DIR_USR_BIN, _BB_SUID_REQUIRE))
  13575. IF_IPCS(APPLET(ipcs, _BB_DIR_USR_BIN, _BB_SUID_REQUIRE))
  13576. +IF_IPKG(APPLET(ipkg, _BB_DIR_USR_BIN, _BB_SUID_DROP))
  13577. IF_IPLINK(APPLET(iplink, _BB_DIR_BIN, _BB_SUID_DROP))
  13578. IF_IPROUTE(APPLET(iproute, _BB_DIR_BIN, _BB_SUID_DROP))
  13579. IF_IPRULE(APPLET(iprule, _BB_DIR_BIN, _BB_SUID_DROP))
  13580. diff -Nur busybox-1.16.1.orig/include/unarchive.h busybox-1.16.1/include/unarchive.h
  13581. --- busybox-1.16.1.orig/include/unarchive.h 2010-03-28 19:43:35.000000000 +0200
  13582. +++ busybox-1.16.1/include/unarchive.h 2010-04-22 19:21:25.000000000 +0200
  13583. @@ -65,7 +65,7 @@
  13584. struct hardlinks_t *cpio__hardlinks_to_create;
  13585. struct hardlinks_t *cpio__created_hardlinks;
  13586. #endif
  13587. -#if ENABLE_DPKG || ENABLE_DPKG_DEB
  13588. +#if ENABLE_DPKG || ENABLE_DPKG_DEB || ENABLE_IPKG
  13589. /* Temporary storage */
  13590. char *dpkg__buffer;
  13591. /* How to process any sub archive, e.g. get_header_tar_gz */
  13592. diff -Nur busybox-1.16.1.orig/include/usage.h busybox-1.16.1/include/usage.h
  13593. --- busybox-1.16.1.orig/include/usage.h 2010-03-28 19:44:04.000000000 +0200
  13594. +++ busybox-1.16.1/include/usage.h 2010-04-22 19:18:12.000000000 +0200
  13595. @@ -1592,6 +1592,82 @@
  13596. "$ ls -la /tmp/busybox*\n" \
  13597. "-rw-rw-r-- 1 andersen andersen 554058 Apr 14 17:49 /tmp/busybox.tar.gz\n"
  13598. +#define ipkg_trivial_usage \
  13599. + "[options]... sub-command [arguments]..."
  13600. +#define ipkg_full_usage \
  13601. + "ipkg is an utility to install, remove and manage .ipk packages.\n" \
  13602. + "\n" \
  13603. + "Sub-commands:\n" \
  13604. + "\nPackage Manipulation:\n" \
  13605. + "\tupdate Update list of available packages\n" \
  13606. + "\tupgrade Upgrade all installed packages to latest version\n" \
  13607. + "\tinstall <pkg> Download and install <pkg> (and dependencies)\n" \
  13608. + "\tinstall <file.ipk> Install package <file.ipk>\n" \
  13609. + "\tconfigure [<pkg>] Configure unpacked packages\n" \
  13610. + "\tremove <pkg|regexp> Remove package <pkg|packages following regexp>\n" \
  13611. + "\tflag <flag> <pkg> ... Flag package(s) <pkg>\n" \
  13612. + "\t <flag>=hold|noprune|user|ok|installed|unpacked (one per invocation) \n" \
  13613. + "\n" \
  13614. + "Informational Commands:\n" \
  13615. + "\tlist List available packages and descriptions\n" \
  13616. + "\tlist_installed List all and only the installed packages and description \n" \
  13617. + "\tfiles <pkg> List all files belonging to <pkg>\n" \
  13618. + "\tsearch <file|regexp> Search for a package providing <file>\n" \
  13619. + "\tinfo [pkg|regexp [<field>]] Display all/some info fields for <pkg> or all\n" \
  13620. + "\tstatus [pkg|regexp [<field>]] Display all/some status fields for <pkg> or all\n" \
  13621. + "\tdownload <pkg> Download <pkg> to current directory.\n" \
  13622. + "\tcompare_versions <v1> <op> <v2>\n" \
  13623. + "\t compare versions using <= < > >= = << >>\n" \
  13624. + "\tprint_architecture prints the architecture.\n" \
  13625. + "\tprint_installation_architecture\n" \
  13626. + "\twhatdepends [-A] [pkgname|pat]+\n" \
  13627. + "\twhatdependsrec [-A] [pkgname|pat]+\n" \
  13628. + "\twhatprovides [-A] [pkgname|pat]+\n" \
  13629. + "\twhatconflicts [-A] [pkgname|pat]+\n" \
  13630. + "\twhatreplaces [-A] [pkgname|pat]+\n" \
  13631. + "\t prints the installation architecture.\n" \
  13632. + "\n" \
  13633. + "\nOptions:\n" \
  13634. + "\t-A Query all packages with whatdepends, whatprovides, whatreplaces, whatconflicts\n" \
  13635. + "\t-V <level> Set verbosity level to <level>. If no value is\n" \
  13636. + "\t--verbosity <level> provided increase verbosity by one. Verbosity levels:\n" \
  13637. + "\t 0 errors only\n" \
  13638. + "\t 1 normal messages (default)\n" \
  13639. + "\t 2 informative messages\n" \
  13640. + "\t 3 debug output\n" \
  13641. + "\t-f <conf_file> Use <conf_file> as the ipkg configuration file\n" \
  13642. + "\t-conf <conf_file> Default configuration file location\n" \
  13643. + " is /etc/ipkg.conf\n" \
  13644. + "\t-d <dest_name> Use <dest_name> as the the root directory for\n" \
  13645. + "\t-dest <dest_name> package installation, removal, upgrading.\n" \
  13646. + " <dest_name> should be a defined dest name from\n" \
  13647. + " the configuration file, (but can also be a\n" \
  13648. + " directory name in a pinch).\n" \
  13649. + "\t-o <offline_root> Use <offline_root> as the root directory for\n" \
  13650. + "\t-offline <offline_root> offline installation of packages.\n" \
  13651. + "\t-verbose_wget more wget messages\n" \
  13652. + "\n" \
  13653. + "Force Options (use when ipkg is too smart for its own good):\n" \
  13654. + "\t-force-depends Make dependency checks warnings instead of errors\n" \
  13655. + "\t Install/remove package in spite of failed dependences\n" \
  13656. + "\t-force-defaults Use default options for questions asked by ipkg.\n" \
  13657. + " (no prompts). Note that this will not prevent\n" \
  13658. + " package installation scripts from prompting.\n" \
  13659. + "\t-force-reinstall Allow ipkg to reinstall a package.\n" \
  13660. + "\t-force-overwrite Allow ipkg to overwrite files from another package during an install.\n" \
  13661. + "\t-force-downgrade Allow ipkg to downgrade packages.\n" \
  13662. + "\t-force_space Install even if there does not seem to be enough space.\n" \
  13663. + "\t-noaction No action -- test only\n" \
  13664. + "\t-nodeps Do not follow dependences\n" \
  13665. + "\t-force-removal-of-dependent-packages\n" \
  13666. + "\t-recursive Allow ipkg to remove package and all that depend on it.\n" \
  13667. + "\t-test No action -- test only\n" \
  13668. + "\t-t Specify tmp-dir.\n" \
  13669. + "\t--tmp-dir Specify tmp-dir.\n" \
  13670. + "\n" \
  13671. + "\tregexp could be something like 'pkgname*' '*file*' or similar\n" \
  13672. + "\teg: ipkg info 'libstd*' or ipkg search '*libop*' or ipkg remove 'libncur*'\n"
  13673. +
  13674. #define halt_trivial_usage \
  13675. "[-d DELAY] [-n] [-f]" IF_FEATURE_WTMP(" [-w]")
  13676. #define halt_full_usage "\n\n" \
  13677. diff -Nur busybox-1.16.1.orig/Makefile busybox-1.16.1/Makefile
  13678. --- busybox-1.16.1.orig/Makefile 2010-03-28 19:44:09.000000000 +0200
  13679. +++ busybox-1.16.1/Makefile 2010-04-22 19:18:12.000000000 +0200
  13680. @@ -454,6 +454,7 @@
  13681. libs-y := \
  13682. archival/ \
  13683. + archival/libipkg/ \
  13684. archival/libunarchive/ \
  13685. console-tools/ \
  13686. coreutils/ \