001-ipkg.patch 423 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707
  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-06-29 17:31:21.805863709 +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-06-29 17:31:21.827118101 +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-06-29 17:31:21.865866986 +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-06-29 17:31:21.905863813 +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-06-29 17:31:21.945866019 +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-06-29 17:31:21.987118040 +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-06-29 17:31:22.018368070 +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-06-29 17:31:22.055873481 +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-06-29 17:31:22.089612450 +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-06-29 17:31:22.137606321 +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-06-29 17:31:22.220596553 +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-06-29 17:31:22.257056261 +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-06-29 17:31:22.305858166 +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-06-29 17:31:22.355873403 +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-06-29 17:31:22.398358961 +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-06-29 17:31:22.425857952 +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-06-29 17:31:22.458368131 +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-06-29 17:31:22.488368061 +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-06-29 17:31:22.527882534 +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-06-29 17:31:22.569385415 +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-06-29 17:31:22.608368046 +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-06-29 17:31:22.647281522 +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-06-29 17:32:10.339618090 +0200
  3649. @@ -0,0 +1,81 @@
  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. +#include <sys/mount.h>
  3729. +
  3730. +#endif /* IPKG_INCLUDES_H */
  3731. diff -Nur busybox-1.16.1.orig/archival/libipkg/ipkg_install.c busybox-1.16.1/archival/libipkg/ipkg_install.c
  3732. --- busybox-1.16.1.orig/archival/libipkg/ipkg_install.c 1970-01-01 01:00:00.000000000 +0100
  3733. +++ busybox-1.16.1/archival/libipkg/ipkg_install.c 2010-06-29 17:31:22.727172508 +0200
  3734. @@ -0,0 +1,1982 @@
  3735. +/* ipkg_install.c - the itsy package management system
  3736. +
  3737. + Carl D. Worth
  3738. +
  3739. + Copyright (C) 2001 University of Southern California
  3740. +
  3741. + This program is free software; you can redistribute it and/or
  3742. + modify it under the terms of the GNU General Public License as
  3743. + published by the Free Software Foundation; either version 2, or (at
  3744. + your option) any later version.
  3745. +
  3746. + This program is distributed in the hope that it will be useful, but
  3747. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3748. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3749. + General Public License for more details.
  3750. +*/
  3751. +
  3752. +#include "ipkg.h"
  3753. +#include <errno.h>
  3754. +#include <dirent.h>
  3755. +#include <glob.h>
  3756. +#include <time.h>
  3757. +#include <signal.h>
  3758. +typedef void (*sighandler_t)(int);
  3759. +
  3760. +#include "pkg.h"
  3761. +#include "pkg_hash.h"
  3762. +#include "pkg_extract.h"
  3763. +
  3764. +#include "ipkg_install.h"
  3765. +#include "ipkg_configure.h"
  3766. +#include "ipkg_download.h"
  3767. +#include "ipkg_remove.h"
  3768. +
  3769. +#include "ipkg_utils.h"
  3770. +#include "ipkg_message.h"
  3771. +
  3772. +#include "sprintf_alloc.h"
  3773. +#include "file_util.h"
  3774. +#include "str_util.h"
  3775. +#include "xsystem.h"
  3776. +#include "user.h"
  3777. +
  3778. +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg);
  3779. +static int verify_pkg_installable(ipkg_conf_t *conf, pkg_t *pkg);
  3780. +static int unpack_pkg_control_files(ipkg_conf_t *conf, pkg_t *pkg);
  3781. +
  3782. +/*
  3783. +static int prerm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3784. +static int prerm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3785. +static int prerm_deconfigure_conflictors(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors);
  3786. +static int prerm_deconfigure_conflictors_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors);
  3787. +static int preinst_configure_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3788. +static int check_data_file_clashes_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3789. +static int postrm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3790. +static int remove_disappeared(ipkg_conf_t *conf, pkg_t *pkg);
  3791. +static int postrm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3792. +*/
  3793. +static int preinst_configure(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3794. +static int check_data_file_clashes(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3795. +static int check_data_file_clashes_change(ipkg_conf_t *conf, pkg_t *pkg);
  3796. +static int backup_modified_conffiles(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3797. +static int backup_modified_conffiles_unwind(pkg_t *pkg, pkg_t *old_pkg);
  3798. +
  3799. +static int remove_obsolesced_files(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3800. +static int install_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3801. +static int install_data_files(ipkg_conf_t *conf, pkg_t *pkg);
  3802. +static int resolve_conffiles(ipkg_conf_t *conf, pkg_t *pkg);
  3803. +
  3804. +static int cleanup_temporary_files(ipkg_conf_t *conf, pkg_t *pkg);
  3805. +
  3806. +static int user_prefers_old_conffile(const char *file, const char *backup);
  3807. +
  3808. +static char *backup_filename_alloc(const char *file_name);
  3809. +static int backup_make_backup(ipkg_conf_t *conf, const char *file_name);
  3810. +static int backup_exists_for(const char *file_name);
  3811. +static int backup_remove(const char *file_name);
  3812. +
  3813. +int pkg_get_installed_replacees(pkg_t *pkg, pkg_vec_t *installed_replacees);
  3814. +int pkg_remove_installed_replacees(ipkg_conf_t *conf, pkg_vec_t *replacees);
  3815. +int pkg_remove_installed_replacees_unwind(ipkg_conf_t *conf, pkg_vec_t *replacees);
  3816. +
  3817. +int ipkg_install_from_file(ipkg_conf_t *conf, const char *filename)
  3818. +{
  3819. + int err, cmp;
  3820. + pkg_t *pkg, *old;
  3821. + char *old_version, *new_version;
  3822. +
  3823. + pkg = pkg_new();
  3824. + if (pkg == NULL) {
  3825. + return ENOMEM;
  3826. + }
  3827. +
  3828. + err = pkg_init_from_file(pkg, filename);
  3829. + if (err) {
  3830. + return err;
  3831. + }
  3832. +
  3833. + if (!pkg->architecture) {
  3834. + ipkg_message(conf, IPKG_ERROR, "Package %s has no Architecture defined.\n", pkg->name);
  3835. + return -EINVAL;
  3836. + }
  3837. +
  3838. + /* XXX: CLEANUP: hash_insert_pkg has a nasty side effect of possibly
  3839. + freeing the pkg that we pass in. It might be nice to clean this up
  3840. + if possible. */
  3841. + pkg = hash_insert_pkg(&conf->pkg_hash, pkg, 1,conf);
  3842. + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name);
  3843. +
  3844. + pkg->local_filename = strdup(filename);
  3845. +
  3846. + if (old) {
  3847. + old_version = pkg_version_str_alloc(old);
  3848. + new_version = pkg_version_str_alloc(pkg);
  3849. +
  3850. + cmp = pkg_compare_versions(old, pkg);
  3851. + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
  3852. + cmp = -1 ; /* then we force ipkg to downgrade */
  3853. + /* We need to use a value < 0 because in the 0 case we are asking to */
  3854. + /* reinstall, and some check could fail asking the "force-reinstall" option */
  3855. + }
  3856. + if (cmp > 0) {
  3857. + ipkg_message(conf, IPKG_NOTICE,
  3858. + "Not downgrading package %s on %s from %s to %s.\n",
  3859. + old->name, old->dest->name, old_version, new_version);
  3860. + pkg->state_want = SW_DEINSTALL;
  3861. + pkg->state_flag |= SF_OBSOLETE;
  3862. + free(old_version);
  3863. + free(new_version);
  3864. + return 0;
  3865. + } else {
  3866. + free(old_version);
  3867. + free(new_version);
  3868. + }
  3869. + }
  3870. +
  3871. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
  3872. + return ipkg_install_pkg(conf, pkg,0);
  3873. +}
  3874. +
  3875. +ipkg_error_t ipkg_install_by_name(ipkg_conf_t *conf, const char *pkg_name)
  3876. +{
  3877. + int cmp;
  3878. + pkg_t *old, *new;
  3879. + char *old_version, *new_version;
  3880. +
  3881. + ipkg_message(conf, IPKG_DEBUG2, " Getting old from pkg_hash_fetch \n" );
  3882. + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg_name);
  3883. + if ( old )
  3884. + ipkg_message(conf, IPKG_DEBUG2, " Old versions from pkg_hash_fetch %s \n", old->version );
  3885. +
  3886. + ipkg_message(conf, IPKG_DEBUG2, " Getting new from pkg_hash_fetch \n" );
  3887. + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, pkg_name);
  3888. + if ( new )
  3889. + ipkg_message(conf, IPKG_DEBUG2, " New versions from pkg_hash_fetch %s \n", new->version );
  3890. +
  3891. +/* Pigi Basically here is broken the version stuff.
  3892. + What's happening is that nothing provide the version to differents
  3893. + functions, so the returned struct is always the latest.
  3894. + That's why the install by name don't work.
  3895. +*/
  3896. + ipkg_message(conf, IPKG_DEBUG2, " Versions from pkg_hash_fetch in %s ", __FUNCTION__ );
  3897. +
  3898. + if ( old )
  3899. + ipkg_message(conf, IPKG_DEBUG2, " old %s ", old->version );
  3900. + if ( new )
  3901. + ipkg_message(conf, IPKG_DEBUG2, " new %s ", new->version );
  3902. + ipkg_message(conf, IPKG_DEBUG2, " \n");
  3903. +
  3904. + if (new == NULL) {
  3905. + return IPKG_PKG_HAS_NO_CANDIDATE;
  3906. + }
  3907. +
  3908. + new->state_flag |= SF_USER;
  3909. + if (old) {
  3910. + old_version = pkg_version_str_alloc(old);
  3911. + new_version = pkg_version_str_alloc(new);
  3912. +
  3913. + cmp = pkg_compare_versions(old, new);
  3914. + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
  3915. + ipkg_message(conf, IPKG_DEBUG, " Forcing downgrade \n");
  3916. + cmp = -1 ; /* then we force ipkg to downgrade */
  3917. + /* We need to use a value < 0 because in the 0 case we are asking to */
  3918. + /* reinstall, and some check could fail asking the "force-reinstall" option */
  3919. + }
  3920. + ipkg_message(conf, IPKG_DEBUG,
  3921. + "Comparing visible versions of pkg %s:"
  3922. + "\n\t%s is installed "
  3923. + "\n\t%s is available "
  3924. + "\n\t%d was comparison result\n",
  3925. + pkg_name, old_version, new_version, cmp);
  3926. + if (cmp == 0 && !conf->force_reinstall) {
  3927. + ipkg_message(conf, IPKG_NOTICE,
  3928. + "Package %s (%s) installed in %s is up to date.\n",
  3929. + old->name, old_version, old->dest->name);
  3930. + free(old_version);
  3931. + free(new_version);
  3932. + return 0;
  3933. + } else if (cmp > 0) {
  3934. + ipkg_message(conf, IPKG_NOTICE,
  3935. + "Not downgrading package %s on %s from %s to %s.\n",
  3936. + old->name, old->dest->name, old_version, new_version);
  3937. + free(old_version);
  3938. + free(new_version);
  3939. + return 0;
  3940. + } else if (cmp < 0) {
  3941. + new->dest = old->dest;
  3942. + old->state_want = SW_DEINSTALL; /* Here probably the problem for bug 1277 */
  3943. + }
  3944. + }
  3945. +
  3946. + /* XXX: CLEANUP: The error code of ipkg_install_by_name is really
  3947. + supposed to be an ipkg_error_t, but ipkg_install_pkg could
  3948. + return any kind of integer, (might be errno from a syscall,
  3949. + etc.). This is a real mess and will need to be cleaned up if
  3950. + anyone ever wants to make a nice libipkg. */
  3951. +
  3952. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
  3953. + return ipkg_install_pkg(conf, new,0);
  3954. +}
  3955. +
  3956. +ipkg_error_t ipkg_install_multi_by_name(ipkg_conf_t *conf, const char *pkg_name)
  3957. +{
  3958. + abstract_pkg_vec_t *providers = pkg_hash_fetch_all_installation_candidates (&conf->pkg_hash, pkg_name);
  3959. + int i;
  3960. + ipkg_error_t err;
  3961. + abstract_pkg_t *ppkg ;
  3962. +
  3963. + if (providers == NULL)
  3964. + return IPKG_PKG_HAS_NO_CANDIDATE;
  3965. +
  3966. + for (i = 0; i < providers->len; i++) {
  3967. + ppkg = abstract_pkg_vec_get(providers, i);
  3968. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_by_name %d \n",__FUNCTION__, i);
  3969. + err = ipkg_install_by_name(conf, ppkg->name);
  3970. + if (err)
  3971. + return err;
  3972. +/* XXX Maybe ppkg should be freed ? */
  3973. + }
  3974. + return 0;
  3975. +}
  3976. +
  3977. +/*
  3978. + * Walk dependence graph starting with pkg, collect packages to be
  3979. + * installed into pkgs_needed, in dependence order.
  3980. + */
  3981. +int pkg_mark_dependencies_for_installation(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *pkgs_needed)
  3982. +{
  3983. + int i, err;
  3984. + pkg_vec_t *depends = pkg_vec_alloc();
  3985. + char **unresolved = NULL;
  3986. + int ndepends;
  3987. +
  3988. + ndepends = pkg_hash_fetch_unsatisfied_dependencies(conf,
  3989. + pkg, depends,
  3990. + &unresolved);
  3991. +
  3992. + if (unresolved) {
  3993. + ipkg_message(conf, IPKG_ERROR,
  3994. + "%s: Cannot satisfy the following dependencies for %s:\n\t",
  3995. + conf->force_depends ? "Warning" : "ERROR", pkg->name);
  3996. + while (*unresolved) {
  3997. + ipkg_message(conf, IPKG_ERROR, " %s", *unresolved);
  3998. + unresolved++;
  3999. + }
  4000. + ipkg_message(conf, IPKG_ERROR, "\n");
  4001. + if (! conf->force_depends) {
  4002. + ipkg_message(conf, IPKG_INFO,
  4003. + "This could mean that your package list is out of date or that the packages\n"
  4004. + "mentioned above do not yet exist (try 'ipkg update'). To proceed in spite\n"
  4005. + "of this problem try again with the '-force-depends' option.\n");
  4006. + pkg_vec_free(depends);
  4007. + return IPKG_PKG_DEPS_UNSATISFIED;
  4008. + }
  4009. + }
  4010. +
  4011. + if (ndepends <= 0) {
  4012. + pkg_vec_free(depends);
  4013. + return 0;
  4014. + }
  4015. +
  4016. + for (i = 0; i < depends->len; i++) {
  4017. + pkg_t *dep = depends->pkgs[i];
  4018. + /* The package was uninstalled when we started, but another
  4019. + dep earlier in this loop may have depended on it and pulled
  4020. + it in, so check first. */
  4021. + if ((dep->state_status != SS_INSTALLED)
  4022. + && (dep->state_status != SS_UNPACKED)
  4023. + && (dep->state_want != SW_INSTALL)) {
  4024. +
  4025. + /* Mark packages as to-be-installed */
  4026. + dep->state_want = SW_INSTALL;
  4027. +
  4028. + /* Dependencies should be installed the same place as pkg */
  4029. + if (dep->dest == NULL) {
  4030. + dep->dest = pkg->dest;
  4031. + }
  4032. +
  4033. + err = pkg_mark_dependencies_for_installation(conf, dep, pkgs_needed);
  4034. + if (err) {
  4035. + pkg_vec_free(depends);
  4036. + return err;
  4037. + }
  4038. + }
  4039. + }
  4040. + if (pkgs_needed)
  4041. + pkg_vec_insert(pkgs_needed, pkg);
  4042. +
  4043. + pkg_vec_free(depends);
  4044. +
  4045. + return 0;
  4046. +}
  4047. +
  4048. +int name_mark_dependencies_for_installation(ipkg_conf_t *conf, const char *pkg_name, pkg_vec_t *pkgs_needed)
  4049. +{
  4050. + int cmp;
  4051. + pkg_t *old, *new;
  4052. + char *old_version, *new_version;
  4053. +
  4054. + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg_name);
  4055. +
  4056. + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, pkg_name);
  4057. + if (new == NULL) {
  4058. + return IPKG_PKG_HAS_NO_CANDIDATE;
  4059. + }
  4060. + if (old) {
  4061. + old_version = pkg_version_str_alloc(old);
  4062. + new_version = pkg_version_str_alloc(new);
  4063. +
  4064. + cmp = pkg_compare_versions(old, new);
  4065. + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
  4066. + ipkg_message(conf, IPKG_DEBUG, " Forcing downgrade ");
  4067. + cmp = -1 ; /* then we force ipkg to downgrade */
  4068. + /* We need to use a value < 0 because in the 0 case we are asking to */
  4069. + /* reinstall, and some check could fail asking the "force-reinstall" option */
  4070. + }
  4071. + ipkg_message(conf, IPKG_DEBUG,
  4072. + "comparing visible versions of pkg %s:"
  4073. + "\n\t%s is installed "
  4074. + "\n\t%s is available "
  4075. + "\n\t%d was comparison result\n",
  4076. + pkg_name, old_version, new_version, cmp);
  4077. + if (cmp == 0 && !conf->force_reinstall) {
  4078. + ipkg_message(conf, IPKG_NOTICE,
  4079. + "Package %s (%s) installed in %s is up to date.\n",
  4080. + old->name, old_version, old->dest->name);
  4081. + free(old_version);
  4082. + free(new_version);
  4083. + return 0;
  4084. + } else if (cmp > 0) {
  4085. + ipkg_message(conf, IPKG_NOTICE,
  4086. + "Not downgrading package %s on %s from %s to %s.\n",
  4087. + old->name, old->dest->name, old_version, new_version);
  4088. + free(old_version);
  4089. + free(new_version);
  4090. + return 0;
  4091. + } else if (cmp < 0) {
  4092. + new->dest = old->dest;
  4093. + old->state_want = SW_DEINSTALL;
  4094. + old->state_flag |= SF_OBSOLETE;
  4095. + }
  4096. + }
  4097. + return pkg_mark_dependencies_for_installation(conf, new, pkgs_needed);
  4098. +}
  4099. +
  4100. +
  4101. +
  4102. +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg)
  4103. +{
  4104. + int i, err;
  4105. + pkg_vec_t *depends = pkg_vec_alloc();
  4106. + pkg_t *dep;
  4107. + char **unresolved = NULL;
  4108. + int ndepends;
  4109. +
  4110. + ndepends = pkg_hash_fetch_unsatisfied_dependencies(conf,
  4111. + pkg, depends,
  4112. + &unresolved);
  4113. +
  4114. + if (unresolved) {
  4115. + ipkg_message(conf, IPKG_ERROR,
  4116. + "%s: Cannot satisfy the following dependencies for %s:\n\t",
  4117. + conf->force_depends ? "Warning" : "ERROR", pkg->name);
  4118. + while (*unresolved) {
  4119. + ipkg_message(conf, IPKG_ERROR, " %s", *unresolved);
  4120. + unresolved++;
  4121. + }
  4122. + ipkg_message(conf, IPKG_ERROR, "\n");
  4123. + if (! conf->force_depends) {
  4124. + ipkg_message(conf, IPKG_INFO,
  4125. + "This could mean that your package list is out of date or that the packages\n"
  4126. + "mentioned above do not yet exist (try 'ipkg update'). To proceed in spite\n"
  4127. + "of this problem try again with the '-force-depends' option.\n");
  4128. + pkg_vec_free(depends);
  4129. + return IPKG_PKG_DEPS_UNSATISFIED;
  4130. + }
  4131. + }
  4132. +
  4133. + if (ndepends <= 0) {
  4134. + return 0;
  4135. + }
  4136. +
  4137. + /* Mark packages as to-be-installed */
  4138. + for (i=0; i < depends->len; i++) {
  4139. + /* Dependencies should be installed the same place as pkg */
  4140. + if (depends->pkgs[i]->dest == NULL) {
  4141. + depends->pkgs[i]->dest = pkg->dest;
  4142. + }
  4143. + depends->pkgs[i]->state_want = SW_INSTALL;
  4144. + }
  4145. +
  4146. + for (i = 0; i < depends->len; i++) {
  4147. + dep = depends->pkgs[i];
  4148. + /* The package was uninstalled when we started, but another
  4149. + dep earlier in this loop may have depended on it and pulled
  4150. + it in, so check first. */
  4151. + if ((dep->state_status != SS_INSTALLED)
  4152. + && (dep->state_status != SS_UNPACKED)) {
  4153. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
  4154. + err = ipkg_install_pkg(conf, dep,0);
  4155. + if (err) {
  4156. + pkg_vec_free(depends);
  4157. + return err;
  4158. + }
  4159. + }
  4160. + }
  4161. +
  4162. + pkg_vec_free(depends);
  4163. +
  4164. + return 0;
  4165. +}
  4166. +
  4167. +
  4168. +/* check all packages have their dependences satisfied, e.g., in case an upgraded package split */
  4169. +int ipkg_satisfy_all_dependences(ipkg_conf_t *conf)
  4170. +{
  4171. + if (conf->nodeps == 0) {
  4172. + int i;
  4173. + pkg_vec_t *installed = pkg_vec_alloc();
  4174. + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
  4175. + for (i = 0; i < installed->len; i++) {
  4176. + pkg_t *pkg = installed->pkgs[i];
  4177. + satisfy_dependencies_for(conf, pkg);
  4178. + }
  4179. + pkg_vec_free(installed);
  4180. + }
  4181. + return 0;
  4182. +}
  4183. +
  4184. +
  4185. +
  4186. +static int check_conflicts_for(ipkg_conf_t *conf, pkg_t *pkg)
  4187. +{
  4188. + int i;
  4189. + pkg_vec_t *conflicts = NULL;
  4190. + int level;
  4191. + const char *prefix;
  4192. + if (conf->force_depends) {
  4193. + level = IPKG_NOTICE;
  4194. + prefix = "Warning";
  4195. + } else {
  4196. + level = IPKG_ERROR;
  4197. + prefix = "ERROR";
  4198. + }
  4199. +
  4200. + if (!conf->force_depends)
  4201. + conflicts = (pkg_vec_t *)pkg_hash_fetch_conflicts(pkg);
  4202. +
  4203. + if (conflicts) {
  4204. + ipkg_message(conf, level,
  4205. + "%s: The following packages conflict with %s:\n\t", prefix, pkg->name);
  4206. + i = 0;
  4207. + while (i < conflicts->len)
  4208. + ipkg_message(conf, level, " %s", conflicts->pkgs[i++]->name);
  4209. + ipkg_message(conf, level, "\n");
  4210. + pkg_vec_free(conflicts);
  4211. + return IPKG_PKG_DEPS_UNSATISFIED;
  4212. + }
  4213. + return 0;
  4214. +}
  4215. +
  4216. +static int update_file_ownership(ipkg_conf_t *conf, pkg_t *new_pkg, pkg_t *old_pkg)
  4217. +{
  4218. + str_list_t *new_list = pkg_get_installed_files(new_pkg);
  4219. + str_list_elt_t *iter;
  4220. +
  4221. + for (iter = new_list->head; iter; iter = iter->next) {
  4222. + char *new_file = iter->data;
  4223. + pkg_t *owner = file_hash_get_file_owner(conf, new_file);
  4224. + if (!new_file)
  4225. + ipkg_message(conf, IPKG_ERROR, "Null new_file for new_pkg=%s\n", new_pkg->name);
  4226. + if (!owner || (owner == old_pkg))
  4227. + file_hash_set_file_owner(conf, new_file, new_pkg);
  4228. + }
  4229. + if (old_pkg) {
  4230. + str_list_t *old_list = pkg_get_installed_files(old_pkg);
  4231. + for (iter = old_list->head; iter; iter = iter->next) {
  4232. + char *old_file = iter->data;
  4233. + pkg_t *owner = file_hash_get_file_owner(conf, old_file);
  4234. + if (owner == old_pkg) {
  4235. + /* obsolete */
  4236. + hash_table_insert(&conf->obs_file_hash, old_file, old_pkg);
  4237. + }
  4238. + }
  4239. + }
  4240. + return 0;
  4241. +}
  4242. +
  4243. +static int verify_pkg_installable(ipkg_conf_t *conf, pkg_t *pkg)
  4244. +{
  4245. + /* XXX: FEATURE: Anything else needed here? Maybe a check on free space? */
  4246. +
  4247. + /* sma 6.20.02: yup; here's the first bit */
  4248. + /*
  4249. + * XXX: BUG easy for cworth
  4250. + * 1) please point the call below to the correct current root destination
  4251. + * 2) we need to resolve how to check the required space for a pending pkg,
  4252. + * my diddling with the .ipk file size below isn't going to cut it.
  4253. + * 3) return a proper error code instead of 1
  4254. + */
  4255. + int comp_size, blocks_available;
  4256. +
  4257. + if (!conf->force_space && pkg->installed_size != NULL) {
  4258. + blocks_available = get_available_blocks(conf->default_dest->root_dir);
  4259. +
  4260. + comp_size = strtoul(pkg->installed_size, NULL, 0);
  4261. + /* round up a blocks count without doing fancy-but-slow casting jazz */
  4262. + comp_size = (int)((comp_size + 1023) / 1024);
  4263. +
  4264. + if (comp_size >= blocks_available) {
  4265. + ipkg_message(conf, IPKG_ERROR,
  4266. + "Only have %d available blocks on filesystem %s, pkg %s needs %d\n",
  4267. + blocks_available, conf->default_dest->root_dir, pkg->name, comp_size);
  4268. + return ENOSPC;
  4269. + }
  4270. + }
  4271. + return 0;
  4272. +}
  4273. +
  4274. +static int unpack_pkg_control_files(ipkg_conf_t *conf, pkg_t *pkg)
  4275. +{
  4276. + int err;
  4277. + char *conffiles_file_name;
  4278. + char *root_dir;
  4279. + FILE *conffiles_file;
  4280. +
  4281. + sprintf_alloc(&pkg->tmp_unpack_dir, "%s/%s-XXXXXX", conf->tmp_dir, pkg->name);
  4282. +
  4283. + pkg->tmp_unpack_dir = mkdtemp(pkg->tmp_unpack_dir);
  4284. + if (pkg->tmp_unpack_dir == NULL) {
  4285. + ipkg_message(conf, IPKG_ERROR,
  4286. + "%s: Failed to create temporary directory '%s': %s\n",
  4287. + __FUNCTION__, pkg->tmp_unpack_dir, strerror(errno));
  4288. + return errno;
  4289. + }
  4290. +
  4291. + err = pkg_extract_control_files_to_dir(pkg, pkg->tmp_unpack_dir);
  4292. + if (err) {
  4293. + return err;
  4294. + }
  4295. +
  4296. + /* XXX: CLEANUP: There might be a cleaner place to read in the
  4297. + conffiles. Seems like I should be able to get everything to go
  4298. + through pkg_init_from_file. If so, maybe it would make sense to
  4299. + move all of unpack_pkg_control_files to that function. */
  4300. +
  4301. + /* Don't need to re-read conffiles if we already have it */
  4302. + if (pkg->conffiles.head) {
  4303. + return 0;
  4304. + }
  4305. +
  4306. + sprintf_alloc(&conffiles_file_name, "%s/conffiles", pkg->tmp_unpack_dir);
  4307. + if (! file_exists(conffiles_file_name)) {
  4308. + free(conffiles_file_name);
  4309. + return 0;
  4310. + }
  4311. +
  4312. + conffiles_file = fopen(conffiles_file_name, "r");
  4313. + if (conffiles_file == NULL) {
  4314. + fprintf(stderr, "%s: failed to open %s: %s\n",
  4315. + __FUNCTION__, conffiles_file_name, strerror(errno));
  4316. + free(conffiles_file_name);
  4317. + return errno;
  4318. + }
  4319. + free(conffiles_file_name);
  4320. +
  4321. + while (1) {
  4322. + char *cf_name;
  4323. + char *cf_name_in_dest;
  4324. +
  4325. + cf_name = file_read_line_alloc(conffiles_file);
  4326. + if (cf_name == NULL) {
  4327. + break;
  4328. + }
  4329. + str_chomp(cf_name);
  4330. + if (cf_name[0] == '\0') {
  4331. + continue;
  4332. + }
  4333. +
  4334. + /* Prepend dest->root_dir to conffile name.
  4335. + Take pains to avoid multiple slashes. */
  4336. + root_dir = pkg->dest->root_dir;
  4337. + if (conf->offline_root)
  4338. + /* skip the offline_root prefix */
  4339. + root_dir = pkg->dest->root_dir + strlen(conf->offline_root);
  4340. + sprintf_alloc(&cf_name_in_dest, "%s%s", root_dir,
  4341. + cf_name[0] == '/' ? (cf_name + 1) : cf_name);
  4342. +
  4343. + /* Can't get an md5sum now, (file isn't extracted yet).
  4344. + We'll wait until resolve_conffiles */
  4345. + conffile_list_append(&pkg->conffiles, cf_name_in_dest, NULL);
  4346. +
  4347. + free(cf_name);
  4348. + free(cf_name_in_dest);
  4349. + }
  4350. +
  4351. + fclose(conffiles_file);
  4352. +
  4353. + return 0;
  4354. +}
  4355. +
  4356. +/* returns number of installed replacees */
  4357. +int pkg_get_installed_replacees(pkg_t *pkg, pkg_vec_t *installed_replacees)
  4358. +{
  4359. + abstract_pkg_t **replaces = pkg->replaces;
  4360. + int replaces_count = pkg->replaces_count;
  4361. + int i, j;
  4362. + for (i = 0; i < replaces_count; i++) {
  4363. + abstract_pkg_t *ab_pkg = replaces[i];
  4364. + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
  4365. + if (pkg_vec) {
  4366. + for (j = 0; j < pkg_vec->len; j++) {
  4367. + pkg_t *replacee = pkg_vec->pkgs[j];
  4368. + if (!pkg_conflicts(pkg, replacee))
  4369. + continue;
  4370. + if (replacee->state_status == SS_INSTALLED) {
  4371. + pkg_vec_insert(installed_replacees, replacee);
  4372. + }
  4373. + }
  4374. + }
  4375. + }
  4376. + return installed_replacees->len;
  4377. +}
  4378. +
  4379. +int pkg_remove_installed_replacees(ipkg_conf_t *conf, pkg_vec_t *replacees)
  4380. +{
  4381. + int i;
  4382. + int replaces_count = replacees->len;
  4383. + for (i = 0; i < replaces_count; i++) {
  4384. + pkg_t *replacee = replacees->pkgs[i];
  4385. + int err;
  4386. + replacee->state_flag |= SF_REPLACE; /* flag it so remove won't complain */
  4387. + err = ipkg_remove_pkg(conf, replacee,0);
  4388. + if (err)
  4389. + return err;
  4390. + }
  4391. + return 0;
  4392. +}
  4393. +
  4394. +/* to unwind the removal: make sure they are installed */
  4395. +int pkg_remove_installed_replacees_unwind(ipkg_conf_t *conf, pkg_vec_t *replacees)
  4396. +{
  4397. + int i, err;
  4398. + int replaces_count = replacees->len;
  4399. + for (i = 0; i < replaces_count; i++) {
  4400. + pkg_t *replacee = replacees->pkgs[i];
  4401. + if (replacee->state_status != SS_INSTALLED) {
  4402. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
  4403. + err = ipkg_install_pkg(conf, replacee,0);
  4404. + if (err)
  4405. + return err;
  4406. + }
  4407. + }
  4408. + return 0;
  4409. +}
  4410. +
  4411. +int caught_sigint = 0;
  4412. +static void ipkg_install_pkg_sigint_handler(int sig)
  4413. +{
  4414. + caught_sigint = sig;
  4415. +}
  4416. +
  4417. +/* compares versions of pkg and old_pkg, returns 0 if OK to proceed with installation of pkg, 1 otherwise */
  4418. +static int ipkg_install_check_downgrade(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg, int message)
  4419. +{
  4420. + if (old_pkg) {
  4421. + char message_out[15];
  4422. + char *old_version = pkg_version_str_alloc(old_pkg);
  4423. + char *new_version = pkg_version_str_alloc(pkg);
  4424. + int cmp = pkg_compare_versions(old_pkg, pkg);
  4425. + int rc = 0;
  4426. +
  4427. + memset(message_out,'\x0',15);
  4428. + strncpy (message_out,"Upgrading ",strlen("Upgrading "));
  4429. + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
  4430. + cmp = -1 ; /* then we force ipkg to downgrade */
  4431. + strncpy (message_out,"Downgrading ",strlen("Downgrading ")); /* We need to use a value < 0 because in the 0 case we are asking to */
  4432. + /* reinstall, and some check could fail asking the "force-reinstall" option */
  4433. + }
  4434. +
  4435. + if (cmp > 0) {
  4436. + ipkg_message(conf, IPKG_NOTICE,
  4437. + "Not downgrading package %s on %s from %s to %s.\n",
  4438. + old_pkg->name, old_pkg->dest->name, old_version, new_version);
  4439. + rc = 1;
  4440. + } else if (cmp < 0) {
  4441. + ipkg_message(conf, IPKG_NOTICE,
  4442. + "%s%s on %s from %s to %s...\n",
  4443. + message_out, pkg->name, old_pkg->dest->name, old_version, new_version);
  4444. + pkg->dest = old_pkg->dest;
  4445. + rc = 0;
  4446. + } else /* cmp == 0 */ {
  4447. + if (conf->force_reinstall) {
  4448. + ipkg_message(conf, IPKG_NOTICE,
  4449. + "Reinstalling %s (%s) on %s...\n",
  4450. + pkg->name, new_version, old_pkg->dest->name);
  4451. + pkg->dest = old_pkg->dest;
  4452. + rc = 0;
  4453. + } else {
  4454. + ipkg_message(conf, IPKG_NOTICE,
  4455. + "Not installing %s (%s) on %s -- already installed.\n",
  4456. + pkg->name, new_version, old_pkg->dest->name);
  4457. + rc = 1;
  4458. + }
  4459. + }
  4460. + free(old_version);
  4461. + free(new_version);
  4462. + return rc;
  4463. + } else {
  4464. + char message_out[15], *version ;
  4465. + memset(message_out,'\x0',15);
  4466. + if ( message )
  4467. + strncpy( message_out,"Upgrading ",strlen("Upgrading ") );
  4468. + else
  4469. + strncpy( message_out,"Installing ",strlen("Installing ") );
  4470. + version = pkg_version_str_alloc(pkg);
  4471. +
  4472. + ipkg_message(conf, IPKG_NOTICE,
  4473. + "%s%s (%s) to %s...\n", message_out,
  4474. + pkg->name, version, pkg->dest->name);
  4475. + free(version);
  4476. + return 0;
  4477. + }
  4478. +}
  4479. +
  4480. +/* and now the meat... */
  4481. +int ipkg_install_pkg(ipkg_conf_t *conf, pkg_t *pkg, int from_upgrade)
  4482. +{
  4483. + int err = 0;
  4484. + int message = 0;
  4485. + pkg_t *old_pkg = NULL;
  4486. + pkg_vec_t *replacees;
  4487. + abstract_pkg_t *ab_pkg = NULL;
  4488. + int old_state_flag;
  4489. + uint8_t *file_md5;
  4490. +
  4491. +
  4492. + if ( from_upgrade )
  4493. + message = 1; /* Coming from an upgrade, and should change the output message */
  4494. +
  4495. + if (!pkg) {
  4496. + ipkg_message(conf, IPKG_ERROR,
  4497. + "INTERNAL ERROR: null pkg passed to ipkg_install_pkg\n");
  4498. + return -EINVAL;
  4499. + }
  4500. +
  4501. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s calling pkg_arch_supported %s \n", __FUNCTION__, __FUNCTION__);
  4502. +
  4503. + if (!pkg_arch_supported(conf, pkg)) {
  4504. + ipkg_message(conf, IPKG_ERROR, "INTERNAL ERROR: architecture %s for pkg %s is unsupported.\n",
  4505. + pkg->architecture, pkg->name);
  4506. + return -EINVAL;
  4507. + }
  4508. + if (pkg->state_status == SS_INSTALLED && conf->force_reinstall == 0 && conf->nodeps == 0) {
  4509. + err = satisfy_dependencies_for(conf, pkg);
  4510. + if (err) { return err; }
  4511. +
  4512. + ipkg_message(conf, IPKG_NOTICE,
  4513. + "Package %s is already installed in %s.\n",
  4514. + pkg->name, pkg->dest->name);
  4515. + return 0;
  4516. + }
  4517. +
  4518. + if (pkg->dest == NULL) {
  4519. + pkg->dest = conf->default_dest;
  4520. + }
  4521. +
  4522. + old_pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name);
  4523. +
  4524. + err = ipkg_install_check_downgrade(conf, pkg, old_pkg, message);
  4525. + if (err) { return err; }
  4526. +
  4527. + pkg->state_want = SW_INSTALL;
  4528. + if (old_pkg){
  4529. + old_pkg->state_want = SW_DEINSTALL; /* needed for check_data_file_clashes of dependences */
  4530. + }
  4531. +
  4532. +
  4533. + /* Abhaya: conflicts check */
  4534. + err = check_conflicts_for(conf, pkg);
  4535. + if (err) { return err; }
  4536. +
  4537. + /* this setup is to remove the upgrade scenario in the end when
  4538. + installing pkg A, A deps B & B deps on A. So both B and A are
  4539. + installed. Then A's installation is started resulting in an
  4540. + uncecessary upgrade */
  4541. + if (pkg->state_status == SS_INSTALLED
  4542. + && conf->force_reinstall == 0) return 0;
  4543. +
  4544. + err = verify_pkg_installable(conf, pkg);
  4545. + if (err) { return err; }
  4546. +
  4547. + if (pkg->local_filename == NULL) {
  4548. + err = ipkg_download_pkg(conf, pkg, conf->tmp_dir);
  4549. + if (err) {
  4550. + ipkg_message(conf, IPKG_ERROR,
  4551. + "Failed to download %s. Perhaps you need to run 'ipkg update'?\n",
  4552. + pkg->name);
  4553. + return err;
  4554. + }
  4555. + }
  4556. +
  4557. +/* Check for md5 values */
  4558. + if (pkg->md5sum)
  4559. + {
  4560. + file_md5 = file_md5sum_alloc(pkg->local_filename);
  4561. + if (strcmp((char *)file_md5, pkg->md5sum))
  4562. + {
  4563. + ipkg_message(conf, IPKG_ERROR,
  4564. + "Package %s md5sum mismatch. Either the ipkg or the package index are corrupt. Try 'ipkg update'.\n",
  4565. + pkg->name);
  4566. + free(file_md5);
  4567. + return err;
  4568. + }
  4569. + free(file_md5);
  4570. + }
  4571. +
  4572. + if (pkg->tmp_unpack_dir == NULL) {
  4573. + unpack_pkg_control_files(conf, pkg);
  4574. + }
  4575. +
  4576. + /* We should update the filelist here, so that upgrades of packages that split will not fail. -Jamey 27-MAR-03 */
  4577. +/* Pigi: check if it will pass from here when replacing. It seems to fail */
  4578. +/* That's rather strange that files don't change owner. Investigate !!!!!!*/
  4579. + err = update_file_ownership(conf, pkg, old_pkg);
  4580. + if (err) { return err; }
  4581. +
  4582. + if (conf->nodeps == 0) {
  4583. + err = satisfy_dependencies_for(conf, pkg);
  4584. + if (err) { return err; }
  4585. + }
  4586. +
  4587. + replacees = pkg_vec_alloc();
  4588. + pkg_get_installed_replacees(pkg, replacees);
  4589. +
  4590. + /* this next section we do with SIGINT blocked to prevent inconsistency between ipkg database and filesystem */
  4591. + {
  4592. + sigset_t newset, oldset;
  4593. + sighandler_t old_handler = NULL;
  4594. + int use_signal = 0;
  4595. + caught_sigint = 0;
  4596. + if (use_signal) {
  4597. + old_handler = signal(SIGINT, ipkg_install_pkg_sigint_handler);
  4598. + } else {
  4599. + sigemptyset(&newset);
  4600. + sigaddset(&newset, SIGINT);
  4601. + sigprocmask(SIG_BLOCK, &newset, &oldset);
  4602. + }
  4603. +
  4604. + ipkg_state_changed++;
  4605. + pkg->state_flag |= SF_FILELIST_CHANGED;
  4606. +
  4607. + /* XXX: BUG: we really should treat replacement more like an upgrade
  4608. + * Instead, we're going to remove the replacees
  4609. + */
  4610. + err = pkg_remove_installed_replacees(conf, replacees);
  4611. + if (err) goto UNWIND_REMOVE_INSTALLED_REPLACEES;
  4612. +
  4613. + /*
  4614. + err = prerm_upgrade_old_pkg(conf, pkg, old_pkg);
  4615. + if (err) goto UNWIND_PRERM_UPGRADE_OLD_PKG;
  4616. +
  4617. + err = prerm_deconfigure_conflictors(conf, pkg, replacees);
  4618. + if (err) goto UNWIND_PRERM_DECONFIGURE_CONFLICTORS;
  4619. + */
  4620. +
  4621. + err = preinst_configure(conf, pkg, old_pkg);
  4622. + /*
  4623. + if (err) goto UNWIND_PREINST_CONFIGURE;
  4624. + */
  4625. +
  4626. + err = backup_modified_conffiles(conf, pkg, old_pkg);
  4627. + if (err) goto UNWIND_BACKUP_MODIFIED_CONFFILES;
  4628. +
  4629. + err = check_data_file_clashes(conf, pkg, old_pkg);
  4630. + /*
  4631. + if (err) goto UNWIND_CHECK_DATA_FILE_CLASHES;
  4632. +
  4633. + err = postrm_upgrade_old_pkg(conf, pkg, old_pkg);
  4634. + if (err) goto UNWIND_POSTRM_UPGRADE_OLD_PKG;
  4635. + */
  4636. +
  4637. + if (conf->noaction) return 0;
  4638. +
  4639. + /* point of no return: no unwinding after this */
  4640. + if (old_pkg && !conf->force_reinstall) {
  4641. + old_pkg->state_want = SW_DEINSTALL;
  4642. +
  4643. + if (old_pkg->state_flag & SF_NOPRUNE) {
  4644. + ipkg_message(conf, IPKG_INFO,
  4645. + " not removing obsolesced files because package marked noprune\n");
  4646. + } else {
  4647. + ipkg_message(conf, IPKG_INFO,
  4648. + " removing obsolesced files\n");
  4649. + remove_obsolesced_files(conf, pkg, old_pkg);
  4650. + }
  4651. + /* removing files from old package, to avoid ghost files */
  4652. + remove_data_files_and_list(conf, old_pkg);
  4653. +/* Pigi : It should be better to remove also maintainer and postrem scripts here, just in case*/
  4654. + remove_maintainer_scripts_except_postrm(conf, old_pkg);
  4655. + remove_postrm(conf, old_pkg);
  4656. +/* Pigi */
  4657. +
  4658. + }
  4659. +
  4660. +
  4661. + ipkg_message(conf, IPKG_INFO,
  4662. + " installing maintainer scripts\n");
  4663. + install_maintainer_scripts(conf, pkg, old_pkg);
  4664. +
  4665. + /* the following just returns 0
  4666. + remove_disappeared(conf, pkg);
  4667. + */
  4668. +
  4669. + ipkg_message(conf, IPKG_INFO,
  4670. + " installing data files\n");
  4671. + install_data_files(conf, pkg);
  4672. +
  4673. +/* read comments from function for detail but I will execute this here as all other tests are ok.*/
  4674. + err = check_data_file_clashes_change(conf, pkg);
  4675. +
  4676. + ipkg_message(conf, IPKG_INFO,
  4677. + " resolving conf files\n");
  4678. + resolve_conffiles(conf, pkg);
  4679. +
  4680. + pkg->state_status = SS_UNPACKED;
  4681. + old_state_flag = pkg->state_flag;
  4682. + pkg->state_flag &= ~SF_PREFER;
  4683. + ipkg_message(conf, IPKG_DEBUG, " pkg=%s old_state_flag=%x state_flag=%x\n", pkg->name, old_state_flag, pkg->state_flag);
  4684. +
  4685. + if (old_pkg && !conf->force_reinstall) {
  4686. + old_pkg->state_status = SS_NOT_INSTALLED;
  4687. + }
  4688. +
  4689. + time(&pkg->installed_time);
  4690. +
  4691. + ipkg_message(conf, IPKG_INFO,
  4692. + " cleanup temp files\n");
  4693. + cleanup_temporary_files(conf, pkg);
  4694. +
  4695. + ab_pkg = pkg->parent;
  4696. + if (ab_pkg)
  4697. + ab_pkg->state_status = pkg->state_status;
  4698. +
  4699. + ipkg_message(conf, IPKG_INFO, "Done.\n");
  4700. +
  4701. + if (use_signal)
  4702. + signal(SIGINT, old_handler);
  4703. + else
  4704. + sigprocmask(SIG_UNBLOCK, &newset, &oldset);
  4705. +
  4706. + return 0;
  4707. +
  4708. +
  4709. + /*
  4710. + UNWIND_POSTRM_UPGRADE_OLD_PKG:
  4711. + postrm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
  4712. + UNWIND_CHECK_DATA_FILE_CLASHES:
  4713. + check_data_file_clashes_unwind(conf, pkg, old_pkg);
  4714. + */
  4715. + UNWIND_BACKUP_MODIFIED_CONFFILES:
  4716. + backup_modified_conffiles_unwind(pkg, old_pkg);
  4717. + /*
  4718. + UNWIND_PREINST_CONFIGURE:
  4719. + preinst_configure_unwind(conf, pkg, old_pkg);
  4720. + UNWIND_PRERM_DECONFIGURE_CONFLICTORS:
  4721. + prerm_deconfigure_conflictors_unwind(conf, pkg, replacees);
  4722. + UNWIND_PRERM_UPGRADE_OLD_PKG:
  4723. + prerm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
  4724. + */
  4725. + UNWIND_REMOVE_INSTALLED_REPLACEES:
  4726. + pkg_remove_installed_replacees_unwind(conf, replacees);
  4727. +
  4728. + ipkg_message(conf, IPKG_INFO,
  4729. + " cleanup temp files\n");
  4730. + cleanup_temporary_files(conf, pkg);
  4731. +
  4732. + ipkg_message(conf, IPKG_INFO,
  4733. + "Failed.\n");
  4734. + if (use_signal)
  4735. + signal(SIGINT, old_handler);
  4736. + else
  4737. + sigprocmask(SIG_UNBLOCK, &newset, &oldset);
  4738. +
  4739. + return err;
  4740. + }
  4741. +}
  4742. +
  4743. +/*
  4744. +static int prerm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4745. +{
  4746. + DPKG_INCOMPATIBILITY:
  4747. + dpkg does some things here that we don't do yet. Do we care?
  4748. +
  4749. + 1. If a version of the package is already installed, call
  4750. + old-prerm upgrade new-version
  4751. + 2. If the script runs but exits with a non-zero exit status
  4752. + new-prerm failed-upgrade old-version
  4753. + Error unwind, for both the above cases:
  4754. + old-postinst abort-upgrade new-version
  4755. + return 0;
  4756. +}
  4757. +*/
  4758. +
  4759. +/*
  4760. +static int prerm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4761. +{
  4762. + DPKG_INCOMPATIBILITY:
  4763. + dpkg does some things here that we don't do yet. Do we care?
  4764. + (See prerm_upgrade_old_package for details)
  4765. +
  4766. + return 0;
  4767. +}
  4768. +*/
  4769. +
  4770. +/*
  4771. +static int prerm_deconfigure_conflictors(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors)
  4772. +{
  4773. + DPKG_INCOMPATIBILITY:
  4774. + dpkg does some things here that we don't do yet. Do we care?
  4775. + 2. If a 'conflicting' package is being removed at the same time:
  4776. + 1. If any packages depended on that conflicting package and
  4777. + --auto-deconfigure is specified, call, for each such package:
  4778. + deconfigured's-prerm deconfigure \
  4779. + in-favour package-being-installed version \
  4780. + removing conflicting-package version
  4781. + Error unwind:
  4782. + deconfigured's-postinst abort-deconfigure \
  4783. + in-favour package-being-installed-but-failed version \
  4784. + removing conflicting-package version
  4785. +
  4786. + The deconfigured packages are marked as requiring
  4787. + configuration, so that if --install is used they will be
  4788. + configured again if possible.
  4789. + 2. To prepare for removal of the conflicting package, call:
  4790. + conflictor's-prerm remove in-favour package new-version
  4791. + Error unwind:
  4792. + conflictor's-postinst abort-remove in-favour package new-version
  4793. + return 0;
  4794. +}
  4795. +*/
  4796. +
  4797. +/*
  4798. +static int prerm_deconfigure_conflictors_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors)
  4799. +{
  4800. + DPKG_INCOMPATIBILITY: dpkg does some things here that we don't
  4801. + do yet. Do we care? (See prerm_deconfigure_conflictors for
  4802. + details)
  4803. + return 0;
  4804. +}
  4805. +*/
  4806. +
  4807. +static int preinst_configure(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4808. +{
  4809. + int err;
  4810. + char *preinst_args;
  4811. +
  4812. + if (old_pkg) {
  4813. + char *old_version = pkg_version_str_alloc(old_pkg);
  4814. + sprintf_alloc(&preinst_args, "upgrade %s", old_version);
  4815. + free(old_version);
  4816. + } else if (pkg->state_status == SS_CONFIG_FILES) {
  4817. + char *pkg_version = pkg_version_str_alloc(pkg);
  4818. + sprintf_alloc(&preinst_args, "install %s", pkg_version);
  4819. + free(pkg_version);
  4820. + } else {
  4821. + preinst_args = strdup("install");
  4822. + }
  4823. +
  4824. + err = pkg_run_script(conf, pkg, "preinst", preinst_args);
  4825. + if (err) {
  4826. + ipkg_message(conf, IPKG_ERROR,
  4827. + "Aborting installation of %s\n", pkg->name);
  4828. + return 1;
  4829. + }
  4830. +
  4831. + free(preinst_args);
  4832. +
  4833. + return 0;
  4834. +}
  4835. +
  4836. +/*
  4837. +static int preinst_configure_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4838. +{
  4839. + DPKG_INCOMPATIBILITY:
  4840. + dpkg does the following error unwind, should we?
  4841. + pkg->postrm abort-upgrade old-version
  4842. + OR pkg->postrm abort-install old-version
  4843. + OR pkg->postrm abort-install
  4844. + return 0;
  4845. +}
  4846. +*/
  4847. +
  4848. +static int backup_modified_conffiles(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4849. +{
  4850. + int err;
  4851. + conffile_list_elt_t *iter;
  4852. + conffile_t *cf;
  4853. +
  4854. + if (conf->noaction) return 0;
  4855. +
  4856. + /* Backup all modified conffiles */
  4857. + if (old_pkg) {
  4858. + for (iter = old_pkg->conffiles.head; iter; iter = iter->next) {
  4859. + char *cf_name;
  4860. +
  4861. + cf = iter->data;
  4862. + cf_name = root_filename_alloc(conf, cf->name);
  4863. +
  4864. + /* Don't worry if the conffile is just plain gone */
  4865. + if (file_exists(cf_name) && conffile_has_been_modified(conf, cf)) {
  4866. + err = backup_make_backup(conf, cf_name);
  4867. + if (err) {
  4868. + return err;
  4869. + }
  4870. + }
  4871. + free(cf_name);
  4872. + }
  4873. + }
  4874. +
  4875. + /* Backup all conffiles that were not conffiles in old_pkg */
  4876. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  4877. + char *cf_name;
  4878. + cf = iter->data;
  4879. + cf_name = root_filename_alloc(conf, cf->name);
  4880. + /* Ignore if this was a conffile in old_pkg as well */
  4881. + if (pkg_get_conffile(old_pkg, cf->name)) {
  4882. + continue;
  4883. + }
  4884. +
  4885. + if (file_exists(cf_name) && (! backup_exists_for(cf_name))) {
  4886. + err = backup_make_backup(conf, cf_name);
  4887. + if (err) {
  4888. + return err;
  4889. + }
  4890. + }
  4891. + free(cf_name);
  4892. + }
  4893. +
  4894. + return 0;
  4895. +}
  4896. +
  4897. +static int backup_modified_conffiles_unwind(pkg_t *pkg, pkg_t *old_pkg)
  4898. +{
  4899. + conffile_list_elt_t *iter;
  4900. +
  4901. + if (old_pkg) {
  4902. + for (iter = old_pkg->conffiles.head; iter; iter = iter->next) {
  4903. + backup_remove(iter->data->name);
  4904. + }
  4905. + }
  4906. +
  4907. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  4908. + backup_remove(iter->data->name);
  4909. + }
  4910. +
  4911. + return 0;
  4912. +}
  4913. +
  4914. +
  4915. +static int check_data_file_clashes(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4916. +{
  4917. + /* DPKG_INCOMPATIBILITY:
  4918. + ipkg takes a slightly different approach than dpkg at this
  4919. + point. dpkg installs each file in the new package while
  4920. + creating a backup for any file that is replaced, (so that it
  4921. + can unwind if necessary). To avoid complexity and redundant
  4922. + storage, ipkg doesn't do any installation until later, (at the
  4923. + point at which dpkg removes the backups.
  4924. +
  4925. + But, we do have to check for data file clashes, since after
  4926. + installing a package with a file clash, removing either of the
  4927. + packages involved in the clash has the potential to break the
  4928. + other package.
  4929. + */
  4930. + str_list_t *files_list;
  4931. + str_list_elt_t *iter;
  4932. +
  4933. + int clashes = 0;
  4934. +
  4935. + files_list = pkg_get_installed_files(pkg);
  4936. + for (iter = files_list->head; iter; iter = iter->next) {
  4937. + char *root_filename;
  4938. + char *filename = iter->data;
  4939. + root_filename = root_filename_alloc(conf, filename);
  4940. + if (file_exists(root_filename) && (! file_is_dir(root_filename))) {
  4941. + pkg_t *owner;
  4942. + pkg_t *obs;
  4943. + /* Pre-existing conffiles are OK */
  4944. + /* @@@@ should have way to check that it is a conffile -Jamey */
  4945. + if (backup_exists_for(root_filename)) {
  4946. + continue;
  4947. + }
  4948. +
  4949. + /* Pre-existing files are OK if force-overwrite was asserted. */
  4950. + if (conf->force_overwrite) {
  4951. + /* but we need to change who owns this file */
  4952. + file_hash_set_file_owner(conf, filename, pkg);
  4953. + continue;
  4954. + }
  4955. +
  4956. + owner = file_hash_get_file_owner(conf, filename);
  4957. +
  4958. + /* Pre-existing files are OK if owned by the pkg being upgraded. */
  4959. + if (owner && old_pkg) {
  4960. + if (strcmp(owner->name, old_pkg->name) == 0) {
  4961. + continue;
  4962. + }
  4963. + }
  4964. +
  4965. + /* Pre-existing files are OK if owned by a package replaced by new pkg. */
  4966. + if (owner) {
  4967. + ipkg_message(conf, IPKG_DEBUG2, "Checking for replaces for %s in package %s\n", filename, owner->name);
  4968. + if (pkg_replaces(pkg, owner)) {
  4969. + continue;
  4970. + }
  4971. +/* If the file that would be installed is owned by the same package, ( as per a reinstall or similar )
  4972. + then it's ok to overwrite. */
  4973. + if (strcmp(owner->name,pkg->name)==0){
  4974. + ipkg_message(conf, IPKG_INFO, "Replacing pre-existing file %s owned by package %s\n", filename, owner->name);
  4975. + continue;
  4976. + }
  4977. + }
  4978. +
  4979. + /* Pre-existing files are OK if they are obsolete */
  4980. + obs = hash_table_get(&conf->obs_file_hash, filename);
  4981. + if (obs) {
  4982. + ipkg_message(conf, IPKG_INFO, "Pre-exiting file %s is obsolete. obs_pkg=%s\n", filename, obs->name);
  4983. + continue;
  4984. + }
  4985. +
  4986. + /* We have found a clash. */
  4987. + ipkg_message(conf, IPKG_ERROR,
  4988. + "Package %s wants to install file %s\n"
  4989. + "\tBut that file is already provided by package ",
  4990. + pkg->name, filename);
  4991. + if (owner) {
  4992. + ipkg_message(conf, IPKG_ERROR,
  4993. + "%s\n", owner->name);
  4994. + } else {
  4995. + ipkg_message(conf, IPKG_ERROR,
  4996. + "<no package>\nPlease move this file out of the way and try again.\n");
  4997. + }
  4998. + clashes++;
  4999. + }
  5000. + free(root_filename);
  5001. + }
  5002. + pkg_free_installed_files(pkg);
  5003. +
  5004. + return clashes;
  5005. +}
  5006. +
  5007. +static int check_data_file_clashes_change(ipkg_conf_t *conf, pkg_t *pkg)
  5008. +{
  5009. + /* Basically that's the worst hack I could do to be able to change ownership of
  5010. + file list, but, being that we have no way to unwind the mods, due to structure
  5011. + of hash table, probably is the quickest hack too, whishing it would not slow-up thing too much.
  5012. + What we do here is change the ownership of file in hash if a replace ( or similar events
  5013. + happens )
  5014. + Only the action that are needed to change name should be considered.
  5015. + @@@ To change after 1.0 release.
  5016. + */
  5017. + str_list_t *files_list;
  5018. + str_list_elt_t *iter;
  5019. +
  5020. + int clashes = 0;
  5021. +
  5022. + files_list = pkg_get_installed_files(pkg);
  5023. + for (iter = files_list->head; iter; iter = iter->next) {
  5024. + char *root_filename;
  5025. + char *filename = iter->data;
  5026. + root_filename = root_filename_alloc(conf, filename);
  5027. + if (file_exists(root_filename) && (! file_is_dir(root_filename))) {
  5028. + pkg_t *owner;
  5029. +
  5030. + if (conf->force_overwrite) {
  5031. + /* but we need to change who owns this file */
  5032. + file_hash_set_file_owner(conf, filename, pkg);
  5033. + continue;
  5034. + }
  5035. +
  5036. + owner = file_hash_get_file_owner(conf, filename);
  5037. +
  5038. + /* Pre-existing files are OK if owned by a package replaced by new pkg. */
  5039. + if (owner) {
  5040. + if (pkg_replaces(pkg, owner)) {
  5041. +/* It's now time to change the owner of that file.
  5042. + It has been "replaced" from the new "Replaces", then I need to inform lists file about that. */
  5043. + ipkg_message(conf, IPKG_INFO, "Replacing pre-existing file %s owned by package %s\n", filename, owner->name);
  5044. + file_hash_set_file_owner(conf, filename, pkg);
  5045. + continue;
  5046. + }
  5047. + }
  5048. +
  5049. + }
  5050. + free(root_filename);
  5051. + }
  5052. + pkg_free_installed_files(pkg);
  5053. +
  5054. + return clashes;
  5055. +}
  5056. +
  5057. +/*
  5058. +static int check_data_file_clashes_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5059. +{
  5060. + Nothing to do since check_data_file_clashes doesn't change state
  5061. + return 0;
  5062. +}
  5063. +*/
  5064. +
  5065. +/*
  5066. +static int postrm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5067. +{
  5068. + DPKG_INCOMPATIBILITY: dpkg does the following here, should we?
  5069. + 1. If the package is being upgraded, call
  5070. + old-postrm upgrade new-version
  5071. + 2. If this fails, attempt:
  5072. + new-postrm failed-upgrade old-version
  5073. + Error unwind, for both cases:
  5074. + old-preinst abort-upgrade new-version
  5075. + return 0;
  5076. +}
  5077. +*/
  5078. +
  5079. +/*
  5080. +static int postrm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5081. +{
  5082. + DPKG_INCOMPATIBILITY:
  5083. + dpkg does some things here that we don't do yet. Do we care?
  5084. + (See postrm_upgrade_old_pkg for details)
  5085. + return 0;
  5086. +}
  5087. +*/
  5088. +
  5089. +static int remove_obsolesced_files(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5090. +{
  5091. + int err;
  5092. + str_list_t *old_files;
  5093. + str_list_elt_t *of;
  5094. + str_list_t *new_files;
  5095. + str_list_elt_t *nf;
  5096. +
  5097. + if (old_pkg == NULL) {
  5098. + return 0;
  5099. + }
  5100. +
  5101. + old_files = pkg_get_installed_files(old_pkg);
  5102. + new_files = pkg_get_installed_files(pkg);
  5103. +
  5104. + for (of = old_files->head; of; of = of->next) {
  5105. + pkg_t *owner;
  5106. + char *old, *new;
  5107. + old = of->data;
  5108. + for (nf = new_files->head; nf; nf = nf->next) {
  5109. + new = nf->data;
  5110. + if (strcmp(old, new) == 0) {
  5111. + goto NOT_OBSOLETE;
  5112. + }
  5113. + }
  5114. + if (file_is_dir(old)) {
  5115. + continue;
  5116. + }
  5117. + owner = file_hash_get_file_owner(conf, old);
  5118. + if (owner != old_pkg) {
  5119. + /* in case obsolete file no longer belongs to old_pkg */
  5120. + continue;
  5121. + }
  5122. +
  5123. + /* old file is obsolete */
  5124. + ipkg_message(conf, IPKG_INFO,
  5125. + " removing obsolete file %s\n", old);
  5126. + if (!conf->noaction) {
  5127. + err = unlink(old);
  5128. + if (err) {
  5129. + ipkg_message(conf, IPKG_ERROR, " Warning: remove %s failed: %s\n", old,
  5130. + strerror(errno));
  5131. + }
  5132. + }
  5133. +
  5134. + NOT_OBSOLETE:
  5135. + ;
  5136. + }
  5137. +
  5138. + pkg_free_installed_files(old_pkg);
  5139. + pkg_free_installed_files(pkg);
  5140. +
  5141. + return 0;
  5142. +}
  5143. +
  5144. +static int remove_obsolete_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5145. +{
  5146. + int i;
  5147. + int err = 0;
  5148. + char *globpattern;
  5149. + glob_t globbuf;
  5150. + if (0) {
  5151. + if (!pkg->dest) {
  5152. + ipkg_message(conf, IPKG_ERROR, "%s: no dest for package %s\n", __FUNCTION__, pkg->name);
  5153. + return -1;
  5154. + }
  5155. + sprintf_alloc(&globpattern, "%s/%s.*", pkg->dest->info_dir, pkg->name);
  5156. + err = glob(globpattern, 0, NULL, &globbuf);
  5157. + free(globpattern);
  5158. + if (err) {
  5159. + return err;
  5160. + }
  5161. + /* XXXX this should perhaps only remove the ones that are not overwritten in new package. Jamey 11/11/2003 */
  5162. + for (i = 0; i < globbuf.gl_pathc; i++) {
  5163. + ipkg_message(conf, IPKG_DEBUG, "Removing control file %s from old_pkg %s\n",
  5164. + globbuf.gl_pathv[i], old_pkg->name);
  5165. + if (!conf->noaction)
  5166. + unlink(globbuf.gl_pathv[i]);
  5167. + }
  5168. + globfree(&globbuf);
  5169. + }
  5170. + return err;
  5171. +}
  5172. +
  5173. +static int install_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5174. +{
  5175. + int ret;
  5176. + char *prefix;
  5177. +
  5178. + if (old_pkg)
  5179. + remove_obsolete_maintainer_scripts(conf, pkg, old_pkg);
  5180. + sprintf_alloc(&prefix, "%s.", pkg->name);
  5181. + ret = pkg_extract_control_files_to_dir_with_prefix(pkg,
  5182. + pkg->dest->info_dir,
  5183. + prefix);
  5184. + free(prefix);
  5185. + return ret;
  5186. +}
  5187. +
  5188. +/*
  5189. +static int remove_disappeared(ipkg_conf_t *conf, pkg_t *pkg)
  5190. +{
  5191. + DPKG_INCOMPATIBILITY:
  5192. + This is a fairly sophisticated dpkg operation. Shall we
  5193. + skip it?
  5194. +
  5195. + Any packages all of whose files have been overwritten during the
  5196. + installation, and which aren't required for dependencies, are
  5197. + considered to have been removed. For each such package
  5198. + 1. disappearer's-postrm disappear overwriter overwriter-version
  5199. + 2. The package's maintainer scripts are removed
  5200. + 3. It is noted in the status database as being in a sane state,
  5201. + namely not installed (any conffiles it may have are ignored,
  5202. + rather than being removed by dpkg). Note that disappearing
  5203. + packages do not have their prerm called, because dpkg doesn't
  5204. + know in advance that the package is going to vanish.
  5205. +
  5206. +
  5207. + return 0;
  5208. +}
  5209. +*/
  5210. +
  5211. +static int install_data_files(ipkg_conf_t *conf, pkg_t *pkg)
  5212. +{
  5213. + int err;
  5214. +
  5215. + /* ipkg takes a slightly different approach to data file backups
  5216. + than dpkg. Rather than removing backups at this point, we
  5217. + actually do the data file installation now. See comments in
  5218. + check_data_file_clashes() for more details. */
  5219. +
  5220. + ipkg_message(conf, IPKG_INFO,
  5221. + " extracting data files to %s\n", pkg->dest->root_dir);
  5222. + err = pkg_extract_data_files_to_dir(pkg, pkg->dest->root_dir);
  5223. + if (err) {
  5224. + return err;
  5225. + }
  5226. +
  5227. + /* XXX: BUG or FEATURE : We are actually loosing the Essential flag,
  5228. + so we can't save ourself from removing important packages
  5229. + At this point we (should) have extracted the .control file, so it
  5230. + would be a good idea to reload the data in it, and set the Essential
  5231. + state in *pkg. From now on the Essential is back in status file and
  5232. + we can protect again.
  5233. + We should operate this way:
  5234. + fopen the file ( pkg->dest->root_dir/pkg->name.control )
  5235. + check for "Essential" in it
  5236. + set the value in pkg->essential.
  5237. + This new routine could be useful also for every other flag
  5238. + Pigi: 16/03/2004 */
  5239. + set_flags_from_control(conf, pkg) ;
  5240. +
  5241. + ipkg_message(conf, IPKG_DEBUG, " Calling pkg_write_filelist from %s\n", __FUNCTION__);
  5242. + err = pkg_write_filelist(conf, pkg);
  5243. + if (err)
  5244. + return err;
  5245. +
  5246. + /* XXX: FEATURE: ipkg should identify any files which existed
  5247. + before installation and which were overwritten, (see
  5248. + check_data_file_clashes()). What it must do is remove any such
  5249. + files from the filelist of the old package which provided the
  5250. + file. Otherwise, if the old package were removed at some point
  5251. + it would break the new package. Removing the new package will
  5252. + also break the old one, but this cannot be helped since the old
  5253. + package's file has already been deleted. This is the importance
  5254. + of check_data_file_clashes(), and only allowing ipkg to install
  5255. + a clashing package with a user force. */
  5256. +
  5257. + return 0;
  5258. +}
  5259. +
  5260. +static int resolve_conffiles(ipkg_conf_t *conf, pkg_t *pkg)
  5261. +{
  5262. + conffile_list_elt_t *iter;
  5263. + conffile_t *cf;
  5264. + char *cf_backup;
  5265. + uint8_t *md5sum;
  5266. +
  5267. +
  5268. + if (conf->noaction) return 0;
  5269. +
  5270. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  5271. + char *root_filename;
  5272. + cf = iter->data;
  5273. + root_filename = root_filename_alloc(conf, cf->name);
  5274. +
  5275. + /* Might need to initialize the md5sum for each conffile */
  5276. + if (cf->value == NULL) {
  5277. + cf->value = (char *)file_md5sum_alloc(root_filename);
  5278. + }
  5279. +
  5280. + if (!file_exists(root_filename)) {
  5281. + free(root_filename);
  5282. + continue;
  5283. + }
  5284. +
  5285. + cf_backup = backup_filename_alloc(root_filename);
  5286. +
  5287. +
  5288. + if (file_exists(cf_backup)) {
  5289. + /* Let's compute md5 to test if files are changed */
  5290. + md5sum = file_md5sum_alloc(cf_backup);
  5291. + if (strcmp( cf->value, (char *)md5sum) != 0 ) {
  5292. + if (conf->force_defaults
  5293. + || user_prefers_old_conffile(cf->name, cf_backup) ) {
  5294. + rename(cf_backup, root_filename);
  5295. + }
  5296. + }
  5297. + unlink(cf_backup);
  5298. + free(md5sum);
  5299. + }
  5300. +
  5301. + free(cf_backup);
  5302. + free(root_filename);
  5303. + }
  5304. +
  5305. + return 0;
  5306. +}
  5307. +
  5308. +static int user_prefers_old_conffile(const char *file_name, const char *backup)
  5309. +{
  5310. + char *response;
  5311. + const char *short_file_name;
  5312. +
  5313. + short_file_name = strrchr(file_name, '/');
  5314. + if (short_file_name) {
  5315. + short_file_name++;
  5316. + } else {
  5317. + short_file_name = file_name;
  5318. + }
  5319. +
  5320. + while (1) {
  5321. + response = get_user_response(" Configuration file '%s'\n"
  5322. + " ==> File on system created by you or by a script.\n"
  5323. + " ==> File also in package provided by package maintainer.\n"
  5324. + " What would you like to do about it ? Your options are:\n"
  5325. + " Y or I : install the package maintainer's version\n"
  5326. + " N or O : keep your currently-installed version\n"
  5327. +#ifdef CONFIG_DIFF
  5328. + " D : show the differences between the versions\n"
  5329. +#endif
  5330. + " The default action is to keep your current version.\n"
  5331. + " *** %s (Y/I/N/O"
  5332. +#ifdef CONFIG_DIFF
  5333. + "/D"
  5334. +#endif
  5335. + ") [default=N] ? ", file_name, short_file_name);
  5336. + if (strcmp(response, "y") == 0
  5337. + || strcmp(response, "i") == 0
  5338. + || strcmp(response, "yes") == 0) {
  5339. + free(response);
  5340. + return 0;
  5341. + }
  5342. +
  5343. +#ifdef CONFIG_DIFF
  5344. + if (strcmp(response, "d") == 0) {
  5345. + char *cmd;
  5346. +
  5347. + free(response);
  5348. + /* XXX: BUG rewrite to use exec or busybox's internal diff */
  5349. + sprintf_alloc(&cmd, "diff -u %s %s", backup, file_name);
  5350. + xsystem(cmd);
  5351. + free(cmd);
  5352. + printf(" [Press ENTER to continue]\n");
  5353. + response = file_read_line_alloc(stdin);
  5354. + free(response);
  5355. + continue;
  5356. + }
  5357. +#endif
  5358. +
  5359. + free(response);
  5360. + return 1;
  5361. + }
  5362. +}
  5363. +
  5364. +/* XXX: CLEANUP: I'd like to move all of the code for
  5365. + creating/cleaning pkg->tmp_unpack_dir directly into pkg.c. (Then,
  5366. + it would make sense to cleanup pkg->tmp_unpack_dir directly from
  5367. + pkg_deinit for example). */
  5368. +static int cleanup_temporary_files(ipkg_conf_t *conf, pkg_t *pkg)
  5369. +{
  5370. + DIR *tmp_dir;
  5371. + struct dirent *dirent;
  5372. + char *tmp_file;
  5373. +
  5374. +#ifdef IPKG_DEBUG_NO_TMP_CLEANUP
  5375. +#error
  5376. + ipkg_message(conf, IPKG_DEBUG,
  5377. + "%s: Not cleaning up %s since ipkg compiled with IPKG_DEBUG_NO_TMP_CLEANUP\n",
  5378. + __FUNCTION__, pkg->tmp_unpack_dir);
  5379. + return 0;
  5380. +#endif
  5381. +
  5382. + if (pkg->tmp_unpack_dir && file_is_dir(pkg->tmp_unpack_dir)) {
  5383. + tmp_dir = opendir(pkg->tmp_unpack_dir);
  5384. + if (tmp_dir) {
  5385. + while (1) {
  5386. + dirent = readdir(tmp_dir);
  5387. + if (dirent == NULL) {
  5388. + break;
  5389. + }
  5390. + sprintf_alloc(&tmp_file, "%s/%s",
  5391. + pkg->tmp_unpack_dir, dirent->d_name);
  5392. + if (! file_is_dir(tmp_file)) {
  5393. + unlink(tmp_file);
  5394. + }
  5395. + free(tmp_file);
  5396. + }
  5397. + closedir(tmp_dir);
  5398. + rmdir(pkg->tmp_unpack_dir);
  5399. + free(pkg->tmp_unpack_dir);
  5400. + pkg->tmp_unpack_dir = NULL;
  5401. + }
  5402. + }
  5403. +
  5404. + ipkg_message(conf, IPKG_INFO, "cleanup_temporary_files: pkg=%s local_filename=%s tmp_dir=%s\n",
  5405. + pkg->name, pkg->local_filename, conf->tmp_dir);
  5406. + if (pkg->local_filename && strncmp(pkg->local_filename, conf->tmp_dir, strlen(conf->tmp_dir)) == 0) {
  5407. + unlink(pkg->local_filename);
  5408. + free(pkg->local_filename);
  5409. + pkg->local_filename = NULL;
  5410. + }
  5411. +
  5412. + return 0;
  5413. +}
  5414. +
  5415. +static char *backup_filename_alloc(const char *file_name)
  5416. +{
  5417. + char *backup;
  5418. +
  5419. + sprintf_alloc(&backup, "%s%s", file_name, IPKG_BACKUP_SUFFIX);
  5420. +
  5421. + return backup;
  5422. +}
  5423. +
  5424. +int backup_make_backup(ipkg_conf_t *conf, const char *file_name)
  5425. +{
  5426. + int err;
  5427. + char *backup;
  5428. +
  5429. + backup = backup_filename_alloc(file_name);
  5430. + err = file_copy(file_name, backup);
  5431. + if (err) {
  5432. + ipkg_message(conf, IPKG_ERROR,
  5433. + "%s: Failed to copy %s to %s\n",
  5434. + __FUNCTION__, file_name, backup);
  5435. + }
  5436. +
  5437. + free(backup);
  5438. +
  5439. + return err;
  5440. +}
  5441. +
  5442. +static int backup_exists_for(const char *file_name)
  5443. +{
  5444. + int ret;
  5445. + char *backup;
  5446. +
  5447. + backup = backup_filename_alloc(file_name);
  5448. +
  5449. + ret = file_exists(backup);
  5450. +
  5451. + free(backup);
  5452. +
  5453. + return ret;
  5454. +}
  5455. +
  5456. +static int backup_remove(const char *file_name)
  5457. +{
  5458. + char *backup;
  5459. +
  5460. + backup = backup_filename_alloc(file_name);
  5461. + unlink(backup);
  5462. + free(backup);
  5463. +
  5464. + return 0;
  5465. +}
  5466. +
  5467. +
  5468. +
  5469. +#ifdef CONFIG_IPKG_PROCESS_ACTIONS
  5470. +
  5471. +int ipkg_remove_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove)
  5472. +{
  5473. + /* first, remove the packages that need removing */
  5474. + for (i = 0 ; i < pkgs_to_remove->len; i++ ) {
  5475. + pkg_t *pkg = pkgs_to_remove->pkgs[i];
  5476. + err = ipkg_remove_pkg(conf, pkg,0);
  5477. + if (err) return err;
  5478. + }
  5479. + return 0;
  5480. +}
  5481. +
  5482. +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)
  5483. +{
  5484. + int i;
  5485. + /* now one more pass checking on the ones that need to be installed */
  5486. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5487. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5488. + if (pkg->dest == NULL)
  5489. + pkg->dest = conf->default_dest;
  5490. +
  5491. + pkg->state_want = SW_INSTALL;
  5492. +
  5493. + /* Abhaya: conflicts check */
  5494. + err = check_conflicts_for(conf, pkg);
  5495. + if (err) { return err; }
  5496. + }
  5497. + return 0;
  5498. +}
  5499. +
  5500. +int ipkg_process_actions_unpack_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_to_install)
  5501. +{
  5502. + int i;
  5503. + /* now one more pass checking on the ones that need to be installed */
  5504. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5505. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5506. +
  5507. + /* XXX: FEATURE: Need to really support Provides/Replaces: here at some point */
  5508. + pkg_vec_t *replacees = pkg_vec_alloc();
  5509. + pkg_get_installed_replacees(pkg, replacees);
  5510. +
  5511. + /* XXX: BUG: we really should treat replacement more like an upgrade
  5512. + * Instead, we're going to remove the replacees
  5513. + */
  5514. + err = pkg_remove_installed_replacees(conf, replacees);
  5515. + if (err) return err;
  5516. + pkg->state_flag |= SF_REMOVED_REPLACEES;
  5517. + }
  5518. + return 0;
  5519. +}
  5520. +
  5521. +int ipkg_process_actions_unpack_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_to_install)
  5522. +{
  5523. + int i;
  5524. + /* now one more pass checking on the ones that need to be installed */
  5525. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5526. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5527. + if (pkg->local_filename == NULL) {
  5528. + err = ipkg_download_pkg(conf, pkg, conf->tmp_dir);
  5529. + if (err) {
  5530. + ipkg_message(conf, IPKG_ERROR,
  5531. + "Failed to download %s. Perhaps you need to run 'ipkg update'?\n",
  5532. + pkg->name);
  5533. + return err;
  5534. + }
  5535. + }
  5536. + if (pkg->tmp_unpack_dir == NULL) {
  5537. + err = unpack_pkg_control_files(conf, pkg);
  5538. + if (err) return err;
  5539. + }
  5540. + }
  5541. + return 0;
  5542. +}
  5543. +
  5544. +int ipkg_process_actions_prerm(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
  5545. +{
  5546. + int i;
  5547. + /* now one more pass checking on the ones that need to be installed */
  5548. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5549. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5550. + pkg_t *old_pkg = pkg->old_pkg;
  5551. +
  5552. + err = prerm_upgrade_old_pkg(conf, pkg, old_pkg);
  5553. + if (err) return err;
  5554. +
  5555. + err = prerm_deconfigure_conflictors(conf, pkg, replacees);
  5556. + if (err) return err;
  5557. +
  5558. + err = preinst_configure(conf, pkg, old_pkg);
  5559. + if (err) return err;
  5560. +
  5561. + err = backup_modified_conffiles(conf, pkg, old_pkg);
  5562. + if (err) return err;
  5563. +
  5564. + err = postrm_upgrade_old_pkg(conf, pkg, old_pkg);
  5565. + if (err) return err;
  5566. + }
  5567. + return 0;
  5568. +}
  5569. +
  5570. +int ipkg_process_actions_install(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
  5571. +{
  5572. + int i;
  5573. + /* now one more pass checking on the ones that need to be installed */
  5574. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5575. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5576. + pkg_t *old_pkg = pkg->old_pkg;
  5577. +
  5578. + if (old_pkg) {
  5579. + old_pkg->state_want = SW_DEINSTALL;
  5580. +
  5581. + if (old_pkg->state_flag & SF_NOPRUNE) {
  5582. + ipkg_message(conf, IPKG_INFO,
  5583. + " not removing obsolesced files because package marked noprune\n");
  5584. + } else {
  5585. + ipkg_message(conf, IPKG_INFO,
  5586. + " removing obsolesced files\n");
  5587. + remove_obsolesced_files(conf, pkg, old_pkg);
  5588. + }
  5589. + }
  5590. +
  5591. + ipkg_message(conf, IPKG_INFO,
  5592. + " installing maintainer scripts\n");
  5593. + install_maintainer_scripts(conf, pkg, old_pkg);
  5594. +
  5595. + /* the following just returns 0 */
  5596. + remove_disappeared(conf, pkg);
  5597. +
  5598. + ipkg_message(conf, IPKG_INFO,
  5599. + " installing data files\n");
  5600. + install_data_files(conf, pkg);
  5601. +
  5602. + ipkg_message(conf, IPKG_INFO,
  5603. + " resolving conf files\n");
  5604. + resolve_conffiles(conf, pkg);
  5605. +
  5606. + pkg->state_status = SS_UNPACKED;
  5607. +
  5608. + if (old_pkg) {
  5609. + old_pkg->state_status = SS_NOT_INSTALLED;
  5610. + }
  5611. +
  5612. + time(&pkg->installed_time);
  5613. +
  5614. + ipkg_message(conf, IPKG_INFO,
  5615. + " cleanup temp files\n");
  5616. + cleanup_temporary_files(conf, pkg);
  5617. +
  5618. + if (pkg->parent)
  5619. + pkg->parent->state_status = pkg->state_status;
  5620. + }
  5621. + return 0;
  5622. +}
  5623. +
  5624. +int ipkg_process_actions_unwind_prerm(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
  5625. +{
  5626. + int i;
  5627. + /* now one more pass checking on the ones that need to be installed */
  5628. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5629. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5630. + pkg_t *old_pkg = pkg->old_pkg;
  5631. +
  5632. + if (old_pkg) {
  5633. + if (old_pkg->state_flags & SF_POSTRM_UPGRADE)
  5634. + postrm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
  5635. + if (old_pkg->state_flags & SF_CHECK_DATA_FILE_CLASHES)
  5636. + check_data_file_clashes_unwind(conf, pkg, old_pkg);
  5637. + if (old_pkg->state_flags & SF_BACKUP_MODIFIED_CONFFILES)
  5638. + backup_modified_conffiles_unwind(pkg, old_pkg);
  5639. + */
  5640. + if (old_pkg->state_flags & SF_PREINST_CONFIGURE)
  5641. + preinst_configure_unwind(conf, pkg, old_pkg);
  5642. + if (old_pkg->state_flags & SF_DECONFIGURE_CONFLICTORS)
  5643. + prerm_deconfigure_conflictors_unwind(conf, pkg, replacees);
  5644. + if (old_pkg->state_flags & SF_PRERM_UPGRADE)
  5645. + prerm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
  5646. + */
  5647. +
  5648. + if (old_pkg->state_flags & SF_REMOVED_REPLACEES)
  5649. + remove_installed_replacees_unwind(conf, pkg, old_pkg);
  5650. +
  5651. + }
  5652. + }
  5653. + return 0;
  5654. +}
  5655. +
  5656. +/*
  5657. + * Perform all the actions.
  5658. + *
  5659. + * pkgs_to_remove are packages marked for removal.
  5660. + * pkgs_superseded are the old packages being replaced by upgrades.
  5661. + *
  5662. + * Assumes pkgs_to_install includes all dependences, recursively, sorted in installable order.
  5663. + */
  5664. +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)
  5665. +{
  5666. + int err;
  5667. + int i;
  5668. +
  5669. + err = ipkg_remove_packages(conf, pkgs_to_remove);
  5670. + if (err) return err;
  5671. +
  5672. + err = ipkg_process_actions_sanity_check(conf, pkgs_superseded, pkgs_to_install);
  5673. + if (err) return err;
  5674. +
  5675. + err = ipkg_process_actions_remove_replacees(conf, pkgs_to_install);
  5676. + if (err) goto UNWIND;
  5677. +
  5678. + /* @@@@ look at ipkg_install_pkg for handling replacements */
  5679. + err = ipkg_process_actions_unpack_packages(conf, pkgs_to_install);
  5680. + if (err) goto UNWIND;
  5681. +
  5682. + /*
  5683. + * Now that we have the packages unpacked, we can look for data
  5684. + * file clashes. First, we mark the files from the superseded
  5685. + * packages as obsolete. Then we scan the files in
  5686. + * pkgs_to_install, and only complain about clashes with
  5687. + * non-obsolete files.
  5688. + */
  5689. +
  5690. + err = ipkg_process_actions_check_data_file_clashes(conf, pkgs_superseded, pkgs_to_install);
  5691. + if (err) goto UNWIND;
  5692. +
  5693. + /* this was before checking data file clashes */
  5694. + err = ipkg_process_actions_prerm(conf, pkgs_superseded, pkgs_to_install);
  5695. + if (err) goto UNWIND;
  5696. +
  5697. + /* point of no return: no unwinding after this */
  5698. + err = ipkg_process_actions_install(conf, pkgs_to_install);
  5699. + if (err) return err;
  5700. +
  5701. + ipkg_message(conf, IPKG_INFO, "Done.\n");
  5702. + return 0;
  5703. +
  5704. + UNWIND:
  5705. + ipkg_process_actions_unwind(conf, pkgs_to_install);
  5706. +
  5707. + ipkg_message(conf, IPKG_INFO,
  5708. + " cleanup temp files\n");
  5709. + cleanup_temporary_files(conf, pkg);
  5710. +
  5711. + ipkg_message(conf, IPKG_INFO,
  5712. + "Failed.\n");
  5713. + return err;
  5714. +}
  5715. +
  5716. +#endif
  5717. diff -Nur busybox-1.16.1.orig/archival/libipkg/ipkg_install.h busybox-1.16.1/archival/libipkg/ipkg_install.h
  5718. --- busybox-1.16.1.orig/archival/libipkg/ipkg_install.h 1970-01-01 01:00:00.000000000 +0100
  5719. +++ busybox-1.16.1/archival/libipkg/ipkg_install.h 2010-06-29 17:31:22.768368136 +0200
  5720. @@ -0,0 +1,35 @@
  5721. +/* ipkg_install.h - the itsy package management system
  5722. +
  5723. + Carl D. Worth
  5724. +
  5725. + Copyright (C) 2001 University of Southern California
  5726. +
  5727. + This program is free software; you can redistribute it and/or
  5728. + modify it under the terms of the GNU General Public License as
  5729. + published by the Free Software Foundation; either version 2, or (at
  5730. + your option) any later version.
  5731. +
  5732. + This program is distributed in the hope that it will be useful, but
  5733. + WITHOUT ANY WARRANTY; without even the implied warranty of
  5734. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  5735. + General Public License for more details.
  5736. +*/
  5737. +
  5738. +#ifndef IPKG_INSTALL_H
  5739. +#define IPKG_INSTALL_H
  5740. +
  5741. +#include "pkg.h"
  5742. +#include "ipkg_conf.h"
  5743. +
  5744. +ipkg_error_t ipkg_install_by_name(ipkg_conf_t *conf, const char *pkg_name);
  5745. +ipkg_error_t ipkg_install_multi_by_name(ipkg_conf_t *conf, const char *pkg_name);
  5746. +int ipkg_install_from_file(ipkg_conf_t *conf, const char *filename);
  5747. +int ipkg_install_pkg(ipkg_conf_t *conf, pkg_t *pkg,int from_upgrading);
  5748. +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg);
  5749. +
  5750. +int ipkg_satisfy_all_dependences(ipkg_conf_t *conf);
  5751. +
  5752. +int pkg_mark_dependencies_for_installation(ipkg_conf_t *conf, pkg_t *pkg_name, pkg_vec_t *pkgs_needed);
  5753. +int name_mark_dependencies_for_installation(ipkg_conf_t *conf, const char *pkg_name, pkg_vec_t *pkgs_needed);
  5754. +
  5755. +#endif
  5756. diff -Nur busybox-1.16.1.orig/archival/libipkg/ipkg_message.c busybox-1.16.1/archival/libipkg/ipkg_message.c
  5757. --- busybox-1.16.1.orig/archival/libipkg/ipkg_message.c 1970-01-01 01:00:00.000000000 +0100
  5758. +++ busybox-1.16.1/archival/libipkg/ipkg_message.c 2010-06-29 17:31:22.798368009 +0200
  5759. @@ -0,0 +1,35 @@
  5760. +/* ipkg_message.c - the itsy package management system
  5761. +
  5762. + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
  5763. +
  5764. + This program is free software; you can redistribute it and/or
  5765. + modify it under the terms of the GNU General Public License as
  5766. + published by the Free Software Foundation; either version 2, or (at
  5767. + your option) any later version.
  5768. +
  5769. + This program is distributed in the hope that it will be useful, but
  5770. + WITHOUT ANY WARRANTY; without even the implied warranty of
  5771. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  5772. + General Public License for more details.
  5773. +*/
  5774. +
  5775. +
  5776. +#include "ipkg.h"
  5777. +#include "ipkg_conf.h"
  5778. +#include "ipkg_message.h"
  5779. +#include "libipkg.h"
  5780. +
  5781. +void
  5782. +ipkg_message (ipkg_conf_t * conf, message_level_t level, const char *fmt, ...)
  5783. +{
  5784. + va_list ap;
  5785. + char ts[256];
  5786. +
  5787. + if (ipkg_cb_message)
  5788. + {
  5789. + va_start (ap, fmt);
  5790. + vsnprintf (ts,256,fmt, ap);
  5791. + va_end (ap);
  5792. + ipkg_cb_message(conf,level,ts);
  5793. + }
  5794. +}
  5795. diff -Nur busybox-1.16.1.orig/archival/libipkg/ipkg_message.h busybox-1.16.1/archival/libipkg/ipkg_message.h
  5796. --- busybox-1.16.1.orig/archival/libipkg/ipkg_message.h 1970-01-01 01:00:00.000000000 +0100
  5797. +++ busybox-1.16.1/archival/libipkg/ipkg_message.h 2010-06-29 17:31:22.839937503 +0200
  5798. @@ -0,0 +1,32 @@
  5799. +/* ipkg_message.h - the itsy package management system
  5800. +
  5801. + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
  5802. +
  5803. + This program is free software; you can redistribute it and/or
  5804. + modify it under the terms of the GNU General Public License as
  5805. + published by the Free Software Foundation; either version 2, or (at
  5806. + your option) any later version.
  5807. +
  5808. + This program is distributed in the hope that it will be useful, but
  5809. + WITHOUT ANY WARRANTY; without even the implied warranty of
  5810. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  5811. + General Public License for more details.
  5812. +*/
  5813. +
  5814. +#ifndef _IPKG_MESSAGE_H_
  5815. +#define _IPKG_MESSAGE_H_
  5816. +
  5817. +#include "ipkg.h"
  5818. +#include "ipkg_conf.h"
  5819. +
  5820. +typedef enum {
  5821. + IPKG_ERROR, /* error conditions */
  5822. + IPKG_NOTICE, /* normal but significant condition */
  5823. + IPKG_INFO, /* informational message */
  5824. + IPKG_DEBUG, /* debug level message */
  5825. + IPKG_DEBUG2, /* more debug level message */
  5826. +} message_level_t;
  5827. +
  5828. +extern void ipkg_message(ipkg_conf_t *conf, message_level_t level, const char *fmt, ...);
  5829. +
  5830. +#endif /* _IPKG_MESSAGE_H_ */
  5831. diff -Nur busybox-1.16.1.orig/archival/libipkg/ipkg_remove.c busybox-1.16.1/archival/libipkg/ipkg_remove.c
  5832. --- busybox-1.16.1.orig/archival/libipkg/ipkg_remove.c 1970-01-01 01:00:00.000000000 +0100
  5833. +++ busybox-1.16.1/archival/libipkg/ipkg_remove.c 2010-06-29 17:31:22.876628032 +0200
  5834. @@ -0,0 +1,385 @@
  5835. +/* ipkg_remove.c - the itsy package management system
  5836. +
  5837. + Carl D. Worth
  5838. +
  5839. + Copyright (C) 2001 University of Southern California
  5840. +
  5841. + This program is free software; you can redistribute it and/or
  5842. + modify it under the terms of the GNU General Public License as
  5843. + published by the Free Software Foundation; either version 2, or (at
  5844. + your option) any later version.
  5845. +
  5846. + This program is distributed in the hope that it will be useful, but
  5847. + WITHOUT ANY WARRANTY; without even the implied warranty of
  5848. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  5849. + General Public License for more details.
  5850. +*/
  5851. +
  5852. +#include "ipkg.h"
  5853. +#include "ipkg_message.h"
  5854. +
  5855. +#include <glob.h>
  5856. +
  5857. +#include "ipkg_remove.h"
  5858. +
  5859. +#include "file_util.h"
  5860. +#include "sprintf_alloc.h"
  5861. +#include "str_util.h"
  5862. +
  5863. +#include "ipkg_cmd.h"
  5864. +
  5865. +int ipkg_remove_dependent_pkgs (ipkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **dependents);
  5866. +
  5867. +/*
  5868. + * Returns number of the number of packages depending on the packages provided by this package.
  5869. + * Every package implicitly provides itself.
  5870. + */
  5871. +int pkg_has_installed_dependents(pkg_t *pkg, abstract_pkg_t *** pdependents)
  5872. +{
  5873. + int nprovides = pkg->provides_count;
  5874. + abstract_pkg_t **provides = pkg->provides;
  5875. + int n_installed_dependents = 0;
  5876. + int i;
  5877. + for (i = 0; i <= nprovides; i++) {
  5878. + abstract_pkg_t *providee = provides[i];
  5879. + abstract_pkg_t **dependers = providee->depended_upon_by;
  5880. + abstract_pkg_t *dep_ab_pkg;
  5881. + if (dependers == NULL)
  5882. + continue;
  5883. + while ((dep_ab_pkg = *dependers++) != NULL) {
  5884. + if (dep_ab_pkg->state_status == SS_INSTALLED){
  5885. + n_installed_dependents++;
  5886. + }
  5887. + }
  5888. +
  5889. + }
  5890. + /* if caller requested the set of installed dependents */
  5891. + if (pdependents) {
  5892. + int p = 0;
  5893. + abstract_pkg_t **dependents = (abstract_pkg_t **)malloc((n_installed_dependents+1)*sizeof(abstract_pkg_t *));
  5894. +
  5895. + if ( dependents == NULL ){
  5896. + fprintf(stderr,"%s Unable to allocate memory. REPORT THIS BUG IN BUGZILLA PLEASE\n", __FUNCTION__);
  5897. + return -1;
  5898. + }
  5899. +
  5900. + *pdependents = dependents;
  5901. + for (i = 0; i <= nprovides; i++) {
  5902. + abstract_pkg_t *providee = provides[i];
  5903. + abstract_pkg_t **dependers = providee->depended_upon_by;
  5904. + abstract_pkg_t *dep_ab_pkg;
  5905. + if (dependers == NULL)
  5906. + continue;
  5907. + while ((dep_ab_pkg = *dependers++) != NULL) {
  5908. + if (dep_ab_pkg->state_status == SS_INSTALLED && !(dep_ab_pkg->state_flag & SF_MARKED)) {
  5909. + dependents[p++] = dep_ab_pkg;
  5910. + dep_ab_pkg->state_flag |= SF_MARKED;
  5911. + }
  5912. + }
  5913. + }
  5914. + dependents[p] = NULL;
  5915. + /* now clear the marks */
  5916. + for (i = 0; i < p; i++) {
  5917. + abstract_pkg_t *dep_ab_pkg = dependents[i];
  5918. + dep_ab_pkg->state_flag &= ~SF_MARKED;
  5919. + }
  5920. + }
  5921. + return n_installed_dependents;
  5922. +}
  5923. +
  5924. +int ipkg_remove_dependent_pkgs (ipkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **dependents)
  5925. +{
  5926. + int i;
  5927. + int a;
  5928. + int count;
  5929. + pkg_vec_t *dependent_pkgs = pkg_vec_alloc();
  5930. + abstract_pkg_t * ab_pkg;
  5931. +
  5932. + if((ab_pkg = pkg->parent) == NULL){
  5933. + fprintf(stderr, "%s: unable to get dependent pkgs. pkg %s isn't in hash table\n",
  5934. + __FUNCTION__, pkg->name);
  5935. + return 0;
  5936. + }
  5937. +
  5938. + if (dependents == NULL)
  5939. + return 0;
  5940. +
  5941. + // here i am using the dependencies_checked
  5942. + if (ab_pkg->dependencies_checked == 2) // variable to make out whether this package
  5943. + return 0; // has already been encountered in the process
  5944. + // of marking packages for removal - Karthik
  5945. + ab_pkg->dependencies_checked = 2;
  5946. +
  5947. + i = 0;
  5948. + count = 1;
  5949. + while (dependents [i] != NULL) {
  5950. + abstract_pkg_t *dep_ab_pkg = dependents[i];
  5951. +
  5952. + if (dep_ab_pkg->dependencies_checked == 2){
  5953. + i++;
  5954. + continue;
  5955. + }
  5956. + if (dep_ab_pkg->state_status == SS_INSTALLED) {
  5957. + for (a = 0; a < dep_ab_pkg->pkgs->len; a++) {
  5958. + pkg_t *dep_pkg = dep_ab_pkg->pkgs->pkgs[a];
  5959. + if (dep_pkg->state_status == SS_INSTALLED) {
  5960. + pkg_vec_insert(dependent_pkgs, dep_pkg);
  5961. + count++;
  5962. + }
  5963. + }
  5964. + }
  5965. + i++;
  5966. + /* 1 - to keep track of visited ab_pkgs when checking for possiblility of a broken removal of pkgs.
  5967. + * 2 - to keep track of pkgs whose deps have been checked alrdy - Karthik */
  5968. + }
  5969. +
  5970. + if (count == 1)
  5971. + return 0;
  5972. +
  5973. +
  5974. + for (i = 0; i < dependent_pkgs->len; i++) {
  5975. + int err = ipkg_remove_pkg(conf, dependent_pkgs->pkgs[i],0);
  5976. + if (err)
  5977. + return err;
  5978. + }
  5979. + return 0;
  5980. +}
  5981. +
  5982. +static int user_prefers_removing_dependents(ipkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **dependents)
  5983. +{
  5984. + abstract_pkg_t *dep_ab_pkg;
  5985. + ipkg_message(conf, IPKG_ERROR, "Package %s is depended upon by packages:\n", pkg->name);
  5986. + while ((dep_ab_pkg = *dependents++) != NULL) {
  5987. + if (dep_ab_pkg->state_status == SS_INSTALLED)
  5988. + ipkg_message(conf, IPKG_ERROR, "\t%s\n", dep_ab_pkg->name);
  5989. + }
  5990. + ipkg_message(conf, IPKG_ERROR, "These might cease to work if package %s is removed.\n\n", pkg->name);
  5991. + ipkg_message(conf, IPKG_ERROR, "");
  5992. + ipkg_message(conf, IPKG_ERROR, "You can force removal of this package with -force-depends.\n");
  5993. + ipkg_message(conf, IPKG_ERROR, "You can force removal of this package and its dependents\n");
  5994. + ipkg_message(conf, IPKG_ERROR, "with -force-removal-of-dependent-packages or -recursive\n");
  5995. + ipkg_message(conf, IPKG_ERROR, "or by setting option force_removal_of_dependent_packages\n");
  5996. + ipkg_message(conf, IPKG_ERROR, "in ipkg.conf.\n");
  5997. + return 0;
  5998. +}
  5999. +
  6000. +int ipkg_remove_pkg(ipkg_conf_t *conf, pkg_t *pkg,int message)
  6001. +{
  6002. +/* Actually, when "message == 1" I have been called from an upgrade, and not from a normal remove
  6003. + thus I wan't check for essential, as I'm upgrading.
  6004. + I hope it won't break anything :)
  6005. +*/
  6006. + int err;
  6007. + abstract_pkg_t *parent_pkg = NULL;
  6008. +
  6009. + if (pkg->essential && !message) {
  6010. + if (conf->force_removal_of_essential_packages) {
  6011. + fprintf(stderr, "WARNING: Removing essential package %s under your coercion.\n"
  6012. + "\tIf your system breaks, you get to keep both pieces\n",
  6013. + pkg->name);
  6014. + } else {
  6015. + fprintf(stderr, "ERROR: Refusing to remove essential package %s.\n"
  6016. + "\tRemoving an essential package may lead to an unusable system, but if\n"
  6017. + "\tyou enjoy that kind of pain, you can force ipkg to proceed against\n"
  6018. + "\tits will with the option: -force-removal-of-essential-packages\n",
  6019. + pkg->name);
  6020. + return IPKG_PKG_IS_ESSENTIAL;
  6021. + }
  6022. + }
  6023. +
  6024. + if ((parent_pkg = pkg->parent) == NULL)
  6025. + return 0;
  6026. +
  6027. + /* only attempt to remove dependent installed packages if
  6028. + * force_depends is not specified or the package is being
  6029. + * replaced.
  6030. + */
  6031. + if (!conf->force_depends
  6032. + && !(pkg->state_flag & SF_REPLACE)) {
  6033. + abstract_pkg_t **dependents;
  6034. + int has_installed_dependents =
  6035. + pkg_has_installed_dependents(pkg, &dependents);
  6036. +
  6037. + if (has_installed_dependents) {
  6038. + /*
  6039. + * if this package is depended up by others, then either we should
  6040. + * not remove it or we should remove it and all of its dependents
  6041. + */
  6042. +
  6043. + if (!conf->force_removal_of_dependent_packages
  6044. + && !user_prefers_removing_dependents(conf, pkg, dependents)) {
  6045. + return IPKG_PKG_HAS_DEPENDENTS;
  6046. + }
  6047. +
  6048. + /* remove packages depending on this package - Karthik */
  6049. + err = ipkg_remove_dependent_pkgs (conf, pkg, dependents);
  6050. + free(dependents);
  6051. + if (err) return err;
  6052. + }
  6053. + }
  6054. +
  6055. + if ( message==0 ){
  6056. + printf("Removing package %s from %s...\n", pkg->name, pkg->dest->name);
  6057. + fflush(stdout);
  6058. + }
  6059. + pkg->state_flag |= SF_FILELIST_CHANGED;
  6060. +
  6061. + pkg->state_want = SW_DEINSTALL;
  6062. + ipkg_state_changed++;
  6063. +
  6064. + pkg_run_script(conf, pkg, "prerm", "remove");
  6065. +
  6066. + /* DPKG_INCOMPATIBILITY: dpkg is slightly different here. It
  6067. + maintains an empty filelist rather than deleting it. That seems
  6068. + like a big pain, and I don't see that that should make a big
  6069. + difference, but for anyone who wants tighter compatibility,
  6070. + feel free to fix this. */
  6071. + remove_data_files_and_list(conf, pkg);
  6072. +
  6073. + pkg_run_script(conf, pkg, "postrm", "remove");
  6074. +
  6075. + remove_maintainer_scripts_except_postrm(conf, pkg);
  6076. +
  6077. + /* Aman Gupta - Since ipkg is made for handheld devices with limited
  6078. + * space, it doesn't make sense to leave extra configurations, files,
  6079. + * and maintainer scripts left around. So, we make remove like purge,
  6080. + * and take out all the crap :) */
  6081. +
  6082. + remove_postrm(conf, pkg);
  6083. + pkg->state_status = SS_NOT_INSTALLED;
  6084. +
  6085. + if (parent_pkg)
  6086. + parent_pkg->state_status = SS_NOT_INSTALLED;
  6087. +
  6088. + return 0;
  6089. +}
  6090. +
  6091. +int ipkg_purge_pkg(ipkg_conf_t *conf, pkg_t *pkg)
  6092. +{
  6093. + ipkg_remove_pkg(conf, pkg,0);
  6094. + return 0;
  6095. +}
  6096. +
  6097. +int remove_data_files_and_list(ipkg_conf_t *conf, pkg_t *pkg)
  6098. +{
  6099. + str_list_t installed_dirs;
  6100. + str_list_t *installed_files;
  6101. + str_list_elt_t *iter;
  6102. + char *file_name;
  6103. + conffile_t *conffile;
  6104. + int removed_a_dir;
  6105. + pkg_t *owner;
  6106. +
  6107. + str_list_init(&installed_dirs);
  6108. + installed_files = pkg_get_installed_files(pkg);
  6109. +
  6110. + for (iter = installed_files->head; iter; iter = iter->next) {
  6111. + file_name = iter->data;
  6112. +
  6113. + if (file_is_dir(file_name)) {
  6114. + str_list_append(&installed_dirs, strdup(file_name));
  6115. + continue;
  6116. + }
  6117. +
  6118. + conffile = pkg_get_conffile(pkg, file_name);
  6119. + if (conffile) {
  6120. + /* XXX: QUESTION: Is this right? I figure we only need to
  6121. + save the conffile if it has been modified. Is that what
  6122. + dpkg does? Or does dpkg preserve all conffiles? If so,
  6123. + this seems like a better thing to do to conserve
  6124. + space. */
  6125. + if (conffile_has_been_modified(conf, conffile)) {
  6126. + printf(" not deleting modified conffile %s\n", file_name);
  6127. + fflush(stdout);
  6128. + continue;
  6129. + }
  6130. + }
  6131. +
  6132. + ipkg_message(conf, IPKG_INFO, " deleting %s (noaction=%d)\n", file_name, conf->noaction);
  6133. + if (!conf->noaction)
  6134. + unlink(file_name);
  6135. + }
  6136. +
  6137. + if (!conf->noaction) {
  6138. + do {
  6139. + removed_a_dir = 0;
  6140. + for (iter = installed_dirs.head; iter; iter = iter->next) {
  6141. + file_name = iter->data;
  6142. +
  6143. + if (rmdir(file_name) == 0) {
  6144. + ipkg_message(conf, IPKG_INFO, " deleting %s\n", file_name);
  6145. + removed_a_dir = 1;
  6146. + str_list_remove(&installed_dirs, &iter);
  6147. + }
  6148. + }
  6149. + } while (removed_a_dir);
  6150. + }
  6151. +
  6152. + pkg_free_installed_files(pkg);
  6153. + /* We have to remove the file list now, so that
  6154. + find_pkg_owning_file does not always just report this package */
  6155. + pkg_remove_installed_files_list(conf, pkg);
  6156. +
  6157. + /* Don't print warning for dirs that are provided by other packages */
  6158. + for (iter = installed_dirs.head; iter; iter = iter->next) {
  6159. + file_name = iter->data;
  6160. +
  6161. + owner = file_hash_get_file_owner(conf, file_name);
  6162. + if (owner) {
  6163. + free(iter->data);
  6164. + iter->data = NULL;
  6165. + str_list_remove(&installed_dirs, &iter);
  6166. + }
  6167. + }
  6168. +
  6169. + /* cleanup */
  6170. + for (iter = installed_dirs.head; iter; iter = iter->next) {
  6171. + free(iter->data);
  6172. + iter->data = NULL;
  6173. + }
  6174. + str_list_deinit(&installed_dirs);
  6175. +
  6176. + return 0;
  6177. +}
  6178. +
  6179. +int remove_maintainer_scripts_except_postrm(ipkg_conf_t *conf, pkg_t *pkg)
  6180. +{
  6181. + int i, err;
  6182. + char *globpattern;
  6183. + glob_t globbuf;
  6184. +
  6185. + if (conf->noaction) return 0;
  6186. +
  6187. + sprintf_alloc(&globpattern, "%s/%s.*",
  6188. + pkg->dest->info_dir, pkg->name);
  6189. + err = glob(globpattern, 0, NULL, &globbuf);
  6190. + free(globpattern);
  6191. + if (err) {
  6192. + return 0;
  6193. + }
  6194. +
  6195. + for (i = 0; i < globbuf.gl_pathc; i++) {
  6196. + if (str_ends_with(globbuf.gl_pathv[i], ".postrm")) {
  6197. + continue;
  6198. + }
  6199. + ipkg_message(conf, IPKG_INFO, " deleting %s\n", globbuf.gl_pathv[i]);
  6200. + unlink(globbuf.gl_pathv[i]);
  6201. + }
  6202. + globfree(&globbuf);
  6203. +
  6204. + return 0;
  6205. +}
  6206. +
  6207. +int remove_postrm(ipkg_conf_t *conf, pkg_t *pkg)
  6208. +{
  6209. + char *postrm_file_name;
  6210. +
  6211. + if (conf->noaction) return 0;
  6212. +
  6213. + sprintf_alloc(&postrm_file_name, "%s/%s.postrm",
  6214. + pkg->dest->info_dir, pkg->name);
  6215. + unlink(postrm_file_name);
  6216. + free(postrm_file_name);
  6217. +
  6218. + return 0;
  6219. +}
  6220. diff -Nur busybox-1.16.1.orig/archival/libipkg/ipkg_remove.h busybox-1.16.1/archival/libipkg/ipkg_remove.h
  6221. --- busybox-1.16.1.orig/archival/libipkg/ipkg_remove.h 1970-01-01 01:00:00.000000000 +0100
  6222. +++ busybox-1.16.1/archival/libipkg/ipkg_remove.h 2010-06-29 17:31:22.918368225 +0200
  6223. @@ -0,0 +1,33 @@
  6224. +/* ipkg_remove.h - the itsy package management system
  6225. +
  6226. + Carl D. Worth
  6227. +
  6228. + Copyright (C) 2001 University of Southern California
  6229. +
  6230. + This program is free software; you can redistribute it and/or
  6231. + modify it under the terms of the GNU General Public License as
  6232. + published by the Free Software Foundation; either version 2, or (at
  6233. + your option) any later version.
  6234. +
  6235. + This program is distributed in the hope that it will be useful, but
  6236. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6237. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6238. + General Public License for more details.
  6239. +*/
  6240. +
  6241. +#ifndef IPKG_REMOVE_H
  6242. +#define IPKG_REMOVE_H
  6243. +
  6244. +#include "pkg.h"
  6245. +#include "ipkg_conf.h"
  6246. +
  6247. +int ipkg_remove_pkg(ipkg_conf_t *conf, pkg_t *pkg,int message);
  6248. +int ipkg_purge_pkg(ipkg_conf_t *conf, pkg_t *pkg);
  6249. +int possible_broken_removal_of_packages (ipkg_conf_t *conf, pkg_t *pkg);
  6250. +int pkg_has_installed_dependents(pkg_t *pkg, abstract_pkg_t *** pdependents);
  6251. +int remove_data_files_and_list(ipkg_conf_t *conf, pkg_t *pkg);
  6252. +int remove_maintainer_scripts_except_postrm (ipkg_conf_t *conf, pkg_t *pkg);
  6253. +int remove_postrm (ipkg_conf_t *conf, pkg_t *pkg);
  6254. +
  6255. +
  6256. +#endif
  6257. diff -Nur busybox-1.16.1.orig/archival/libipkg/ipkg_upgrade.c busybox-1.16.1/archival/libipkg/ipkg_upgrade.c
  6258. --- busybox-1.16.1.orig/archival/libipkg/ipkg_upgrade.c 1970-01-01 01:00:00.000000000 +0100
  6259. +++ busybox-1.16.1/archival/libipkg/ipkg_upgrade.c 2010-06-29 17:31:22.976264794 +0200
  6260. @@ -0,0 +1,79 @@
  6261. +/* ipkg_upgrade.c - the itsy package management system
  6262. +
  6263. + Carl D. Worth
  6264. + Copyright (C) 2001 University of Southern California
  6265. +
  6266. + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
  6267. +
  6268. + This program is free software; you can redistribute it and/or
  6269. + modify it under the terms of the GNU General Public License as
  6270. + published by the Free Software Foundation; either version 2, or (at
  6271. + your option) any later version.
  6272. +
  6273. + This program is distributed in the hope that it will be useful, but
  6274. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6275. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6276. + General Public License for more details.
  6277. +*/
  6278. +
  6279. +#include "ipkg.h"
  6280. +#include "ipkg_install.h"
  6281. +#include "ipkg_message.h"
  6282. +
  6283. +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old);
  6284. +
  6285. +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old)
  6286. +{
  6287. + pkg_t *new;
  6288. + int cmp;
  6289. + char *old_version, *new_version;
  6290. +
  6291. + if (old->state_flag & SF_HOLD) {
  6292. + ipkg_message(conf, IPKG_NOTICE,
  6293. + "Not upgrading package %s which is marked "
  6294. + "hold (flags=%#x)\n", old->name, old->state_flag);
  6295. + return 0;
  6296. + }
  6297. +
  6298. + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, old->name);
  6299. + if (new == NULL) {
  6300. + old_version = pkg_version_str_alloc(old);
  6301. + ipkg_message(conf, IPKG_NOTICE,
  6302. + "Assuming locally installed package %s (%s) "
  6303. + "is up to date.\n", old->name, old_version);
  6304. + free(old_version);
  6305. + return 0;
  6306. + }
  6307. +
  6308. + old_version = pkg_version_str_alloc(old);
  6309. + new_version = pkg_version_str_alloc(new);
  6310. +
  6311. + cmp = pkg_compare_versions(old, new);
  6312. + ipkg_message(conf, IPKG_DEBUG,
  6313. + "comparing visible versions of pkg %s:"
  6314. + "\n\t%s is installed "
  6315. + "\n\t%s is available "
  6316. + "\n\t%d was comparison result\n",
  6317. + old->name, old_version, new_version, cmp);
  6318. + if (cmp == 0) {
  6319. + ipkg_message(conf, IPKG_INFO,
  6320. + "Package %s (%s) installed in %s is up to date.\n",
  6321. + old->name, old_version, old->dest->name);
  6322. + free(old_version);
  6323. + free(new_version);
  6324. + return 0;
  6325. + } else if (cmp > 0) {
  6326. + ipkg_message(conf, IPKG_NOTICE,
  6327. + "Not downgrading package %s on %s from %s to %s.\n",
  6328. + old->name, old->dest->name, old_version, new_version);
  6329. + free(old_version);
  6330. + free(new_version);
  6331. + return 0;
  6332. + } else if (cmp < 0) {
  6333. + new->dest = old->dest;
  6334. + old->state_want = SW_DEINSTALL;
  6335. + }
  6336. +
  6337. + new->state_flag |= SF_USER;
  6338. + return ipkg_install_pkg(conf, new,1);
  6339. +}
  6340. diff -Nur busybox-1.16.1.orig/archival/libipkg/ipkg_upgrade.h busybox-1.16.1/archival/libipkg/ipkg_upgrade.h
  6341. --- busybox-1.16.1.orig/archival/libipkg/ipkg_upgrade.h 1970-01-01 01:00:00.000000000 +0100
  6342. +++ busybox-1.16.1/archival/libipkg/ipkg_upgrade.h 2010-06-29 17:31:23.015873328 +0200
  6343. @@ -0,0 +1,18 @@
  6344. +/* ipkg_upgrade.c - the itsy package management system
  6345. +
  6346. + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
  6347. +
  6348. + This program is free software; you can redistribute it and/or
  6349. + modify it under the terms of the GNU General Public License as
  6350. + published by the Free Software Foundation; either version 2, or (at
  6351. + your option) any later version.
  6352. +
  6353. + This program is distributed in the hope that it will be useful, but
  6354. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6355. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6356. + General Public License for more details.
  6357. +*/
  6358. +
  6359. +#include "ipkg.h"
  6360. +
  6361. +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old);
  6362. diff -Nur busybox-1.16.1.orig/archival/libipkg/ipkg_utils.c busybox-1.16.1/archival/libipkg/ipkg_utils.c
  6363. --- busybox-1.16.1.orig/archival/libipkg/ipkg_utils.c 1970-01-01 01:00:00.000000000 +0100
  6364. +++ busybox-1.16.1/archival/libipkg/ipkg_utils.c 2010-06-29 17:31:23.067592883 +0200
  6365. @@ -0,0 +1,185 @@
  6366. +/* ipkg_utils.c - the itsy package management system
  6367. +
  6368. + Steven M. Ayer
  6369. +
  6370. + Copyright (C) 2002 Compaq Computer Corporation
  6371. +
  6372. + This program is free software; you can redistribute it and/or
  6373. + modify it under the terms of the GNU General Public License as
  6374. + published by the Free Software Foundation; either version 2, or (at
  6375. + your option) any later version.
  6376. +
  6377. + This program is distributed in the hope that it will be useful, but
  6378. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6379. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6380. + General Public License for more details.
  6381. +*/
  6382. +
  6383. +#include "ipkg.h"
  6384. +#include <errno.h>
  6385. +#include <ctype.h>
  6386. +#include <sys/vfs.h>
  6387. +
  6388. +#include "ipkg_utils.h"
  6389. +#include "pkg.h"
  6390. +#include "pkg_hash.h"
  6391. +
  6392. +void push_error_list(struct errlist ** errors, char * msg);
  6393. +void reverse_error_list(struct errlist **errors);
  6394. +void free_error_list(struct errlist **errors);
  6395. +
  6396. +struct errlist* error_list;
  6397. +
  6398. +int get_available_blocks(char * filesystem)
  6399. +{
  6400. + struct statfs sfs;
  6401. +
  6402. + if(statfs(filesystem, &sfs)){
  6403. + fprintf(stderr, "bad statfs\n");
  6404. + return 0;
  6405. + }
  6406. + /* fprintf(stderr, "reported fs type %x\n", sfs.f_type); */
  6407. + return ((sfs.f_bavail * sfs.f_bsize) / 1024);
  6408. +}
  6409. +
  6410. +char **read_raw_pkgs_from_file(const char *file_name)
  6411. +{
  6412. + FILE *fp;
  6413. + char **ret;
  6414. +
  6415. + if(!(fp = fopen(file_name, "r"))){
  6416. + fprintf(stderr, "can't get %s open for read\n", file_name);
  6417. + return NULL;
  6418. + }
  6419. +
  6420. + ret = read_raw_pkgs_from_stream(fp);
  6421. +
  6422. + fclose(fp);
  6423. +
  6424. + return ret;
  6425. +}
  6426. +
  6427. +char **read_raw_pkgs_from_stream(FILE *fp)
  6428. +{
  6429. + char **raw = NULL, *buf, *scout;
  6430. + int count = 0;
  6431. + size_t size = 512;
  6432. +
  6433. + buf = malloc (size);
  6434. +
  6435. + while (fgets(buf, size, fp)) {
  6436. + while (strlen (buf) == (size - 1)
  6437. + && buf[size-2] != '\n') {
  6438. + size_t o = size - 1;
  6439. + size *= 2;
  6440. + buf = realloc (buf, size);
  6441. + if (fgets (buf + o, size - o, fp) == NULL)
  6442. + break;
  6443. + }
  6444. +
  6445. + if(!(count % 50))
  6446. + raw = realloc(raw, (count + 50) * sizeof(char *));
  6447. +
  6448. + if((scout = strchr(buf, '\n')))
  6449. + *scout = '\0';
  6450. +
  6451. + raw[count++] = strdup(buf);
  6452. + }
  6453. +
  6454. + raw = realloc(raw, (count + 1) * sizeof(char *));
  6455. + raw[count] = NULL;
  6456. +
  6457. + free (buf);
  6458. +
  6459. + return raw;
  6460. +}
  6461. +
  6462. +/* something to remove whitespace, a hash pooper */
  6463. +char *trim_alloc(char *line)
  6464. +{
  6465. + char *new;
  6466. + char *dest, *src, *end;
  6467. +
  6468. + new = malloc(strlen(line) + 1);
  6469. + if ( new == NULL ){
  6470. + fprintf(stderr,"%s: Unable to allocate memory\n",__FUNCTION__);
  6471. + return NULL;
  6472. + }
  6473. + dest = new, src = line, end = line + (strlen(line) - 1);
  6474. +
  6475. + /* remove it from the front */
  6476. + while(src &&
  6477. + isspace(*src) &&
  6478. + *src)
  6479. + src++;
  6480. + /* and now from the back */
  6481. + while((end > src) &&
  6482. + isspace(*end))
  6483. + end--;
  6484. + end++;
  6485. + *end = '\0';
  6486. + strcpy(new, src);
  6487. + /* this does from the first space
  6488. + * blasting away any versions stuff in depends
  6489. + while(src &&
  6490. + !isspace(*src) &&
  6491. + *src)
  6492. + *dest++ = *src++;
  6493. + *dest = '\0';
  6494. + */
  6495. +
  6496. + return new;
  6497. +}
  6498. +
  6499. +int line_is_blank(const char *line)
  6500. +{
  6501. + const char *s;
  6502. +
  6503. + for (s = line; *s; s++) {
  6504. + if (!isspace(*s))
  6505. + return 0;
  6506. + }
  6507. + return 1;
  6508. +}
  6509. +
  6510. +void push_error_list(struct errlist ** errors, char * msg){
  6511. + struct errlist *err_lst_tmp;
  6512. +
  6513. +
  6514. + err_lst_tmp = malloc ( sizeof (err_lst_tmp) );
  6515. + err_lst_tmp->errmsg=strdup(msg) ;
  6516. + err_lst_tmp->next = *errors;
  6517. + *errors = err_lst_tmp;
  6518. +}
  6519. +
  6520. +
  6521. +void reverse_error_list(struct errlist **errors){
  6522. + struct errlist *result=NULL;
  6523. + struct errlist *current= *errors;
  6524. + struct errlist *next;
  6525. +
  6526. + while ( current != NULL ) {
  6527. + next = current->next;
  6528. + current->next=result;
  6529. + result=current;
  6530. + current=next;
  6531. + }
  6532. + *errors=result;
  6533. +
  6534. +}
  6535. +
  6536. +
  6537. +void free_error_list(struct errlist **errors){
  6538. + struct errlist *current = *errors;
  6539. +
  6540. + while (current != NULL) {
  6541. + free(current->errmsg);
  6542. + current = (*errors)->next;
  6543. + free(*errors);
  6544. + *errors = current;
  6545. + }
  6546. +
  6547. +
  6548. +}
  6549. +
  6550. +
  6551. diff -Nur busybox-1.16.1.orig/archival/libipkg/ipkg_utils.h busybox-1.16.1/archival/libipkg/ipkg_utils.h
  6552. --- busybox-1.16.1.orig/archival/libipkg/ipkg_utils.h 1970-01-01 01:00:00.000000000 +0100
  6553. +++ busybox-1.16.1/archival/libipkg/ipkg_utils.h 2010-06-29 17:31:23.105873432 +0200
  6554. @@ -0,0 +1,29 @@
  6555. +/* ipkg_utils.h - the itsy package management system
  6556. +
  6557. + Steven M. Ayer
  6558. +
  6559. + Copyright (C) 2002 Compaq Computer Corporation
  6560. +
  6561. + This program is free software; you can redistribute it and/or
  6562. + modify it under the terms of the GNU General Public License as
  6563. + published by the Free Software Foundation; either version 2, or (at
  6564. + your option) any later version.
  6565. +
  6566. + This program is distributed in the hope that it will be useful, but
  6567. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6568. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6569. + General Public License for more details.
  6570. +*/
  6571. +
  6572. +#ifndef IPKG_UTILS_H
  6573. +#define IPKG_UTILS_H
  6574. +
  6575. +#include "pkg.h"
  6576. +
  6577. +int get_available_blocks(char * filesystem);
  6578. +char **read_raw_pkgs_from_file(const char *file_name);
  6579. +char **read_raw_pkgs_from_stream(FILE *fp);
  6580. +char *trim_alloc(char * line);
  6581. +int line_is_blank(const char *line);
  6582. +
  6583. +#endif
  6584. diff -Nur busybox-1.16.1.orig/archival/libipkg/Kbuild busybox-1.16.1/archival/libipkg/Kbuild
  6585. --- busybox-1.16.1.orig/archival/libipkg/Kbuild 1970-01-01 01:00:00.000000000 +0100
  6586. +++ busybox-1.16.1/archival/libipkg/Kbuild 2010-06-29 17:31:23.145868229 +0200
  6587. @@ -0,0 +1,60 @@
  6588. +# Makefile for busybox
  6589. +#
  6590. +# Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
  6591. +# Copyright (C) 2006 OpenWrt.org
  6592. +#
  6593. +# Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
  6594. +
  6595. +LIBIPKG_CORE_OBJS:= \
  6596. + args.o \
  6597. + libipkg.o \
  6598. + user.o \
  6599. +
  6600. +LIBIPKG_CMD_OBJS:= \
  6601. + ipkg_cmd.o \
  6602. + ipkg_configure.o \
  6603. + ipkg_download.o \
  6604. + ipkg_install.o \
  6605. + ipkg_remove.o \
  6606. + ipkg_upgrade.o \
  6607. +
  6608. +LIBIPKG_DB_OBJS:= \
  6609. + hash_table.o \
  6610. + ipkg_conf.o \
  6611. + ipkg_utils.o \
  6612. + pkg.o \
  6613. + pkg_depends.o \
  6614. + pkg_extract.o \
  6615. + pkg_hash.o \
  6616. + pkg_parse.o \
  6617. + pkg_vec.o \
  6618. +
  6619. +LIBIPKG_LIST_OBJS:= \
  6620. + conffile.o \
  6621. + conffile_list.o \
  6622. + nv_pair.o \
  6623. + nv_pair_list.o \
  6624. + pkg_dest.o \
  6625. + pkg_dest_list.o \
  6626. + pkg_src.o \
  6627. + pkg_src_list.o \
  6628. + str_list.o \
  6629. + void_list.o \
  6630. +
  6631. +LIBIPKG_UTIL_OBJS:= \
  6632. + file_util.o \
  6633. + ipkg_message.o \
  6634. + str_util.o \
  6635. + xsystem.o \
  6636. +
  6637. +lib-y :=
  6638. +lib-$(CONFIG_IPKG) += $(LIBIPKG_CORE_OBJS)
  6639. +lib-$(CONFIG_IPKG) += $(LIBIPKG_CMD_OBJS)
  6640. +lib-$(CONFIG_IPKG) += $(LIBIPKG_DB_OBJS)
  6641. +lib-$(CONFIG_IPKG) += $(LIBIPKG_LIST_OBJS)
  6642. +lib-$(CONFIG_IPKG) += $(LIBIPKG_UTIL_OBJS)
  6643. +
  6644. +ifeq ($(strip $(IPKG_ARCH)),)
  6645. +IPKG_ARCH:=$(TARGET_ARCH)
  6646. +endif
  6647. +CFLAGS += -DIPKGLIBDIR="\"/usr/lib\"" -DHOST_CPU_STR="\"$(IPKG_ARCH)\""
  6648. diff -Nur busybox-1.16.1.orig/archival/libipkg/libipkg.c busybox-1.16.1/archival/libipkg/libipkg.c
  6649. --- busybox-1.16.1.orig/archival/libipkg/libipkg.c 1970-01-01 01:00:00.000000000 +0100
  6650. +++ busybox-1.16.1/archival/libipkg/libipkg.c 2010-06-29 17:35:49.219617937 +0200
  6651. @@ -0,0 +1,532 @@
  6652. +/* ipkglib.c - the itsy package management system
  6653. +
  6654. + Florina Boor
  6655. +
  6656. + Copyright (C) 2003 kernel concepts
  6657. +
  6658. + This program is free software; you can redistribute it and/or
  6659. + modify it under the terms of the GNU General Public License as
  6660. + published by the Free Software Foundation; either version 2, or (at
  6661. + your option) any later version.
  6662. +
  6663. + This program is distributed in the hope that it will be useful, but
  6664. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6665. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6666. + General Public License for more details.
  6667. +*/
  6668. +
  6669. +#include "ipkg.h"
  6670. +#include "ipkg_includes.h"
  6671. +#include "libipkg.h"
  6672. +
  6673. +#include "args.h"
  6674. +#include "ipkg_conf.h"
  6675. +#include "ipkg_cmd.h"
  6676. +#include "file_util.h"
  6677. +
  6678. +int ipkg_file_what(args_t *args, const char *file, const char* command);
  6679. +int default_ipkg_message_callback(ipkg_conf_t *conf, message_level_t level,
  6680. + char *msg);
  6681. +int default_ipkg_list_callback(char *name, char *desc, char *version);
  6682. +int default_ipkg_files_callback(char *desc);
  6683. +int default_ipkg_status_callback(char *desc);
  6684. +char* default_ipkg_response_callback(char *question);
  6685. +
  6686. +
  6687. +ipkg_message_callback ipkg_cb_message = NULL;
  6688. +ipkg_response_callback ipkg_cb_response = NULL;
  6689. +ipkg_status_callback ipkg_cb_status = NULL;
  6690. +ipkg_list_callback ipkg_cb_list = NULL;
  6691. +
  6692. +
  6693. +int
  6694. +ipkg_init (ipkg_message_callback mcall,
  6695. + ipkg_response_callback rcall,
  6696. + args_t * args)
  6697. +{
  6698. + ipkg_cb_message = mcall;
  6699. + ipkg_cb_response = rcall;
  6700. +
  6701. + args_init (args);
  6702. +
  6703. + return 0;
  6704. +}
  6705. +
  6706. +
  6707. +int
  6708. +ipkg_deinit (args_t * args)
  6709. +{
  6710. + args_deinit (args);
  6711. + ipkg_cb_message = NULL;
  6712. + ipkg_cb_response = NULL;
  6713. +
  6714. + /* place other cleanup stuff here */
  6715. +
  6716. + return 0;
  6717. +}
  6718. +
  6719. +
  6720. +int
  6721. +ipkg_packages_list(args_t *args,
  6722. + const char *packages,
  6723. + ipkg_list_callback cblist,
  6724. + void *userdata)
  6725. +{
  6726. + ipkg_cmd_t *cmd;
  6727. + ipkg_conf_t ipkg_conf;
  6728. + int err;
  6729. +
  6730. + err = ipkg_conf_init (&ipkg_conf, args);
  6731. + if (err)
  6732. + {
  6733. + return err;
  6734. + }
  6735. +
  6736. + ipkg_cb_list = cblist;
  6737. + /* we need to do this because of static declarations,
  6738. + * maybe a good idea to change */
  6739. + cmd = ipkg_cmd_find ("list");
  6740. + if (packages)
  6741. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
  6742. + else
  6743. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
  6744. + ipkg_cb_list = NULL;
  6745. + ipkg_conf_deinit (&ipkg_conf);
  6746. + return (err);
  6747. +}
  6748. +
  6749. +
  6750. +int
  6751. +ipkg_packages_status(args_t *args,
  6752. + const char *packages,
  6753. + ipkg_status_callback cbstatus,
  6754. + void *userdata)
  6755. +{
  6756. + ipkg_cmd_t *cmd;
  6757. + ipkg_conf_t ipkg_conf;
  6758. + int err;
  6759. +
  6760. + err = ipkg_conf_init (&ipkg_conf, args);
  6761. + if (err)
  6762. + {
  6763. + return err;
  6764. + }
  6765. +
  6766. + ipkg_cb_status = cbstatus;
  6767. +
  6768. + /* we need to do this because of static declarations,
  6769. + * maybe a good idea to change */
  6770. + cmd = ipkg_cmd_find ("status");
  6771. + if (packages)
  6772. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
  6773. + else
  6774. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
  6775. +
  6776. + ipkg_cb_status = NULL;
  6777. + ipkg_conf_deinit (&ipkg_conf);
  6778. + return (err);
  6779. +}
  6780. +
  6781. +
  6782. +int
  6783. +ipkg_packages_info(args_t *args,
  6784. + const char *packages,
  6785. + ipkg_status_callback cbstatus,
  6786. + void *userdata)
  6787. +{
  6788. + ipkg_cmd_t *cmd;
  6789. + ipkg_conf_t ipkg_conf;
  6790. + int err;
  6791. +
  6792. + err = ipkg_conf_init (&ipkg_conf, args);
  6793. + if (err)
  6794. + {
  6795. + return err;
  6796. + }
  6797. +
  6798. + ipkg_cb_status = cbstatus;
  6799. +
  6800. + /* we need to do this because of static declarations,
  6801. + * maybe a good idea to change */
  6802. + cmd = ipkg_cmd_find ("info");
  6803. + if (packages)
  6804. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
  6805. + else
  6806. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
  6807. +
  6808. + ipkg_cb_status = NULL;
  6809. + ipkg_conf_deinit (&ipkg_conf);
  6810. + return (err);
  6811. +}
  6812. +
  6813. +
  6814. +int
  6815. +ipkg_packages_install (args_t * args, const char *name)
  6816. +{
  6817. + ipkg_cmd_t *cmd;
  6818. + ipkg_conf_t ipkg_conf;
  6819. + int err;
  6820. +
  6821. + /* this error should be handled in application */
  6822. + if (!name || !strlen (name))
  6823. + return (-1);
  6824. +
  6825. + err = ipkg_conf_init (&ipkg_conf, args);
  6826. + if (err)
  6827. + {
  6828. + return err;
  6829. + }
  6830. +
  6831. + /* we need to do this because of static declarations,
  6832. + * maybe a good idea to change */
  6833. + cmd = ipkg_cmd_find ("install");
  6834. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
  6835. +
  6836. + ipkg_conf_deinit(&ipkg_conf);
  6837. + return (err);
  6838. +}
  6839. +
  6840. +
  6841. +int
  6842. +ipkg_packages_remove(args_t *args, const char *name, int purge)
  6843. +{
  6844. + ipkg_cmd_t *cmd;
  6845. + ipkg_conf_t ipkg_conf;
  6846. + int err;
  6847. +
  6848. + /* this error should be handled in application */
  6849. + if (!name || !strlen (name))
  6850. + return (-1);
  6851. +
  6852. + err = ipkg_conf_init (&ipkg_conf, args);
  6853. + if (err)
  6854. + {
  6855. + return err;
  6856. + }
  6857. +
  6858. + /* we need to do this because of static declarations,
  6859. + * maybe a good idea to change */
  6860. + if (purge)
  6861. + cmd = ipkg_cmd_find ("purge");
  6862. + else
  6863. + cmd = ipkg_cmd_find ("remove");
  6864. +
  6865. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
  6866. +
  6867. + ipkg_conf_deinit(&ipkg_conf);
  6868. + return (err);
  6869. +}
  6870. +
  6871. +
  6872. +int
  6873. +ipkg_lists_update(args_t *args)
  6874. +{
  6875. + ipkg_cmd_t *cmd;
  6876. + ipkg_conf_t ipkg_conf;
  6877. + int err;
  6878. +
  6879. + err = ipkg_conf_init (&ipkg_conf, args);
  6880. + if (err)
  6881. + {
  6882. + return err;
  6883. + }
  6884. +
  6885. + /* we need to do this because of static declarations,
  6886. + * maybe a good idea to change */
  6887. + cmd = ipkg_cmd_find ("update");
  6888. +
  6889. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, NULL);
  6890. +
  6891. + ipkg_conf_deinit(&ipkg_conf);
  6892. + return (err);
  6893. +}
  6894. +
  6895. +
  6896. +int
  6897. +ipkg_packages_upgrade(args_t *args)
  6898. +{
  6899. + ipkg_cmd_t *cmd;
  6900. + ipkg_conf_t ipkg_conf;
  6901. + int err;
  6902. +
  6903. + err = ipkg_conf_init (&ipkg_conf, args);
  6904. + if (err)
  6905. + {
  6906. + return err;
  6907. + }
  6908. +
  6909. + /* we need to do this because of static declarations,
  6910. + * maybe a good idea to change */
  6911. + cmd = ipkg_cmd_find ("upgrade");
  6912. +
  6913. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, NULL);
  6914. +
  6915. + ipkg_conf_deinit(&ipkg_conf);
  6916. + return (err);
  6917. +}
  6918. +
  6919. +
  6920. +int
  6921. +ipkg_packages_download (args_t * args, const char *name)
  6922. +{
  6923. + ipkg_cmd_t *cmd;
  6924. + ipkg_conf_t ipkg_conf;
  6925. + int err;
  6926. +
  6927. + /* this error should be handled in application */
  6928. + if (!name || !strlen (name))
  6929. + return (-1);
  6930. +
  6931. + err = ipkg_conf_init (&ipkg_conf, args);
  6932. + if (err)
  6933. + {
  6934. + return err;
  6935. + }
  6936. +
  6937. + /* we need to do this because of static declarations,
  6938. + * maybe a good idea to change */
  6939. + cmd = ipkg_cmd_find ("download");
  6940. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
  6941. +
  6942. + ipkg_conf_deinit(&ipkg_conf);
  6943. + return (err);
  6944. +}
  6945. +
  6946. +
  6947. +int
  6948. +ipkg_package_files(args_t *args,
  6949. + const char *name,
  6950. + ipkg_list_callback cblist,
  6951. + void *userdata)
  6952. +{
  6953. + ipkg_cmd_t *cmd;
  6954. + ipkg_conf_t ipkg_conf;
  6955. + int err;
  6956. +
  6957. + /* this error should be handled in application */
  6958. + if (!name || !strlen (name))
  6959. + return (-1);
  6960. +
  6961. + err = ipkg_conf_init (&ipkg_conf, args);
  6962. + if (err)
  6963. + {
  6964. + return err;
  6965. + }
  6966. +
  6967. + ipkg_cb_list = cblist;
  6968. +
  6969. + /* we need to do this because of static declarations,
  6970. + * maybe a good idea to change */
  6971. + cmd = ipkg_cmd_find ("files");
  6972. +
  6973. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, userdata);
  6974. +
  6975. + ipkg_cb_list = NULL;
  6976. + ipkg_conf_deinit(&ipkg_conf);
  6977. + return (err);
  6978. +}
  6979. +
  6980. +
  6981. +int
  6982. +ipkg_file_search(args_t *args,
  6983. + const char *file,
  6984. + ipkg_list_callback cblist,
  6985. + void *userdata)
  6986. +{
  6987. + ipkg_cmd_t *cmd;
  6988. + ipkg_conf_t ipkg_conf;
  6989. + int err;
  6990. +
  6991. + /* this error should be handled in application */
  6992. + if (!file || !strlen (file))
  6993. + return (-1);
  6994. +
  6995. + err = ipkg_conf_init (&ipkg_conf, args);
  6996. + if (err)
  6997. + {
  6998. + return err;
  6999. + }
  7000. +
  7001. + ipkg_cb_list = cblist;
  7002. +
  7003. + /* we need to do this because of static declarations,
  7004. + * maybe a good idea to change */
  7005. + cmd = ipkg_cmd_find ("search");
  7006. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &file, userdata);
  7007. +
  7008. + ipkg_cb_list = NULL;
  7009. + ipkg_conf_deinit(&ipkg_conf);
  7010. + return(err);
  7011. +}
  7012. +
  7013. +
  7014. +int
  7015. +ipkg_file_what(args_t *args, const char *file, const char* command)
  7016. +{
  7017. + ipkg_cmd_t *cmd;
  7018. + ipkg_conf_t ipkg_conf;
  7019. + int err;
  7020. +
  7021. + /* this error should be handled in application */
  7022. + if (!file || !strlen (file))
  7023. + return (-1);
  7024. +
  7025. + err = ipkg_conf_init (&ipkg_conf, args);
  7026. + if (err)
  7027. + {
  7028. + return err;
  7029. + }
  7030. +
  7031. + /* we need to do this because of static declarations,
  7032. + * maybe a good idea to change */
  7033. + cmd = ipkg_cmd_find (command);
  7034. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &file, NULL);
  7035. +
  7036. + ipkg_conf_deinit(&ipkg_conf);
  7037. + return(err);
  7038. +}
  7039. +
  7040. +#define ipkg_package_whatdepends(args,file) ipkg_file_what(args,file,"whatdepends")
  7041. +#define ipkg_package_whatrecommends(args, file) ipkg_file_what(args,file,"whatrecommends")
  7042. +#define ipkg_package_whatprovides(args, file) ipkg_file_what(args,file,"whatprovides")
  7043. +#define ipkg_package_whatconflicts(args, file) ipkg_file_what(args,file,"whatconflicts")
  7044. +#define ipkg_package_whatreplaces(args, file) ipkg_file_what(args,file,"whatreplaces")
  7045. +
  7046. +
  7047. +int default_ipkg_message_callback(ipkg_conf_t *conf, message_level_t level,
  7048. + char *msg)
  7049. +{
  7050. + if (conf && (conf->verbosity < level)) {
  7051. + return 0;
  7052. + } else {
  7053. + if ( level == IPKG_ERROR )
  7054. + push_error_list(&error_list, msg);
  7055. + else
  7056. + printf(msg);
  7057. + }
  7058. + return 0;
  7059. +}
  7060. +
  7061. +int default_ipkg_list_callback(char *name, char *desc, char *version)
  7062. +{
  7063. + if (desc)
  7064. + printf("%s - %s - %s\n", name, version, desc);
  7065. + else
  7066. + printf("%s - %s\n", name, version);
  7067. + return 0;
  7068. +}
  7069. +
  7070. +int default_ipkg_files_callback(char *desc)
  7071. +{
  7072. + if (desc)
  7073. + printf("%s\n", desc);
  7074. + return 0;
  7075. +}
  7076. +
  7077. +int default_ipkg_status_callback(char *desc)
  7078. +{
  7079. + printf("%s\n", desc);
  7080. + return 0;
  7081. +}
  7082. +
  7083. +char* default_ipkg_response_callback(char *question)
  7084. +{
  7085. + char *response = NULL;
  7086. + printf(question);
  7087. + fflush(stdout);
  7088. + do {
  7089. + response = (char *)file_read_line_alloc(stdin);
  7090. + } while (response == NULL);
  7091. + return response;
  7092. +}
  7093. +
  7094. +/* This is used for backward compatibility */
  7095. +int
  7096. +ipkg_op (int argc, char *argv[])
  7097. +{
  7098. + int err, optind_;
  7099. + args_t args;
  7100. + char *cmd_name;
  7101. + ipkg_cmd_t *cmd;
  7102. + ipkg_conf_t ipkg_conf;
  7103. + const char *message = "ipkg must have one sub-command argument";
  7104. +
  7105. + /* mount rootfs read-write */
  7106. + if (mount("","/",0,MS_REMOUNT,0)<0)
  7107. + fprintf (stderr, "Mounting rootfs read-write failed\n");
  7108. +
  7109. + args_init (&args);
  7110. +
  7111. + optind_ = args_parse (&args, argc, argv);
  7112. + if (optind_ == argc || optind_ < 0)
  7113. + {
  7114. + args_usage(message);
  7115. + }
  7116. +
  7117. + cmd_name = argv[optind_++];
  7118. +/* Pigi: added a flag to disable the checking of structures if the command does not need to
  7119. + read anything from there.
  7120. +*/
  7121. + if ( !strcmp(cmd_name,"print-architecture") ||
  7122. + !strcmp(cmd_name,"print_architecture") ||
  7123. + !strcmp(cmd_name,"print-installation-architecture") ||
  7124. + !strcmp(cmd_name,"print_installation_architecture") )
  7125. + args.nocheckfordirorfile = 1;
  7126. +
  7127. +/* Pigi: added a flag to disable the reading of feed files if the command does not need to
  7128. + read anything from there.
  7129. +*/
  7130. + if ( !strcmp(cmd_name,"flag") ||
  7131. + !strcmp(cmd_name,"configure") ||
  7132. + !strcmp(cmd_name,"remove") ||
  7133. + !strcmp(cmd_name,"files") ||
  7134. + !strcmp(cmd_name,"search") ||
  7135. + !strcmp(cmd_name,"compare_versions") ||
  7136. + !strcmp(cmd_name,"compare-versions") ||
  7137. + !strcmp(cmd_name,"list_installed") ||
  7138. + !strcmp(cmd_name,"list-installed") ||
  7139. + !strcmp(cmd_name,"status") )
  7140. + args.noreadfeedsfile = 1;
  7141. +
  7142. +
  7143. + err = ipkg_conf_init (&ipkg_conf, &args);
  7144. + if (err)
  7145. + {
  7146. + return err;
  7147. + }
  7148. +
  7149. + args_deinit (&args);
  7150. +
  7151. + ipkg_cb_message = default_ipkg_message_callback;
  7152. + ipkg_cb_response = default_ipkg_response_callback;
  7153. + ipkg_cb_status = (ipkg_status_callback)default_ipkg_status_callback;
  7154. + if ( strcmp(cmd_name, "files")==0)
  7155. + ipkg_cb_list = (ipkg_list_callback)default_ipkg_files_callback;
  7156. + else
  7157. + ipkg_cb_list = (ipkg_list_callback)default_ipkg_list_callback;
  7158. +
  7159. + cmd = ipkg_cmd_find (cmd_name);
  7160. + if (cmd == NULL)
  7161. + {
  7162. + fprintf (stderr, "%s: unknown sub-command %s\n", argv[0],
  7163. + cmd_name);
  7164. + args_usage (NULL);
  7165. + }
  7166. +
  7167. + if (cmd->requires_args && optind_ == argc)
  7168. + {
  7169. + fprintf (stderr,
  7170. + "%s: the ``%s'' command requires at least one argument\n",
  7171. + __FUNCTION__, cmd_name);
  7172. + args_usage (NULL);
  7173. + }
  7174. +
  7175. + err = ipkg_cmd_exec (cmd, &ipkg_conf, argc - optind_, (const char **) (argv + optind_), NULL);
  7176. +
  7177. + ipkg_conf_deinit (&ipkg_conf);
  7178. + /* mount rootfs read-only */
  7179. + if (mount("","/",0,MS_REMOUNT|MS_RDONLY,0)<0)
  7180. + fprintf (stderr, "Mounting rootfs read-only failed\n");
  7181. +
  7182. + return err;
  7183. +}
  7184. diff -Nur busybox-1.16.1.orig/archival/libipkg/libipkg.h busybox-1.16.1/archival/libipkg/libipkg.h
  7185. --- busybox-1.16.1.orig/archival/libipkg/libipkg.h 1970-01-01 01:00:00.000000000 +0100
  7186. +++ busybox-1.16.1/archival/libipkg/libipkg.h 2010-06-29 17:31:24.283460019 +0200
  7187. @@ -0,0 +1,78 @@
  7188. +/* ipkglib.h - the itsy package management system
  7189. +
  7190. + Florian Boor <florian.boor@kernelconcepts.de>
  7191. +
  7192. + This program is free software; you can redistribute it and/or
  7193. + modify it under the terms of the GNU General Public License as
  7194. + published by the Free Software Foundation; either version 2, or (at
  7195. + your option) any later version.
  7196. +
  7197. + This program is distributed in the hope that it will be useful, but
  7198. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7199. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7200. + General Public License for more details.
  7201. +*/
  7202. +
  7203. +#ifndef IPKGLIB_H
  7204. +#define IPKGLIB_H
  7205. +
  7206. +#include "ipkg_conf.h"
  7207. +#include "ipkg_message.h"
  7208. +
  7209. +#include "args.h"
  7210. +#include "pkg.h"
  7211. +
  7212. +typedef int (*ipkg_message_callback)(ipkg_conf_t *conf, message_level_t level,
  7213. + char *msg);
  7214. +typedef int (*ipkg_list_callback)(char *name, char *desc, char *version,
  7215. + pkg_state_status_t status, void *userdata);
  7216. +typedef int (*ipkg_status_callback)(char *name, int istatus, char *desc,
  7217. + void *userdata);
  7218. +typedef char* (*ipkg_response_callback)(char *question);
  7219. +
  7220. +extern int ipkg_op(int argc, char *argv[]); /* ipkglib.c */
  7221. +extern int ipkg_init (ipkg_message_callback mcall,
  7222. + ipkg_response_callback rcall,
  7223. + args_t * args);
  7224. +
  7225. +extern int ipkg_deinit (args_t *args);
  7226. +extern int ipkg_packages_list(args_t *args,
  7227. + const char *packages,
  7228. + ipkg_list_callback cblist,
  7229. + void *userdata);
  7230. +extern int ipkg_packages_status(args_t *args,
  7231. + const char *packages,
  7232. + ipkg_status_callback cbstatus,
  7233. + void *userdata);
  7234. +extern int ipkg_packages_info(args_t *args,
  7235. + const char *packages,
  7236. + ipkg_status_callback cbstatus,
  7237. + void *userdata);
  7238. +extern int ipkg_packages_install(args_t *args, const char *name);
  7239. +extern int ipkg_packages_remove(args_t *args, const char *name, int purge);
  7240. +extern int ipkg_lists_update(args_t *args);
  7241. +extern int ipkg_packages_upgrade(args_t *args);
  7242. +extern int ipkg_packages_download(args_t *args, const char *name);
  7243. +extern int ipkg_package_files(args_t *args,
  7244. + const char *name,
  7245. + ipkg_list_callback cblist,
  7246. + void *userdata);
  7247. +extern int ipkg_file_search(args_t *args,
  7248. + const char *file,
  7249. + ipkg_list_callback cblist,
  7250. + void *userdata);
  7251. +extern int ipkg_package_whatdepends(args_t *args, const char *file);
  7252. +extern int ipkg_package_whatrecommends(args_t *args, const char *file);
  7253. +extern int ipkg_package_whatprovides(args_t *args, const char *file);
  7254. +extern int ipkg_package_whatconflicts(args_t *args, const char *file);
  7255. +extern int ipkg_package_whatreplaces(args_t *args, const char *file);
  7256. +
  7257. +extern ipkg_message_callback ipkg_cb_message; /* ipkglib.c */
  7258. +extern ipkg_response_callback ipkg_cb_response;
  7259. +extern ipkg_status_callback ipkg_cb_status;
  7260. +extern ipkg_list_callback ipkg_cb_list;
  7261. +extern void push_error_list(struct errlist **errors,char * msg);
  7262. +extern void reverse_error_list(struct errlist **errors);
  7263. +extern void free_error_list(struct errlist **errors);
  7264. +
  7265. +#endif
  7266. diff -Nur busybox-1.16.1.orig/archival/libipkg/nv_pair.c busybox-1.16.1/archival/libipkg/nv_pair.c
  7267. --- busybox-1.16.1.orig/archival/libipkg/nv_pair.c 1970-01-01 01:00:00.000000000 +0100
  7268. +++ busybox-1.16.1/archival/libipkg/nv_pair.c 2010-06-29 17:31:24.316180264 +0200
  7269. @@ -0,0 +1,40 @@
  7270. +/* nv_pair.c - the itsy package management system
  7271. +
  7272. + Carl D. Worth
  7273. +
  7274. + Copyright (C) 2001 University of Southern California
  7275. +
  7276. + This program is free software; you can redistribute it and/or
  7277. + modify it under the terms of the GNU General Public License as
  7278. + published by the Free Software Foundation; either version 2, or (at
  7279. + your option) any later version.
  7280. +
  7281. + This program is distributed in the hope that it will be useful, but
  7282. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7283. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7284. + General Public License for more details.
  7285. +*/
  7286. +
  7287. +#include "ipkg.h"
  7288. +
  7289. +#include "nv_pair.h"
  7290. +#include "str_util.h"
  7291. +
  7292. +int nv_pair_init(nv_pair_t *nv_pair, const char *name, const char *value)
  7293. +{
  7294. + nv_pair->name = str_dup_safe(name);
  7295. + nv_pair->value = str_dup_safe(value);
  7296. +
  7297. + return 0;
  7298. +}
  7299. +
  7300. +void nv_pair_deinit(nv_pair_t *nv_pair)
  7301. +{
  7302. + free(nv_pair->name);
  7303. + nv_pair->name = NULL;
  7304. +
  7305. + free(nv_pair->value);
  7306. + nv_pair->value = NULL;
  7307. +}
  7308. +
  7309. +
  7310. diff -Nur busybox-1.16.1.orig/archival/libipkg/nv_pair.h busybox-1.16.1/archival/libipkg/nv_pair.h
  7311. --- busybox-1.16.1.orig/archival/libipkg/nv_pair.h 1970-01-01 01:00:00.000000000 +0100
  7312. +++ busybox-1.16.1/archival/libipkg/nv_pair.h 2010-06-29 17:31:24.358376170 +0200
  7313. @@ -0,0 +1,32 @@
  7314. +/* nv_pair.h - the itsy package management system
  7315. +
  7316. + Carl D. Worth
  7317. +
  7318. + Copyright (C) 2001 University of Southern California
  7319. +
  7320. + This program is free software; you can redistribute it and/or
  7321. + modify it under the terms of the GNU General Public License as
  7322. + published by the Free Software Foundation; either version 2, or (at
  7323. + your option) any later version.
  7324. +
  7325. + This program is distributed in the hope that it will be useful, but
  7326. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7327. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7328. + General Public License for more details.
  7329. +*/
  7330. +
  7331. +#ifndef NV_PAIR_H
  7332. +#define NV_PAIR_H
  7333. +
  7334. +typedef struct nv_pair nv_pair_t;
  7335. +struct nv_pair
  7336. +{
  7337. + char *name;
  7338. + char *value;
  7339. +};
  7340. +
  7341. +int nv_pair_init(nv_pair_t *nv_pair, const char *name, const char *value);
  7342. +void nv_pair_deinit(nv_pair_t *nv_pair);
  7343. +
  7344. +#endif
  7345. +
  7346. diff -Nur busybox-1.16.1.orig/archival/libipkg/nv_pair_list.c busybox-1.16.1/archival/libipkg/nv_pair_list.c
  7347. --- busybox-1.16.1.orig/archival/libipkg/nv_pair_list.c 1970-01-01 01:00:00.000000000 +0100
  7348. +++ busybox-1.16.1/archival/libipkg/nv_pair_list.c 2010-06-29 17:31:24.395873641 +0200
  7349. @@ -0,0 +1,98 @@
  7350. +/* nv_pair_list.c - the itsy package management system
  7351. +
  7352. + Carl D. Worth
  7353. +
  7354. + Copyright (C) 2001 University of Southern California
  7355. +
  7356. + This program is free software; you can redistribute it and/or
  7357. + modify it under the terms of the GNU General Public License as
  7358. + published by the Free Software Foundation; either version 2, or (at
  7359. + your option) any later version.
  7360. +
  7361. + This program is distributed in the hope that it will be useful, but
  7362. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7363. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7364. + General Public License for more details.
  7365. +*/
  7366. +
  7367. +#include "ipkg.h"
  7368. +
  7369. +#include "nv_pair.h"
  7370. +#include "void_list.h"
  7371. +#include "nv_pair_list.h"
  7372. +
  7373. +int nv_pair_list_elt_init(nv_pair_list_elt_t *elt, nv_pair_t *data)
  7374. +{
  7375. + return void_list_elt_init((void_list_elt_t *) elt, data);
  7376. +}
  7377. +
  7378. +void nv_pair_list_elt_deinit(nv_pair_list_elt_t *elt)
  7379. +{
  7380. + void_list_elt_deinit((void_list_elt_t *) elt);
  7381. +}
  7382. +
  7383. +int nv_pair_list_init(nv_pair_list_t *list)
  7384. +{
  7385. + return void_list_init((void_list_t *) list);
  7386. +}
  7387. +
  7388. +void nv_pair_list_deinit(nv_pair_list_t *list)
  7389. +{
  7390. + nv_pair_list_elt_t *iter;
  7391. + nv_pair_t *nv_pair;
  7392. +
  7393. + for (iter = list->head; iter; iter = iter->next) {
  7394. + nv_pair = iter->data;
  7395. + nv_pair_deinit(nv_pair);
  7396. +
  7397. + /* malloced in nv_pair_list_append */
  7398. + free(nv_pair);
  7399. + iter->data = NULL;
  7400. + }
  7401. + void_list_deinit((void_list_t *) list);
  7402. +}
  7403. +
  7404. +nv_pair_t *nv_pair_list_append(nv_pair_list_t *list, const char *name, const char *value)
  7405. +{
  7406. + int err;
  7407. +
  7408. + /* freed in nv_pair_list_deinit */
  7409. + nv_pair_t *nv_pair = malloc(sizeof(nv_pair_t));
  7410. +
  7411. + if (nv_pair == NULL) {
  7412. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  7413. + return NULL;
  7414. + }
  7415. + nv_pair_init(nv_pair, name, value);
  7416. +
  7417. + err = void_list_append((void_list_t *) list, nv_pair);
  7418. + if (err) {
  7419. + return NULL;
  7420. + }
  7421. +
  7422. + return nv_pair;
  7423. +}
  7424. +
  7425. +int nv_pair_list_push(nv_pair_list_t *list, nv_pair_t *data)
  7426. +{
  7427. + return void_list_push((void_list_t *) list, data);
  7428. +}
  7429. +
  7430. +nv_pair_list_elt_t *nv_pair_list_pop(nv_pair_list_t *list)
  7431. +{
  7432. + return (nv_pair_list_elt_t *) void_list_pop((void_list_t *) list);
  7433. +}
  7434. +
  7435. +char *nv_pair_list_find(nv_pair_list_t *list, char *name)
  7436. +{
  7437. + nv_pair_list_elt_t *iter;
  7438. + nv_pair_t *nv_pair;
  7439. +
  7440. + for (iter = list->head; iter; iter = iter->next) {
  7441. + nv_pair = iter->data;
  7442. + if (strcmp(nv_pair->name, name) == 0) {
  7443. + return nv_pair->value;
  7444. + }
  7445. + }
  7446. + return NULL;
  7447. +}
  7448. diff -Nur busybox-1.16.1.orig/archival/libipkg/nv_pair_list.h busybox-1.16.1/archival/libipkg/nv_pair_list.h
  7449. --- busybox-1.16.1.orig/archival/libipkg/nv_pair_list.h 1970-01-01 01:00:00.000000000 +0100
  7450. +++ busybox-1.16.1/archival/libipkg/nv_pair_list.h 2010-06-29 17:31:24.439618049 +0200
  7451. @@ -0,0 +1,60 @@
  7452. +/* nv_pair_list.h - the itsy package management system
  7453. +
  7454. + Carl D. Worth
  7455. +
  7456. + Copyright (C) 2001 University of Southern California
  7457. +
  7458. + This program is free software; you can redistribute it and/or
  7459. + modify it under the terms of the GNU General Public License as
  7460. + published by the Free Software Foundation; either version 2, or (at
  7461. + your option) any later version.
  7462. +
  7463. + This program is distributed in the hope that it will be useful, but
  7464. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7465. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7466. + General Public License for more details.
  7467. +*/
  7468. +
  7469. +#ifndef NV_PAIR_LIST_H
  7470. +#define NV_PAIR_LIST_H
  7471. +
  7472. +#include "nv_pair.h"
  7473. +#include "void_list.h"
  7474. +
  7475. +typedef struct nv_pair_list_elt nv_pair_list_elt_t;
  7476. +struct nv_pair_list_elt
  7477. +{
  7478. + nv_pair_list_elt_t *next;
  7479. + nv_pair_t *data;
  7480. +};
  7481. +
  7482. +typedef struct nv_pair_list nv_pair_list_t;
  7483. +struct nv_pair_list
  7484. +{
  7485. + nv_pair_list_elt_t pre_head;
  7486. + nv_pair_list_elt_t *head;
  7487. + nv_pair_list_elt_t *tail;
  7488. +};
  7489. +
  7490. +static inline int nv_pair_list_empty(nv_pair_list_t *list)
  7491. +{
  7492. + if (list->head == NULL)
  7493. + return 1;
  7494. + else
  7495. + return 0;
  7496. +}
  7497. +
  7498. +int nv_pair_list_elt_init(nv_pair_list_elt_t *elt, nv_pair_t *data);
  7499. +void nv_pair_list_elt_deinit(nv_pair_list_elt_t *elt);
  7500. +
  7501. +int nv_pair_list_init(nv_pair_list_t *list);
  7502. +void nv_pair_list_deinit(nv_pair_list_t *list);
  7503. +
  7504. +nv_pair_t *nv_pair_list_append(nv_pair_list_t *list,
  7505. + const char *name, const char *value);
  7506. +int nv_pair_list_push(nv_pair_list_t *list, nv_pair_t *data);
  7507. +nv_pair_list_elt_t *nv_pair_list_pop(nv_pair_list_t *list);
  7508. +char *nv_pair_list_find(nv_pair_list_t *list, char *name);
  7509. +
  7510. +#endif
  7511. +
  7512. diff -Nur busybox-1.16.1.orig/archival/libipkg/pkg.c busybox-1.16.1/archival/libipkg/pkg.c
  7513. --- busybox-1.16.1.orig/archival/libipkg/pkg.c 1970-01-01 01:00:00.000000000 +0100
  7514. +++ busybox-1.16.1/archival/libipkg/pkg.c 2010-06-29 17:31:24.502860549 +0200
  7515. @@ -0,0 +1,1757 @@
  7516. +/* pkg.c - the itsy package management system
  7517. +
  7518. + Carl D. Worth
  7519. +
  7520. + Copyright (C) 2001 University of Southern California
  7521. +
  7522. + This program is free software; you can redistribute it and/or
  7523. + modify it under the terms of the GNU General Public License as
  7524. + published by the Free Software Foundation; either version 2, or (at
  7525. + your option) any later version.
  7526. +
  7527. + This program is distributed in the hope that it will be useful, but
  7528. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7529. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7530. + General Public License for more details.
  7531. +*/
  7532. +
  7533. +#include "ipkg.h"
  7534. +#include <ctype.h>
  7535. +#include <string.h>
  7536. +#include <errno.h>
  7537. +
  7538. +#include "pkg.h"
  7539. +
  7540. +#include "pkg_parse.h"
  7541. +#include "pkg_extract.h"
  7542. +#include "ipkg_message.h"
  7543. +#include "ipkg_utils.h"
  7544. +
  7545. +#include "sprintf_alloc.h"
  7546. +#include "file_util.h"
  7547. +#include "str_util.h"
  7548. +#include "xsystem.h"
  7549. +#include "ipkg_conf.h"
  7550. +
  7551. +int pkg_get_arch_priority(ipkg_conf_t *conf, const char *archname);
  7552. +void pkg_write_filelist_helper(const char *key, void *entry_, void *data_);
  7553. +
  7554. +typedef struct enum_map enum_map_t;
  7555. +struct enum_map
  7556. +{
  7557. + int value;
  7558. + const char *str;
  7559. +};
  7560. +
  7561. +static const enum_map_t pkg_state_want_map[] = {
  7562. + { SW_UNKNOWN, "unknown"},
  7563. + { SW_INSTALL, "install"},
  7564. + { SW_DEINSTALL, "deinstall"},
  7565. + { SW_PURGE, "purge"}
  7566. +};
  7567. +
  7568. +static const enum_map_t pkg_state_flag_map[] = {
  7569. + { SF_OK, "ok"},
  7570. + { SF_REINSTREQ, "reinstreq"},
  7571. + { SF_HOLD, "hold"},
  7572. + { SF_REPLACE, "replace"},
  7573. + { SF_NOPRUNE, "noprune"},
  7574. + { SF_PREFER, "prefer"},
  7575. + { SF_OBSOLETE, "obsolete"},
  7576. + { SF_USER, "user"},
  7577. +};
  7578. +
  7579. +static const enum_map_t pkg_state_status_map[] = {
  7580. + { SS_NOT_INSTALLED, "not-installed" },
  7581. + { SS_UNPACKED, "unpacked" },
  7582. + { SS_HALF_CONFIGURED, "half-configured" },
  7583. + { SS_INSTALLED, "installed" },
  7584. + { SS_HALF_INSTALLED, "half-installed" },
  7585. + { SS_CONFIG_FILES, "config-files" },
  7586. + { SS_POST_INST_FAILED, "post-inst-failed" },
  7587. + { SS_REMOVAL_FAILED, "removal-failed" }
  7588. +};
  7589. +
  7590. +static int verrevcmp(const char *val, const char *ref);
  7591. +
  7592. +
  7593. +pkg_t *pkg_new(void)
  7594. +{
  7595. + pkg_t *pkg;
  7596. +
  7597. + pkg = malloc(sizeof(pkg_t));
  7598. + if (pkg == NULL) {
  7599. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  7600. + return NULL;
  7601. + }
  7602. +
  7603. + pkg_init(pkg);
  7604. +
  7605. + return pkg;
  7606. +}
  7607. +
  7608. +int pkg_init(pkg_t *pkg)
  7609. +{
  7610. + memset(pkg, 0, sizeof(pkg_t));
  7611. + pkg->name = NULL;
  7612. + pkg->epoch = 0;
  7613. + pkg->version = NULL;
  7614. + pkg->revision = NULL;
  7615. + pkg->familiar_revision = NULL;
  7616. + pkg->dest = NULL;
  7617. + pkg->src = NULL;
  7618. + pkg->architecture = NULL;
  7619. + pkg->maintainer = NULL;
  7620. + pkg->section = NULL;
  7621. + pkg->description = NULL;
  7622. + pkg->state_want = SW_UNKNOWN;
  7623. + pkg->state_flag = SF_OK;
  7624. + pkg->state_status = SS_NOT_INSTALLED;
  7625. + pkg->depends_str = NULL;
  7626. + pkg->provides_str = NULL;
  7627. + pkg->depends_count = 0;
  7628. + pkg->depends = NULL;
  7629. + pkg->suggests_str = NULL;
  7630. + pkg->recommends_str = NULL;
  7631. + pkg->suggests_count = 0;
  7632. + pkg->recommends_count = 0;
  7633. +
  7634. + /* Abhaya: added init for conflicts fields */
  7635. + pkg->conflicts = NULL;
  7636. + pkg->conflicts_count = 0;
  7637. +
  7638. + /* added for replaces. Jamey 7/23/2002 */
  7639. + pkg->replaces = NULL;
  7640. + pkg->replaces_count = 0;
  7641. +
  7642. + pkg->pre_depends_count = 0;
  7643. + pkg->pre_depends_str = NULL;
  7644. + pkg->provides_count = 0;
  7645. + pkg->provides = NULL;
  7646. + pkg->filename = NULL;
  7647. + pkg->local_filename = NULL;
  7648. + pkg->tmp_unpack_dir = NULL;
  7649. + pkg->md5sum = NULL;
  7650. + pkg->size = NULL;
  7651. + pkg->installed_size = NULL;
  7652. + pkg->priority = NULL;
  7653. + pkg->source = NULL;
  7654. + conffile_list_init(&pkg->conffiles);
  7655. + pkg->installed_files = NULL;
  7656. + pkg->installed_files_ref_cnt = 0;
  7657. + pkg->essential = 0;
  7658. + pkg->provided_by_hand = 0;
  7659. +
  7660. + return 0;
  7661. +}
  7662. +
  7663. +void pkg_deinit(pkg_t *pkg)
  7664. +{
  7665. + free(pkg->name);
  7666. + pkg->name = NULL;
  7667. + pkg->epoch = 0;
  7668. + free(pkg->version);
  7669. + pkg->version = NULL;
  7670. + /* revision and familiar_revision share storage with version, so
  7671. + don't free */
  7672. + pkg->revision = NULL;
  7673. + pkg->familiar_revision = NULL;
  7674. + /* owned by ipkg_conf_t */
  7675. + pkg->dest = NULL;
  7676. + /* owned by ipkg_conf_t */
  7677. + pkg->src = NULL;
  7678. + free(pkg->architecture);
  7679. + pkg->architecture = NULL;
  7680. + free(pkg->maintainer);
  7681. + pkg->maintainer = NULL;
  7682. + free(pkg->section);
  7683. + pkg->section = NULL;
  7684. + free(pkg->description);
  7685. + pkg->description = NULL;
  7686. + pkg->state_want = SW_UNKNOWN;
  7687. + pkg->state_flag = SF_OK;
  7688. + pkg->state_status = SS_NOT_INSTALLED;
  7689. + free(pkg->depends_str);
  7690. + pkg->depends_str = NULL;
  7691. + free(pkg->provides_str);
  7692. + pkg->provides_str = NULL;
  7693. + pkg->depends_count = 0;
  7694. + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->depends ? */
  7695. + pkg->pre_depends_count = 0;
  7696. + free(pkg->pre_depends_str);
  7697. + pkg->pre_depends_str = NULL;
  7698. + pkg->provides_count = 0;
  7699. + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->provides ? */
  7700. + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->suggests ? */
  7701. + free(pkg->filename);
  7702. + pkg->filename = NULL;
  7703. + free(pkg->local_filename);
  7704. + pkg->local_filename = NULL;
  7705. + /* CLEANUP: It'd be nice to pullin the cleanup function from
  7706. + ipkg_install.c here. See comment in
  7707. + ipkg_install.c:cleanup_temporary_files */
  7708. + free(pkg->tmp_unpack_dir);
  7709. + pkg->tmp_unpack_dir = NULL;
  7710. + free(pkg->md5sum);
  7711. + pkg->md5sum = NULL;
  7712. + free(pkg->size);
  7713. + pkg->size = NULL;
  7714. + free(pkg->installed_size);
  7715. + pkg->installed_size = NULL;
  7716. + free(pkg->priority);
  7717. + pkg->priority = NULL;
  7718. + free(pkg->source);
  7719. + pkg->source = NULL;
  7720. + conffile_list_deinit(&pkg->conffiles);
  7721. + /* XXX: QUESTION: Is forcing this to 1 correct? I suppose so,
  7722. + since if they are calling deinit, they should know. Maybe do an
  7723. + assertion here instead? */
  7724. + pkg->installed_files_ref_cnt = 1;
  7725. + pkg_free_installed_files(pkg);
  7726. + pkg->essential = 0;
  7727. +}
  7728. +
  7729. +int pkg_init_from_file(pkg_t *pkg, const char *filename)
  7730. +{
  7731. + int err;
  7732. + char **raw;
  7733. + FILE *control_file;
  7734. +
  7735. + err = pkg_init(pkg);
  7736. + if (err) { return err; }
  7737. +
  7738. + pkg->local_filename = strdup(filename);
  7739. +
  7740. + control_file = tmpfile();
  7741. + err = pkg_extract_control_file_to_stream(pkg, control_file);
  7742. + if (err) { return err; }
  7743. +
  7744. + rewind(control_file);
  7745. + raw = read_raw_pkgs_from_stream(control_file);
  7746. + pkg_parse_raw(pkg, &raw, NULL, NULL);
  7747. +
  7748. + fclose(control_file);
  7749. +
  7750. + return 0;
  7751. +}
  7752. +
  7753. +/* Merge any new information in newpkg into oldpkg */
  7754. +/* XXX: CLEANUP: This function shouldn't actually modify anything in
  7755. + newpkg, but should leave it usable. This rework is so that
  7756. + pkg_hash_insert doesn't clobber the pkg that you pass into it. */
  7757. +/*
  7758. + * uh, i thought that i had originally written this so that it took
  7759. + * two pkgs and returned a new one? we can do that again... -sma
  7760. + */
  7761. +int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status)
  7762. +{
  7763. + if (oldpkg == newpkg) {
  7764. + return 0;
  7765. + }
  7766. +
  7767. + if (!oldpkg->src)
  7768. + oldpkg->src = newpkg->src;
  7769. + if (!oldpkg->dest)
  7770. + oldpkg->dest = newpkg->dest;
  7771. + if (!oldpkg->architecture)
  7772. + oldpkg->architecture = str_dup_safe(newpkg->architecture);
  7773. + if (!oldpkg->arch_priority)
  7774. + oldpkg->arch_priority = newpkg->arch_priority;
  7775. + if (!oldpkg->section)
  7776. + oldpkg->section = str_dup_safe(newpkg->section);
  7777. + if(!oldpkg->maintainer)
  7778. + oldpkg->maintainer = str_dup_safe(newpkg->maintainer);
  7779. + if(!oldpkg->description)
  7780. + oldpkg->description = str_dup_safe(newpkg->description);
  7781. + if (set_status) {
  7782. + /* merge the state_flags from the new package */
  7783. + oldpkg->state_want = newpkg->state_want;
  7784. + oldpkg->state_status = newpkg->state_status;
  7785. + oldpkg->state_flag = newpkg->state_flag;
  7786. + } else {
  7787. + if (oldpkg->state_want == SW_UNKNOWN)
  7788. + oldpkg->state_want = newpkg->state_want;
  7789. + if (oldpkg->state_status == SS_NOT_INSTALLED)
  7790. + oldpkg->state_status = newpkg->state_status;
  7791. + oldpkg->state_flag |= newpkg->state_flag;
  7792. + }
  7793. +
  7794. + if (!oldpkg->depends_str && !oldpkg->pre_depends_str && !oldpkg->recommends_str && !oldpkg->suggests_str) {
  7795. + oldpkg->depends_str = newpkg->depends_str;
  7796. + newpkg->depends_str = NULL;
  7797. + oldpkg->depends_count = newpkg->depends_count;
  7798. + newpkg->depends_count = 0;
  7799. +
  7800. + oldpkg->depends = newpkg->depends;
  7801. + newpkg->depends = NULL;
  7802. +
  7803. + oldpkg->pre_depends_str = newpkg->pre_depends_str;
  7804. + newpkg->pre_depends_str = NULL;
  7805. + oldpkg->pre_depends_count = newpkg->pre_depends_count;
  7806. + newpkg->pre_depends_count = 0;
  7807. +
  7808. + oldpkg->recommends_str = newpkg->recommends_str;
  7809. + newpkg->recommends_str = NULL;
  7810. + oldpkg->recommends_count = newpkg->recommends_count;
  7811. + newpkg->recommends_count = 0;
  7812. +
  7813. + oldpkg->suggests_str = newpkg->suggests_str;
  7814. + newpkg->suggests_str = NULL;
  7815. + oldpkg->suggests_count = newpkg->suggests_count;
  7816. + newpkg->suggests_count = 0;
  7817. + }
  7818. +
  7819. + if (!oldpkg->provides_str) {
  7820. + oldpkg->provides_str = newpkg->provides_str;
  7821. + newpkg->provides_str = NULL;
  7822. + oldpkg->provides_count = newpkg->provides_count;
  7823. + newpkg->provides_count = 0;
  7824. +
  7825. + oldpkg->provides = newpkg->provides;
  7826. + newpkg->provides = NULL;
  7827. + }
  7828. +
  7829. + if (!oldpkg->conflicts_str) {
  7830. + oldpkg->conflicts_str = newpkg->conflicts_str;
  7831. + newpkg->conflicts_str = NULL;
  7832. + oldpkg->conflicts_count = newpkg->conflicts_count;
  7833. + newpkg->conflicts_count = 0;
  7834. +
  7835. + oldpkg->conflicts = newpkg->conflicts;
  7836. + newpkg->conflicts = NULL;
  7837. + }
  7838. +
  7839. + if (!oldpkg->replaces_str) {
  7840. + oldpkg->replaces_str = newpkg->replaces_str;
  7841. + newpkg->replaces_str = NULL;
  7842. + oldpkg->replaces_count = newpkg->replaces_count;
  7843. + newpkg->replaces_count = 0;
  7844. +
  7845. + oldpkg->replaces = newpkg->replaces;
  7846. + newpkg->replaces = NULL;
  7847. + }
  7848. +
  7849. + if (!oldpkg->filename)
  7850. + oldpkg->filename = str_dup_safe(newpkg->filename);
  7851. + if (0)
  7852. + fprintf(stdout, "pkg=%s old local_filename=%s new local_filename=%s\n",
  7853. + oldpkg->name, oldpkg->local_filename, newpkg->local_filename);
  7854. + if (!oldpkg->local_filename)
  7855. + oldpkg->local_filename = str_dup_safe(newpkg->local_filename);
  7856. + if (!oldpkg->tmp_unpack_dir)
  7857. + oldpkg->tmp_unpack_dir = str_dup_safe(newpkg->tmp_unpack_dir);
  7858. + if (!oldpkg->md5sum)
  7859. + oldpkg->md5sum = str_dup_safe(newpkg->md5sum);
  7860. + if (!oldpkg->size)
  7861. + oldpkg->size = str_dup_safe(newpkg->size);
  7862. + if (!oldpkg->installed_size)
  7863. + oldpkg->installed_size = str_dup_safe(newpkg->installed_size);
  7864. + if (!oldpkg->priority)
  7865. + oldpkg->priority = str_dup_safe(newpkg->priority);
  7866. + if (!oldpkg->source)
  7867. + oldpkg->source = str_dup_safe(newpkg->source);
  7868. + if (oldpkg->conffiles.head == NULL){
  7869. + oldpkg->conffiles = newpkg->conffiles;
  7870. + conffile_list_init(&newpkg->conffiles);
  7871. + }
  7872. + if (!oldpkg->installed_files){
  7873. + oldpkg->installed_files = newpkg->installed_files;
  7874. + oldpkg->installed_files_ref_cnt = newpkg->installed_files_ref_cnt;
  7875. + newpkg->installed_files = NULL;
  7876. + }
  7877. + if (!oldpkg->essential)
  7878. + oldpkg->essential = newpkg->essential;
  7879. +
  7880. + return 0;
  7881. +}
  7882. +
  7883. +abstract_pkg_t *abstract_pkg_new(void)
  7884. +{
  7885. + abstract_pkg_t * ab_pkg;
  7886. +
  7887. + ab_pkg = malloc(sizeof(abstract_pkg_t));
  7888. +
  7889. + if (ab_pkg == NULL) {
  7890. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  7891. + return NULL;
  7892. + }
  7893. +
  7894. + if ( abstract_pkg_init(ab_pkg) < 0 )
  7895. + return NULL;
  7896. +
  7897. + return ab_pkg;
  7898. +}
  7899. +
  7900. +int abstract_pkg_init(abstract_pkg_t *ab_pkg)
  7901. +{
  7902. + memset(ab_pkg, 0, sizeof(abstract_pkg_t));
  7903. +
  7904. + ab_pkg->provided_by = abstract_pkg_vec_alloc();
  7905. + if (ab_pkg->provided_by==NULL){
  7906. + return -1;
  7907. + }
  7908. + ab_pkg->dependencies_checked = 0;
  7909. + ab_pkg->state_status = SS_NOT_INSTALLED;
  7910. +
  7911. + return 0;
  7912. +}
  7913. +
  7914. +void set_flags_from_control(ipkg_conf_t *conf, pkg_t *pkg){
  7915. + char * temp_str;
  7916. + char **raw =NULL;
  7917. + char **raw_start=NULL;
  7918. +
  7919. + temp_str = (char *) malloc (strlen(pkg->dest->info_dir)+strlen(pkg->name)+12);
  7920. + if (temp_str == NULL ){
  7921. + ipkg_message(conf, IPKG_INFO, "Out of memory in %s\n", __FUNCTION__);
  7922. + return;
  7923. + }
  7924. + sprintf( temp_str,"%s/%s.control",pkg->dest->info_dir,pkg->name);
  7925. +
  7926. + raw = raw_start = read_raw_pkgs_from_file(temp_str);
  7927. + if (raw == NULL ){
  7928. + ipkg_message(conf, IPKG_ERROR, "Unable to open the control file in %s\n", __FUNCTION__);
  7929. + return;
  7930. + }
  7931. +
  7932. + while(*raw){
  7933. + if (!pkg_valorize_other_field(pkg, &raw ) == 0) {
  7934. + ipkg_message(conf, IPKG_DEBUG, "unable to read control file for %s. May be empty\n", pkg->name);
  7935. + }
  7936. + }
  7937. + raw = raw_start;
  7938. + while (*raw) {
  7939. + if (raw!=NULL)
  7940. + free(*raw++);
  7941. + }
  7942. +
  7943. + free(raw_start);
  7944. + free(temp_str);
  7945. +
  7946. + return ;
  7947. +
  7948. +}
  7949. +
  7950. +char * pkg_formatted_info(pkg_t *pkg )
  7951. +{
  7952. + char *line;
  7953. + char * buff;
  7954. +
  7955. + buff = malloc(8192);
  7956. + if (buff == NULL) {
  7957. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  7958. + return NULL;
  7959. + }
  7960. +
  7961. + buff[0] = '\0';
  7962. +
  7963. + line = pkg_formatted_field(pkg, "Package");
  7964. + strncat(buff ,line, strlen(line));
  7965. + free(line);
  7966. +
  7967. + line = pkg_formatted_field(pkg, "Version");
  7968. + strncat(buff ,line, strlen(line));
  7969. + free(line);
  7970. +
  7971. + line = pkg_formatted_field(pkg, "Depends");
  7972. + strncat(buff ,line, strlen(line));
  7973. + free(line);
  7974. +
  7975. + line = pkg_formatted_field(pkg, "Recommends");
  7976. + strncat(buff ,line, strlen(line));
  7977. + free(line);
  7978. +
  7979. + line = pkg_formatted_field(pkg, "Suggests");
  7980. + strncat(buff ,line, strlen(line));
  7981. + free(line);
  7982. +
  7983. + line = pkg_formatted_field(pkg, "Provides");
  7984. + strncat(buff ,line, strlen(line));
  7985. + free(line);
  7986. +
  7987. + line = pkg_formatted_field(pkg, "Replaces");
  7988. + strncat(buff ,line, strlen(line));
  7989. + free(line);
  7990. +
  7991. + line = pkg_formatted_field(pkg, "Conflicts");
  7992. + strncat(buff ,line, strlen(line));
  7993. + free(line);
  7994. +
  7995. + line = pkg_formatted_field(pkg, "Status");
  7996. + strncat(buff ,line, strlen(line));
  7997. + free(line);
  7998. +
  7999. + line = pkg_formatted_field(pkg, "Section");
  8000. + strncat(buff ,line, strlen(line));
  8001. + free(line);
  8002. +
  8003. + line = pkg_formatted_field(pkg, "Essential"); /* @@@@ should be removed in future release. *//* I do not agree with this Pigi*/
  8004. + strncat(buff ,line, strlen(line));
  8005. + free(line);
  8006. +
  8007. + line = pkg_formatted_field(pkg, "Architecture");
  8008. + strncat(buff ,line, strlen(line));
  8009. + free(line);
  8010. +
  8011. + line = pkg_formatted_field(pkg, "Maintainer");
  8012. + strncat(buff ,line, strlen(line));
  8013. + free(line);
  8014. +
  8015. + line = pkg_formatted_field(pkg, "MD5sum");
  8016. + strncat(buff ,line, strlen(line));
  8017. + free(line);
  8018. +
  8019. + line = pkg_formatted_field(pkg, "Size");
  8020. + strncat(buff ,line, strlen(line));
  8021. + free(line);
  8022. +
  8023. + line = pkg_formatted_field(pkg, "Filename");
  8024. + strncat(buff ,line, strlen(line));
  8025. + free(line);
  8026. +
  8027. + line = pkg_formatted_field(pkg, "Conffiles");
  8028. + strncat(buff ,line, strlen(line));
  8029. + free(line);
  8030. +
  8031. + line = pkg_formatted_field(pkg, "Source");
  8032. + strncat(buff ,line, strlen(line));
  8033. + free(line);
  8034. +
  8035. + line = pkg_formatted_field(pkg, "Description");
  8036. + strncat(buff ,line, strlen(line));
  8037. + free(line);
  8038. +
  8039. + line = pkg_formatted_field(pkg, "Installed-Time");
  8040. + strncat(buff ,line, strlen(line));
  8041. + free(line);
  8042. +
  8043. + return buff;
  8044. +}
  8045. +
  8046. +char * pkg_formatted_field(pkg_t *pkg, const char *field )
  8047. +{
  8048. + static size_t LINE_LEN = 128;
  8049. + char * temp = (char *)malloc(1);
  8050. + int len = 0;
  8051. + int flag_provide_false = 0;
  8052. +
  8053. +/*
  8054. + Pigi: After some discussion with Florian we decided to modify the full procedure in
  8055. + dynamic memory allocation. This should avoid any other segv in this area ( except for bugs )
  8056. +*/
  8057. +
  8058. + if (strlen(field) < PKG_MINIMUM_FIELD_NAME_LEN) {
  8059. + goto UNKNOWN_FMT_FIELD;
  8060. + }
  8061. +
  8062. + temp[0]='\0';
  8063. +
  8064. + switch (field[0])
  8065. + {
  8066. + case 'a':
  8067. + case 'A':
  8068. + if (strcasecmp(field, "Architecture") == 0) {
  8069. + /* Architecture */
  8070. + if (pkg->architecture) {
  8071. + temp = (char *)realloc(temp,strlen(pkg->architecture)+17);
  8072. + if ( temp == NULL ){
  8073. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8074. + return NULL;
  8075. + }
  8076. + temp[0]='\0';
  8077. + snprintf(temp, (strlen(pkg->architecture)+17), "Architecture: %s\n", pkg->architecture);
  8078. + }
  8079. + } else {
  8080. + goto UNKNOWN_FMT_FIELD;
  8081. + }
  8082. + break;
  8083. + case 'c':
  8084. + case 'C':
  8085. + if (strcasecmp(field, "Conffiles") == 0) {
  8086. + /* Conffiles */
  8087. + conffile_list_elt_t *iter;
  8088. + char confstr_[LINE_LEN];
  8089. +
  8090. + if (pkg->conffiles.head == NULL) {
  8091. + return temp;
  8092. + }
  8093. +
  8094. + len = 14 ;
  8095. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  8096. + if (iter->data->name && iter->data->value) {
  8097. + len = len + (strlen(iter->data->name)+strlen(iter->data->value)+5);
  8098. + }
  8099. + }
  8100. + temp = (char *)realloc(temp,len);
  8101. + if ( temp == NULL ){
  8102. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8103. + return NULL;
  8104. + }
  8105. + temp[0]='\0';
  8106. + strncpy(temp, "Conffiles:\n", 12);
  8107. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  8108. + if (iter->data->name && iter->data->value) {
  8109. + snprintf(confstr_, LINE_LEN, "%s %s\n", iter->data->name, iter->data->value);
  8110. + strncat(temp, confstr_, strlen(confstr_));
  8111. + }
  8112. + }
  8113. + } else if (strcasecmp(field, "Conflicts") == 0) {
  8114. + int i;
  8115. +
  8116. + if (pkg->conflicts_count) {
  8117. + char conflictstr[LINE_LEN];
  8118. + len = 14 ;
  8119. + for(i = 0; i < pkg->conflicts_count; i++) {
  8120. + len = len + (strlen(pkg->conflicts_str[i])+5);
  8121. + }
  8122. + temp = (char *)realloc(temp,len);
  8123. + if ( temp == NULL ){
  8124. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8125. + return NULL;
  8126. + }
  8127. + temp[0]='\0';
  8128. + strncpy(temp, "Conflicts:", 11);
  8129. + for(i = 0; i < pkg->conflicts_count; i++) {
  8130. + snprintf(conflictstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->conflicts_str[i]);
  8131. + strncat(temp, conflictstr, strlen(conflictstr));
  8132. + }
  8133. + strncat(temp, "\n", strlen("\n"));
  8134. + }
  8135. + } else {
  8136. + goto UNKNOWN_FMT_FIELD;
  8137. + }
  8138. + break;
  8139. + case 'd':
  8140. + case 'D':
  8141. + if (strcasecmp(field, "Depends") == 0) {
  8142. + /* Depends */
  8143. + int i;
  8144. +
  8145. + if (pkg->depends_count) {
  8146. + char depstr[LINE_LEN];
  8147. + len = 14 ;
  8148. + for(i = 0; i < pkg->depends_count; i++) {
  8149. + len = len + (strlen(pkg->depends_str[i])+4);
  8150. + }
  8151. + temp = (char *)realloc(temp,len);
  8152. + if ( temp == NULL ){
  8153. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8154. + return NULL;
  8155. + }
  8156. + temp[0]='\0';
  8157. + strncpy(temp, "Depends:", 10);
  8158. + for(i = 0; i < pkg->depends_count; i++) {
  8159. + snprintf(depstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->depends_str[i]);
  8160. + strncat(temp, depstr, strlen(depstr));
  8161. + }
  8162. + strncat(temp, "\n", strlen("\n"));
  8163. + }
  8164. + } else if (strcasecmp(field, "Description") == 0) {
  8165. + /* Description */
  8166. + if (pkg->description) {
  8167. + temp = (char *)realloc(temp,strlen(pkg->description)+16);
  8168. + if ( temp == NULL ){
  8169. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8170. + return NULL;
  8171. + }
  8172. + temp[0]='\0';
  8173. + snprintf(temp, (strlen(pkg->description)+16), "Description: %s\n", pkg->description);
  8174. + }
  8175. + } else {
  8176. + goto UNKNOWN_FMT_FIELD;
  8177. + }
  8178. + break;
  8179. + case 'e':
  8180. + case 'E': {
  8181. + /* Essential */
  8182. + if (pkg->essential) {
  8183. + temp = (char *)realloc(temp,16);
  8184. + if ( temp == NULL ){
  8185. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8186. + return NULL;
  8187. + }
  8188. + temp[0]='\0';
  8189. + snprintf(temp, (16), "Essential: yes\n");
  8190. + }
  8191. + }
  8192. + break;
  8193. + case 'f':
  8194. + case 'F': {
  8195. + /* Filename */
  8196. + if (pkg->filename) {
  8197. + temp = (char *)realloc(temp,strlen(pkg->filename)+12);
  8198. + if ( temp == NULL ){
  8199. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8200. + return NULL;
  8201. + }
  8202. + temp[0]='\0';
  8203. + snprintf(temp, (strlen(pkg->filename)+12), "Filename: %s\n", pkg->filename);
  8204. + }
  8205. + }
  8206. + break;
  8207. + case 'i':
  8208. + case 'I': {
  8209. + if (strcasecmp(field, "Installed-Size") == 0) {
  8210. + /* Installed-Size */
  8211. + temp = (char *)realloc(temp,strlen(pkg->installed_size)+17);
  8212. + if ( temp == NULL ){
  8213. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8214. + return NULL;
  8215. + }
  8216. + temp[0]='\0';
  8217. + snprintf(temp, (strlen(pkg->installed_size)+17), "Installed-Size: %s\n", pkg->installed_size);
  8218. + } else if (strcasecmp(field, "Installed-Time") == 0 && pkg->installed_time) {
  8219. + temp = (char *)realloc(temp,29);
  8220. + if ( temp == NULL ){
  8221. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8222. + return NULL;
  8223. + }
  8224. + temp[0]='\0';
  8225. + snprintf(temp, 29, "Installed-Time: %lu\n", pkg->installed_time);
  8226. + }
  8227. + }
  8228. + break;
  8229. + case 'm':
  8230. + case 'M': {
  8231. + /* Maintainer | MD5sum */
  8232. + if (strcasecmp(field, "Maintainer") == 0) {
  8233. + /* Maintainer */
  8234. + if (pkg->maintainer) {
  8235. + temp = (char *)realloc(temp,strlen(pkg->maintainer)+14);
  8236. + if ( temp == NULL ){
  8237. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8238. + return NULL;
  8239. + }
  8240. + temp[0]='\0';
  8241. + snprintf(temp, (strlen(pkg->maintainer)+14), "maintainer: %s\n", pkg->maintainer);
  8242. + }
  8243. + } else if (strcasecmp(field, "MD5sum") == 0) {
  8244. + /* MD5sum */
  8245. + if (pkg->md5sum) {
  8246. + temp = (char *)realloc(temp,strlen(pkg->md5sum)+11);
  8247. + if ( temp == NULL ){
  8248. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8249. + return NULL;
  8250. + }
  8251. + temp[0]='\0';
  8252. + snprintf(temp, (strlen(pkg->md5sum)+11), "MD5Sum: %s\n", pkg->md5sum);
  8253. + }
  8254. + } else {
  8255. + goto UNKNOWN_FMT_FIELD;
  8256. + }
  8257. + }
  8258. + break;
  8259. + case 'p':
  8260. + case 'P': {
  8261. + if (strcasecmp(field, "Package") == 0) {
  8262. + /* Package */
  8263. + temp = (char *)realloc(temp,strlen(pkg->name)+11);
  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->name)+11), "Package: %s\n", pkg->name);
  8270. + } else if (strcasecmp(field, "Priority") == 0) {
  8271. + /* Priority */
  8272. + temp = (char *)realloc(temp,strlen(pkg->priority)+12);
  8273. + if ( temp == NULL ){
  8274. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8275. + return NULL;
  8276. + }
  8277. + temp[0]='\0';
  8278. + snprintf(temp, (strlen(pkg->priority)+12), "Priority: %s\n", pkg->priority);
  8279. + } else if (strcasecmp(field, "Provides") == 0) {
  8280. + /* Provides */
  8281. + int i;
  8282. +
  8283. + if (pkg->provides_count) {
  8284. + /* Here we check if the ipkg_internal_use_only is used, and we discard it.*/
  8285. + for ( i=0; i < pkg->provides_count; i++ ){
  8286. + if (strstr(pkg->provides_str[i],"ipkg_internal_use_only")!=NULL) {
  8287. + memset (pkg->provides_str[i],'\x0',strlen(pkg->provides_str[i])); /* Pigi clear my trick flag, just in case */
  8288. + flag_provide_false = 1;
  8289. + }
  8290. + }
  8291. + if ( !flag_provide_false || /* Pigi there is not my trick flag */
  8292. + ((flag_provide_false) && (pkg->provides_count > 1))){ /* Pigi There is, but we also have others Provides */
  8293. + char provstr[LINE_LEN];
  8294. + len = 15;
  8295. + for(i = 0; i < pkg->provides_count; i++) {
  8296. + len = len + (strlen(pkg->provides_str[i])+5);
  8297. + }
  8298. + temp = (char *)realloc(temp,len);
  8299. + if ( temp == NULL ){
  8300. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8301. + return NULL;
  8302. + }
  8303. + temp[0]='\0';
  8304. + strncpy(temp, "Provides:", 12);
  8305. + for(i = 0; i < pkg->provides_count; i++) {
  8306. + if (strlen(pkg->provides_str[i])>0){;
  8307. + snprintf(provstr, LINE_LEN, "%s %s", i == 1 ? "" : ",", pkg->provides_str[i]);
  8308. + strncat(temp, provstr, strlen(provstr));
  8309. + }
  8310. + }
  8311. + strncat(temp, "\n", strlen("\n"));
  8312. + }
  8313. + }
  8314. + } else {
  8315. + goto UNKNOWN_FMT_FIELD;
  8316. + }
  8317. + }
  8318. + break;
  8319. + case 'r':
  8320. + case 'R': {
  8321. + int i;
  8322. + /* Replaces | Recommends*/
  8323. + if (strcasecmp (field, "Replaces") == 0) {
  8324. + if (pkg->replaces_count) {
  8325. + char replstr[LINE_LEN];
  8326. + len = 14;
  8327. + for (i = 0; i < pkg->replaces_count; i++) {
  8328. + len = len + (strlen(pkg->replaces_str[i])+5);
  8329. + }
  8330. + temp = (char *)realloc(temp,len);
  8331. + if ( temp == NULL ){
  8332. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8333. + return NULL;
  8334. + }
  8335. + temp[0]='\0';
  8336. + strncpy(temp, "Replaces:", 12);
  8337. + for (i = 0; i < pkg->replaces_count; i++) {
  8338. + snprintf(replstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->replaces_str[i]);
  8339. + strncat(temp, replstr, strlen(replstr));
  8340. + }
  8341. + strncat(temp, "\n", strlen("\n"));
  8342. + }
  8343. + } else if (strcasecmp (field, "Recommends") == 0) {
  8344. + if (pkg->recommends_count) {
  8345. + char recstr[LINE_LEN];
  8346. + len = 15;
  8347. + for(i = 0; i < pkg->recommends_count; i++) {
  8348. + len = len + (strlen( pkg->recommends_str[i])+5);
  8349. + }
  8350. + temp = (char *)realloc(temp,len);
  8351. + if ( temp == NULL ){
  8352. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8353. + return NULL;
  8354. + }
  8355. + temp[0]='\0';
  8356. + strncpy(temp, "Recommends:", 13);
  8357. + for(i = 0; i < pkg->recommends_count; i++) {
  8358. + snprintf(recstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->recommends_str[i]);
  8359. + strncat(temp, recstr, strlen(recstr));
  8360. + }
  8361. + strncat(temp, "\n", strlen("\n"));
  8362. + }
  8363. + } else {
  8364. + goto UNKNOWN_FMT_FIELD;
  8365. + }
  8366. + }
  8367. + break;
  8368. + case 's':
  8369. + case 'S': {
  8370. + /* Section | Size | Source | Status | Suggests */
  8371. + if (strcasecmp(field, "Section") == 0) {
  8372. + /* Section */
  8373. + if (pkg->section) {
  8374. + temp = (char *)realloc(temp,strlen(pkg->section)+11);
  8375. + if ( temp == NULL ){
  8376. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8377. + return NULL;
  8378. + }
  8379. + temp[0]='\0';
  8380. + snprintf(temp, (strlen(pkg->section)+11), "Section: %s\n", pkg->section);
  8381. + }
  8382. + } else if (strcasecmp(field, "Size") == 0) {
  8383. + /* Size */
  8384. + if (pkg->size) {
  8385. + temp = (char *)realloc(temp,strlen(pkg->size)+8);
  8386. + if ( temp == NULL ){
  8387. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8388. + return NULL;
  8389. + }
  8390. + temp[0]='\0';
  8391. + snprintf(temp, (strlen(pkg->size)+8), "Size: %s\n", pkg->size);
  8392. + }
  8393. + } else if (strcasecmp(field, "Source") == 0) {
  8394. + /* Source */
  8395. + if (pkg->source) {
  8396. + temp = (char *)realloc(temp,strlen(pkg->source)+10);
  8397. + if ( temp == NULL ){
  8398. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8399. + return NULL;
  8400. + }
  8401. + temp[0]='\0';
  8402. + snprintf(temp, (strlen(pkg->source)+10), "Source: %s\n", pkg->source);
  8403. + }
  8404. + } else if (strcasecmp(field, "Status") == 0) {
  8405. + /* Status */
  8406. + /* Benjamin Pineau note: we should avoid direct usage of
  8407. + * strlen(arg) without keeping "arg" for later free()
  8408. + */
  8409. + char *pflag=pkg_state_flag_to_str(pkg->state_flag);
  8410. + char *pstat=pkg_state_status_to_str(pkg->state_status);
  8411. + char *pwant=pkg_state_want_to_str(pkg->state_want);
  8412. +
  8413. + size_t sum_of_sizes = (size_t) ( strlen(pwant)+ strlen(pflag)+ strlen(pstat) + 12 );
  8414. + temp = (char *)realloc(temp,sum_of_sizes);
  8415. + if ( temp == NULL ){
  8416. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8417. + return NULL;
  8418. + }
  8419. + temp[0]='\0';
  8420. + snprintf(temp, sum_of_sizes , "Status: %s %s %s\n", pwant, pflag, pstat);
  8421. + free(pflag);
  8422. + free(pwant);
  8423. + if(pstat) /* pfstat can be NULL if ENOMEM */
  8424. + free(pstat);
  8425. + } else if (strcasecmp(field, "Suggests") == 0) {
  8426. + if (pkg->suggests_count) {
  8427. + int i;
  8428. + char sugstr[LINE_LEN];
  8429. + len = 13;
  8430. + for(i = 0; i < pkg->suggests_count; i++) {
  8431. + len = len + (strlen(pkg->suggests_str[i])+5);
  8432. + }
  8433. + temp = (char *)realloc(temp,len);
  8434. + if ( temp == NULL ){
  8435. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8436. + return NULL;
  8437. + }
  8438. + temp[0]='\0';
  8439. + strncpy(temp, "Suggests:", 10);
  8440. + for(i = 0; i < pkg->suggests_count; i++) {
  8441. + snprintf(sugstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->suggests_str[i]);
  8442. + strncat(temp, sugstr, strlen(sugstr));
  8443. + }
  8444. + strncat(temp, "\n", strlen("\n"));
  8445. + }
  8446. + } else {
  8447. + goto UNKNOWN_FMT_FIELD;
  8448. + }
  8449. + }
  8450. + break;
  8451. + case 'v':
  8452. + case 'V': {
  8453. + /* Version */
  8454. + char *version = pkg_version_str_alloc(pkg);
  8455. + temp = (char *)realloc(temp,strlen(version)+14);
  8456. + if ( temp == NULL ){
  8457. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8458. + return NULL;
  8459. + }
  8460. + temp[0]='\0';
  8461. + snprintf(temp, (strlen(version)+12), "Version: %s\n", version);
  8462. + free(version);
  8463. + }
  8464. + break;
  8465. + default:
  8466. + goto UNKNOWN_FMT_FIELD;
  8467. + }
  8468. +
  8469. + if ( strlen(temp)<2 ) {
  8470. + temp[0]='\0';
  8471. + }
  8472. + return temp;
  8473. +
  8474. + UNKNOWN_FMT_FIELD:
  8475. + fprintf(stderr, "%s: ERROR: Unknown field name: %s\n", __FUNCTION__, field);
  8476. + if ( strlen(temp)<2 ) {
  8477. + temp[0]='\0';
  8478. + }
  8479. +
  8480. + return temp;
  8481. +}
  8482. +
  8483. +void pkg_print_info(pkg_t *pkg, FILE *file)
  8484. +{
  8485. + char * buff;
  8486. + if (pkg == NULL) {
  8487. + return;
  8488. + }
  8489. +
  8490. + buff = pkg_formatted_info(pkg);
  8491. + if ( buff == NULL )
  8492. + return;
  8493. + if (strlen(buff)>2){
  8494. + fwrite(buff, 1, strlen(buff), file);
  8495. + }
  8496. + free(buff);
  8497. +}
  8498. +
  8499. +void pkg_print_status(pkg_t * pkg, FILE * file)
  8500. +{
  8501. + if (pkg == NULL) {
  8502. + return;
  8503. + }
  8504. +
  8505. + /* XXX: QUESTION: Do we actually want more fields here? The
  8506. + original idea was to save space by installing only what was
  8507. + needed for actual computation, (package, version, status,
  8508. + essential, conffiles). The assumption is that all other fields
  8509. + can be found in th available file.
  8510. +
  8511. + But, someone proposed the idea to make it possible to
  8512. + reconstruct a .ipk from an installed package, (ie. for beaming
  8513. + from one handheld to another). So, maybe we actually want a few
  8514. + more fields here, (depends, suggests, etc.), so that that would
  8515. + be guaranteed to work even in the absence of more information
  8516. + from the available file.
  8517. +
  8518. + 28-MAR-03: kergoth and I discussed this yesterday. We think
  8519. + the essential info needs to be here for all installed packages
  8520. + because they may not appear in the Packages files on various
  8521. + feeds. Furthermore, one should be able to install from URL or
  8522. + local storage without requiring a Packages file from any feed.
  8523. + -Jamey
  8524. + */
  8525. + pkg_print_field(pkg, file, "Package");
  8526. + pkg_print_field(pkg, file, "Version");
  8527. + pkg_print_field(pkg, file, "Depends");
  8528. + pkg_print_field(pkg, file, "Recommends");
  8529. + pkg_print_field(pkg, file, "Suggests");
  8530. + pkg_print_field(pkg, file, "Provides");
  8531. + pkg_print_field(pkg, file, "Replaces");
  8532. + pkg_print_field(pkg, file, "Conflicts");
  8533. + pkg_print_field(pkg, file, "Status");
  8534. + pkg_print_field(pkg, file, "Essential"); /* @@@@ should be removed in future release. */
  8535. + pkg_print_field(pkg, file, "Architecture");
  8536. + pkg_print_field(pkg, file, "Conffiles");
  8537. + pkg_print_field(pkg, file, "Installed-Time");
  8538. + fputs("\n", file);
  8539. +}
  8540. +
  8541. +void pkg_print_field(pkg_t *pkg, FILE *file, const char *field)
  8542. +{
  8543. + char *buff;
  8544. + if (strlen(field) < PKG_MINIMUM_FIELD_NAME_LEN) {
  8545. + fprintf(stderr, "%s: ERROR: Unknown field name: %s\n",
  8546. + __FUNCTION__, field);
  8547. + }
  8548. + buff = pkg_formatted_field(pkg, field);
  8549. + if (strlen(buff)>2) {
  8550. + fprintf(file, "%s", buff);
  8551. + fflush(file);
  8552. + }
  8553. + free(buff);
  8554. + return;
  8555. +}
  8556. +
  8557. +/*
  8558. + * libdpkg - Debian packaging suite library routines
  8559. + * vercmp.c - comparison of version numbers
  8560. + *
  8561. + * Copyright (C) 1995 Ian Jackson <iwj10@cus.cam.ac.uk>
  8562. + */
  8563. +int pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg)
  8564. +{
  8565. + int r;
  8566. +
  8567. + if (pkg->epoch > ref_pkg->epoch) {
  8568. + return 1;
  8569. + }
  8570. +
  8571. + if (pkg->epoch < ref_pkg->epoch) {
  8572. + return -1;
  8573. + }
  8574. +
  8575. + r = verrevcmp(pkg->version, ref_pkg->version);
  8576. + if (r) {
  8577. + return r;
  8578. + }
  8579. +
  8580. +#ifdef USE_DEBVERSION
  8581. + r = verrevcmp(pkg->revision, ref_pkg->revision);
  8582. + if (r) {
  8583. + return r;
  8584. + }
  8585. +
  8586. + r = verrevcmp(pkg->familiar_revision, ref_pkg->familiar_revision);
  8587. +#endif
  8588. +
  8589. + return r;
  8590. +}
  8591. +
  8592. +int verrevcmp(const char *val, const char *ref)
  8593. +{
  8594. + int vc, rc;
  8595. + long vl, rl;
  8596. + const char *vp, *rp;
  8597. + const char *vsep, *rsep;
  8598. +
  8599. + if (!val) val= "";
  8600. + if (!ref) ref= "";
  8601. + for (;;) {
  8602. + vp= val; while (*vp && !isdigit(*vp)) vp++;
  8603. + rp= ref; while (*rp && !isdigit(*rp)) rp++;
  8604. + for (;;) {
  8605. + vc= (val == vp) ? 0 : *val++;
  8606. + rc= (ref == rp) ? 0 : *ref++;
  8607. + if (!rc && !vc) break;
  8608. + if (vc && !isalpha(vc)) vc += 256; /* assumes ASCII character set */
  8609. + if (rc && !isalpha(rc)) rc += 256;
  8610. + if (vc != rc) return vc - rc;
  8611. + }
  8612. + val= vp;
  8613. + ref= rp;
  8614. + vl=0; if (isdigit(*vp)) vl= strtol(val,(char**)&val,10);
  8615. + rl=0; if (isdigit(*rp)) rl= strtol(ref,(char**)&ref,10);
  8616. + if (vl != rl) return vl - rl;
  8617. +
  8618. + vc = *val;
  8619. + rc = *ref;
  8620. + vsep = strchr(".-", vc);
  8621. + rsep = strchr(".-", rc);
  8622. + if (vsep && !rsep) return -1;
  8623. + if (!vsep && rsep) return +1;
  8624. +
  8625. + if (!*val && !*ref) return 0;
  8626. + if (!*val) return -1;
  8627. + if (!*ref) return +1;
  8628. + }
  8629. +}
  8630. +
  8631. +int pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op)
  8632. +{
  8633. + int r;
  8634. +
  8635. + r = pkg_compare_versions(it, ref);
  8636. +
  8637. + if (strcmp(op, "<=") == 0 || strcmp(op, "<") == 0) {
  8638. + return r <= 0;
  8639. + }
  8640. +
  8641. + if (strcmp(op, ">=") == 0 || strcmp(op, ">") == 0) {
  8642. + return r >= 0;
  8643. + }
  8644. +
  8645. + if (strcmp(op, "<<") == 0) {
  8646. + return r < 0;
  8647. + }
  8648. +
  8649. + if (strcmp(op, ">>") == 0) {
  8650. + return r > 0;
  8651. + }
  8652. +
  8653. + if (strcmp(op, "=") == 0) {
  8654. + return r == 0;
  8655. + }
  8656. +
  8657. + fprintf(stderr, "unknown operator: %s", op);
  8658. + return 0;
  8659. +}
  8660. +
  8661. +int pkg_name_version_and_architecture_compare(pkg_t *p1, pkg_t *p2)
  8662. +{
  8663. + const pkg_t *a = *(const pkg_t **)p1;
  8664. + const pkg_t *b = *(const pkg_t **)p2;
  8665. + int namecmp;
  8666. + int vercmp;
  8667. + if (!a->name || !b->name) {
  8668. + fprintf(stderr, "pkg_name_version_and_architecture_compare: a=%p a->name=%p b=%p b->name=%p\n",
  8669. + a, a->name, b, b->name);
  8670. + return 0;
  8671. + }
  8672. +
  8673. + namecmp = strcmp(a->name, b->name);
  8674. + if (namecmp)
  8675. + return namecmp;
  8676. + vercmp = pkg_compare_versions(a, b);
  8677. + if (vercmp)
  8678. + return vercmp;
  8679. + if (!a->arch_priority || !b->arch_priority) {
  8680. + fprintf(stderr, "pkg_name_version_and_architecture_compare: a=%p a->arch_priority=%i b=%p b->arch_priority=%i\n",
  8681. + a, a->arch_priority, b, b->arch_priority);
  8682. + return 0;
  8683. + }
  8684. + if (a->arch_priority > b->arch_priority)
  8685. + return 1;
  8686. + if (a->arch_priority < b->arch_priority)
  8687. + return -1;
  8688. + return 0;
  8689. +}
  8690. +
  8691. +int abstract_pkg_name_compare(abstract_pkg_t *p1, abstract_pkg_t *p2)
  8692. +{
  8693. + const abstract_pkg_t *a = *(const abstract_pkg_t **)p1;
  8694. + const abstract_pkg_t *b = *(const abstract_pkg_t **)p2;
  8695. + if (!a->name || !b->name) {
  8696. + fprintf(stderr, "abstract_pkg_name_compare: a=%p a->name=%p b=%p b->name=%p\n",
  8697. + a, a->name, b, b->name);
  8698. + return 0;
  8699. + }
  8700. + return strcmp(a->name, b->name);
  8701. +}
  8702. +
  8703. +
  8704. +char *pkg_version_str_alloc(pkg_t *pkg)
  8705. +{
  8706. + char *complete_version;
  8707. + char *epoch_str;
  8708. +#ifdef USE_DEBVERSION
  8709. + char *revision_str;
  8710. + char *familiar_revision_str;
  8711. +#endif
  8712. +
  8713. + if (pkg->epoch) {
  8714. + sprintf_alloc(&epoch_str, "%lu:", (unsigned long)pkg->epoch);
  8715. + } else {
  8716. + epoch_str = strdup("");
  8717. + }
  8718. +
  8719. +#ifdef USE_DEBVERSION
  8720. + if (pkg->revision && strlen(pkg->revision)) {
  8721. + sprintf_alloc(&revision_str, "-%s", pkg->revision);
  8722. + } else {
  8723. + revision_str = strdup("");
  8724. + }
  8725. +
  8726. + if (pkg->familiar_revision && strlen(pkg->familiar_revision)) {
  8727. + sprintf_alloc(&familiar_revision_str, "-fam%s", pkg->familiar_revision);
  8728. + } else {
  8729. + familiar_revision_str = strdup("");
  8730. + }
  8731. +#endif
  8732. +
  8733. +#ifdef USE_DEBVERSION
  8734. + sprintf_alloc(&complete_version, "%s%s%s%s",
  8735. + epoch_str, pkg->version, revision_str, familiar_revision_str);
  8736. +#else
  8737. + sprintf_alloc(&complete_version, "%s%s",
  8738. + epoch_str, pkg->version);
  8739. +#endif
  8740. +
  8741. + free(epoch_str);
  8742. +#ifdef USE_DEBVERSION
  8743. + free(revision_str);
  8744. + free(familiar_revision_str);
  8745. +#endif
  8746. +
  8747. + return complete_version;
  8748. +}
  8749. +
  8750. +str_list_t *pkg_get_installed_files(pkg_t *pkg)
  8751. +{
  8752. + int err;
  8753. + char *list_file_name = NULL;
  8754. + FILE *list_file = NULL;
  8755. + char *line;
  8756. + char *installed_file_name;
  8757. + int rootdirlen;
  8758. +
  8759. + pkg->installed_files_ref_cnt++;
  8760. +
  8761. + if (pkg->installed_files) {
  8762. + return pkg->installed_files;
  8763. + }
  8764. +
  8765. + pkg->installed_files = str_list_alloc();
  8766. + if (pkg->installed_files == NULL) {
  8767. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8768. + return NULL;
  8769. + }
  8770. +
  8771. + /* For uninstalled packages, get the file list firectly from the package.
  8772. + For installed packages, look at the package.list file in the database.
  8773. + */
  8774. + if (pkg->state_status == SS_NOT_INSTALLED || pkg->dest == NULL) {
  8775. + if (pkg->local_filename == NULL) {
  8776. + return pkg->installed_files;
  8777. + }
  8778. + /* XXX: CLEANUP: Maybe rewrite this to avoid using a temporary
  8779. + file. In other words, change deb_extract so that it can
  8780. + simply return the file list as a char *[] rather than
  8781. + insisting on writing in to a FILE * as it does now. */
  8782. + list_file = tmpfile();
  8783. + err = pkg_extract_data_file_names_to_stream(pkg, list_file);
  8784. + if (err) {
  8785. + fclose(list_file);
  8786. + fprintf(stderr, "%s: Error extracting file list from %s: %s\n",
  8787. + __FUNCTION__, pkg->local_filename, strerror(err));
  8788. + return pkg->installed_files;
  8789. + }
  8790. + rewind(list_file);
  8791. + } else {
  8792. + sprintf_alloc(&list_file_name, "%s/%s.list",
  8793. + pkg->dest->info_dir, pkg->name);
  8794. + if (! file_exists(list_file_name)) {
  8795. + free(list_file_name);
  8796. + return pkg->installed_files;
  8797. + }
  8798. +
  8799. + list_file = fopen(list_file_name, "r");
  8800. + if (list_file == NULL) {
  8801. + fprintf(stderr, "WARNING: Cannot open %s: %s\n",
  8802. + list_file_name, strerror(errno));
  8803. + free(list_file_name);
  8804. + return pkg->installed_files;
  8805. + }
  8806. + free(list_file_name);
  8807. + }
  8808. +
  8809. + rootdirlen = strlen( pkg->dest->root_dir );
  8810. + while (1) {
  8811. + char *file_name;
  8812. +
  8813. + line = file_read_line_alloc(list_file);
  8814. + if (line == NULL) {
  8815. + break;
  8816. + }
  8817. + str_chomp(line);
  8818. + file_name = line;
  8819. +
  8820. + /* Take pains to avoid uglies like "/./" in the middle of file_name. */
  8821. + if( strncmp( pkg->dest->root_dir,
  8822. + file_name,
  8823. + rootdirlen ) ) {
  8824. + if (*file_name == '.') {
  8825. + file_name++;
  8826. + }
  8827. + if (*file_name == '/') {
  8828. + file_name++;
  8829. + }
  8830. +
  8831. + /* Freed in pkg_free_installed_files */
  8832. + sprintf_alloc(&installed_file_name, "%s%s", pkg->dest->root_dir, file_name);
  8833. + } else {
  8834. + // already contains root_dir as header -> ABSOLUTE
  8835. + sprintf_alloc(&installed_file_name, "%s", file_name);
  8836. + }
  8837. + str_list_append(pkg->installed_files, installed_file_name);
  8838. + free(line);
  8839. + }
  8840. +
  8841. + fclose(list_file);
  8842. +
  8843. + return pkg->installed_files;
  8844. +}
  8845. +
  8846. +/* XXX: CLEANUP: This function and it's counterpart,
  8847. + (pkg_get_installed_files), do not match our init/deinit naming
  8848. + convention. Nor the alloc/free convention. But, then again, neither
  8849. + of these conventions currrently fit the way these two functions
  8850. + work. */
  8851. +int pkg_free_installed_files(pkg_t *pkg)
  8852. +{
  8853. + str_list_elt_t *iter;
  8854. +
  8855. + pkg->installed_files_ref_cnt--;
  8856. + if (pkg->installed_files_ref_cnt > 0) {
  8857. + return 0;
  8858. + }
  8859. +
  8860. + if (pkg->installed_files) {
  8861. +
  8862. + for (iter = pkg->installed_files->head; iter; iter = iter->next) {
  8863. + /* malloced in pkg_get_installed_files */
  8864. + free (iter->data);
  8865. + iter->data = NULL;
  8866. + }
  8867. +
  8868. + str_list_deinit(pkg->installed_files);
  8869. + }
  8870. +
  8871. + pkg->installed_files = NULL;
  8872. +
  8873. + return 0;
  8874. +}
  8875. +
  8876. +int pkg_remove_installed_files_list(ipkg_conf_t *conf, pkg_t *pkg)
  8877. +{
  8878. + int err;
  8879. + char *list_file_name;
  8880. +
  8881. + //I don't think pkg_free_installed_files should be called here. Jamey
  8882. + //pkg_free_installed_files(pkg);
  8883. +
  8884. + sprintf_alloc(&list_file_name, "%s/%s.list",
  8885. + pkg->dest->info_dir, pkg->name);
  8886. + if (!conf->noaction) {
  8887. + err = unlink(list_file_name);
  8888. + free(list_file_name);
  8889. +
  8890. + if (err) {
  8891. + return errno;
  8892. + }
  8893. + }
  8894. + return 0;
  8895. +}
  8896. +
  8897. +conffile_t *pkg_get_conffile(pkg_t *pkg, const char *file_name)
  8898. +{
  8899. + conffile_list_elt_t *iter;
  8900. + conffile_t *conffile;
  8901. +
  8902. + if (pkg == NULL) {
  8903. + return NULL;
  8904. + }
  8905. +
  8906. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  8907. + conffile = iter->data;
  8908. +
  8909. + if (strcmp(conffile->name, file_name) == 0) {
  8910. + return conffile;
  8911. + }
  8912. + }
  8913. +
  8914. + return NULL;
  8915. +}
  8916. +
  8917. +int pkg_run_script(ipkg_conf_t *conf, pkg_t *pkg,
  8918. + const char *script, const char *args)
  8919. +{
  8920. + int err;
  8921. + char *path;
  8922. + char *cmd;
  8923. +
  8924. + /* XXX: FEATURE: When conf->offline_root is set, we should run the
  8925. + maintainer script within a chroot environment. */
  8926. +
  8927. + /* Installed packages have scripts in pkg->dest->info_dir, uninstalled packages
  8928. + have scripts in pkg->tmp_unpack_dir. */
  8929. + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) {
  8930. + if (pkg->dest == NULL) {
  8931. + fprintf(stderr, "%s: ERROR: installed package %s has a NULL dest\n",
  8932. + __FUNCTION__, pkg->name);
  8933. + return EINVAL;
  8934. + }
  8935. + sprintf_alloc(&path, "%s/%s.%s", pkg->dest->info_dir, pkg->name, script);
  8936. + } else {
  8937. + if (pkg->tmp_unpack_dir == NULL) {
  8938. + fprintf(stderr, "%s: ERROR: uninstalled package %s has a NULL tmp_unpack_dir\n",
  8939. + __FUNCTION__, pkg->name);
  8940. + return EINVAL;
  8941. + }
  8942. + sprintf_alloc(&path, "%s/%s", pkg->tmp_unpack_dir, script);
  8943. + }
  8944. +
  8945. + ipkg_message(conf, IPKG_INFO, "Running script %s\n", path);
  8946. + if (conf->noaction) return 0;
  8947. +
  8948. + /* XXX: CLEANUP: There must be a better way to handle maintainer
  8949. + scripts when running with offline_root mode and/or a dest other
  8950. + than '/'. I've been playing around with some clever chroot
  8951. + tricks and I might come up with something workable. */
  8952. + if (conf->offline_root) {
  8953. + setenv("IPKG_OFFLINE_ROOT", conf->offline_root, 1);
  8954. + }
  8955. +
  8956. + setenv("PKG_ROOT",
  8957. + pkg->dest ? pkg->dest->root_dir : conf->default_dest->root_dir, 1);
  8958. +
  8959. + if (! file_exists(path)) {
  8960. + free(path);
  8961. + return 0;
  8962. + }
  8963. +
  8964. + if (conf->offline_root) {
  8965. + fprintf(stderr, "(offline root mode: not running %s.%s)\n", pkg->name, script);
  8966. + free(path);
  8967. + return 0;
  8968. + }
  8969. +
  8970. + sprintf_alloc(&cmd, "%s %s", path, args);
  8971. + free(path);
  8972. +
  8973. + err = xsystem(cmd);
  8974. + free(cmd);
  8975. +
  8976. + if (err) {
  8977. + fprintf(stderr, "%s script returned status %d\n", script, err);
  8978. + return err;
  8979. + }
  8980. +
  8981. + return 0;
  8982. +}
  8983. +
  8984. +char *pkg_state_want_to_str(pkg_state_want_t sw)
  8985. +{
  8986. + int i;
  8987. +
  8988. + for (i=0; i < ARRAY_SIZE(pkg_state_want_map); i++) {
  8989. + if (pkg_state_want_map[i].value == sw) {
  8990. + return strdup(pkg_state_want_map[i].str);
  8991. + }
  8992. + }
  8993. +
  8994. + fprintf(stderr, "%s: ERROR: Illegal value for state_want: %d\n",
  8995. + __FUNCTION__, sw);
  8996. + return strdup("<STATE_WANT_UNKNOWN>");
  8997. +}
  8998. +
  8999. +pkg_state_want_t pkg_state_want_from_str(char *str)
  9000. +{
  9001. + int i;
  9002. +
  9003. + for (i=0; i < ARRAY_SIZE(pkg_state_want_map); i++) {
  9004. + if (strcmp(str, pkg_state_want_map[i].str) == 0) {
  9005. + return pkg_state_want_map[i].value;
  9006. + }
  9007. + }
  9008. +
  9009. + fprintf(stderr, "%s: ERROR: Illegal value for state_want string: %s\n",
  9010. + __FUNCTION__, str);
  9011. + return SW_UNKNOWN;
  9012. +}
  9013. +
  9014. +char *pkg_state_flag_to_str(pkg_state_flag_t sf)
  9015. +{
  9016. + int i;
  9017. + int len = 3; /* ok\000 is minimum */
  9018. + char *str = NULL;
  9019. +
  9020. + /* clear the temporary flags before converting to string */
  9021. + sf &= SF_NONVOLATILE_FLAGS;
  9022. +
  9023. + if (sf == 0) {
  9024. + return strdup("ok");
  9025. + } else {
  9026. +
  9027. + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
  9028. + if (sf & pkg_state_flag_map[i].value) {
  9029. + len += strlen(pkg_state_flag_map[i].str) + 1;
  9030. + }
  9031. + }
  9032. + str = malloc(len);
  9033. + if ( str == NULL ) {
  9034. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  9035. + return NULL;
  9036. + }
  9037. + str[0] = 0;
  9038. + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
  9039. + if (sf & pkg_state_flag_map[i].value) {
  9040. + strcat(str, pkg_state_flag_map[i].str);
  9041. + strcat(str, ",");
  9042. + }
  9043. + }
  9044. + len = strlen(str);
  9045. + str[len-1] = 0; /* squash last comma */
  9046. + return str;
  9047. + }
  9048. +}
  9049. +
  9050. +pkg_state_flag_t pkg_state_flag_from_str(char *str)
  9051. +{
  9052. + int i;
  9053. + int sf = SF_OK;
  9054. +
  9055. + if (strcmp(str, "ok") == 0) {
  9056. + return SF_OK;
  9057. + }
  9058. + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
  9059. + const char *sfname = pkg_state_flag_map[i].str;
  9060. + int sfname_len = strlen(sfname);
  9061. + if (strncmp(str, sfname, sfname_len) == 0) {
  9062. + sf |= pkg_state_flag_map[i].value;
  9063. + str += sfname_len;
  9064. + if (str[0] == ',') {
  9065. + str++;
  9066. + } else {
  9067. + break;
  9068. + }
  9069. + }
  9070. + }
  9071. +
  9072. + return sf;
  9073. +}
  9074. +
  9075. +char *pkg_state_status_to_str(pkg_state_status_t ss)
  9076. +{
  9077. + int i;
  9078. +
  9079. + for (i=0; i < ARRAY_SIZE(pkg_state_status_map); i++) {
  9080. + if (pkg_state_status_map[i].value == ss) {
  9081. + return strdup(pkg_state_status_map[i].str);
  9082. + }
  9083. + }
  9084. +
  9085. + fprintf(stderr, "%s: ERROR: Illegal value for state_status: %d\n",
  9086. + __FUNCTION__, ss);
  9087. + return strdup("<STATE_STATUS_UNKNOWN>");
  9088. +}
  9089. +
  9090. +pkg_state_status_t pkg_state_status_from_str(char *str)
  9091. +{
  9092. + int i;
  9093. +
  9094. + for (i=0; i < ARRAY_SIZE(pkg_state_status_map); i++) {
  9095. + if (strcmp(str, pkg_state_status_map[i].str) == 0) {
  9096. + return pkg_state_status_map[i].value;
  9097. + }
  9098. + }
  9099. +
  9100. + fprintf(stderr, "%s: ERROR: Illegal value for state_status string: %s\n",
  9101. + __FUNCTION__, str);
  9102. + return SS_NOT_INSTALLED;
  9103. +}
  9104. +
  9105. +int pkg_arch_supported(ipkg_conf_t *conf, pkg_t *pkg)
  9106. +{
  9107. + nv_pair_list_elt_t *l;
  9108. +
  9109. + if (!pkg->architecture)
  9110. + return 1;
  9111. +
  9112. + l = conf->arch_list.head;
  9113. +
  9114. + while (l) {
  9115. + nv_pair_t *nv = l->data;
  9116. + if (strcmp(nv->name, pkg->architecture) == 0) {
  9117. + ipkg_message(conf, IPKG_DEBUG, "arch %s (priority %s) supported for pkg %s\n", nv->name, nv->value, pkg->name);
  9118. + return 1;
  9119. + }
  9120. + l = l->next;
  9121. + }
  9122. +
  9123. + ipkg_message(conf, IPKG_DEBUG, "arch %s unsupported for pkg %s\n", pkg->architecture, pkg->name);
  9124. + return 0;
  9125. +}
  9126. +
  9127. +int pkg_get_arch_priority(ipkg_conf_t *conf, const char *archname)
  9128. +{
  9129. + nv_pair_list_elt_t *l;
  9130. +
  9131. + l = conf->arch_list.head;
  9132. +
  9133. + while (l) {
  9134. + nv_pair_t *nv = l->data;
  9135. + if (strcmp(nv->name, archname) == 0) {
  9136. + int priority = strtol(nv->value, NULL, 0);
  9137. + return priority;
  9138. + }
  9139. + l = l->next;
  9140. + }
  9141. + return 0;
  9142. +}
  9143. +
  9144. +int pkg_info_preinstall_check(ipkg_conf_t *conf)
  9145. +{
  9146. + int i;
  9147. + hash_table_t *pkg_hash = &conf->pkg_hash;
  9148. + pkg_vec_t *available_pkgs = pkg_vec_alloc();
  9149. + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
  9150. +
  9151. + ipkg_message(conf, IPKG_INFO, "pkg_info_preinstall_check: updating arch priority for each package\n");
  9152. + pkg_hash_fetch_available(pkg_hash, available_pkgs);
  9153. + /* update arch_priority for each package */
  9154. + for (i = 0; i < available_pkgs->len; i++) {
  9155. + pkg_t *pkg = available_pkgs->pkgs[i];
  9156. + int arch_priority = 1;
  9157. + if (!pkg)
  9158. + continue;
  9159. + // ipkg_message(conf, IPKG_DEBUG2, " package %s version=%s arch=%p:", pkg->name, pkg->version, pkg->architecture);
  9160. + if (pkg->architecture)
  9161. + arch_priority = pkg_get_arch_priority(conf, pkg->architecture);
  9162. + else
  9163. + ipkg_message(conf, IPKG_ERROR, "pkg_info_preinstall_check: no architecture for package %s\n", pkg->name);
  9164. + // ipkg_message(conf, IPKG_DEBUG2, "%s arch_priority=%d\n", pkg->architecture, arch_priority);
  9165. + pkg->arch_priority = arch_priority;
  9166. + }
  9167. +
  9168. + for (i = 0; i < available_pkgs->len; i++) {
  9169. + pkg_t *pkg = available_pkgs->pkgs[i];
  9170. + if (!pkg->arch_priority && (pkg->state_flag || (pkg->state_want != SW_UNKNOWN))) {
  9171. + /* clear flags and want for any uninstallable package */
  9172. + ipkg_message(conf, IPKG_NOTICE, "Clearing state_want and state_flag for pkg=%s (arch_priority=%d flag=%d want=%d)\n",
  9173. + pkg->name, pkg->arch_priority, pkg->state_flag, pkg->state_want);
  9174. + pkg->state_want = SW_UNKNOWN;
  9175. + pkg->state_flag = 0;
  9176. + }
  9177. + }
  9178. + pkg_vec_free(available_pkgs);
  9179. +
  9180. + /* update the file owner data structure */
  9181. + ipkg_message(conf, IPKG_INFO, "pkg_info_preinstall_check: update file owner list\n");
  9182. + pkg_hash_fetch_all_installed(pkg_hash, installed_pkgs);
  9183. + for (i = 0; i < installed_pkgs->len; i++) {
  9184. + pkg_t *pkg = installed_pkgs->pkgs[i];
  9185. + str_list_t *installed_files = pkg_get_installed_files(pkg); /* this causes installed_files to be cached */
  9186. + str_list_elt_t *iter;
  9187. + if (installed_files == NULL) {
  9188. + ipkg_message(conf, IPKG_ERROR, "No installed files for pkg %s\n", pkg->name);
  9189. + break;
  9190. + }
  9191. + for (iter = installed_files->head; iter; iter = iter->next) {
  9192. + char *installed_file = iter->data;
  9193. + // ipkg_message(conf, IPKG_DEBUG2, "pkg %s: file=%s\n", pkg->name, installed_file);
  9194. + file_hash_set_file_owner(conf, installed_file, pkg);
  9195. + }
  9196. + }
  9197. + pkg_vec_free(installed_pkgs);
  9198. +
  9199. + return 0;
  9200. +}
  9201. +
  9202. +struct pkg_write_filelist_data {
  9203. + ipkg_conf_t *conf;
  9204. + pkg_t *pkg;
  9205. + FILE *stream;
  9206. +};
  9207. +
  9208. +void pkg_write_filelist_helper(const char *key, void *entry_, void *data_)
  9209. +{
  9210. + struct pkg_write_filelist_data *data = data_;
  9211. + pkg_t *entry = entry_;
  9212. + if (entry == data->pkg) {
  9213. + fprintf(data->stream, "%s\n", key);
  9214. + }
  9215. +}
  9216. +
  9217. +int pkg_write_filelist(ipkg_conf_t *conf, pkg_t *pkg)
  9218. +{
  9219. + struct pkg_write_filelist_data data;
  9220. + char *list_file_name = NULL;
  9221. + int err = 0;
  9222. +
  9223. + if (!pkg) {
  9224. + ipkg_message(conf, IPKG_ERROR, "Null pkg\n");
  9225. + return -EINVAL;
  9226. + }
  9227. + ipkg_message(conf, IPKG_INFO,
  9228. + " creating %s.list file\n", pkg->name);
  9229. + sprintf_alloc(&list_file_name, "%s/%s.list", pkg->dest->info_dir, pkg->name);
  9230. + if (!list_file_name) {
  9231. + ipkg_message(conf, IPKG_ERROR, "Failed to alloc list_file_name\n");
  9232. + return -ENOMEM;
  9233. + }
  9234. + ipkg_message(conf, IPKG_INFO,
  9235. + " creating %s file for pkg %s\n", list_file_name, pkg->name);
  9236. + data.stream = fopen(list_file_name, "w");
  9237. + if (!data.stream) {
  9238. + ipkg_message(conf, IPKG_ERROR, "Could not open %s for writing: %s\n",
  9239. + list_file_name, strerror(errno));
  9240. + return errno;
  9241. + }
  9242. + data.pkg = pkg;
  9243. + data.conf = conf;
  9244. + hash_table_foreach(&conf->file_hash, pkg_write_filelist_helper, &data);
  9245. + fclose(data.stream);
  9246. + free(list_file_name);
  9247. +
  9248. + return err;
  9249. +}
  9250. +
  9251. +int pkg_write_changed_filelists(ipkg_conf_t *conf)
  9252. +{
  9253. + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
  9254. + hash_table_t *pkg_hash = &conf->pkg_hash;
  9255. + int i;
  9256. + int err;
  9257. + if (conf->noaction)
  9258. + return 0;
  9259. +
  9260. + ipkg_message(conf, IPKG_INFO, "%s: saving changed filelists\n", __FUNCTION__);
  9261. + pkg_hash_fetch_all_installed(pkg_hash, installed_pkgs);
  9262. + for (i = 0; i < installed_pkgs->len; i++) {
  9263. + pkg_t *pkg = installed_pkgs->pkgs[i];
  9264. + if (pkg->state_flag & SF_FILELIST_CHANGED) {
  9265. + ipkg_message(conf, IPKG_DEBUG, "Calling pkg_write_filelist for pkg=%s from %s\n", pkg->name, __FUNCTION__);
  9266. + err = pkg_write_filelist(conf, pkg);
  9267. + if (err)
  9268. + ipkg_message(conf, IPKG_NOTICE, "pkg_write_filelist pkg=%s returned %d\n", pkg->name, err);
  9269. + }
  9270. + }
  9271. + return 0;
  9272. +}
  9273. diff -Nur busybox-1.16.1.orig/archival/libipkg/pkg_depends.c busybox-1.16.1/archival/libipkg/pkg_depends.c
  9274. --- busybox-1.16.1.orig/archival/libipkg/pkg_depends.c 1970-01-01 01:00:00.000000000 +0100
  9275. +++ busybox-1.16.1/archival/libipkg/pkg_depends.c 2010-06-29 17:31:24.548368104 +0200
  9276. @@ -0,0 +1,1032 @@
  9277. +/* pkg_depends.c - the itsy package management system
  9278. +
  9279. + Steven M. Ayer
  9280. +
  9281. + Copyright (C) 2002 Compaq Computer Corporation
  9282. +
  9283. + This program is free software; you can redistribute it and/or
  9284. + modify it under the terms of the GNU General Public License as
  9285. + published by the Free Software Foundation; either version 2, or (at
  9286. + your option) any later version.
  9287. +
  9288. + This program is distributed in the hope that it will be useful, but
  9289. + WITHOUT ANY WARRANTY; without even the implied warranty of
  9290. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  9291. + General Public License for more details.
  9292. +*/
  9293. +
  9294. +#include "ipkg.h"
  9295. +#include <errno.h>
  9296. +#include <ctype.h>
  9297. +
  9298. +#include "pkg.h"
  9299. +#include "ipkg_utils.h"
  9300. +#include "pkg_hash.h"
  9301. +#include "ipkg_message.h"
  9302. +#include "pkg_parse.h"
  9303. +#include "hash_table.h"
  9304. +
  9305. +static int parseDepends(compound_depend_t *compound_depend, hash_table_t * hash, char * depend_str);
  9306. +static depend_t * depend_init(void);
  9307. +static void depend_deinit(depend_t *d);
  9308. +static char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx);
  9309. +static char ** merge_unresolved(char ** oldstuff, char ** newstuff);
  9310. +static int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg);
  9311. +int is_pkg_a_replaces(pkg_t *pkg_scout,pkg_t *pkg);
  9312. +
  9313. +static int pkg_installed_and_constraint_satisfied(pkg_t *pkg, void *cdata)
  9314. +{
  9315. + depend_t *depend = (depend_t *)cdata;
  9316. + if ((pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) && version_constraints_satisfied(depend, pkg))
  9317. + return 1;
  9318. + else
  9319. + return 0;
  9320. +}
  9321. +
  9322. +static int pkg_constraint_satisfied(pkg_t *pkg, void *cdata)
  9323. +{
  9324. + depend_t *depend = (depend_t *)cdata;
  9325. +#if 0
  9326. + pkg_t * temp = pkg_new();
  9327. + int comparison;
  9328. + parseVersion(temp, depend->version);
  9329. + comparison = pkg_compare_versions(pkg, temp);
  9330. + free(temp);
  9331. +
  9332. + fprintf(stderr, "%s: pkg=%s pkg->version=%s constraint=%p type=%d version=%s comparison=%d satisfied=%d\n",
  9333. + __FUNCTION__, pkg->name, pkg->version,
  9334. + depend, depend->constraint, depend->version,
  9335. + comparison, version_constraints_satisfied(depend, pkg));
  9336. +#endif
  9337. + if (version_constraints_satisfied(depend, pkg))
  9338. + return 1;
  9339. + else
  9340. + return 0;
  9341. +}
  9342. +
  9343. +/* returns ndependences or negative error value */
  9344. +int pkg_hash_fetch_unsatisfied_dependencies(ipkg_conf_t *conf, pkg_t * pkg,
  9345. + pkg_vec_t *unsatisfied, char *** unresolved)
  9346. +{
  9347. + pkg_t * satisfier_entry_pkg;
  9348. + register int i, j, k, l;
  9349. + int count, found;
  9350. + char ** the_lost;
  9351. + abstract_pkg_t * ab_pkg;
  9352. +
  9353. + /*
  9354. + * this is a setup to check for redundant/cyclic dependency checks,
  9355. + * which are marked at the abstract_pkg level
  9356. + */
  9357. + if (!(ab_pkg = pkg->parent)) {
  9358. + fprintf(stderr, "%s:%d: something terribly wrong with pkg %s\n", __FUNCTION__, __LINE__, pkg->name);
  9359. + *unresolved = NULL;
  9360. + return 0;
  9361. + }
  9362. + if (ab_pkg->dependencies_checked) { /* avoid duplicate or cyclic checks */
  9363. + *unresolved = NULL;
  9364. + return 0;
  9365. + } else {
  9366. + ab_pkg->dependencies_checked = 1; /* mark it for subsequent visits */
  9367. + }
  9368. + /**/
  9369. +
  9370. + count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count;
  9371. + if (!count){
  9372. + *unresolved = NULL;
  9373. + return 0;
  9374. + }
  9375. +
  9376. + the_lost = NULL;
  9377. +
  9378. + /* foreach dependency */
  9379. + for (i = 0; i < count; i++) {
  9380. + compound_depend_t * compound_depend = &pkg->depends[i];
  9381. + depend_t ** possible_satisfiers = compound_depend->possibilities;;
  9382. + found = 0;
  9383. + satisfier_entry_pkg = NULL;
  9384. +
  9385. + if (compound_depend->type == GREEDY_DEPEND) {
  9386. + /* foreach possible satisfier */
  9387. + for (j = 0; j < compound_depend->possibility_count; j++) {
  9388. + /* foreach provided_by, which includes the abstract_pkg itself */
  9389. + abstract_pkg_t *abpkg = possible_satisfiers[j]->pkg;
  9390. + abstract_pkg_vec_t *ab_provider_vec = abpkg->provided_by;
  9391. + int nposs = ab_provider_vec->len;
  9392. + abstract_pkg_t **ab_providers = ab_provider_vec->pkgs;
  9393. + for (l = 0; l < nposs; l++) {
  9394. + pkg_vec_t *test_vec = ab_providers[l]->pkgs;
  9395. + /* if no depends on this one, try the first package that Provides this one */
  9396. + if (!test_vec){ /* no pkg_vec hooked up to the abstract_pkg! (need another feed?) */
  9397. + continue;
  9398. + }
  9399. +
  9400. + /* cruise this possiblity's pkg_vec looking for an installed version */
  9401. + for (k = 0; k < test_vec->len; k++) {
  9402. + pkg_t *pkg_scout = test_vec->pkgs[k];
  9403. + /* not installed, and not already known about? */
  9404. + if ((pkg_scout->state_want != SW_INSTALL)
  9405. + && !pkg_scout->parent->dependencies_checked
  9406. + && !is_pkg_in_pkg_vec(unsatisfied, pkg_scout)) {
  9407. + char ** newstuff = NULL;
  9408. + int rc;
  9409. + pkg_vec_t *tmp_vec = pkg_vec_alloc ();
  9410. + /* check for not-already-installed dependencies */
  9411. + rc = pkg_hash_fetch_unsatisfied_dependencies(conf,
  9412. + pkg_scout,
  9413. + tmp_vec,
  9414. + &newstuff);
  9415. + if (newstuff == NULL) {
  9416. + int ok = 1;
  9417. + for (i = 0; i < rc; i++) {
  9418. + pkg_t *p = tmp_vec->pkgs[i];
  9419. + if (p->state_want == SW_INSTALL)
  9420. + continue;
  9421. + ipkg_message(conf, IPKG_DEBUG, "not installing %s due to requirement for %s\n", pkg_scout->name, p->name);
  9422. + ok = 0;
  9423. + break;
  9424. + }
  9425. + pkg_vec_free (tmp_vec);
  9426. + if (ok) {
  9427. + /* mark this one for installation */
  9428. + ipkg_message(conf, IPKG_NOTICE, "Adding satisfier for greedy dependence: %s\n", pkg_scout->name);
  9429. + pkg_vec_insert(unsatisfied, pkg_scout);
  9430. + }
  9431. + } else {
  9432. + ipkg_message(conf, IPKG_DEBUG, "not installing %s due to broken depends \n", pkg_scout->name);
  9433. + free (newstuff);
  9434. + }
  9435. + }
  9436. + }
  9437. + }
  9438. + }
  9439. +
  9440. + continue;
  9441. + }
  9442. +
  9443. + /* foreach possible satisfier, look for installed package */
  9444. + for (j = 0; j < compound_depend->possibility_count; j++) {
  9445. + /* foreach provided_by, which includes the abstract_pkg itself */
  9446. + depend_t *dependence_to_satisfy = possible_satisfiers[j];
  9447. + abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg;
  9448. + pkg_t *satisfying_pkg =
  9449. + pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg,
  9450. + pkg_installed_and_constraint_satisfied,
  9451. + dependence_to_satisfy, 1);
  9452. + /* Being that I can't test constraing in pkg_hash, I will test it here */
  9453. + if (satisfying_pkg != NULL) {
  9454. + if (!pkg_installed_and_constraint_satisfied ( satisfying_pkg,dependence_to_satisfy)) {
  9455. + satisfying_pkg = NULL;
  9456. + }
  9457. + }
  9458. + ipkg_message(conf, IPKG_DEBUG, "%s:%d: satisfying_pkg=%p \n", __FILE__, __LINE__, satisfying_pkg);
  9459. + if (satisfying_pkg != NULL) {
  9460. + found = 1;
  9461. + break;
  9462. + }
  9463. +
  9464. + }
  9465. + /* if nothing installed matches, then look for uninstalled satisfier */
  9466. + if (!found) {
  9467. + /* foreach possible satisfier, look for installed package */
  9468. + for (j = 0; j < compound_depend->possibility_count; j++) {
  9469. + /* foreach provided_by, which includes the abstract_pkg itself */
  9470. + depend_t *dependence_to_satisfy = possible_satisfiers[j];
  9471. + abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg;
  9472. + pkg_t *satisfying_pkg =
  9473. + pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg,
  9474. + pkg_constraint_satisfied,
  9475. + dependence_to_satisfy, 1);
  9476. + /* Being that I can't test constraing in pkg_hash, I will test it here too */
  9477. + if (satisfying_pkg != NULL) {
  9478. + if (!pkg_constraint_satisfied ( satisfying_pkg,dependence_to_satisfy)) {
  9479. + satisfying_pkg = NULL;
  9480. + }
  9481. + }
  9482. +
  9483. + /* user request overrides package recommendation */
  9484. + if (satisfying_pkg != NULL
  9485. + && (compound_depend->type == RECOMMEND || compound_depend->type == SUGGEST)
  9486. + && (satisfying_pkg->state_want == SW_DEINSTALL || satisfying_pkg->state_want == SW_PURGE)) {
  9487. + ipkg_message (conf, IPKG_NOTICE, "%s: ignoring recommendation for %s at user request\n",
  9488. + pkg->name, satisfying_pkg->name);
  9489. + continue;
  9490. + }
  9491. +
  9492. + ipkg_message(conf, IPKG_DEBUG, "%s:%d: satisfying_pkg=%p\n", __FILE__, __LINE__, satisfying_pkg);
  9493. + if (satisfying_pkg != NULL) {
  9494. + satisfier_entry_pkg = satisfying_pkg;
  9495. + break;
  9496. + }
  9497. + }
  9498. + }
  9499. +
  9500. + /* we didn't find one, add something to the unsatisfied vector */
  9501. + if (!found) {
  9502. + if (!satisfier_entry_pkg) {
  9503. + /* failure to meet recommendations is not an error */
  9504. + if (compound_depend->type != RECOMMEND && compound_depend->type != SUGGEST)
  9505. + the_lost = add_unresolved_dep(pkg, the_lost, i);
  9506. + else
  9507. + ipkg_message (conf, IPKG_NOTICE, "%s: unsatisfied recommendation for %s\n",
  9508. + pkg->name, compound_depend->possibilities[0]->pkg->name);
  9509. + }
  9510. + else {
  9511. + if (compound_depend->type == SUGGEST) {
  9512. + /* just mention it politely */
  9513. + ipkg_message (conf, IPKG_NOTICE, "package %s suggests installing %s\n",
  9514. + pkg->name, satisfier_entry_pkg->name);
  9515. + } else {
  9516. + char ** newstuff = NULL;
  9517. +
  9518. + if (satisfier_entry_pkg != pkg &&
  9519. + !is_pkg_in_pkg_vec(unsatisfied, satisfier_entry_pkg)) {
  9520. + pkg_vec_insert(unsatisfied, satisfier_entry_pkg);
  9521. + pkg_hash_fetch_unsatisfied_dependencies(conf,
  9522. + satisfier_entry_pkg,
  9523. + unsatisfied,
  9524. + &newstuff);
  9525. + the_lost = merge_unresolved(the_lost, newstuff);
  9526. + }
  9527. + }
  9528. + }
  9529. + }
  9530. + }
  9531. + *unresolved = the_lost;
  9532. +
  9533. + return unsatisfied->len;
  9534. +}
  9535. +
  9536. +/*checking for conflicts !in replaces
  9537. + If a packages conflicts with another but is also replacing it, I should not consider it a
  9538. + really conflicts
  9539. + returns 0 if conflicts <> replaces or 1 if conflicts == replaces
  9540. +*/
  9541. +int is_pkg_a_replaces(pkg_t *pkg_scout,pkg_t *pkg)
  9542. +{
  9543. + int i ;
  9544. + int replaces_count = pkg->replaces_count;
  9545. + abstract_pkg_t **replaces;
  9546. +
  9547. + if (pkg->replaces_count==0) // No replaces, it's surely a conflict
  9548. + return 0;
  9549. +
  9550. + replaces = pkg->replaces;
  9551. +
  9552. + for (i = 0; i < replaces_count; i++) {
  9553. + if (strcmp(pkg_scout->name,pkg->replaces[i]->name)==0) { // Found
  9554. + ipkg_message(NULL, IPKG_DEBUG2, "Seems I've found a replace %s %s \n",pkg_scout->name,pkg->replaces[i]->name);
  9555. + return 1;
  9556. + }
  9557. + }
  9558. + return 0;
  9559. +
  9560. +}
  9561. +
  9562. +
  9563. +/* Abhaya: added support for conflicts */
  9564. +pkg_vec_t * pkg_hash_fetch_conflicts(pkg_t * pkg)
  9565. +{
  9566. + pkg_vec_t * installed_conflicts, * test_vec;
  9567. + compound_depend_t * conflicts;
  9568. + depend_t ** possible_satisfiers;
  9569. + depend_t * possible_satisfier;
  9570. + register int i, j, k;
  9571. + int count;
  9572. + abstract_pkg_t * ab_pkg;
  9573. + pkg_t **pkg_scouts;
  9574. + pkg_t *pkg_scout;
  9575. +
  9576. + /*
  9577. + * this is a setup to check for redundant/cyclic dependency checks,
  9578. + * which are marked at the abstract_pkg level
  9579. + */
  9580. + if(!(ab_pkg = pkg->parent)){
  9581. + fprintf(stderr, "dependency check error. pkg %s isn't in hash table\n", pkg->name);
  9582. + return (pkg_vec_t *)NULL;
  9583. + }
  9584. +
  9585. + conflicts = pkg->conflicts;
  9586. + if(!conflicts){
  9587. + return (pkg_vec_t *)NULL;
  9588. + }
  9589. + installed_conflicts = pkg_vec_alloc();
  9590. +
  9591. + count = pkg->conflicts_count;
  9592. +
  9593. +
  9594. +
  9595. + /* foreach conflict */
  9596. + for(i = 0; i < pkg->conflicts_count; i++){
  9597. +
  9598. + possible_satisfiers = conflicts->possibilities;
  9599. +
  9600. + /* foreach possible satisfier */
  9601. + for(j = 0; j < conflicts->possibility_count; j++){
  9602. + possible_satisfier = possible_satisfiers[j];
  9603. + if (!possible_satisfier)
  9604. + fprintf(stderr, "%s:%d: possible_satisfier is null\n", __FUNCTION__, __LINE__);
  9605. + if (!possible_satisfier->pkg)
  9606. + fprintf(stderr, "%s:%d: possible_satisfier->pkg is null\n", __FUNCTION__, __LINE__);
  9607. + test_vec = possible_satisfier->pkg->pkgs;
  9608. + if (test_vec) {
  9609. + /* pkg_vec found, it is an actual package conflict
  9610. + * cruise this possiblity's pkg_vec looking for an installed version */
  9611. + pkg_scouts = test_vec->pkgs;
  9612. + for(k = 0; k < test_vec->len; k++){
  9613. + pkg_scout = pkg_scouts[k];
  9614. + if (!pkg_scout) {
  9615. + fprintf(stderr, "%s: null pkg scout\n", __FUNCTION__);
  9616. + continue;
  9617. + }
  9618. + if ((pkg_scout->state_status == SS_INSTALLED || pkg_scout->state_want == SW_INSTALL) &&
  9619. + version_constraints_satisfied(possible_satisfier, pkg_scout) && !is_pkg_a_replaces(pkg_scout,pkg)){
  9620. + if (!is_pkg_in_pkg_vec(installed_conflicts, pkg_scout)){
  9621. + pkg_vec_insert(installed_conflicts, pkg_scout);
  9622. + }
  9623. + }
  9624. + }
  9625. + }
  9626. + }
  9627. + conflicts++;
  9628. + }
  9629. +
  9630. + if (installed_conflicts->len)
  9631. + return installed_conflicts;
  9632. + pkg_vec_free(installed_conflicts);
  9633. + return (pkg_vec_t *)NULL;
  9634. +}
  9635. +
  9636. +int version_constraints_satisfied(depend_t * depends, pkg_t * pkg)
  9637. +{
  9638. + pkg_t * temp;
  9639. + int comparison;
  9640. +
  9641. + if(depends->constraint == NONE)
  9642. + return 1;
  9643. +
  9644. + temp = pkg_new();
  9645. +
  9646. + parseVersion(temp, depends->version);
  9647. +
  9648. + comparison = pkg_compare_versions(pkg, temp);
  9649. +
  9650. + free(temp);
  9651. +
  9652. + if((depends->constraint == EARLIER) &&
  9653. + (comparison < 0))
  9654. + return 1;
  9655. + else if((depends->constraint == LATER) &&
  9656. + (comparison > 0))
  9657. + return 1;
  9658. + else if(comparison == 0)
  9659. + return 1;
  9660. + else if((depends->constraint == LATER_EQUAL) &&
  9661. + (comparison >= 0))
  9662. + return 1;
  9663. + else if((depends->constraint == EARLIER_EQUAL) &&
  9664. + (comparison <= 0))
  9665. + return 1;
  9666. +
  9667. + return 0;
  9668. +}
  9669. +
  9670. +int pkg_dependence_satisfiable(depend_t *depend)
  9671. +{
  9672. + abstract_pkg_t *apkg = depend->pkg;
  9673. + abstract_pkg_vec_t *provider_apkgs = apkg->provided_by;
  9674. + int n_providers = provider_apkgs->len;
  9675. + abstract_pkg_t **apkgs = provider_apkgs->pkgs;
  9676. + pkg_vec_t *pkg_vec;
  9677. + int n_pkgs ;
  9678. + int i;
  9679. + int j;
  9680. +
  9681. + for (i = 0; i < n_providers; i++) {
  9682. + abstract_pkg_t *papkg = apkgs[i];
  9683. + pkg_vec = papkg->pkgs;
  9684. + if (pkg_vec) {
  9685. + n_pkgs = pkg_vec->len;
  9686. + for (j = 0; j < n_pkgs; j++) {
  9687. + pkg_t *pkg = pkg_vec->pkgs[j];
  9688. + if (version_constraints_satisfied(depend, pkg)) {
  9689. + return 1;
  9690. + }
  9691. + }
  9692. + }
  9693. + }
  9694. + return 0;
  9695. +}
  9696. +
  9697. +int pkg_dependence_satisfied(depend_t *depend)
  9698. +{
  9699. + abstract_pkg_t *apkg = depend->pkg;
  9700. + abstract_pkg_vec_t *provider_apkgs = apkg->provided_by;
  9701. + int n_providers = provider_apkgs->len;
  9702. + abstract_pkg_t **apkgs = provider_apkgs->pkgs;
  9703. + int i;
  9704. + int n_pkgs;
  9705. + int j;
  9706. +
  9707. + for (i = 0; i < n_providers; i++) {
  9708. + abstract_pkg_t *papkg = apkgs[i];
  9709. + pkg_vec_t *pkg_vec = papkg->pkgs;
  9710. + if (pkg_vec) {
  9711. + n_pkgs = pkg_vec->len;
  9712. + for (j = 0; j < n_pkgs; j++) {
  9713. + pkg_t *pkg = pkg_vec->pkgs[j];
  9714. + if (version_constraints_satisfied(depend, pkg)) {
  9715. + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED)
  9716. + return 1;
  9717. + }
  9718. + }
  9719. + }
  9720. + }
  9721. + return 0;
  9722. +}
  9723. +
  9724. +static int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg)
  9725. +{
  9726. + register int i;
  9727. + pkg_t ** pkgs = vec->pkgs;
  9728. +
  9729. + for(i = 0; i < vec->len; i++)
  9730. + if((strcmp(pkg->name, (*(pkgs + i))->name) == 0)
  9731. + && (pkg_compare_versions(pkg, *(pkgs + i)) == 0)
  9732. + && (strcmp(pkg->architecture, (*(pkgs + i))->architecture) == 0))
  9733. + return 1;
  9734. + return 0;
  9735. +}
  9736. +
  9737. +
  9738. +#ifdef DeadCode
  9739. +/**
  9740. + * pkg_has_common_provides returns 1 if pkg and replacee both provide
  9741. + * the same abstract package and 0 otherwise.
  9742. + */
  9743. +int pkg_has_common_provides(pkg_t *pkg, pkg_t *replacee)
  9744. +{
  9745. + abstract_pkg_t **provides = pkg->provides;
  9746. + int provides_count = pkg->provides_count;
  9747. + abstract_pkg_t **replacee_provides = replacee->provides;
  9748. + int replacee_provides_count = replacee->provides_count;
  9749. + int i, j;
  9750. + for (i = 0; i < provides_count; i++) {
  9751. + abstract_pkg_t *apkg = provides[i];
  9752. + for (j = 0; j < replacee_provides_count; j++) {
  9753. + abstract_pkg_t *replacee_apkg = replacee_provides[i];
  9754. + if (apkg == replacee_apkg)
  9755. + return 1;
  9756. + }
  9757. + }
  9758. + return 0;
  9759. +}
  9760. +#endif
  9761. +
  9762. +/**
  9763. + * pkg_provides_abstract returns 1 if pkg->provides contains providee
  9764. + * and 0 otherwise.
  9765. + */
  9766. +int pkg_provides_abstract(pkg_t *pkg, abstract_pkg_t *providee)
  9767. +{
  9768. + abstract_pkg_t **provides = pkg->provides;
  9769. + int provides_count = pkg->provides_count;
  9770. + int i;
  9771. + for (i = 0; i < provides_count; i++) {
  9772. + if (provides[i] == providee)
  9773. + return 1;
  9774. + }
  9775. + return 0;
  9776. +}
  9777. +
  9778. +/**
  9779. + * pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0
  9780. + * otherwise.
  9781. + */
  9782. +int pkg_replaces(pkg_t *pkg, pkg_t *replacee)
  9783. +{
  9784. + abstract_pkg_t **replaces = pkg->replaces;
  9785. + int replaces_count = pkg->replaces_count;
  9786. + /* abstract_pkg_t **replacee_provides = pkg->provides;
  9787. + int replacee_provides_count = pkg->provides_count; */
  9788. + int i, j;
  9789. + for (i = 0; i < replaces_count; i++) {
  9790. + abstract_pkg_t *abstract_replacee = replaces[i];
  9791. + for (j = 0; j < replaces_count; j++) {
  9792. + /* ipkg_message(NULL, IPKG_DEBUG2, "Searching pkg-name %s repprovname %s absrepname %s \n",
  9793. + pkg->name,replacee->provides[j]->name, abstract_replacee->name); */
  9794. + if (replacee->provides[j] == abstract_replacee)
  9795. + return 1;
  9796. + }
  9797. + }
  9798. + return 0;
  9799. +}
  9800. +
  9801. +
  9802. +/**
  9803. + * pkg_conflicts_abstract returns 1 if pkg->conflicts contains conflictee and 0
  9804. + * otherwise.
  9805. + */
  9806. +int pkg_conflicts_abstract(pkg_t *pkg, abstract_pkg_t *conflictee)
  9807. +{
  9808. + compound_depend_t *conflicts = pkg->conflicts;
  9809. + int conflicts_count = pkg->conflicts_count;
  9810. + int i, j;
  9811. + for (i = 0; i < conflicts_count; i++) {
  9812. + int possibility_count = conflicts[i].possibility_count;
  9813. + struct depend **possibilities = conflicts[i].possibilities;
  9814. + for (j = 0; j < possibility_count; j++) {
  9815. + if (possibilities[j]->pkg == conflictee) {
  9816. + return 1;
  9817. + }
  9818. + }
  9819. + }
  9820. + return 0;
  9821. +}
  9822. +
  9823. +/**
  9824. + * pkg_conflicts returns 1 if pkg->conflicts contains one of
  9825. + * conflictee's provides and 0 otherwise.
  9826. + */
  9827. +int pkg_conflicts(pkg_t *pkg, pkg_t *conflictee)
  9828. +{
  9829. + compound_depend_t *conflicts = pkg->conflicts;
  9830. + int conflicts_count = pkg->conflicts_count;
  9831. + abstract_pkg_t **conflictee_provides = conflictee->provides;
  9832. + int conflictee_provides_count = conflictee->provides_count;
  9833. + int i, j, k;
  9834. + int possibility_count;
  9835. + struct depend **possibilities;
  9836. + abstract_pkg_t *possibility ;
  9837. +
  9838. + for (i = 0; i < conflicts_count; i++) {
  9839. + possibility_count = conflicts[i].possibility_count;
  9840. + possibilities = conflicts[i].possibilities;
  9841. + for (j = 0; j < possibility_count; j++) {
  9842. + possibility = possibilities[j]->pkg;
  9843. + for (k = 0; k < conflictee_provides_count; k++) {
  9844. + if (possibility == conflictee_provides[k]) {
  9845. + return 1;
  9846. + }
  9847. + }
  9848. + }
  9849. + }
  9850. + return 0;
  9851. +}
  9852. +
  9853. +static char ** merge_unresolved(char ** oldstuff, char ** newstuff)
  9854. +{
  9855. + int oldlen = 0, newlen = 0;
  9856. + char ** result;
  9857. + register int i, j;
  9858. +
  9859. + if(!newstuff)
  9860. + return oldstuff;
  9861. +
  9862. + while(oldstuff && oldstuff[oldlen]) oldlen++;
  9863. + while(newstuff && newstuff[newlen]) newlen++;
  9864. +
  9865. + result = (char **)realloc(oldstuff, sizeof(char *) * (oldlen + newlen + 1));
  9866. + if (result == NULL) {
  9867. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  9868. + return NULL;
  9869. + }
  9870. +
  9871. + for(i = oldlen, j = 0; i < (oldlen + newlen); i++, j++)
  9872. + *(result + i) = *(newstuff + j);
  9873. +
  9874. + *(result + i) = NULL;
  9875. +
  9876. + return result;
  9877. +}
  9878. +
  9879. +/*
  9880. + * a kinda kludgy way to back out depends str from two different arrays (reg'l'r 'n pre)
  9881. + * this is null terminated, no count is carried around
  9882. + */
  9883. +char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx)
  9884. +{
  9885. + int count;
  9886. + char ** resized;
  9887. + char *depend_str = pkg_depend_str(pkg, ref_ndx);
  9888. +
  9889. + count = 0;
  9890. + while(the_lost && the_lost[count]) count++;
  9891. +
  9892. + count++; /* need one to hold the null */
  9893. + resized = (char **)realloc(the_lost, sizeof(char *) * (count + 1));
  9894. + if (resized == NULL) {
  9895. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  9896. + return NULL;
  9897. + }
  9898. + resized[count - 1] = strdup(depend_str);
  9899. + resized[count] = NULL;
  9900. +
  9901. + return resized;
  9902. +}
  9903. +
  9904. +void printDepends(pkg_t * pkg)
  9905. +{
  9906. + register int i, j;
  9907. + compound_depend_t * depend;
  9908. + int count;
  9909. +
  9910. + count = pkg->pre_depends_count + pkg->depends_count;
  9911. +
  9912. + depend = pkg->depends;
  9913. + if(!depend){
  9914. + fprintf(stderr, "Depends pointer is NULL\n");
  9915. + return;
  9916. + }
  9917. + for(i = 0; i < count; i++){
  9918. + fprintf(stderr, "%s has %d possibilities:\n",
  9919. + (depend->type == GREEDY_DEPEND) ? "Greedy-Depend" : ((depend->type == DEPEND) ? "Depend" : "Pre-Depend"),
  9920. + depend->possibility_count);
  9921. + for(j = 0; j < depend->possibility_count; j++)
  9922. + fprintf(stderr, "\t%s version %s (%d)\n",
  9923. + depend->possibilities[j]->pkg->name,
  9924. + depend->possibilities[j]->version,
  9925. + depend->possibilities[j]->constraint);
  9926. + depend++;
  9927. + }
  9928. +}
  9929. +
  9930. +int buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
  9931. +{
  9932. + register int i, j;
  9933. +
  9934. + /* every pkg provides itself */
  9935. + abstract_pkg_vec_insert(ab_pkg->provided_by, ab_pkg);
  9936. +
  9937. + if (!pkg->provides_count)
  9938. + return 0;
  9939. +
  9940. + pkg->provides = (abstract_pkg_t **)malloc(sizeof(abstract_pkg_t *) * (pkg->provides_count + 1));
  9941. + if (pkg->provides == NULL) {
  9942. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  9943. + return -1 ;
  9944. + }
  9945. + pkg->provides[0] = ab_pkg;
  9946. +
  9947. + // if (strcmp(ab_pkg->name, pkg->name))
  9948. + // fprintf(stderr, __FUNCTION__ ": ab_pkg=%s pkg=%s\n", ab_pkg->name, pkg->name);
  9949. +
  9950. + for(i = 0; i < pkg->provides_count; i++){
  9951. + abstract_pkg_t *provided_abpkg = ensure_abstract_pkg_by_name(hash, pkg->provides_str[i]);
  9952. +
  9953. + pkg->provides[i+1] = provided_abpkg;
  9954. +
  9955. + j = 0;
  9956. + abstract_pkg_vec_insert(provided_abpkg->provided_by, ab_pkg);
  9957. + }
  9958. + return 0;
  9959. +}
  9960. +
  9961. +/* Abhaya: added conflicts support */
  9962. +int buildConflicts(hash_table_t * hash, pkg_t * pkg)
  9963. +{
  9964. + register int i;
  9965. + compound_depend_t * conflicts;
  9966. +
  9967. + if (!pkg->conflicts_count)
  9968. + return 0;
  9969. +
  9970. + conflicts = pkg->conflicts = malloc(sizeof(compound_depend_t) *
  9971. + pkg->conflicts_count);
  9972. + if (conflicts == NULL) {
  9973. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  9974. + return -1;
  9975. + }
  9976. + for (i = 0; i < pkg->conflicts_count; i++) {
  9977. + conflicts->type = CONFLICTS;
  9978. + parseDepends(conflicts, hash,
  9979. + pkg->conflicts_str[i]);
  9980. +#if 0
  9981. + for (j = 0; j < conflicts->possibility_count; j++) {
  9982. + depend_t *possibility = conflicts->possibilities[j];
  9983. + abstract_pkg_t *conflicting_apkg = possibility->pkg;
  9984. + pkg_add_conflict_pair(ab_pkg, conflicting_apkg);
  9985. + }
  9986. +#endif
  9987. + conflicts++;
  9988. + }
  9989. + return 0;
  9990. +}
  9991. +
  9992. +int buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
  9993. +{
  9994. + register int i, j;
  9995. +
  9996. + if (!pkg->replaces_count)
  9997. + return 0;
  9998. +
  9999. + pkg->replaces = (abstract_pkg_t **)malloc(sizeof(abstract_pkg_t *) * pkg->replaces_count);
  10000. + if (pkg->replaces == NULL) {
  10001. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10002. + return -1;
  10003. + }
  10004. +
  10005. + // if (strcmp(ab_pkg->name, pkg->name))
  10006. + // fprintf(stderr, __FUNCTION__ ": ab_pkg=%s pkg=%s\n", ab_pkg->name, pkg->name);
  10007. +
  10008. + for(i = 0; i < pkg->replaces_count; i++){
  10009. + abstract_pkg_t *old_abpkg = ensure_abstract_pkg_by_name(hash, pkg->replaces_str[i]);
  10010. +
  10011. + pkg->replaces[i] = old_abpkg;
  10012. +
  10013. + j = 0;
  10014. + if (!old_abpkg->replaced_by)
  10015. + old_abpkg->replaced_by = abstract_pkg_vec_alloc();
  10016. + if ( old_abpkg->replaced_by == NULL ){
  10017. + return -1;
  10018. + }
  10019. + /* if a package pkg both replaces and conflicts old_abpkg,
  10020. + * then add it to the replaced_by vector so that old_abpkg
  10021. + * will be upgraded to ab_pkg automatically */
  10022. + if (pkg_conflicts_abstract(pkg, old_abpkg))
  10023. + abstract_pkg_vec_insert(old_abpkg->replaced_by, ab_pkg);
  10024. + }
  10025. + return 0;
  10026. +}
  10027. +
  10028. +int buildDepends(hash_table_t * hash, pkg_t * pkg)
  10029. +{
  10030. + int count;
  10031. + register int i;
  10032. + compound_depend_t * depends;
  10033. +
  10034. + if(!(count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count))
  10035. + return 0;
  10036. +
  10037. + if (0 && pkg->pre_depends_count)
  10038. + fprintf(stderr, "pkg=%s pre_depends_count=%d depends_count=%d\n",
  10039. + pkg->name, pkg->pre_depends_count, pkg->depends_count);
  10040. + depends = pkg->depends = malloc(sizeof(compound_depend_t) * count);
  10041. + if (depends == NULL) {
  10042. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10043. + return -1;
  10044. + }
  10045. +
  10046. +
  10047. + for(i = 0; i < pkg->pre_depends_count; i++){
  10048. + parseDepends(depends, hash, pkg->pre_depends_str[i]);
  10049. + if (0 && pkg->pre_depends_count)
  10050. + fprintf(stderr, " pre_depends_str=%s depends=%p possibility_count=%x\n",
  10051. + pkg->pre_depends_str[i], depends, depends->possibility_count);
  10052. + depends->type = PREDEPEND;
  10053. + depends++;
  10054. + }
  10055. +
  10056. + for(i = 0; i < pkg->recommends_count; i++){
  10057. + parseDepends(depends, hash, pkg->recommends_str[i]);
  10058. + if (0 && pkg->recommends_count)
  10059. + fprintf(stderr, " recommends_str=%s depends=%p possibility_count=%x\n",
  10060. + pkg->recommends_str[i], depends, depends->possibility_count);
  10061. + depends->type = RECOMMEND;
  10062. + depends++;
  10063. + }
  10064. +
  10065. + for(i = 0; i < pkg->suggests_count; i++){
  10066. + parseDepends(depends, hash, pkg->suggests_str[i]);
  10067. + if (0 && pkg->suggests_count)
  10068. + fprintf(stderr, " suggests_str=%s depends=%p possibility_count=%x\n",
  10069. + pkg->suggests_str[i], depends, depends->possibility_count);
  10070. + depends->type = SUGGEST;
  10071. + depends++;
  10072. + }
  10073. +
  10074. + for(i = 0; i < pkg->depends_count; i++){
  10075. + parseDepends(depends, hash, pkg->depends_str[i]);
  10076. + if (0 && pkg->depends_count)
  10077. + fprintf(stderr, " depends_str=%s depends=%p possibility_count=%x\n",
  10078. + pkg->depends_str[i], depends, depends->possibility_count);
  10079. + depends++;
  10080. + }
  10081. + return 0;
  10082. +}
  10083. +
  10084. +/*
  10085. + * pkg_depend_string: returns the depends string specified by index_.
  10086. + * All 4 kinds of dependences: dependence, pre-dependence, recommend, and suggest are number starting from 0.
  10087. + * [0,npredepends) -> returns pre_depends_str[index_]
  10088. + * [npredepends,npredepends+nrecommends) -> returns recommends_str[index_]
  10089. + * [npredepends+nrecommends,npredepends+nrecommends+nsuggests) -> returns recommends_str[index_]
  10090. + * [npredepends+nrecommends+nsuggests,npredepends+nrecommends+nsuggests+ndepends) -> returns depends_str[index_]
  10091. + */
  10092. +char *pkg_depend_str(pkg_t *pkg, int index_)
  10093. +{
  10094. + if (index_ < pkg->pre_depends_count) {
  10095. + return pkg->pre_depends_str[index_];
  10096. + }
  10097. + index_ -= pkg->pre_depends_count;
  10098. +
  10099. + if (index_ < pkg->recommends_count) {
  10100. + return pkg->recommends_str[index_];
  10101. + }
  10102. + index_ -= pkg->recommends_count;
  10103. +
  10104. + if (index_ < pkg->suggests_count) {
  10105. + return pkg->suggests_str[index_];
  10106. + }
  10107. + index_ -= pkg->suggests_count;
  10108. +
  10109. + if (index_ < pkg->depends_count) {
  10110. + return pkg->depends_str[index_];
  10111. + }
  10112. + fprintf(stderr, "pkg_depend_str: index_ %d out of range for pkg=%s\n", index_, pkg->name);
  10113. + return NULL;
  10114. +}
  10115. +
  10116. +void freeDepends(pkg_t *pkg)
  10117. +{
  10118. + int i;
  10119. +
  10120. + if (pkg == NULL || pkg->depends == NULL) {
  10121. + return;
  10122. + }
  10123. +
  10124. + fprintf(stderr, "Freeing depends=%p\n", pkg->depends);
  10125. + for (i=0; i < pkg->depends->possibility_count; i++) {
  10126. + depend_deinit(pkg->depends->possibilities[i]);
  10127. + }
  10128. + free(pkg->depends->possibilities);
  10129. + free(pkg->depends);
  10130. + pkg->depends = NULL;
  10131. +}
  10132. +
  10133. +void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg)
  10134. +{
  10135. + compound_depend_t * depends;
  10136. + int count, othercount;
  10137. + register int i, j;
  10138. + abstract_pkg_t * ab_depend;
  10139. + abstract_pkg_t ** temp;
  10140. +
  10141. + count = pkg->pre_depends_count + pkg->depends_count;
  10142. + depends = pkg->depends;
  10143. +
  10144. + if (0 && pkg->pre_depends_count)
  10145. + fprintf(stderr, "pkg=%s pre_depends_count=%d depends_count=%d\n",
  10146. + pkg->name, pkg->pre_depends_count, pkg->depends_count);
  10147. + for (i = 0; i < count; i++) {
  10148. + if (0 && pkg->pre_depends_count)
  10149. + fprintf(stderr, " i=%d possibility_count=%x depends=%p\n", i, depends->possibility_count, depends);
  10150. + for (j = 0; j < depends->possibility_count; j++){
  10151. + ab_depend = depends->possibilities[j]->pkg;
  10152. + if(!ab_depend->depended_upon_by)
  10153. + ab_depend->depended_upon_by = (abstract_pkg_t **)calloc(1, sizeof(abstract_pkg_t *));
  10154. +
  10155. + temp = ab_depend->depended_upon_by;
  10156. + othercount = 1;
  10157. + while(*temp){
  10158. + temp++;
  10159. + othercount++;
  10160. + }
  10161. + *temp = ab_pkg;
  10162. +
  10163. + ab_depend->depended_upon_by = (abstract_pkg_t **)realloc(ab_depend->depended_upon_by,
  10164. + (othercount + 1) * sizeof(abstract_pkg_t *));
  10165. + /* the array may have moved */
  10166. + temp = ab_depend->depended_upon_by + othercount;
  10167. + *temp = NULL;
  10168. + }
  10169. + depends++;
  10170. + }
  10171. +}
  10172. +
  10173. +static depend_t * depend_init(void)
  10174. +{
  10175. + depend_t * d = (depend_t *)malloc(sizeof(depend_t));
  10176. + if ( d==NULL ){
  10177. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10178. + return NULL;
  10179. + }
  10180. + d->constraint = NONE;
  10181. + d->version = NULL;
  10182. + d->pkg = NULL;
  10183. +
  10184. + return d;
  10185. +}
  10186. +
  10187. +static void depend_deinit(depend_t *d)
  10188. +{
  10189. + free(d);
  10190. +}
  10191. +
  10192. +static int parseDepends(compound_depend_t *compound_depend,
  10193. + hash_table_t * hash, char * depend_str)
  10194. +{
  10195. + char * pkg_name, buffer[2048];
  10196. + int num_of_ors = 0;
  10197. + register int i;
  10198. + register char * src, * dest;
  10199. + depend_t ** possibilities;
  10200. +
  10201. + /* first count the number of ored possibilities for satisfying dependency */
  10202. + src = depend_str;
  10203. + while(*src)
  10204. + if(*src++ == '|')
  10205. + num_of_ors++;
  10206. +
  10207. + compound_depend->type = DEPEND;
  10208. +
  10209. + compound_depend->possibility_count = num_of_ors + 1;
  10210. + possibilities = (depend_t **)malloc(sizeof(depend_t *) * (num_of_ors + 1));
  10211. + if (!possibilities)
  10212. + return -ENOMEM;
  10213. + compound_depend->possibilities = possibilities;
  10214. +
  10215. + src = depend_str;
  10216. + for(i = 0; i < num_of_ors + 1; i++){
  10217. + possibilities[i] = depend_init();
  10218. + if (!possibilities[i])
  10219. + return -ENOMEM;
  10220. + /* gobble up just the name first */
  10221. + dest = buffer;
  10222. + while(*src &&
  10223. + !isspace(*src) &&
  10224. + (*src != '(') &&
  10225. + (*src != '*') &&
  10226. + (*src != '|'))
  10227. + *dest++ = *src++;
  10228. + *dest = '\0';
  10229. + pkg_name = trim_alloc(buffer);
  10230. + if (pkg_name == NULL )
  10231. + return -ENOMEM;
  10232. +
  10233. + /* now look at possible version info */
  10234. +
  10235. + /* skip to next chars */
  10236. + if(isspace(*src))
  10237. + while(*src && isspace(*src)) src++;
  10238. +
  10239. + /* extract constraint and version */
  10240. + if(*src == '('){
  10241. + src++;
  10242. + if(!strncmp(src, "<<", 2)){
  10243. + possibilities[i]->constraint = EARLIER;
  10244. + src += 2;
  10245. + }
  10246. + else if(!strncmp(src, "<=", 2)){
  10247. + possibilities[i]->constraint = EARLIER_EQUAL;
  10248. + src += 2;
  10249. + }
  10250. + else if(!strncmp(src, ">=", 2)){
  10251. + possibilities[i]->constraint = LATER_EQUAL;
  10252. + src += 2;
  10253. + }
  10254. + else if(!strncmp(src, ">>", 2)){
  10255. + possibilities[i]->constraint = LATER;
  10256. + src += 2;
  10257. + }
  10258. + else if(!strncmp(src, "=", 1)){
  10259. + possibilities[i]->constraint = EQUAL;
  10260. + src++;
  10261. + }
  10262. + /* should these be here to support deprecated designations; dpkg does */
  10263. + else if(!strncmp(src, "<", 1)){
  10264. + possibilities[i]->constraint = EARLIER_EQUAL;
  10265. + src++;
  10266. + }
  10267. + else if(!strncmp(src, ">", 1)){
  10268. + possibilities[i]->constraint = LATER_EQUAL;
  10269. + src++;
  10270. + }
  10271. +
  10272. + /* now we have any constraint, pass space to version string */
  10273. + while(isspace(*src)) src++;
  10274. +
  10275. + /* this would be the version string */
  10276. + dest = buffer;
  10277. + while(*src && *src != ')')
  10278. + *dest++ = *src++;
  10279. + *dest = '\0';
  10280. +
  10281. + possibilities[i]->version = trim_alloc(buffer);
  10282. + /* fprintf(stderr, "let's print the depends version string:");
  10283. + fprintf(stderr, "version %s\n", possibilities[i]->version);*/
  10284. + if (possibilities[i]->version == NULL )
  10285. + return -ENOMEM;
  10286. +
  10287. +
  10288. + }
  10289. + /* hook up the dependency to its abstract pkg */
  10290. + possibilities[i]->pkg = ensure_abstract_pkg_by_name(hash, pkg_name);
  10291. +
  10292. + free(pkg_name);
  10293. +
  10294. + /* now get past the ) and any possible | chars */
  10295. + while(*src &&
  10296. + (isspace(*src) ||
  10297. + (*src == ')') ||
  10298. + (*src == '|')))
  10299. + src++;
  10300. + if (*src == '*')
  10301. + {
  10302. + compound_depend->type = GREEDY_DEPEND;
  10303. + src++;
  10304. + }
  10305. + }
  10306. +
  10307. + return 0;
  10308. +}
  10309. diff -Nur busybox-1.16.1.orig/archival/libipkg/pkg_depends.h busybox-1.16.1/archival/libipkg/pkg_depends.h
  10310. --- busybox-1.16.1.orig/archival/libipkg/pkg_depends.h 1970-01-01 01:00:00.000000000 +0100
  10311. +++ busybox-1.16.1/archival/libipkg/pkg_depends.h 2010-06-29 17:31:24.588368223 +0200
  10312. @@ -0,0 +1,105 @@
  10313. +/* pkg_depends.h - the itsy package management system
  10314. +
  10315. + Steven M. Ayer
  10316. +
  10317. + Copyright (C) 2002 Compaq Computer Corporation
  10318. +
  10319. + This program is free software; you can redistribute it and/or
  10320. + modify it under the terms of the GNU General Public License as
  10321. + published by the Free Software Foundation; either version 2, or (at
  10322. + your option) any later version.
  10323. +
  10324. + This program is distributed in the hope that it will be useful, but
  10325. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10326. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10327. + General Public License for more details.
  10328. +*/
  10329. +
  10330. +#ifndef PKG_DEPENDS_H
  10331. +#define PKG_DEPENDS_H
  10332. +
  10333. +#include "pkg.h"
  10334. +#include "pkg_hash.h"
  10335. +
  10336. +enum depend_type {
  10337. + PREDEPEND,
  10338. + DEPEND,
  10339. + CONFLICTS,
  10340. + GREEDY_DEPEND,
  10341. + RECOMMEND,
  10342. + SUGGEST
  10343. +};
  10344. +typedef enum depend_type depend_type_t;
  10345. +
  10346. +enum version_constraint {
  10347. + NONE,
  10348. + EARLIER,
  10349. + EARLIER_EQUAL,
  10350. + EQUAL,
  10351. + LATER_EQUAL,
  10352. + LATER
  10353. +};
  10354. +typedef enum version_constraint version_constraint_t;
  10355. +
  10356. +struct depend{
  10357. + version_constraint_t constraint;
  10358. + char * version;
  10359. + abstract_pkg_t * pkg;
  10360. +};
  10361. +typedef struct depend depend_t;
  10362. +
  10363. +struct compound_depend{
  10364. + depend_type_t type;
  10365. + int possibility_count;
  10366. + struct depend ** possibilities;
  10367. +};
  10368. +typedef struct compound_depend compound_depend_t;
  10369. +
  10370. +#include "hash_table.h"
  10371. +
  10372. +int buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
  10373. +int buildConflicts(hash_table_t * hash, pkg_t * pkg);
  10374. +int buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
  10375. +int buildDepends(hash_table_t * hash, pkg_t * pkg);
  10376. +
  10377. +/**
  10378. + * pkg_has_common_provides returns 1 if pkg and replacee both provide
  10379. + * the same abstract package and 0 otherwise.
  10380. + */
  10381. +int pkg_has_common_provides(pkg_t *pkg, pkg_t *replacee);
  10382. +
  10383. +/**
  10384. + * pkg_provides returns 1 if pkg->provides contains providee and 0
  10385. + * otherwise.
  10386. + */
  10387. +int pkg_provides_abstract(pkg_t *pkg, abstract_pkg_t *providee);
  10388. +
  10389. +/**
  10390. + * pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0
  10391. + * otherwise.
  10392. + */
  10393. +int pkg_replaces(pkg_t *pkg, pkg_t *replacee);
  10394. +
  10395. +/**
  10396. + * pkg_conflicts_abstract returns 1 if pkg->conflicts contains conflictee provides and 0
  10397. + * otherwise.
  10398. + */
  10399. +int pkg_conflicts_abstract(pkg_t *pkg, abstract_pkg_t *conflicts);
  10400. +
  10401. +/**
  10402. + * pkg_conflicts returns 1 if pkg->conflicts contains one of conflictee's provides and 0
  10403. + * otherwise.
  10404. + */
  10405. +int pkg_conflicts(pkg_t *pkg, pkg_t *conflicts);
  10406. +
  10407. +char *pkg_depend_str(pkg_t *pkg, int index_);
  10408. +void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg);
  10409. +void freeDepends(pkg_t *pkg);
  10410. +void printDepends(pkg_t * pkg);
  10411. +int version_constraints_satisfied(depend_t * depends, pkg_t * pkg);
  10412. +int pkg_hash_fetch_unsatisfied_dependencies(ipkg_conf_t *conf, pkg_t * pkg, pkg_vec_t *depends, char *** unresolved);
  10413. +pkg_vec_t * pkg_hash_fetch_conflicts(pkg_t * pkg);
  10414. +int pkg_dependence_satisfiable(depend_t *depend);
  10415. +int pkg_dependence_satisfied(depend_t *depend);
  10416. +
  10417. +#endif
  10418. diff -Nur busybox-1.16.1.orig/archival/libipkg/pkg_dest.c busybox-1.16.1/archival/libipkg/pkg_dest.c
  10419. --- busybox-1.16.1.orig/archival/libipkg/pkg_dest.c 1970-01-01 01:00:00.000000000 +0100
  10420. +++ busybox-1.16.1/archival/libipkg/pkg_dest.c 2010-06-29 17:31:24.625873289 +0200
  10421. @@ -0,0 +1,92 @@
  10422. +/* pkg_dest.c - the itsy package management system
  10423. +
  10424. + Carl D. Worth
  10425. +
  10426. + Copyright (C) 2001 University of Southern California
  10427. +
  10428. + This program is free software; you can redistribute it and/or
  10429. + modify it under the terms of the GNU General Public License as
  10430. + published by the Free Software Foundation; either version 2, or (at
  10431. + your option) any later version.
  10432. +
  10433. + This program is distributed in the hope that it will be useful, but
  10434. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10435. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10436. + General Public License for more details.
  10437. +*/
  10438. +
  10439. +#include "ipkg.h"
  10440. +
  10441. +#include "pkg_dest.h"
  10442. +#include "file_util.h"
  10443. +#include "str_util.h"
  10444. +#include "sprintf_alloc.h"
  10445. +
  10446. +int pkg_dest_init(pkg_dest_t *dest, const char *name, const char *root_dir,const char * lists_dir)
  10447. +{
  10448. + dest->name = strdup(name);
  10449. +
  10450. + /* Guarantee that dest->root_dir ends with a '/' */
  10451. + if (str_ends_with(root_dir, "/")) {
  10452. + dest->root_dir = strdup(root_dir);
  10453. + } else {
  10454. + sprintf_alloc(&dest->root_dir, "%s/", root_dir);
  10455. + }
  10456. + file_mkdir_hier(dest->root_dir, 0755);
  10457. +
  10458. + sprintf_alloc(&dest->ipkg_dir, "%s%s",
  10459. + dest->root_dir, IPKG_STATE_DIR_PREFIX);
  10460. + file_mkdir_hier(dest->ipkg_dir, 0755);
  10461. +
  10462. + if (str_starts_with (lists_dir, "/"))
  10463. + sprintf_alloc(&dest->lists_dir, "%s", lists_dir);
  10464. + else
  10465. + sprintf_alloc(&dest->lists_dir, "/%s", lists_dir);
  10466. +
  10467. + file_mkdir_hier(dest->lists_dir, 0755);
  10468. +
  10469. + sprintf_alloc(&dest->info_dir, "%s/%s",
  10470. + dest->ipkg_dir, IPKG_INFO_DIR_SUFFIX);
  10471. + file_mkdir_hier(dest->info_dir, 0755);
  10472. +
  10473. + sprintf_alloc(&dest->status_file_name, "%s/%s",
  10474. + dest->ipkg_dir, IPKG_STATUS_FILE_SUFFIX);
  10475. +
  10476. + sprintf_alloc(&dest->status_file_tmp_name, "%s/%s.tmp",
  10477. + dest->ipkg_dir, IPKG_STATUS_FILE_SUFFIX);
  10478. +
  10479. + dest->status_file = NULL;
  10480. +
  10481. + return 0;
  10482. +}
  10483. +
  10484. +void pkg_dest_deinit(pkg_dest_t *dest)
  10485. +{
  10486. + free(dest->name);
  10487. + dest->name = NULL;
  10488. +
  10489. + free(dest->root_dir);
  10490. + dest->root_dir = NULL;
  10491. +
  10492. + free(dest->ipkg_dir);
  10493. + dest->ipkg_dir = NULL;
  10494. +
  10495. + free(dest->lists_dir);
  10496. + dest->lists_dir = NULL;
  10497. +
  10498. + free(dest->info_dir);
  10499. + dest->info_dir = NULL;
  10500. +
  10501. + free(dest->status_file_name);
  10502. + dest->status_file_name = NULL;
  10503. +
  10504. + free(dest->status_file_tmp_name);
  10505. + dest->status_file_tmp_name = NULL;
  10506. +
  10507. + if (dest->status_file) {
  10508. + fclose(dest->status_file);
  10509. + }
  10510. + dest->status_file = NULL;
  10511. +
  10512. + dest->root_dir = NULL;
  10513. +}
  10514. diff -Nur busybox-1.16.1.orig/archival/libipkg/pkg_dest.h busybox-1.16.1/archival/libipkg/pkg_dest.h
  10515. --- busybox-1.16.1.orig/archival/libipkg/pkg_dest.h 1970-01-01 01:00:00.000000000 +0100
  10516. +++ busybox-1.16.1/archival/libipkg/pkg_dest.h 2010-06-29 17:31:24.669618111 +0200
  10517. @@ -0,0 +1,38 @@
  10518. +/* pkg_dest.h - the itsy package management system
  10519. +
  10520. + Carl D. Worth
  10521. +
  10522. + Copyright (C) 2001 University of Southern California
  10523. +
  10524. + This program is free software; you can redistribute it and/or
  10525. + modify it under the terms of the GNU General Public License as
  10526. + published by the Free Software Foundation; either version 2, or (at
  10527. + your option) any later version.
  10528. +
  10529. + This program is distributed in the hope that it will be useful, but
  10530. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10531. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10532. + General Public License for more details.
  10533. +*/
  10534. +
  10535. +#ifndef PKG_DEST_H
  10536. +#define PKG_DEST_H
  10537. +
  10538. +typedef struct pkg_dest pkg_dest_t;
  10539. +struct pkg_dest
  10540. +{
  10541. + char *name;
  10542. + char *root_dir;
  10543. + char *ipkg_dir;
  10544. + char *lists_dir;
  10545. + char *info_dir;
  10546. + char *status_file_name;
  10547. + char *status_file_tmp_name;
  10548. + FILE *status_file;
  10549. +};
  10550. +
  10551. +int pkg_dest_init(pkg_dest_t *dest, const char *name, const char *root_dir,const char *lists_dir);
  10552. +void pkg_dest_deinit(pkg_dest_t *dest);
  10553. +
  10554. +#endif
  10555. +
  10556. diff -Nur busybox-1.16.1.orig/archival/libipkg/pkg_dest_list.c busybox-1.16.1/archival/libipkg/pkg_dest_list.c
  10557. --- busybox-1.16.1.orig/archival/libipkg/pkg_dest_list.c 1970-01-01 01:00:00.000000000 +0100
  10558. +++ busybox-1.16.1/archival/libipkg/pkg_dest_list.c 2010-06-29 17:31:24.715868178 +0200
  10559. @@ -0,0 +1,85 @@
  10560. +/* pkg_dest_list.c - the itsy package management system
  10561. +
  10562. + Carl D. Worth
  10563. +
  10564. + Copyright (C) 2001 University of Southern California
  10565. +
  10566. + This program is free software; you can redistribute it and/or
  10567. + modify it under the terms of the GNU General Public License as
  10568. + published by the Free Software Foundation; either version 2, or (at
  10569. + your option) any later version.
  10570. +
  10571. + This program is distributed in the hope that it will be useful, but
  10572. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10573. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10574. + General Public License for more details.
  10575. +*/
  10576. +
  10577. +#include "ipkg.h"
  10578. +
  10579. +#include "pkg_dest.h"
  10580. +#include "void_list.h"
  10581. +#include "pkg_dest_list.h"
  10582. +
  10583. +int pkg_dest_list_elt_init(pkg_dest_list_elt_t *elt, pkg_dest_t *data)
  10584. +{
  10585. + return void_list_elt_init((void_list_elt_t *) elt, data);
  10586. +}
  10587. +
  10588. +void pkg_dest_list_elt_deinit(pkg_dest_list_elt_t *elt)
  10589. +{
  10590. + void_list_elt_deinit((void_list_elt_t *) elt);
  10591. +}
  10592. +
  10593. +int pkg_dest_list_init(pkg_dest_list_t *list)
  10594. +{
  10595. + return void_list_init((void_list_t *) list);
  10596. +}
  10597. +
  10598. +void pkg_dest_list_deinit(pkg_dest_list_t *list)
  10599. +{
  10600. + pkg_dest_list_elt_t *iter;
  10601. + pkg_dest_t *pkg_dest;
  10602. +
  10603. + for (iter = list->head; iter; iter = iter->next) {
  10604. + pkg_dest = iter->data;
  10605. + pkg_dest_deinit(pkg_dest);
  10606. +
  10607. + /* malloced in pkg_dest_list_append */
  10608. + free(pkg_dest);
  10609. + iter->data = NULL;
  10610. + }
  10611. + void_list_deinit((void_list_t *) list);
  10612. +}
  10613. +
  10614. +pkg_dest_t *pkg_dest_list_append(pkg_dest_list_t *list, const char *name,
  10615. + const char *root_dir,const char *lists_dir)
  10616. +{
  10617. + int err;
  10618. + pkg_dest_t *pkg_dest;
  10619. +
  10620. + /* freed in plg_dest_list_deinit */
  10621. + pkg_dest = malloc(sizeof(pkg_dest_t));
  10622. + if (pkg_dest == NULL) {
  10623. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10624. + return NULL;
  10625. + }
  10626. +
  10627. + pkg_dest_init(pkg_dest, name, root_dir,lists_dir);
  10628. + err = void_list_append((void_list_t *) list, pkg_dest);
  10629. + if (err) {
  10630. + return NULL;
  10631. + }
  10632. +
  10633. + return pkg_dest;
  10634. +}
  10635. +
  10636. +int pkg_dest_list_push(pkg_dest_list_t *list, pkg_dest_t *data)
  10637. +{
  10638. + return void_list_push((void_list_t *) list, data);
  10639. +}
  10640. +
  10641. +pkg_dest_list_elt_t *pkg_dest_list_pop(pkg_dest_list_t *list)
  10642. +{
  10643. + return (pkg_dest_list_elt_t *) void_list_pop((void_list_t *) list);
  10644. +}
  10645. diff -Nur busybox-1.16.1.orig/archival/libipkg/pkg_dest_list.h busybox-1.16.1/archival/libipkg/pkg_dest_list.h
  10646. --- busybox-1.16.1.orig/archival/libipkg/pkg_dest_list.h 1970-01-01 01:00:00.000000000 +0100
  10647. +++ busybox-1.16.1/archival/libipkg/pkg_dest_list.h 2010-06-29 17:31:24.760275316 +0200
  10648. @@ -0,0 +1,50 @@
  10649. +/* pkg_dest_list.h - the itsy package management system
  10650. +
  10651. + Carl D. Worth
  10652. +
  10653. + Copyright (C) 2001 University of Southern California
  10654. +
  10655. + This program is free software; you can redistribute it and/or
  10656. + modify it under the terms of the GNU General Public License as
  10657. + published by the Free Software Foundation; either version 2, or (at
  10658. + your option) any later version.
  10659. +
  10660. + This program is distributed in the hope that it will be useful, but
  10661. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10662. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10663. + General Public License for more details.
  10664. +*/
  10665. +
  10666. +#ifndef PKG_DEST_LIST_H
  10667. +#define PKG_DEST_LIST_H
  10668. +
  10669. +#include "pkg_dest.h"
  10670. +
  10671. +typedef struct pkg_dest_list_elt pkg_dest_list_elt_t;
  10672. +struct pkg_dest_list_elt
  10673. +{
  10674. + pkg_dest_list_elt_t *next;
  10675. + pkg_dest_t *data;
  10676. +};
  10677. +
  10678. +typedef struct pkg_dest_list pkg_dest_list_t;
  10679. +struct pkg_dest_list
  10680. +{
  10681. + pkg_dest_list_elt_t pre_head;
  10682. + pkg_dest_list_elt_t *head;
  10683. + pkg_dest_list_elt_t *tail;
  10684. +};
  10685. +
  10686. +int pkg_dest_list_elt_init(pkg_dest_list_elt_t *elt, pkg_dest_t *data);
  10687. +void pkg_dest_list_elt_deinit(pkg_dest_list_elt_t *elt);
  10688. +
  10689. +int pkg_dest_list_init(pkg_dest_list_t *list);
  10690. +void pkg_dest_list_deinit(pkg_dest_list_t *list);
  10691. +
  10692. +pkg_dest_t *pkg_dest_list_append(pkg_dest_list_t *list, const char *name,
  10693. + const char *root_dir,const char* lists_dir);
  10694. +int pkg_dest_list_push(pkg_dest_list_t *list, pkg_dest_t *data);
  10695. +pkg_dest_list_elt_t *pkg_dest_list_pop(pkg_dest_list_t *list);
  10696. +
  10697. +#endif
  10698. +
  10699. diff -Nur busybox-1.16.1.orig/archival/libipkg/pkg_extract.c busybox-1.16.1/archival/libipkg/pkg_extract.c
  10700. --- busybox-1.16.1.orig/archival/libipkg/pkg_extract.c 1970-01-01 01:00:00.000000000 +0100
  10701. +++ busybox-1.16.1/archival/libipkg/pkg_extract.c 2010-06-29 17:31:24.818364193 +0200
  10702. @@ -0,0 +1,255 @@
  10703. +/* pkg_extract.c - the itsy package management system
  10704. +
  10705. + Carl D. Worth
  10706. +
  10707. + Copyright (C) 2001 University of Southern California
  10708. +
  10709. + This program is free software; you can redistribute it and/or
  10710. + modify it under the terms of the GNU General Public License as
  10711. + published by the Free Software Foundation; either version 2, or (at
  10712. + your option) any later version.
  10713. +
  10714. + This program is distributed in the hope that it will be useful, but
  10715. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10716. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10717. + General Public License for more details.
  10718. +*/
  10719. +
  10720. +#include "ipkg.h"
  10721. +#include <errno.h>
  10722. +#include <fcntl.h>
  10723. +#include <stdio.h>
  10724. +
  10725. +#include "pkg_extract.h"
  10726. +
  10727. +#include "libbb.h"
  10728. +#include "file_util.h"
  10729. +#include "sprintf_alloc.h"
  10730. +#include "unarchive.h"
  10731. +
  10732. +#define IPKG_CONTROL_ARCHIVE "control.tar.gz"
  10733. +#define IPKG_DATA_ARCHIVE "data.tar.gz"
  10734. +#define IPKG_CONTROL_FILE "control"
  10735. +
  10736. +static void FAST_FUNC ipkg_data_extract_all_prefix(archive_handle_t *archive_handle)
  10737. +{
  10738. + char *name_ptr = archive_handle->file_header->name;
  10739. +
  10740. + /* Skip all leading "/" */
  10741. + while (*name_ptr == '/')
  10742. + name_ptr++;
  10743. + /* Skip all leading "./" and "../" */
  10744. + while (name_ptr[0] == '.') {
  10745. + if (name_ptr[1] == '.' && name_ptr[2] == '/')
  10746. + name_ptr++;
  10747. + if (name_ptr[1] != '/')
  10748. + break;
  10749. + name_ptr += 2;
  10750. + }
  10751. +
  10752. + if (name_ptr[0] != '\0') {
  10753. + archive_handle->file_header->name = xasprintf("%s%s", archive_handle->dpkg__buffer, name_ptr);
  10754. + data_extract_all(archive_handle);
  10755. + }
  10756. +}
  10757. +
  10758. +static void FAST_FUNC ipkg_data_extract_to_buffer(archive_handle_t *archive_handle)
  10759. +{
  10760. + unsigned size = archive_handle->file_header->size;
  10761. +
  10762. + archive_handle->dpkg__buffer = xzalloc(size + 1);
  10763. + xread(archive_handle->src_fd, archive_handle->dpkg__buffer, size);
  10764. +}
  10765. +
  10766. +static void extract_ipkg_file_to_dir(pkg_t *pkg, const char *dir, const char *filename)
  10767. +{
  10768. + archive_handle_t *archive;
  10769. + char *path;
  10770. +
  10771. + sprintf_alloc(&path, "%s/", dir);
  10772. + archive = init_handle();
  10773. + archive->src_fd = xopen(pkg->local_filename, O_RDONLY);
  10774. + archive->filter = filter_accept_list;
  10775. + llist_add_to(&(archive->accept), (char *)filename);
  10776. + archive->dpkg__buffer = path;
  10777. + archive->action_data = ipkg_data_extract_all_prefix;
  10778. + archive->ah_flags |= ARCHIVE_UNLINK_OLD;
  10779. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  10780. + close(archive->src_fd);
  10781. + free(archive->accept);
  10782. + free(archive);
  10783. + free(path);
  10784. +}
  10785. +
  10786. +static void FAST_FUNC data_extract_file_name_to_buffer(archive_handle_t *archive)
  10787. +{
  10788. + unsigned int size = strlen(archive->file_header->name) + 2;
  10789. +
  10790. + if (archive->dpkg__buffer == NULL) {
  10791. + archive->dpkg__buffer = xmalloc(size);
  10792. + strcpy(archive->dpkg__buffer, archive->file_header->name);
  10793. + } else {
  10794. + size += strlen(archive->dpkg__buffer);
  10795. + archive->dpkg__buffer = xrealloc(archive->dpkg__buffer, size);
  10796. + strcat(archive->dpkg__buffer, archive->file_header->name);
  10797. + }
  10798. + strcat(archive->dpkg__buffer, "\n");
  10799. + data_skip(archive);
  10800. +}
  10801. +
  10802. +int pkg_extract_control_file_to_stream(pkg_t *pkg, FILE *stream)
  10803. +{
  10804. + archive_handle_t *archive;
  10805. + char *name;
  10806. + const char *filename = "./" IPKG_CONTROL_FILE;
  10807. +
  10808. + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_CONTROL_ARCHIVE);
  10809. + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_CONTROL_ARCHIVE);
  10810. + archive = init_handle();
  10811. + archive->src_fd = xopen(name, O_RDONLY);
  10812. + archive->filter = filter_accept_list;
  10813. + llist_add_to(&(archive->accept), (char *)filename);
  10814. + archive->action_data = ipkg_data_extract_to_buffer;
  10815. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  10816. + close(archive->src_fd);
  10817. + fputs(archive->dpkg__buffer, stream);
  10818. + free(archive->dpkg__buffer);
  10819. + free(archive->accept);
  10820. + free(archive);
  10821. + free(name);
  10822. +
  10823. + return 0;
  10824. +}
  10825. +
  10826. +int pkg_extract_control_files_to_dir(pkg_t *pkg, const char *dir)
  10827. +{
  10828. + return pkg_extract_control_files_to_dir_with_prefix(pkg, dir, "");
  10829. +}
  10830. +
  10831. +int pkg_extract_control_files_to_dir_with_prefix(pkg_t *pkg, const char *dir, const char *prefix)
  10832. +{
  10833. + archive_handle_t *archive;
  10834. + char *name;
  10835. + char *path;
  10836. +
  10837. + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_CONTROL_ARCHIVE);
  10838. + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_CONTROL_ARCHIVE);
  10839. + sprintf_alloc(&path, "%s/%s", dir, prefix);
  10840. + archive = init_handle();
  10841. + archive->src_fd = xopen(name, O_RDONLY);
  10842. + archive->filter = filter_accept_all;
  10843. + archive->dpkg__buffer = path;
  10844. + archive->action_data = ipkg_data_extract_all_prefix;
  10845. + archive->ah_flags |= ARCHIVE_CREATE_LEADING_DIRS | ARCHIVE_RESTORE_DATE | ARCHIVE_UNLINK_OLD;
  10846. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  10847. + close(archive->src_fd);
  10848. + free(archive);
  10849. + free(path);
  10850. + free(name);
  10851. +
  10852. + return 0;
  10853. +}
  10854. +
  10855. +int pkg_extract_data_files_to_dir(pkg_t *pkg, const char *dir)
  10856. +{
  10857. + archive_handle_t *archive;
  10858. + char *name;
  10859. + char *path;
  10860. +
  10861. + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_DATA_ARCHIVE);
  10862. + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_DATA_ARCHIVE);
  10863. + sprintf_alloc(&path, "%s/", dir);
  10864. + archive = init_handle();
  10865. + archive->src_fd = xopen(name, O_RDONLY);
  10866. + archive->filter = filter_accept_all;
  10867. + archive->dpkg__buffer = path;
  10868. + archive->action_data = ipkg_data_extract_all_prefix;
  10869. + archive->ah_flags |= ARCHIVE_CREATE_LEADING_DIRS | ARCHIVE_RESTORE_DATE | ARCHIVE_UNLINK_OLD;
  10870. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  10871. + close(archive->src_fd);
  10872. + free(archive);
  10873. + free(path);
  10874. + free(name);
  10875. +
  10876. + return 0;
  10877. +}
  10878. +
  10879. +int pkg_extract_data_file_names_to_file(pkg_t *pkg, const char *file_name)
  10880. +{
  10881. + int err=0;
  10882. + char *line, *data_file;
  10883. + FILE *file;
  10884. + FILE *tmp;
  10885. +
  10886. + file = fopen(file_name, "w");
  10887. + if (file == NULL) {
  10888. + fprintf(stderr, "%s: ERROR: Failed to open %s for writing.\n",
  10889. + __FUNCTION__, file_name);
  10890. + return EINVAL;
  10891. + }
  10892. +
  10893. + tmp = tmpfile();
  10894. + if (pkg->installed_files) {
  10895. + str_list_elt_t *elt;
  10896. + for (elt = pkg->installed_files->head; elt; elt = elt->next) {
  10897. + fprintf(file, "%s\n", elt->data);
  10898. + }
  10899. + } else {
  10900. + err = pkg_extract_data_file_names_to_stream(pkg, tmp);
  10901. + if (err) {
  10902. + fclose(file);
  10903. + fclose(tmp);
  10904. + return err;
  10905. + }
  10906. +
  10907. + /* Fixup data file names by removing the initial '.' */
  10908. + rewind(tmp);
  10909. + while (1) {
  10910. + line = file_read_line_alloc(tmp);
  10911. + if (line == NULL) {
  10912. + break;
  10913. + }
  10914. +
  10915. + data_file = line;
  10916. + if (*data_file == '.') {
  10917. + data_file++;
  10918. + }
  10919. +
  10920. + if (*data_file != '/') {
  10921. + fputs("/", file);
  10922. + }
  10923. +
  10924. + /* I have no idea why, but this is what dpkg does */
  10925. + if (strcmp(data_file, "/\n") == 0) {
  10926. + fputs("/.\n", file);
  10927. + } else {
  10928. + fputs(data_file, file);
  10929. + }
  10930. + }
  10931. + }
  10932. + fclose(tmp);
  10933. + fclose(file);
  10934. +
  10935. + return err;
  10936. +}
  10937. +
  10938. +int pkg_extract_data_file_names_to_stream(pkg_t *pkg, FILE *file)
  10939. +{
  10940. + archive_handle_t *archive;
  10941. + char *name;
  10942. +
  10943. + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_DATA_ARCHIVE);
  10944. + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_DATA_ARCHIVE);
  10945. + archive = init_handle();
  10946. + archive->src_fd = xopen(name, O_RDONLY);
  10947. + archive->filter = filter_accept_all;
  10948. + archive->action_data = data_extract_file_name_to_buffer;
  10949. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  10950. + close(archive->src_fd);
  10951. + fputs(archive->dpkg__buffer, file);
  10952. + free(archive->dpkg__buffer);
  10953. + free(archive);
  10954. + free(name);
  10955. +
  10956. + return 0;
  10957. +}
  10958. diff -Nur busybox-1.16.1.orig/archival/libipkg/pkg_extract.h busybox-1.16.1/archival/libipkg/pkg_extract.h
  10959. --- busybox-1.16.1.orig/archival/libipkg/pkg_extract.h 1970-01-01 01:00:00.000000000 +0100
  10960. +++ busybox-1.16.1/archival/libipkg/pkg_extract.h 2010-06-29 17:31:24.858368110 +0200
  10961. @@ -0,0 +1,32 @@
  10962. +/* pkg_extract.c - the itsy package management system
  10963. +
  10964. + Carl D. Worth
  10965. +
  10966. + Copyright (C) 2001 University of Southern California
  10967. +
  10968. + This program is free software; you can redistribute it and/or
  10969. + modify it under the terms of the GNU General Public License as
  10970. + published by the Free Software Foundation; either version 2, or (at
  10971. + your option) any later version.
  10972. +
  10973. + This program is distributed in the hope that it will be useful, but
  10974. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10975. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10976. + General Public License for more details.
  10977. +*/
  10978. +
  10979. +#ifndef PKG_EXTRACT_H
  10980. +#define PKG_EXTRACT_H
  10981. +
  10982. +#include "pkg.h"
  10983. +
  10984. +int pkg_extract_control_file_to_stream(pkg_t *pkg, FILE *stream);
  10985. +int pkg_extract_control_files_to_dir(pkg_t *pkg, const char *dir);
  10986. +int pkg_extract_control_files_to_dir_with_prefix(pkg_t *pkg,
  10987. + const char *dir,
  10988. + const char *prefix);
  10989. +int pkg_extract_data_files_to_dir(pkg_t *pkg, const char *dir);
  10990. +int pkg_extract_data_file_names_to_file(pkg_t *pkg, const char *file_name);
  10991. +int pkg_extract_data_file_names_to_stream(pkg_t *pkg, FILE *file);
  10992. +
  10993. +#endif
  10994. diff -Nur busybox-1.16.1.orig/archival/libipkg/pkg.h busybox-1.16.1/archival/libipkg/pkg.h
  10995. --- busybox-1.16.1.orig/archival/libipkg/pkg.h 1970-01-01 01:00:00.000000000 +0100
  10996. +++ busybox-1.16.1/archival/libipkg/pkg.h 2010-06-29 17:31:24.897965989 +0200
  10997. @@ -0,0 +1,229 @@
  10998. +/* pkg.h - the itsy package management system
  10999. +
  11000. + Carl D. Worth
  11001. +
  11002. + Copyright (C) 2001 University of Southern California
  11003. +
  11004. + This program is free software; you can redistribute it and/or
  11005. + modify it under the terms of the GNU General Public License as
  11006. + published by the Free Software Foundation; either version 2, or (at
  11007. + your option) any later version.
  11008. +
  11009. + This program is distributed in the hope that it will be useful, but
  11010. + WITHOUT ANY WARRANTY; without even the implied warranty of
  11011. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11012. + General Public License for more details.
  11013. +*/
  11014. +
  11015. +#ifndef PKG_H
  11016. +#define PKG_H
  11017. +
  11018. +#include <sys/types.h>
  11019. +#include <sys/stat.h>
  11020. +#include <unistd.h>
  11021. +
  11022. +#include "pkg_vec.h"
  11023. +#include "str_list.h"
  11024. +#include "pkg_src.h"
  11025. +#include "pkg_dest.h"
  11026. +#include "ipkg_conf.h"
  11027. +#include "conffile_list.h"
  11028. +
  11029. +struct ipkg_conf;
  11030. +
  11031. +/* I think "Size" is currently the shortest field name */
  11032. +#define PKG_MINIMUM_FIELD_NAME_LEN 4
  11033. +
  11034. +enum pkg_state_want
  11035. +{
  11036. + SW_UNKNOWN = 1,
  11037. + SW_INSTALL,
  11038. + SW_DEINSTALL,
  11039. + SW_PURGE,
  11040. + SW_LAST_STATE_WANT
  11041. +};
  11042. +typedef enum pkg_state_want pkg_state_want_t;
  11043. +
  11044. +enum pkg_state_flag
  11045. +{
  11046. + SF_OK = 0,
  11047. + SF_REINSTREQ = 1,
  11048. + SF_HOLD = 2, /* do not upgrade version */
  11049. + SF_REPLACE = 4, /* replace this package */
  11050. + SF_NOPRUNE = 8, /* do not remove obsolete files */
  11051. + SF_PREFER = 16, /* prefer this version */
  11052. + SF_OBSOLETE = 32, /* old package in upgrade pair */
  11053. + SF_MARKED = 64, /* temporary mark */
  11054. + SF_FILELIST_CHANGED = 128, /* needs filelist written */
  11055. + SF_USER = 256,
  11056. + SF_LAST_STATE_FLAG
  11057. +};
  11058. +typedef enum pkg_state_flag pkg_state_flag_t;
  11059. +#define SF_NONVOLATILE_FLAGS (SF_HOLD|SF_NOPRUNE|SF_PREFER|SF_OBSOLETE|SF_USER)
  11060. +
  11061. +enum pkg_state_status
  11062. +{
  11063. + SS_NOT_INSTALLED = 1,
  11064. + SS_UNPACKED,
  11065. + SS_HALF_CONFIGURED,
  11066. + SS_INSTALLED,
  11067. + SS_HALF_INSTALLED,
  11068. + SS_CONFIG_FILES,
  11069. + SS_POST_INST_FAILED,
  11070. + SS_REMOVAL_FAILED,
  11071. + SS_LAST_STATE_STATUS
  11072. +};
  11073. +typedef enum pkg_state_status pkg_state_status_t;
  11074. +
  11075. +struct abstract_pkg{
  11076. + char * name;
  11077. + int dependencies_checked;
  11078. + pkg_vec_t * pkgs;
  11079. + pkg_state_status_t state_status;
  11080. + pkg_state_flag_t state_flag;
  11081. + struct abstract_pkg ** depended_upon_by; /* @@@@ this should be abstract_pkg_vec_t -Jamey */
  11082. + abstract_pkg_vec_t * provided_by;
  11083. + abstract_pkg_vec_t * replaced_by;
  11084. +};
  11085. +
  11086. +#include "pkg_depends.h"
  11087. +
  11088. +/* XXX: CLEANUP: I'd like to clean up pkg_t in several ways:
  11089. +
  11090. + The 3 version fields should go into a single version struct. (This
  11091. + is especially important since, currently, pkg->version can easily
  11092. + be mistaken for pkg_verson_str_alloc(pkg) although they are very
  11093. + distinct. This has been the source of multiple bugs.
  11094. +
  11095. + The 3 state fields could possibly also go into their own struct.
  11096. +
  11097. + All fields which deal with lists of packages, (Depends,
  11098. + Pre-Depends, Provides, Suggests, Recommends, Enhances), should each
  11099. + be handled by a single struct in pkg_t
  11100. +
  11101. + All string fields for which there is a small set of possible
  11102. + values, (section, maintainer, architecture, maybe version?), that
  11103. + are reused among different packages -- for all such packages we
  11104. + should move from "char *"s to some atom datatype to share data
  11105. + storage and use less memory. We might even do reference counting,
  11106. + but probably not since most often we only create new pkg_t structs,
  11107. + we don't often free them. */
  11108. +struct pkg
  11109. +{
  11110. + char *name;
  11111. + unsigned long epoch;
  11112. + char *version;
  11113. + char *revision;
  11114. + char *familiar_revision;
  11115. + pkg_src_t *src;
  11116. + pkg_dest_t *dest;
  11117. + char *architecture;
  11118. + char *section;
  11119. + char *maintainer;
  11120. + char *description;
  11121. + pkg_state_want_t state_want;
  11122. + pkg_state_flag_t state_flag;
  11123. + pkg_state_status_t state_status;
  11124. + char **depends_str;
  11125. + int depends_count;
  11126. + char **pre_depends_str;
  11127. + int pre_depends_count;
  11128. + char **recommends_str;
  11129. + int recommends_count;
  11130. + char **suggests_str;
  11131. + int suggests_count;
  11132. + compound_depend_t * depends;
  11133. +
  11134. + /* Abhaya: new conflicts */
  11135. + char **conflicts_str;
  11136. + compound_depend_t * conflicts;
  11137. + int conflicts_count;
  11138. +
  11139. + char **replaces_str;
  11140. + int replaces_count;
  11141. + abstract_pkg_t ** replaces;
  11142. +
  11143. + char **provides_str;
  11144. + int provides_count;
  11145. + abstract_pkg_t ** provides;
  11146. +
  11147. + abstract_pkg_t *parent;
  11148. +
  11149. + pkg_t *old_pkg; /* during upgrade, points from installee to previously installed */
  11150. +
  11151. + char *filename;
  11152. + char *local_filename;
  11153. + char *url;
  11154. + char *tmp_unpack_dir;
  11155. + char *md5sum;
  11156. + char *size;
  11157. + char *installed_size;
  11158. + char *priority;
  11159. + char *source;
  11160. + conffile_list_t conffiles;
  11161. + time_t installed_time;
  11162. + /* As pointer for lazy evaluation */
  11163. + str_list_t *installed_files;
  11164. + /* XXX: CLEANUP: I'd like to perhaps come up with a better
  11165. + mechanism to avoid the problem here, (which is that the
  11166. + installed_files list was being freed from an inner loop while
  11167. + still being used within an outer loop. */
  11168. + int installed_files_ref_cnt;
  11169. + int essential;
  11170. + int arch_priority;
  11171. +/* Adding this flag, to "force" ipkg to choose a "provided_by_hand" package, if there are multiple choice */
  11172. + int provided_by_hand;
  11173. +};
  11174. +
  11175. +pkg_t *pkg_new(void);
  11176. +int pkg_init(pkg_t *pkg);
  11177. +void pkg_deinit(pkg_t *pkg);
  11178. +int pkg_init_from_file(pkg_t *pkg, const char *filename);
  11179. +abstract_pkg_t *abstract_pkg_new(void);
  11180. +int abstract_pkg_init(abstract_pkg_t *ab_pkg);
  11181. +
  11182. +/*
  11183. + * merges fields from newpkg into oldpkg.
  11184. + * Forcibly sets oldpkg state_status, state_want and state_flags if set_status is nonzero
  11185. + */
  11186. +int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status);
  11187. +
  11188. +char *pkg_version_str_alloc(pkg_t *pkg);
  11189. +
  11190. +int pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg);
  11191. +int pkg_name_version_and_architecture_compare(pkg_t *a, pkg_t *b);
  11192. +int abstract_pkg_name_compare(abstract_pkg_t *a, abstract_pkg_t *b);
  11193. +
  11194. +char * pkg_formatted_info(pkg_t *pkg );
  11195. +char * pkg_formatted_field(pkg_t *pkg, const char *field );
  11196. +
  11197. +void set_flags_from_control(ipkg_conf_t *conf, pkg_t *pkg);
  11198. +
  11199. +void pkg_print_info(pkg_t *pkg, FILE *file);
  11200. +void pkg_print_status(pkg_t * pkg, FILE * file);
  11201. +void pkg_print_field(pkg_t *pkg, FILE *file, const char *field);
  11202. +str_list_t *pkg_get_installed_files(pkg_t *pkg);
  11203. +int pkg_free_installed_files(pkg_t *pkg);
  11204. +int pkg_remove_installed_files_list(ipkg_conf_t *conf, pkg_t *pkg);
  11205. +conffile_t *pkg_get_conffile(pkg_t *pkg, const char *file_name);
  11206. +int pkg_run_script(struct ipkg_conf *conf, pkg_t *pkg,
  11207. + const char *script, const char *args);
  11208. +
  11209. +/* enum mappings */
  11210. +char *pkg_state_want_to_str(pkg_state_want_t sw);
  11211. +pkg_state_want_t pkg_state_want_from_str(char *str);
  11212. +char *pkg_state_flag_to_str(pkg_state_flag_t sf);
  11213. +pkg_state_flag_t pkg_state_flag_from_str(char *str);
  11214. +char *pkg_state_status_to_str(pkg_state_status_t ss);
  11215. +pkg_state_status_t pkg_state_status_from_str(char *str);
  11216. +
  11217. +int pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op);
  11218. +
  11219. +int pkg_arch_supported(ipkg_conf_t *conf, pkg_t *pkg);
  11220. +int pkg_info_preinstall_check(ipkg_conf_t *conf);
  11221. +int pkg_free_installed_files(pkg_t *pkg);
  11222. +
  11223. +int pkg_write_filelist(ipkg_conf_t *conf, pkg_t *pkg);
  11224. +int pkg_write_changed_filelists(ipkg_conf_t *conf);
  11225. +
  11226. +#endif
  11227. diff -Nur busybox-1.16.1.orig/archival/libipkg/pkg_hash.c busybox-1.16.1/archival/libipkg/pkg_hash.c
  11228. --- busybox-1.16.1.orig/archival/libipkg/pkg_hash.c 1970-01-01 01:00:00.000000000 +0100
  11229. +++ busybox-1.16.1/archival/libipkg/pkg_hash.c 2010-06-29 17:31:24.956062867 +0200
  11230. @@ -0,0 +1,623 @@
  11231. +/* ipkg_hash.c - the itsy package management system
  11232. +
  11233. + Steven M. Ayer
  11234. +
  11235. + Copyright (C) 2002 Compaq Computer Corporation
  11236. +
  11237. + This program is free software; you can redistribute it and/or
  11238. + modify it under the terms of the GNU General Public License as
  11239. + published by the Free Software Foundation; either version 2, or (at
  11240. + your option) any later version.
  11241. +
  11242. + This program is distributed in the hope that it will be useful, but
  11243. + WITHOUT ANY WARRANTY; without even the implied warranty of
  11244. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11245. + General Public License for more details.
  11246. +*/
  11247. +
  11248. +#include "ipkg.h"
  11249. +#include <errno.h>
  11250. +#include <ctype.h>
  11251. +#include <stdlib.h>
  11252. +#include <string.h>
  11253. +
  11254. +#include "hash_table.h"
  11255. +#include "pkg.h"
  11256. +#include "ipkg_message.h"
  11257. +#include "pkg_vec.h"
  11258. +#include "pkg_hash.h"
  11259. +#include "pkg_parse.h"
  11260. +#include "ipkg_utils.h"
  11261. +
  11262. +static abstract_pkg_t * add_new_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name);
  11263. +
  11264. +/*
  11265. + * this will talk to both feeds-lists files and installed status files
  11266. + * example api:
  11267. + *
  11268. + * hash_table_t hash;
  11269. + * pkg_hash_init(name, &hash, 1000);
  11270. + * pkg_hash_add_from_file(<feed filename>);
  11271. + *
  11272. + * the query function is just there as a shell to prove to me that this
  11273. + * sort of works, but isn't far from doing something useful
  11274. + *
  11275. + * -sma, 12/21/01
  11276. + * modified: CDW 3 Jan. 2002
  11277. + */
  11278. +
  11279. +
  11280. +
  11281. +int pkg_hash_init(const char *name, hash_table_t *hash, int len)
  11282. +{
  11283. + return hash_table_init(name, hash, len);
  11284. +}
  11285. +
  11286. +void pkg_hash_deinit(hash_table_t *hash)
  11287. +{
  11288. + hash_table_deinit(hash);
  11289. +}
  11290. +
  11291. +
  11292. +/* Find the default arch for a given package status file if none is given. */
  11293. +static char *pkg_get_default_arch(ipkg_conf_t *conf)
  11294. +{
  11295. + nv_pair_list_elt_t *l;
  11296. + const char *def_arch = HOST_CPU_STR; /* Default arch */
  11297. + int def_prio = 0; /* Other archs override this */
  11298. +
  11299. + l = conf->arch_list.head;
  11300. +
  11301. + while (l) {
  11302. + nv_pair_t *nv = l->data;
  11303. + int priority = strtol(nv->value, NULL, 0);
  11304. +
  11305. + /* Check if this arch has higher priority, and is valid */
  11306. + if ((priority > def_prio) &&
  11307. + (strcmp(nv->name, "all")) && (strcmp(nv->name, "noarch"))) {
  11308. + /* Our new default */
  11309. + def_prio = priority;
  11310. + def_arch = nv->name;
  11311. + }
  11312. + l = l->next;
  11313. + }
  11314. +
  11315. + return strdup(def_arch);
  11316. +}
  11317. +
  11318. +int pkg_hash_add_from_file(ipkg_conf_t *conf, const char *file_name,
  11319. + pkg_src_t *src, pkg_dest_t *dest, int is_status_file)
  11320. +{
  11321. + hash_table_t *hash = &conf->pkg_hash;
  11322. + char **raw;
  11323. + char **raw_start;
  11324. + pkg_t *pkg;
  11325. +
  11326. + raw = raw_start = read_raw_pkgs_from_file(file_name);
  11327. + if (!raw)
  11328. + return -ENOMEM;
  11329. +
  11330. + while(*raw){ /* don't worry, we'll increment raw in the parsing function */
  11331. + pkg = pkg_new();
  11332. + if (!pkg)
  11333. + return -ENOMEM;
  11334. +
  11335. + if (pkg_parse_raw(pkg, &raw, src, dest) == 0) {
  11336. + if (!pkg->architecture) {
  11337. + char *version_str = pkg_version_str_alloc(pkg);
  11338. + pkg->architecture = pkg_get_default_arch(conf);
  11339. + ipkg_message(conf, IPKG_ERROR, "Package %s version %s has no architecture specified, defaulting to %s.\n",
  11340. + pkg->name, version_str, pkg->architecture);
  11341. + free(version_str);
  11342. + }
  11343. + hash_insert_pkg(hash, pkg, is_status_file,conf);
  11344. + } else {
  11345. + free(pkg);
  11346. + }
  11347. + }
  11348. +
  11349. + /* XXX: CLEANUP: I'd like a cleaner interface for cleaning up
  11350. + memory after read_raw_pkgs_from_file */
  11351. + raw = raw_start;
  11352. + while (*raw) {
  11353. + free(*raw++);
  11354. + }
  11355. + free(raw_start);
  11356. + return 0;
  11357. +}
  11358. +
  11359. +abstract_pkg_t * abstract_pkg_fetch_by_name(hash_table_t * hash, const char * pkg_name)
  11360. +{
  11361. + return (abstract_pkg_t *)hash_table_get(hash, pkg_name);
  11362. +}
  11363. +
  11364. +abstract_pkg_vec_t *pkg_hash_fetch_all_installation_candidates(hash_table_t *hash, const char *name)
  11365. +{
  11366. + abstract_pkg_t *apkg = abstract_pkg_fetch_by_name(hash, name);
  11367. + if (apkg)
  11368. + return NULL;
  11369. + return apkg->provided_by;
  11370. +}
  11371. +
  11372. +
  11373. +pkg_t *pkg_hash_fetch_best_installation_candidate(ipkg_conf_t *conf, abstract_pkg_t *apkg,
  11374. + int (*constraint_fcn)(pkg_t *pkg, void *cdata), void *cdata, int quiet)
  11375. +{
  11376. + int i;
  11377. + int nprovides = 0;
  11378. + int nmatching = 0;
  11379. + pkg_vec_t *matching_pkgs = pkg_vec_alloc();
  11380. + abstract_pkg_vec_t *matching_apkgs = abstract_pkg_vec_alloc();
  11381. + abstract_pkg_vec_t *provided_apkg_vec;
  11382. + abstract_pkg_t **provided_apkgs;
  11383. + abstract_pkg_vec_t *providers = abstract_pkg_vec_alloc();
  11384. + pkg_t *latest_installed_parent = NULL;
  11385. + pkg_t *latest_matching = NULL;
  11386. + pkg_t *held_pkg = NULL;
  11387. + pkg_t *good_pkg_by_name = NULL;
  11388. +
  11389. + if (matching_apkgs == NULL || providers == NULL ||
  11390. + apkg == NULL || apkg->provided_by == NULL || (apkg->provided_by->len == 0))
  11391. + return NULL;
  11392. +
  11393. + ipkg_message(conf, IPKG_DEBUG, "best installation candidate for %s\n", apkg->name);
  11394. +
  11395. + provided_apkg_vec = apkg->provided_by;
  11396. + nprovides = provided_apkg_vec->len;
  11397. + provided_apkgs = provided_apkg_vec->pkgs;
  11398. + if (nprovides > 1)
  11399. + ipkg_message(conf, IPKG_DEBUG, " apkg=%s nprovides=%d\n", apkg->name, nprovides);
  11400. +
  11401. + /* accumulate all the providers */
  11402. + for (i = 0; i < nprovides; i++) {
  11403. + abstract_pkg_t *provider_apkg = provided_apkgs[i];
  11404. + ipkg_message(conf, IPKG_DEBUG, " adding %s to providers\n", provider_apkg->name);
  11405. + abstract_pkg_vec_insert(providers, provider_apkg);
  11406. + }
  11407. + nprovides = providers->len;
  11408. +
  11409. + for (i = 0; i < nprovides; i++) {
  11410. + abstract_pkg_t *provider_apkg = abstract_pkg_vec_get(providers, i);
  11411. + abstract_pkg_t *replacement_apkg = NULL;
  11412. + pkg_vec_t *vec;
  11413. +
  11414. + if (provider_apkg->replaced_by && provider_apkg->replaced_by->len) {
  11415. + replacement_apkg = provider_apkg->replaced_by->pkgs[0];
  11416. + if (provider_apkg->replaced_by->len > 1) {
  11417. + ipkg_message(conf, IPKG_NOTICE, "Multiple replacers for %s, using first one (%s)\n",
  11418. + provider_apkg->name, replacement_apkg->name);
  11419. + }
  11420. + }
  11421. +
  11422. + if (replacement_apkg)
  11423. + ipkg_message(conf, IPKG_DEBUG, " replacement_apkg=%s for provider_apkg=%s\n",
  11424. + replacement_apkg->name, provider_apkg->name);
  11425. +
  11426. + if (replacement_apkg && (replacement_apkg != provider_apkg)) {
  11427. + if (abstract_pkg_vec_contains(providers, replacement_apkg))
  11428. + continue;
  11429. + else
  11430. + provider_apkg = replacement_apkg;
  11431. + }
  11432. +
  11433. + if (!(vec = provider_apkg->pkgs)) {
  11434. + ipkg_message(conf, IPKG_DEBUG, " no pkgs for provider_apkg %s\n", provider_apkg->name);
  11435. + continue;
  11436. + }
  11437. +
  11438. +
  11439. + /* now check for supported architecture */
  11440. + {
  11441. + int max_count = 0;
  11442. + int j;
  11443. +
  11444. + /* count packages matching max arch priority and keep track of last one */
  11445. + for (j = 0; j < vec->len; j++) {
  11446. + pkg_t *maybe = vec->pkgs[j];
  11447. + ipkg_message(conf, IPKG_DEBUG, " %s arch=%s arch_priority=%d version=%s \n",
  11448. + maybe->name, maybe->architecture, maybe->arch_priority, maybe->version);
  11449. + if (maybe->arch_priority > 0) {
  11450. + max_count++;
  11451. + abstract_pkg_vec_insert(matching_apkgs, maybe->parent);
  11452. + pkg_vec_insert(matching_pkgs, maybe);
  11453. + }
  11454. + }
  11455. + }
  11456. + }
  11457. +
  11458. + if (matching_pkgs->len > 1)
  11459. + pkg_vec_sort(matching_pkgs, pkg_name_version_and_architecture_compare);
  11460. + if (matching_apkgs->len > 1)
  11461. + abstract_pkg_vec_sort(matching_pkgs, abstract_pkg_name_compare);
  11462. +
  11463. +/* Here it is usefull, if ( matching_apkgs->len > 1 ), to test if one of this matching packages has the same name of the
  11464. + needed package. In this case, I would return it for install, otherwise I will continue with the procedure */
  11465. +/* The problem is what to do when there are more than a mathing package, with the same name and several version ?
  11466. + Until now I always got the latest, but that breaks the downgrade option.
  11467. + If I stop at the first one, I would probably miss the new ones
  11468. + Maybe the way is to have some kind of flag somewhere, to see if the package been asked to install is from a file,
  11469. + or from a Packages feed.
  11470. + 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*/
  11471. +/*Pigi*/
  11472. +
  11473. + for (i = 0; i < matching_pkgs->len; i++) {
  11474. + pkg_t *matching = matching_pkgs->pkgs[i];
  11475. + if (constraint_fcn(matching, cdata)) { /* We found it */
  11476. + ipkg_message(conf, IPKG_DEBUG, " Found a valid candidate for the install: %s %s \n", matching->name, matching->version) ;
  11477. + good_pkg_by_name = matching;
  11478. + if ( matching->provided_by_hand == 1 ) /* It has been provided by hand, so it is what user want */
  11479. + break;
  11480. + }
  11481. + }
  11482. +
  11483. +
  11484. + for (i = 0; i < matching_pkgs->len; i++) {
  11485. + pkg_t *matching = matching_pkgs->pkgs[i];
  11486. + latest_matching = matching;
  11487. + if (matching->parent->state_status == SS_INSTALLED || matching->parent->state_status == SS_UNPACKED)
  11488. + latest_installed_parent = matching;
  11489. + if (matching->state_flag & (SF_HOLD|SF_PREFER)) {
  11490. + if (held_pkg)
  11491. + ipkg_message(conf, IPKG_ERROR, "Multiple packages (%s and %s) providing same name marked HOLD or PREFER. Using latest.\n",
  11492. + held_pkg->name, matching->name);
  11493. + held_pkg = matching;
  11494. + }
  11495. + }
  11496. +
  11497. + if (!good_pkg_by_name && !held_pkg && !latest_installed_parent && matching_apkgs->len > 1 && !quiet) {
  11498. + ipkg_message(conf, IPKG_ERROR, "Package=%s, %d matching providers\n",
  11499. + apkg->name, matching_apkgs->len);
  11500. + for (i = 0; i < matching_apkgs->len; i++) {
  11501. + abstract_pkg_t *matching = matching_apkgs->pkgs[i];
  11502. + ipkg_message(conf, IPKG_ERROR, " %s\n", matching->name);
  11503. + }
  11504. + ipkg_message(conf, IPKG_ERROR, "Please select one with ipkg install or ipkg flag prefer\n");
  11505. + }
  11506. +
  11507. + if (matching_apkgs->len > 1 && conf->verbosity > 1) {
  11508. + ipkg_message(conf, IPKG_NOTICE, "%s: for apkg=%s, %d matching pkgs\n",
  11509. + __FUNCTION__, apkg->name, matching_pkgs->len);
  11510. + for (i = 0; i < matching_pkgs->len; i++) {
  11511. + pkg_t *matching = matching_pkgs->pkgs[i];
  11512. + ipkg_message(conf, IPKG_INFO, " %s %s %s\n",
  11513. + matching->name, matching->version, matching->architecture);
  11514. + }
  11515. + }
  11516. +
  11517. + nmatching = matching_apkgs->len;
  11518. +
  11519. + pkg_vec_free(matching_pkgs);
  11520. + abstract_pkg_vec_free(matching_apkgs);
  11521. + abstract_pkg_vec_free(providers);
  11522. +
  11523. + if (good_pkg_by_name) { /* We found a good candidate, we will install it */
  11524. + return good_pkg_by_name;
  11525. + }
  11526. + if (held_pkg) {
  11527. + ipkg_message(conf, IPKG_INFO, " using held package %s\n", held_pkg->name);
  11528. + return held_pkg;
  11529. + }
  11530. + if (latest_installed_parent) {
  11531. + ipkg_message(conf, IPKG_INFO, " using latest version of installed package %s\n", latest_installed_parent->name);
  11532. + return latest_installed_parent;
  11533. + }
  11534. + if (nmatching > 1) {
  11535. + ipkg_message(conf, IPKG_INFO, " no matching pkg out of matching_apkgs=%d\n", nmatching);
  11536. + return NULL;
  11537. + }
  11538. + if (latest_matching) {
  11539. + ipkg_message(conf, IPKG_INFO, " using latest matching %s %s %s\n",
  11540. + latest_matching->name, latest_matching->version, latest_matching->architecture);
  11541. + return latest_matching;
  11542. + }
  11543. + return NULL;
  11544. +}
  11545. +
  11546. +static int pkg_name_constraint_fcn(pkg_t *pkg, void *cdata)
  11547. +{
  11548. + const char *name = (const char *)cdata;
  11549. + if (strcmp(pkg->name, name) == 0)
  11550. + return 1;
  11551. + else
  11552. + return 0;
  11553. +}
  11554. +
  11555. +pkg_t *pkg_hash_fetch_best_installation_candidate_by_name(ipkg_conf_t *conf, const char *name)
  11556. +{
  11557. + hash_table_t *hash = &conf->pkg_hash;
  11558. + abstract_pkg_t *apkg = NULL;
  11559. +
  11560. + if (!(apkg = abstract_pkg_fetch_by_name(hash, name)))
  11561. + return NULL;
  11562. +
  11563. + return pkg_hash_fetch_best_installation_candidate(conf, apkg, pkg_name_constraint_fcn, apkg->name, 0);
  11564. +}
  11565. +
  11566. +
  11567. +pkg_t * pkg_hash_fetch_by_name_version(hash_table_t *hash,
  11568. + const char *pkg_name,
  11569. + const char * version)
  11570. +{
  11571. + pkg_vec_t * vec;
  11572. + register int i;
  11573. + char *version_str = NULL;
  11574. +
  11575. + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name)))
  11576. + return NULL;
  11577. +
  11578. + for(i = 0; i < vec->len; i++) {
  11579. + version_str = pkg_version_str_alloc(vec->pkgs[i]);
  11580. + if(!strcmp(version_str, version)) {
  11581. + free(version_str);
  11582. + break;
  11583. + }
  11584. + free(version_str);
  11585. + }
  11586. +
  11587. + if(i == vec->len)
  11588. + return NULL;
  11589. +
  11590. + return vec->pkgs[i];
  11591. +}
  11592. +
  11593. +pkg_t *pkg_hash_fetch_installed_by_name_dest(hash_table_t *hash,
  11594. + const char *pkg_name,
  11595. + pkg_dest_t *dest)
  11596. +{
  11597. + pkg_vec_t * vec;
  11598. + register int i;
  11599. +
  11600. + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name))) {
  11601. + return NULL;
  11602. + }
  11603. +
  11604. + for(i = 0; i < vec->len; i++)
  11605. + if((vec->pkgs[i]->state_status == SS_INSTALLED || vec->pkgs[i]->state_status == SS_UNPACKED) && vec->pkgs[i]->dest == dest) {
  11606. + return vec->pkgs[i];
  11607. + }
  11608. + return NULL;
  11609. +}
  11610. +
  11611. +pkg_t *pkg_hash_fetch_installed_by_name(hash_table_t *hash,
  11612. + const char *pkg_name)
  11613. +{
  11614. + pkg_vec_t * vec;
  11615. + register int i;
  11616. +
  11617. + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name))){
  11618. + return NULL;
  11619. + }
  11620. +
  11621. + for(i = 0; i < vec->len; i++)
  11622. + if (vec->pkgs[i]->state_status == SS_INSTALLED || vec->pkgs[i]->state_status == SS_UNPACKED){
  11623. + return vec->pkgs[i];
  11624. + }
  11625. +
  11626. + return NULL;
  11627. +}
  11628. +
  11629. +pkg_vec_t *pkg_vec_fetch_by_name(hash_table_t *hash, const char *pkg_name)
  11630. +{
  11631. + abstract_pkg_t * ab_pkg;
  11632. +
  11633. + if(!(ab_pkg = abstract_pkg_fetch_by_name(hash, pkg_name))){
  11634. + return NULL;
  11635. + }
  11636. +
  11637. + if (ab_pkg->pkgs) {
  11638. + return ab_pkg->pkgs;
  11639. + } else if (ab_pkg->provided_by) {
  11640. + abstract_pkg_t *abpkg = abstract_pkg_vec_get(ab_pkg->provided_by, 0);
  11641. + if (abpkg != NULL){
  11642. + return abpkg->pkgs;
  11643. + } else {
  11644. + return ab_pkg->pkgs;
  11645. + }
  11646. + } else {
  11647. + return NULL;
  11648. + }
  11649. +}
  11650. +
  11651. +static int pkg_compare_names(const void *p1, const void *p2)
  11652. +{
  11653. + const pkg_t *pkg1 = *(const pkg_t **)p1;
  11654. + const pkg_t *pkg2 = *(const pkg_t **)p2;
  11655. + if (pkg1->name == NULL)
  11656. + return 1;
  11657. + if (pkg2->name == NULL)
  11658. + return -1;
  11659. + return(strcmp(pkg1->name, pkg2->name));
  11660. +}
  11661. +
  11662. +
  11663. +static void pkg_hash_fetch_available_helper(const char *pkg_name, void *entry, void *data)
  11664. +{
  11665. + int j;
  11666. + const char *name;
  11667. + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
  11668. + pkg_vec_t *all = (pkg_vec_t *)data;
  11669. + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
  11670. + name = pkg_name;
  11671. + if (pkg_vec) {
  11672. + for (j = 0; j < pkg_vec->len; j++) {
  11673. + pkg_t *pkg = pkg_vec->pkgs[j];
  11674. + pkg_vec_insert(all, pkg);
  11675. + }
  11676. + }
  11677. +}
  11678. +
  11679. +void pkg_hash_fetch_available(hash_table_t *hash, pkg_vec_t *all)
  11680. +{
  11681. + hash_table_foreach(hash, pkg_hash_fetch_available_helper, all);
  11682. + qsort(all->pkgs, all->len, sizeof(pkg_t *), pkg_compare_names);
  11683. +}
  11684. +
  11685. +static void pkg_hash_fetch_all_installed_helper(const char *pkg_name, void *entry, void *data)
  11686. +{
  11687. + const char *name;
  11688. + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
  11689. + pkg_vec_t *all = (pkg_vec_t *)data;
  11690. + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
  11691. + int j;
  11692. + name = pkg_name;
  11693. + if (pkg_vec) {
  11694. + for (j = 0; j < pkg_vec->len; j++) {
  11695. + pkg_t *pkg = pkg_vec->pkgs[j];
  11696. + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) {
  11697. + pkg_vec_insert(all, pkg);
  11698. + }
  11699. + }
  11700. + }
  11701. +}
  11702. +void pkg_hash_fetch_all_installed(hash_table_t *hash, pkg_vec_t *all)
  11703. +{
  11704. + hash_table_foreach(hash, pkg_hash_fetch_all_installed_helper, all);
  11705. + qsort(all->pkgs, all->len, sizeof(void*), pkg_compare_names);
  11706. +}
  11707. +
  11708. +static void pkg_hash_dump_helper(const char *pkg_name, void *entry, void *data)
  11709. +{
  11710. + int i;
  11711. + pkg_t *pkg;
  11712. + const char *name;
  11713. + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
  11714. + ipkg_conf_t *conf = (ipkg_conf_t *)data;
  11715. + abstract_pkg_t ** dependents = ab_pkg->depended_upon_by;
  11716. + name = pkg_name;
  11717. + fprintf(stdout, "%s\n", ab_pkg->name);
  11718. + i = 0;
  11719. + if (dependents != NULL)
  11720. + while (dependents [i] != NULL)
  11721. + printf ("\tdepended upon by - %s\n", dependents [i ++]->name);
  11722. + dependents = ab_pkg->provided_by->pkgs;
  11723. + i = 0;
  11724. + if (dependents != NULL)
  11725. + while (dependents [i] != NULL && i < ab_pkg->provided_by->len)
  11726. + printf ("\tprovided by - %s\n", dependents [i ++]->name);
  11727. + pkg = pkg_hash_fetch_best_installation_candidate_by_name (conf, ab_pkg->name);
  11728. + if (pkg) {
  11729. + i = 0;
  11730. + while (i < pkg->depends_count)
  11731. + printf ("\tdepends on - %s\n", pkg->depends_str [i ++]);
  11732. + }
  11733. +}
  11734. +void pkg_hash_dump(hash_table_t *hash, void *data)
  11735. +{
  11736. +
  11737. + printf ("\n\n+=+%s+=+\n\n", __FUNCTION__);
  11738. + hash_table_foreach(hash, pkg_hash_dump_helper, data);
  11739. + printf ("\n+=+%s+=+\n\n", __FUNCTION__);
  11740. +}
  11741. +
  11742. +abstract_pkg_t * ensure_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name)
  11743. +{
  11744. + abstract_pkg_t * ab_pkg;
  11745. +
  11746. + if(!(ab_pkg = abstract_pkg_fetch_by_name(hash, pkg_name)))
  11747. + ab_pkg = add_new_abstract_pkg_by_name(hash, pkg_name);
  11748. +
  11749. + return ab_pkg;
  11750. +}
  11751. +
  11752. +pkg_t *hash_insert_pkg(hash_table_t *hash, pkg_t *pkg, int set_status,ipkg_conf_t *conf)
  11753. +{
  11754. + abstract_pkg_t * ab_pkg;
  11755. + int arch_priority;
  11756. +
  11757. + if(!pkg)
  11758. + return pkg;
  11759. +
  11760. + arch_priority = pkg->arch_priority;
  11761. +
  11762. + if (buildDepends(hash, pkg)<0){
  11763. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  11764. + return NULL;
  11765. + }
  11766. + ab_pkg = ensure_abstract_pkg_by_name(hash, pkg->name);
  11767. +
  11768. + if (set_status) {
  11769. + if (pkg->state_status == SS_INSTALLED) {
  11770. + ab_pkg->state_status = SS_INSTALLED;
  11771. + } else if (pkg->state_status == SS_UNPACKED) {
  11772. + ab_pkg->state_status = SS_UNPACKED;
  11773. + }
  11774. + }
  11775. +
  11776. + if(!ab_pkg->pkgs)
  11777. + ab_pkg->pkgs = pkg_vec_alloc();
  11778. +
  11779. + /* pkg_vec_insert_merge might munge package, but it returns an unmunged pkg */
  11780. + pkg = pkg_vec_insert_merge(ab_pkg->pkgs, pkg, set_status,conf );
  11781. + pkg->parent = ab_pkg;
  11782. +
  11783. + if (buildProvides(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. + /* need to build the conflicts graph before replaces for correct calculation of replaced_by relation */
  11788. + if (buildConflicts(hash, pkg)<0){
  11789. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  11790. + return NULL;
  11791. + }
  11792. + if (buildReplaces(hash, ab_pkg, pkg)<0) {
  11793. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  11794. + return NULL;
  11795. + }
  11796. +
  11797. + buildDependedUponBy(pkg, ab_pkg);
  11798. + return pkg;
  11799. +}
  11800. +
  11801. +/*
  11802. + * this will assume that we've already determined that
  11803. + * the abstract pkg doesn't exist, 'cause we should know these things...
  11804. + */
  11805. +static abstract_pkg_t * add_new_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name)
  11806. +{
  11807. + abstract_pkg_t * ab_pkg;
  11808. +
  11809. + ab_pkg = abstract_pkg_new();
  11810. + if (ab_pkg == NULL) { return NULL; }
  11811. +
  11812. + ab_pkg->name = strdup(pkg_name);
  11813. + hash_table_insert(hash, pkg_name, ab_pkg);
  11814. +
  11815. + return ab_pkg;
  11816. +}
  11817. +
  11818. +
  11819. +pkg_t *file_hash_get_file_owner(ipkg_conf_t *conf, const char *file_name)
  11820. +{
  11821. + hash_table_t *file_hash = &conf->file_hash;
  11822. +
  11823. + return hash_table_get(file_hash, file_name);
  11824. +}
  11825. +
  11826. +int file_hash_set_file_owner(ipkg_conf_t *conf, const char *file_name, pkg_t *owning_pkg)
  11827. +{
  11828. + hash_table_t *file_hash = &conf->file_hash;
  11829. + pkg_t *old_owning_pkg = hash_table_get(file_hash, file_name);
  11830. + int file_name_len = strlen(file_name);
  11831. +
  11832. + if (file_name[file_name_len -1] == '/')
  11833. + return 0;
  11834. +
  11835. + if (conf->offline_root) {
  11836. + int len = strlen(conf->offline_root);
  11837. + if (strncmp(file_name, conf->offline_root, len) == 0) {
  11838. + file_name += len;
  11839. + }
  11840. + }
  11841. +
  11842. + // ipkg_message(conf, IPKG_DEBUG2, "owning_pkg=%s filename=%s\n", owning_pkg->name, file_name);
  11843. + hash_table_insert(file_hash, file_name, owning_pkg);
  11844. + if (old_owning_pkg) {
  11845. + str_list_remove_elt(old_owning_pkg->installed_files, file_name);
  11846. + /* mark this package to have its filelist written */
  11847. + old_owning_pkg->state_flag |= SF_FILELIST_CHANGED;
  11848. + owning_pkg->state_flag |= SF_FILELIST_CHANGED;
  11849. + }
  11850. + return 0;
  11851. +}
  11852. +
  11853. +
  11854. diff -Nur busybox-1.16.1.orig/archival/libipkg/pkg_hash.h busybox-1.16.1/archival/libipkg/pkg_hash.h
  11855. --- busybox-1.16.1.orig/archival/libipkg/pkg_hash.h 1970-01-01 01:00:00.000000000 +0100
  11856. +++ busybox-1.16.1/archival/libipkg/pkg_hash.h 2010-06-29 17:31:25.005861391 +0200
  11857. @@ -0,0 +1,61 @@
  11858. +/* pkg_hash.h - the itsy package management system
  11859. +
  11860. + Steven M. Ayer
  11861. +
  11862. + Copyright (C) 2002 Compaq Computer Corporation
  11863. +
  11864. + This program is free software; you can redistribute it and/or
  11865. + modify it under the terms of the GNU General Public License as
  11866. + published by the Free Software Foundation; either version 2, or (at
  11867. + your option) any later version.
  11868. +
  11869. + This program is distributed in the hope that it will be useful, but
  11870. + WITHOUT ANY WARRANTY; without even the implied warranty of
  11871. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11872. + General Public License for more details.
  11873. +*/
  11874. +
  11875. +#ifndef PKG_HASH_H
  11876. +#define PKG_HASH_H
  11877. +
  11878. +#include "pkg.h"
  11879. +#include "pkg_vec.h"
  11880. +#include "hash_table.h"
  11881. +
  11882. +
  11883. +int pkg_hash_init(const char *name, hash_table_t *hash, int len);
  11884. +void pkg_hash_deinit(hash_table_t *hash);
  11885. +void pkg_hash_map(hash_table_t *hash, void (*f)(void *data, void *entry), void *data);
  11886. +
  11887. +void pkg_hash_dump(hash_table_t *hash, void *data);
  11888. +void pkg_hash_fetch_available(hash_table_t *hash, pkg_vec_t *available);
  11889. +
  11890. +int pkg_hash_add_from_file(ipkg_conf_t *conf, const char *file_name,
  11891. + pkg_src_t *src, pkg_dest_t *dest, int is_status_file);
  11892. +pkg_t *hash_insert_pkg(hash_table_t *hash, pkg_t *pkg, int set_status,ipkg_conf_t *conf);
  11893. +
  11894. +abstract_pkg_t * ensure_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name);
  11895. +abstract_pkg_t * abstract_pkg_fetch_by_name(hash_table_t * hash, const char * pkg_name);
  11896. +pkg_vec_t *pkg_hash_fetch_by_name(hash_table_t *hash, const char *pkg_name);
  11897. +void pkg_hash_fetch_all_installed(hash_table_t *hash, pkg_vec_t *installed);
  11898. +pkg_t * pkg_hash_fetch_by_name_version(hash_table_t *hash,
  11899. + const char *pkg_name,
  11900. + const char * version);
  11901. +abstract_pkg_vec_t *pkg_hash_fetch_all_installation_candidates(hash_table_t *hash, const char *name);
  11902. +pkg_t *pkg_hash_fetch_best_installation_candidate(ipkg_conf_t *conf, abstract_pkg_t *apkg,
  11903. + int (*constraint_fcn)(pkg_t *pkg, void *data), void *cdata, int quiet);
  11904. +pkg_t *pkg_hash_fetch_best_installation_candidate_by_name(ipkg_conf_t *conf, const char *name);
  11905. +pkg_t *pkg_hash_fetch_installed_by_name(hash_table_t *hash,
  11906. + const char *pkg_name);
  11907. +pkg_t *pkg_hash_fetch_installed_by_name_dest(hash_table_t *hash,
  11908. + const char *pkg_name,
  11909. + pkg_dest_t *dest);
  11910. +
  11911. +pkg_t *file_hash_get_file_owner(ipkg_conf_t *conf, const char *file_name);
  11912. +int file_hash_set_file_owner(ipkg_conf_t *conf, const char *file_name, pkg_t *pkg);
  11913. +
  11914. +/* XXX: shouldn't this go in pkg_vec.[ch]? */
  11915. +pkg_vec_t *pkg_vec_fetch_by_name(hash_table_t *hash, const char *pkg_name);
  11916. +
  11917. +#endif
  11918. +
  11919. diff -Nur busybox-1.16.1.orig/archival/libipkg/pkg_parse.c busybox-1.16.1/archival/libipkg/pkg_parse.c
  11920. --- busybox-1.16.1.orig/archival/libipkg/pkg_parse.c 1970-01-01 01:00:00.000000000 +0100
  11921. +++ busybox-1.16.1/archival/libipkg/pkg_parse.c 2010-06-29 17:31:25.059133294 +0200
  11922. @@ -0,0 +1,368 @@
  11923. +/* pkg_parse.c - the itsy package management system
  11924. +
  11925. + Steven M. Ayer
  11926. +
  11927. + Copyright (C) 2002 Compaq Computer Corporation
  11928. +
  11929. + This program is free software; you can redistribute it and/or
  11930. + modify it under the terms of the GNU General Public License as
  11931. + published by the Free Software Foundation; either version 2, or (at
  11932. + your option) any later version.
  11933. +
  11934. + This program is distributed in the hope that it will be useful, but
  11935. + WITHOUT ANY WARRANTY; without even the implied warranty of
  11936. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11937. + General Public License for more details.
  11938. +*/
  11939. +
  11940. +#include "ipkg.h"
  11941. +#include <errno.h>
  11942. +#include <ctype.h>
  11943. +
  11944. +#include "pkg.h"
  11945. +#include "ipkg_utils.h"
  11946. +#include "pkg_parse.h"
  11947. +
  11948. +int alterProvidesLine(char *raw, char *temp);
  11949. +
  11950. +int isGenericFieldType(char * type, char * line)
  11951. +{
  11952. + if(!strncmp(line, type, strlen(type)))
  11953. + return 1;
  11954. + return 0;
  11955. +}
  11956. +
  11957. +char * parseGenericFieldType(char * type, char * raw)
  11958. +{
  11959. + char * field_value = raw + (strlen(type) + 1);
  11960. + return trim_alloc(field_value);
  11961. +}
  11962. +
  11963. +void parseStatus(pkg_t *pkg, char * raw)
  11964. +{
  11965. + char sw_str[64], sf_str[64], ss_str[64];
  11966. +
  11967. + sscanf(raw, "Status: %s %s %s", sw_str, sf_str, ss_str);
  11968. + pkg->state_want = pkg_state_want_from_str(sw_str);
  11969. + pkg->state_flag = pkg_state_flag_from_str(sf_str);
  11970. + pkg->state_status = pkg_state_status_from_str(ss_str);
  11971. +}
  11972. +
  11973. +char ** parseDependsString(char * raw, int * depends_count)
  11974. +{
  11975. + char ** depends = NULL;
  11976. + int line_count = 0;
  11977. + char buff[2048], * dest;
  11978. +
  11979. + while(raw && *raw && !isspace(*raw)) {
  11980. + raw++;
  11981. + }
  11982. +
  11983. + if(line_is_blank(raw)){
  11984. + *depends_count = line_count;
  11985. + return NULL;
  11986. + }
  11987. + while(raw && *raw){
  11988. + depends = (char **)realloc(depends, sizeof(char *) * (line_count + 1));
  11989. +
  11990. + while(isspace(*raw)) raw++;
  11991. +
  11992. + dest = buff;
  11993. + while((*raw != ',') && *raw)
  11994. + *dest++ = *raw++;
  11995. +
  11996. + *dest = '\0';
  11997. + depends[line_count] = trim_alloc(buff);
  11998. + if(depends[line_count] ==NULL)
  11999. + return NULL;
  12000. + line_count++;
  12001. + if(*raw == ',')
  12002. + raw++;
  12003. + }
  12004. + *depends_count = line_count;
  12005. + return depends;
  12006. +}
  12007. +
  12008. +void parseConffiles(pkg_t * pkg, char * raw)
  12009. +{
  12010. + char file_name[1048], md5sum[1048]; /* please tell me there aren't any longer that 1k */
  12011. +
  12012. + if(!strncmp(raw, "Conffiles:", 10))
  12013. + raw += strlen("Conffiles:");
  12014. +
  12015. + while(*raw && (sscanf(raw, "%s%s", file_name, md5sum) == 2)){
  12016. + conffile_list_append(&pkg->conffiles, file_name, md5sum);
  12017. + /* fprintf(stderr, "%s %s ", file_name, md5sum);*/
  12018. + while (*raw && isspace(*raw)) {
  12019. + raw++;
  12020. + }
  12021. + raw += strlen(file_name);
  12022. + while (*raw && isspace(*raw)) {
  12023. + raw++;
  12024. + }
  12025. + raw += strlen(md5sum);
  12026. + }
  12027. +}
  12028. +
  12029. +int parseVersion(pkg_t *pkg, char *raw)
  12030. +{
  12031. + char *colon, *eepochcolon;
  12032. +#ifdef USE_DEBVERSION
  12033. + char *hyphen;
  12034. +#endif
  12035. + unsigned long epoch;
  12036. +
  12037. + if (!*raw) {
  12038. + fprintf(stderr, "%s: ERROR: version string is empty", __FUNCTION__);
  12039. + return EINVAL;
  12040. + }
  12041. +
  12042. + if (strncmp(raw, "Version:", 8) == 0) {
  12043. + raw += 8;
  12044. + }
  12045. + while (*raw && isspace(*raw)) {
  12046. + raw++;
  12047. + }
  12048. +
  12049. + colon= strchr(raw,':');
  12050. + if (colon) {
  12051. + epoch= strtoul(raw,&eepochcolon,10);
  12052. + if (colon != eepochcolon) {
  12053. + fprintf(stderr, "%s: ERROR: epoch in version is not number", __FUNCTION__);
  12054. + return EINVAL;
  12055. + }
  12056. + if (!*++colon) {
  12057. + fprintf(stderr, "%s: ERROR: nothing after colon in version number", __FUNCTION__);
  12058. + return EINVAL;
  12059. + }
  12060. + raw= colon;
  12061. + pkg->epoch= epoch;
  12062. + } else {
  12063. + pkg->epoch= 0;
  12064. + }
  12065. +
  12066. + pkg->revision = (char *)"";
  12067. + pkg->familiar_revision = (char *)"";
  12068. +
  12069. + pkg->version= malloc(strlen(raw)+1);
  12070. + if ( pkg->version == NULL ) {
  12071. + fprintf(stderr, "%s: out of memory \n", __FUNCTION__);
  12072. + return ENOMEM;
  12073. + }
  12074. + strcpy(pkg->version, raw);
  12075. +
  12076. +#ifdef USE_DEBVERSION
  12077. + hyphen= strrchr(pkg->version,'-');
  12078. +
  12079. + if (hyphen) {
  12080. + *hyphen++= 0;
  12081. + if (strncmp("fam", hyphen, 3) == 0) {
  12082. + pkg->familiar_revision=hyphen+3;
  12083. + hyphen= strrchr(pkg->version,'-');
  12084. + if (hyphen) {
  12085. + *hyphen++= 0;
  12086. + pkg->revision = hyphen;
  12087. + }
  12088. + } else {
  12089. + pkg->revision = hyphen;
  12090. + }
  12091. + }
  12092. +#endif
  12093. +
  12094. +/*
  12095. + fprintf(stderr,"Parsed version: %lu, %s, %s, %s\n",
  12096. + pkg->epoch,
  12097. + pkg->version,
  12098. + pkg->revision,
  12099. + pkg->familiar_revision);
  12100. +*/
  12101. +
  12102. + return 0;
  12103. +}
  12104. +
  12105. +
  12106. +/* This code is needed to insert in first position the keyword for the aligning bug */
  12107. +
  12108. +int alterProvidesLine(char *raw, char *temp)
  12109. +{
  12110. +
  12111. +
  12112. + if (!*raw) {
  12113. + fprintf(stderr, "%s: ERROR: Provides string is empty", __FUNCTION__);
  12114. + return -EINVAL;
  12115. + }
  12116. +
  12117. + if ( temp == NULL ) {
  12118. + fprintf(stderr, "%s: out of memory \n", __FUNCTION__);
  12119. + return -ENOMEM;
  12120. + }
  12121. +
  12122. + if (strncmp(raw, "Provides:", 9) == 0) {
  12123. + raw += 9;
  12124. + }
  12125. + while (*raw && isspace(*raw)) {
  12126. + raw++;
  12127. + }
  12128. +
  12129. + snprintf ( temp, 35, "Provides: ipkg_internal_use_only, "); /* First part of the line */
  12130. + while (*raw) {
  12131. + strncat( temp, raw++, 1);
  12132. + }
  12133. + return 0;
  12134. +
  12135. +}
  12136. +
  12137. +/* Some random thoughts from Carl:
  12138. +
  12139. + This function could be considerably simplified if we just kept
  12140. + an array of all the generic string-valued field names, and looped
  12141. + through those looking for a match. Also, these fields could perhaps
  12142. + be stored in the package as an array as well, (or, probably better,
  12143. + as an nv_pair_list_t).
  12144. +
  12145. + Fields which require special parsing or storage, (such as Depends:
  12146. + and Status:) could be handled as they are now.
  12147. +*/
  12148. +/* XXX: FEATURE: The Suggests: field needs to be changed from a string
  12149. + to a dependency list. And, since we already have
  12150. + Depends/Pre-Depends and need to add Conflicts, Recommends, and
  12151. + Enhances, perhaps we could generalize all of these and save some
  12152. + code duplication.
  12153. +*/
  12154. +int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest)
  12155. +{
  12156. + int reading_conffiles, reading_description;
  12157. + int pkg_false_provides=1;
  12158. + char ** lines;
  12159. + char * provide=NULL;
  12160. +
  12161. + pkg->src = src;
  12162. + pkg->dest = dest;
  12163. +
  12164. + reading_conffiles = reading_description = 0;
  12165. +
  12166. + for (lines = *raw; *lines; lines++) {
  12167. + /* fprintf(stderr, "PARSING %s\n", *lines);*/
  12168. + if(isGenericFieldType((char *)"Package:", *lines))
  12169. + pkg->name = parseGenericFieldType((char *)"Package", *lines);
  12170. + else if(isGenericFieldType((char *)"Architecture:", *lines))
  12171. + pkg->architecture = parseGenericFieldType((char *)"Architecture", *lines);
  12172. + else if(isGenericFieldType((char *)"Filename:", *lines))
  12173. + pkg->filename = parseGenericFieldType((char *)"Filename", *lines);
  12174. + else if(isGenericFieldType((char *)"Section:", *lines))
  12175. + pkg->section = parseGenericFieldType((char *)"Section", *lines);
  12176. + else if(isGenericFieldType((char *)"MD5sum:", *lines))
  12177. + pkg->md5sum = parseGenericFieldType((char *)"MD5sum", *lines);
  12178. + /* The old ipkg wrote out status files with the wrong case for MD5sum,
  12179. + let's parse it either way */
  12180. + else if(isGenericFieldType((char *)"MD5Sum:", *lines))
  12181. + pkg->md5sum = parseGenericFieldType((char *)"MD5Sum", *lines);
  12182. + else if(isGenericFieldType((char *)"Size:", *lines))
  12183. + pkg->size = parseGenericFieldType((char *)"Size", *lines);
  12184. + else if(isGenericFieldType((char *)"Source:", *lines))
  12185. + pkg->source = parseGenericFieldType((char *)"Source", *lines);
  12186. + else if(isGenericFieldType((char *)"Installed-Size:", *lines))
  12187. + pkg->installed_size = parseGenericFieldType((char *)"Installed-Size", *lines);
  12188. + else if(isGenericFieldType((char *)"Installed-Time:", *lines)) {
  12189. + char *time_str = parseGenericFieldType((char *)"Installed-Time", *lines);
  12190. + pkg->installed_time = strtoul(time_str, NULL, 0);
  12191. + } else if(isGenericFieldType((char *)"Priority:", *lines))
  12192. + pkg->priority = parseGenericFieldType((char *)"Priority", *lines);
  12193. + else if(isGenericFieldType((char *)"Essential:", *lines)) {
  12194. + char *essential_value;
  12195. + essential_value = parseGenericFieldType((char *)"Essential", *lines);
  12196. + if (strcmp(essential_value, "yes") == 0) {
  12197. + pkg->essential = 1;
  12198. + }
  12199. + free(essential_value);
  12200. + }
  12201. + else if(isGenericFieldType((char *)"Status", *lines))
  12202. + parseStatus(pkg, *lines);
  12203. + else if(isGenericFieldType((char *)"Version", *lines))
  12204. + parseVersion(pkg, *lines);
  12205. + else if(isGenericFieldType((char *)"Maintainer", *lines))
  12206. + pkg->maintainer = parseGenericFieldType((char *)"Maintainer", *lines);
  12207. + else if(isGenericFieldType((char *)"Conffiles", *lines)){
  12208. + parseConffiles(pkg, *lines);
  12209. + reading_conffiles = 1;
  12210. + }
  12211. + else if(isGenericFieldType((char *)"Description", *lines)) {
  12212. + pkg->description = parseGenericFieldType((char *)"Description", *lines);
  12213. + reading_conffiles = 0;
  12214. + reading_description = 1;
  12215. + }
  12216. +
  12217. + else if(isGenericFieldType((char *)"Provides", *lines)){
  12218. +/* Here we add the internal_use to align the off by one problem between provides_str and provides */
  12219. + provide = (char * ) malloc(strlen(*lines)+ 35 ); /* Preparing the space for the new ipkg_internal_use_only */
  12220. + if ( alterProvidesLine(*lines,provide) ){
  12221. + return EINVAL;
  12222. + }
  12223. + pkg->provides_str = parseDependsString( provide, &pkg->provides_count);
  12224. +/* Let's try to hack a bit here.
  12225. + The idea is that if a package has no Provides, we would add one generic, to permit the check of dependencies
  12226. + in alot of other places. We will remove it before writing down the status database */
  12227. + pkg_false_provides=0;
  12228. + free(provide);
  12229. + }
  12230. +
  12231. + else if(isGenericFieldType((char *)"Depends", *lines))
  12232. + pkg->depends_str = parseDependsString(*lines, &pkg->depends_count);
  12233. + else if(isGenericFieldType((char *)"Pre-Depends", *lines))
  12234. + pkg->pre_depends_str = parseDependsString(*lines, &pkg->pre_depends_count);
  12235. + else if(isGenericFieldType((char *)"Recommends", *lines))
  12236. + pkg->recommends_str = parseDependsString(*lines, &pkg->recommends_count);
  12237. + else if(isGenericFieldType((char *)"Suggests", *lines))
  12238. + pkg->suggests_str = parseDependsString(*lines, &pkg->suggests_count);
  12239. + /* Abhaya: support for conflicts */
  12240. + else if(isGenericFieldType((char *)"Conflicts", *lines))
  12241. + pkg->conflicts_str = parseDependsString(*lines, &pkg->conflicts_count);
  12242. + else if(isGenericFieldType((char *)"Replaces", *lines))
  12243. + pkg->replaces_str = parseDependsString(*lines, &pkg->replaces_count);
  12244. + else if(line_is_blank(*lines)) {
  12245. + lines++;
  12246. + break;
  12247. + }
  12248. + else if(**lines == ' '){
  12249. + if(reading_description) {
  12250. + /* we already know it's not blank, so the rest of description */
  12251. + pkg->description = realloc(pkg->description,
  12252. + strlen(pkg->description)
  12253. + + 1 + strlen(*lines) + 1);
  12254. + strcat(pkg->description, "\n");
  12255. + strcat(pkg->description, (*lines));
  12256. + }
  12257. + else if(reading_conffiles)
  12258. + parseConffiles(pkg, *lines);
  12259. + }
  12260. + }
  12261. + *raw = lines;
  12262. +/* If the ipk has not a Provides line, we insert our false line */
  12263. + if ( pkg_false_provides==1)
  12264. + pkg->provides_str = parseDependsString ((char *)"Provides: ipkg_internal_use_only ", &pkg->provides_count);
  12265. +
  12266. + if (pkg->name) {
  12267. + return 0;
  12268. + } else {
  12269. + return EINVAL;
  12270. + }
  12271. +}
  12272. +
  12273. +int pkg_valorize_other_field(pkg_t *pkg, char ***raw)
  12274. +{
  12275. + char ** lines;
  12276. +
  12277. + for (lines = *raw; *lines; lines++) {
  12278. + if(isGenericFieldType((char *)"Essential:", *lines)) {
  12279. + char *essential_value;
  12280. + essential_value = parseGenericFieldType((char *)"Essential", *lines);
  12281. + if (strcmp(essential_value, "yes") == 0) {
  12282. + pkg->essential = 1;
  12283. + }
  12284. + free(essential_value);
  12285. + }
  12286. + }
  12287. + *raw = lines;
  12288. +
  12289. + return 0;
  12290. +}
  12291. diff -Nur busybox-1.16.1.orig/archival/libipkg/pkg_parse.h busybox-1.16.1/archival/libipkg/pkg_parse.h
  12292. --- busybox-1.16.1.orig/archival/libipkg/pkg_parse.h 1970-01-01 01:00:00.000000000 +0100
  12293. +++ busybox-1.16.1/archival/libipkg/pkg_parse.h 2010-06-29 17:31:25.098367969 +0200
  12294. @@ -0,0 +1,31 @@
  12295. +/* pkg_parse.h - the itsy package management system
  12296. +
  12297. + Steven M. Ayer
  12298. +
  12299. + Copyright (C) 2002 Compaq Computer Corporation
  12300. +
  12301. + This program is free software; you can redistribute it and/or
  12302. + modify it under the terms of the GNU General Public License as
  12303. + published by the Free Software Foundation; either version 2, or (at
  12304. + your option) any later version.
  12305. +
  12306. + This program is distributed in the hope that it will be useful, but
  12307. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12308. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12309. + General Public License for more details.
  12310. +*/
  12311. +
  12312. +#ifndef PKG_PARSE_H
  12313. +#define PKG_PARSE_H
  12314. +
  12315. +int isGenericFieldType(char * type, char * line);
  12316. +char * parseGenericFieldType(char * type, char * raw);
  12317. +void parseStatus(pkg_t *pkg, char * raw);
  12318. +int parseVersion(pkg_t *pkg, char *raw);
  12319. +char ** parseDependsString(char * raw, int * depends_count);
  12320. +int parseVersion(pkg_t *pkg, char *raw);
  12321. +void parseConffiles(pkg_t * pkg, char * raw);
  12322. +int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest);
  12323. +int pkg_valorize_other_field(pkg_t *pkg, char ***raw);
  12324. +
  12325. +#endif
  12326. diff -Nur busybox-1.16.1.orig/archival/libipkg/pkg_src.c busybox-1.16.1/archival/libipkg/pkg_src.c
  12327. --- busybox-1.16.1.orig/archival/libipkg/pkg_src.c 1970-01-01 01:00:00.000000000 +0100
  12328. +++ busybox-1.16.1/archival/libipkg/pkg_src.c 2010-06-29 17:31:25.135873346 +0200
  12329. @@ -0,0 +1,43 @@
  12330. +/* pkg_src.c - the itsy package management system
  12331. +
  12332. + Carl D. Worth
  12333. +
  12334. + Copyright (C) 2001 University of Southern California
  12335. +
  12336. + This program is free software; you can redistribute it and/or
  12337. + modify it under the terms of the GNU General Public License as
  12338. + published by the Free Software Foundation; either version 2, or (at
  12339. + your option) any later version.
  12340. +
  12341. + This program is distributed in the hope that it will be useful, but
  12342. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12343. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12344. + General Public License for more details.
  12345. +*/
  12346. +
  12347. +#include "ipkg.h"
  12348. +
  12349. +#include "pkg_src.h"
  12350. +#include "str_util.h"
  12351. +
  12352. +int pkg_src_init(pkg_src_t *src, const char *name, const char *base_url, const char *extra_data, int gzip)
  12353. +{
  12354. + src->gzip = gzip;
  12355. + src->name = str_dup_safe (name);
  12356. + src->value = str_dup_safe (base_url);
  12357. + if (extra_data)
  12358. + src->extra_data = str_dup_safe (extra_data);
  12359. + else
  12360. + src->extra_data = NULL;
  12361. + return 0;
  12362. +}
  12363. +
  12364. +void pkg_src_deinit(pkg_src_t *src)
  12365. +{
  12366. + free (src->name);
  12367. + free (src->value);
  12368. + if (src->extra_data)
  12369. + free (src->extra_data);
  12370. +}
  12371. +
  12372. +
  12373. diff -Nur busybox-1.16.1.orig/archival/libipkg/pkg_src.h busybox-1.16.1/archival/libipkg/pkg_src.h
  12374. --- busybox-1.16.1.orig/archival/libipkg/pkg_src.h 1970-01-01 01:00:00.000000000 +0100
  12375. +++ busybox-1.16.1/archival/libipkg/pkg_src.h 2010-06-29 17:31:25.195873136 +0200
  12376. @@ -0,0 +1,34 @@
  12377. +/* pkg_src.h - the itsy package management system
  12378. +
  12379. + Carl D. Worth
  12380. +
  12381. + Copyright (C) 2001 University of Southern California
  12382. +
  12383. + This program is free software; you can redistribute it and/or
  12384. + modify it under the terms of the GNU General Public License as
  12385. + published by the Free Software Foundation; either version 2, or (at
  12386. + your option) any later version.
  12387. +
  12388. + This program is distributed in the hope that it will be useful, but
  12389. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12390. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12391. + General Public License for more details.
  12392. +*/
  12393. +
  12394. +#ifndef PKG_SRC_H
  12395. +#define PKG_SRC_H
  12396. +
  12397. +#include "nv_pair.h"
  12398. +
  12399. +typedef struct
  12400. +{
  12401. + char *name;
  12402. + char *value;
  12403. + char *extra_data;
  12404. + int gzip;
  12405. +} pkg_src_t;
  12406. +
  12407. +int pkg_src_init(pkg_src_t *src, const char *name, const char *base_url, const char *extra_data, int gzip);
  12408. +void pkg_src_deinit(pkg_src_t *src);
  12409. +
  12410. +#endif
  12411. diff -Nur busybox-1.16.1.orig/archival/libipkg/pkg_src_list.c busybox-1.16.1/archival/libipkg/pkg_src_list.c
  12412. --- busybox-1.16.1.orig/archival/libipkg/pkg_src_list.c 1970-01-01 01:00:00.000000000 +0100
  12413. +++ busybox-1.16.1/archival/libipkg/pkg_src_list.c 2010-06-29 17:31:25.238287396 +0200
  12414. @@ -0,0 +1,75 @@
  12415. +/* pkg_src_list.c - the itsy package management system
  12416. +
  12417. + Carl D. Worth
  12418. +
  12419. + Copyright (C) 2001 University of Southern California
  12420. +
  12421. + This program is free software; you can redistribute it and/or
  12422. + modify it under the terms of the GNU General Public License as
  12423. + published by the Free Software Foundation; either version 2, or (at
  12424. + your option) any later version.
  12425. +
  12426. + This program is distributed in the hope that it will be useful, but
  12427. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12428. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12429. + General Public License for more details.
  12430. +*/
  12431. +
  12432. +#include "ipkg.h"
  12433. +
  12434. +#include "pkg_src_list.h"
  12435. +#include "void_list.h"
  12436. +
  12437. +int pkg_src_list_init(pkg_src_list_t *list)
  12438. +{
  12439. + return void_list_init((void_list_t *) list);
  12440. +}
  12441. +
  12442. +void pkg_src_list_deinit(pkg_src_list_t *list)
  12443. +{
  12444. + pkg_src_list_elt_t *iter;
  12445. + pkg_src_t *pkg_src;
  12446. +
  12447. + for (iter = list->head; iter; iter = iter->next) {
  12448. + pkg_src = iter->data;
  12449. + pkg_src_deinit(pkg_src);
  12450. +
  12451. + /* malloced in pkg_src_list_append */
  12452. + free(pkg_src);
  12453. + iter->data = NULL;
  12454. + }
  12455. + void_list_deinit((void_list_t *) list);
  12456. +}
  12457. +
  12458. +pkg_src_t *pkg_src_list_append(pkg_src_list_t *list,
  12459. + const char *name, const char *base_url, const char *extra_data,
  12460. + int gzip)
  12461. +{
  12462. + int err;
  12463. +
  12464. + /* freed in pkg_src_list_deinit */
  12465. + pkg_src_t *pkg_src = malloc(sizeof(pkg_src_t));
  12466. +
  12467. + if (pkg_src == NULL) {
  12468. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  12469. + return NULL;
  12470. + }
  12471. + pkg_src_init(pkg_src, name, base_url, extra_data, gzip);
  12472. +
  12473. + err = void_list_append((void_list_t *) list, pkg_src);
  12474. + if (err) {
  12475. + return NULL;
  12476. + }
  12477. +
  12478. + return pkg_src;
  12479. +}
  12480. +
  12481. +int pkg_src_list_push(pkg_src_list_t *list, pkg_src_t *data)
  12482. +{
  12483. + return void_list_push((void_list_t *) list, data);
  12484. +}
  12485. +
  12486. +pkg_src_list_elt_t *pkg_src_list_pop(pkg_src_list_t *list)
  12487. +{
  12488. + return (pkg_src_list_elt_t *) void_list_pop((void_list_t *) list);
  12489. +}
  12490. diff -Nur busybox-1.16.1.orig/archival/libipkg/pkg_src_list.h busybox-1.16.1/archival/libipkg/pkg_src_list.h
  12491. --- busybox-1.16.1.orig/archival/libipkg/pkg_src_list.h 1970-01-01 01:00:00.000000000 +0100
  12492. +++ busybox-1.16.1/archival/libipkg/pkg_src_list.h 2010-06-29 17:31:25.278367968 +0200
  12493. @@ -0,0 +1,57 @@
  12494. +/* pkg_src_list.h - the itsy package management system
  12495. +
  12496. + Carl D. Worth
  12497. +
  12498. + Copyright (C) 2001 University of Southern California
  12499. +
  12500. + This program is free software; you can redistribute it and/or
  12501. + modify it under the terms of the GNU General Public License as
  12502. + published by the Free Software Foundation; either version 2, or (at
  12503. + your option) any later version.
  12504. +
  12505. + This program is distributed in the hope that it will be useful, but
  12506. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12507. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12508. + General Public License for more details.
  12509. +*/
  12510. +
  12511. +#ifndef PKG_SRC_LIST_H
  12512. +#define PKG_SRC_LIST_H
  12513. +
  12514. +#include "pkg_src.h"
  12515. +
  12516. +typedef struct pkg_src_list_elt pkg_src_list_elt_t;
  12517. +struct pkg_src_list_elt
  12518. +{
  12519. + pkg_src_list_elt_t *next;
  12520. + pkg_src_t *data;
  12521. +};
  12522. +
  12523. +typedef struct pkg_src_list pkg_src_list_t;
  12524. +struct pkg_src_list
  12525. +{
  12526. + pkg_src_list_elt_t pre_head;
  12527. + pkg_src_list_elt_t *head;
  12528. + pkg_src_list_elt_t *tail;
  12529. +};
  12530. +
  12531. +static inline int pkg_src_list_empty(pkg_src_list_t *list)
  12532. +{
  12533. + if (list->head == NULL)
  12534. + return 1;
  12535. + else
  12536. + return 0;
  12537. +}
  12538. +
  12539. +int pkg_src_list_elt_init(pkg_src_list_elt_t *elt, nv_pair_t *data);
  12540. +void pkg_src_list_elt_deinit(pkg_src_list_elt_t *elt);
  12541. +
  12542. +int pkg_src_list_init(pkg_src_list_t *list);
  12543. +void pkg_src_list_deinit(pkg_src_list_t *list);
  12544. +
  12545. +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);
  12546. +int pkg_src_list_push(pkg_src_list_t *list, pkg_src_t *data);
  12547. +pkg_src_list_elt_t *pkg_src_list_pop(pkg_src_list_t *list);
  12548. +
  12549. +#endif
  12550. +
  12551. diff -Nur busybox-1.16.1.orig/archival/libipkg/pkg_vec.c busybox-1.16.1/archival/libipkg/pkg_vec.c
  12552. --- busybox-1.16.1.orig/archival/libipkg/pkg_vec.c 1970-01-01 01:00:00.000000000 +0100
  12553. +++ busybox-1.16.1/archival/libipkg/pkg_vec.c 2010-06-29 17:31:25.319617983 +0200
  12554. @@ -0,0 +1,231 @@
  12555. +/* pkg_vec.c - the itsy package management system
  12556. +
  12557. + Steven M. Ayer
  12558. +
  12559. + Copyright (C) 2002 Compaq Computer Corporation
  12560. +
  12561. + This program is free software; you can redistribute it and/or
  12562. + modify it under the terms of the GNU General Public License as
  12563. + published by the Free Software Foundation; either version 2, or (at
  12564. + your option) any later version.
  12565. +
  12566. + This program is distributed in the hope that it will be useful, but
  12567. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12568. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12569. + General Public License for more details.
  12570. +*/
  12571. +
  12572. +#include <stdlib.h>
  12573. +#include <fnmatch.h>
  12574. +#include "libbb.h"
  12575. +#include "xregex.h"
  12576. +#include "ipkg.h"
  12577. +#include "pkg.h"
  12578. +
  12579. +pkg_vec_t * pkg_vec_alloc(void)
  12580. +{
  12581. + pkg_vec_t * vec = (pkg_vec_t *)malloc(sizeof(pkg_vec_t));
  12582. + if (!vec) {
  12583. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  12584. + return NULL;
  12585. + }
  12586. + vec->pkgs = NULL;
  12587. + vec->len = 0;
  12588. +
  12589. + return vec;
  12590. +}
  12591. +
  12592. +void pkg_vec_free(pkg_vec_t *vec)
  12593. +{
  12594. + free(vec->pkgs);
  12595. + free(vec);
  12596. +}
  12597. +
  12598. +/*
  12599. + * assumption: all names in a vector are identical
  12600. + * assumption: all version strings are trimmed,
  12601. + * so identical versions have identical version strings,
  12602. + * implying identical packages; let's marry these
  12603. + */
  12604. +pkg_t *pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status,ipkg_conf_t *conf)
  12605. +{
  12606. + int i;
  12607. + int found = 0;
  12608. +
  12609. + /* look for a duplicate pkg by name, version, and architecture */
  12610. + for (i = 0; i < vec->len; i++){
  12611. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Found pkg=%s version=%s arch=%s cmp=%s version=%s arch=%s \n",
  12612. + __FUNCTION__, pkg->name, pkg->version, pkg->architecture,
  12613. + vec->pkgs[i]->name, vec->pkgs[i]->version,vec->pkgs[i]->architecture );
  12614. + if ((strcmp(pkg->name, vec->pkgs[i]->name) == 0)
  12615. + && (pkg_compare_versions(pkg, vec->pkgs[i]) == 0)
  12616. + && (strcmp(pkg->architecture, vec->pkgs[i]->architecture) == 0)) {
  12617. + found = 1;
  12618. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Found duplicate for pkg=%s version=%s arch=%s\n",
  12619. + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
  12620. + break;
  12621. + }
  12622. + }
  12623. +
  12624. + /* we didn't find one, add it */
  12625. + if (!found){
  12626. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Adding new pkg=%s version=%s arch=%s\n",
  12627. + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
  12628. +
  12629. + vec->pkgs = (pkg_t **)realloc(vec->pkgs, (vec->len + 1) * sizeof(pkg_t *));
  12630. + vec->pkgs[vec->len] = pkg;
  12631. + vec->len++;
  12632. + return pkg;
  12633. + }
  12634. + /* update the one that we have */
  12635. + else {
  12636. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. calling pkg_merge for pkg=%s version=%s arch=%s",
  12637. + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
  12638. + if (set_status) {
  12639. + /* this is from the status file, so need to merge with existing database */
  12640. + ipkg_message(conf, IPKG_DEBUG2, " with set_status\n");
  12641. + pkg_merge(vec->pkgs[i], pkg, set_status);
  12642. + /* XXX: CLEANUP: It's not so polite to free something here
  12643. + that was passed in from above. */
  12644. + pkg_deinit(pkg);
  12645. + free(pkg);
  12646. + } else {
  12647. + ipkg_message(conf, IPKG_DEBUG2, " WITHOUT set_status\n");
  12648. + /* just overwrite the old one */
  12649. + pkg_deinit(vec->pkgs[i]);
  12650. + free(vec->pkgs[i]);
  12651. + vec->pkgs[i] = pkg;
  12652. + }
  12653. + return vec->pkgs[i];
  12654. + }
  12655. +}
  12656. +
  12657. +void pkg_vec_insert(pkg_vec_t *vec, const pkg_t *pkg)
  12658. +{
  12659. + int i;
  12660. + int found = 0;
  12661. +
  12662. + /* look for a duplicate pkg by name, version, and architecture */
  12663. + for (i = 0; i < vec->len; i++)
  12664. + if ((strcmp(pkg->name, vec->pkgs[i]->name) == 0)
  12665. + && (pkg_compare_versions(pkg, vec->pkgs[i]) == 0)
  12666. + && (strcmp(pkg->architecture, vec->pkgs[i]->name) == 0)) {
  12667. + found = 1;
  12668. + break;
  12669. + }
  12670. +
  12671. + /* we didn't find one, add it */
  12672. + if(!found){
  12673. + vec->pkgs = (pkg_t **)realloc(vec->pkgs, (vec->len + 1) * sizeof(pkg_t *));
  12674. + *(const pkg_t **)&vec->pkgs[vec->len] = pkg;
  12675. + vec->len++;
  12676. + }
  12677. +}
  12678. +
  12679. +int pkg_vec_contains(pkg_vec_t *vec, pkg_t *apkg)
  12680. +{
  12681. + int i;
  12682. + for (i = 0; i < vec->len; i++)
  12683. + if (vec->pkgs[i] == apkg)
  12684. + return 1;
  12685. + return 0;
  12686. +}
  12687. +
  12688. +typedef int (*compare_fcn_t)(const void *, const void *);
  12689. +void pkg_vec_sort(pkg_vec_t *vec, int (*compar)(pkg_t *, pkg_t *))
  12690. +{
  12691. + qsort(vec->pkgs, vec->len, sizeof(pkg_t *), (compare_fcn_t)compar);
  12692. +}
  12693. +
  12694. +int pkg_vec_clear_marks(pkg_vec_t *vec)
  12695. +{
  12696. + int npkgs = vec->len;
  12697. + int i;
  12698. + for (i = 0; i < npkgs; i++) {
  12699. + pkg_t *pkg = vec->pkgs[i];
  12700. + pkg->state_flag &= ~SF_MARKED;
  12701. + }
  12702. + return 0;
  12703. +}
  12704. +
  12705. +int pkg_vec_mark_if_matches(pkg_vec_t *vec, const char *pattern)
  12706. +{
  12707. + int matching_count = 0;
  12708. + pkg_t **pkgs = vec->pkgs;
  12709. + int npkgs = vec->len;
  12710. + int i;
  12711. + for (i = 0; i < npkgs; i++) {
  12712. + pkg_t *pkg = pkgs[i];
  12713. + if (fnmatch(pattern, pkg->name, 0)==0) {
  12714. + pkg->state_flag |= SF_MARKED;
  12715. + matching_count++;
  12716. + }
  12717. + }
  12718. + return matching_count;
  12719. +}
  12720. +
  12721. +
  12722. +abstract_pkg_vec_t * abstract_pkg_vec_alloc(void)
  12723. +{
  12724. + abstract_pkg_vec_t * vec ;
  12725. + vec = (abstract_pkg_vec_t *)malloc(sizeof(abstract_pkg_vec_t));
  12726. + if (!vec) {
  12727. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  12728. + return NULL;
  12729. + }
  12730. + vec->pkgs = NULL;
  12731. + vec->len = 0;
  12732. +
  12733. + return vec;
  12734. +}
  12735. +
  12736. +void abstract_pkg_vec_free(abstract_pkg_vec_t *vec)
  12737. +{
  12738. + free(vec->pkgs);
  12739. + free(vec);
  12740. +}
  12741. +
  12742. +/*
  12743. + * assumption: all names in a vector are unique
  12744. + */
  12745. +void abstract_pkg_vec_insert(abstract_pkg_vec_t *vec, abstract_pkg_t *pkg)
  12746. +{
  12747. + int i;
  12748. +
  12749. + /* look for a duplicate pkg by name */
  12750. + for(i = 0; i < vec->len; i++)
  12751. + if (strcmp(pkg->name, vec->pkgs[i]->name) == 0)
  12752. + break;
  12753. +
  12754. + /* we didn't find one, add it */
  12755. + if(i == vec->len){
  12756. + vec->pkgs =
  12757. + (abstract_pkg_t **)
  12758. + realloc(vec->pkgs, (vec->len + 1) * sizeof(abstract_pkg_t *));
  12759. + vec->pkgs[vec->len] = pkg;
  12760. + vec->len++;
  12761. + }
  12762. +}
  12763. +
  12764. +abstract_pkg_t * abstract_pkg_vec_get(abstract_pkg_vec_t *vec, int i)
  12765. +{
  12766. + if (vec->len > i)
  12767. + return vec->pkgs[i];
  12768. + else
  12769. + return NULL;
  12770. +}
  12771. +
  12772. +int abstract_pkg_vec_contains(abstract_pkg_vec_t *vec, abstract_pkg_t *apkg)
  12773. +{
  12774. + int i;
  12775. + for (i = 0; i < vec->len; i++)
  12776. + if (vec->pkgs[i] == apkg)
  12777. + return 1;
  12778. + return 0;
  12779. +}
  12780. +
  12781. +void abstract_pkg_vec_sort(pkg_vec_t *vec, int (*compar)(abstract_pkg_t *, abstract_pkg_t *))
  12782. +{
  12783. + qsort(vec->pkgs, vec->len, sizeof(pkg_t *), (compare_fcn_t)compar);
  12784. +}
  12785. +
  12786. diff -Nur busybox-1.16.1.orig/archival/libipkg/pkg_vec.h busybox-1.16.1/archival/libipkg/pkg_vec.h
  12787. --- busybox-1.16.1.orig/archival/libipkg/pkg_vec.h 1970-01-01 01:00:00.000000000 +0100
  12788. +++ busybox-1.16.1/archival/libipkg/pkg_vec.h 2010-06-29 17:31:25.358368186 +0200
  12789. @@ -0,0 +1,62 @@
  12790. +/* pkg_vec.h - the itsy package management system
  12791. +
  12792. + Steven M. Ayer
  12793. +
  12794. + Copyright (C) 2002 Compaq Computer Corporation
  12795. +
  12796. + This program is free software; you can redistribute it and/or
  12797. + modify it under the terms of the GNU General Public License as
  12798. + published by the Free Software Foundation; either version 2, or (at
  12799. + your option) any later version.
  12800. +
  12801. + This program is distributed in the hope that it will be useful, but
  12802. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12803. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12804. + General Public License for more details.
  12805. +*/
  12806. +
  12807. +#ifndef PKG_VEC_H
  12808. +#define PKG_VEC_H
  12809. +
  12810. +typedef struct pkg pkg_t;
  12811. +typedef struct abstract_pkg abstract_pkg_t;
  12812. +
  12813. +struct pkg_vec
  12814. +{
  12815. + pkg_t **pkgs;
  12816. + int len;
  12817. +};
  12818. +typedef struct pkg_vec pkg_vec_t;
  12819. +
  12820. +struct abstract_pkg_vec
  12821. +{
  12822. + abstract_pkg_t **pkgs;
  12823. + int len;
  12824. +};
  12825. +typedef struct abstract_pkg_vec abstract_pkg_vec_t;
  12826. +
  12827. +
  12828. +pkg_vec_t * pkg_vec_alloc(void);
  12829. +void pkg_vec_free(pkg_vec_t *vec);
  12830. +void marry_two_packages(pkg_t * newpkg, pkg_t * oldpkg);
  12831. +
  12832. +void pkg_vec_add(pkg_vec_t *vec, pkg_t *pkg);
  12833. +/* pkg_vec_insert_merge: might munge pkg.
  12834. +* returns the pkg that is in the pkg graph */
  12835. +pkg_t *pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status, ipkg_conf_t *conf);
  12836. +/* this one never munges pkg */
  12837. +void pkg_vec_insert(pkg_vec_t *vec, const pkg_t *pkg);
  12838. +int pkg_vec_contains(pkg_vec_t *vec, pkg_t *apkg);
  12839. +void pkg_vec_sort(pkg_vec_t *vec, int (*compar)(pkg_t *, pkg_t *));
  12840. +
  12841. +int pkg_vec_clear_marks(pkg_vec_t *vec);
  12842. +int pkg_vec_mark_if_matches(pkg_vec_t *vec, const char *pattern);
  12843. +
  12844. +abstract_pkg_vec_t * abstract_pkg_vec_alloc(void);
  12845. +void abstract_pkg_vec_free(abstract_pkg_vec_t *vec);
  12846. +void abstract_pkg_vec_insert(abstract_pkg_vec_t *vec, abstract_pkg_t *pkg);
  12847. +abstract_pkg_t * abstract_pkg_vec_get(abstract_pkg_vec_t *vec, int i);
  12848. +int abstract_pkg_vec_contains(abstract_pkg_vec_t *vec, abstract_pkg_t *apkg);
  12849. +void abstract_pkg_vec_sort(pkg_vec_t *vec, int (*compar)(abstract_pkg_t *, abstract_pkg_t *));
  12850. +#endif
  12851. +
  12852. diff -Nur busybox-1.16.1.orig/archival/libipkg/sprintf_alloc.h busybox-1.16.1/archival/libipkg/sprintf_alloc.h
  12853. --- busybox-1.16.1.orig/archival/libipkg/sprintf_alloc.h 1970-01-01 01:00:00.000000000 +0100
  12854. +++ busybox-1.16.1/archival/libipkg/sprintf_alloc.h 2010-06-29 17:31:25.395865857 +0200
  12855. @@ -0,0 +1,25 @@
  12856. +/* sprintf_alloca.c -- like sprintf with memory allocation
  12857. +
  12858. + Carl D. Worth
  12859. +
  12860. + Copyright (C) 2001 University of Southern California
  12861. +
  12862. + This program is free software; you can redistribute it and/or modify
  12863. + it under the terms of the GNU General Public License as published by
  12864. + the Free Software Foundation; either version 2, or (at your option)
  12865. + any later version.
  12866. +
  12867. + This program is distributed in the hope that it will be useful,
  12868. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  12869. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12870. + GNU General Public License for more details.
  12871. +*/
  12872. +
  12873. +#ifndef SPRINTF_ALLOC_H
  12874. +#define SPRINTF_ALLOC_H
  12875. +
  12876. +#include "libbb.h"
  12877. +
  12878. +#define sprintf_alloc(str, fmt, args...) *str = xasprintf(fmt, ## args)
  12879. +
  12880. +#endif
  12881. diff -Nur busybox-1.16.1.orig/archival/libipkg/str_list.c busybox-1.16.1/archival/libipkg/str_list.c
  12882. --- busybox-1.16.1.orig/archival/libipkg/str_list.c 1970-01-01 01:00:00.000000000 +0100
  12883. +++ busybox-1.16.1/archival/libipkg/str_list.c 2010-06-29 17:31:25.437577685 +0200
  12884. @@ -0,0 +1,76 @@
  12885. +/* str_list.c - the itsy package management system
  12886. +
  12887. + Carl D. Worth
  12888. +
  12889. + Copyright (C) 2001 University of Southern California
  12890. +
  12891. + This program is free software; you can redistribute it and/or
  12892. + modify it under the terms of the GNU General Public License as
  12893. + published by the Free Software Foundation; either version 2, or (at
  12894. + your option) any later version.
  12895. +
  12896. + This program is distributed in the hope that it will be useful, but
  12897. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12898. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12899. + General Public License for more details.
  12900. +*/
  12901. +
  12902. +#include "ipkg.h"
  12903. +
  12904. +#include "str_list.h"
  12905. +
  12906. +int str_list_elt_init(str_list_elt_t *elt, char *data)
  12907. +{
  12908. + return void_list_elt_init((void_list_elt_t *) elt, data);
  12909. +}
  12910. +
  12911. +void str_list_elt_deinit(str_list_elt_t *elt)
  12912. +{
  12913. + void_list_elt_deinit((void_list_elt_t *) elt);
  12914. +}
  12915. +
  12916. +str_list_t *str_list_alloc(void)
  12917. +{
  12918. + str_list_t *list = (str_list_t *)malloc(sizeof(str_list_t));
  12919. + if (list)
  12920. + str_list_init(list);
  12921. + return list;
  12922. +}
  12923. +
  12924. +int str_list_init(str_list_t *list)
  12925. +{
  12926. + return void_list_init((void_list_t *) list);
  12927. +}
  12928. +
  12929. +void str_list_deinit(str_list_t *list)
  12930. +{
  12931. + void_list_deinit((void_list_t *) list);
  12932. +}
  12933. +
  12934. +int str_list_append(str_list_t *list, char *data)
  12935. +{
  12936. + return void_list_append((void_list_t *) list, data);
  12937. +}
  12938. +
  12939. +int str_list_push(str_list_t *list, char *data)
  12940. +{
  12941. + return void_list_push((void_list_t *) list, data);
  12942. +}
  12943. +
  12944. +str_list_elt_t *str_list_pop(str_list_t *list)
  12945. +{
  12946. + return (str_list_elt_t *) void_list_pop((void_list_t *) list);
  12947. +}
  12948. +
  12949. +str_list_elt_t *str_list_remove(str_list_t *list, str_list_elt_t **iter)
  12950. +{
  12951. + return (str_list_elt_t *) void_list_remove((void_list_t *) list,
  12952. + (void_list_elt_t **) iter);
  12953. +}
  12954. +
  12955. +char *str_list_remove_elt(str_list_t *list, const char *target_str)
  12956. +{
  12957. + return (char *)void_list_remove_elt((void_list_t *) list,
  12958. + (void *)target_str,
  12959. + (void_list_cmp_t)strcmp);
  12960. +}
  12961. diff -Nur busybox-1.16.1.orig/archival/libipkg/str_list.h busybox-1.16.1/archival/libipkg/str_list.h
  12962. --- busybox-1.16.1.orig/archival/libipkg/str_list.h 1970-01-01 01:00:00.000000000 +0100
  12963. +++ busybox-1.16.1/archival/libipkg/str_list.h 2010-06-29 17:31:25.487410851 +0200
  12964. @@ -0,0 +1,51 @@
  12965. +/* str_list.h - the itsy package management system
  12966. +
  12967. + Carl D. Worth
  12968. +
  12969. + Copyright (C) 2001 University of Southern California
  12970. +
  12971. + This program is free software; you can redistribute it and/or
  12972. + modify it under the terms of the GNU General Public License as
  12973. + published by the Free Software Foundation; either version 2, or (at
  12974. + your option) any later version.
  12975. +
  12976. + This program is distributed in the hope that it will be useful, but
  12977. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12978. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12979. + General Public License for more details.
  12980. +*/
  12981. +
  12982. +#ifndef STR_LIST_H
  12983. +#define STR_LIST_H
  12984. +
  12985. +#include "void_list.h"
  12986. +
  12987. +typedef struct str_list_elt str_list_elt_t;
  12988. +struct str_list_elt
  12989. +{
  12990. + str_list_elt_t *next;
  12991. + char *data;
  12992. +};
  12993. +
  12994. +typedef struct xstr_list str_list_t;
  12995. +struct xstr_list
  12996. +{
  12997. + str_list_elt_t pre_head;
  12998. + str_list_elt_t *head;
  12999. + str_list_elt_t *tail;
  13000. +};
  13001. +
  13002. +int str_list_elt_init(str_list_elt_t *elt, char *data);
  13003. +void str_list_elt_deinit(str_list_elt_t *elt);
  13004. +
  13005. +str_list_t *str_list_alloc(void);
  13006. +int str_list_init(str_list_t *list);
  13007. +void str_list_deinit(str_list_t *list);
  13008. +
  13009. +int str_list_append(str_list_t *list, char *data);
  13010. +int str_list_push(str_list_t *list, char *data);
  13011. +str_list_elt_t *str_list_pop(str_list_t *list);
  13012. +str_list_elt_t *str_list_remove(str_list_t *list, str_list_elt_t **iter);
  13013. +char *str_list_remove_elt(str_list_t *list, const char *target_str);
  13014. +
  13015. +#endif
  13016. diff -Nur busybox-1.16.1.orig/archival/libipkg/str_util.c busybox-1.16.1/archival/libipkg/str_util.c
  13017. --- busybox-1.16.1.orig/archival/libipkg/str_util.c 1970-01-01 01:00:00.000000000 +0100
  13018. +++ busybox-1.16.1/archival/libipkg/str_util.c 2010-06-29 17:31:25.540714295 +0200
  13019. @@ -0,0 +1,69 @@
  13020. +/* str_utils.c - the itsy package management system
  13021. +
  13022. + Carl D. Worth
  13023. +
  13024. + Copyright (C) 2001 University of Southern California
  13025. +
  13026. + This program is free software; you can redistribute it and/or
  13027. + modify it under the terms of the GNU General Public License as
  13028. + published by the Free Software Foundation; either version 2, or (at
  13029. + your option) any later version.
  13030. +
  13031. + This program is distributed in the hope that it will be useful, but
  13032. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13033. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13034. + General Public License for more details.
  13035. +*/
  13036. +
  13037. +#include "ipkg.h"
  13038. +
  13039. +int str_starts_with(const char *str, const char *prefix);
  13040. +int str_ends_with(const char *str, const char *suffix);
  13041. +int str_chomp(char *str);
  13042. +int str_toupper(char *str);
  13043. +char *str_dup_safe(const char *str);
  13044. +
  13045. +int str_starts_with(const char *str, const char *prefix)
  13046. +{
  13047. + return (strncmp(str, prefix, strlen(prefix)) == 0);
  13048. +}
  13049. +
  13050. +int str_ends_with(const char *str, const char *suffix)
  13051. +{
  13052. + int suffix_len;
  13053. + int str_len;
  13054. +
  13055. + str_len = strlen(str);
  13056. + suffix_len = strlen(suffix);
  13057. +
  13058. + if (str_len < suffix_len) {
  13059. + return 0;
  13060. + }
  13061. +
  13062. + return (strcmp(str + str_len - suffix_len, suffix) == 0);
  13063. +}
  13064. +
  13065. +int str_chomp(char *str)
  13066. +{
  13067. + if (str[strlen(str) - 1] == '\n') {
  13068. + str[strlen(str) - 1] = '\0';
  13069. + return 1;
  13070. + }
  13071. + return 0;
  13072. +}
  13073. +
  13074. +int str_toupper(char *str)
  13075. +{
  13076. + while (*str) {
  13077. + *str = toupper(*str);
  13078. + str++;
  13079. + }
  13080. +
  13081. + return 0;
  13082. +}
  13083. +
  13084. +char *str_dup_safe(const char *str)
  13085. +{
  13086. + return str ? strdup(str) : NULL;
  13087. +}
  13088. +
  13089. diff -Nur busybox-1.16.1.orig/archival/libipkg/str_util.h busybox-1.16.1/archival/libipkg/str_util.h
  13090. --- busybox-1.16.1.orig/archival/libipkg/str_util.h 1970-01-01 01:00:00.000000000 +0100
  13091. +++ busybox-1.16.1/archival/libipkg/str_util.h 2010-06-29 17:31:25.578749246 +0200
  13092. @@ -0,0 +1,27 @@
  13093. +/* str_utils.h - the itsy package management system
  13094. +
  13095. + Carl D. Worth
  13096. +
  13097. + Copyright (C) 2001 University of Southern California
  13098. +
  13099. + This program is free software; you can redistribute it and/or
  13100. + modify it under the terms of the GNU General Public License as
  13101. + published by the Free Software Foundation; either version 2, or (at
  13102. + your option) any later version.
  13103. +
  13104. + This program is distributed in the hope that it will be useful, but
  13105. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13106. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13107. + General Public License for more details.
  13108. +*/
  13109. +
  13110. +#ifndef STR_UTILS_H
  13111. +#define STR_UTILS_H
  13112. +
  13113. +int str_starts_with(const char *str, const char *prefix);
  13114. +int str_ends_with(const char *str, const char *suffix);
  13115. +int str_chomp(char *str);
  13116. +int str_toupper(char *str);
  13117. +char *str_dup_safe(const char *str);
  13118. +
  13119. +#endif
  13120. diff -Nur busybox-1.16.1.orig/archival/libipkg/user.c busybox-1.16.1/archival/libipkg/user.c
  13121. --- busybox-1.16.1.orig/archival/libipkg/user.c 1970-01-01 01:00:00.000000000 +0100
  13122. +++ busybox-1.16.1/archival/libipkg/user.c 2010-06-29 17:31:25.628536327 +0200
  13123. @@ -0,0 +1,49 @@
  13124. +/* user.c - the itsy package management system
  13125. +
  13126. + Jamey Hicks
  13127. +
  13128. + Copyright (C) 2002 Hewlett Packard Company
  13129. + Copyright (C) 2001 University of Southern California
  13130. +
  13131. + This program is free software; you can redistribute it and/or
  13132. + modify it under the terms of the GNU General Public License as
  13133. + published by the Free Software Foundation; either version 2, or (at
  13134. + your option) any later version.
  13135. +
  13136. + This program is distributed in the hope that it will be useful, but
  13137. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13138. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13139. + General Public License for more details.
  13140. +*/
  13141. +
  13142. +#include <stdio.h>
  13143. +#include <stdarg.h>
  13144. +#include "libbb.h"
  13145. +#include "file_util.h"
  13146. +#include "str_util.h"
  13147. +#include "libipkg.h"
  13148. +
  13149. +char *get_user_response(const char *format, ...);
  13150. +static char *question = NULL;
  13151. +static int question_len = 255;
  13152. +
  13153. +char *get_user_response(const char *format, ...)
  13154. +{
  13155. + int len = question_len;
  13156. + va_list ap;
  13157. + char *response;
  13158. + va_start(ap, format);
  13159. +
  13160. + do {
  13161. + if (question == NULL || len > question_len) {
  13162. + question = realloc(question, len + 1);
  13163. + question_len = len;
  13164. + }
  13165. + len = vsnprintf(question,question_len,format,ap);
  13166. + } while (len > question_len);
  13167. + response = strdup(ipkg_cb_response(question));
  13168. + str_chomp(response);
  13169. + str_tolower(response);
  13170. +
  13171. + return response;
  13172. +}
  13173. diff -Nur busybox-1.16.1.orig/archival/libipkg/user.h busybox-1.16.1/archival/libipkg/user.h
  13174. --- busybox-1.16.1.orig/archival/libipkg/user.h 1970-01-01 01:00:00.000000000 +0100
  13175. +++ busybox-1.16.1/archival/libipkg/user.h 2010-06-29 17:31:25.678337891 +0200
  13176. @@ -0,0 +1,23 @@
  13177. +/* user.c - the itsy package management system
  13178. +
  13179. + Jamey Hicks
  13180. +
  13181. + Copyright (C) 2002 Hewlett Packard Company
  13182. + Copyright (C) 2001 University of Southern California
  13183. +
  13184. + This program is free software; you can redistribute it and/or
  13185. + modify it under the terms of the GNU General Public License as
  13186. + published by the Free Software Foundation; either version 2, or (at
  13187. + your option) any later version.
  13188. +
  13189. + This program is distributed in the hope that it will be useful, but
  13190. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13191. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13192. + General Public License for more details.
  13193. +*/
  13194. +
  13195. +#include <stdio.h>
  13196. +#include <stdarg.h>
  13197. +
  13198. +char *get_user_response(const char *format, ...);
  13199. +
  13200. diff -Nur busybox-1.16.1.orig/archival/libipkg/void_list.c busybox-1.16.1/archival/libipkg/void_list.c
  13201. --- busybox-1.16.1.orig/archival/libipkg/void_list.c 1970-01-01 01:00:00.000000000 +0100
  13202. +++ busybox-1.16.1/archival/libipkg/void_list.c 2010-06-29 17:31:25.715873105 +0200
  13203. @@ -0,0 +1,194 @@
  13204. +/* void_list.c - the itsy package management system
  13205. +
  13206. + Carl D. Worth
  13207. +
  13208. + Copyright (C) 2001 University of Southern California
  13209. +
  13210. + This program is free software; you can redistribute it and/or
  13211. + modify it under the terms of the GNU General Public License as
  13212. + published by the Free Software Foundation; either version 2, or (at
  13213. + your option) any later version.
  13214. +
  13215. + This program is distributed in the hope that it will be useful, but
  13216. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13217. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13218. + General Public License for more details.
  13219. +*/
  13220. +
  13221. +#include "ipkg.h"
  13222. +#include <errno.h>
  13223. +
  13224. +#include "void_list.h"
  13225. +
  13226. +int void_list_elt_init(void_list_elt_t *elt, void *data)
  13227. +{
  13228. + elt->next = NULL;
  13229. + elt->data = data;
  13230. +
  13231. + return 0;
  13232. +}
  13233. +
  13234. +void void_list_elt_deinit(void_list_elt_t *elt)
  13235. +{
  13236. + void_list_elt_init(elt, NULL);
  13237. +}
  13238. +
  13239. +int void_list_init(void_list_t *list)
  13240. +{
  13241. + void_list_elt_init(&list->pre_head, NULL);
  13242. + list->head = NULL;
  13243. + list->pre_head.next = list->head;
  13244. + list->tail = NULL;
  13245. +
  13246. + return 0;
  13247. +}
  13248. +
  13249. +void void_list_deinit(void_list_t *list)
  13250. +{
  13251. + void_list_elt_t *elt;
  13252. +
  13253. + while (list->head) {
  13254. + elt = void_list_pop(list);
  13255. + void_list_elt_deinit(elt);
  13256. + /* malloced in void_list_append */
  13257. + free(elt);
  13258. + }
  13259. +}
  13260. +
  13261. +int void_list_append(void_list_t *list, void *data)
  13262. +{
  13263. + void_list_elt_t *elt;
  13264. +
  13265. + /* freed in void_list_deinit */
  13266. + elt = malloc(sizeof(void_list_elt_t));
  13267. + if (elt == NULL) {
  13268. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  13269. + return ENOMEM;
  13270. + }
  13271. +
  13272. + void_list_elt_init(elt, data);
  13273. +
  13274. + if (list->tail) {
  13275. + list->tail->next = elt;
  13276. + list->tail = elt;
  13277. + } else {
  13278. + list->head = elt;
  13279. + list->pre_head.next = list->head;
  13280. + list->tail = elt;
  13281. + }
  13282. +
  13283. + return 0;
  13284. +}
  13285. +
  13286. +int void_list_push(void_list_t *list, void *data)
  13287. +{
  13288. + void_list_elt_t *elt;
  13289. +
  13290. + elt = malloc(sizeof(void_list_elt_t));
  13291. + if (elt == NULL) {
  13292. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  13293. + return ENOMEM;
  13294. + }
  13295. +
  13296. + void_list_elt_init(elt, data);
  13297. +
  13298. + elt->next = list->head;
  13299. + list->head->next = elt;
  13300. + if (list->tail == NULL) {
  13301. + list->tail = list->head;
  13302. + }
  13303. +
  13304. + return 0;
  13305. +}
  13306. +
  13307. +void_list_elt_t *void_list_pop(void_list_t *list)
  13308. +{
  13309. + void_list_elt_t *elt;
  13310. +
  13311. + elt = list->head;
  13312. +
  13313. + if (list->head) {
  13314. + list->head = list->head->next;
  13315. + list->pre_head.next = list->head;
  13316. + if (list->head == NULL) {
  13317. + list->tail = NULL;
  13318. + }
  13319. + }
  13320. +
  13321. + return elt;
  13322. +}
  13323. +
  13324. +void *void_list_remove(void_list_t *list, void_list_elt_t **iter)
  13325. +{
  13326. + void_list_elt_t *prior;
  13327. + void_list_elt_t *old_elt;
  13328. + void *old_data;
  13329. +
  13330. + old_elt = *iter;
  13331. + old_data = old_elt->data;
  13332. +
  13333. + if (old_elt == list->head) {
  13334. + prior = &list->pre_head;
  13335. + void_list_pop(list);
  13336. + } else {
  13337. + for (prior = list->head; prior; prior = prior->next) {
  13338. + if (prior->next == old_elt) {
  13339. + break;
  13340. + }
  13341. + }
  13342. + if (prior == NULL || prior->next != old_elt) {
  13343. + fprintf(stderr, "%s: ERROR: element not found in list\n", __FUNCTION__);
  13344. + return NULL;
  13345. + }
  13346. + prior->next = old_elt->next;
  13347. +
  13348. + if (old_elt == list->tail) {
  13349. + list->tail = prior;
  13350. + }
  13351. + }
  13352. +
  13353. + void_list_elt_deinit(old_elt);
  13354. + *iter = prior;
  13355. +
  13356. + return old_data;
  13357. +}
  13358. +
  13359. +/* remove element containing elt data, using cmp(elt->data, target_data) == 0. */
  13360. +void *void_list_remove_elt(void_list_t *list, const void *target_data, void_list_cmp_t cmp)
  13361. +{
  13362. + void_list_elt_t *prior;
  13363. + void_list_elt_t *old_elt = NULL;
  13364. + void *old_data = NULL;
  13365. +
  13366. + /* first element */
  13367. + if (list->head && list->head->data && (cmp(list->head->data, target_data) == 0)) {
  13368. + old_elt = list->head;
  13369. + old_data = list->head->data;
  13370. + void_list_pop(list);
  13371. + } else {
  13372. + int found = 0;
  13373. + for (prior = list->head; prior && prior->next; prior = prior->next) {
  13374. + if (prior->next->data && (cmp(prior->next->data, target_data) == 0)) {
  13375. + old_elt = prior->next;
  13376. + old_data = old_elt->data;
  13377. + found = 1;
  13378. + break;
  13379. + }
  13380. + }
  13381. + if (!found) {
  13382. + return NULL;
  13383. + }
  13384. + prior->next = old_elt->next;
  13385. +
  13386. + if (old_elt == list->tail) {
  13387. + list->tail = prior;
  13388. + }
  13389. + }
  13390. + if (old_elt)
  13391. + void_list_elt_deinit(old_elt);
  13392. +
  13393. + if (old_data)
  13394. + return old_data;
  13395. + else
  13396. + return NULL;
  13397. +}
  13398. diff -Nur busybox-1.16.1.orig/archival/libipkg/void_list.h busybox-1.16.1/archival/libipkg/void_list.h
  13399. --- busybox-1.16.1.orig/archival/libipkg/void_list.h 1970-01-01 01:00:00.000000000 +0100
  13400. +++ busybox-1.16.1/archival/libipkg/void_list.h 2010-06-29 17:31:25.758368030 +0200
  13401. @@ -0,0 +1,59 @@
  13402. +/* void_list.h - the itsy package management system
  13403. +
  13404. + Carl D. Worth
  13405. +
  13406. + Copyright (C) 2001 University of Southern California
  13407. +
  13408. + This program is free software; you can redistribute it and/or
  13409. + modify it under the terms of the GNU General Public License as
  13410. + published by the Free Software Foundation; either version 2, or (at
  13411. + your option) any later version.
  13412. +
  13413. + This program is distributed in the hope that it will be useful, but
  13414. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13415. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13416. + General Public License for more details.
  13417. +*/
  13418. +
  13419. +#ifndef VOID_LIST_H
  13420. +#define VOID_LIST_H
  13421. +
  13422. +typedef struct void_list_elt void_list_elt_t;
  13423. +struct void_list_elt
  13424. +{
  13425. + void_list_elt_t *next;
  13426. + void *data;
  13427. +};
  13428. +
  13429. +typedef struct void_list void_list_t;
  13430. +struct void_list
  13431. +{
  13432. + void_list_elt_t pre_head;
  13433. + void_list_elt_t *head;
  13434. + void_list_elt_t *tail;
  13435. +};
  13436. +
  13437. +static inline int void_list_empty(void_list_t *list)
  13438. +{
  13439. + if (list->head == NULL)
  13440. + return 1;
  13441. + else
  13442. + return 0;
  13443. +}
  13444. +
  13445. +int void_list_elt_init(void_list_elt_t *elt, void *data);
  13446. +void void_list_elt_deinit(void_list_elt_t *elt);
  13447. +
  13448. +int void_list_init(void_list_t *list);
  13449. +void void_list_deinit(void_list_t *list);
  13450. +
  13451. +int void_list_append(void_list_t *list, void *data);
  13452. +int void_list_push(void_list_t *list, void *data);
  13453. +void_list_elt_t *void_list_pop(void_list_t *list);
  13454. +
  13455. +void *void_list_remove(void_list_t *list, void_list_elt_t **iter);
  13456. +/* remove element containing elt data, using cmp(elt->data, target_data) == 0. */
  13457. +typedef int (*void_list_cmp_t)(const void *, const void *);
  13458. +void *void_list_remove_elt(void_list_t *list, const void *target_data, void_list_cmp_t cmp);
  13459. +
  13460. +#endif
  13461. diff -Nur busybox-1.16.1.orig/archival/libipkg/xsystem.c busybox-1.16.1/archival/libipkg/xsystem.c
  13462. --- busybox-1.16.1.orig/archival/libipkg/xsystem.c 1970-01-01 01:00:00.000000000 +0100
  13463. +++ busybox-1.16.1/archival/libipkg/xsystem.c 2010-06-29 17:31:25.799781135 +0200
  13464. @@ -0,0 +1,64 @@
  13465. +/* xsystem.c - system(3) with error messages
  13466. +
  13467. + Carl D. Worth
  13468. +
  13469. + Copyright (C) 2001 University of Southern California
  13470. +
  13471. + This program is free software; you can redistribute it and/or
  13472. + modify it under the terms of the GNU General Public License as
  13473. + published by the Free Software Foundation; either version 2, or (at
  13474. + your option) any later version.
  13475. +
  13476. + This program is distributed in the hope that it will be useful, but
  13477. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13478. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13479. + General Public License for more details.
  13480. +*/
  13481. +
  13482. +#include "ipkg.h"
  13483. +#include <sys/wait.h>
  13484. +
  13485. +#include "xsystem.h"
  13486. +
  13487. +/* XXX: FEATURE: I shouldn't actually use system(3) at all. I don't
  13488. + really need the /bin/sh invocation which takes resources and
  13489. + introduces security problems. I should switch all of this to a sort
  13490. + of execl() or execv() interface/implementation.
  13491. +*/
  13492. +
  13493. +/* Like system(3), but with error messages printed if the fork fails
  13494. + or if the child process dies due to an uncaught signal. Also, the
  13495. + return value is a bit simpler:
  13496. +
  13497. + -1 if there was any problem
  13498. + Otherwise, the 8-bit return value of the program ala WEXITSTATUS
  13499. + as defined in <sys/wait.h>.
  13500. +*/
  13501. +int xsystem(const char *cmd)
  13502. +{
  13503. + int err;
  13504. +
  13505. + err = system(cmd);
  13506. +
  13507. + if (err == -1) {
  13508. + fprintf(stderr, "%s: ERROR: fork failed before execution: `%s'\n",
  13509. + __FUNCTION__, cmd);
  13510. + return -1;
  13511. + }
  13512. +
  13513. + if (WIFSIGNALED(err)) {
  13514. + fprintf(stderr, "%s: ERROR: Child process died due to signal %d: `%s'\n",
  13515. + __FUNCTION__, WTERMSIG(err), cmd);
  13516. + return -1;
  13517. + }
  13518. +
  13519. + if (WIFEXITED(err)) {
  13520. + /* Normal child exit */
  13521. + return WEXITSTATUS(err);
  13522. + }
  13523. +
  13524. + fprintf(stderr, "%s: ERROR: Received unintelligible return value from system: %d",
  13525. + __FUNCTION__, err);
  13526. + return -1;
  13527. +}
  13528. +
  13529. diff -Nur busybox-1.16.1.orig/archival/libipkg/xsystem.h busybox-1.16.1/archival/libipkg/xsystem.h
  13530. --- busybox-1.16.1.orig/archival/libipkg/xsystem.h 1970-01-01 01:00:00.000000000 +0100
  13531. +++ busybox-1.16.1/archival/libipkg/xsystem.h 2010-06-29 17:31:25.855865061 +0200
  13532. @@ -0,0 +1,34 @@
  13533. +/* xsystem.h - system(3) with error messages
  13534. +
  13535. + Carl D. Worth
  13536. +
  13537. + Copyright (C) 2001 University of Southern California
  13538. +
  13539. + This program is free software; you can redistribute it and/or
  13540. + modify it under the terms of the GNU General Public License as
  13541. + published by the Free Software Foundation; either version 2, or (at
  13542. + your option) any later version.
  13543. +
  13544. + This program is distributed in the hope that it will be useful, but
  13545. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13546. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13547. + General Public License for more details.
  13548. +*/
  13549. +
  13550. +#ifndef XSYSTEM_H
  13551. +#define XSYSTEM_H
  13552. +
  13553. +#include <stdlib.h>
  13554. +
  13555. +/* Like system(3), but with error messages printed if the fork fails
  13556. + or if the child process dies due to an uncaught signal. Also, the
  13557. + return value is a bit simpler:
  13558. +
  13559. + -1 if there was any problem
  13560. + Otherwise, the 8-bit return value of the program ala WEXITSTATUS
  13561. + as defined in <sys/wait.h>.
  13562. +*/
  13563. +int xsystem(const char *cmd);
  13564. +
  13565. +#endif
  13566. +
  13567. diff -Nur busybox-1.16.1.orig/archival/libunarchive/Kbuild busybox-1.16.1/archival/libunarchive/Kbuild
  13568. --- busybox-1.16.1.orig/archival/libunarchive/Kbuild 2010-03-20 03:58:07.000000000 +0100
  13569. +++ busybox-1.16.1/archival/libunarchive/Kbuild 2010-06-29 17:31:25.898368046 +0200
  13570. @@ -40,6 +40,7 @@
  13571. lib-$(CONFIG_DPKG) += $(DPKG_FILES)
  13572. lib-$(CONFIG_DPKG_DEB) += $(DPKG_FILES)
  13573. lib-$(CONFIG_GUNZIP) += decompress_unzip.o
  13574. +lib-$(CONFIG_IPKG) += open_transformer.o get_header_tar.o get_header_tar_gz.o
  13575. lib-$(CONFIG_RPM2CPIO) += decompress_unzip.o get_header_cpio.o
  13576. lib-$(CONFIG_RPM) += open_transformer.o decompress_unzip.o get_header_cpio.o
  13577. lib-$(CONFIG_TAR) += get_header_tar.o
  13578. diff -Nur busybox-1.16.1.orig/include/applets.h busybox-1.16.1/include/applets.h
  13579. --- busybox-1.16.1.orig/include/applets.h 2010-03-28 19:43:35.000000000 +0200
  13580. +++ busybox-1.16.1/include/applets.h 2010-06-29 17:31:25.938368064 +0200
  13581. @@ -214,6 +214,7 @@
  13582. IF_IPCALC(APPLET(ipcalc, _BB_DIR_BIN, _BB_SUID_DROP))
  13583. IF_IPCRM(APPLET(ipcrm, _BB_DIR_USR_BIN, _BB_SUID_REQUIRE))
  13584. IF_IPCS(APPLET(ipcs, _BB_DIR_USR_BIN, _BB_SUID_REQUIRE))
  13585. +IF_IPKG(APPLET(ipkg, _BB_DIR_USR_BIN, _BB_SUID_DROP))
  13586. IF_IPLINK(APPLET(iplink, _BB_DIR_BIN, _BB_SUID_DROP))
  13587. IF_IPROUTE(APPLET(iproute, _BB_DIR_BIN, _BB_SUID_DROP))
  13588. IF_IPRULE(APPLET(iprule, _BB_DIR_BIN, _BB_SUID_DROP))
  13589. diff -Nur busybox-1.16.1.orig/include/unarchive.h busybox-1.16.1/include/unarchive.h
  13590. --- busybox-1.16.1.orig/include/unarchive.h 2010-03-28 19:43:35.000000000 +0200
  13591. +++ busybox-1.16.1/include/unarchive.h 2010-06-29 17:31:25.978368044 +0200
  13592. @@ -53,7 +53,7 @@
  13593. off_t offset;
  13594. /* Archiver specific. Can make it a union if it ever gets big */
  13595. -#if ENABLE_TAR || ENABLE_DPKG || ENABLE_DPKG_DEB
  13596. +#if ENABLE_TAR || ENABLE_DPKG || ENABLE_DPKG_DEB || ENABLE_IPKG
  13597. smallint tar__end;
  13598. # if ENABLE_FEATURE_TAR_GNU_EXTENSIONS
  13599. char* tar__longname;
  13600. @@ -65,7 +65,7 @@
  13601. struct hardlinks_t *cpio__hardlinks_to_create;
  13602. struct hardlinks_t *cpio__created_hardlinks;
  13603. #endif
  13604. -#if ENABLE_DPKG || ENABLE_DPKG_DEB
  13605. +#if ENABLE_DPKG || ENABLE_DPKG_DEB || ENABLE_IPKG
  13606. /* Temporary storage */
  13607. char *dpkg__buffer;
  13608. /* How to process any sub archive, e.g. get_header_tar_gz */
  13609. diff -Nur busybox-1.16.1.orig/include/usage.h busybox-1.16.1/include/usage.h
  13610. --- busybox-1.16.1.orig/include/usage.h 2010-03-28 19:44:04.000000000 +0200
  13611. +++ busybox-1.16.1/include/usage.h 2010-06-29 17:31:26.018367985 +0200
  13612. @@ -1592,6 +1592,82 @@
  13613. "$ ls -la /tmp/busybox*\n" \
  13614. "-rw-rw-r-- 1 andersen andersen 554058 Apr 14 17:49 /tmp/busybox.tar.gz\n"
  13615. +#define ipkg_trivial_usage \
  13616. + "[options]... sub-command [arguments]..."
  13617. +#define ipkg_full_usage \
  13618. + "ipkg is an utility to install, remove and manage .ipk packages.\n" \
  13619. + "\n" \
  13620. + "Sub-commands:\n" \
  13621. + "\nPackage Manipulation:\n" \
  13622. + "\tupdate Update list of available packages\n" \
  13623. + "\tupgrade Upgrade all installed packages to latest version\n" \
  13624. + "\tinstall <pkg> Download and install <pkg> (and dependencies)\n" \
  13625. + "\tinstall <file.ipk> Install package <file.ipk>\n" \
  13626. + "\tconfigure [<pkg>] Configure unpacked packages\n" \
  13627. + "\tremove <pkg|regexp> Remove package <pkg|packages following regexp>\n" \
  13628. + "\tflag <flag> <pkg> ... Flag package(s) <pkg>\n" \
  13629. + "\t <flag>=hold|noprune|user|ok|installed|unpacked (one per invocation) \n" \
  13630. + "\n" \
  13631. + "Informational Commands:\n" \
  13632. + "\tlist List available packages and descriptions\n" \
  13633. + "\tlist_installed List all and only the installed packages and description \n" \
  13634. + "\tfiles <pkg> List all files belonging to <pkg>\n" \
  13635. + "\tsearch <file|regexp> Search for a package providing <file>\n" \
  13636. + "\tinfo [pkg|regexp [<field>]] Display all/some info fields for <pkg> or all\n" \
  13637. + "\tstatus [pkg|regexp [<field>]] Display all/some status fields for <pkg> or all\n" \
  13638. + "\tdownload <pkg> Download <pkg> to current directory.\n" \
  13639. + "\tcompare_versions <v1> <op> <v2>\n" \
  13640. + "\t compare versions using <= < > >= = << >>\n" \
  13641. + "\tprint_architecture prints the architecture.\n" \
  13642. + "\tprint_installation_architecture\n" \
  13643. + "\twhatdepends [-A] [pkgname|pat]+\n" \
  13644. + "\twhatdependsrec [-A] [pkgname|pat]+\n" \
  13645. + "\twhatprovides [-A] [pkgname|pat]+\n" \
  13646. + "\twhatconflicts [-A] [pkgname|pat]+\n" \
  13647. + "\twhatreplaces [-A] [pkgname|pat]+\n" \
  13648. + "\t prints the installation architecture.\n" \
  13649. + "\n" \
  13650. + "\nOptions:\n" \
  13651. + "\t-A Query all packages with whatdepends, whatprovides, whatreplaces, whatconflicts\n" \
  13652. + "\t-V <level> Set verbosity level to <level>. If no value is\n" \
  13653. + "\t--verbosity <level> provided increase verbosity by one. Verbosity levels:\n" \
  13654. + "\t 0 errors only\n" \
  13655. + "\t 1 normal messages (default)\n" \
  13656. + "\t 2 informative messages\n" \
  13657. + "\t 3 debug output\n" \
  13658. + "\t-f <conf_file> Use <conf_file> as the ipkg configuration file\n" \
  13659. + "\t-conf <conf_file> Default configuration file location\n" \
  13660. + " is /etc/ipkg.conf\n" \
  13661. + "\t-d <dest_name> Use <dest_name> as the the root directory for\n" \
  13662. + "\t-dest <dest_name> package installation, removal, upgrading.\n" \
  13663. + " <dest_name> should be a defined dest name from\n" \
  13664. + " the configuration file, (but can also be a\n" \
  13665. + " directory name in a pinch).\n" \
  13666. + "\t-o <offline_root> Use <offline_root> as the root directory for\n" \
  13667. + "\t-offline <offline_root> offline installation of packages.\n" \
  13668. + "\t-verbose_wget more wget messages\n" \
  13669. + "\n" \
  13670. + "Force Options (use when ipkg is too smart for its own good):\n" \
  13671. + "\t-force-depends Make dependency checks warnings instead of errors\n" \
  13672. + "\t Install/remove package in spite of failed dependences\n" \
  13673. + "\t-force-defaults Use default options for questions asked by ipkg.\n" \
  13674. + " (no prompts). Note that this will not prevent\n" \
  13675. + " package installation scripts from prompting.\n" \
  13676. + "\t-force-reinstall Allow ipkg to reinstall a package.\n" \
  13677. + "\t-force-overwrite Allow ipkg to overwrite files from another package during an install.\n" \
  13678. + "\t-force-downgrade Allow ipkg to downgrade packages.\n" \
  13679. + "\t-force_space Install even if there does not seem to be enough space.\n" \
  13680. + "\t-noaction No action -- test only\n" \
  13681. + "\t-nodeps Do not follow dependences\n" \
  13682. + "\t-force-removal-of-dependent-packages\n" \
  13683. + "\t-recursive Allow ipkg to remove package and all that depend on it.\n" \
  13684. + "\t-test No action -- test only\n" \
  13685. + "\t-t Specify tmp-dir.\n" \
  13686. + "\t--tmp-dir Specify tmp-dir.\n" \
  13687. + "\n" \
  13688. + "\tregexp could be something like 'pkgname*' '*file*' or similar\n" \
  13689. + "\teg: ipkg info 'libstd*' or ipkg search '*libop*' or ipkg remove 'libncur*'\n"
  13690. +
  13691. #define halt_trivial_usage \
  13692. "[-d DELAY] [-n] [-f]" IF_FEATURE_WTMP(" [-w]")
  13693. #define halt_full_usage "\n\n" \
  13694. diff -Nur busybox-1.16.1.orig/Makefile busybox-1.16.1/Makefile
  13695. --- busybox-1.16.1.orig/Makefile 2010-03-28 19:44:09.000000000 +0200
  13696. +++ busybox-1.16.1/Makefile 2010-06-29 17:31:26.058368031 +0200
  13697. @@ -454,6 +454,7 @@
  13698. libs-y := \
  13699. archival/ \
  13700. + archival/libipkg/ \
  13701. archival/libunarchive/ \
  13702. console-tools/ \
  13703. coreutils/ \