001-ipkg.patch 424 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737
  1. diff -Nur busybox-1.17.2.orig/Makefile busybox-1.17.2/Makefile
  2. --- busybox-1.17.2.orig/Makefile 2010-08-23 02:51:08.000000000 +0200
  3. +++ busybox-1.17.2/Makefile 2010-12-01 22:25:23.000000000 +0100
  4. @@ -464,6 +464,7 @@
  5. libs-y := \
  6. archival/ \
  7. + archival/libipkg/ \
  8. archival/libunarchive/ \
  9. console-tools/ \
  10. coreutils/ \
  11. diff -Nur busybox-1.17.2.orig/archival/Config.src busybox-1.17.2/archival/Config.src
  12. --- busybox-1.17.2.orig/archival/Config.src 2010-08-22 10:21:38.000000000 +0200
  13. +++ busybox-1.17.2/archival/Config.src 2010-12-01 22:25:23.000000000 +0100
  14. @@ -202,6 +202,12 @@
  15. are actually slower than gzip at equivalent compression ratios
  16. and take up 3.2K of code.
  17. +config IPKG
  18. + bool "ipkg"
  19. + default n
  20. + help
  21. + ipkg is the itsy package management system.
  22. +
  23. config RPM2CPIO
  24. bool "rpm2cpio"
  25. default y
  26. diff -Nur busybox-1.17.2.orig/archival/Kbuild.src busybox-1.17.2/archival/Kbuild.src
  27. --- busybox-1.17.2.orig/archival/Kbuild.src 2010-08-23 02:44:35.000000000 +0200
  28. +++ busybox-1.17.2/archival/Kbuild.src 2010-12-01 22:25:23.000000000 +0100
  29. @@ -23,6 +23,7 @@
  30. lib-$(CONFIG_LZOP_COMPR_HIGH) += lzo1x_9x.o
  31. lib-$(CONFIG_GZIP) += gzip.o bbunzip.o
  32. lib-$(CONFIG_BZIP2) += bzip2.o bbunzip.o
  33. +lib-$(CONFIG_IPKG) += ipkg.o
  34. lib-$(CONFIG_UNXZ) += bbunzip.o
  35. lib-$(CONFIG_UNLZMA) += bbunzip.o
  36. diff -Nur busybox-1.17.2.orig/archival/ipkg.c busybox-1.17.2/archival/ipkg.c
  37. --- busybox-1.17.2.orig/archival/ipkg.c 1970-01-01 01:00:00.000000000 +0100
  38. +++ busybox-1.17.2/archival/ipkg.c 2010-12-01 22:25:23.000000000 +0100
  39. @@ -0,0 +1,28 @@
  40. +/* ipkg.c - the itsy package management system
  41. +
  42. + Florina Boor
  43. +
  44. + Copyright (C) 2003 kernel concepts
  45. +
  46. + This program is free software; you can redistribute it and/or
  47. + modify it under the terms of the GNU General Public License as
  48. + published by the Free Software Foundation; either version 2, or (at
  49. + your option) any later version.
  50. +
  51. + This program is distributed in the hope that it will be useful, but
  52. + WITHOUT ANY WARRANTY; without even the implied warranty of
  53. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  54. + General Public License for more details.
  55. +
  56. + ipkg command line frontend using libipkg
  57. +
  58. +*/
  59. +
  60. +#include "libbb.h"
  61. +#include "libipkg/libipkg.h"
  62. +
  63. +int ipkg_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  64. +int ipkg_main(int argc, char **argv)
  65. +{
  66. + return ipkg_op(argc, argv);
  67. +}
  68. diff -Nur busybox-1.17.2.orig/archival/libipkg/Kbuild busybox-1.17.2/archival/libipkg/Kbuild
  69. --- busybox-1.17.2.orig/archival/libipkg/Kbuild 1970-01-01 01:00:00.000000000 +0100
  70. +++ busybox-1.17.2/archival/libipkg/Kbuild 2010-12-01 22:25:23.000000000 +0100
  71. @@ -0,0 +1,60 @@
  72. +# Makefile for busybox
  73. +#
  74. +# Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
  75. +# Copyright (C) 2006 OpenWrt.org
  76. +#
  77. +# Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
  78. +
  79. +LIBIPKG_CORE_OBJS:= \
  80. + args.o \
  81. + libipkg.o \
  82. + user.o \
  83. +
  84. +LIBIPKG_CMD_OBJS:= \
  85. + ipkg_cmd.o \
  86. + ipkg_configure.o \
  87. + ipkg_download.o \
  88. + ipkg_install.o \
  89. + ipkg_remove.o \
  90. + ipkg_upgrade.o \
  91. +
  92. +LIBIPKG_DB_OBJS:= \
  93. + hash_table.o \
  94. + ipkg_conf.o \
  95. + ipkg_utils.o \
  96. + pkg.o \
  97. + pkg_depends.o \
  98. + pkg_extract.o \
  99. + pkg_hash.o \
  100. + pkg_parse.o \
  101. + pkg_vec.o \
  102. +
  103. +LIBIPKG_LIST_OBJS:= \
  104. + conffile.o \
  105. + conffile_list.o \
  106. + nv_pair.o \
  107. + nv_pair_list.o \
  108. + pkg_dest.o \
  109. + pkg_dest_list.o \
  110. + pkg_src.o \
  111. + pkg_src_list.o \
  112. + str_list.o \
  113. + void_list.o \
  114. +
  115. +LIBIPKG_UTIL_OBJS:= \
  116. + file_util.o \
  117. + ipkg_message.o \
  118. + str_util.o \
  119. + xsystem.o \
  120. +
  121. +lib-y :=
  122. +lib-$(CONFIG_IPKG) += $(LIBIPKG_CORE_OBJS)
  123. +lib-$(CONFIG_IPKG) += $(LIBIPKG_CMD_OBJS)
  124. +lib-$(CONFIG_IPKG) += $(LIBIPKG_DB_OBJS)
  125. +lib-$(CONFIG_IPKG) += $(LIBIPKG_LIST_OBJS)
  126. +lib-$(CONFIG_IPKG) += $(LIBIPKG_UTIL_OBJS)
  127. +
  128. +ifeq ($(strip $(IPKG_ARCH)),)
  129. +IPKG_ARCH:=$(TARGET_ARCH)
  130. +endif
  131. +CFLAGS += -DIPKGLIBDIR="\"/usr/lib\"" -DHOST_CPU_STR="\"$(IPKG_ARCH)\""
  132. diff -Nur busybox-1.17.2.orig/archival/libipkg/args.c busybox-1.17.2/archival/libipkg/args.c
  133. --- busybox-1.17.2.orig/archival/libipkg/args.c 1970-01-01 01:00:00.000000000 +0100
  134. +++ busybox-1.17.2/archival/libipkg/args.c 2010-12-01 22:25:23.000000000 +0100
  135. @@ -0,0 +1,242 @@
  136. +/* args.c - parse command-line args
  137. +
  138. + Carl D. Worth
  139. +
  140. + Copyright 2001 University of Southern California
  141. +
  142. + This program is free software; you can redistribute it and/or modify
  143. + it under the terms of the GNU General Public License as published by
  144. + the Free Software Foundation; either version 2, or (at your option)
  145. + any later version.
  146. +
  147. + This program is distributed in the hope that it will be useful,
  148. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  149. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  150. + GNU General Public License for more details.
  151. + */
  152. +
  153. +#include <getopt.h>
  154. +#include <stdlib.h>
  155. +#include <string.h>
  156. +#include <unistd.h>
  157. +
  158. +#include "ipkg.h"
  159. +#include "ipkg_message.h"
  160. +
  161. +#include "args.h"
  162. +#include "sprintf_alloc.h"
  163. +
  164. +#include "libbb.h"
  165. +
  166. +
  167. +static void print_version(void);
  168. +
  169. +enum long_args_opt
  170. +{
  171. + ARGS_OPT_FORCE_DEFAULTS = 129,
  172. + ARGS_OPT_FORCE_DEPENDS,
  173. + ARGS_OPT_FORCE_OVERWRITE,
  174. + ARGS_OPT_FORCE_DOWNGRADE,
  175. + ARGS_OPT_FORCE_REINSTALL,
  176. + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES,
  177. + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES,
  178. + ARGS_OPT_FORCE_SPACE,
  179. + ARGS_OPT_NOACTION,
  180. + ARGS_OPT_NODEPS,
  181. + ARGS_OPT_VERBOSE_WGET,
  182. + ARGS_OPT_VERBOSITY,
  183. + ARGS_OPT_MULTIPLE_PROVIDERS
  184. +};
  185. +
  186. +int args_init(args_t *args)
  187. +{
  188. + const char *conf_file_dir;
  189. +
  190. + memset(args, 0, sizeof(args_t));
  191. +
  192. + args->dest = ARGS_DEFAULT_DEST;
  193. +
  194. + conf_file_dir = getenv("IPKG_CONF_DIR");
  195. + if (conf_file_dir == NULL || conf_file_dir[0] == '\0') {
  196. + conf_file_dir = ARGS_DEFAULT_CONF_FILE_DIR;
  197. + }
  198. + sprintf_alloc(&args->conf_file, "%s/%s", conf_file_dir,
  199. + ARGS_DEFAULT_CONF_FILE_NAME);
  200. +
  201. + args->force_defaults = ARGS_DEFAULT_FORCE_DEFAULTS;
  202. + args->force_depends = ARGS_DEFAULT_FORCE_DEPENDS;
  203. + args->force_overwrite = ARGS_DEFAULT_FORCE_OVERWRITE;
  204. + args->force_downgrade = ARGS_DEFAULT_FORCE_DOWNGRADE;
  205. + args->force_reinstall = ARGS_DEFAULT_FORCE_REINSTALL;
  206. + args->force_removal_of_dependent_packages = ARGS_DEFAULT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES;
  207. + args->force_removal_of_essential_packages = ARGS_DEFAULT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES;
  208. + args->noaction = ARGS_DEFAULT_NOACTION;
  209. + args->nodeps = ARGS_DEFAULT_NODEPS;
  210. + args->verbose_wget = ARGS_DEFAULT_VERBOSE_WGET;
  211. + args->verbosity = ARGS_DEFAULT_VERBOSITY;
  212. + args->offline_root = ARGS_DEFAULT_OFFLINE_ROOT;
  213. + args->offline_root_pre_script_cmd = ARGS_DEFAULT_OFFLINE_ROOT_PRE_SCRIPT_CMD;
  214. + args->offline_root_post_script_cmd = ARGS_DEFAULT_OFFLINE_ROOT_POST_SCRIPT_CMD;
  215. + args->multiple_providers = 0;
  216. + args->nocheckfordirorfile = 0;
  217. + args->noreadfeedsfile = 0;
  218. +
  219. + return 1;
  220. +}
  221. +
  222. +void args_deinit(args_t *args)
  223. +{
  224. + free(args->conf_file);
  225. + args->conf_file = NULL;
  226. +}
  227. +
  228. +int args_parse(args_t *args, int argc, char *argv[])
  229. +{
  230. + int c;
  231. + int option_index = 0;
  232. + int parse_err = 0;
  233. + static struct option long_options[] = {
  234. + {"query-all", 0, 0, 'A'},
  235. + {"conf-file", 1, 0, 'f'},
  236. + {"conf", 1, 0, 'f'},
  237. + {"dest", 1, 0, 'd'},
  238. + {"force-defaults", 0, 0, ARGS_OPT_FORCE_DEFAULTS},
  239. + {"force_defaults", 0, 0, ARGS_OPT_FORCE_DEFAULTS},
  240. + {"force-depends", 0, 0, ARGS_OPT_FORCE_DEPENDS},
  241. + {"force_depends", 0, 0, ARGS_OPT_FORCE_DEPENDS},
  242. + {"force-overwrite", 0, 0, ARGS_OPT_FORCE_OVERWRITE},
  243. + {"force_overwrite", 0, 0, ARGS_OPT_FORCE_OVERWRITE},
  244. + {"force_downgrade", 0, 0, ARGS_OPT_FORCE_DOWNGRADE},
  245. + {"force-downgrade", 0, 0, ARGS_OPT_FORCE_DOWNGRADE},
  246. + {"force-reinstall", 0, 0, ARGS_OPT_FORCE_REINSTALL},
  247. + {"force_reinstall", 0, 0, ARGS_OPT_FORCE_REINSTALL},
  248. + {"force-space", 0, 0, ARGS_OPT_FORCE_SPACE},
  249. + {"force_space", 0, 0, ARGS_OPT_FORCE_SPACE},
  250. + {"recursive", 0, 0,
  251. + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
  252. + {"force-removal-of-dependent-packages", 0, 0,
  253. + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
  254. + {"force_removal_of_dependent_packages", 0, 0,
  255. + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
  256. + {"force-removal-of-essential-packages", 0, 0,
  257. + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES},
  258. + {"force_removal_of_essential_packages", 0, 0,
  259. + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES},
  260. + {"multiple-providers", 0, 0, ARGS_OPT_MULTIPLE_PROVIDERS},
  261. + {"multiple_providers", 0, 0, ARGS_OPT_MULTIPLE_PROVIDERS},
  262. + {"noaction", 0, 0, ARGS_OPT_NOACTION},
  263. + {"nodeps", 0, 0, ARGS_OPT_NODEPS},
  264. + {"offline", 1, 0, 'o'},
  265. + {"offline-root", 1, 0, 'o'},
  266. + {"test", 0, 0, ARGS_OPT_NOACTION},
  267. + {"tmp-dir", 1, 0, 't'},
  268. + {"verbose-wget", 0, 0, ARGS_OPT_VERBOSE_WGET},
  269. + {"verbose_wget", 0, 0, ARGS_OPT_VERBOSE_WGET},
  270. + {"verbosity", 2, 0, 'V'},
  271. + {"version", 0, 0, 'v'},
  272. + {0, 0, 0, 0}
  273. + };
  274. +
  275. + while (1) {
  276. + c = getopt_long_only(argc, argv, "Ad:f:no:t:vV:", long_options, &option_index);
  277. + if (c == -1)
  278. + break;
  279. +
  280. + switch (c) {
  281. + case 'A':
  282. + args->query_all = 1;
  283. + break;
  284. + case 'd':
  285. + args->dest = optarg;
  286. + break;
  287. + case 'f':
  288. + free(args->conf_file);
  289. + args->conf_file = strdup(optarg);
  290. + break;
  291. + case 'o':
  292. + args->offline_root = optarg;
  293. + break;
  294. + case 'n':
  295. + args->noaction = 1;
  296. + break;
  297. + case 't':
  298. + args->tmp_dir = strdup(optarg);
  299. + break;
  300. + case 'v':
  301. + print_version();
  302. + exit(0);
  303. + case 'V':
  304. + case ARGS_OPT_VERBOSITY:
  305. + if (optarg)
  306. + args->verbosity = atoi(optarg);
  307. + else
  308. + args->verbosity += 1;
  309. + break;
  310. + case ARGS_OPT_FORCE_DEFAULTS:
  311. + args->force_defaults = 1;
  312. + break;
  313. + case ARGS_OPT_FORCE_DEPENDS:
  314. + args->force_depends = 1;
  315. + break;
  316. + case ARGS_OPT_FORCE_OVERWRITE:
  317. + args->force_overwrite = 1;
  318. + break;
  319. + case ARGS_OPT_FORCE_DOWNGRADE:
  320. + args->force_downgrade = 1;
  321. + break;
  322. + case ARGS_OPT_FORCE_REINSTALL:
  323. + args->force_reinstall = 1;
  324. + break;
  325. + case ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES:
  326. + args->force_removal_of_essential_packages = 1;
  327. + break;
  328. + case ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES:
  329. + args->force_removal_of_dependent_packages = 1;
  330. + break;
  331. + case ARGS_OPT_FORCE_SPACE:
  332. + args->force_space = 1;
  333. + break;
  334. + case ARGS_OPT_VERBOSE_WGET:
  335. + args->verbose_wget = 1;
  336. + break;
  337. + case ARGS_OPT_MULTIPLE_PROVIDERS:
  338. + args->multiple_providers = 1;
  339. + break;
  340. + case ARGS_OPT_NODEPS:
  341. + args->nodeps = 1;
  342. + break;
  343. + case ARGS_OPT_NOACTION:
  344. + args->noaction = 1;
  345. + break;
  346. + case ':':
  347. + parse_err++;
  348. + break;
  349. + case '?':
  350. + parse_err++;
  351. + break;
  352. + default:
  353. + bb_error_msg("Confusion: getopt_long returned %d\n", c);
  354. + }
  355. + }
  356. +
  357. + if (parse_err) {
  358. + return -parse_err;
  359. + } else {
  360. + return optind;
  361. + }
  362. +}
  363. +
  364. +void args_usage(const char *complaint)
  365. +{
  366. + if (complaint) {
  367. + bb_error_msg("%s\n", complaint);
  368. + }
  369. + print_version();
  370. + bb_show_usage();
  371. + exit(1);
  372. +}
  373. +
  374. +static void print_version(void)
  375. +{
  376. + bb_error_msg("version %s\n", IPKG_VERSION);
  377. +}
  378. diff -Nur busybox-1.17.2.orig/archival/libipkg/args.h busybox-1.17.2/archival/libipkg/args.h
  379. --- busybox-1.17.2.orig/archival/libipkg/args.h 1970-01-01 01:00:00.000000000 +0100
  380. +++ busybox-1.17.2/archival/libipkg/args.h 2010-12-01 22:25:23.000000000 +0100
  381. @@ -0,0 +1,72 @@
  382. +/* args.h - parse command-line args
  383. +
  384. + Carl D. Worth
  385. +
  386. + Copyright 2001 University of Southern California
  387. +
  388. + This program is free software; you can redistribute it and/or modify
  389. + it under the terms of the GNU General Public License as published by
  390. + the Free Software Foundation; either version 2, or (at your option)
  391. + any later version.
  392. +
  393. + This program is distributed in the hope that it will be useful,
  394. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  395. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  396. + GNU General Public License for more details.
  397. +*/
  398. +
  399. +#ifndef ARGS_H
  400. +#define ARGS_H
  401. +
  402. +struct args
  403. +{
  404. + char *conf_file;
  405. + char *dest;
  406. + char *tmp_dir;
  407. + int force_defaults;
  408. + int force_depends;
  409. + int force_overwrite;
  410. + int force_downgrade;
  411. + int force_reinstall;
  412. + int force_removal_of_essential_packages;
  413. + int force_removal_of_dependent_packages;
  414. + int force_space;
  415. + int noaction;
  416. + int nodeps;
  417. + int multiple_providers;
  418. + int query_all;
  419. + int verbose_wget;
  420. + int verbosity;
  421. + int nocheckfordirorfile;
  422. + int noreadfeedsfile;
  423. + char *offline_root;
  424. + char *offline_root_pre_script_cmd;
  425. + char *offline_root_post_script_cmd;
  426. +};
  427. +typedef struct args args_t;
  428. +
  429. +#define ARGS_DEFAULT_CONF_FILE_DIR "/etc"
  430. +#define ARGS_DEFAULT_CONF_FILE_NAME "ipkg.conf"
  431. +#define ARGS_DEFAULT_DEST NULL
  432. +#define ARGS_DEFAULT_FORCE_DEFAULTS 0
  433. +#define ARGS_DEFAULT_FORCE_DEPENDS 0
  434. +#define ARGS_DEFAULT_FORCE_OVERWRITE 0
  435. +#define ARGS_DEFAULT_FORCE_DOWNGRADE 0
  436. +#define ARGS_DEFAULT_FORCE_REINSTALL 0
  437. +#define ARGS_DEFAULT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES 0
  438. +#define ARGS_DEFAULT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES 0
  439. +#define ARGS_DEFAULT_FORCE_SPACE 0
  440. +#define ARGS_DEFAULT_OFFLINE_ROOT NULL
  441. +#define ARGS_DEFAULT_OFFLINE_ROOT_PRE_SCRIPT_CMD NULL
  442. +#define ARGS_DEFAULT_OFFLINE_ROOT_POST_SCRIPT_CMD NULL
  443. +#define ARGS_DEFAULT_NOACTION 0
  444. +#define ARGS_DEFAULT_NODEPS 0
  445. +#define ARGS_DEFAULT_VERBOSE_WGET 0
  446. +#define ARGS_DEFAULT_VERBOSITY 1
  447. +
  448. +int args_init(args_t *args);
  449. +void args_deinit(args_t *args);
  450. +int args_parse(args_t *args, int argc, char *argv[]);
  451. +void args_usage(const char *complaint);
  452. +
  453. +#endif
  454. diff -Nur busybox-1.17.2.orig/archival/libipkg/conffile.c busybox-1.17.2/archival/libipkg/conffile.c
  455. --- busybox-1.17.2.orig/archival/libipkg/conffile.c 1970-01-01 01:00:00.000000000 +0100
  456. +++ busybox-1.17.2/archival/libipkg/conffile.c 2010-12-01 22:25:23.000000000 +0100
  457. @@ -0,0 +1,65 @@
  458. +/* conffile.c - the itsy package management system
  459. +
  460. + Carl D. Worth
  461. +
  462. + Copyright (C) 2001 University of Southern California
  463. +
  464. + This program is free software; you can redistribute it and/or
  465. + modify it under the terms of the GNU General Public License as
  466. + published by the Free Software Foundation; either version 2, or (at
  467. + your option) any later version.
  468. +
  469. + This program is distributed in the hope that it will be useful, but
  470. + WITHOUT ANY WARRANTY; without even the implied warranty of
  471. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  472. + General Public License for more details.
  473. +*/
  474. +
  475. +#include <string.h>
  476. +#include <stdlib.h>
  477. +
  478. +#include "libbb.h"
  479. +#include "ipkg.h"
  480. +#include "ipkg_message.h"
  481. +
  482. +#include "conffile.h"
  483. +#include "file_util.h"
  484. +#include "sprintf_alloc.h"
  485. +
  486. +int conffile_init(conffile_t *conffile, const char *file_name, const uint8_t *md5sum)
  487. +{
  488. + return nv_pair_init(conffile, file_name, (char *)md5sum);
  489. +}
  490. +
  491. +void conffile_deinit(conffile_t *conffile)
  492. +{
  493. + nv_pair_deinit(conffile);
  494. +}
  495. +
  496. +int conffile_has_been_modified(ipkg_conf_t *conf, conffile_t *conffile)
  497. +{
  498. + uint8_t *md5sum;
  499. + char *filename = conffile->name;
  500. + char *root_filename;
  501. + int ret;
  502. +
  503. + if (conffile->value == NULL) {
  504. + ipkg_message(conf, IPKG_NOTICE, "%s: conffile %s has no md5sum\n", __FUNCTION__, conffile->name);
  505. + return 1;
  506. + }
  507. +
  508. + root_filename = root_filename_alloc(conf, filename);
  509. +
  510. + md5sum = file_md5sum_alloc(root_filename);
  511. +
  512. + ret = strcmp((char *)md5sum, conffile->value);
  513. + if (ret) {
  514. + ipkg_message(conf, IPKG_NOTICE, "%s: conffile %s: \t\nold md5=%s \t\nnew md5=%s\n", __FUNCTION__,
  515. + conffile->name, md5sum, conffile->value);
  516. + }
  517. +
  518. + free(root_filename);
  519. + free(md5sum);
  520. +
  521. + return ret;
  522. +}
  523. diff -Nur busybox-1.17.2.orig/archival/libipkg/conffile.h busybox-1.17.2/archival/libipkg/conffile.h
  524. --- busybox-1.17.2.orig/archival/libipkg/conffile.h 1970-01-01 01:00:00.000000000 +0100
  525. +++ busybox-1.17.2/archival/libipkg/conffile.h 2010-12-01 22:25:23.000000000 +0100
  526. @@ -0,0 +1,30 @@
  527. +/* conffile.h - the itsy package management system
  528. +
  529. + Carl D. Worth
  530. +
  531. + Copyright (C) 2001 University of Southern California
  532. +
  533. + This program is free software; you can redistribute it and/or
  534. + modify it under the terms of the GNU General Public License as
  535. + published by the Free Software Foundation; either version 2, or (at
  536. + your option) any later version.
  537. +
  538. + This program is distributed in the hope that it will be useful, but
  539. + WITHOUT ANY WARRANTY; without even the implied warranty of
  540. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  541. + General Public License for more details.
  542. +*/
  543. +
  544. +#ifndef CONFFILE_H
  545. +#define CONFFILE_H
  546. +
  547. +#include "nv_pair.h"
  548. +
  549. +typedef struct nv_pair conffile_t;
  550. +
  551. +int conffile_init(conffile_t *conffile, const char *file_name, const uint8_t *md5sum);
  552. +void conffile_deinit(conffile_t *conffile);
  553. +int conffile_has_been_modified(struct ipkg_conf *conf, conffile_t *conffile);
  554. +
  555. +#endif
  556. +
  557. diff -Nur busybox-1.17.2.orig/archival/libipkg/conffile_list.c busybox-1.17.2/archival/libipkg/conffile_list.c
  558. --- busybox-1.17.2.orig/archival/libipkg/conffile_list.c 1970-01-01 01:00:00.000000000 +0100
  559. +++ busybox-1.17.2/archival/libipkg/conffile_list.c 2010-12-01 22:25:23.000000000 +0100
  560. @@ -0,0 +1,47 @@
  561. +/* conffile_list.c - the itsy package management system
  562. +
  563. + Carl D. Worth
  564. +
  565. + Copyright (C) 2001 University of Southern California
  566. +
  567. + This program is free software; you can redistribute it and/or
  568. + modify it under the terms of the GNU General Public License as
  569. + published by the Free Software Foundation; either version 2, or (at
  570. + your option) any later version.
  571. +
  572. + This program is distributed in the hope that it will be useful, but
  573. + WITHOUT ANY WARRANTY; without even the implied warranty of
  574. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  575. + General Public License for more details.
  576. +*/
  577. +
  578. +#include "ipkg.h"
  579. +
  580. +#include "conffile_list.h"
  581. +
  582. +int conffile_list_init(conffile_list_t *list)
  583. +{
  584. + return nv_pair_list_init(list);
  585. +}
  586. +
  587. +void conffile_list_deinit(conffile_list_t *list)
  588. +{
  589. + nv_pair_list_deinit(list);
  590. +}
  591. +
  592. +conffile_t *conffile_list_append(conffile_list_t *list, const char *file_name,
  593. + const char *md5sum)
  594. +{
  595. + return nv_pair_list_append(list, file_name, md5sum);
  596. +}
  597. +
  598. +int conffile_list_push(conffile_list_t *list, conffile_t *data)
  599. +{
  600. + return nv_pair_list_push(list, data);
  601. +}
  602. +
  603. +conffile_list_elt_t *conffile_list_pop(conffile_list_t *list)
  604. +{
  605. + return nv_pair_list_pop(list);
  606. +}
  607. +
  608. diff -Nur busybox-1.17.2.orig/archival/libipkg/conffile_list.h busybox-1.17.2/archival/libipkg/conffile_list.h
  609. --- busybox-1.17.2.orig/archival/libipkg/conffile_list.h 1970-01-01 01:00:00.000000000 +0100
  610. +++ busybox-1.17.2/archival/libipkg/conffile_list.h 2010-12-01 22:25:23.000000000 +0100
  611. @@ -0,0 +1,36 @@
  612. +/* conffile_list.h - the itsy package management system
  613. +
  614. + Carl D. Worth
  615. +
  616. + Copyright (C) 2001 University of Southern California
  617. +
  618. + This program is free software; you can redistribute it and/or
  619. + modify it under the terms of the GNU General Public License as
  620. + published by the Free Software Foundation; either version 2, or (at
  621. + your option) any later version.
  622. +
  623. + This program is distributed in the hope that it will be useful, but
  624. + WITHOUT ANY WARRANTY; without even the implied warranty of
  625. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  626. + General Public License for more details.
  627. +*/
  628. +
  629. +#ifndef CONFFILE_LIST_H
  630. +#define CONFFILE_LIST_H
  631. +
  632. +#include "conffile.h"
  633. +#include "nv_pair_list.h"
  634. +
  635. +typedef struct nv_pair_list_elt conffile_list_elt_t;
  636. +typedef struct nv_pair_list conffile_list_t;
  637. +
  638. +int conffile_list_init(conffile_list_t *list);
  639. +void conffile_list_deinit(conffile_list_t *list);
  640. +
  641. +conffile_t *conffile_list_append(conffile_list_t *list, const char *name,
  642. + const char *root_dir);
  643. +int conffile_list_push(conffile_list_t *list, conffile_t *data);
  644. +conffile_list_elt_t *conffile_list_pop(conffile_list_t *list);
  645. +
  646. +#endif
  647. +
  648. diff -Nur busybox-1.17.2.orig/archival/libipkg/file_util.c busybox-1.17.2/archival/libipkg/file_util.c
  649. --- busybox-1.17.2.orig/archival/libipkg/file_util.c 1970-01-01 01:00:00.000000000 +0100
  650. +++ busybox-1.17.2/archival/libipkg/file_util.c 2010-12-01 22:25:23.000000000 +0100
  651. @@ -0,0 +1,186 @@
  652. +/* file_util.c - convenience routines for common stat operations
  653. +
  654. + Carl D. Worth
  655. +
  656. + Copyright (C) 2001 University of Southern California
  657. +
  658. + This program is free software; you can redistribute it and/or
  659. + modify it under the terms of the GNU General Public License as
  660. + published by the Free Software Foundation; either version 2, or (at
  661. + your option) any later version.
  662. +
  663. + This program is distributed in the hope that it will be useful, but
  664. + WITHOUT ANY WARRANTY; without even the implied warranty of
  665. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  666. + General Public License for more details.
  667. +*/
  668. +
  669. +#include "ipkg.h"
  670. +#include <sys/types.h>
  671. +#include <sys/stat.h>
  672. +
  673. +#include "sprintf_alloc.h"
  674. +#include "file_util.h"
  675. +#include "libbb.h"
  676. +#undef strlen
  677. +
  678. +int file_exists(const char *file_name)
  679. +{
  680. + int err;
  681. + struct stat stat_buf;
  682. +
  683. + err = stat(file_name, &stat_buf);
  684. + if (err == 0) {
  685. + return 1;
  686. + } else {
  687. + return 0;
  688. + }
  689. +}
  690. +
  691. +int file_is_dir(const char *file_name)
  692. +{
  693. + int err;
  694. + struct stat stat_buf;
  695. +
  696. + err = stat(file_name, &stat_buf);
  697. + if (err) {
  698. + return 0;
  699. + }
  700. +
  701. + return S_ISDIR(stat_buf.st_mode);
  702. +}
  703. +
  704. +/* read a single line from a file, stopping at a newline or EOF.
  705. + If a newline is read, it will appear in the resulting string.
  706. + Return value is a malloc'ed char * which should be freed at
  707. + some point by the caller.
  708. +
  709. + Return value is NULL if the file is at EOF when called.
  710. +*/
  711. +#define FILE_READ_LINE_BUF_SIZE 1024
  712. +char *file_read_line_alloc(FILE *file)
  713. +{
  714. + char buf[FILE_READ_LINE_BUF_SIZE];
  715. + int buf_len;
  716. + char *line = NULL;
  717. + int line_size = 0;
  718. +
  719. + memset(buf, 0, FILE_READ_LINE_BUF_SIZE);
  720. + while (fgets(buf, FILE_READ_LINE_BUF_SIZE, file)) {
  721. + buf_len = strlen(buf);
  722. + if (line) {
  723. + line_size += buf_len;
  724. + line = realloc(line, line_size);
  725. + if (line == NULL) {
  726. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  727. + break;
  728. + }
  729. + strcat(line, buf);
  730. + } else {
  731. + line_size = buf_len + 1;
  732. + line = strdup(buf);
  733. + }
  734. + if (buf[buf_len - 1] == '\n') {
  735. + break;
  736. + }
  737. + }
  738. +
  739. + return line;
  740. +}
  741. +
  742. +int file_move(const char *src, const char *dest)
  743. +{
  744. + int err;
  745. +
  746. + err = rename(src, dest);
  747. +
  748. + if (err && errno == EXDEV) {
  749. + err = file_copy(src, dest);
  750. + unlink(src);
  751. + } else if (err) {
  752. + fprintf(stderr, "%s: ERROR: failed to rename %s to %s: %s\n",
  753. + __FUNCTION__, src, dest, strerror(errno));
  754. + }
  755. +
  756. + return err;
  757. +}
  758. +
  759. +/* I put these here to keep libbb dependencies from creeping all over
  760. + the ipkg code */
  761. +int file_copy(const char *src, const char *dest)
  762. +{
  763. + int err;
  764. +
  765. + err = copy_file(src, dest, FILEUTILS_FORCE | FILEUTILS_PRESERVE_STATUS);
  766. + if (err) {
  767. + fprintf(stderr, "%s: ERROR: failed to copy %s to %s\n",
  768. + __FUNCTION__, src, dest);
  769. + }
  770. +
  771. + return err;
  772. +}
  773. +
  774. +int file_mkdir_hier(char *path, long mode)
  775. +{
  776. + return bb_make_directory(path, mode, FILEUTILS_RECUR);
  777. +}
  778. +
  779. +static unsigned char *hash_bin_to_hex(unsigned char *hash_value,
  780. + unsigned hash_length)
  781. +{
  782. + /* xzalloc zero-terminates */
  783. + char *hex_value = xzalloc((hash_length * 2) + 1);
  784. + bin2hex(hex_value, (char*)hash_value, hash_length);
  785. + return (unsigned char *)hex_value;
  786. +}
  787. +
  788. +static uint8_t *hash_file(const char *filename, hash_algo_t hash_algo)
  789. +{
  790. + int src_fd, hash_len, count;
  791. + union _ctx_ {
  792. + sha1_ctx_t sha1;
  793. + md5_ctx_t md5;
  794. + } context;
  795. + uint8_t *hash_value = NULL;
  796. + RESERVE_CONFIG_UBUFFER(in_buf, 4096);
  797. + void FAST_FUNC (*update)(const void*, size_t, void*);
  798. + void FAST_FUNC (*final)(void*, void*);
  799. +
  800. + src_fd = open_or_warn_stdin(filename);
  801. + if (src_fd < 0) {
  802. + return NULL;
  803. + }
  804. +
  805. + /* figure specific hash algorithims */
  806. + if (ENABLE_MD5SUM && hash_algo == HASH_MD5) {
  807. + md5_begin(&context.md5);
  808. + update = (void*)md5_hash;
  809. + final = (void*)md5_end;
  810. + hash_len = 16;
  811. + } else {
  812. + bb_error_msg_and_die("algorithm not supported");
  813. + }
  814. +
  815. + while (0 < (count = safe_read(src_fd, in_buf, 4096))) {
  816. + update(in_buf, count, &context);
  817. + }
  818. +
  819. + if (count == 0) {
  820. + final(in_buf, &context);
  821. + hash_value = hash_bin_to_hex(in_buf, hash_len);
  822. + }
  823. +
  824. + RELEASE_CONFIG_BUFFER(in_buf);
  825. +
  826. + if (src_fd != STDIN_FILENO) {
  827. + close(src_fd);
  828. + }
  829. +
  830. + return hash_value;
  831. +}
  832. +
  833. +uint8_t *file_md5sum_alloc(const char *file_name)
  834. +{
  835. + return hash_file(file_name, HASH_MD5);
  836. +}
  837. +
  838. diff -Nur busybox-1.17.2.orig/archival/libipkg/file_util.h busybox-1.17.2/archival/libipkg/file_util.h
  839. --- busybox-1.17.2.orig/archival/libipkg/file_util.h 1970-01-01 01:00:00.000000000 +0100
  840. +++ busybox-1.17.2/archival/libipkg/file_util.h 2010-12-01 22:25:23.000000000 +0100
  841. @@ -0,0 +1,29 @@
  842. +/* file_util.h - convenience routines for common file operations
  843. +
  844. + Carl D. Worth
  845. +
  846. + Copyright (C) 2001 University of Southern California
  847. +
  848. + This program is free software; you can redistribute it and/or
  849. + modify it under the terms of the GNU General Public License as
  850. + published by the Free Software Foundation; either version 2, or (at
  851. + your option) any later version.
  852. +
  853. + This program is distributed in the hope that it will be useful, but
  854. + WITHOUT ANY WARRANTY; without even the implied warranty of
  855. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  856. + General Public License for more details.
  857. +*/
  858. +
  859. +#ifndef FILE_UTIL_H
  860. +#define FILE_UTIL_H
  861. +
  862. +int file_exists(const char *file_name);
  863. +int file_is_dir(const char *file_name);
  864. +char *file_read_line_alloc(FILE *file);
  865. +int file_move(const char *src, const char *dest);
  866. +int file_copy(const char *src, const char *dest);
  867. +int file_mkdir_hier(char *path, long mode);
  868. +uint8_t *file_md5sum_alloc(const char *file_name);
  869. +
  870. +#endif
  871. diff -Nur busybox-1.17.2.orig/archival/libipkg/hash_table.c busybox-1.17.2/archival/libipkg/hash_table.c
  872. --- busybox-1.17.2.orig/archival/libipkg/hash_table.c 1970-01-01 01:00:00.000000000 +0100
  873. +++ busybox-1.17.2/archival/libipkg/hash_table.c 2010-12-01 22:25:23.000000000 +0100
  874. @@ -0,0 +1,155 @@
  875. +/* hash.c - hash tables for ipkg
  876. +
  877. + Steven M. Ayer, Jamey Hicks
  878. +
  879. + Copyright (C) 2002 Compaq Computer Corporation
  880. +
  881. + This program is free software; you can redistribute it and/or
  882. + modify it under the terms of the GNU General Public License as
  883. + published by the Free Software Foundation; either version 2, or (at
  884. + your option) any later version.
  885. +
  886. + This program is distributed in the hope that it will be useful, but
  887. + WITHOUT ANY WARRANTY; without even the implied warranty of
  888. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  889. + General Public License for more details.
  890. +*/
  891. +
  892. +#include <errno.h>
  893. +#include <stdio.h>
  894. +#include <stdlib.h>
  895. +#include <string.h>
  896. +#include "hash_table.h"
  897. +#include "ipkg_message.h"
  898. +
  899. +
  900. +static int hash_index(hash_table_t *hash, const char *pkg_name);
  901. +static int rotating(const char *key, int len, int prime);
  902. +
  903. +static int hash_index(hash_table_t *hash, const char *pkg_name)
  904. +{
  905. + return rotating(pkg_name, strlen(pkg_name), hash->n_entries);
  906. +}
  907. +
  908. +static int rotating(const char *key, int len, int prime)
  909. +{
  910. + unsigned int hash, i;
  911. + for (hash=len, i=0; i<len; ++i)
  912. + hash = (hash<<4)^(hash>>28)^key[i];
  913. + return (hash % prime);
  914. +}
  915. +
  916. +
  917. +/*
  918. + * this is an open table keyed by strings
  919. + */
  920. +int hash_table_init(const char *name, hash_table_t *hash, int len)
  921. +{
  922. + static int primes_table[] = {
  923. + 379, 761, 983, 1423, 2711, 3361, 3931, 4679, 5519, 6701, 9587,
  924. + 19471, 23143, 33961, 46499, 49727, 99529, 0
  925. + };
  926. + int *picker;
  927. +
  928. + if (hash->entries != NULL) {
  929. + /* we have been here already */
  930. + return 0;
  931. + }
  932. +
  933. + hash->name = name;
  934. + hash->entries = NULL;
  935. + hash->n_entries = 0;
  936. + hash->hash_entry_key = NULL;
  937. +
  938. + picker = primes_table;
  939. + while(*picker && (*picker++ < len));
  940. + if(!*picker)
  941. + fprintf(stderr, "%s: primes table might not be big enough (! << %d)\n", __FUNCTION__, len);
  942. + --picker;
  943. +
  944. + hash->n_entries = *picker;
  945. + hash->entries = (hash_entry_t *)calloc(hash->n_entries, sizeof(hash_entry_t));
  946. + if (hash->entries == NULL) {
  947. + fprintf(stderr, "%s: Out of memory.\n", __FUNCTION__);
  948. + return ENOMEM;
  949. + }
  950. + return 0;
  951. +}
  952. +
  953. +void hash_table_deinit(hash_table_t *hash)
  954. +{
  955. + free(hash->entries);
  956. + hash->entries = NULL;
  957. + hash->n_entries = 0;
  958. +}
  959. +
  960. +void *hash_table_get(hash_table_t *hash, const char *key)
  961. +{
  962. + int ndx= hash_index(hash, key);
  963. + hash_entry_t *hash_entry = hash->entries + ndx;
  964. + while (hash_entry)
  965. + {
  966. + if (hash_entry->key)
  967. + {
  968. + if (strcmp(key, hash_entry->key) == 0) {
  969. + // ipkg_message(NULL, IPKG_DEBUG, "Function: %s. Key found for '%s' \n", __FUNCTION__, key);
  970. + return hash_entry->data;
  971. + }
  972. + }
  973. + hash_entry = hash_entry->next;
  974. + }
  975. + return NULL;
  976. +}
  977. +
  978. +int hash_table_insert(hash_table_t *hash, const char *key, void *value)
  979. +{
  980. + int ndx= hash_index(hash, key);
  981. + hash_entry_t *hash_entry = hash->entries + ndx;
  982. + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Inserting in hash for '%s' \n", __FUNCTION__, key);
  983. + if (hash_entry->key) {
  984. + if (strcmp(hash_entry->key, key) == 0) {
  985. + /* alread in table, update the value */
  986. + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Value already in hash for '%s' \n", __FUNCTION__, key);
  987. + hash_entry->data = value;
  988. + return 0;
  989. + } else {
  990. + /*
  991. + * if this is a collision, we have to go to the end of the ll,
  992. + * then add a new entry
  993. + * before we can hook up the value
  994. + */
  995. + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Value already in hash by collision for '%s' \n", __FUNCTION__, key);
  996. + while (hash_entry->next)
  997. + hash_entry = hash_entry->next;
  998. + hash_entry->next = (hash_entry_t *)malloc(sizeof(hash_entry_t));
  999. + if (!hash_entry->next) {
  1000. + return -ENOMEM;
  1001. + }
  1002. + hash_entry = hash_entry->next;
  1003. + hash_entry->next = NULL;
  1004. + }
  1005. + }
  1006. + hash->n_elements++;
  1007. + hash_entry->key = strdup(key);
  1008. + hash_entry->data = value;
  1009. +
  1010. + return 0;
  1011. +}
  1012. +
  1013. +
  1014. +void hash_table_foreach(hash_table_t *hash, void (*f)(const char *key, void *entry, void *data), void *data)
  1015. +{
  1016. + int i;
  1017. + if (!hash || !f)
  1018. + return;
  1019. +
  1020. + for (i = 0; i < hash->n_entries; i++) {
  1021. + hash_entry_t *hash_entry = (hash->entries + i);
  1022. + do {
  1023. + if(hash_entry->key) {
  1024. + f(hash_entry->key, hash_entry->data, data);
  1025. + }
  1026. + } while((hash_entry = hash_entry->next));
  1027. + }
  1028. +}
  1029. +
  1030. diff -Nur busybox-1.17.2.orig/archival/libipkg/hash_table.h busybox-1.17.2/archival/libipkg/hash_table.h
  1031. --- busybox-1.17.2.orig/archival/libipkg/hash_table.h 1970-01-01 01:00:00.000000000 +0100
  1032. +++ busybox-1.17.2/archival/libipkg/hash_table.h 2010-12-01 22:25:23.000000000 +0100
  1033. @@ -0,0 +1,44 @@
  1034. +/* hash.h - hash tables for ipkg
  1035. +
  1036. + Steven M. Ayer, Jamey Hicks
  1037. +
  1038. + Copyright (C) 2002 Compaq Computer Corporation
  1039. +
  1040. + This program is free software; you can redistribute it and/or
  1041. + modify it under the terms of the GNU General Public License as
  1042. + published by the Free Software Foundation; either version 2, or (at
  1043. + your option) any later version.
  1044. +
  1045. + This program is distributed in the hope that it will be useful, but
  1046. + WITHOUT ANY WARRANTY; without even the implied warranty of
  1047. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  1048. + General Public License for more details.
  1049. +*/
  1050. +
  1051. +#ifndef _HASH_TABLE_H_
  1052. +#define _HASH_TABLE_H_
  1053. +
  1054. +typedef struct hash_entry hash_entry_t;
  1055. +typedef struct hash_table hash_table_t;
  1056. +
  1057. +struct hash_entry {
  1058. + const char * key;
  1059. + void * data;
  1060. + struct hash_entry * next;
  1061. +};
  1062. +
  1063. +struct hash_table {
  1064. + const char *name;
  1065. + hash_entry_t * entries;
  1066. + int n_entries; /* number of buckets */
  1067. + int n_elements;
  1068. + const char * (*hash_entry_key)(void * data);
  1069. +};
  1070. +
  1071. +int hash_table_init(const char *name, hash_table_t *hash, int len);
  1072. +void hash_table_deinit(hash_table_t *hash);
  1073. +void *hash_table_get(hash_table_t *hash, const char *key);
  1074. +int hash_table_insert(hash_table_t *hash, const char *key, void *value);
  1075. +void hash_table_foreach(hash_table_t *hash, void (*f)(const char *key, void *entry, void *data), void *data);
  1076. +
  1077. +#endif /* _HASH_TABLE_H_ */
  1078. diff -Nur busybox-1.17.2.orig/archival/libipkg/ipkg.h busybox-1.17.2/archival/libipkg/ipkg.h
  1079. --- busybox-1.17.2.orig/archival/libipkg/ipkg.h 1970-01-01 01:00:00.000000000 +0100
  1080. +++ busybox-1.17.2/archival/libipkg/ipkg.h 2010-12-01 22:25:23.000000000 +0100
  1081. @@ -0,0 +1,68 @@
  1082. +/* ipkg.h - the itsy package management system
  1083. +
  1084. + Carl D. Worth
  1085. +
  1086. + Copyright (C) 2001 University of Southern California
  1087. +
  1088. + This program is free software; you can redistribute it and/or
  1089. + modify it under the terms of the GNU General Public License as
  1090. + published by the Free Software Foundation; either version 2, or (at
  1091. + your option) any later version.
  1092. +
  1093. + This program is distributed in the hope that it will be useful, but
  1094. + WITHOUT ANY WARRANTY; without even the implied warranty of
  1095. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  1096. + General Public License for more details.
  1097. +*/
  1098. +
  1099. +#ifndef IPKG_H
  1100. +#define IPKG_H
  1101. +
  1102. +#include "libbb.h"
  1103. +
  1104. +#include "ipkg_includes.h"
  1105. +#include "ipkg_conf.h"
  1106. +#include "ipkg_message.h"
  1107. +
  1108. +#define IPKG_PKG_EXTENSION ".ipk"
  1109. +#define DPKG_PKG_EXTENSION ".deb"
  1110. +
  1111. +#define IPKG_LEGAL_PKG_NAME_CHARS "abcdefghijklmnopqrstuvwxyz0123456789.+-"
  1112. +#define IPKG_PKG_VERSION_SEP_CHAR '_'
  1113. +
  1114. +#define IPKG_STATE_DIR_PREFIX IPKGLIBDIR"/ipkg"
  1115. +#define IPKG_LISTS_DIR_SUFFIX "lists"
  1116. +#define IPKG_INFO_DIR_SUFFIX "info"
  1117. +#define IPKG_STATUS_FILE_SUFFIX "status"
  1118. +
  1119. +#define IPKG_BACKUP_SUFFIX "-ipkg.backup"
  1120. +
  1121. +#define IPKG_LIST_DESCRIPTION_LENGTH 128
  1122. +
  1123. +#define IPKG_VERSION "1.00"
  1124. +
  1125. +
  1126. +enum ipkg_error {
  1127. + IPKG_SUCCESS = 0,
  1128. + IPKG_PKG_DEPS_UNSATISFIED,
  1129. + IPKG_PKG_IS_ESSENTIAL,
  1130. + IPKG_PKG_HAS_DEPENDENTS,
  1131. + IPKG_PKG_HAS_NO_CANDIDATE
  1132. +};
  1133. +typedef enum ipkg_error ipkg_error_t;
  1134. +
  1135. +extern int ipkg_state_changed;
  1136. +
  1137. +
  1138. +struct errlist {
  1139. + char * errmsg;
  1140. + struct errlist * next;
  1141. +} ;
  1142. +
  1143. +extern struct errlist* error_list;
  1144. +
  1145. +extern ipkg_conf_t *global_conf;
  1146. +
  1147. +typedef enum { HASH_SHA1, HASH_MD5 } hash_algo_t;
  1148. +
  1149. +#endif
  1150. diff -Nur busybox-1.17.2.orig/archival/libipkg/ipkg_cmd.c busybox-1.17.2/archival/libipkg/ipkg_cmd.c
  1151. --- busybox-1.17.2.orig/archival/libipkg/ipkg_cmd.c 1970-01-01 01:00:00.000000000 +0100
  1152. +++ busybox-1.17.2/archival/libipkg/ipkg_cmd.c 2010-12-01 22:25:23.000000000 +0100
  1153. @@ -0,0 +1,1366 @@
  1154. +/* ipkg_cmd.c - the itsy package management system
  1155. +
  1156. + Carl D. Worth
  1157. +
  1158. + Copyright (C) 2001 University of Southern California
  1159. +
  1160. + This program is free software; you can redistribute it and/or
  1161. + modify it under the terms of the GNU General Public License as
  1162. + published by the Free Software Foundation; either version 2, or (at
  1163. + your option) any later version.
  1164. +
  1165. + This program is distributed in the hope that it will be useful, but
  1166. + WITHOUT ANY WARRANTY; without even the implied warranty of
  1167. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  1168. + General Public License for more details.
  1169. +*/
  1170. +
  1171. +#include <string.h>
  1172. +
  1173. +#include "ipkg.h"
  1174. +#include <libgen.h>
  1175. +#include <glob.h>
  1176. +#include <errno.h>
  1177. +#include <stdlib.h>
  1178. +#include <unistd.h>
  1179. +#include <signal.h>
  1180. +#include <stdio.h>
  1181. +#include <dirent.h>
  1182. +
  1183. +#include "ipkg_conf.h"
  1184. +#include "ipkg_cmd.h"
  1185. +#include "ipkg_message.h"
  1186. +#include "pkg.h"
  1187. +#include "pkg_dest.h"
  1188. +#include "pkg_parse.h"
  1189. +#include "sprintf_alloc.h"
  1190. +#include "pkg.h"
  1191. +#include "file_util.h"
  1192. +#include "str_util.h"
  1193. +#include "unarchive.h"
  1194. +
  1195. +#include <fnmatch.h>
  1196. +
  1197. +
  1198. +#include "ipkg_download.h"
  1199. +#include "ipkg_install.h"
  1200. +#include "ipkg_upgrade.h"
  1201. +#include "ipkg_remove.h"
  1202. +#include "ipkg_configure.h"
  1203. +#include "ipkg_message.h"
  1204. +
  1205. +#include "libipkg.h"
  1206. +static void *p_userdata = NULL;
  1207. +
  1208. +static int ipkg_update_cmd(ipkg_conf_t *conf);
  1209. +static int ipkg_upgrade_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1210. +static int ipkg_list_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1211. +static int ipkg_info_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1212. +static int ipkg_status_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1213. +static int ipkg_install_pending_cmd(ipkg_conf_t *conf);
  1214. +static int ipkg_install_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1215. +static int ipkg_list_installed_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1216. +static int ipkg_remove_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1217. +static int ipkg_purge_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1218. +static int ipkg_flag_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1219. +static int ipkg_files_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1220. +static int ipkg_search_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1221. +static int ipkg_download_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1222. +static int ipkg_depends_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1223. +static int ipkg_whatdepends_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1224. +static int ipkg_whatdepends_recursively_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1225. +static int ipkg_whatsuggests_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1226. +static int ipkg_whatrecommends_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1227. +static int ipkg_whatprovides_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1228. +static int ipkg_whatconflicts_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1229. +static int ipkg_whatreplaces_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1230. +static int ipkg_compare_versions_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1231. +static int ipkg_print_architecture_cmd(ipkg_conf_t *conf);
  1232. +static int ipkg_configure_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1233. +
  1234. +/* XXX: CLEANUP: The usage strings should be incorporated into this
  1235. + array for easier maintenance */
  1236. +static ipkg_cmd_t cmds[] = {
  1237. + {"update", 0, (ipkg_cmd_fun_t)ipkg_update_cmd},
  1238. + {"upgrade", 0, (ipkg_cmd_fun_t)ipkg_upgrade_cmd},
  1239. + {"list", 0, (ipkg_cmd_fun_t)ipkg_list_cmd},
  1240. + {"list_installed", 0, (ipkg_cmd_fun_t)ipkg_list_installed_cmd},
  1241. + {"info", 0, (ipkg_cmd_fun_t)ipkg_info_cmd},
  1242. + {"flag", 1, (ipkg_cmd_fun_t)ipkg_flag_cmd},
  1243. + {"status", 0, (ipkg_cmd_fun_t)ipkg_status_cmd},
  1244. + {"install_pending", 0, (ipkg_cmd_fun_t)ipkg_install_pending_cmd},
  1245. + {"install", 1, (ipkg_cmd_fun_t)ipkg_install_cmd},
  1246. + {"remove", 1, (ipkg_cmd_fun_t)ipkg_remove_cmd},
  1247. + {"purge", 1, (ipkg_cmd_fun_t)ipkg_purge_cmd},
  1248. + {"configure", 0, (ipkg_cmd_fun_t)ipkg_configure_cmd},
  1249. + {"files", 1, (ipkg_cmd_fun_t)ipkg_files_cmd},
  1250. + {"search", 1, (ipkg_cmd_fun_t)ipkg_search_cmd},
  1251. + {"download", 1, (ipkg_cmd_fun_t)ipkg_download_cmd},
  1252. + {"compare_versions", 1, (ipkg_cmd_fun_t)ipkg_compare_versions_cmd},
  1253. + {"compare-versions", 1, (ipkg_cmd_fun_t)ipkg_compare_versions_cmd},
  1254. + {"print-architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
  1255. + {"print_architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
  1256. + {"print-installation-architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
  1257. + {"print_installation_architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
  1258. + {"depends", 1, (ipkg_cmd_fun_t)ipkg_depends_cmd},
  1259. + {"whatdepends", 1, (ipkg_cmd_fun_t)ipkg_whatdepends_cmd},
  1260. + {"whatdependsrec", 1, (ipkg_cmd_fun_t)ipkg_whatdepends_recursively_cmd},
  1261. + {"whatrecommends", 1, (ipkg_cmd_fun_t)ipkg_whatrecommends_cmd},
  1262. + {"whatsuggests", 1, (ipkg_cmd_fun_t)ipkg_whatsuggests_cmd},
  1263. + {"whatprovides", 1, (ipkg_cmd_fun_t)ipkg_whatprovides_cmd},
  1264. + {"whatreplaces", 1, (ipkg_cmd_fun_t)ipkg_whatreplaces_cmd},
  1265. + {"whatconflicts", 1, (ipkg_cmd_fun_t)ipkg_whatconflicts_cmd},
  1266. +};
  1267. +
  1268. +int ipkg_state_changed;
  1269. +static void write_status_files_if_changed(ipkg_conf_t *conf)
  1270. +{
  1271. + if (ipkg_state_changed && !conf->noaction) {
  1272. + ipkg_message(conf, IPKG_INFO,
  1273. + " writing status file\n");
  1274. + ipkg_conf_write_status_files(conf);
  1275. + pkg_write_changed_filelists(conf);
  1276. + } else {
  1277. + ipkg_message(conf, IPKG_NOTICE, "Nothing to be done\n");
  1278. + }
  1279. +}
  1280. +
  1281. +
  1282. +static int num_cmds = sizeof(cmds) / sizeof(ipkg_cmd_t);
  1283. +
  1284. +ipkg_cmd_t *ipkg_cmd_find(const char *name)
  1285. +{
  1286. + int i;
  1287. + ipkg_cmd_t *cmd;
  1288. +
  1289. + for (i=0; i < num_cmds; i++) {
  1290. + cmd = &cmds[i];
  1291. + if (strcmp(name, cmd->name) == 0) {
  1292. + return cmd;
  1293. + }
  1294. + }
  1295. +
  1296. + return NULL;
  1297. +}
  1298. +
  1299. +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc, const char **argv, void *userdata)
  1300. +{
  1301. + int result;
  1302. + p_userdata = userdata;
  1303. +
  1304. +
  1305. + result = (cmd->fun)(conf, argc, argv);
  1306. + if ( result == 0 ) {
  1307. + ipkg_message(conf, IPKG_NOTICE, "Done.\n");
  1308. + } else {
  1309. + ipkg_message(conf, IPKG_NOTICE, "An error ocurred, return value: %d.\n", result);
  1310. +
  1311. + }
  1312. + if ( error_list ) {
  1313. + reverse_error_list(&error_list);
  1314. +
  1315. + ipkg_message(conf, IPKG_NOTICE, "Collected errors:\n");
  1316. + /* Here we print the errors collected and free the list */
  1317. + while (error_list != NULL) {
  1318. + ipkg_message(conf, IPKG_NOTICE, "%s",error_list->errmsg);
  1319. + error_list = error_list->next;
  1320. +
  1321. + }
  1322. + free_error_list(&error_list);
  1323. +
  1324. + }
  1325. +
  1326. + p_userdata = NULL;
  1327. + return result;
  1328. +}
  1329. +
  1330. +static int ipkg_update_cmd(ipkg_conf_t *conf)
  1331. +{
  1332. + int err;
  1333. + int failures;
  1334. + char *lists_dir;
  1335. + pkg_src_list_elt_t *iter;
  1336. + pkg_src_t *src;
  1337. +
  1338. +
  1339. + sprintf_alloc(&lists_dir, "%s", conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir);
  1340. +
  1341. + if (! file_is_dir(lists_dir)) {
  1342. + if (file_exists(lists_dir)) {
  1343. + ipkg_message(conf, IPKG_ERROR,
  1344. + "%s: ERROR: %s exists, but is not a directory\n",
  1345. + __FUNCTION__, lists_dir);
  1346. + free(lists_dir);
  1347. + return EINVAL;
  1348. + }
  1349. + err = file_mkdir_hier(lists_dir, 0755);
  1350. + if (err) {
  1351. + ipkg_message(conf, IPKG_ERROR,
  1352. + "%s: ERROR: failed to make directory %s: %s\n",
  1353. + __FUNCTION__, lists_dir, strerror(errno));
  1354. + free(lists_dir);
  1355. + return EINVAL;
  1356. + }
  1357. + }
  1358. +
  1359. + failures = 0;
  1360. + for (iter = conf->pkg_src_list.head; iter; iter = iter->next) {
  1361. + char *url, *list_file_name;
  1362. +
  1363. + src = iter->data;
  1364. +
  1365. + if (src->extra_data) /* debian style? */
  1366. + sprintf_alloc(&url, "%s/%s/%s", src->value, src->extra_data,
  1367. + src->gzip ? "Packages.gz" : "Packages");
  1368. + else
  1369. + sprintf_alloc(&url, "%s/%s", src->value, src->gzip ? "Packages.gz" : "Packages");
  1370. +
  1371. + sprintf_alloc(&list_file_name, "%s/%s", lists_dir, src->name);
  1372. + if (src->gzip) {
  1373. + char *tmp;
  1374. + char *tmp_file_name;
  1375. + FILE *in, *out;
  1376. +
  1377. + tmp = strdup ("/tmp/ipkg.XXXXXX");
  1378. +
  1379. + if (mkdtemp (tmp) == NULL) {
  1380. + perror ("mkdtemp");
  1381. + failures++;
  1382. + continue;
  1383. + }
  1384. +
  1385. + sprintf_alloc (&tmp_file_name, "%s/%s.gz", tmp, src->name);
  1386. + err = ipkg_download(conf, url, tmp_file_name);
  1387. + if (err == 0) {
  1388. + ipkg_message (conf, IPKG_NOTICE, "Inflating %s\n", url);
  1389. + in = fopen (tmp_file_name, "r");
  1390. + out = fopen (list_file_name, "w");
  1391. + if (in && out) {
  1392. + inflate_unzip_result res;
  1393. + inflate_unzip (&res, 0x8000, fileno(in), fileno(out));
  1394. + } else
  1395. + err = 1;
  1396. + if (in)
  1397. + fclose (in);
  1398. + if (out)
  1399. + fclose (out);
  1400. + unlink (tmp_file_name);
  1401. + rmdir (tmp);
  1402. + free (tmp);
  1403. + }
  1404. + } else
  1405. + err = ipkg_download(conf, url, list_file_name);
  1406. + if (err) {
  1407. + failures++;
  1408. + } else {
  1409. + ipkg_message(conf, IPKG_NOTICE,
  1410. + "Updated list of available packages in %s\n",
  1411. + list_file_name);
  1412. + }
  1413. + free(url);
  1414. + free(list_file_name);
  1415. + }
  1416. + free(lists_dir);
  1417. +
  1418. +#ifdef CONFIG_CLEAR_SW_INSTALL_FLAG
  1419. +#warning here
  1420. + /* clear SW_INSTALL on any package where state is SS_NOT_INSTALLED.
  1421. + * this is a hack to work around poor bookkeeping in old ipkg upgrade code
  1422. + * -Jamey 3/1/03
  1423. + */
  1424. + {
  1425. + int i;
  1426. + int changed = 0;
  1427. + pkg_vec_t *available = pkg_vec_alloc();
  1428. + pkg_hash_fetch_available(&conf->pkg_hash, available);
  1429. + ipkg_message(conf, IPKG_DEBUG, "Clearing SW_INSTALL for SS_NOT_INSTALLED packages.\n");
  1430. + for (i = 0; i < available->len; i++) {
  1431. + pkg_t *pkg = available->pkgs[i];
  1432. + if (pkg->state_want == SW_INSTALL && pkg->state_status == SS_NOT_INSTALLED) {
  1433. + ipkg_message(conf, IPKG_DEBUG, "Clearing SW_INSTALL on package %s.\n", pkg->name);
  1434. + pkg->state_want = SW_UNKNOWN;
  1435. + changed = 1;
  1436. + }
  1437. + }
  1438. + pkg_vec_free(available);
  1439. + if (changed) {
  1440. + write_status_files_if_changed(conf);
  1441. + }
  1442. + }
  1443. +#endif
  1444. +
  1445. + return failures;
  1446. +}
  1447. +
  1448. +
  1449. +/* scan the args passed and cache the local filenames of the packages */
  1450. +int ipkg_multiple_files_scan(ipkg_conf_t *conf, int argc, char **argv)
  1451. +{
  1452. + int i;
  1453. + int err;
  1454. +
  1455. + /*
  1456. + * First scan through package names/urls
  1457. + * For any urls, download the packages and install in database.
  1458. + * For any files, install package info in database.
  1459. + */
  1460. + for (i = 0; i < argc; i ++) {
  1461. + char *filename = argv [i];
  1462. + //char *tmp = basename (tmp);
  1463. + //int tmplen = strlen (tmp);
  1464. +
  1465. + //if (strcmp (tmp + (tmplen - strlen (IPKG_PKG_EXTENSION)), IPKG_PKG_EXTENSION) != 0)
  1466. + // continue;
  1467. + //if (strcmp (tmp + (tmplen - strlen (DPKG_PKG_EXTENSION)), DPKG_PKG_EXTENSION) != 0)
  1468. + // continue;
  1469. +
  1470. + ipkg_message(conf, IPKG_DEBUG2, "Debug mfs: %s \n",filename );
  1471. +
  1472. + err = ipkg_prepare_url_for_install(conf, filename, &argv[i]);
  1473. + if (err)
  1474. + return err;
  1475. + }
  1476. + return 0;
  1477. +}
  1478. +
  1479. +struct ipkg_intercept
  1480. +{
  1481. + char *oldpath;
  1482. + char *statedir;
  1483. +};
  1484. +
  1485. +typedef struct ipkg_intercept *ipkg_intercept_t;
  1486. +ipkg_intercept_t ipkg_prep_intercepts(void);
  1487. +
  1488. +ipkg_intercept_t ipkg_prep_intercepts(void)
  1489. +{
  1490. + ipkg_intercept_t ctx;
  1491. + char *newpath;
  1492. + int gen;
  1493. +
  1494. + ctx = malloc (sizeof (*ctx));
  1495. + ctx->oldpath = strdup (getenv ("PATH"));
  1496. +
  1497. + sprintf_alloc (&newpath, "%s/ipkg/intercept:%s", IPKGLIBDIR, ctx->oldpath);
  1498. + setenv ("PATH", newpath, 1);
  1499. + free (newpath);
  1500. +
  1501. + gen = 0;
  1502. + retry:
  1503. + sprintf_alloc (&ctx->statedir, "/tmp/ipkg-intercept-%d-%d", getpid (), gen);
  1504. + if (mkdir (ctx->statedir, 0770) < 0) {
  1505. + if (errno == EEXIST) {
  1506. + free (ctx->statedir);
  1507. + gen++;
  1508. + goto retry;
  1509. + }
  1510. + perror (ctx->statedir);
  1511. + return NULL;
  1512. + }
  1513. + setenv ("IPKG_INTERCEPT_DIR", ctx->statedir, 1);
  1514. + return ctx;
  1515. +}
  1516. +
  1517. +int ipkg_finalize_intercepts(ipkg_intercept_t ctx);
  1518. +
  1519. +int ipkg_finalize_intercepts(ipkg_intercept_t ctx)
  1520. +{
  1521. + char *cmd;
  1522. + DIR *dir;
  1523. + int err = 0;
  1524. +
  1525. + setenv ("PATH", ctx->oldpath, 1);
  1526. + free (ctx->oldpath);
  1527. +
  1528. + dir = opendir (ctx->statedir);
  1529. + if (dir) {
  1530. + struct dirent *de;
  1531. + while (de = readdir (dir), de != NULL) {
  1532. + char *path;
  1533. +
  1534. + if (de->d_name[0] == '.')
  1535. + continue;
  1536. +
  1537. + sprintf_alloc (&path, "%s/%s", ctx->statedir, de->d_name);
  1538. + if (access (path, X_OK) == 0) {
  1539. + if (system (path)) {
  1540. + err = errno;
  1541. + perror (de->d_name);
  1542. + }
  1543. + }
  1544. + free (path);
  1545. + }
  1546. + } else
  1547. + perror (ctx->statedir);
  1548. +
  1549. + sprintf_alloc (&cmd, "rm -rf %s", ctx->statedir);
  1550. + system (cmd);
  1551. + free (cmd);
  1552. +
  1553. + free (ctx->statedir);
  1554. + free (ctx);
  1555. +
  1556. + return err;
  1557. +}
  1558. +
  1559. +int ipkg_configure_packages(ipkg_conf_t *conf, char *pkg_name)
  1560. +{
  1561. + pkg_vec_t *all;
  1562. + int i;
  1563. + pkg_t *pkg;
  1564. + ipkg_intercept_t ic;
  1565. + int r, err = 0;
  1566. +
  1567. + ipkg_message(conf, IPKG_INFO,
  1568. + "Configuring unpacked packages\n");
  1569. + fflush( stdout );
  1570. +
  1571. + all = pkg_vec_alloc();
  1572. + pkg_hash_fetch_available(&conf->pkg_hash, all);
  1573. +
  1574. + ic = ipkg_prep_intercepts();
  1575. +
  1576. + for(i = 0; i < all->len; i++) {
  1577. + pkg = all->pkgs[i];
  1578. +
  1579. + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
  1580. + continue;
  1581. +
  1582. + if (pkg->state_status == SS_UNPACKED) {
  1583. + ipkg_message(conf, IPKG_NOTICE,
  1584. + "Configuring %s\n", pkg->name);
  1585. + fflush( stdout );
  1586. + r = ipkg_configure(conf, pkg);
  1587. + if (r == 0) {
  1588. + pkg->state_status = SS_INSTALLED;
  1589. + pkg->parent->state_status = SS_INSTALLED;
  1590. + pkg->state_flag &= ~SF_PREFER;
  1591. + } else {
  1592. + if (!err)
  1593. + err = r;
  1594. + }
  1595. + }
  1596. + }
  1597. +
  1598. + r = ipkg_finalize_intercepts (ic);
  1599. + if (r && !err)
  1600. + err = r;
  1601. +
  1602. + pkg_vec_free(all);
  1603. + return err;
  1604. +}
  1605. +
  1606. +static void sigint_handler(int sig)
  1607. +{
  1608. + signal(sig, SIG_DFL);
  1609. + ipkg_message(NULL, IPKG_NOTICE,
  1610. + "ipkg: interrupted. writing out status database\n");
  1611. + write_status_files_if_changed(global_conf);
  1612. + exit(128 + sig);
  1613. +}
  1614. +
  1615. +static int ipkg_install_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1616. +{
  1617. + int i;
  1618. + char *arg;
  1619. + int err=0;
  1620. +
  1621. + global_conf = conf;
  1622. + signal(SIGINT, sigint_handler);
  1623. +
  1624. + /*
  1625. + * Now scan through package names and install
  1626. + */
  1627. + for (i=0; i < argc; i++) {
  1628. + arg = argv[i];
  1629. +
  1630. + ipkg_message(conf, IPKG_DEBUG2, "Debug install_cmd: %s \n",arg );
  1631. + err = ipkg_prepare_url_for_install(conf, arg, &argv[i]);
  1632. + if (err != EINVAL && err != 0)
  1633. + return err;
  1634. + }
  1635. + pkg_info_preinstall_check(conf);
  1636. +
  1637. + for (i=0; i < argc; i++) {
  1638. + arg = argv[i];
  1639. + if (conf->multiple_providers)
  1640. + err = ipkg_install_multi_by_name(conf, arg);
  1641. + else{
  1642. + err = ipkg_install_by_name(conf, arg);
  1643. + }
  1644. + if (err == IPKG_PKG_HAS_NO_CANDIDATE) {
  1645. + ipkg_message(conf, IPKG_ERROR,
  1646. + "Cannot find package %s.\n"
  1647. + "Check the spelling or perhaps run 'ipkg update'\n",
  1648. + arg);
  1649. + }
  1650. + }
  1651. +
  1652. + /* recheck to verify that all dependences are satisfied */
  1653. + if (0) ipkg_satisfy_all_dependences(conf);
  1654. +
  1655. + ipkg_configure_packages(conf, NULL);
  1656. +
  1657. + write_status_files_if_changed(conf);
  1658. +
  1659. + return err;
  1660. +}
  1661. +
  1662. +static int ipkg_upgrade_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1663. +{
  1664. + int i;
  1665. + pkg_t *pkg;
  1666. + int err;
  1667. +
  1668. + global_conf = conf;
  1669. + signal(SIGINT, sigint_handler);
  1670. +
  1671. + if (argc) {
  1672. + for (i=0; i < argc; i++) {
  1673. + char *arg = argv[i];
  1674. +
  1675. + err = ipkg_prepare_url_for_install(conf, arg, &arg);
  1676. + if (err != EINVAL && err != 0)
  1677. + return err;
  1678. + }
  1679. + pkg_info_preinstall_check(conf);
  1680. +
  1681. + for (i=0; i < argc; i++) {
  1682. + char *arg = argv[i];
  1683. + if (conf->restrict_to_default_dest) {
  1684. + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
  1685. + argv[i],
  1686. + conf->default_dest);
  1687. + if (pkg == NULL) {
  1688. + ipkg_message(conf, IPKG_NOTICE,
  1689. + "Package %s not installed in %s\n",
  1690. + argv[i], conf->default_dest->name);
  1691. + continue;
  1692. + }
  1693. + } else {
  1694. + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash,
  1695. + argv[i]);
  1696. + }
  1697. + if (pkg)
  1698. + ipkg_upgrade_pkg(conf, pkg);
  1699. + else {
  1700. + ipkg_install_by_name(conf, arg);
  1701. + }
  1702. + }
  1703. + } else {
  1704. + pkg_vec_t *installed = pkg_vec_alloc();
  1705. +
  1706. + pkg_info_preinstall_check(conf);
  1707. +
  1708. + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
  1709. + for (i = 0; i < installed->len; i++) {
  1710. + pkg = installed->pkgs[i];
  1711. + ipkg_upgrade_pkg(conf, pkg);
  1712. + }
  1713. + pkg_vec_free(installed);
  1714. + }
  1715. +
  1716. + /* recheck to verify that all dependences are satisfied */
  1717. + if (0) ipkg_satisfy_all_dependences(conf);
  1718. +
  1719. + ipkg_configure_packages(conf, NULL);
  1720. +
  1721. + write_status_files_if_changed(conf);
  1722. +
  1723. + return 0;
  1724. +}
  1725. +
  1726. +static int ipkg_download_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1727. +{
  1728. + int i, err;
  1729. + char *arg;
  1730. + pkg_t *pkg;
  1731. +
  1732. + pkg_info_preinstall_check(conf);
  1733. + for (i = 0; i < argc; i++) {
  1734. + arg = argv[i];
  1735. +
  1736. + pkg = pkg_hash_fetch_best_installation_candidate_by_name(conf, arg);
  1737. + if (pkg == NULL) {
  1738. + ipkg_message(conf, IPKG_ERROR,
  1739. + "Cannot find package %s.\n"
  1740. + "Check the spelling or perhaps run 'ipkg update'\n",
  1741. + arg);
  1742. + continue;
  1743. + }
  1744. +
  1745. + err = ipkg_download_pkg(conf, pkg, ".");
  1746. +
  1747. + if (err) {
  1748. + ipkg_message(conf, IPKG_ERROR,
  1749. + "Failed to download %s\n", pkg->name);
  1750. + } else {
  1751. + ipkg_message(conf, IPKG_NOTICE,
  1752. + "Downloaded %s as %s\n",
  1753. + pkg->name, pkg->local_filename);
  1754. + }
  1755. + }
  1756. +
  1757. + return 0;
  1758. +}
  1759. +
  1760. +
  1761. +static int ipkg_list_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1762. +{
  1763. + int i ;
  1764. + pkg_vec_t *available;
  1765. + pkg_t *pkg;
  1766. + char desc_short[IPKG_LIST_DESCRIPTION_LENGTH];
  1767. + char *newline;
  1768. + char *pkg_name = NULL;
  1769. + char *version_str;
  1770. +
  1771. + if (argc > 0) {
  1772. + pkg_name = argv[0];
  1773. + }
  1774. + available = pkg_vec_alloc();
  1775. + pkg_hash_fetch_available(&conf->pkg_hash, available);
  1776. + for (i=0; i < available->len; i++) {
  1777. + pkg = available->pkgs[i];
  1778. + /* if we have package name or pattern and pkg does not match, then skip it */
  1779. + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
  1780. + continue;
  1781. + if (pkg->description) {
  1782. + strncpy(desc_short, pkg->description, IPKG_LIST_DESCRIPTION_LENGTH);
  1783. + } else {
  1784. + desc_short[0] = '\0';
  1785. + }
  1786. + desc_short[IPKG_LIST_DESCRIPTION_LENGTH - 1] = '\0';
  1787. + newline = strchr(desc_short, '\n');
  1788. + if (newline) {
  1789. + *newline = '\0';
  1790. + }
  1791. + if (ipkg_cb_list) {
  1792. + version_str = pkg_version_str_alloc(pkg);
  1793. + ipkg_cb_list(pkg->name,desc_short,
  1794. + version_str,
  1795. + pkg->state_status,
  1796. + p_userdata);
  1797. + free(version_str);
  1798. + }
  1799. + }
  1800. + pkg_vec_free(available);
  1801. +
  1802. + return 0;
  1803. +}
  1804. +
  1805. +
  1806. +static int ipkg_list_installed_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1807. +{
  1808. + int i ;
  1809. + pkg_vec_t *available;
  1810. + pkg_t *pkg;
  1811. + char desc_short[IPKG_LIST_DESCRIPTION_LENGTH];
  1812. + char *newline;
  1813. + char *pkg_name = NULL;
  1814. + char *version_str;
  1815. +
  1816. + if (argc > 0) {
  1817. + pkg_name = argv[0];
  1818. + }
  1819. + available = pkg_vec_alloc();
  1820. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
  1821. + for (i=0; i < available->len; i++) {
  1822. + pkg = available->pkgs[i];
  1823. + /* if we have package name or pattern and pkg does not match, then skip it */
  1824. + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
  1825. + continue;
  1826. + if (pkg->description) {
  1827. + strncpy(desc_short, pkg->description, IPKG_LIST_DESCRIPTION_LENGTH);
  1828. + } else {
  1829. + desc_short[0] = '\0';
  1830. + }
  1831. + desc_short[IPKG_LIST_DESCRIPTION_LENGTH - 1] = '\0';
  1832. + newline = strchr(desc_short, '\n');
  1833. + if (newline) {
  1834. + *newline = '\0';
  1835. + }
  1836. + if (ipkg_cb_list) {
  1837. + version_str = pkg_version_str_alloc(pkg);
  1838. + ipkg_cb_list(pkg->name,desc_short,
  1839. + version_str,
  1840. + pkg->state_status,
  1841. + p_userdata);
  1842. + free(version_str);
  1843. + }
  1844. + }
  1845. +
  1846. + return 0;
  1847. +}
  1848. +
  1849. +static int ipkg_info_status_cmd(ipkg_conf_t *conf, int argc, char **argv, int installed_only)
  1850. +{
  1851. + int i;
  1852. + pkg_vec_t *available;
  1853. + pkg_t *pkg;
  1854. + char *pkg_name = NULL;
  1855. + char **pkg_fields = NULL;
  1856. + int n_fields = 0;
  1857. + char *buff ; // = (char *)malloc(1);
  1858. +
  1859. + if (argc > 0) {
  1860. + pkg_name = argv[0];
  1861. + }
  1862. + if (argc > 1) {
  1863. + pkg_fields = &argv[1];
  1864. + n_fields = argc - 1;
  1865. + }
  1866. +
  1867. + available = pkg_vec_alloc();
  1868. + if (installed_only)
  1869. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
  1870. + else
  1871. + pkg_hash_fetch_available(&conf->pkg_hash, available);
  1872. + for (i=0; i < available->len; i++) {
  1873. + pkg = available->pkgs[i];
  1874. + if (pkg_name && fnmatch(pkg_name, pkg->name, 0)) {
  1875. + continue;
  1876. + }
  1877. + buff = pkg_formatted_info(pkg);
  1878. + if ( buff ) {
  1879. + if (ipkg_cb_status) ipkg_cb_status(pkg->name,
  1880. + pkg->state_status,
  1881. + buff,
  1882. + p_userdata);
  1883. + free(buff);
  1884. + }
  1885. + if (conf->verbosity > 1) {
  1886. + conffile_list_elt_t *iter;
  1887. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  1888. + conffile_t *cf = iter->data;
  1889. + int modified = conffile_has_been_modified(conf, cf);
  1890. + ipkg_message(conf, IPKG_NOTICE, "conffile=%s md5sum=%s modified=%d\n",
  1891. + cf->name, cf->value, modified);
  1892. + }
  1893. + }
  1894. + }
  1895. + pkg_vec_free(available);
  1896. +
  1897. + return 0;
  1898. +}
  1899. +
  1900. +static int ipkg_info_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1901. +{
  1902. + return ipkg_info_status_cmd(conf, argc, argv, 0);
  1903. +}
  1904. +
  1905. +static int ipkg_status_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1906. +{
  1907. + return ipkg_info_status_cmd(conf, argc, argv, 1);
  1908. +}
  1909. +
  1910. +static int ipkg_configure_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1911. +{
  1912. +
  1913. + int err;
  1914. + if (argc > 0) {
  1915. + char *pkg_name = NULL;
  1916. +
  1917. + pkg_name = argv[0];
  1918. +
  1919. + err = ipkg_configure_packages (conf, pkg_name);
  1920. +
  1921. + } else {
  1922. + err = ipkg_configure_packages (conf, NULL);
  1923. + }
  1924. +
  1925. + write_status_files_if_changed(conf);
  1926. +
  1927. + return err;
  1928. +}
  1929. +
  1930. +static int ipkg_install_pending_cmd(ipkg_conf_t *conf)
  1931. +{
  1932. + int i, err;
  1933. + char *globpattern;
  1934. + glob_t globbuf;
  1935. +
  1936. + sprintf_alloc(&globpattern, "%s/*" IPKG_PKG_EXTENSION, conf->pending_dir);
  1937. + err = glob(globpattern, 0, NULL, &globbuf);
  1938. + free(globpattern);
  1939. + if (err) {
  1940. + return 0;
  1941. + }
  1942. +
  1943. + ipkg_message(conf, IPKG_NOTICE,
  1944. + "The following packages in %s will now be installed.\n",
  1945. + conf->pending_dir);
  1946. + for (i = 0; i < globbuf.gl_pathc; i++) {
  1947. + ipkg_message(conf, IPKG_NOTICE,
  1948. + "%s%s", i == 0 ? "" : " ", globbuf.gl_pathv[i]);
  1949. + }
  1950. + ipkg_message(conf, IPKG_NOTICE, "\n");
  1951. + for (i = 0; i < globbuf.gl_pathc; i++) {
  1952. + err = ipkg_install_from_file(conf, globbuf.gl_pathv[i]);
  1953. + if (err == 0) {
  1954. + err = unlink(globbuf.gl_pathv[i]);
  1955. + if (err) {
  1956. + ipkg_message(conf, IPKG_ERROR,
  1957. + "%s: ERROR: failed to unlink %s: %s\n",
  1958. + __FUNCTION__, globbuf.gl_pathv[i], strerror(err));
  1959. + return err;
  1960. + }
  1961. + }
  1962. + }
  1963. + globfree(&globbuf);
  1964. +
  1965. + return err;
  1966. +}
  1967. +
  1968. +static int ipkg_remove_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1969. +{
  1970. + int i,a,done;
  1971. + pkg_t *pkg;
  1972. + pkg_t *pkg_to_remove;
  1973. + pkg_vec_t *available;
  1974. + char *pkg_name = NULL;
  1975. + global_conf = conf;
  1976. + signal(SIGINT, sigint_handler);
  1977. +
  1978. +// ENH: Add the "no pkg removed" just in case.
  1979. +
  1980. + done = 0;
  1981. +
  1982. + available = pkg_vec_alloc();
  1983. + pkg_info_preinstall_check(conf);
  1984. + if ( argc > 0 ) {
  1985. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
  1986. + for (i=0; i < argc; i++) {
  1987. + pkg_name = malloc(strlen(argv[i])+2);
  1988. + strcpy(pkg_name,argv[i]);
  1989. + for (a=0; a < available->len; a++) {
  1990. + pkg = available->pkgs[a];
  1991. + if (pkg_name && fnmatch(pkg_name, pkg->name, 0)) {
  1992. + continue;
  1993. + }
  1994. + if (conf->restrict_to_default_dest) {
  1995. + pkg_to_remove = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
  1996. + pkg->name,
  1997. + conf->default_dest);
  1998. + } else {
  1999. + pkg_to_remove = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name );
  2000. + }
  2001. +
  2002. + if (pkg == NULL) {
  2003. + ipkg_message(conf, IPKG_ERROR, "Package %s is not installed.\n", pkg->name);
  2004. + continue;
  2005. + }
  2006. + if (pkg->state_status == SS_NOT_INSTALLED) { // Added the control, so every already removed package could be skipped
  2007. + ipkg_message(conf, IPKG_ERROR, "Package seems to be %s not installed (STATUS = NOT_INSTALLED).\n", pkg->name);
  2008. + continue;
  2009. + }
  2010. + ipkg_remove_pkg(conf, pkg_to_remove,0);
  2011. + done = 1;
  2012. + }
  2013. + free (pkg_name);
  2014. + }
  2015. + pkg_vec_free(available);
  2016. + } else {
  2017. + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
  2018. + int flagged_pkg_count = 0;
  2019. + int removed;
  2020. +
  2021. + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed_pkgs);
  2022. +
  2023. + for (i = 0; i < installed_pkgs->len; i++) {
  2024. + pkg = installed_pkgs->pkgs[i];
  2025. + if (pkg->state_flag & SF_USER) {
  2026. + flagged_pkg_count++;
  2027. + } else {
  2028. + if (!pkg_has_installed_dependents(pkg, NULL))
  2029. + ipkg_message(conf, IPKG_NOTICE, "Non-user leaf package: %s\n", pkg->name);
  2030. + }
  2031. + }
  2032. + if (!flagged_pkg_count) {
  2033. + ipkg_message(conf, IPKG_NOTICE, "No packages flagged as installed by user, \n"
  2034. + "so refusing to uninstall unflagged non-leaf packages\n");
  2035. + return 0;
  2036. + }
  2037. +
  2038. + /* find packages not flagged SF_USER (i.e., installed to
  2039. + * satisfy a dependence) and not having any dependents, and
  2040. + * remove them */
  2041. + do {
  2042. + removed = 0;
  2043. + for (i = 0; i < installed_pkgs->len; i++) {
  2044. + pkg = installed_pkgs->pkgs[i];
  2045. + if (!(pkg->state_flag & SF_USER)
  2046. + && !pkg_has_installed_dependents(pkg, NULL)) {
  2047. + removed++;
  2048. + ipkg_message(conf, IPKG_NOTICE, "Removing non-user leaf package %s\n");
  2049. + ipkg_remove_pkg(conf, pkg,0);
  2050. + done = 1;
  2051. + }
  2052. + }
  2053. + } while (removed);
  2054. + pkg_vec_free(installed_pkgs);
  2055. + }
  2056. +
  2057. + if ( done == 0 )
  2058. + ipkg_message(conf, IPKG_NOTICE, "No packages removed.\n");
  2059. +
  2060. + write_status_files_if_changed(conf);
  2061. + return 0;
  2062. +}
  2063. +
  2064. +static int ipkg_purge_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2065. +{
  2066. + int i;
  2067. + pkg_t *pkg;
  2068. +
  2069. + global_conf = conf;
  2070. + signal(SIGINT, sigint_handler);
  2071. +
  2072. + pkg_info_preinstall_check(conf);
  2073. +
  2074. + for (i=0; i < argc; i++) {
  2075. + if (conf->restrict_to_default_dest) {
  2076. + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
  2077. + argv[i],
  2078. + conf->default_dest);
  2079. + } else {
  2080. + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, argv[i]);
  2081. + }
  2082. +
  2083. + if (pkg == NULL) {
  2084. + ipkg_message(conf, IPKG_ERROR,
  2085. + "Package %s is not installed.\n", argv[i]);
  2086. + continue;
  2087. + }
  2088. + ipkg_purge_pkg(conf, pkg);
  2089. + }
  2090. +
  2091. + write_status_files_if_changed(conf);
  2092. + return 0;
  2093. +}
  2094. +
  2095. +static int ipkg_flag_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2096. +{
  2097. + int i;
  2098. + pkg_t *pkg;
  2099. + char *flags = argv[0];
  2100. +
  2101. + global_conf = conf;
  2102. + signal(SIGINT, sigint_handler);
  2103. +
  2104. + for (i=1; i < argc; i++) {
  2105. + if (conf->restrict_to_default_dest) {
  2106. + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
  2107. + argv[i],
  2108. + conf->default_dest);
  2109. + } else {
  2110. + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, argv[i]);
  2111. + }
  2112. +
  2113. + if (pkg == NULL) {
  2114. + ipkg_message(conf, IPKG_ERROR,
  2115. + "Package %s is not installed.\n", argv[i]);
  2116. + continue;
  2117. + }
  2118. + if (( strcmp(flags,"hold")==0)||( strcmp(flags,"noprune")==0)||
  2119. + ( strcmp(flags,"user")==0)||( strcmp(flags,"ok")==0)) {
  2120. + pkg->state_flag = pkg_state_flag_from_str(flags);
  2121. + }
  2122. +/* pb_ asked this feature 03292004 */
  2123. +/* Actually I will use only this two, but this is an open for various status */
  2124. + if (( strcmp(flags,"installed")==0)||( strcmp(flags,"unpacked")==0)){
  2125. + pkg->state_status = pkg_state_status_from_str(flags);
  2126. + }
  2127. + ipkg_state_changed++;
  2128. + ipkg_message(conf, IPKG_NOTICE,
  2129. + "Setting flags for package %s to %s\n",
  2130. + pkg->name, flags);
  2131. + }
  2132. +
  2133. + write_status_files_if_changed(conf);
  2134. + return 0;
  2135. +}
  2136. +
  2137. +static int ipkg_files_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2138. +{
  2139. + pkg_t *pkg;
  2140. + str_list_t *installed_files;
  2141. + str_list_elt_t *iter;
  2142. + char *pkg_version;
  2143. + size_t buff_len = 8192;
  2144. + size_t used_len;
  2145. + char *buff ;
  2146. +
  2147. + buff = (char *)malloc(buff_len);
  2148. + if ( buff == NULL ) {
  2149. + fprintf( stderr,"%s: Unable to allocate memory \n",__FUNCTION__);
  2150. + return ENOMEM;
  2151. + }
  2152. +
  2153. + if (argc < 1) {
  2154. + return EINVAL;
  2155. + }
  2156. +
  2157. + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash,
  2158. + argv[0]);
  2159. + if (pkg == NULL) {
  2160. + ipkg_message(conf, IPKG_ERROR,
  2161. + "Package %s not installed.\n", argv[0]);
  2162. + return 0;
  2163. + }
  2164. +
  2165. + installed_files = pkg_get_installed_files(pkg);
  2166. + pkg_version = pkg_version_str_alloc(pkg);
  2167. +
  2168. + printf("Package %s (%s) is installed on %s and has the following files:\n",
  2169. + pkg->name, pkg_version, pkg->dest->name);
  2170. + for (iter = installed_files->head; iter; iter = iter->next) {
  2171. + puts(iter->data);
  2172. + }
  2173. +
  2174. + free(pkg_version);
  2175. + pkg_free_installed_files(pkg);
  2176. +
  2177. + return 0;
  2178. +}
  2179. +
  2180. +static int ipkg_depends_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2181. +{
  2182. +
  2183. + if (argc > 0) {
  2184. + pkg_vec_t *available_pkgs = pkg_vec_alloc();
  2185. + const char *rel_str = "depends on";
  2186. + int i;
  2187. +
  2188. + pkg_info_preinstall_check(conf);
  2189. +
  2190. + if (conf->query_all)
  2191. + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
  2192. + else
  2193. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
  2194. + for (i = 0; i < argc; i++) {
  2195. + const char *target = argv[i];
  2196. + int j;
  2197. +
  2198. + ipkg_message(conf, IPKG_ERROR, "target=%s\n", target);
  2199. +
  2200. + for (j = 0; j < available_pkgs->len; j++) {
  2201. + pkg_t *pkg = available_pkgs->pkgs[j];
  2202. + if (fnmatch(target, pkg->name, 0) == 0) {
  2203. + int k;
  2204. + int count = pkg->depends_count + pkg->pre_depends_count;
  2205. + ipkg_message(conf, IPKG_ERROR, "What %s (arch=%s) %s\n",
  2206. + target, pkg->architecture, rel_str);
  2207. + for (k = 0; k < count; k++) {
  2208. + compound_depend_t *cdepend = &pkg->depends[k];
  2209. + int l;
  2210. + for (l = 0; l < cdepend->possibility_count; l++) {
  2211. + depend_t *possibility = cdepend->possibilities[l];
  2212. + ipkg_message(conf, IPKG_ERROR, " %s", possibility->pkg->name);
  2213. + if (conf->verbosity > 0) {
  2214. + // char *ver = abstract_pkg_version_str_alloc(possibility->pkg);
  2215. + ipkg_message(conf, IPKG_NOTICE, " %s", possibility->version);
  2216. + if (possibility->version) {
  2217. + const char *typestr = NULL;
  2218. + switch (possibility->constraint) {
  2219. + case NONE: typestr = "none"; break;
  2220. + case EARLIER: typestr = "<"; break;
  2221. + case EARLIER_EQUAL: typestr = "<="; break;
  2222. + case EQUAL: typestr = "="; break;
  2223. + case LATER_EQUAL: typestr = ">="; break;
  2224. + case LATER: typestr = ">"; break;
  2225. + }
  2226. + ipkg_message(conf, IPKG_NOTICE, " (%s %s)", typestr, possibility->version);
  2227. + }
  2228. + // free(ver);
  2229. + }
  2230. + ipkg_message(conf, IPKG_ERROR, "\n");
  2231. + }
  2232. + }
  2233. + }
  2234. + }
  2235. + }
  2236. + pkg_vec_free(available_pkgs);
  2237. + }
  2238. + return 0;
  2239. +}
  2240. +
  2241. +enum what_field_type {
  2242. + WHATDEPENDS,
  2243. + WHATCONFLICTS,
  2244. + WHATPROVIDES,
  2245. + WHATREPLACES,
  2246. + WHATRECOMMENDS,
  2247. + WHATSUGGESTS
  2248. +};
  2249. +
  2250. +static int ipkg_what_depends_conflicts_cmd(ipkg_conf_t *conf, enum what_field_type what_field_type, int recursive, int argc, char **argv)
  2251. +{
  2252. +
  2253. + if (argc > 0) {
  2254. + pkg_vec_t *available_pkgs = pkg_vec_alloc();
  2255. + const char *rel_str = NULL;
  2256. + int i;
  2257. + int changed;
  2258. +
  2259. + switch (what_field_type) {
  2260. + case WHATDEPENDS: rel_str = "depends on"; break;
  2261. + case WHATCONFLICTS: rel_str = "conflicts with"; break;
  2262. + case WHATSUGGESTS: rel_str = "suggests"; break;
  2263. + case WHATRECOMMENDS: rel_str = "recommends"; break;
  2264. + case WHATPROVIDES: rel_str = "provides"; break;
  2265. + case WHATREPLACES: rel_str = "replaces"; break;
  2266. + }
  2267. +
  2268. + if (conf->query_all)
  2269. + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
  2270. + else
  2271. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
  2272. +
  2273. + /* mark the root set */
  2274. + pkg_vec_clear_marks(available_pkgs);
  2275. + ipkg_message(conf, IPKG_NOTICE, "Root set:\n");
  2276. + for (i = 0; i < argc; i++) {
  2277. + const char *dependee_pattern = argv[i];
  2278. + pkg_vec_mark_if_matches(available_pkgs, dependee_pattern);
  2279. + }
  2280. + for (i = 0; i < available_pkgs->len; i++) {
  2281. + pkg_t *pkg = available_pkgs->pkgs[i];
  2282. + if (pkg->state_flag & SF_MARKED) {
  2283. + /* mark the parent (abstract) package */
  2284. + pkg_mark_provides(pkg);
  2285. + ipkg_message(conf, IPKG_NOTICE, " %s\n", pkg->name);
  2286. + }
  2287. + }
  2288. +
  2289. + ipkg_message(conf, IPKG_NOTICE, "What %s root set\n", rel_str);
  2290. + do {
  2291. + int j;
  2292. + changed = 0;
  2293. +
  2294. + for (j = 0; j < available_pkgs->len; j++) {
  2295. + pkg_t *pkg = available_pkgs->pkgs[j];
  2296. + int k;
  2297. + int count = ((what_field_type == WHATCONFLICTS)
  2298. + ? pkg->conflicts_count
  2299. + : pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count);
  2300. + /* skip this package if it is already marked */
  2301. + if (pkg->parent->state_flag & SF_MARKED) {
  2302. + continue;
  2303. + }
  2304. + for (k = 0; k < count; k++) {
  2305. + compound_depend_t *cdepend =
  2306. + (what_field_type == WHATCONFLICTS) ? &pkg->conflicts[k] : &pkg->depends[k];
  2307. + int l;
  2308. + for (l = 0; l < cdepend->possibility_count; l++) {
  2309. + depend_t *possibility = cdepend->possibilities[l];
  2310. + if (possibility->pkg->state_flag & SF_MARKED) {
  2311. + /* mark the depending package so we won't visit it again */
  2312. + pkg->state_flag |= SF_MARKED;
  2313. + pkg_mark_provides(pkg);
  2314. + changed++;
  2315. +
  2316. + ipkg_message(conf, IPKG_NOTICE, " %s", pkg->name);
  2317. + if (conf->verbosity > 0) {
  2318. + char *ver = pkg_version_str_alloc(pkg);
  2319. + ipkg_message(conf, IPKG_NOTICE, " %s", ver);
  2320. + ipkg_message(conf, IPKG_NOTICE, "\t%s %s", rel_str, possibility->pkg->name);
  2321. + if (possibility->version) {
  2322. + const char *typestr = NULL;
  2323. + switch (possibility->constraint) {
  2324. + case NONE: typestr = "none"; break;
  2325. + case EARLIER: typestr = "<"; break;
  2326. + case EARLIER_EQUAL: typestr = "<="; break;
  2327. + case EQUAL: typestr = "="; break;
  2328. + case LATER_EQUAL: typestr = ">="; break;
  2329. + case LATER: typestr = ">"; break;
  2330. + }
  2331. + ipkg_message(conf, IPKG_NOTICE, " (%s %s)", typestr, possibility->version);
  2332. + }
  2333. + free(ver);
  2334. + if (!pkg_dependence_satisfiable(possibility))
  2335. + ipkg_message(conf, IPKG_NOTICE, " unsatisfiable");
  2336. + }
  2337. + ipkg_message(conf, IPKG_NOTICE, "\n");
  2338. + goto next_package;
  2339. + }
  2340. + }
  2341. + }
  2342. + next_package:
  2343. + ;
  2344. + }
  2345. + } while (changed && recursive);
  2346. + pkg_vec_free(available_pkgs);
  2347. + }
  2348. +
  2349. + return 0;
  2350. +}
  2351. +
  2352. +int pkg_mark_provides(pkg_t *pkg)
  2353. +{
  2354. + int provides_count = pkg->provides_count;
  2355. + abstract_pkg_t **provides = pkg->provides;
  2356. + int i;
  2357. + pkg->parent->state_flag |= SF_MARKED;
  2358. + for (i = 0; i < provides_count; i++) {
  2359. + provides[i]->state_flag |= SF_MARKED;
  2360. + }
  2361. + return 0;
  2362. +}
  2363. +
  2364. +static int ipkg_whatdepends_recursively_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2365. +{
  2366. + return ipkg_what_depends_conflicts_cmd(conf, WHATDEPENDS, 1, argc, argv);
  2367. +}
  2368. +static int ipkg_whatdepends_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2369. +{
  2370. + return ipkg_what_depends_conflicts_cmd(conf, WHATDEPENDS, 0, argc, argv);
  2371. +}
  2372. +
  2373. +static int ipkg_whatsuggests_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2374. +{
  2375. + return ipkg_what_depends_conflicts_cmd(conf, WHATSUGGESTS, 0, argc, argv);
  2376. +}
  2377. +
  2378. +static int ipkg_whatrecommends_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2379. +{
  2380. + return ipkg_what_depends_conflicts_cmd(conf, WHATRECOMMENDS, 0, argc, argv);
  2381. +}
  2382. +
  2383. +static int ipkg_whatconflicts_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2384. +{
  2385. + return ipkg_what_depends_conflicts_cmd(conf, WHATCONFLICTS, 0, argc, argv);
  2386. +}
  2387. +
  2388. +static int ipkg_what_provides_replaces_cmd(ipkg_conf_t *conf, enum what_field_type what_field_type, int argc, char **argv)
  2389. +{
  2390. +
  2391. + if (argc > 0) {
  2392. + pkg_vec_t *available_pkgs = pkg_vec_alloc();
  2393. + const char *rel_str = (what_field_type == WHATPROVIDES ? "provides" : "replaces");
  2394. + int i;
  2395. +
  2396. + pkg_info_preinstall_check(conf);
  2397. +
  2398. + if (conf->query_all)
  2399. + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
  2400. + else
  2401. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
  2402. + for (i = 0; i < argc; i++) {
  2403. + const char *target = argv[i];
  2404. + int j;
  2405. +
  2406. + ipkg_message(conf, IPKG_ERROR, "What %s %s\n",
  2407. + rel_str, target);
  2408. + for (j = 0; j < available_pkgs->len; j++) {
  2409. + pkg_t *pkg = available_pkgs->pkgs[j];
  2410. + int k;
  2411. + int count = (what_field_type == WHATPROVIDES) ? pkg->provides_count : pkg->replaces_count;
  2412. + for (k = 0; k < count; k++) {
  2413. + abstract_pkg_t *apkg =
  2414. + ((what_field_type == WHATPROVIDES)
  2415. + ? pkg->provides[k]
  2416. + : pkg->replaces[k]);
  2417. + if (fnmatch(target, apkg->name, 0) == 0) {
  2418. + ipkg_message(conf, IPKG_ERROR, " %s", pkg->name);
  2419. + if (strcmp(target, apkg->name) != 0)
  2420. + ipkg_message(conf, IPKG_ERROR, "\t%s %s\n", rel_str, apkg->name);
  2421. + ipkg_message(conf, IPKG_ERROR, "\n");
  2422. + }
  2423. + }
  2424. + }
  2425. + }
  2426. + pkg_vec_free(available_pkgs);
  2427. + }
  2428. + return 0;
  2429. +}
  2430. +
  2431. +static int ipkg_whatprovides_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2432. +{
  2433. + return ipkg_what_provides_replaces_cmd(conf, WHATPROVIDES, argc, argv);
  2434. +}
  2435. +
  2436. +static int ipkg_whatreplaces_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2437. +{
  2438. + return ipkg_what_provides_replaces_cmd(conf, WHATREPLACES, argc, argv);
  2439. +}
  2440. +
  2441. +static int ipkg_search_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2442. +{
  2443. + int i;
  2444. +
  2445. + pkg_vec_t *installed;
  2446. + pkg_t *pkg;
  2447. + str_list_t *installed_files;
  2448. + str_list_elt_t *iter;
  2449. + char *installed_file;
  2450. +
  2451. + if (argc < 1) {
  2452. + return EINVAL;
  2453. + }
  2454. +
  2455. + installed = pkg_vec_alloc();
  2456. + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
  2457. +
  2458. + for (i=0; i < installed->len; i++) {
  2459. + pkg = installed->pkgs[i];
  2460. +
  2461. + installed_files = pkg_get_installed_files(pkg);
  2462. +
  2463. + for (iter = installed_files->head; iter; iter = iter->next) {
  2464. + installed_file = iter->data;
  2465. + if (fnmatch(argv[0], installed_file, 0)==0) {
  2466. + if (ipkg_cb_list) ipkg_cb_list(pkg->name,
  2467. + installed_file,
  2468. + pkg_version_str_alloc(pkg),
  2469. + pkg->state_status, p_userdata);
  2470. + }
  2471. + }
  2472. +
  2473. + pkg_free_installed_files(pkg);
  2474. + }
  2475. +
  2476. + /* XXX: CLEANUP: It's not obvious from the name of
  2477. + pkg_hash_fetch_all_installed that we need to call
  2478. + pkg_vec_free to avoid a memory leak. */
  2479. + pkg_vec_free(installed);
  2480. +
  2481. + return 0;
  2482. +}
  2483. +
  2484. +static int ipkg_compare_versions_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2485. +{
  2486. + if (argc == 3) {
  2487. + /* this is a bit gross */
  2488. + struct pkg p1, p2;
  2489. + parseVersion(&p1, argv[0]);
  2490. + parseVersion(&p2, argv[2]);
  2491. + return pkg_version_satisfied(&p1, &p2, argv[1]);
  2492. + } else {
  2493. + ipkg_message(conf, IPKG_ERROR,
  2494. + "ipkg compare_versions <v1> <op> <v2>\n"
  2495. + "<op> is one of <= >= << >> =\n");
  2496. + return -1;
  2497. + }
  2498. +}
  2499. +
  2500. +#ifndef HOST_CPU_STR
  2501. +#define HOST_CPU_STR__(X) #X
  2502. +#define HOST_CPU_STR_(X) HOST_CPU_STR__(X)
  2503. +#define HOST_CPU_STR HOST_CPU_STR_(HOST_CPU_FOO)
  2504. +#endif
  2505. +
  2506. +static int ipkg_print_architecture_cmd(ipkg_conf_t *conf)
  2507. +{
  2508. + nv_pair_list_elt_t *l;
  2509. +
  2510. + l = conf->arch_list.head;
  2511. + while (l) {
  2512. + nv_pair_t *nv = l->data;
  2513. + printf("arch %s %s\n", nv->name, nv->value);
  2514. + l = l->next;
  2515. + }
  2516. + return 0;
  2517. +}
  2518. +
  2519. +
  2520. diff -Nur busybox-1.17.2.orig/archival/libipkg/ipkg_cmd.h busybox-1.17.2/archival/libipkg/ipkg_cmd.h
  2521. --- busybox-1.17.2.orig/archival/libipkg/ipkg_cmd.h 1970-01-01 01:00:00.000000000 +0100
  2522. +++ busybox-1.17.2/archival/libipkg/ipkg_cmd.h 2010-12-01 22:25:23.000000000 +0100
  2523. @@ -0,0 +1,41 @@
  2524. +/* ipkg_cmd.h - the itsy package management system
  2525. +
  2526. + Carl D. Worth
  2527. +
  2528. + Copyright (C) 2001 University of Southern California
  2529. +
  2530. + This program is free software; you can redistribute it and/or
  2531. + modify it under the terms of the GNU General Public License as
  2532. + published by the Free Software Foundation; either version 2, or (at
  2533. + your option) any later version.
  2534. +
  2535. + This program is distributed in the hope that it will be useful, but
  2536. + WITHOUT ANY WARRANTY; without even the implied warranty of
  2537. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  2538. + General Public License for more details.
  2539. +*/
  2540. +
  2541. +#ifndef IPKG_CMD_H
  2542. +#define IPKG_CMD_H
  2543. +
  2544. +typedef int (*ipkg_cmd_fun_t)(ipkg_conf_t *conf, int argc, const char **argv);
  2545. +
  2546. +struct ipkg_cmd
  2547. +{
  2548. + const char *name;
  2549. + int requires_args;
  2550. + ipkg_cmd_fun_t fun;
  2551. +};
  2552. +typedef struct ipkg_cmd ipkg_cmd_t;
  2553. +
  2554. +ipkg_cmd_t *ipkg_cmd_find(const char *name);
  2555. +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc,
  2556. + const char **argv, void *userdata);
  2557. +int ipkg_multiple_files_scan (ipkg_conf_t *conf, int argc, char *argv[]);
  2558. +/* install any packges with state_want == SW_INSTALL */
  2559. +int ipkg_install_wanted_packages(ipkg_conf_t *conf);
  2560. +/* ensure that all dependences are satisfied */
  2561. +int ipkg_configure_packages(ipkg_conf_t *conf, char *pkg_name);
  2562. +int pkg_mark_provides(pkg_t *pkg);
  2563. +
  2564. +#endif
  2565. diff -Nur busybox-1.17.2.orig/archival/libipkg/ipkg_conf.c busybox-1.17.2/archival/libipkg/ipkg_conf.c
  2566. --- busybox-1.17.2.orig/archival/libipkg/ipkg_conf.c 1970-01-01 01:00:00.000000000 +0100
  2567. +++ busybox-1.17.2/archival/libipkg/ipkg_conf.c 2010-12-01 22:25:23.000000000 +0100
  2568. @@ -0,0 +1,711 @@
  2569. +/* ipkg_conf.c - the itsy package management system
  2570. +
  2571. + Carl D. Worth
  2572. +
  2573. + Copyright (C) 2001 University of Southern California
  2574. +
  2575. + This program is free software; you can redistribute it and/or
  2576. + modify it under the terms of the GNU General Public License as
  2577. + published by the Free Software Foundation; either version 2, or (at
  2578. + your option) any later version.
  2579. +
  2580. + This program is distributed in the hope that it will be useful, but
  2581. + WITHOUT ANY WARRANTY; without even the implied warranty of
  2582. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  2583. + General Public License for more details.
  2584. +*/
  2585. +
  2586. +#include <glob.h>
  2587. +
  2588. +#include "ipkg.h"
  2589. +#include "ipkg_conf.h"
  2590. +
  2591. +#include "xregex.h"
  2592. +#include "sprintf_alloc.h"
  2593. +#include "ipkg_conf.h"
  2594. +#include "ipkg_message.h"
  2595. +#include "file_util.h"
  2596. +#include "str_util.h"
  2597. +#include "xsystem.h"
  2598. +
  2599. +
  2600. +ipkg_conf_t *global_conf;
  2601. +
  2602. +static int ipkg_conf_parse_file(ipkg_conf_t *conf, const char *filename,
  2603. + pkg_src_list_t *pkg_src_list,
  2604. + nv_pair_list_t *tmp_dest_nv_pair_list,
  2605. + char **tmp_lists_dir);
  2606. +static int ipkg_init_options_array(const ipkg_conf_t *conf, ipkg_option_t **options);
  2607. +static int ipkg_conf_set_option(const ipkg_option_t *options,
  2608. + const char *name, const char *value);
  2609. +static int ipkg_conf_set_default_dest(ipkg_conf_t *conf,
  2610. + const char *default_dest_name);
  2611. +static int set_and_load_pkg_src_list(ipkg_conf_t *conf,
  2612. + pkg_src_list_t *nv_pair_list);
  2613. +static int set_and_load_pkg_dest_list(ipkg_conf_t *conf,
  2614. + nv_pair_list_t *nv_pair_list, char * lists_dir);
  2615. +
  2616. +int ipkg_init_options_array(const ipkg_conf_t *conf, ipkg_option_t **options)
  2617. +{
  2618. + ipkg_option_t tmp[] = {
  2619. + { "force_defaults", IPKG_OPT_TYPE_BOOL, &conf->force_defaults },
  2620. + { "force_depends", IPKG_OPT_TYPE_BOOL, &conf->force_depends },
  2621. + { "force_overwrite", IPKG_OPT_TYPE_BOOL, &conf->force_overwrite },
  2622. + { "force_downgrade", IPKG_OPT_TYPE_BOOL, &conf->force_downgrade },
  2623. + { "force_reinstall", IPKG_OPT_TYPE_BOOL, &conf->force_reinstall },
  2624. + { "force_space", IPKG_OPT_TYPE_BOOL, &conf->force_space },
  2625. + { "ftp_proxy", IPKG_OPT_TYPE_STRING, &conf->ftp_proxy },
  2626. + { "http_proxy", IPKG_OPT_TYPE_STRING, &conf->http_proxy },
  2627. + { "multiple_providers", IPKG_OPT_TYPE_BOOL, &conf->multiple_providers },
  2628. + { "no_proxy", IPKG_OPT_TYPE_STRING, &conf->no_proxy },
  2629. + { "test", IPKG_OPT_TYPE_INT, &conf->noaction },
  2630. + { "noaction", IPKG_OPT_TYPE_INT, &conf->noaction },
  2631. + { "nodeps", IPKG_OPT_TYPE_BOOL, &conf->nodeps },
  2632. + { "offline_root", IPKG_OPT_TYPE_STRING, &conf->offline_root },
  2633. + { "offline_root_post_script_cmd", IPKG_OPT_TYPE_STRING, &conf->offline_root_post_script_cmd },
  2634. + { "offline_root_pre_script_cmd", IPKG_OPT_TYPE_STRING, &conf->offline_root_pre_script_cmd },
  2635. + { "proxy_passwd", IPKG_OPT_TYPE_STRING, &conf->proxy_passwd },
  2636. + { "proxy_user", IPKG_OPT_TYPE_STRING, &conf->proxy_user },
  2637. + { "query-all", IPKG_OPT_TYPE_BOOL, &conf->query_all },
  2638. + { "verbose-wget", IPKG_OPT_TYPE_BOOL, &conf->verbose_wget },
  2639. + { "verbosity", IPKG_OPT_TYPE_BOOL, &conf->verbosity },
  2640. + { NULL }
  2641. + };
  2642. +
  2643. + *options = (ipkg_option_t *)malloc(sizeof(tmp));
  2644. + if ( options == NULL ){
  2645. + fprintf(stderr,"%s: Unable to allocate memory\n",__FUNCTION__);
  2646. + return -1;
  2647. + }
  2648. +
  2649. + memcpy(*options, tmp, sizeof(tmp));
  2650. + return 0;
  2651. +};
  2652. +
  2653. +static void ipkg_conf_override_string(char **conf_str, char *arg_str)
  2654. +{
  2655. + if (arg_str) {
  2656. + if (*conf_str) {
  2657. + free(*conf_str);
  2658. + }
  2659. + *conf_str = strdup(arg_str);
  2660. + }
  2661. +}
  2662. +
  2663. +static void ipkg_conf_free_string(char **conf_str)
  2664. +{
  2665. + if (*conf_str) {
  2666. + free(*conf_str);
  2667. + *conf_str = NULL;
  2668. + }
  2669. +}
  2670. +
  2671. +int ipkg_conf_init(ipkg_conf_t *conf, const args_t *args)
  2672. +{
  2673. + int err;
  2674. + char *tmp_dir_base;
  2675. + nv_pair_list_t tmp_dest_nv_pair_list;
  2676. + char * lists_dir =NULL;
  2677. + glob_t globbuf;
  2678. + const char *etc_ipkg_conf_pattern = "/etc/ipkg/*.conf";
  2679. + char *pending_dir =NULL;
  2680. +
  2681. + memset(conf, 0, sizeof(ipkg_conf_t));
  2682. +
  2683. + pkg_src_list_init(&conf->pkg_src_list);
  2684. +
  2685. + nv_pair_list_init(&tmp_dest_nv_pair_list);
  2686. + pkg_dest_list_init(&conf->pkg_dest_list);
  2687. +
  2688. + nv_pair_list_init(&conf->arch_list);
  2689. +
  2690. + conf->restrict_to_default_dest = 0;
  2691. + conf->default_dest = NULL;
  2692. +
  2693. +
  2694. + if (args->tmp_dir)
  2695. + tmp_dir_base = args->tmp_dir;
  2696. + else
  2697. + tmp_dir_base = getenv("TMPDIR");
  2698. + sprintf_alloc(&conf->tmp_dir, "%s/%s",
  2699. + tmp_dir_base ? tmp_dir_base : IPKG_CONF_DEFAULT_TMP_DIR_BASE,
  2700. + IPKG_CONF_TMP_DIR_SUFFIX);
  2701. + conf->tmp_dir = mkdtemp(conf->tmp_dir);
  2702. + if (conf->tmp_dir == NULL) {
  2703. + fprintf(stderr, "%s: Failed to create temporary directory `%s': %s\n",
  2704. + __FUNCTION__, conf->tmp_dir, strerror(errno));
  2705. + return errno;
  2706. + }
  2707. +
  2708. + conf->force_depends = 0;
  2709. + conf->force_defaults = 0;
  2710. + conf->force_overwrite = 0;
  2711. + conf->force_downgrade = 0;
  2712. + conf->force_reinstall = 0;
  2713. + conf->force_space = 0;
  2714. + conf->force_removal_of_essential_packages = 0;
  2715. + conf->force_removal_of_dependent_packages = 0;
  2716. + conf->nodeps = 0;
  2717. + conf->verbose_wget = 0;
  2718. + conf->offline_root = NULL;
  2719. + conf->offline_root_pre_script_cmd = NULL;
  2720. + conf->offline_root_post_script_cmd = NULL;
  2721. + conf->multiple_providers = 0;
  2722. + conf->verbosity = 1;
  2723. + conf->noaction = 0;
  2724. +
  2725. + conf->http_proxy = NULL;
  2726. + conf->ftp_proxy = NULL;
  2727. + conf->no_proxy = NULL;
  2728. + conf->proxy_user = NULL;
  2729. + conf->proxy_passwd = NULL;
  2730. +
  2731. + pkg_hash_init("pkg-hash", &conf->pkg_hash, IPKG_CONF_DEFAULT_HASH_LEN);
  2732. + hash_table_init("file-hash", &conf->file_hash, IPKG_CONF_DEFAULT_HASH_LEN);
  2733. + hash_table_init("obs-file-hash", &conf->obs_file_hash, IPKG_CONF_DEFAULT_HASH_LEN);
  2734. + lists_dir=(char *)malloc(1);
  2735. + lists_dir[0]='\0';
  2736. + if (args->conf_file) {
  2737. + struct stat stat_buf;
  2738. + err = stat(args->conf_file, &stat_buf);
  2739. + if (err == 0)
  2740. + if (ipkg_conf_parse_file(conf, args->conf_file,
  2741. + &conf->pkg_src_list, &tmp_dest_nv_pair_list,&lists_dir)<0) {
  2742. + /* Memory leakage from ipkg_conf_parse-file */
  2743. + return -1;
  2744. + }
  2745. +
  2746. + }
  2747. +
  2748. + /* if (!lists_dir ){*/
  2749. + if (strlen(lists_dir)<=1 ){
  2750. + lists_dir = realloc(lists_dir,strlen(IPKG_CONF_LISTS_DIR)+2);
  2751. + sprintf (lists_dir,"%s",IPKG_CONF_LISTS_DIR);
  2752. + }
  2753. +
  2754. + if (args->offline_root) {
  2755. + char *tmp = malloc(strlen(lists_dir) + strlen(args->offline_root) + 1);
  2756. + sprintf_alloc(&tmp, "%s/%s",args->offline_root,lists_dir);
  2757. + free(lists_dir);
  2758. + lists_dir = tmp;
  2759. + }
  2760. +
  2761. + pending_dir = malloc(strlen(lists_dir)+strlen("/pending")+5);
  2762. + snprintf(pending_dir,strlen(lists_dir)+strlen("/pending") ,"%s%s",lists_dir,"/pending");
  2763. +
  2764. + conf->lists_dir = strdup(lists_dir);
  2765. + conf->pending_dir = strdup(pending_dir);
  2766. +
  2767. + if (args->offline_root)
  2768. + sprintf_alloc(&etc_ipkg_conf_pattern, "%s/etc/ipkg/*.conf", args->offline_root);
  2769. + memset(&globbuf, 0, sizeof(globbuf));
  2770. + err = glob(etc_ipkg_conf_pattern, 0, NULL, &globbuf);
  2771. + if (!err) {
  2772. + int i;
  2773. + for (i = 0; i < globbuf.gl_pathc; i++) {
  2774. + if (globbuf.gl_pathv[i])
  2775. + if ( ipkg_conf_parse_file(conf, globbuf.gl_pathv[i],
  2776. + &conf->pkg_src_list, &tmp_dest_nv_pair_list,&lists_dir)<0) {
  2777. + /* Memory leakage from ipkg_conf_parse-file */
  2778. + return -1;
  2779. + }
  2780. + }
  2781. + }
  2782. + globfree(&globbuf);
  2783. +
  2784. + /* if no architectures were defined, then default all, noarch, and host architecture */
  2785. + if (nv_pair_list_empty(&conf->arch_list)) {
  2786. + nv_pair_list_append(&conf->arch_list, "all", "1");
  2787. + nv_pair_list_append(&conf->arch_list, "noarch", "1");
  2788. + nv_pair_list_append(&conf->arch_list, HOST_CPU_STR, "10");
  2789. + }
  2790. +
  2791. + /* Even if there is no conf file, we'll need at least one dest. */
  2792. + if (tmp_dest_nv_pair_list.head == NULL) {
  2793. + nv_pair_list_append(&tmp_dest_nv_pair_list,
  2794. + IPKG_CONF_DEFAULT_DEST_NAME,
  2795. + IPKG_CONF_DEFAULT_DEST_ROOT_DIR);
  2796. + }
  2797. +
  2798. + /* After parsing the file, set options from command-line, (so that
  2799. + command-line arguments take precedence) */
  2800. + /* XXX: CLEANUP: The interaction between args.c and ipkg_conf.c
  2801. + really needs to be cleaned up. There is so much duplication
  2802. + right now it is ridiculous. Maybe ipkg_conf_t should just save
  2803. + a pointer to args_t (which could then not be freed), rather
  2804. + than duplicating every field here? */
  2805. + if (args->force_depends) {
  2806. + conf->force_depends = 1;
  2807. + }
  2808. + if (args->force_defaults) {
  2809. + conf->force_defaults = 1;
  2810. + }
  2811. + if (args->force_overwrite) {
  2812. + conf->force_overwrite = 1;
  2813. + }
  2814. + if (args->force_downgrade) {
  2815. + conf->force_downgrade = 1;
  2816. + }
  2817. + if (args->force_reinstall) {
  2818. + conf->force_reinstall = 1;
  2819. + }
  2820. + if (args->force_removal_of_dependent_packages) {
  2821. + conf->force_removal_of_dependent_packages = 1;
  2822. + }
  2823. + if (args->force_removal_of_essential_packages) {
  2824. + conf->force_removal_of_essential_packages = 1;
  2825. + }
  2826. + if (args->nodeps) {
  2827. + conf->nodeps = 1;
  2828. + }
  2829. + if (args->noaction) {
  2830. + conf->noaction = 1;
  2831. + }
  2832. + if (args->query_all) {
  2833. + conf->query_all = 1;
  2834. + }
  2835. + if (args->verbose_wget) {
  2836. + conf->verbose_wget = 1;
  2837. + }
  2838. + if (args->multiple_providers) {
  2839. + conf->multiple_providers = 1;
  2840. + }
  2841. + if (args->verbosity != conf->verbosity) {
  2842. + conf->verbosity = args->verbosity;
  2843. + }
  2844. +
  2845. + ipkg_conf_override_string(&conf->offline_root,
  2846. + args->offline_root);
  2847. + ipkg_conf_override_string(&conf->offline_root_pre_script_cmd,
  2848. + args->offline_root_pre_script_cmd);
  2849. + ipkg_conf_override_string(&conf->offline_root_post_script_cmd,
  2850. + args->offline_root_post_script_cmd);
  2851. +
  2852. +/* Pigi: added a flag to disable the checking of structures if the command does not need to
  2853. + read anything from there.
  2854. +*/
  2855. + if ( !(args->nocheckfordirorfile)){
  2856. + /* need to run load the source list before dest list -Jamey */
  2857. + if ( !(args->noreadfeedsfile))
  2858. + set_and_load_pkg_src_list(conf, &conf->pkg_src_list);
  2859. +
  2860. + /* Now that we have resolved conf->offline_root, we can commit to
  2861. + the directory names for the dests and load in all the package
  2862. + lists. */
  2863. + set_and_load_pkg_dest_list(conf, &tmp_dest_nv_pair_list,lists_dir);
  2864. +
  2865. + if (args->dest) {
  2866. + err = ipkg_conf_set_default_dest(conf, args->dest);
  2867. + if (err) {
  2868. + return err;
  2869. + }
  2870. + }
  2871. + }
  2872. + nv_pair_list_deinit(&tmp_dest_nv_pair_list);
  2873. + free(lists_dir);
  2874. + free(pending_dir);
  2875. +
  2876. + return 0;
  2877. +}
  2878. +
  2879. +void ipkg_conf_deinit(ipkg_conf_t *conf)
  2880. +{
  2881. +#ifdef IPKG_DEBUG_NO_TMP_CLEANUP
  2882. +#error
  2883. + fprintf(stderr, "%s: Not cleaning up %s since ipkg compiled "
  2884. + "with IPKG_DEBUG_NO_TMP_CLEANUP\n",
  2885. + __FUNCTION__, conf->tmp_dir);
  2886. +#else
  2887. + int err;
  2888. +
  2889. + err = rmdir(conf->tmp_dir);
  2890. + if (err) {
  2891. + if (errno == ENOTEMPTY) {
  2892. + char *cmd;
  2893. + sprintf_alloc(&cmd, "rm -fr %s\n", conf->tmp_dir);
  2894. + err = xsystem(cmd);
  2895. + free(cmd);
  2896. + }
  2897. + if (err)
  2898. + fprintf(stderr, "WARNING: Unable to remove temporary directory: %s: %s\n", conf->tmp_dir, strerror(errno));
  2899. + }
  2900. +#endif /* IPKG_DEBUG_NO_TMP_CLEANUP */
  2901. +
  2902. + free(conf->tmp_dir); /*XXX*/
  2903. +
  2904. + pkg_src_list_deinit(&conf->pkg_src_list);
  2905. + pkg_dest_list_deinit(&conf->pkg_dest_list);
  2906. + nv_pair_list_deinit(&conf->arch_list);
  2907. + if (&conf->pkg_hash)
  2908. + pkg_hash_deinit(&conf->pkg_hash);
  2909. + if (&conf->file_hash)
  2910. + hash_table_deinit(&conf->file_hash);
  2911. + if (&conf->obs_file_hash)
  2912. + hash_table_deinit(&conf->obs_file_hash);
  2913. +
  2914. + ipkg_conf_free_string(&conf->offline_root);
  2915. + ipkg_conf_free_string(&conf->offline_root_pre_script_cmd);
  2916. + ipkg_conf_free_string(&conf->offline_root_post_script_cmd);
  2917. +
  2918. + if (conf->verbosity > 1) {
  2919. + int i;
  2920. + hash_table_t *hashes[] = {
  2921. + &conf->pkg_hash,
  2922. + &conf->file_hash,
  2923. + &conf->obs_file_hash };
  2924. + for (i = 0; i < 3; i++) {
  2925. + hash_table_t *hash = hashes[i];
  2926. + int c = 0;
  2927. + int n_conflicts = 0;
  2928. + int j;
  2929. + for (j = 0; j < hash->n_entries; j++) {
  2930. + int len = 0;
  2931. + hash_entry_t *e = &hash->entries[j];
  2932. + if (e->next)
  2933. + n_conflicts++;
  2934. + while (e && e->key) {
  2935. + len++;
  2936. + e = e->next;
  2937. + }
  2938. + if (len > c)
  2939. + c = len;
  2940. + }
  2941. + ipkg_message(conf, IPKG_DEBUG, "hash_table[%s] n_buckets=%d n_elements=%d max_conflicts=%d n_conflicts=%d\n",
  2942. + hash->name, hash->n_entries, hash->n_elements, c, n_conflicts);
  2943. + hash_table_deinit(hash);
  2944. + }
  2945. + }
  2946. +}
  2947. +
  2948. +static int ipkg_conf_set_default_dest(ipkg_conf_t *conf,
  2949. + const char *default_dest_name)
  2950. +{
  2951. + pkg_dest_list_elt_t *iter;
  2952. + pkg_dest_t *dest;
  2953. +
  2954. + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
  2955. + dest = iter->data;
  2956. + if (strcmp(dest->name, default_dest_name) == 0) {
  2957. + conf->default_dest = dest;
  2958. + conf->restrict_to_default_dest = 1;
  2959. + return 0;
  2960. + }
  2961. + }
  2962. +
  2963. + fprintf(stderr, "ERROR: Unknown dest name: `%s'\n", default_dest_name);
  2964. +
  2965. + return 1;
  2966. +}
  2967. +
  2968. +static int set_and_load_pkg_src_list(ipkg_conf_t *conf, pkg_src_list_t *pkg_src_list)
  2969. +{
  2970. + pkg_src_list_elt_t *iter;
  2971. + pkg_src_t *src;
  2972. + char *list_file;
  2973. +
  2974. + for (iter = pkg_src_list->head; iter; iter = iter->next) {
  2975. + src = iter->data;
  2976. + if (src == NULL) {
  2977. + continue;
  2978. + }
  2979. +
  2980. + sprintf_alloc(&list_file, "%s/%s",
  2981. + conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir,
  2982. + src->name);
  2983. +
  2984. + if (file_exists(list_file)) {
  2985. + pkg_hash_add_from_file(conf, list_file, src, NULL, 0);
  2986. + }
  2987. + free(list_file);
  2988. + }
  2989. +
  2990. + return 0;
  2991. +}
  2992. +
  2993. +static int set_and_load_pkg_dest_list(ipkg_conf_t *conf, nv_pair_list_t *nv_pair_list, char *lists_dir )
  2994. +{
  2995. + nv_pair_list_elt_t *iter;
  2996. + nv_pair_t *nv_pair;
  2997. + pkg_dest_t *dest;
  2998. + char *root_dir;
  2999. +
  3000. + for (iter = nv_pair_list->head; iter; iter = iter->next) {
  3001. + nv_pair = iter->data;
  3002. +
  3003. + if (conf->offline_root) {
  3004. + sprintf_alloc(&root_dir, "%s%s", conf->offline_root, nv_pair->value);
  3005. + } else {
  3006. + root_dir = strdup(nv_pair->value);
  3007. + }
  3008. + dest = pkg_dest_list_append(&conf->pkg_dest_list, nv_pair->name, root_dir, lists_dir);
  3009. + free(root_dir);
  3010. + if (dest == NULL) {
  3011. + continue;
  3012. + }
  3013. + if (conf->default_dest == NULL) {
  3014. + conf->default_dest = dest;
  3015. + }
  3016. + if (file_exists(dest->status_file_name)) {
  3017. + pkg_hash_add_from_file(conf, dest->status_file_name,
  3018. + NULL, dest, 1);
  3019. + }
  3020. + }
  3021. +
  3022. + return 0;
  3023. +}
  3024. +
  3025. +static int ipkg_conf_parse_file(ipkg_conf_t *conf, const char *filename,
  3026. + pkg_src_list_t *pkg_src_list,
  3027. + nv_pair_list_t *tmp_dest_nv_pair_list,
  3028. + char **lists_dir)
  3029. +{
  3030. + ipkg_option_t * options;
  3031. + FILE *file = fopen(filename, "r");
  3032. + regex_t valid_line_re, comment_re;
  3033. +#define regmatch_size 12
  3034. + regmatch_t regmatch[regmatch_size];
  3035. +
  3036. + if (ipkg_init_options_array(conf, &options)<0)
  3037. + return ENOMEM;
  3038. +
  3039. + if (file == NULL) {
  3040. + fprintf(stderr, "%s: failed to open %s: %s\n",
  3041. + __FUNCTION__, filename, strerror(errno));
  3042. + free(options);
  3043. + return errno;
  3044. + }
  3045. + ipkg_message(conf, IPKG_NOTICE, "loading conf file %s\n", filename);
  3046. +
  3047. + xregcomp(&comment_re,
  3048. + "^[[:space:]]*(#.*|[[:space:]]*)$",
  3049. + REG_EXTENDED);
  3050. + xregcomp(&valid_line_re, "^[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))([[:space:]]+([^[:space:]]+))?[[:space:]]*$", REG_EXTENDED);
  3051. +
  3052. + while(1) {
  3053. + int line_num = 0;
  3054. + char *line;
  3055. + char *type, *name, *value, *extra;
  3056. +
  3057. + line = file_read_line_alloc(file);
  3058. + line_num++;
  3059. + if (line == NULL) {
  3060. + break;
  3061. + }
  3062. +
  3063. + str_chomp(line);
  3064. +
  3065. + if (regexec(&comment_re, line, 0, 0, 0) == 0) {
  3066. + goto NEXT_LINE;
  3067. + }
  3068. +
  3069. + if (regexec(&valid_line_re, line, regmatch_size, regmatch, 0) == REG_NOMATCH) {
  3070. + str_chomp(line);
  3071. + fprintf(stderr, "%s:%d: Ignoring invalid line: `%s'\n",
  3072. + filename, line_num, line);
  3073. + goto NEXT_LINE;
  3074. + }
  3075. +
  3076. + /* This has to be so ugly to deal with optional quotation marks */
  3077. + if (regmatch[2].rm_so > 0) {
  3078. + type = strndup(line + regmatch[2].rm_so,
  3079. + regmatch[2].rm_eo - regmatch[2].rm_so);
  3080. + } else {
  3081. + type = strndup(line + regmatch[3].rm_so,
  3082. + regmatch[3].rm_eo - regmatch[3].rm_so);
  3083. + }
  3084. + if (regmatch[5].rm_so > 0) {
  3085. + name = strndup(line + regmatch[5].rm_so,
  3086. + regmatch[5].rm_eo - regmatch[5].rm_so);
  3087. + } else {
  3088. + name = strndup(line + regmatch[6].rm_so,
  3089. + regmatch[6].rm_eo - regmatch[6].rm_so);
  3090. + }
  3091. + if (regmatch[8].rm_so > 0) {
  3092. + value = strndup(line + regmatch[8].rm_so,
  3093. + regmatch[8].rm_eo - regmatch[8].rm_so);
  3094. + } else {
  3095. + value = strndup(line + regmatch[9].rm_so,
  3096. + regmatch[9].rm_eo - regmatch[9].rm_so);
  3097. + }
  3098. + extra = NULL;
  3099. + if (regmatch[11].rm_so > 0) {
  3100. + extra = strndup (line + regmatch[11].rm_so,
  3101. + regmatch[11].rm_eo - regmatch[11].rm_so);
  3102. + }
  3103. +
  3104. + /* We use the tmp_dest_nv_pair_list below instead of
  3105. + conf->pkg_dest_list because we might encounter an
  3106. + offline_root option later and that would invalidate the
  3107. + directories we would have computed in
  3108. + pkg_dest_list_init. (We do a similar thing with
  3109. + tmp_src_nv_pair_list for sake of symmetry.) */
  3110. + if (strcmp(type, "option") == 0) {
  3111. + ipkg_conf_set_option(options, name, value);
  3112. + } else if (strcmp(type, "src") == 0) {
  3113. + if (!nv_pair_list_find((nv_pair_list_t *)pkg_src_list, name)) {
  3114. + pkg_src_list_append (pkg_src_list, name, value, extra, 0);
  3115. + } else {
  3116. + ipkg_message(conf, IPKG_ERROR, "ERROR: duplicate src declaration. Skipping:\n\t src %s %s\n",
  3117. + name, value);
  3118. + }
  3119. + } else if (strcmp(type, "src/gz") == 0) {
  3120. + if (!nv_pair_list_find((nv_pair_list_t *)pkg_src_list, name)) {
  3121. + pkg_src_list_append (pkg_src_list, name, value, extra, 1);
  3122. + } else {
  3123. + ipkg_message(conf, IPKG_ERROR, "ERROR: duplicate src declaration. Skipping:\n\t src %s %s\n",
  3124. + name, value);
  3125. + }
  3126. + } else if (strcmp(type, "dest") == 0) {
  3127. + nv_pair_list_append(tmp_dest_nv_pair_list, name, value);
  3128. + } else if (strcmp(type, "lists_dir") == 0) {
  3129. + *lists_dir = realloc(*lists_dir,strlen(value)+1);
  3130. + if (*lists_dir == NULL) {
  3131. + ipkg_message(conf, IPKG_ERROR, "ERROR: Not enough memory\n");
  3132. + free(options);
  3133. + return EINVAL;
  3134. + }
  3135. + sprintf (*lists_dir,"%s",value);
  3136. + } else if (strcmp(type, "arch") == 0) {
  3137. + ipkg_message(conf, IPKG_INFO, "supported arch %s priority (%s)\n", name, value);
  3138. + if (!value) {
  3139. + ipkg_message(conf, IPKG_NOTICE, "defaulting architecture %s priority to 10\n", name);
  3140. + value = strdup("10");
  3141. + }
  3142. + nv_pair_list_append(&conf->arch_list, strdup(name), strdup(value));
  3143. + } else {
  3144. + fprintf(stderr, "WARNING: Ignoring unknown configuration "
  3145. + "parameter: %s %s %s\n", type, name, value);
  3146. + free(options);
  3147. + return EINVAL;
  3148. + }
  3149. +
  3150. + free(type);
  3151. + free(name);
  3152. + free(value);
  3153. + if (extra)
  3154. + free (extra);
  3155. +
  3156. + NEXT_LINE:
  3157. + free(line);
  3158. + }
  3159. +
  3160. + free(options);
  3161. + regfree(&comment_re);
  3162. + regfree(&valid_line_re);
  3163. + fclose(file);
  3164. +
  3165. + return 0;
  3166. +}
  3167. +
  3168. +static int ipkg_conf_set_option(const ipkg_option_t *options,
  3169. + const char *name, const char *value)
  3170. +{
  3171. + int i = 0;
  3172. + while (options[i].name) {
  3173. + if (strcmp(options[i].name, name) == 0) {
  3174. + switch (options[i].type) {
  3175. + case IPKG_OPT_TYPE_BOOL:
  3176. + *((int *)options[i].value) = 1;
  3177. + return 0;
  3178. + case IPKG_OPT_TYPE_INT:
  3179. + if (value) {
  3180. + *((int *)options[i].value) = atoi(value);
  3181. + return 0;
  3182. + } else {
  3183. + printf("%s: Option %s need an argument\n",
  3184. + __FUNCTION__, name);
  3185. + return EINVAL;
  3186. + }
  3187. + case IPKG_OPT_TYPE_STRING:
  3188. + if (value) {
  3189. + *((char **)options[i].value) = strdup(value);
  3190. + return 0;
  3191. + } else {
  3192. + printf("%s: Option %s need an argument\n",
  3193. + __FUNCTION__, name);
  3194. + return EINVAL;
  3195. + }
  3196. + }
  3197. + }
  3198. + i++;
  3199. + }
  3200. +
  3201. + fprintf(stderr, "%s: Unrecognized option: %s=%s\n",
  3202. + __FUNCTION__, name, value);
  3203. + return EINVAL;
  3204. +}
  3205. +
  3206. +int ipkg_conf_write_status_files(ipkg_conf_t *conf)
  3207. +{
  3208. + pkg_dest_list_elt_t *iter;
  3209. + pkg_dest_t *dest;
  3210. + pkg_vec_t *all;
  3211. + pkg_t *pkg;
  3212. + register int i;
  3213. + int err;
  3214. +
  3215. + if (conf->noaction)
  3216. + return 0;
  3217. + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
  3218. + dest = iter->data;
  3219. + dest->status_file = fopen(dest->status_file_tmp_name, "w");
  3220. + if (dest->status_file == NULL) {
  3221. + fprintf(stderr, "%s: Can't open status file: %s for writing: %s\n",
  3222. + __FUNCTION__, dest->status_file_name, strerror(errno));
  3223. + }
  3224. + }
  3225. +
  3226. + all = pkg_vec_alloc();
  3227. + pkg_hash_fetch_available(&conf->pkg_hash, all);
  3228. +
  3229. + for(i = 0; i < all->len; i++) {
  3230. + pkg = all->pkgs[i];
  3231. + /* We don't need most uninstalled packages in the status file */
  3232. + if (pkg->state_status == SS_NOT_INSTALLED
  3233. + && (pkg->state_want == SW_UNKNOWN
  3234. + || pkg->state_want == SW_DEINSTALL
  3235. + || pkg->state_want == SW_PURGE)) {
  3236. + continue;
  3237. + }
  3238. + if (!pkg) {
  3239. + fprintf(stderr, "Null package\n");
  3240. + }
  3241. + if (pkg->dest == NULL) {
  3242. + fprintf(stderr, "%s: ERROR: Can't write status for "
  3243. + "package %s since it has a NULL dest\n",
  3244. + __FUNCTION__, pkg->name);
  3245. + continue;
  3246. + }
  3247. + if (pkg->dest->status_file) {
  3248. + pkg_print_status(pkg, pkg->dest->status_file);
  3249. + }
  3250. + }
  3251. +
  3252. + pkg_vec_free(all);
  3253. +
  3254. + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
  3255. + dest = iter->data;
  3256. + if (dest->status_file) {
  3257. + err = ferror(dest->status_file);
  3258. + fclose(dest->status_file);
  3259. + dest->status_file = NULL;
  3260. + if (!err) {
  3261. + file_move(dest->status_file_tmp_name, dest->status_file_name);
  3262. + } else {
  3263. + fprintf(stderr, "%s: ERROR: An error has occurred writing %s, "
  3264. + "retaining old %s\n", __FUNCTION__,
  3265. + dest->status_file_tmp_name, dest->status_file_name);
  3266. + }
  3267. + }
  3268. + }
  3269. +
  3270. + return 0;
  3271. +}
  3272. +
  3273. +
  3274. +char *root_filename_alloc(ipkg_conf_t *conf, char *filename)
  3275. +{
  3276. + char *root_filename;
  3277. + sprintf_alloc(&root_filename, "%s%s", (conf->offline_root ? conf->offline_root : ""), filename);
  3278. + return root_filename;
  3279. +}
  3280. diff -Nur busybox-1.17.2.orig/archival/libipkg/ipkg_conf.h busybox-1.17.2/archival/libipkg/ipkg_conf.h
  3281. --- busybox-1.17.2.orig/archival/libipkg/ipkg_conf.h 1970-01-01 01:00:00.000000000 +0100
  3282. +++ busybox-1.17.2/archival/libipkg/ipkg_conf.h 2010-12-01 22:25:23.000000000 +0100
  3283. @@ -0,0 +1,107 @@
  3284. +/* ipkg_conf.h - the itsy package management system
  3285. +
  3286. + Carl D. Worth
  3287. +
  3288. + Copyright (C) 2001 University of Southern California
  3289. +
  3290. + This program is free software; you can redistribute it and/or
  3291. + modify it under the terms of the GNU General Public License as
  3292. + published by the Free Software Foundation; either version 2, or (at
  3293. + your option) any later version.
  3294. +
  3295. + This program is distributed in the hope that it will be useful, but
  3296. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3297. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3298. + General Public License for more details.
  3299. +*/
  3300. +
  3301. +#ifndef IPKG_CONF_H
  3302. +#define IPKG_CONF_H
  3303. +
  3304. +typedef struct ipkg_conf ipkg_conf_t;
  3305. +
  3306. +#include "hash_table.h"
  3307. +#include "ipkg.h"
  3308. +#include "args.h"
  3309. +#include "pkg.h"
  3310. +#include "pkg_hash.h"
  3311. +#include "pkg_src_list.h"
  3312. +#include "pkg_dest_list.h"
  3313. +#include "nv_pair_list.h"
  3314. +
  3315. +#define IPKG_CONF_DEFAULT_TMP_DIR_BASE "/tmp"
  3316. +#define IPKG_CONF_TMP_DIR_SUFFIX "ipkg-XXXXXX"
  3317. +#define IPKG_CONF_LISTS_DIR IPKG_STATE_DIR_PREFIX "/lists"
  3318. +#define IPKG_CONF_PENDING_DIR IPKG_STATE_DIR_PREFIX "/pending"
  3319. +
  3320. +/* In case the config file defines no dest */
  3321. +#define IPKG_CONF_DEFAULT_DEST_NAME "root"
  3322. +#define IPKG_CONF_DEFAULT_DEST_ROOT_DIR "/"
  3323. +
  3324. +#define IPKG_CONF_DEFAULT_HASH_LEN 1024
  3325. +
  3326. +struct ipkg_conf
  3327. +{
  3328. + pkg_src_list_t pkg_src_list;
  3329. + pkg_dest_list_t pkg_dest_list;
  3330. + nv_pair_list_t arch_list;
  3331. +
  3332. + int restrict_to_default_dest;
  3333. + pkg_dest_t *default_dest;
  3334. +
  3335. + char *tmp_dir;
  3336. + char *lists_dir;
  3337. + char *pending_dir;
  3338. +
  3339. + /* options */
  3340. + int force_depends;
  3341. + int force_defaults;
  3342. + int force_overwrite;
  3343. + int force_downgrade;
  3344. + int force_reinstall;
  3345. + int force_space;
  3346. + int force_removal_of_dependent_packages;
  3347. + int force_removal_of_essential_packages;
  3348. + int nodeps; /* do not follow dependences */
  3349. + int verbose_wget;
  3350. + int multiple_providers;
  3351. + char *offline_root;
  3352. + char *offline_root_pre_script_cmd;
  3353. + char *offline_root_post_script_cmd;
  3354. + int query_all;
  3355. + int verbosity;
  3356. + int noaction;
  3357. +
  3358. + /* proxy options */
  3359. + char *http_proxy;
  3360. + char *ftp_proxy;
  3361. + char *no_proxy;
  3362. + char *proxy_user;
  3363. + char *proxy_passwd;
  3364. +
  3365. + hash_table_t pkg_hash;
  3366. + hash_table_t file_hash;
  3367. + hash_table_t obs_file_hash;
  3368. +};
  3369. +
  3370. +enum ipkg_option_type {
  3371. + IPKG_OPT_TYPE_BOOL,
  3372. + IPKG_OPT_TYPE_INT,
  3373. + IPKG_OPT_TYPE_STRING
  3374. +};
  3375. +typedef enum ipkg_option_type ipkg_option_type_t;
  3376. +
  3377. +typedef struct ipkg_option ipkg_option_t;
  3378. +struct ipkg_option {
  3379. + const char *name;
  3380. + const ipkg_option_type_t type;
  3381. + const void *value;
  3382. +};
  3383. +
  3384. +int ipkg_conf_init(ipkg_conf_t *conf, const args_t *args);
  3385. +void ipkg_conf_deinit(ipkg_conf_t *conf);
  3386. +
  3387. +int ipkg_conf_write_status_files(ipkg_conf_t *conf);
  3388. +char *root_filename_alloc(ipkg_conf_t *conf, char *filename);
  3389. +
  3390. +#endif
  3391. diff -Nur busybox-1.17.2.orig/archival/libipkg/ipkg_configure.c busybox-1.17.2/archival/libipkg/ipkg_configure.c
  3392. --- busybox-1.17.2.orig/archival/libipkg/ipkg_configure.c 1970-01-01 01:00:00.000000000 +0100
  3393. +++ busybox-1.17.2/archival/libipkg/ipkg_configure.c 2010-12-01 22:25:23.000000000 +0100
  3394. @@ -0,0 +1,40 @@
  3395. +/* ipkg_configure.c - the itsy package management system
  3396. +
  3397. + Carl D. Worth
  3398. +
  3399. + Copyright (C) 2001 University of Southern California
  3400. +
  3401. + This program is free software; you can redistribute it and/or
  3402. + modify it under the terms of the GNU General Public License as
  3403. + published by the Free Software Foundation; either version 2, or (at
  3404. + your option) any later version.
  3405. +
  3406. + This program is distributed in the hope that it will be useful, but
  3407. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3408. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3409. + General Public License for more details.
  3410. +*/
  3411. +
  3412. +#include "ipkg.h"
  3413. +
  3414. +#include "ipkg_configure.h"
  3415. +
  3416. +int ipkg_configure(ipkg_conf_t *conf, pkg_t *pkg)
  3417. +{
  3418. + int err;
  3419. +
  3420. + /* DPKG_INCOMPATIBILITY:
  3421. + dpkg actually does some conffile handling here, rather than at the
  3422. + end of ipkg_install(). Do we care? */
  3423. + /* DPKG_INCOMPATIBILITY:
  3424. + dpkg actually includes a version number to this script call */
  3425. + err = pkg_run_script(conf, pkg, "postinst", "configure");
  3426. + if (err) {
  3427. + printf("ERROR: %s.postinst returned %d\n", pkg->name, err);
  3428. + return err;
  3429. + }
  3430. +
  3431. + ipkg_state_changed++;
  3432. + return 0;
  3433. +}
  3434. +
  3435. diff -Nur busybox-1.17.2.orig/archival/libipkg/ipkg_configure.h busybox-1.17.2/archival/libipkg/ipkg_configure.h
  3436. --- busybox-1.17.2.orig/archival/libipkg/ipkg_configure.h 1970-01-01 01:00:00.000000000 +0100
  3437. +++ busybox-1.17.2/archival/libipkg/ipkg_configure.h 2010-12-01 22:25:23.000000000 +0100
  3438. @@ -0,0 +1,25 @@
  3439. +/* ipkg_configure.h - the itsy package management system
  3440. +
  3441. + Carl D. Worth
  3442. +
  3443. + Copyright (C) 2001 University of Southern California
  3444. +
  3445. + This program is free software; you can redistribute it and/or
  3446. + modify it under the terms of the GNU General Public License as
  3447. + published by the Free Software Foundation; either version 2, or (at
  3448. + your option) any later version.
  3449. +
  3450. + This program is distributed in the hope that it will be useful, but
  3451. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3452. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3453. + General Public License for more details.
  3454. +*/
  3455. +
  3456. +#ifndef IPKG_CONFIGURE_H
  3457. +#define IPKG_CONFIGURE_H
  3458. +
  3459. +#include "ipkg_conf.h"
  3460. +
  3461. +int ipkg_configure(ipkg_conf_t *ipkg_conf, pkg_t *pkg);
  3462. +
  3463. +#endif
  3464. diff -Nur busybox-1.17.2.orig/archival/libipkg/ipkg_download.c busybox-1.17.2/archival/libipkg/ipkg_download.c
  3465. --- busybox-1.17.2.orig/archival/libipkg/ipkg_download.c 1970-01-01 01:00:00.000000000 +0100
  3466. +++ busybox-1.17.2/archival/libipkg/ipkg_download.c 2010-12-01 22:25:23.000000000 +0100
  3467. @@ -0,0 +1,195 @@
  3468. +/* ipkg_download.c - the itsy package management system
  3469. +
  3470. + Carl D. Worth
  3471. +
  3472. + Copyright (C) 2001 University of Southern California
  3473. +
  3474. + This program is free software; you can redistribute it and/or
  3475. + modify it under the terms of the GNU General Public License as
  3476. + published by the Free Software Foundation; either version 2, or (at
  3477. + your option) any later version.
  3478. +
  3479. + This program is distributed in the hope that it will be useful, but
  3480. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3481. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3482. + General Public License for more details.
  3483. +*/
  3484. +
  3485. +#include "ipkg.h"
  3486. +#include "ipkg_download.h"
  3487. +#include "ipkg_message.h"
  3488. +
  3489. +#include "sprintf_alloc.h"
  3490. +#include "xsystem.h"
  3491. +#include "file_util.h"
  3492. +#include "str_util.h"
  3493. +
  3494. +int ipkg_download(ipkg_conf_t *conf, const char *src, const char *dest_file_name)
  3495. +{
  3496. + int err = 0;
  3497. +
  3498. + char *src_basec = strdup(src);
  3499. + char *src_base = basename(src_basec);
  3500. + char *tmp_file_location;
  3501. + char *cmd;
  3502. +
  3503. + ipkg_message(conf,IPKG_NOTICE,"Downloading %s\n", src);
  3504. +
  3505. + fflush(stdout);
  3506. +
  3507. + if (str_starts_with(src, "file:")) {
  3508. + int ret;
  3509. + const char *file_src = src + 5;
  3510. + ipkg_message(conf,IPKG_INFO,"Copying %s to %s...", file_src, dest_file_name);
  3511. + ret = file_copy(src + 5, dest_file_name);
  3512. + ipkg_message(conf,IPKG_INFO,"Done.\n");
  3513. + return ret;
  3514. + }
  3515. +
  3516. + sprintf_alloc(&tmp_file_location, "%s/%s", conf->tmp_dir, src_base);
  3517. + err = unlink(tmp_file_location);
  3518. + if (err && errno != ENOENT) {
  3519. + ipkg_message(conf,IPKG_ERROR, "%s: ERROR: failed to unlink %s: %s\n",
  3520. + __FUNCTION__, tmp_file_location, strerror(errno));
  3521. + free(tmp_file_location);
  3522. + return errno;
  3523. + }
  3524. +
  3525. + if (conf->http_proxy) {
  3526. + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: http_proxy = %s\n", conf->http_proxy);
  3527. + setenv("http_proxy", conf->http_proxy, 1);
  3528. + }
  3529. + if (conf->ftp_proxy) {
  3530. + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: ftp_proxy = %s\n", conf->ftp_proxy);
  3531. + setenv("ftp_proxy", conf->ftp_proxy, 1);
  3532. + }
  3533. + if (conf->no_proxy) {
  3534. + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: no_proxy = %s\n", conf->no_proxy);
  3535. + setenv("no_proxy", conf->no_proxy, 1);
  3536. + }
  3537. +
  3538. + /* XXX: BUG rewrite to use execvp or else busybox's internal wget -Jamey 7/23/2002 */
  3539. + sprintf_alloc(&cmd, "wget %s %s%s %s%s %s -P %s %s",
  3540. + (conf->http_proxy || conf->ftp_proxy) ? "-Y on" : "",
  3541. + conf->proxy_user ? "--proxy-user=" : "",
  3542. + conf->proxy_user ? conf->proxy_user : "",
  3543. + conf->proxy_passwd ? "--proxy-passwd=" : "",
  3544. + conf->proxy_passwd ? conf->proxy_passwd : "",
  3545. + conf->verbose_wget ? "" : "-q",
  3546. + conf->tmp_dir,
  3547. + src);
  3548. + err = xsystem(cmd);
  3549. + if (err) {
  3550. + if (err != -1) {
  3551. + ipkg_message(conf,IPKG_ERROR, "%s: ERROR: Command failed with return value %d: `%s'\n",
  3552. + __FUNCTION__, err, cmd);
  3553. + }
  3554. + unlink(tmp_file_location);
  3555. + free(tmp_file_location);
  3556. + free(src_basec);
  3557. + free(cmd);
  3558. + return EINVAL;
  3559. + }
  3560. + free(cmd);
  3561. +
  3562. + err = file_move(tmp_file_location, dest_file_name);
  3563. +
  3564. + free(tmp_file_location);
  3565. + free(src_basec);
  3566. +
  3567. + if (err) {
  3568. + return err;
  3569. + }
  3570. +
  3571. + return 0;
  3572. +}
  3573. +
  3574. +int ipkg_download_pkg(ipkg_conf_t *conf, pkg_t *pkg, const char *dir)
  3575. +{
  3576. + int err;
  3577. + char *url;
  3578. +
  3579. + if (pkg->src == NULL) {
  3580. + ipkg_message(conf,IPKG_ERROR, "ERROR: Package %s (parent %s) is not available from any configured src.\n",
  3581. + pkg->name, pkg->parent->name);
  3582. + return -1;
  3583. + }
  3584. +
  3585. + sprintf_alloc(&url, "%s/%s", pkg->src->value, pkg->filename);
  3586. +
  3587. + /* XXX: BUG: The pkg->filename might be something like
  3588. + "../../foo.ipk". While this is correct, and exactly what we
  3589. + want to use to construct url above, here we actually need to
  3590. + use just the filename part, without any directory. */
  3591. + sprintf_alloc(&pkg->local_filename, "%s/%s", dir, pkg->filename);
  3592. +
  3593. + err = ipkg_download(conf, url, pkg->local_filename);
  3594. + free(url);
  3595. +
  3596. + return err;
  3597. +}
  3598. +
  3599. +/*
  3600. + * Downloads file from url, installs in package database, return package name.
  3601. + */
  3602. +int ipkg_prepare_url_for_install(ipkg_conf_t *conf, const char *url, char **namep)
  3603. +{
  3604. + int err = 0;
  3605. + pkg_t *pkg;
  3606. + pkg = pkg_new();
  3607. + if (pkg == NULL)
  3608. + return ENOMEM;
  3609. +
  3610. + if (str_starts_with(url, "http://")
  3611. + || str_starts_with(url, "ftp://")) {
  3612. + char *tmp_file;
  3613. + char *file_basec = strdup(url);
  3614. + char *file_base = basename(file_basec);
  3615. +
  3616. + sprintf_alloc(&tmp_file, "%s/%s", conf->tmp_dir, file_base);
  3617. + err = ipkg_download(conf, url, tmp_file);
  3618. + if (err)
  3619. + return err;
  3620. +
  3621. + err = pkg_init_from_file(pkg, tmp_file);
  3622. + if (err)
  3623. + return err;
  3624. + pkg->local_filename = strdup(tmp_file);
  3625. +
  3626. + free(tmp_file);
  3627. + free(file_basec);
  3628. +
  3629. + } else if (strcmp(&url[strlen(url) - 4], IPKG_PKG_EXTENSION) == 0
  3630. + || strcmp(&url[strlen(url) - 4], DPKG_PKG_EXTENSION) == 0) {
  3631. +
  3632. + err = pkg_init_from_file(pkg, url);
  3633. + if (err)
  3634. + return err;
  3635. + pkg->local_filename = strdup(url);
  3636. + ipkg_message(conf, IPKG_DEBUG2, "Package %s provided by hand (%s).\n", pkg->name,pkg->local_filename);
  3637. + pkg->provided_by_hand = 1;
  3638. +
  3639. + } else {
  3640. + pkg_deinit(pkg);
  3641. + free(pkg);
  3642. + return 0;
  3643. + }
  3644. +
  3645. + if (!pkg->architecture) {
  3646. + ipkg_message(conf, IPKG_ERROR, "Package %s has no Architecture defined.\n", pkg->name);
  3647. + return -EINVAL;
  3648. + }
  3649. +
  3650. + pkg->dest = conf->default_dest;
  3651. + pkg->state_want = SW_INSTALL;
  3652. + pkg->state_flag |= SF_PREFER;
  3653. + pkg = hash_insert_pkg(&conf->pkg_hash, pkg, 1,conf);
  3654. + if ( pkg == NULL ){
  3655. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  3656. + return 0;
  3657. + }
  3658. + if (namep) {
  3659. + *namep = strdup(pkg->name);
  3660. + }
  3661. + return 0;
  3662. +}
  3663. diff -Nur busybox-1.17.2.orig/archival/libipkg/ipkg_download.h busybox-1.17.2/archival/libipkg/ipkg_download.h
  3664. --- busybox-1.17.2.orig/archival/libipkg/ipkg_download.h 1970-01-01 01:00:00.000000000 +0100
  3665. +++ busybox-1.17.2/archival/libipkg/ipkg_download.h 2010-12-01 22:25:23.000000000 +0100
  3666. @@ -0,0 +1,30 @@
  3667. +/* ipkg_download.h - the itsy package management system
  3668. +
  3669. + Carl D. Worth
  3670. +
  3671. + Copyright (C) 2001 University of Southern California
  3672. +
  3673. + This program is free software; you can redistribute it and/or
  3674. + modify it under the terms of the GNU General Public License as
  3675. + published by the Free Software Foundation; either version 2, or (at
  3676. + your option) any later version.
  3677. +
  3678. + This program is distributed in the hope that it will be useful, but
  3679. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3680. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3681. + General Public License for more details.
  3682. +*/
  3683. +
  3684. +#ifndef IPKG_DOWNLOAD_H
  3685. +#define IPKG_DOWNLOAD_H
  3686. +
  3687. +#include "ipkg_conf.h"
  3688. +
  3689. +int ipkg_download(ipkg_conf_t *conf, const char *src, const char *dest_file_name);
  3690. +int ipkg_download_pkg(ipkg_conf_t *conf, pkg_t *pkg, const char *dir);
  3691. +/*
  3692. + * Downloads file from url, installs in package database, return package name.
  3693. + */
  3694. +int ipkg_prepare_url_for_install(ipkg_conf_t *conf, const char *url, char **namep);
  3695. +
  3696. +#endif
  3697. diff -Nur busybox-1.17.2.orig/archival/libipkg/ipkg_includes.h busybox-1.17.2/archival/libipkg/ipkg_includes.h
  3698. --- busybox-1.17.2.orig/archival/libipkg/ipkg_includes.h 1970-01-01 01:00:00.000000000 +0100
  3699. +++ busybox-1.17.2/archival/libipkg/ipkg_includes.h 2010-12-01 22:25:23.000000000 +0100
  3700. @@ -0,0 +1,82 @@
  3701. +#ifndef IPKG_INCLUDES_H
  3702. +#define IPKG_INCLUDES_H
  3703. +
  3704. +/* Define to 1 if you have the <memory.h> header file. */
  3705. +#define HAVE_MEMORY_H 1
  3706. +
  3707. +/* Define to 1 if you have the <regex.h> header file. */
  3708. +#define HAVE_REGEX_H 1
  3709. +
  3710. +/* Define to 1 if you have the <stdlib.h> header file. */
  3711. +#define HAVE_STDLIB_H 1
  3712. +
  3713. +/* Define to 1 if you have the <strings.h> header file. */
  3714. +#define HAVE_STRINGS_H 1
  3715. +
  3716. +/* Define to 1 if you have the <string.h> header file. */
  3717. +#define HAVE_STRING_H 1
  3718. +
  3719. +/* Define to 1 if you have the <sys/stat.h> header file. */
  3720. +#define HAVE_SYS_STAT_H 1
  3721. +
  3722. +/* Define to 1 if you have <sys/wait.h> that is POSIX.1 compatible. */
  3723. +#define HAVE_SYS_WAIT_H 1
  3724. +
  3725. +/* Define to 1 if you have the <unistd.h> header file. */
  3726. +#define HAVE_UNISTD_H 1
  3727. +
  3728. +/* Define to 1 if you have the ANSI C header files. */
  3729. +#define STDC_HEADERS 1
  3730. +
  3731. +
  3732. +#include <stdio.h>
  3733. +
  3734. +#if STDC_HEADERS
  3735. +# include <stdlib.h>
  3736. +# include <stdarg.h>
  3737. +# include <stddef.h>
  3738. +# include <ctype.h>
  3739. +# include <errno.h>
  3740. +#else
  3741. +# if HAVE_STDLIB_H
  3742. +# include <stdlib.h>
  3743. +# endif
  3744. +#endif
  3745. +
  3746. +#if HAVE_REGEX_H
  3747. +# include <regex.h>
  3748. +#endif
  3749. +
  3750. +#if HAVE_STRING_H
  3751. +# if !STDC_HEADERS && HAVE_MEMORY_H
  3752. +# include <memory.h>
  3753. +# endif
  3754. +/* XXX: What's the right way to pick up GNU's strndup declaration? */
  3755. +# if __GNUC__
  3756. +# define __USE_GNU 1
  3757. +# endif
  3758. +# include <string.h>
  3759. +# undef __USE_GNU
  3760. +#endif
  3761. +
  3762. +#if HAVE_STRINGS_H
  3763. +# include <strings.h>
  3764. +#endif
  3765. +
  3766. +#if HAVE_SYS_STAT_H
  3767. +# include <sys/stat.h>
  3768. +#endif
  3769. +
  3770. +#if HAVE_SYS_WAIT_H
  3771. +# include <sys/wait.h>
  3772. +#endif
  3773. +
  3774. +#if HAVE_UNISTD_H
  3775. +# include <sys/types.h>
  3776. +# include <unistd.h>
  3777. +#endif
  3778. +
  3779. +#include <sys/mount.h>
  3780. +#include <mntent.h>
  3781. +
  3782. +#endif /* IPKG_INCLUDES_H */
  3783. diff -Nur busybox-1.17.2.orig/archival/libipkg/ipkg_install.c busybox-1.17.2/archival/libipkg/ipkg_install.c
  3784. --- busybox-1.17.2.orig/archival/libipkg/ipkg_install.c 1970-01-01 01:00:00.000000000 +0100
  3785. +++ busybox-1.17.2/archival/libipkg/ipkg_install.c 2010-12-01 22:25:23.000000000 +0100
  3786. @@ -0,0 +1,1982 @@
  3787. +/* ipkg_install.c - the itsy package management system
  3788. +
  3789. + Carl D. Worth
  3790. +
  3791. + Copyright (C) 2001 University of Southern California
  3792. +
  3793. + This program is free software; you can redistribute it and/or
  3794. + modify it under the terms of the GNU General Public License as
  3795. + published by the Free Software Foundation; either version 2, or (at
  3796. + your option) any later version.
  3797. +
  3798. + This program is distributed in the hope that it will be useful, but
  3799. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3800. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3801. + General Public License for more details.
  3802. +*/
  3803. +
  3804. +#include "ipkg.h"
  3805. +#include <errno.h>
  3806. +#include <dirent.h>
  3807. +#include <glob.h>
  3808. +#include <time.h>
  3809. +#include <signal.h>
  3810. +typedef void (*sighandler_t)(int);
  3811. +
  3812. +#include "pkg.h"
  3813. +#include "pkg_hash.h"
  3814. +#include "pkg_extract.h"
  3815. +
  3816. +#include "ipkg_install.h"
  3817. +#include "ipkg_configure.h"
  3818. +#include "ipkg_download.h"
  3819. +#include "ipkg_remove.h"
  3820. +
  3821. +#include "ipkg_utils.h"
  3822. +#include "ipkg_message.h"
  3823. +
  3824. +#include "sprintf_alloc.h"
  3825. +#include "file_util.h"
  3826. +#include "str_util.h"
  3827. +#include "xsystem.h"
  3828. +#include "user.h"
  3829. +
  3830. +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg);
  3831. +static int verify_pkg_installable(ipkg_conf_t *conf, pkg_t *pkg);
  3832. +static int unpack_pkg_control_files(ipkg_conf_t *conf, pkg_t *pkg);
  3833. +
  3834. +/*
  3835. +static int prerm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3836. +static int prerm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3837. +static int prerm_deconfigure_conflictors(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors);
  3838. +static int prerm_deconfigure_conflictors_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors);
  3839. +static int preinst_configure_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3840. +static int check_data_file_clashes_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3841. +static int postrm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3842. +static int remove_disappeared(ipkg_conf_t *conf, pkg_t *pkg);
  3843. +static int postrm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3844. +*/
  3845. +static int preinst_configure(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3846. +static int check_data_file_clashes(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3847. +static int check_data_file_clashes_change(ipkg_conf_t *conf, pkg_t *pkg);
  3848. +static int backup_modified_conffiles(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3849. +static int backup_modified_conffiles_unwind(pkg_t *pkg, pkg_t *old_pkg);
  3850. +
  3851. +static int remove_obsolesced_files(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3852. +static int install_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3853. +static int install_data_files(ipkg_conf_t *conf, pkg_t *pkg);
  3854. +static int resolve_conffiles(ipkg_conf_t *conf, pkg_t *pkg);
  3855. +
  3856. +static int cleanup_temporary_files(ipkg_conf_t *conf, pkg_t *pkg);
  3857. +
  3858. +static int user_prefers_old_conffile(const char *file, const char *backup);
  3859. +
  3860. +static char *backup_filename_alloc(const char *file_name);
  3861. +static int backup_make_backup(ipkg_conf_t *conf, const char *file_name);
  3862. +static int backup_exists_for(const char *file_name);
  3863. +static int backup_remove(const char *file_name);
  3864. +
  3865. +int pkg_get_installed_replacees(pkg_t *pkg, pkg_vec_t *installed_replacees);
  3866. +int pkg_remove_installed_replacees(ipkg_conf_t *conf, pkg_vec_t *replacees);
  3867. +int pkg_remove_installed_replacees_unwind(ipkg_conf_t *conf, pkg_vec_t *replacees);
  3868. +
  3869. +int ipkg_install_from_file(ipkg_conf_t *conf, const char *filename)
  3870. +{
  3871. + int err, cmp;
  3872. + pkg_t *pkg, *old;
  3873. + char *old_version, *new_version;
  3874. +
  3875. + pkg = pkg_new();
  3876. + if (pkg == NULL) {
  3877. + return ENOMEM;
  3878. + }
  3879. +
  3880. + err = pkg_init_from_file(pkg, filename);
  3881. + if (err) {
  3882. + return err;
  3883. + }
  3884. +
  3885. + if (!pkg->architecture) {
  3886. + ipkg_message(conf, IPKG_ERROR, "Package %s has no Architecture defined.\n", pkg->name);
  3887. + return -EINVAL;
  3888. + }
  3889. +
  3890. + /* XXX: CLEANUP: hash_insert_pkg has a nasty side effect of possibly
  3891. + freeing the pkg that we pass in. It might be nice to clean this up
  3892. + if possible. */
  3893. + pkg = hash_insert_pkg(&conf->pkg_hash, pkg, 1,conf);
  3894. + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name);
  3895. +
  3896. + pkg->local_filename = strdup(filename);
  3897. +
  3898. + if (old) {
  3899. + old_version = pkg_version_str_alloc(old);
  3900. + new_version = pkg_version_str_alloc(pkg);
  3901. +
  3902. + cmp = pkg_compare_versions(old, pkg);
  3903. + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
  3904. + cmp = -1 ; /* then we force ipkg to downgrade */
  3905. + /* We need to use a value < 0 because in the 0 case we are asking to */
  3906. + /* reinstall, and some check could fail asking the "force-reinstall" option */
  3907. + }
  3908. + if (cmp > 0) {
  3909. + ipkg_message(conf, IPKG_NOTICE,
  3910. + "Not downgrading package %s on %s from %s to %s.\n",
  3911. + old->name, old->dest->name, old_version, new_version);
  3912. + pkg->state_want = SW_DEINSTALL;
  3913. + pkg->state_flag |= SF_OBSOLETE;
  3914. + free(old_version);
  3915. + free(new_version);
  3916. + return 0;
  3917. + } else {
  3918. + free(old_version);
  3919. + free(new_version);
  3920. + }
  3921. + }
  3922. +
  3923. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
  3924. + return ipkg_install_pkg(conf, pkg,0);
  3925. +}
  3926. +
  3927. +ipkg_error_t ipkg_install_by_name(ipkg_conf_t *conf, const char *pkg_name)
  3928. +{
  3929. + int cmp;
  3930. + pkg_t *old, *new;
  3931. + char *old_version, *new_version;
  3932. +
  3933. + ipkg_message(conf, IPKG_DEBUG2, " Getting old from pkg_hash_fetch \n" );
  3934. + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg_name);
  3935. + if ( old )
  3936. + ipkg_message(conf, IPKG_DEBUG2, " Old versions from pkg_hash_fetch %s \n", old->version );
  3937. +
  3938. + ipkg_message(conf, IPKG_DEBUG2, " Getting new from pkg_hash_fetch \n" );
  3939. + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, pkg_name);
  3940. + if ( new )
  3941. + ipkg_message(conf, IPKG_DEBUG2, " New versions from pkg_hash_fetch %s \n", new->version );
  3942. +
  3943. +/* Pigi Basically here is broken the version stuff.
  3944. + What's happening is that nothing provide the version to differents
  3945. + functions, so the returned struct is always the latest.
  3946. + That's why the install by name don't work.
  3947. +*/
  3948. + ipkg_message(conf, IPKG_DEBUG2, " Versions from pkg_hash_fetch in %s ", __FUNCTION__ );
  3949. +
  3950. + if ( old )
  3951. + ipkg_message(conf, IPKG_DEBUG2, " old %s ", old->version );
  3952. + if ( new )
  3953. + ipkg_message(conf, IPKG_DEBUG2, " new %s ", new->version );
  3954. + ipkg_message(conf, IPKG_DEBUG2, " \n");
  3955. +
  3956. + if (new == NULL) {
  3957. + return IPKG_PKG_HAS_NO_CANDIDATE;
  3958. + }
  3959. +
  3960. + new->state_flag |= SF_USER;
  3961. + if (old) {
  3962. + old_version = pkg_version_str_alloc(old);
  3963. + new_version = pkg_version_str_alloc(new);
  3964. +
  3965. + cmp = pkg_compare_versions(old, new);
  3966. + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
  3967. + ipkg_message(conf, IPKG_DEBUG, " Forcing downgrade \n");
  3968. + cmp = -1 ; /* then we force ipkg to downgrade */
  3969. + /* We need to use a value < 0 because in the 0 case we are asking to */
  3970. + /* reinstall, and some check could fail asking the "force-reinstall" option */
  3971. + }
  3972. + ipkg_message(conf, IPKG_DEBUG,
  3973. + "Comparing visible versions of pkg %s:"
  3974. + "\n\t%s is installed "
  3975. + "\n\t%s is available "
  3976. + "\n\t%d was comparison result\n",
  3977. + pkg_name, old_version, new_version, cmp);
  3978. + if (cmp == 0 && !conf->force_reinstall) {
  3979. + ipkg_message(conf, IPKG_NOTICE,
  3980. + "Package %s (%s) installed in %s is up to date.\n",
  3981. + old->name, old_version, old->dest->name);
  3982. + free(old_version);
  3983. + free(new_version);
  3984. + return 0;
  3985. + } else if (cmp > 0) {
  3986. + ipkg_message(conf, IPKG_NOTICE,
  3987. + "Not downgrading package %s on %s from %s to %s.\n",
  3988. + old->name, old->dest->name, old_version, new_version);
  3989. + free(old_version);
  3990. + free(new_version);
  3991. + return 0;
  3992. + } else if (cmp < 0) {
  3993. + new->dest = old->dest;
  3994. + old->state_want = SW_DEINSTALL; /* Here probably the problem for bug 1277 */
  3995. + }
  3996. + }
  3997. +
  3998. + /* XXX: CLEANUP: The error code of ipkg_install_by_name is really
  3999. + supposed to be an ipkg_error_t, but ipkg_install_pkg could
  4000. + return any kind of integer, (might be errno from a syscall,
  4001. + etc.). This is a real mess and will need to be cleaned up if
  4002. + anyone ever wants to make a nice libipkg. */
  4003. +
  4004. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
  4005. + return ipkg_install_pkg(conf, new,0);
  4006. +}
  4007. +
  4008. +ipkg_error_t ipkg_install_multi_by_name(ipkg_conf_t *conf, const char *pkg_name)
  4009. +{
  4010. + abstract_pkg_vec_t *providers = pkg_hash_fetch_all_installation_candidates (&conf->pkg_hash, pkg_name);
  4011. + int i;
  4012. + ipkg_error_t err;
  4013. + abstract_pkg_t *ppkg ;
  4014. +
  4015. + if (providers == NULL)
  4016. + return IPKG_PKG_HAS_NO_CANDIDATE;
  4017. +
  4018. + for (i = 0; i < providers->len; i++) {
  4019. + ppkg = abstract_pkg_vec_get(providers, i);
  4020. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_by_name %d \n",__FUNCTION__, i);
  4021. + err = ipkg_install_by_name(conf, ppkg->name);
  4022. + if (err)
  4023. + return err;
  4024. +/* XXX Maybe ppkg should be freed ? */
  4025. + }
  4026. + return 0;
  4027. +}
  4028. +
  4029. +/*
  4030. + * Walk dependence graph starting with pkg, collect packages to be
  4031. + * installed into pkgs_needed, in dependence order.
  4032. + */
  4033. +int pkg_mark_dependencies_for_installation(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *pkgs_needed)
  4034. +{
  4035. + int i, err;
  4036. + pkg_vec_t *depends = pkg_vec_alloc();
  4037. + char **unresolved = NULL;
  4038. + int ndepends;
  4039. +
  4040. + ndepends = pkg_hash_fetch_unsatisfied_dependencies(conf,
  4041. + pkg, depends,
  4042. + &unresolved);
  4043. +
  4044. + if (unresolved) {
  4045. + ipkg_message(conf, IPKG_ERROR,
  4046. + "%s: Cannot satisfy the following dependencies for %s:\n\t",
  4047. + conf->force_depends ? "Warning" : "ERROR", pkg->name);
  4048. + while (*unresolved) {
  4049. + ipkg_message(conf, IPKG_ERROR, " %s", *unresolved);
  4050. + unresolved++;
  4051. + }
  4052. + ipkg_message(conf, IPKG_ERROR, "\n");
  4053. + if (! conf->force_depends) {
  4054. + ipkg_message(conf, IPKG_INFO,
  4055. + "This could mean that your package list is out of date or that the packages\n"
  4056. + "mentioned above do not yet exist (try 'ipkg update'). To proceed in spite\n"
  4057. + "of this problem try again with the '-force-depends' option.\n");
  4058. + pkg_vec_free(depends);
  4059. + return IPKG_PKG_DEPS_UNSATISFIED;
  4060. + }
  4061. + }
  4062. +
  4063. + if (ndepends <= 0) {
  4064. + pkg_vec_free(depends);
  4065. + return 0;
  4066. + }
  4067. +
  4068. + for (i = 0; i < depends->len; i++) {
  4069. + pkg_t *dep = depends->pkgs[i];
  4070. + /* The package was uninstalled when we started, but another
  4071. + dep earlier in this loop may have depended on it and pulled
  4072. + it in, so check first. */
  4073. + if ((dep->state_status != SS_INSTALLED)
  4074. + && (dep->state_status != SS_UNPACKED)
  4075. + && (dep->state_want != SW_INSTALL)) {
  4076. +
  4077. + /* Mark packages as to-be-installed */
  4078. + dep->state_want = SW_INSTALL;
  4079. +
  4080. + /* Dependencies should be installed the same place as pkg */
  4081. + if (dep->dest == NULL) {
  4082. + dep->dest = pkg->dest;
  4083. + }
  4084. +
  4085. + err = pkg_mark_dependencies_for_installation(conf, dep, pkgs_needed);
  4086. + if (err) {
  4087. + pkg_vec_free(depends);
  4088. + return err;
  4089. + }
  4090. + }
  4091. + }
  4092. + if (pkgs_needed)
  4093. + pkg_vec_insert(pkgs_needed, pkg);
  4094. +
  4095. + pkg_vec_free(depends);
  4096. +
  4097. + return 0;
  4098. +}
  4099. +
  4100. +int name_mark_dependencies_for_installation(ipkg_conf_t *conf, const char *pkg_name, pkg_vec_t *pkgs_needed)
  4101. +{
  4102. + int cmp;
  4103. + pkg_t *old, *new;
  4104. + char *old_version, *new_version;
  4105. +
  4106. + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg_name);
  4107. +
  4108. + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, pkg_name);
  4109. + if (new == NULL) {
  4110. + return IPKG_PKG_HAS_NO_CANDIDATE;
  4111. + }
  4112. + if (old) {
  4113. + old_version = pkg_version_str_alloc(old);
  4114. + new_version = pkg_version_str_alloc(new);
  4115. +
  4116. + cmp = pkg_compare_versions(old, new);
  4117. + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
  4118. + ipkg_message(conf, IPKG_DEBUG, " Forcing downgrade ");
  4119. + cmp = -1 ; /* then we force ipkg to downgrade */
  4120. + /* We need to use a value < 0 because in the 0 case we are asking to */
  4121. + /* reinstall, and some check could fail asking the "force-reinstall" option */
  4122. + }
  4123. + ipkg_message(conf, IPKG_DEBUG,
  4124. + "comparing visible versions of pkg %s:"
  4125. + "\n\t%s is installed "
  4126. + "\n\t%s is available "
  4127. + "\n\t%d was comparison result\n",
  4128. + pkg_name, old_version, new_version, cmp);
  4129. + if (cmp == 0 && !conf->force_reinstall) {
  4130. + ipkg_message(conf, IPKG_NOTICE,
  4131. + "Package %s (%s) installed in %s is up to date.\n",
  4132. + old->name, old_version, old->dest->name);
  4133. + free(old_version);
  4134. + free(new_version);
  4135. + return 0;
  4136. + } else if (cmp > 0) {
  4137. + ipkg_message(conf, IPKG_NOTICE,
  4138. + "Not downgrading package %s on %s from %s to %s.\n",
  4139. + old->name, old->dest->name, old_version, new_version);
  4140. + free(old_version);
  4141. + free(new_version);
  4142. + return 0;
  4143. + } else if (cmp < 0) {
  4144. + new->dest = old->dest;
  4145. + old->state_want = SW_DEINSTALL;
  4146. + old->state_flag |= SF_OBSOLETE;
  4147. + }
  4148. + }
  4149. + return pkg_mark_dependencies_for_installation(conf, new, pkgs_needed);
  4150. +}
  4151. +
  4152. +
  4153. +
  4154. +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg)
  4155. +{
  4156. + int i, err;
  4157. + pkg_vec_t *depends = pkg_vec_alloc();
  4158. + pkg_t *dep;
  4159. + char **unresolved = NULL;
  4160. + int ndepends;
  4161. +
  4162. + ndepends = pkg_hash_fetch_unsatisfied_dependencies(conf,
  4163. + pkg, depends,
  4164. + &unresolved);
  4165. +
  4166. + if (unresolved) {
  4167. + ipkg_message(conf, IPKG_ERROR,
  4168. + "%s: Cannot satisfy the following dependencies for %s:\n\t",
  4169. + conf->force_depends ? "Warning" : "ERROR", pkg->name);
  4170. + while (*unresolved) {
  4171. + ipkg_message(conf, IPKG_ERROR, " %s", *unresolved);
  4172. + unresolved++;
  4173. + }
  4174. + ipkg_message(conf, IPKG_ERROR, "\n");
  4175. + if (! conf->force_depends) {
  4176. + ipkg_message(conf, IPKG_INFO,
  4177. + "This could mean that your package list is out of date or that the packages\n"
  4178. + "mentioned above do not yet exist (try 'ipkg update'). To proceed in spite\n"
  4179. + "of this problem try again with the '-force-depends' option.\n");
  4180. + pkg_vec_free(depends);
  4181. + return IPKG_PKG_DEPS_UNSATISFIED;
  4182. + }
  4183. + }
  4184. +
  4185. + if (ndepends <= 0) {
  4186. + return 0;
  4187. + }
  4188. +
  4189. + /* Mark packages as to-be-installed */
  4190. + for (i=0; i < depends->len; i++) {
  4191. + /* Dependencies should be installed the same place as pkg */
  4192. + if (depends->pkgs[i]->dest == NULL) {
  4193. + depends->pkgs[i]->dest = pkg->dest;
  4194. + }
  4195. + depends->pkgs[i]->state_want = SW_INSTALL;
  4196. + }
  4197. +
  4198. + for (i = 0; i < depends->len; i++) {
  4199. + dep = depends->pkgs[i];
  4200. + /* The package was uninstalled when we started, but another
  4201. + dep earlier in this loop may have depended on it and pulled
  4202. + it in, so check first. */
  4203. + if ((dep->state_status != SS_INSTALLED)
  4204. + && (dep->state_status != SS_UNPACKED)) {
  4205. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
  4206. + err = ipkg_install_pkg(conf, dep,0);
  4207. + if (err) {
  4208. + pkg_vec_free(depends);
  4209. + return err;
  4210. + }
  4211. + }
  4212. + }
  4213. +
  4214. + pkg_vec_free(depends);
  4215. +
  4216. + return 0;
  4217. +}
  4218. +
  4219. +
  4220. +/* check all packages have their dependences satisfied, e.g., in case an upgraded package split */
  4221. +int ipkg_satisfy_all_dependences(ipkg_conf_t *conf)
  4222. +{
  4223. + if (conf->nodeps == 0) {
  4224. + int i;
  4225. + pkg_vec_t *installed = pkg_vec_alloc();
  4226. + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
  4227. + for (i = 0; i < installed->len; i++) {
  4228. + pkg_t *pkg = installed->pkgs[i];
  4229. + satisfy_dependencies_for(conf, pkg);
  4230. + }
  4231. + pkg_vec_free(installed);
  4232. + }
  4233. + return 0;
  4234. +}
  4235. +
  4236. +
  4237. +
  4238. +static int check_conflicts_for(ipkg_conf_t *conf, pkg_t *pkg)
  4239. +{
  4240. + int i;
  4241. + pkg_vec_t *conflicts = NULL;
  4242. + int level;
  4243. + const char *prefix;
  4244. + if (conf->force_depends) {
  4245. + level = IPKG_NOTICE;
  4246. + prefix = "Warning";
  4247. + } else {
  4248. + level = IPKG_ERROR;
  4249. + prefix = "ERROR";
  4250. + }
  4251. +
  4252. + if (!conf->force_depends)
  4253. + conflicts = (pkg_vec_t *)pkg_hash_fetch_conflicts(pkg);
  4254. +
  4255. + if (conflicts) {
  4256. + ipkg_message(conf, level,
  4257. + "%s: The following packages conflict with %s:\n\t", prefix, pkg->name);
  4258. + i = 0;
  4259. + while (i < conflicts->len)
  4260. + ipkg_message(conf, level, " %s", conflicts->pkgs[i++]->name);
  4261. + ipkg_message(conf, level, "\n");
  4262. + pkg_vec_free(conflicts);
  4263. + return IPKG_PKG_DEPS_UNSATISFIED;
  4264. + }
  4265. + return 0;
  4266. +}
  4267. +
  4268. +static int update_file_ownership(ipkg_conf_t *conf, pkg_t *new_pkg, pkg_t *old_pkg)
  4269. +{
  4270. + str_list_t *new_list = pkg_get_installed_files(new_pkg);
  4271. + str_list_elt_t *iter;
  4272. +
  4273. + for (iter = new_list->head; iter; iter = iter->next) {
  4274. + char *new_file = iter->data;
  4275. + pkg_t *owner = file_hash_get_file_owner(conf, new_file);
  4276. + if (!new_file)
  4277. + ipkg_message(conf, IPKG_ERROR, "Null new_file for new_pkg=%s\n", new_pkg->name);
  4278. + if (!owner || (owner == old_pkg))
  4279. + file_hash_set_file_owner(conf, new_file, new_pkg);
  4280. + }
  4281. + if (old_pkg) {
  4282. + str_list_t *old_list = pkg_get_installed_files(old_pkg);
  4283. + for (iter = old_list->head; iter; iter = iter->next) {
  4284. + char *old_file = iter->data;
  4285. + pkg_t *owner = file_hash_get_file_owner(conf, old_file);
  4286. + if (owner == old_pkg) {
  4287. + /* obsolete */
  4288. + hash_table_insert(&conf->obs_file_hash, old_file, old_pkg);
  4289. + }
  4290. + }
  4291. + }
  4292. + return 0;
  4293. +}
  4294. +
  4295. +static int verify_pkg_installable(ipkg_conf_t *conf, pkg_t *pkg)
  4296. +{
  4297. + /* XXX: FEATURE: Anything else needed here? Maybe a check on free space? */
  4298. +
  4299. + /* sma 6.20.02: yup; here's the first bit */
  4300. + /*
  4301. + * XXX: BUG easy for cworth
  4302. + * 1) please point the call below to the correct current root destination
  4303. + * 2) we need to resolve how to check the required space for a pending pkg,
  4304. + * my diddling with the .ipk file size below isn't going to cut it.
  4305. + * 3) return a proper error code instead of 1
  4306. + */
  4307. + int comp_size, blocks_available;
  4308. +
  4309. + if (!conf->force_space && pkg->installed_size != NULL) {
  4310. + blocks_available = get_available_blocks(conf->default_dest->root_dir);
  4311. +
  4312. + comp_size = strtoul(pkg->installed_size, NULL, 0);
  4313. + /* round up a blocks count without doing fancy-but-slow casting jazz */
  4314. + comp_size = (int)((comp_size + 1023) / 1024);
  4315. +
  4316. + if (comp_size >= blocks_available) {
  4317. + ipkg_message(conf, IPKG_ERROR,
  4318. + "Only have %d available blocks on filesystem %s, pkg %s needs %d\n",
  4319. + blocks_available, conf->default_dest->root_dir, pkg->name, comp_size);
  4320. + return ENOSPC;
  4321. + }
  4322. + }
  4323. + return 0;
  4324. +}
  4325. +
  4326. +static int unpack_pkg_control_files(ipkg_conf_t *conf, pkg_t *pkg)
  4327. +{
  4328. + int err;
  4329. + char *conffiles_file_name;
  4330. + char *root_dir;
  4331. + FILE *conffiles_file;
  4332. +
  4333. + sprintf_alloc(&pkg->tmp_unpack_dir, "%s/%s-XXXXXX", conf->tmp_dir, pkg->name);
  4334. +
  4335. + pkg->tmp_unpack_dir = mkdtemp(pkg->tmp_unpack_dir);
  4336. + if (pkg->tmp_unpack_dir == NULL) {
  4337. + ipkg_message(conf, IPKG_ERROR,
  4338. + "%s: Failed to create temporary directory '%s': %s\n",
  4339. + __FUNCTION__, pkg->tmp_unpack_dir, strerror(errno));
  4340. + return errno;
  4341. + }
  4342. +
  4343. + err = pkg_extract_control_files_to_dir(pkg, pkg->tmp_unpack_dir);
  4344. + if (err) {
  4345. + return err;
  4346. + }
  4347. +
  4348. + /* XXX: CLEANUP: There might be a cleaner place to read in the
  4349. + conffiles. Seems like I should be able to get everything to go
  4350. + through pkg_init_from_file. If so, maybe it would make sense to
  4351. + move all of unpack_pkg_control_files to that function. */
  4352. +
  4353. + /* Don't need to re-read conffiles if we already have it */
  4354. + if (pkg->conffiles.head) {
  4355. + return 0;
  4356. + }
  4357. +
  4358. + sprintf_alloc(&conffiles_file_name, "%s/conffiles", pkg->tmp_unpack_dir);
  4359. + if (! file_exists(conffiles_file_name)) {
  4360. + free(conffiles_file_name);
  4361. + return 0;
  4362. + }
  4363. +
  4364. + conffiles_file = fopen(conffiles_file_name, "r");
  4365. + if (conffiles_file == NULL) {
  4366. + fprintf(stderr, "%s: failed to open %s: %s\n",
  4367. + __FUNCTION__, conffiles_file_name, strerror(errno));
  4368. + free(conffiles_file_name);
  4369. + return errno;
  4370. + }
  4371. + free(conffiles_file_name);
  4372. +
  4373. + while (1) {
  4374. + char *cf_name;
  4375. + char *cf_name_in_dest;
  4376. +
  4377. + cf_name = file_read_line_alloc(conffiles_file);
  4378. + if (cf_name == NULL) {
  4379. + break;
  4380. + }
  4381. + str_chomp(cf_name);
  4382. + if (cf_name[0] == '\0') {
  4383. + continue;
  4384. + }
  4385. +
  4386. + /* Prepend dest->root_dir to conffile name.
  4387. + Take pains to avoid multiple slashes. */
  4388. + root_dir = pkg->dest->root_dir;
  4389. + if (conf->offline_root)
  4390. + /* skip the offline_root prefix */
  4391. + root_dir = pkg->dest->root_dir + strlen(conf->offline_root);
  4392. + sprintf_alloc(&cf_name_in_dest, "%s%s", root_dir,
  4393. + cf_name[0] == '/' ? (cf_name + 1) : cf_name);
  4394. +
  4395. + /* Can't get an md5sum now, (file isn't extracted yet).
  4396. + We'll wait until resolve_conffiles */
  4397. + conffile_list_append(&pkg->conffiles, cf_name_in_dest, NULL);
  4398. +
  4399. + free(cf_name);
  4400. + free(cf_name_in_dest);
  4401. + }
  4402. +
  4403. + fclose(conffiles_file);
  4404. +
  4405. + return 0;
  4406. +}
  4407. +
  4408. +/* returns number of installed replacees */
  4409. +int pkg_get_installed_replacees(pkg_t *pkg, pkg_vec_t *installed_replacees)
  4410. +{
  4411. + abstract_pkg_t **replaces = pkg->replaces;
  4412. + int replaces_count = pkg->replaces_count;
  4413. + int i, j;
  4414. + for (i = 0; i < replaces_count; i++) {
  4415. + abstract_pkg_t *ab_pkg = replaces[i];
  4416. + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
  4417. + if (pkg_vec) {
  4418. + for (j = 0; j < pkg_vec->len; j++) {
  4419. + pkg_t *replacee = pkg_vec->pkgs[j];
  4420. + if (!pkg_conflicts(pkg, replacee))
  4421. + continue;
  4422. + if (replacee->state_status == SS_INSTALLED) {
  4423. + pkg_vec_insert(installed_replacees, replacee);
  4424. + }
  4425. + }
  4426. + }
  4427. + }
  4428. + return installed_replacees->len;
  4429. +}
  4430. +
  4431. +int pkg_remove_installed_replacees(ipkg_conf_t *conf, pkg_vec_t *replacees)
  4432. +{
  4433. + int i;
  4434. + int replaces_count = replacees->len;
  4435. + for (i = 0; i < replaces_count; i++) {
  4436. + pkg_t *replacee = replacees->pkgs[i];
  4437. + int err;
  4438. + replacee->state_flag |= SF_REPLACE; /* flag it so remove won't complain */
  4439. + err = ipkg_remove_pkg(conf, replacee,0);
  4440. + if (err)
  4441. + return err;
  4442. + }
  4443. + return 0;
  4444. +}
  4445. +
  4446. +/* to unwind the removal: make sure they are installed */
  4447. +int pkg_remove_installed_replacees_unwind(ipkg_conf_t *conf, pkg_vec_t *replacees)
  4448. +{
  4449. + int i, err;
  4450. + int replaces_count = replacees->len;
  4451. + for (i = 0; i < replaces_count; i++) {
  4452. + pkg_t *replacee = replacees->pkgs[i];
  4453. + if (replacee->state_status != SS_INSTALLED) {
  4454. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
  4455. + err = ipkg_install_pkg(conf, replacee,0);
  4456. + if (err)
  4457. + return err;
  4458. + }
  4459. + }
  4460. + return 0;
  4461. +}
  4462. +
  4463. +int caught_sigint = 0;
  4464. +static void ipkg_install_pkg_sigint_handler(int sig)
  4465. +{
  4466. + caught_sigint = sig;
  4467. +}
  4468. +
  4469. +/* compares versions of pkg and old_pkg, returns 0 if OK to proceed with installation of pkg, 1 otherwise */
  4470. +static int ipkg_install_check_downgrade(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg, int message)
  4471. +{
  4472. + if (old_pkg) {
  4473. + char message_out[15];
  4474. + char *old_version = pkg_version_str_alloc(old_pkg);
  4475. + char *new_version = pkg_version_str_alloc(pkg);
  4476. + int cmp = pkg_compare_versions(old_pkg, pkg);
  4477. + int rc = 0;
  4478. +
  4479. + memset(message_out,'\x0',15);
  4480. + strncpy (message_out,"Upgrading ",strlen("Upgrading "));
  4481. + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
  4482. + cmp = -1 ; /* then we force ipkg to downgrade */
  4483. + strncpy (message_out,"Downgrading ",strlen("Downgrading ")); /* We need to use a value < 0 because in the 0 case we are asking to */
  4484. + /* reinstall, and some check could fail asking the "force-reinstall" option */
  4485. + }
  4486. +
  4487. + if (cmp > 0) {
  4488. + ipkg_message(conf, IPKG_NOTICE,
  4489. + "Not downgrading package %s on %s from %s to %s.\n",
  4490. + old_pkg->name, old_pkg->dest->name, old_version, new_version);
  4491. + rc = 1;
  4492. + } else if (cmp < 0) {
  4493. + ipkg_message(conf, IPKG_NOTICE,
  4494. + "%s%s on %s from %s to %s...\n",
  4495. + message_out, pkg->name, old_pkg->dest->name, old_version, new_version);
  4496. + pkg->dest = old_pkg->dest;
  4497. + rc = 0;
  4498. + } else /* cmp == 0 */ {
  4499. + if (conf->force_reinstall) {
  4500. + ipkg_message(conf, IPKG_NOTICE,
  4501. + "Reinstalling %s (%s) on %s...\n",
  4502. + pkg->name, new_version, old_pkg->dest->name);
  4503. + pkg->dest = old_pkg->dest;
  4504. + rc = 0;
  4505. + } else {
  4506. + ipkg_message(conf, IPKG_NOTICE,
  4507. + "Not installing %s (%s) on %s -- already installed.\n",
  4508. + pkg->name, new_version, old_pkg->dest->name);
  4509. + rc = 1;
  4510. + }
  4511. + }
  4512. + free(old_version);
  4513. + free(new_version);
  4514. + return rc;
  4515. + } else {
  4516. + char message_out[15], *version ;
  4517. + memset(message_out,'\x0',15);
  4518. + if ( message )
  4519. + strncpy( message_out,"Upgrading ",strlen("Upgrading ") );
  4520. + else
  4521. + strncpy( message_out,"Installing ",strlen("Installing ") );
  4522. + version = pkg_version_str_alloc(pkg);
  4523. +
  4524. + ipkg_message(conf, IPKG_NOTICE,
  4525. + "%s%s (%s) to %s...\n", message_out,
  4526. + pkg->name, version, pkg->dest->name);
  4527. + free(version);
  4528. + return 0;
  4529. + }
  4530. +}
  4531. +
  4532. +/* and now the meat... */
  4533. +int ipkg_install_pkg(ipkg_conf_t *conf, pkg_t *pkg, int from_upgrade)
  4534. +{
  4535. + int err = 0;
  4536. + int message = 0;
  4537. + pkg_t *old_pkg = NULL;
  4538. + pkg_vec_t *replacees;
  4539. + abstract_pkg_t *ab_pkg = NULL;
  4540. + int old_state_flag;
  4541. + uint8_t *file_md5;
  4542. +
  4543. +
  4544. + if ( from_upgrade )
  4545. + message = 1; /* Coming from an upgrade, and should change the output message */
  4546. +
  4547. + if (!pkg) {
  4548. + ipkg_message(conf, IPKG_ERROR,
  4549. + "INTERNAL ERROR: null pkg passed to ipkg_install_pkg\n");
  4550. + return -EINVAL;
  4551. + }
  4552. +
  4553. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s calling pkg_arch_supported %s \n", __FUNCTION__, __FUNCTION__);
  4554. +
  4555. + if (!pkg_arch_supported(conf, pkg)) {
  4556. + ipkg_message(conf, IPKG_ERROR, "INTERNAL ERROR: architecture %s for pkg %s is unsupported.\n",
  4557. + pkg->architecture, pkg->name);
  4558. + return -EINVAL;
  4559. + }
  4560. + if (pkg->state_status == SS_INSTALLED && conf->force_reinstall == 0 && conf->nodeps == 0) {
  4561. + err = satisfy_dependencies_for(conf, pkg);
  4562. + if (err) { return err; }
  4563. +
  4564. + ipkg_message(conf, IPKG_NOTICE,
  4565. + "Package %s is already installed in %s.\n",
  4566. + pkg->name, pkg->dest->name);
  4567. + return 0;
  4568. + }
  4569. +
  4570. + if (pkg->dest == NULL) {
  4571. + pkg->dest = conf->default_dest;
  4572. + }
  4573. +
  4574. + old_pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name);
  4575. +
  4576. + err = ipkg_install_check_downgrade(conf, pkg, old_pkg, message);
  4577. + if (err) { return err; }
  4578. +
  4579. + pkg->state_want = SW_INSTALL;
  4580. + if (old_pkg){
  4581. + old_pkg->state_want = SW_DEINSTALL; /* needed for check_data_file_clashes of dependences */
  4582. + }
  4583. +
  4584. +
  4585. + /* Abhaya: conflicts check */
  4586. + err = check_conflicts_for(conf, pkg);
  4587. + if (err) { return err; }
  4588. +
  4589. + /* this setup is to remove the upgrade scenario in the end when
  4590. + installing pkg A, A deps B & B deps on A. So both B and A are
  4591. + installed. Then A's installation is started resulting in an
  4592. + uncecessary upgrade */
  4593. + if (pkg->state_status == SS_INSTALLED
  4594. + && conf->force_reinstall == 0) return 0;
  4595. +
  4596. + err = verify_pkg_installable(conf, pkg);
  4597. + if (err) { return err; }
  4598. +
  4599. + if (pkg->local_filename == NULL) {
  4600. + err = ipkg_download_pkg(conf, pkg, conf->tmp_dir);
  4601. + if (err) {
  4602. + ipkg_message(conf, IPKG_ERROR,
  4603. + "Failed to download %s. Perhaps you need to run 'ipkg update'?\n",
  4604. + pkg->name);
  4605. + return err;
  4606. + }
  4607. + }
  4608. +
  4609. +/* Check for md5 values */
  4610. + if (pkg->md5sum)
  4611. + {
  4612. + file_md5 = file_md5sum_alloc(pkg->local_filename);
  4613. + if (strcmp((char *)file_md5, pkg->md5sum))
  4614. + {
  4615. + ipkg_message(conf, IPKG_ERROR,
  4616. + "Package %s md5sum mismatch. Either the ipkg or the package index are corrupt. Try 'ipkg update'.\n",
  4617. + pkg->name);
  4618. + free(file_md5);
  4619. + return err;
  4620. + }
  4621. + free(file_md5);
  4622. + }
  4623. +
  4624. + if (pkg->tmp_unpack_dir == NULL) {
  4625. + unpack_pkg_control_files(conf, pkg);
  4626. + }
  4627. +
  4628. + /* We should update the filelist here, so that upgrades of packages that split will not fail. -Jamey 27-MAR-03 */
  4629. +/* Pigi: check if it will pass from here when replacing. It seems to fail */
  4630. +/* That's rather strange that files don't change owner. Investigate !!!!!!*/
  4631. + err = update_file_ownership(conf, pkg, old_pkg);
  4632. + if (err) { return err; }
  4633. +
  4634. + if (conf->nodeps == 0) {
  4635. + err = satisfy_dependencies_for(conf, pkg);
  4636. + if (err) { return err; }
  4637. + }
  4638. +
  4639. + replacees = pkg_vec_alloc();
  4640. + pkg_get_installed_replacees(pkg, replacees);
  4641. +
  4642. + /* this next section we do with SIGINT blocked to prevent inconsistency between ipkg database and filesystem */
  4643. + {
  4644. + sigset_t newset, oldset;
  4645. + sighandler_t old_handler = NULL;
  4646. + int use_signal = 0;
  4647. + caught_sigint = 0;
  4648. + if (use_signal) {
  4649. + old_handler = signal(SIGINT, ipkg_install_pkg_sigint_handler);
  4650. + } else {
  4651. + sigemptyset(&newset);
  4652. + sigaddset(&newset, SIGINT);
  4653. + sigprocmask(SIG_BLOCK, &newset, &oldset);
  4654. + }
  4655. +
  4656. + ipkg_state_changed++;
  4657. + pkg->state_flag |= SF_FILELIST_CHANGED;
  4658. +
  4659. + /* XXX: BUG: we really should treat replacement more like an upgrade
  4660. + * Instead, we're going to remove the replacees
  4661. + */
  4662. + err = pkg_remove_installed_replacees(conf, replacees);
  4663. + if (err) goto UNWIND_REMOVE_INSTALLED_REPLACEES;
  4664. +
  4665. + /*
  4666. + err = prerm_upgrade_old_pkg(conf, pkg, old_pkg);
  4667. + if (err) goto UNWIND_PRERM_UPGRADE_OLD_PKG;
  4668. +
  4669. + err = prerm_deconfigure_conflictors(conf, pkg, replacees);
  4670. + if (err) goto UNWIND_PRERM_DECONFIGURE_CONFLICTORS;
  4671. + */
  4672. +
  4673. + err = preinst_configure(conf, pkg, old_pkg);
  4674. + /*
  4675. + if (err) goto UNWIND_PREINST_CONFIGURE;
  4676. + */
  4677. +
  4678. + err = backup_modified_conffiles(conf, pkg, old_pkg);
  4679. + if (err) goto UNWIND_BACKUP_MODIFIED_CONFFILES;
  4680. +
  4681. + err = check_data_file_clashes(conf, pkg, old_pkg);
  4682. + /*
  4683. + if (err) goto UNWIND_CHECK_DATA_FILE_CLASHES;
  4684. +
  4685. + err = postrm_upgrade_old_pkg(conf, pkg, old_pkg);
  4686. + if (err) goto UNWIND_POSTRM_UPGRADE_OLD_PKG;
  4687. + */
  4688. +
  4689. + if (conf->noaction) return 0;
  4690. +
  4691. + /* point of no return: no unwinding after this */
  4692. + if (old_pkg && !conf->force_reinstall) {
  4693. + old_pkg->state_want = SW_DEINSTALL;
  4694. +
  4695. + if (old_pkg->state_flag & SF_NOPRUNE) {
  4696. + ipkg_message(conf, IPKG_INFO,
  4697. + " not removing obsolesced files because package marked noprune\n");
  4698. + } else {
  4699. + ipkg_message(conf, IPKG_INFO,
  4700. + " removing obsolesced files\n");
  4701. + remove_obsolesced_files(conf, pkg, old_pkg);
  4702. + }
  4703. + /* removing files from old package, to avoid ghost files */
  4704. + remove_data_files_and_list(conf, old_pkg);
  4705. +/* Pigi : It should be better to remove also maintainer and postrem scripts here, just in case*/
  4706. + remove_maintainer_scripts_except_postrm(conf, old_pkg);
  4707. + remove_postrm(conf, old_pkg);
  4708. +/* Pigi */
  4709. +
  4710. + }
  4711. +
  4712. +
  4713. + ipkg_message(conf, IPKG_INFO,
  4714. + " installing maintainer scripts\n");
  4715. + install_maintainer_scripts(conf, pkg, old_pkg);
  4716. +
  4717. + /* the following just returns 0
  4718. + remove_disappeared(conf, pkg);
  4719. + */
  4720. +
  4721. + ipkg_message(conf, IPKG_INFO,
  4722. + " installing data files\n");
  4723. + install_data_files(conf, pkg);
  4724. +
  4725. +/* read comments from function for detail but I will execute this here as all other tests are ok.*/
  4726. + err = check_data_file_clashes_change(conf, pkg);
  4727. +
  4728. + ipkg_message(conf, IPKG_INFO,
  4729. + " resolving conf files\n");
  4730. + resolve_conffiles(conf, pkg);
  4731. +
  4732. + pkg->state_status = SS_UNPACKED;
  4733. + old_state_flag = pkg->state_flag;
  4734. + pkg->state_flag &= ~SF_PREFER;
  4735. + ipkg_message(conf, IPKG_DEBUG, " pkg=%s old_state_flag=%x state_flag=%x\n", pkg->name, old_state_flag, pkg->state_flag);
  4736. +
  4737. + if (old_pkg && !conf->force_reinstall) {
  4738. + old_pkg->state_status = SS_NOT_INSTALLED;
  4739. + }
  4740. +
  4741. + time(&pkg->installed_time);
  4742. +
  4743. + ipkg_message(conf, IPKG_INFO,
  4744. + " cleanup temp files\n");
  4745. + cleanup_temporary_files(conf, pkg);
  4746. +
  4747. + ab_pkg = pkg->parent;
  4748. + if (ab_pkg)
  4749. + ab_pkg->state_status = pkg->state_status;
  4750. +
  4751. + ipkg_message(conf, IPKG_INFO, "Done.\n");
  4752. +
  4753. + if (use_signal)
  4754. + signal(SIGINT, old_handler);
  4755. + else
  4756. + sigprocmask(SIG_UNBLOCK, &newset, &oldset);
  4757. +
  4758. + return 0;
  4759. +
  4760. +
  4761. + /*
  4762. + UNWIND_POSTRM_UPGRADE_OLD_PKG:
  4763. + postrm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
  4764. + UNWIND_CHECK_DATA_FILE_CLASHES:
  4765. + check_data_file_clashes_unwind(conf, pkg, old_pkg);
  4766. + */
  4767. + UNWIND_BACKUP_MODIFIED_CONFFILES:
  4768. + backup_modified_conffiles_unwind(pkg, old_pkg);
  4769. + /*
  4770. + UNWIND_PREINST_CONFIGURE:
  4771. + preinst_configure_unwind(conf, pkg, old_pkg);
  4772. + UNWIND_PRERM_DECONFIGURE_CONFLICTORS:
  4773. + prerm_deconfigure_conflictors_unwind(conf, pkg, replacees);
  4774. + UNWIND_PRERM_UPGRADE_OLD_PKG:
  4775. + prerm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
  4776. + */
  4777. + UNWIND_REMOVE_INSTALLED_REPLACEES:
  4778. + pkg_remove_installed_replacees_unwind(conf, replacees);
  4779. +
  4780. + ipkg_message(conf, IPKG_INFO,
  4781. + " cleanup temp files\n");
  4782. + cleanup_temporary_files(conf, pkg);
  4783. +
  4784. + ipkg_message(conf, IPKG_INFO,
  4785. + "Failed.\n");
  4786. + if (use_signal)
  4787. + signal(SIGINT, old_handler);
  4788. + else
  4789. + sigprocmask(SIG_UNBLOCK, &newset, &oldset);
  4790. +
  4791. + return err;
  4792. + }
  4793. +}
  4794. +
  4795. +/*
  4796. +static int prerm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4797. +{
  4798. + DPKG_INCOMPATIBILITY:
  4799. + dpkg does some things here that we don't do yet. Do we care?
  4800. +
  4801. + 1. If a version of the package is already installed, call
  4802. + old-prerm upgrade new-version
  4803. + 2. If the script runs but exits with a non-zero exit status
  4804. + new-prerm failed-upgrade old-version
  4805. + Error unwind, for both the above cases:
  4806. + old-postinst abort-upgrade new-version
  4807. + return 0;
  4808. +}
  4809. +*/
  4810. +
  4811. +/*
  4812. +static int prerm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4813. +{
  4814. + DPKG_INCOMPATIBILITY:
  4815. + dpkg does some things here that we don't do yet. Do we care?
  4816. + (See prerm_upgrade_old_package for details)
  4817. +
  4818. + return 0;
  4819. +}
  4820. +*/
  4821. +
  4822. +/*
  4823. +static int prerm_deconfigure_conflictors(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors)
  4824. +{
  4825. + DPKG_INCOMPATIBILITY:
  4826. + dpkg does some things here that we don't do yet. Do we care?
  4827. + 2. If a 'conflicting' package is being removed at the same time:
  4828. + 1. If any packages depended on that conflicting package and
  4829. + --auto-deconfigure is specified, call, for each such package:
  4830. + deconfigured's-prerm deconfigure \
  4831. + in-favour package-being-installed version \
  4832. + removing conflicting-package version
  4833. + Error unwind:
  4834. + deconfigured's-postinst abort-deconfigure \
  4835. + in-favour package-being-installed-but-failed version \
  4836. + removing conflicting-package version
  4837. +
  4838. + The deconfigured packages are marked as requiring
  4839. + configuration, so that if --install is used they will be
  4840. + configured again if possible.
  4841. + 2. To prepare for removal of the conflicting package, call:
  4842. + conflictor's-prerm remove in-favour package new-version
  4843. + Error unwind:
  4844. + conflictor's-postinst abort-remove in-favour package new-version
  4845. + return 0;
  4846. +}
  4847. +*/
  4848. +
  4849. +/*
  4850. +static int prerm_deconfigure_conflictors_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors)
  4851. +{
  4852. + DPKG_INCOMPATIBILITY: dpkg does some things here that we don't
  4853. + do yet. Do we care? (See prerm_deconfigure_conflictors for
  4854. + details)
  4855. + return 0;
  4856. +}
  4857. +*/
  4858. +
  4859. +static int preinst_configure(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4860. +{
  4861. + int err;
  4862. + char *preinst_args;
  4863. +
  4864. + if (old_pkg) {
  4865. + char *old_version = pkg_version_str_alloc(old_pkg);
  4866. + sprintf_alloc(&preinst_args, "upgrade %s", old_version);
  4867. + free(old_version);
  4868. + } else if (pkg->state_status == SS_CONFIG_FILES) {
  4869. + char *pkg_version = pkg_version_str_alloc(pkg);
  4870. + sprintf_alloc(&preinst_args, "install %s", pkg_version);
  4871. + free(pkg_version);
  4872. + } else {
  4873. + preinst_args = strdup("install");
  4874. + }
  4875. +
  4876. + err = pkg_run_script(conf, pkg, "preinst", preinst_args);
  4877. + if (err) {
  4878. + ipkg_message(conf, IPKG_ERROR,
  4879. + "Aborting installation of %s\n", pkg->name);
  4880. + return 1;
  4881. + }
  4882. +
  4883. + free(preinst_args);
  4884. +
  4885. + return 0;
  4886. +}
  4887. +
  4888. +/*
  4889. +static int preinst_configure_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4890. +{
  4891. + DPKG_INCOMPATIBILITY:
  4892. + dpkg does the following error unwind, should we?
  4893. + pkg->postrm abort-upgrade old-version
  4894. + OR pkg->postrm abort-install old-version
  4895. + OR pkg->postrm abort-install
  4896. + return 0;
  4897. +}
  4898. +*/
  4899. +
  4900. +static int backup_modified_conffiles(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4901. +{
  4902. + int err;
  4903. + conffile_list_elt_t *iter;
  4904. + conffile_t *cf;
  4905. +
  4906. + if (conf->noaction) return 0;
  4907. +
  4908. + /* Backup all modified conffiles */
  4909. + if (old_pkg) {
  4910. + for (iter = old_pkg->conffiles.head; iter; iter = iter->next) {
  4911. + char *cf_name;
  4912. +
  4913. + cf = iter->data;
  4914. + cf_name = root_filename_alloc(conf, cf->name);
  4915. +
  4916. + /* Don't worry if the conffile is just plain gone */
  4917. + if (file_exists(cf_name) && conffile_has_been_modified(conf, cf)) {
  4918. + err = backup_make_backup(conf, cf_name);
  4919. + if (err) {
  4920. + return err;
  4921. + }
  4922. + }
  4923. + free(cf_name);
  4924. + }
  4925. + }
  4926. +
  4927. + /* Backup all conffiles that were not conffiles in old_pkg */
  4928. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  4929. + char *cf_name;
  4930. + cf = iter->data;
  4931. + cf_name = root_filename_alloc(conf, cf->name);
  4932. + /* Ignore if this was a conffile in old_pkg as well */
  4933. + if (pkg_get_conffile(old_pkg, cf->name)) {
  4934. + continue;
  4935. + }
  4936. +
  4937. + if (file_exists(cf_name) && (! backup_exists_for(cf_name))) {
  4938. + err = backup_make_backup(conf, cf_name);
  4939. + if (err) {
  4940. + return err;
  4941. + }
  4942. + }
  4943. + free(cf_name);
  4944. + }
  4945. +
  4946. + return 0;
  4947. +}
  4948. +
  4949. +static int backup_modified_conffiles_unwind(pkg_t *pkg, pkg_t *old_pkg)
  4950. +{
  4951. + conffile_list_elt_t *iter;
  4952. +
  4953. + if (old_pkg) {
  4954. + for (iter = old_pkg->conffiles.head; iter; iter = iter->next) {
  4955. + backup_remove(iter->data->name);
  4956. + }
  4957. + }
  4958. +
  4959. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  4960. + backup_remove(iter->data->name);
  4961. + }
  4962. +
  4963. + return 0;
  4964. +}
  4965. +
  4966. +
  4967. +static int check_data_file_clashes(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4968. +{
  4969. + /* DPKG_INCOMPATIBILITY:
  4970. + ipkg takes a slightly different approach than dpkg at this
  4971. + point. dpkg installs each file in the new package while
  4972. + creating a backup for any file that is replaced, (so that it
  4973. + can unwind if necessary). To avoid complexity and redundant
  4974. + storage, ipkg doesn't do any installation until later, (at the
  4975. + point at which dpkg removes the backups.
  4976. +
  4977. + But, we do have to check for data file clashes, since after
  4978. + installing a package with a file clash, removing either of the
  4979. + packages involved in the clash has the potential to break the
  4980. + other package.
  4981. + */
  4982. + str_list_t *files_list;
  4983. + str_list_elt_t *iter;
  4984. +
  4985. + int clashes = 0;
  4986. +
  4987. + files_list = pkg_get_installed_files(pkg);
  4988. + for (iter = files_list->head; iter; iter = iter->next) {
  4989. + char *root_filename;
  4990. + char *filename = iter->data;
  4991. + root_filename = root_filename_alloc(conf, filename);
  4992. + if (file_exists(root_filename) && (! file_is_dir(root_filename))) {
  4993. + pkg_t *owner;
  4994. + pkg_t *obs;
  4995. + /* Pre-existing conffiles are OK */
  4996. + /* @@@@ should have way to check that it is a conffile -Jamey */
  4997. + if (backup_exists_for(root_filename)) {
  4998. + continue;
  4999. + }
  5000. +
  5001. + /* Pre-existing files are OK if force-overwrite was asserted. */
  5002. + if (conf->force_overwrite) {
  5003. + /* but we need to change who owns this file */
  5004. + file_hash_set_file_owner(conf, filename, pkg);
  5005. + continue;
  5006. + }
  5007. +
  5008. + owner = file_hash_get_file_owner(conf, filename);
  5009. +
  5010. + /* Pre-existing files are OK if owned by the pkg being upgraded. */
  5011. + if (owner && old_pkg) {
  5012. + if (strcmp(owner->name, old_pkg->name) == 0) {
  5013. + continue;
  5014. + }
  5015. + }
  5016. +
  5017. + /* Pre-existing files are OK if owned by a package replaced by new pkg. */
  5018. + if (owner) {
  5019. + ipkg_message(conf, IPKG_DEBUG2, "Checking for replaces for %s in package %s\n", filename, owner->name);
  5020. + if (pkg_replaces(pkg, owner)) {
  5021. + continue;
  5022. + }
  5023. +/* If the file that would be installed is owned by the same package, ( as per a reinstall or similar )
  5024. + then it's ok to overwrite. */
  5025. + if (strcmp(owner->name,pkg->name)==0){
  5026. + ipkg_message(conf, IPKG_INFO, "Replacing pre-existing file %s owned by package %s\n", filename, owner->name);
  5027. + continue;
  5028. + }
  5029. + }
  5030. +
  5031. + /* Pre-existing files are OK if they are obsolete */
  5032. + obs = hash_table_get(&conf->obs_file_hash, filename);
  5033. + if (obs) {
  5034. + ipkg_message(conf, IPKG_INFO, "Pre-exiting file %s is obsolete. obs_pkg=%s\n", filename, obs->name);
  5035. + continue;
  5036. + }
  5037. +
  5038. + /* We have found a clash. */
  5039. + ipkg_message(conf, IPKG_ERROR,
  5040. + "Package %s wants to install file %s\n"
  5041. + "\tBut that file is already provided by package ",
  5042. + pkg->name, filename);
  5043. + if (owner) {
  5044. + ipkg_message(conf, IPKG_ERROR,
  5045. + "%s\n", owner->name);
  5046. + } else {
  5047. + ipkg_message(conf, IPKG_ERROR,
  5048. + "<no package>\nPlease move this file out of the way and try again.\n");
  5049. + }
  5050. + clashes++;
  5051. + }
  5052. + free(root_filename);
  5053. + }
  5054. + pkg_free_installed_files(pkg);
  5055. +
  5056. + return clashes;
  5057. +}
  5058. +
  5059. +static int check_data_file_clashes_change(ipkg_conf_t *conf, pkg_t *pkg)
  5060. +{
  5061. + /* Basically that's the worst hack I could do to be able to change ownership of
  5062. + file list, but, being that we have no way to unwind the mods, due to structure
  5063. + of hash table, probably is the quickest hack too, whishing it would not slow-up thing too much.
  5064. + What we do here is change the ownership of file in hash if a replace ( or similar events
  5065. + happens )
  5066. + Only the action that are needed to change name should be considered.
  5067. + @@@ To change after 1.0 release.
  5068. + */
  5069. + str_list_t *files_list;
  5070. + str_list_elt_t *iter;
  5071. +
  5072. + int clashes = 0;
  5073. +
  5074. + files_list = pkg_get_installed_files(pkg);
  5075. + for (iter = files_list->head; iter; iter = iter->next) {
  5076. + char *root_filename;
  5077. + char *filename = iter->data;
  5078. + root_filename = root_filename_alloc(conf, filename);
  5079. + if (file_exists(root_filename) && (! file_is_dir(root_filename))) {
  5080. + pkg_t *owner;
  5081. +
  5082. + if (conf->force_overwrite) {
  5083. + /* but we need to change who owns this file */
  5084. + file_hash_set_file_owner(conf, filename, pkg);
  5085. + continue;
  5086. + }
  5087. +
  5088. + owner = file_hash_get_file_owner(conf, filename);
  5089. +
  5090. + /* Pre-existing files are OK if owned by a package replaced by new pkg. */
  5091. + if (owner) {
  5092. + if (pkg_replaces(pkg, owner)) {
  5093. +/* It's now time to change the owner of that file.
  5094. + It has been "replaced" from the new "Replaces", then I need to inform lists file about that. */
  5095. + ipkg_message(conf, IPKG_INFO, "Replacing pre-existing file %s owned by package %s\n", filename, owner->name);
  5096. + file_hash_set_file_owner(conf, filename, pkg);
  5097. + continue;
  5098. + }
  5099. + }
  5100. +
  5101. + }
  5102. + free(root_filename);
  5103. + }
  5104. + pkg_free_installed_files(pkg);
  5105. +
  5106. + return clashes;
  5107. +}
  5108. +
  5109. +/*
  5110. +static int check_data_file_clashes_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5111. +{
  5112. + Nothing to do since check_data_file_clashes doesn't change state
  5113. + return 0;
  5114. +}
  5115. +*/
  5116. +
  5117. +/*
  5118. +static int postrm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5119. +{
  5120. + DPKG_INCOMPATIBILITY: dpkg does the following here, should we?
  5121. + 1. If the package is being upgraded, call
  5122. + old-postrm upgrade new-version
  5123. + 2. If this fails, attempt:
  5124. + new-postrm failed-upgrade old-version
  5125. + Error unwind, for both cases:
  5126. + old-preinst abort-upgrade new-version
  5127. + return 0;
  5128. +}
  5129. +*/
  5130. +
  5131. +/*
  5132. +static int postrm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5133. +{
  5134. + DPKG_INCOMPATIBILITY:
  5135. + dpkg does some things here that we don't do yet. Do we care?
  5136. + (See postrm_upgrade_old_pkg for details)
  5137. + return 0;
  5138. +}
  5139. +*/
  5140. +
  5141. +static int remove_obsolesced_files(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5142. +{
  5143. + int err;
  5144. + str_list_t *old_files;
  5145. + str_list_elt_t *of;
  5146. + str_list_t *new_files;
  5147. + str_list_elt_t *nf;
  5148. +
  5149. + if (old_pkg == NULL) {
  5150. + return 0;
  5151. + }
  5152. +
  5153. + old_files = pkg_get_installed_files(old_pkg);
  5154. + new_files = pkg_get_installed_files(pkg);
  5155. +
  5156. + for (of = old_files->head; of; of = of->next) {
  5157. + pkg_t *owner;
  5158. + char *old, *new;
  5159. + old = of->data;
  5160. + for (nf = new_files->head; nf; nf = nf->next) {
  5161. + new = nf->data;
  5162. + if (strcmp(old, new) == 0) {
  5163. + goto NOT_OBSOLETE;
  5164. + }
  5165. + }
  5166. + if (file_is_dir(old)) {
  5167. + continue;
  5168. + }
  5169. + owner = file_hash_get_file_owner(conf, old);
  5170. + if (owner != old_pkg) {
  5171. + /* in case obsolete file no longer belongs to old_pkg */
  5172. + continue;
  5173. + }
  5174. +
  5175. + /* old file is obsolete */
  5176. + ipkg_message(conf, IPKG_INFO,
  5177. + " removing obsolete file %s\n", old);
  5178. + if (!conf->noaction) {
  5179. + err = unlink(old);
  5180. + if (err) {
  5181. + ipkg_message(conf, IPKG_ERROR, " Warning: remove %s failed: %s\n", old,
  5182. + strerror(errno));
  5183. + }
  5184. + }
  5185. +
  5186. + NOT_OBSOLETE:
  5187. + ;
  5188. + }
  5189. +
  5190. + pkg_free_installed_files(old_pkg);
  5191. + pkg_free_installed_files(pkg);
  5192. +
  5193. + return 0;
  5194. +}
  5195. +
  5196. +static int remove_obsolete_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5197. +{
  5198. + int i;
  5199. + int err = 0;
  5200. + char *globpattern;
  5201. + glob_t globbuf;
  5202. + if (0) {
  5203. + if (!pkg->dest) {
  5204. + ipkg_message(conf, IPKG_ERROR, "%s: no dest for package %s\n", __FUNCTION__, pkg->name);
  5205. + return -1;
  5206. + }
  5207. + sprintf_alloc(&globpattern, "%s/%s.*", pkg->dest->info_dir, pkg->name);
  5208. + err = glob(globpattern, 0, NULL, &globbuf);
  5209. + free(globpattern);
  5210. + if (err) {
  5211. + return err;
  5212. + }
  5213. + /* XXXX this should perhaps only remove the ones that are not overwritten in new package. Jamey 11/11/2003 */
  5214. + for (i = 0; i < globbuf.gl_pathc; i++) {
  5215. + ipkg_message(conf, IPKG_DEBUG, "Removing control file %s from old_pkg %s\n",
  5216. + globbuf.gl_pathv[i], old_pkg->name);
  5217. + if (!conf->noaction)
  5218. + unlink(globbuf.gl_pathv[i]);
  5219. + }
  5220. + globfree(&globbuf);
  5221. + }
  5222. + return err;
  5223. +}
  5224. +
  5225. +static int install_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5226. +{
  5227. + int ret;
  5228. + char *prefix;
  5229. +
  5230. + if (old_pkg)
  5231. + remove_obsolete_maintainer_scripts(conf, pkg, old_pkg);
  5232. + sprintf_alloc(&prefix, "%s.", pkg->name);
  5233. + ret = pkg_extract_control_files_to_dir_with_prefix(pkg,
  5234. + pkg->dest->info_dir,
  5235. + prefix);
  5236. + free(prefix);
  5237. + return ret;
  5238. +}
  5239. +
  5240. +/*
  5241. +static int remove_disappeared(ipkg_conf_t *conf, pkg_t *pkg)
  5242. +{
  5243. + DPKG_INCOMPATIBILITY:
  5244. + This is a fairly sophisticated dpkg operation. Shall we
  5245. + skip it?
  5246. +
  5247. + Any packages all of whose files have been overwritten during the
  5248. + installation, and which aren't required for dependencies, are
  5249. + considered to have been removed. For each such package
  5250. + 1. disappearer's-postrm disappear overwriter overwriter-version
  5251. + 2. The package's maintainer scripts are removed
  5252. + 3. It is noted in the status database as being in a sane state,
  5253. + namely not installed (any conffiles it may have are ignored,
  5254. + rather than being removed by dpkg). Note that disappearing
  5255. + packages do not have their prerm called, because dpkg doesn't
  5256. + know in advance that the package is going to vanish.
  5257. +
  5258. +
  5259. + return 0;
  5260. +}
  5261. +*/
  5262. +
  5263. +static int install_data_files(ipkg_conf_t *conf, pkg_t *pkg)
  5264. +{
  5265. + int err;
  5266. +
  5267. + /* ipkg takes a slightly different approach to data file backups
  5268. + than dpkg. Rather than removing backups at this point, we
  5269. + actually do the data file installation now. See comments in
  5270. + check_data_file_clashes() for more details. */
  5271. +
  5272. + ipkg_message(conf, IPKG_INFO,
  5273. + " extracting data files to %s\n", pkg->dest->root_dir);
  5274. + err = pkg_extract_data_files_to_dir(pkg, pkg->dest->root_dir);
  5275. + if (err) {
  5276. + return err;
  5277. + }
  5278. +
  5279. + /* XXX: BUG or FEATURE : We are actually loosing the Essential flag,
  5280. + so we can't save ourself from removing important packages
  5281. + At this point we (should) have extracted the .control file, so it
  5282. + would be a good idea to reload the data in it, and set the Essential
  5283. + state in *pkg. From now on the Essential is back in status file and
  5284. + we can protect again.
  5285. + We should operate this way:
  5286. + fopen the file ( pkg->dest->root_dir/pkg->name.control )
  5287. + check for "Essential" in it
  5288. + set the value in pkg->essential.
  5289. + This new routine could be useful also for every other flag
  5290. + Pigi: 16/03/2004 */
  5291. + set_flags_from_control(conf, pkg) ;
  5292. +
  5293. + ipkg_message(conf, IPKG_DEBUG, " Calling pkg_write_filelist from %s\n", __FUNCTION__);
  5294. + err = pkg_write_filelist(conf, pkg);
  5295. + if (err)
  5296. + return err;
  5297. +
  5298. + /* XXX: FEATURE: ipkg should identify any files which existed
  5299. + before installation and which were overwritten, (see
  5300. + check_data_file_clashes()). What it must do is remove any such
  5301. + files from the filelist of the old package which provided the
  5302. + file. Otherwise, if the old package were removed at some point
  5303. + it would break the new package. Removing the new package will
  5304. + also break the old one, but this cannot be helped since the old
  5305. + package's file has already been deleted. This is the importance
  5306. + of check_data_file_clashes(), and only allowing ipkg to install
  5307. + a clashing package with a user force. */
  5308. +
  5309. + return 0;
  5310. +}
  5311. +
  5312. +static int resolve_conffiles(ipkg_conf_t *conf, pkg_t *pkg)
  5313. +{
  5314. + conffile_list_elt_t *iter;
  5315. + conffile_t *cf;
  5316. + char *cf_backup;
  5317. + uint8_t *md5sum;
  5318. +
  5319. +
  5320. + if (conf->noaction) return 0;
  5321. +
  5322. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  5323. + char *root_filename;
  5324. + cf = iter->data;
  5325. + root_filename = root_filename_alloc(conf, cf->name);
  5326. +
  5327. + /* Might need to initialize the md5sum for each conffile */
  5328. + if (cf->value == NULL) {
  5329. + cf->value = (char *)file_md5sum_alloc(root_filename);
  5330. + }
  5331. +
  5332. + if (!file_exists(root_filename)) {
  5333. + free(root_filename);
  5334. + continue;
  5335. + }
  5336. +
  5337. + cf_backup = backup_filename_alloc(root_filename);
  5338. +
  5339. +
  5340. + if (file_exists(cf_backup)) {
  5341. + /* Let's compute md5 to test if files are changed */
  5342. + md5sum = file_md5sum_alloc(cf_backup);
  5343. + if (strcmp( cf->value, (char *)md5sum) != 0 ) {
  5344. + if (conf->force_defaults
  5345. + || user_prefers_old_conffile(cf->name, cf_backup) ) {
  5346. + rename(cf_backup, root_filename);
  5347. + }
  5348. + }
  5349. + unlink(cf_backup);
  5350. + free(md5sum);
  5351. + }
  5352. +
  5353. + free(cf_backup);
  5354. + free(root_filename);
  5355. + }
  5356. +
  5357. + return 0;
  5358. +}
  5359. +
  5360. +static int user_prefers_old_conffile(const char *file_name, const char *backup)
  5361. +{
  5362. + char *response;
  5363. + const char *short_file_name;
  5364. +
  5365. + short_file_name = strrchr(file_name, '/');
  5366. + if (short_file_name) {
  5367. + short_file_name++;
  5368. + } else {
  5369. + short_file_name = file_name;
  5370. + }
  5371. +
  5372. + while (1) {
  5373. + response = get_user_response(" Configuration file '%s'\n"
  5374. + " ==> File on system created by you or by a script.\n"
  5375. + " ==> File also in package provided by package maintainer.\n"
  5376. + " What would you like to do about it ? Your options are:\n"
  5377. + " Y or I : install the package maintainer's version\n"
  5378. + " N or O : keep your currently-installed version\n"
  5379. +#ifdef CONFIG_DIFF
  5380. + " D : show the differences between the versions\n"
  5381. +#endif
  5382. + " The default action is to keep your current version.\n"
  5383. + " *** %s (Y/I/N/O"
  5384. +#ifdef CONFIG_DIFF
  5385. + "/D"
  5386. +#endif
  5387. + ") [default=N] ? ", file_name, short_file_name);
  5388. + if (strcmp(response, "y") == 0
  5389. + || strcmp(response, "i") == 0
  5390. + || strcmp(response, "yes") == 0) {
  5391. + free(response);
  5392. + return 0;
  5393. + }
  5394. +
  5395. +#ifdef CONFIG_DIFF
  5396. + if (strcmp(response, "d") == 0) {
  5397. + char *cmd;
  5398. +
  5399. + free(response);
  5400. + /* XXX: BUG rewrite to use exec or busybox's internal diff */
  5401. + sprintf_alloc(&cmd, "diff -u %s %s", backup, file_name);
  5402. + xsystem(cmd);
  5403. + free(cmd);
  5404. + printf(" [Press ENTER to continue]\n");
  5405. + response = file_read_line_alloc(stdin);
  5406. + free(response);
  5407. + continue;
  5408. + }
  5409. +#endif
  5410. +
  5411. + free(response);
  5412. + return 1;
  5413. + }
  5414. +}
  5415. +
  5416. +/* XXX: CLEANUP: I'd like to move all of the code for
  5417. + creating/cleaning pkg->tmp_unpack_dir directly into pkg.c. (Then,
  5418. + it would make sense to cleanup pkg->tmp_unpack_dir directly from
  5419. + pkg_deinit for example). */
  5420. +static int cleanup_temporary_files(ipkg_conf_t *conf, pkg_t *pkg)
  5421. +{
  5422. + DIR *tmp_dir;
  5423. + struct dirent *dirent;
  5424. + char *tmp_file;
  5425. +
  5426. +#ifdef IPKG_DEBUG_NO_TMP_CLEANUP
  5427. +#error
  5428. + ipkg_message(conf, IPKG_DEBUG,
  5429. + "%s: Not cleaning up %s since ipkg compiled with IPKG_DEBUG_NO_TMP_CLEANUP\n",
  5430. + __FUNCTION__, pkg->tmp_unpack_dir);
  5431. + return 0;
  5432. +#endif
  5433. +
  5434. + if (pkg->tmp_unpack_dir && file_is_dir(pkg->tmp_unpack_dir)) {
  5435. + tmp_dir = opendir(pkg->tmp_unpack_dir);
  5436. + if (tmp_dir) {
  5437. + while (1) {
  5438. + dirent = readdir(tmp_dir);
  5439. + if (dirent == NULL) {
  5440. + break;
  5441. + }
  5442. + sprintf_alloc(&tmp_file, "%s/%s",
  5443. + pkg->tmp_unpack_dir, dirent->d_name);
  5444. + if (! file_is_dir(tmp_file)) {
  5445. + unlink(tmp_file);
  5446. + }
  5447. + free(tmp_file);
  5448. + }
  5449. + closedir(tmp_dir);
  5450. + rmdir(pkg->tmp_unpack_dir);
  5451. + free(pkg->tmp_unpack_dir);
  5452. + pkg->tmp_unpack_dir = NULL;
  5453. + }
  5454. + }
  5455. +
  5456. + ipkg_message(conf, IPKG_INFO, "cleanup_temporary_files: pkg=%s local_filename=%s tmp_dir=%s\n",
  5457. + pkg->name, pkg->local_filename, conf->tmp_dir);
  5458. + if (pkg->local_filename && strncmp(pkg->local_filename, conf->tmp_dir, strlen(conf->tmp_dir)) == 0) {
  5459. + unlink(pkg->local_filename);
  5460. + free(pkg->local_filename);
  5461. + pkg->local_filename = NULL;
  5462. + }
  5463. +
  5464. + return 0;
  5465. +}
  5466. +
  5467. +static char *backup_filename_alloc(const char *file_name)
  5468. +{
  5469. + char *backup;
  5470. +
  5471. + sprintf_alloc(&backup, "%s%s", file_name, IPKG_BACKUP_SUFFIX);
  5472. +
  5473. + return backup;
  5474. +}
  5475. +
  5476. +int backup_make_backup(ipkg_conf_t *conf, const char *file_name)
  5477. +{
  5478. + int err;
  5479. + char *backup;
  5480. +
  5481. + backup = backup_filename_alloc(file_name);
  5482. + err = file_copy(file_name, backup);
  5483. + if (err) {
  5484. + ipkg_message(conf, IPKG_ERROR,
  5485. + "%s: Failed to copy %s to %s\n",
  5486. + __FUNCTION__, file_name, backup);
  5487. + }
  5488. +
  5489. + free(backup);
  5490. +
  5491. + return err;
  5492. +}
  5493. +
  5494. +static int backup_exists_for(const char *file_name)
  5495. +{
  5496. + int ret;
  5497. + char *backup;
  5498. +
  5499. + backup = backup_filename_alloc(file_name);
  5500. +
  5501. + ret = file_exists(backup);
  5502. +
  5503. + free(backup);
  5504. +
  5505. + return ret;
  5506. +}
  5507. +
  5508. +static int backup_remove(const char *file_name)
  5509. +{
  5510. + char *backup;
  5511. +
  5512. + backup = backup_filename_alloc(file_name);
  5513. + unlink(backup);
  5514. + free(backup);
  5515. +
  5516. + return 0;
  5517. +}
  5518. +
  5519. +
  5520. +
  5521. +#ifdef CONFIG_IPKG_PROCESS_ACTIONS
  5522. +
  5523. +int ipkg_remove_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove)
  5524. +{
  5525. + /* first, remove the packages that need removing */
  5526. + for (i = 0 ; i < pkgs_to_remove->len; i++ ) {
  5527. + pkg_t *pkg = pkgs_to_remove->pkgs[i];
  5528. + err = ipkg_remove_pkg(conf, pkg,0);
  5529. + if (err) return err;
  5530. + }
  5531. + return 0;
  5532. +}
  5533. +
  5534. +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)
  5535. +{
  5536. + int i;
  5537. + /* now one more pass checking on the ones that need to be installed */
  5538. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5539. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5540. + if (pkg->dest == NULL)
  5541. + pkg->dest = conf->default_dest;
  5542. +
  5543. + pkg->state_want = SW_INSTALL;
  5544. +
  5545. + /* Abhaya: conflicts check */
  5546. + err = check_conflicts_for(conf, pkg);
  5547. + if (err) { return err; }
  5548. + }
  5549. + return 0;
  5550. +}
  5551. +
  5552. +int ipkg_process_actions_unpack_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_to_install)
  5553. +{
  5554. + int i;
  5555. + /* now one more pass checking on the ones that need to be installed */
  5556. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5557. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5558. +
  5559. + /* XXX: FEATURE: Need to really support Provides/Replaces: here at some point */
  5560. + pkg_vec_t *replacees = pkg_vec_alloc();
  5561. + pkg_get_installed_replacees(pkg, replacees);
  5562. +
  5563. + /* XXX: BUG: we really should treat replacement more like an upgrade
  5564. + * Instead, we're going to remove the replacees
  5565. + */
  5566. + err = pkg_remove_installed_replacees(conf, replacees);
  5567. + if (err) return err;
  5568. + pkg->state_flag |= SF_REMOVED_REPLACEES;
  5569. + }
  5570. + return 0;
  5571. +}
  5572. +
  5573. +int ipkg_process_actions_unpack_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_to_install)
  5574. +{
  5575. + int i;
  5576. + /* now one more pass checking on the ones that need to be installed */
  5577. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5578. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5579. + if (pkg->local_filename == NULL) {
  5580. + err = ipkg_download_pkg(conf, pkg, conf->tmp_dir);
  5581. + if (err) {
  5582. + ipkg_message(conf, IPKG_ERROR,
  5583. + "Failed to download %s. Perhaps you need to run 'ipkg update'?\n",
  5584. + pkg->name);
  5585. + return err;
  5586. + }
  5587. + }
  5588. + if (pkg->tmp_unpack_dir == NULL) {
  5589. + err = unpack_pkg_control_files(conf, pkg);
  5590. + if (err) return err;
  5591. + }
  5592. + }
  5593. + return 0;
  5594. +}
  5595. +
  5596. +int ipkg_process_actions_prerm(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
  5597. +{
  5598. + int i;
  5599. + /* now one more pass checking on the ones that need to be installed */
  5600. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5601. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5602. + pkg_t *old_pkg = pkg->old_pkg;
  5603. +
  5604. + err = prerm_upgrade_old_pkg(conf, pkg, old_pkg);
  5605. + if (err) return err;
  5606. +
  5607. + err = prerm_deconfigure_conflictors(conf, pkg, replacees);
  5608. + if (err) return err;
  5609. +
  5610. + err = preinst_configure(conf, pkg, old_pkg);
  5611. + if (err) return err;
  5612. +
  5613. + err = backup_modified_conffiles(conf, pkg, old_pkg);
  5614. + if (err) return err;
  5615. +
  5616. + err = postrm_upgrade_old_pkg(conf, pkg, old_pkg);
  5617. + if (err) return err;
  5618. + }
  5619. + return 0;
  5620. +}
  5621. +
  5622. +int ipkg_process_actions_install(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
  5623. +{
  5624. + int i;
  5625. + /* now one more pass checking on the ones that need to be installed */
  5626. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5627. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5628. + pkg_t *old_pkg = pkg->old_pkg;
  5629. +
  5630. + if (old_pkg) {
  5631. + old_pkg->state_want = SW_DEINSTALL;
  5632. +
  5633. + if (old_pkg->state_flag & SF_NOPRUNE) {
  5634. + ipkg_message(conf, IPKG_INFO,
  5635. + " not removing obsolesced files because package marked noprune\n");
  5636. + } else {
  5637. + ipkg_message(conf, IPKG_INFO,
  5638. + " removing obsolesced files\n");
  5639. + remove_obsolesced_files(conf, pkg, old_pkg);
  5640. + }
  5641. + }
  5642. +
  5643. + ipkg_message(conf, IPKG_INFO,
  5644. + " installing maintainer scripts\n");
  5645. + install_maintainer_scripts(conf, pkg, old_pkg);
  5646. +
  5647. + /* the following just returns 0 */
  5648. + remove_disappeared(conf, pkg);
  5649. +
  5650. + ipkg_message(conf, IPKG_INFO,
  5651. + " installing data files\n");
  5652. + install_data_files(conf, pkg);
  5653. +
  5654. + ipkg_message(conf, IPKG_INFO,
  5655. + " resolving conf files\n");
  5656. + resolve_conffiles(conf, pkg);
  5657. +
  5658. + pkg->state_status = SS_UNPACKED;
  5659. +
  5660. + if (old_pkg) {
  5661. + old_pkg->state_status = SS_NOT_INSTALLED;
  5662. + }
  5663. +
  5664. + time(&pkg->installed_time);
  5665. +
  5666. + ipkg_message(conf, IPKG_INFO,
  5667. + " cleanup temp files\n");
  5668. + cleanup_temporary_files(conf, pkg);
  5669. +
  5670. + if (pkg->parent)
  5671. + pkg->parent->state_status = pkg->state_status;
  5672. + }
  5673. + return 0;
  5674. +}
  5675. +
  5676. +int ipkg_process_actions_unwind_prerm(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
  5677. +{
  5678. + int i;
  5679. + /* now one more pass checking on the ones that need to be installed */
  5680. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5681. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5682. + pkg_t *old_pkg = pkg->old_pkg;
  5683. +
  5684. + if (old_pkg) {
  5685. + if (old_pkg->state_flags & SF_POSTRM_UPGRADE)
  5686. + postrm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
  5687. + if (old_pkg->state_flags & SF_CHECK_DATA_FILE_CLASHES)
  5688. + check_data_file_clashes_unwind(conf, pkg, old_pkg);
  5689. + if (old_pkg->state_flags & SF_BACKUP_MODIFIED_CONFFILES)
  5690. + backup_modified_conffiles_unwind(pkg, old_pkg);
  5691. + */
  5692. + if (old_pkg->state_flags & SF_PREINST_CONFIGURE)
  5693. + preinst_configure_unwind(conf, pkg, old_pkg);
  5694. + if (old_pkg->state_flags & SF_DECONFIGURE_CONFLICTORS)
  5695. + prerm_deconfigure_conflictors_unwind(conf, pkg, replacees);
  5696. + if (old_pkg->state_flags & SF_PRERM_UPGRADE)
  5697. + prerm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
  5698. + */
  5699. +
  5700. + if (old_pkg->state_flags & SF_REMOVED_REPLACEES)
  5701. + remove_installed_replacees_unwind(conf, pkg, old_pkg);
  5702. +
  5703. + }
  5704. + }
  5705. + return 0;
  5706. +}
  5707. +
  5708. +/*
  5709. + * Perform all the actions.
  5710. + *
  5711. + * pkgs_to_remove are packages marked for removal.
  5712. + * pkgs_superseded are the old packages being replaced by upgrades.
  5713. + *
  5714. + * Assumes pkgs_to_install includes all dependences, recursively, sorted in installable order.
  5715. + */
  5716. +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)
  5717. +{
  5718. + int err;
  5719. + int i;
  5720. +
  5721. + err = ipkg_remove_packages(conf, pkgs_to_remove);
  5722. + if (err) return err;
  5723. +
  5724. + err = ipkg_process_actions_sanity_check(conf, pkgs_superseded, pkgs_to_install);
  5725. + if (err) return err;
  5726. +
  5727. + err = ipkg_process_actions_remove_replacees(conf, pkgs_to_install);
  5728. + if (err) goto UNWIND;
  5729. +
  5730. + /* @@@@ look at ipkg_install_pkg for handling replacements */
  5731. + err = ipkg_process_actions_unpack_packages(conf, pkgs_to_install);
  5732. + if (err) goto UNWIND;
  5733. +
  5734. + /*
  5735. + * Now that we have the packages unpacked, we can look for data
  5736. + * file clashes. First, we mark the files from the superseded
  5737. + * packages as obsolete. Then we scan the files in
  5738. + * pkgs_to_install, and only complain about clashes with
  5739. + * non-obsolete files.
  5740. + */
  5741. +
  5742. + err = ipkg_process_actions_check_data_file_clashes(conf, pkgs_superseded, pkgs_to_install);
  5743. + if (err) goto UNWIND;
  5744. +
  5745. + /* this was before checking data file clashes */
  5746. + err = ipkg_process_actions_prerm(conf, pkgs_superseded, pkgs_to_install);
  5747. + if (err) goto UNWIND;
  5748. +
  5749. + /* point of no return: no unwinding after this */
  5750. + err = ipkg_process_actions_install(conf, pkgs_to_install);
  5751. + if (err) return err;
  5752. +
  5753. + ipkg_message(conf, IPKG_INFO, "Done.\n");
  5754. + return 0;
  5755. +
  5756. + UNWIND:
  5757. + ipkg_process_actions_unwind(conf, pkgs_to_install);
  5758. +
  5759. + ipkg_message(conf, IPKG_INFO,
  5760. + " cleanup temp files\n");
  5761. + cleanup_temporary_files(conf, pkg);
  5762. +
  5763. + ipkg_message(conf, IPKG_INFO,
  5764. + "Failed.\n");
  5765. + return err;
  5766. +}
  5767. +
  5768. +#endif
  5769. diff -Nur busybox-1.17.2.orig/archival/libipkg/ipkg_install.h busybox-1.17.2/archival/libipkg/ipkg_install.h
  5770. --- busybox-1.17.2.orig/archival/libipkg/ipkg_install.h 1970-01-01 01:00:00.000000000 +0100
  5771. +++ busybox-1.17.2/archival/libipkg/ipkg_install.h 2010-12-01 22:25:23.000000000 +0100
  5772. @@ -0,0 +1,35 @@
  5773. +/* ipkg_install.h - the itsy package management system
  5774. +
  5775. + Carl D. Worth
  5776. +
  5777. + Copyright (C) 2001 University of Southern California
  5778. +
  5779. + This program is free software; you can redistribute it and/or
  5780. + modify it under the terms of the GNU General Public License as
  5781. + published by the Free Software Foundation; either version 2, or (at
  5782. + your option) any later version.
  5783. +
  5784. + This program is distributed in the hope that it will be useful, but
  5785. + WITHOUT ANY WARRANTY; without even the implied warranty of
  5786. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  5787. + General Public License for more details.
  5788. +*/
  5789. +
  5790. +#ifndef IPKG_INSTALL_H
  5791. +#define IPKG_INSTALL_H
  5792. +
  5793. +#include "pkg.h"
  5794. +#include "ipkg_conf.h"
  5795. +
  5796. +ipkg_error_t ipkg_install_by_name(ipkg_conf_t *conf, const char *pkg_name);
  5797. +ipkg_error_t ipkg_install_multi_by_name(ipkg_conf_t *conf, const char *pkg_name);
  5798. +int ipkg_install_from_file(ipkg_conf_t *conf, const char *filename);
  5799. +int ipkg_install_pkg(ipkg_conf_t *conf, pkg_t *pkg,int from_upgrading);
  5800. +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg);
  5801. +
  5802. +int ipkg_satisfy_all_dependences(ipkg_conf_t *conf);
  5803. +
  5804. +int pkg_mark_dependencies_for_installation(ipkg_conf_t *conf, pkg_t *pkg_name, pkg_vec_t *pkgs_needed);
  5805. +int name_mark_dependencies_for_installation(ipkg_conf_t *conf, const char *pkg_name, pkg_vec_t *pkgs_needed);
  5806. +
  5807. +#endif
  5808. diff -Nur busybox-1.17.2.orig/archival/libipkg/ipkg_message.c busybox-1.17.2/archival/libipkg/ipkg_message.c
  5809. --- busybox-1.17.2.orig/archival/libipkg/ipkg_message.c 1970-01-01 01:00:00.000000000 +0100
  5810. +++ busybox-1.17.2/archival/libipkg/ipkg_message.c 2010-12-01 22:25:23.000000000 +0100
  5811. @@ -0,0 +1,35 @@
  5812. +/* ipkg_message.c - the itsy package management system
  5813. +
  5814. + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
  5815. +
  5816. + This program is free software; you can redistribute it and/or
  5817. + modify it under the terms of the GNU General Public License as
  5818. + published by the Free Software Foundation; either version 2, or (at
  5819. + your option) any later version.
  5820. +
  5821. + This program is distributed in the hope that it will be useful, but
  5822. + WITHOUT ANY WARRANTY; without even the implied warranty of
  5823. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  5824. + General Public License for more details.
  5825. +*/
  5826. +
  5827. +
  5828. +#include "ipkg.h"
  5829. +#include "ipkg_conf.h"
  5830. +#include "ipkg_message.h"
  5831. +#include "libipkg.h"
  5832. +
  5833. +void
  5834. +ipkg_message (ipkg_conf_t * conf, message_level_t level, const char *fmt, ...)
  5835. +{
  5836. + va_list ap;
  5837. + char ts[256];
  5838. +
  5839. + if (ipkg_cb_message)
  5840. + {
  5841. + va_start (ap, fmt);
  5842. + vsnprintf (ts,256,fmt, ap);
  5843. + va_end (ap);
  5844. + ipkg_cb_message(conf,level,ts);
  5845. + }
  5846. +}
  5847. diff -Nur busybox-1.17.2.orig/archival/libipkg/ipkg_message.h busybox-1.17.2/archival/libipkg/ipkg_message.h
  5848. --- busybox-1.17.2.orig/archival/libipkg/ipkg_message.h 1970-01-01 01:00:00.000000000 +0100
  5849. +++ busybox-1.17.2/archival/libipkg/ipkg_message.h 2010-12-01 22:25:23.000000000 +0100
  5850. @@ -0,0 +1,32 @@
  5851. +/* ipkg_message.h - the itsy package management system
  5852. +
  5853. + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
  5854. +
  5855. + This program is free software; you can redistribute it and/or
  5856. + modify it under the terms of the GNU General Public License as
  5857. + published by the Free Software Foundation; either version 2, or (at
  5858. + your option) any later version.
  5859. +
  5860. + This program is distributed in the hope that it will be useful, but
  5861. + WITHOUT ANY WARRANTY; without even the implied warranty of
  5862. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  5863. + General Public License for more details.
  5864. +*/
  5865. +
  5866. +#ifndef _IPKG_MESSAGE_H_
  5867. +#define _IPKG_MESSAGE_H_
  5868. +
  5869. +#include "ipkg.h"
  5870. +#include "ipkg_conf.h"
  5871. +
  5872. +typedef enum {
  5873. + IPKG_ERROR, /* error conditions */
  5874. + IPKG_NOTICE, /* normal but significant condition */
  5875. + IPKG_INFO, /* informational message */
  5876. + IPKG_DEBUG, /* debug level message */
  5877. + IPKG_DEBUG2, /* more debug level message */
  5878. +} message_level_t;
  5879. +
  5880. +extern void ipkg_message(ipkg_conf_t *conf, message_level_t level, const char *fmt, ...);
  5881. +
  5882. +#endif /* _IPKG_MESSAGE_H_ */
  5883. diff -Nur busybox-1.17.2.orig/archival/libipkg/ipkg_remove.c busybox-1.17.2/archival/libipkg/ipkg_remove.c
  5884. --- busybox-1.17.2.orig/archival/libipkg/ipkg_remove.c 1970-01-01 01:00:00.000000000 +0100
  5885. +++ busybox-1.17.2/archival/libipkg/ipkg_remove.c 2010-12-01 22:25:23.000000000 +0100
  5886. @@ -0,0 +1,385 @@
  5887. +/* ipkg_remove.c - the itsy package management system
  5888. +
  5889. + Carl D. Worth
  5890. +
  5891. + Copyright (C) 2001 University of Southern California
  5892. +
  5893. + This program is free software; you can redistribute it and/or
  5894. + modify it under the terms of the GNU General Public License as
  5895. + published by the Free Software Foundation; either version 2, or (at
  5896. + your option) any later version.
  5897. +
  5898. + This program is distributed in the hope that it will be useful, but
  5899. + WITHOUT ANY WARRANTY; without even the implied warranty of
  5900. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  5901. + General Public License for more details.
  5902. +*/
  5903. +
  5904. +#include "ipkg.h"
  5905. +#include "ipkg_message.h"
  5906. +
  5907. +#include <glob.h>
  5908. +
  5909. +#include "ipkg_remove.h"
  5910. +
  5911. +#include "file_util.h"
  5912. +#include "sprintf_alloc.h"
  5913. +#include "str_util.h"
  5914. +
  5915. +#include "ipkg_cmd.h"
  5916. +
  5917. +int ipkg_remove_dependent_pkgs (ipkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **dependents);
  5918. +
  5919. +/*
  5920. + * Returns number of the number of packages depending on the packages provided by this package.
  5921. + * Every package implicitly provides itself.
  5922. + */
  5923. +int pkg_has_installed_dependents(pkg_t *pkg, abstract_pkg_t *** pdependents)
  5924. +{
  5925. + int nprovides = pkg->provides_count;
  5926. + abstract_pkg_t **provides = pkg->provides;
  5927. + int n_installed_dependents = 0;
  5928. + int i;
  5929. + for (i = 0; i <= nprovides; i++) {
  5930. + abstract_pkg_t *providee = provides[i];
  5931. + abstract_pkg_t **dependers = providee->depended_upon_by;
  5932. + abstract_pkg_t *dep_ab_pkg;
  5933. + if (dependers == NULL)
  5934. + continue;
  5935. + while ((dep_ab_pkg = *dependers++) != NULL) {
  5936. + if (dep_ab_pkg->state_status == SS_INSTALLED){
  5937. + n_installed_dependents++;
  5938. + }
  5939. + }
  5940. +
  5941. + }
  5942. + /* if caller requested the set of installed dependents */
  5943. + if (pdependents) {
  5944. + int p = 0;
  5945. + abstract_pkg_t **dependents = (abstract_pkg_t **)malloc((n_installed_dependents+1)*sizeof(abstract_pkg_t *));
  5946. +
  5947. + if ( dependents == NULL ){
  5948. + fprintf(stderr,"%s Unable to allocate memory. REPORT THIS BUG IN BUGZILLA PLEASE\n", __FUNCTION__);
  5949. + return -1;
  5950. + }
  5951. +
  5952. + *pdependents = dependents;
  5953. + for (i = 0; i <= nprovides; i++) {
  5954. + abstract_pkg_t *providee = provides[i];
  5955. + abstract_pkg_t **dependers = providee->depended_upon_by;
  5956. + abstract_pkg_t *dep_ab_pkg;
  5957. + if (dependers == NULL)
  5958. + continue;
  5959. + while ((dep_ab_pkg = *dependers++) != NULL) {
  5960. + if (dep_ab_pkg->state_status == SS_INSTALLED && !(dep_ab_pkg->state_flag & SF_MARKED)) {
  5961. + dependents[p++] = dep_ab_pkg;
  5962. + dep_ab_pkg->state_flag |= SF_MARKED;
  5963. + }
  5964. + }
  5965. + }
  5966. + dependents[p] = NULL;
  5967. + /* now clear the marks */
  5968. + for (i = 0; i < p; i++) {
  5969. + abstract_pkg_t *dep_ab_pkg = dependents[i];
  5970. + dep_ab_pkg->state_flag &= ~SF_MARKED;
  5971. + }
  5972. + }
  5973. + return n_installed_dependents;
  5974. +}
  5975. +
  5976. +int ipkg_remove_dependent_pkgs (ipkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **dependents)
  5977. +{
  5978. + int i;
  5979. + int a;
  5980. + int count;
  5981. + pkg_vec_t *dependent_pkgs = pkg_vec_alloc();
  5982. + abstract_pkg_t * ab_pkg;
  5983. +
  5984. + if((ab_pkg = pkg->parent) == NULL){
  5985. + fprintf(stderr, "%s: unable to get dependent pkgs. pkg %s isn't in hash table\n",
  5986. + __FUNCTION__, pkg->name);
  5987. + return 0;
  5988. + }
  5989. +
  5990. + if (dependents == NULL)
  5991. + return 0;
  5992. +
  5993. + // here i am using the dependencies_checked
  5994. + if (ab_pkg->dependencies_checked == 2) // variable to make out whether this package
  5995. + return 0; // has already been encountered in the process
  5996. + // of marking packages for removal - Karthik
  5997. + ab_pkg->dependencies_checked = 2;
  5998. +
  5999. + i = 0;
  6000. + count = 1;
  6001. + while (dependents [i] != NULL) {
  6002. + abstract_pkg_t *dep_ab_pkg = dependents[i];
  6003. +
  6004. + if (dep_ab_pkg->dependencies_checked == 2){
  6005. + i++;
  6006. + continue;
  6007. + }
  6008. + if (dep_ab_pkg->state_status == SS_INSTALLED) {
  6009. + for (a = 0; a < dep_ab_pkg->pkgs->len; a++) {
  6010. + pkg_t *dep_pkg = dep_ab_pkg->pkgs->pkgs[a];
  6011. + if (dep_pkg->state_status == SS_INSTALLED) {
  6012. + pkg_vec_insert(dependent_pkgs, dep_pkg);
  6013. + count++;
  6014. + }
  6015. + }
  6016. + }
  6017. + i++;
  6018. + /* 1 - to keep track of visited ab_pkgs when checking for possiblility of a broken removal of pkgs.
  6019. + * 2 - to keep track of pkgs whose deps have been checked alrdy - Karthik */
  6020. + }
  6021. +
  6022. + if (count == 1)
  6023. + return 0;
  6024. +
  6025. +
  6026. + for (i = 0; i < dependent_pkgs->len; i++) {
  6027. + int err = ipkg_remove_pkg(conf, dependent_pkgs->pkgs[i],0);
  6028. + if (err)
  6029. + return err;
  6030. + }
  6031. + return 0;
  6032. +}
  6033. +
  6034. +static int user_prefers_removing_dependents(ipkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **dependents)
  6035. +{
  6036. + abstract_pkg_t *dep_ab_pkg;
  6037. + ipkg_message(conf, IPKG_ERROR, "Package %s is depended upon by packages:\n", pkg->name);
  6038. + while ((dep_ab_pkg = *dependents++) != NULL) {
  6039. + if (dep_ab_pkg->state_status == SS_INSTALLED)
  6040. + ipkg_message(conf, IPKG_ERROR, "\t%s\n", dep_ab_pkg->name);
  6041. + }
  6042. + ipkg_message(conf, IPKG_ERROR, "These might cease to work if package %s is removed.\n\n", pkg->name);
  6043. + ipkg_message(conf, IPKG_ERROR, "");
  6044. + ipkg_message(conf, IPKG_ERROR, "You can force removal of this package with -force-depends.\n");
  6045. + ipkg_message(conf, IPKG_ERROR, "You can force removal of this package and its dependents\n");
  6046. + ipkg_message(conf, IPKG_ERROR, "with -force-removal-of-dependent-packages or -recursive\n");
  6047. + ipkg_message(conf, IPKG_ERROR, "or by setting option force_removal_of_dependent_packages\n");
  6048. + ipkg_message(conf, IPKG_ERROR, "in ipkg.conf.\n");
  6049. + return 0;
  6050. +}
  6051. +
  6052. +int ipkg_remove_pkg(ipkg_conf_t *conf, pkg_t *pkg,int message)
  6053. +{
  6054. +/* Actually, when "message == 1" I have been called from an upgrade, and not from a normal remove
  6055. + thus I wan't check for essential, as I'm upgrading.
  6056. + I hope it won't break anything :)
  6057. +*/
  6058. + int err;
  6059. + abstract_pkg_t *parent_pkg = NULL;
  6060. +
  6061. + if (pkg->essential && !message) {
  6062. + if (conf->force_removal_of_essential_packages) {
  6063. + fprintf(stderr, "WARNING: Removing essential package %s under your coercion.\n"
  6064. + "\tIf your system breaks, you get to keep both pieces\n",
  6065. + pkg->name);
  6066. + } else {
  6067. + fprintf(stderr, "ERROR: Refusing to remove essential package %s.\n"
  6068. + "\tRemoving an essential package may lead to an unusable system, but if\n"
  6069. + "\tyou enjoy that kind of pain, you can force ipkg to proceed against\n"
  6070. + "\tits will with the option: -force-removal-of-essential-packages\n",
  6071. + pkg->name);
  6072. + return IPKG_PKG_IS_ESSENTIAL;
  6073. + }
  6074. + }
  6075. +
  6076. + if ((parent_pkg = pkg->parent) == NULL)
  6077. + return 0;
  6078. +
  6079. + /* only attempt to remove dependent installed packages if
  6080. + * force_depends is not specified or the package is being
  6081. + * replaced.
  6082. + */
  6083. + if (!conf->force_depends
  6084. + && !(pkg->state_flag & SF_REPLACE)) {
  6085. + abstract_pkg_t **dependents;
  6086. + int has_installed_dependents =
  6087. + pkg_has_installed_dependents(pkg, &dependents);
  6088. +
  6089. + if (has_installed_dependents) {
  6090. + /*
  6091. + * if this package is depended up by others, then either we should
  6092. + * not remove it or we should remove it and all of its dependents
  6093. + */
  6094. +
  6095. + if (!conf->force_removal_of_dependent_packages
  6096. + && !user_prefers_removing_dependents(conf, pkg, dependents)) {
  6097. + return IPKG_PKG_HAS_DEPENDENTS;
  6098. + }
  6099. +
  6100. + /* remove packages depending on this package - Karthik */
  6101. + err = ipkg_remove_dependent_pkgs (conf, pkg, dependents);
  6102. + free(dependents);
  6103. + if (err) return err;
  6104. + }
  6105. + }
  6106. +
  6107. + if ( message==0 ){
  6108. + printf("Removing package %s from %s...\n", pkg->name, pkg->dest->name);
  6109. + fflush(stdout);
  6110. + }
  6111. + pkg->state_flag |= SF_FILELIST_CHANGED;
  6112. +
  6113. + pkg->state_want = SW_DEINSTALL;
  6114. + ipkg_state_changed++;
  6115. +
  6116. + pkg_run_script(conf, pkg, "prerm", "remove");
  6117. +
  6118. + /* DPKG_INCOMPATIBILITY: dpkg is slightly different here. It
  6119. + maintains an empty filelist rather than deleting it. That seems
  6120. + like a big pain, and I don't see that that should make a big
  6121. + difference, but for anyone who wants tighter compatibility,
  6122. + feel free to fix this. */
  6123. + remove_data_files_and_list(conf, pkg);
  6124. +
  6125. + pkg_run_script(conf, pkg, "postrm", "remove");
  6126. +
  6127. + remove_maintainer_scripts_except_postrm(conf, pkg);
  6128. +
  6129. + /* Aman Gupta - Since ipkg is made for handheld devices with limited
  6130. + * space, it doesn't make sense to leave extra configurations, files,
  6131. + * and maintainer scripts left around. So, we make remove like purge,
  6132. + * and take out all the crap :) */
  6133. +
  6134. + remove_postrm(conf, pkg);
  6135. + pkg->state_status = SS_NOT_INSTALLED;
  6136. +
  6137. + if (parent_pkg)
  6138. + parent_pkg->state_status = SS_NOT_INSTALLED;
  6139. +
  6140. + return 0;
  6141. +}
  6142. +
  6143. +int ipkg_purge_pkg(ipkg_conf_t *conf, pkg_t *pkg)
  6144. +{
  6145. + ipkg_remove_pkg(conf, pkg,0);
  6146. + return 0;
  6147. +}
  6148. +
  6149. +int remove_data_files_and_list(ipkg_conf_t *conf, pkg_t *pkg)
  6150. +{
  6151. + str_list_t installed_dirs;
  6152. + str_list_t *installed_files;
  6153. + str_list_elt_t *iter;
  6154. + char *file_name;
  6155. + conffile_t *conffile;
  6156. + int removed_a_dir;
  6157. + pkg_t *owner;
  6158. +
  6159. + str_list_init(&installed_dirs);
  6160. + installed_files = pkg_get_installed_files(pkg);
  6161. +
  6162. + for (iter = installed_files->head; iter; iter = iter->next) {
  6163. + file_name = iter->data;
  6164. +
  6165. + if (file_is_dir(file_name)) {
  6166. + str_list_append(&installed_dirs, strdup(file_name));
  6167. + continue;
  6168. + }
  6169. +
  6170. + conffile = pkg_get_conffile(pkg, file_name);
  6171. + if (conffile) {
  6172. + /* XXX: QUESTION: Is this right? I figure we only need to
  6173. + save the conffile if it has been modified. Is that what
  6174. + dpkg does? Or does dpkg preserve all conffiles? If so,
  6175. + this seems like a better thing to do to conserve
  6176. + space. */
  6177. + if (conffile_has_been_modified(conf, conffile)) {
  6178. + printf(" not deleting modified conffile %s\n", file_name);
  6179. + fflush(stdout);
  6180. + continue;
  6181. + }
  6182. + }
  6183. +
  6184. + ipkg_message(conf, IPKG_INFO, " deleting %s (noaction=%d)\n", file_name, conf->noaction);
  6185. + if (!conf->noaction)
  6186. + unlink(file_name);
  6187. + }
  6188. +
  6189. + if (!conf->noaction) {
  6190. + do {
  6191. + removed_a_dir = 0;
  6192. + for (iter = installed_dirs.head; iter; iter = iter->next) {
  6193. + file_name = iter->data;
  6194. +
  6195. + if (rmdir(file_name) == 0) {
  6196. + ipkg_message(conf, IPKG_INFO, " deleting %s\n", file_name);
  6197. + removed_a_dir = 1;
  6198. + str_list_remove(&installed_dirs, &iter);
  6199. + }
  6200. + }
  6201. + } while (removed_a_dir);
  6202. + }
  6203. +
  6204. + pkg_free_installed_files(pkg);
  6205. + /* We have to remove the file list now, so that
  6206. + find_pkg_owning_file does not always just report this package */
  6207. + pkg_remove_installed_files_list(conf, pkg);
  6208. +
  6209. + /* Don't print warning for dirs that are provided by other packages */
  6210. + for (iter = installed_dirs.head; iter; iter = iter->next) {
  6211. + file_name = iter->data;
  6212. +
  6213. + owner = file_hash_get_file_owner(conf, file_name);
  6214. + if (owner) {
  6215. + free(iter->data);
  6216. + iter->data = NULL;
  6217. + str_list_remove(&installed_dirs, &iter);
  6218. + }
  6219. + }
  6220. +
  6221. + /* cleanup */
  6222. + for (iter = installed_dirs.head; iter; iter = iter->next) {
  6223. + free(iter->data);
  6224. + iter->data = NULL;
  6225. + }
  6226. + str_list_deinit(&installed_dirs);
  6227. +
  6228. + return 0;
  6229. +}
  6230. +
  6231. +int remove_maintainer_scripts_except_postrm(ipkg_conf_t *conf, pkg_t *pkg)
  6232. +{
  6233. + int i, err;
  6234. + char *globpattern;
  6235. + glob_t globbuf;
  6236. +
  6237. + if (conf->noaction) return 0;
  6238. +
  6239. + sprintf_alloc(&globpattern, "%s/%s.*",
  6240. + pkg->dest->info_dir, pkg->name);
  6241. + err = glob(globpattern, 0, NULL, &globbuf);
  6242. + free(globpattern);
  6243. + if (err) {
  6244. + return 0;
  6245. + }
  6246. +
  6247. + for (i = 0; i < globbuf.gl_pathc; i++) {
  6248. + if (str_ends_with(globbuf.gl_pathv[i], ".postrm")) {
  6249. + continue;
  6250. + }
  6251. + ipkg_message(conf, IPKG_INFO, " deleting %s\n", globbuf.gl_pathv[i]);
  6252. + unlink(globbuf.gl_pathv[i]);
  6253. + }
  6254. + globfree(&globbuf);
  6255. +
  6256. + return 0;
  6257. +}
  6258. +
  6259. +int remove_postrm(ipkg_conf_t *conf, pkg_t *pkg)
  6260. +{
  6261. + char *postrm_file_name;
  6262. +
  6263. + if (conf->noaction) return 0;
  6264. +
  6265. + sprintf_alloc(&postrm_file_name, "%s/%s.postrm",
  6266. + pkg->dest->info_dir, pkg->name);
  6267. + unlink(postrm_file_name);
  6268. + free(postrm_file_name);
  6269. +
  6270. + return 0;
  6271. +}
  6272. diff -Nur busybox-1.17.2.orig/archival/libipkg/ipkg_remove.h busybox-1.17.2/archival/libipkg/ipkg_remove.h
  6273. --- busybox-1.17.2.orig/archival/libipkg/ipkg_remove.h 1970-01-01 01:00:00.000000000 +0100
  6274. +++ busybox-1.17.2/archival/libipkg/ipkg_remove.h 2010-12-01 22:25:23.000000000 +0100
  6275. @@ -0,0 +1,33 @@
  6276. +/* ipkg_remove.h - the itsy package management system
  6277. +
  6278. + Carl D. Worth
  6279. +
  6280. + Copyright (C) 2001 University of Southern California
  6281. +
  6282. + This program is free software; you can redistribute it and/or
  6283. + modify it under the terms of the GNU General Public License as
  6284. + published by the Free Software Foundation; either version 2, or (at
  6285. + your option) any later version.
  6286. +
  6287. + This program is distributed in the hope that it will be useful, but
  6288. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6289. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6290. + General Public License for more details.
  6291. +*/
  6292. +
  6293. +#ifndef IPKG_REMOVE_H
  6294. +#define IPKG_REMOVE_H
  6295. +
  6296. +#include "pkg.h"
  6297. +#include "ipkg_conf.h"
  6298. +
  6299. +int ipkg_remove_pkg(ipkg_conf_t *conf, pkg_t *pkg,int message);
  6300. +int ipkg_purge_pkg(ipkg_conf_t *conf, pkg_t *pkg);
  6301. +int possible_broken_removal_of_packages (ipkg_conf_t *conf, pkg_t *pkg);
  6302. +int pkg_has_installed_dependents(pkg_t *pkg, abstract_pkg_t *** pdependents);
  6303. +int remove_data_files_and_list(ipkg_conf_t *conf, pkg_t *pkg);
  6304. +int remove_maintainer_scripts_except_postrm (ipkg_conf_t *conf, pkg_t *pkg);
  6305. +int remove_postrm (ipkg_conf_t *conf, pkg_t *pkg);
  6306. +
  6307. +
  6308. +#endif
  6309. diff -Nur busybox-1.17.2.orig/archival/libipkg/ipkg_upgrade.c busybox-1.17.2/archival/libipkg/ipkg_upgrade.c
  6310. --- busybox-1.17.2.orig/archival/libipkg/ipkg_upgrade.c 1970-01-01 01:00:00.000000000 +0100
  6311. +++ busybox-1.17.2/archival/libipkg/ipkg_upgrade.c 2010-12-01 22:25:23.000000000 +0100
  6312. @@ -0,0 +1,79 @@
  6313. +/* ipkg_upgrade.c - the itsy package management system
  6314. +
  6315. + Carl D. Worth
  6316. + Copyright (C) 2001 University of Southern California
  6317. +
  6318. + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
  6319. +
  6320. + This program is free software; you can redistribute it and/or
  6321. + modify it under the terms of the GNU General Public License as
  6322. + published by the Free Software Foundation; either version 2, or (at
  6323. + your option) any later version.
  6324. +
  6325. + This program is distributed in the hope that it will be useful, but
  6326. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6327. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6328. + General Public License for more details.
  6329. +*/
  6330. +
  6331. +#include "ipkg.h"
  6332. +#include "ipkg_install.h"
  6333. +#include "ipkg_message.h"
  6334. +
  6335. +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old);
  6336. +
  6337. +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old)
  6338. +{
  6339. + pkg_t *new;
  6340. + int cmp;
  6341. + char *old_version, *new_version;
  6342. +
  6343. + if (old->state_flag & SF_HOLD) {
  6344. + ipkg_message(conf, IPKG_NOTICE,
  6345. + "Not upgrading package %s which is marked "
  6346. + "hold (flags=%#x)\n", old->name, old->state_flag);
  6347. + return 0;
  6348. + }
  6349. +
  6350. + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, old->name);
  6351. + if (new == NULL) {
  6352. + old_version = pkg_version_str_alloc(old);
  6353. + ipkg_message(conf, IPKG_NOTICE,
  6354. + "Assuming locally installed package %s (%s) "
  6355. + "is up to date.\n", old->name, old_version);
  6356. + free(old_version);
  6357. + return 0;
  6358. + }
  6359. +
  6360. + old_version = pkg_version_str_alloc(old);
  6361. + new_version = pkg_version_str_alloc(new);
  6362. +
  6363. + cmp = pkg_compare_versions(old, new);
  6364. + ipkg_message(conf, IPKG_DEBUG,
  6365. + "comparing visible versions of pkg %s:"
  6366. + "\n\t%s is installed "
  6367. + "\n\t%s is available "
  6368. + "\n\t%d was comparison result\n",
  6369. + old->name, old_version, new_version, cmp);
  6370. + if (cmp == 0) {
  6371. + ipkg_message(conf, IPKG_INFO,
  6372. + "Package %s (%s) installed in %s is up to date.\n",
  6373. + old->name, old_version, old->dest->name);
  6374. + free(old_version);
  6375. + free(new_version);
  6376. + return 0;
  6377. + } else if (cmp > 0) {
  6378. + ipkg_message(conf, IPKG_NOTICE,
  6379. + "Not downgrading package %s on %s from %s to %s.\n",
  6380. + old->name, old->dest->name, old_version, new_version);
  6381. + free(old_version);
  6382. + free(new_version);
  6383. + return 0;
  6384. + } else if (cmp < 0) {
  6385. + new->dest = old->dest;
  6386. + old->state_want = SW_DEINSTALL;
  6387. + }
  6388. +
  6389. + new->state_flag |= SF_USER;
  6390. + return ipkg_install_pkg(conf, new,1);
  6391. +}
  6392. diff -Nur busybox-1.17.2.orig/archival/libipkg/ipkg_upgrade.h busybox-1.17.2/archival/libipkg/ipkg_upgrade.h
  6393. --- busybox-1.17.2.orig/archival/libipkg/ipkg_upgrade.h 1970-01-01 01:00:00.000000000 +0100
  6394. +++ busybox-1.17.2/archival/libipkg/ipkg_upgrade.h 2010-12-01 22:25:23.000000000 +0100
  6395. @@ -0,0 +1,18 @@
  6396. +/* ipkg_upgrade.c - the itsy package management system
  6397. +
  6398. + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
  6399. +
  6400. + This program is free software; you can redistribute it and/or
  6401. + modify it under the terms of the GNU General Public License as
  6402. + published by the Free Software Foundation; either version 2, or (at
  6403. + your option) any later version.
  6404. +
  6405. + This program is distributed in the hope that it will be useful, but
  6406. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6407. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6408. + General Public License for more details.
  6409. +*/
  6410. +
  6411. +#include "ipkg.h"
  6412. +
  6413. +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old);
  6414. diff -Nur busybox-1.17.2.orig/archival/libipkg/ipkg_utils.c busybox-1.17.2/archival/libipkg/ipkg_utils.c
  6415. --- busybox-1.17.2.orig/archival/libipkg/ipkg_utils.c 1970-01-01 01:00:00.000000000 +0100
  6416. +++ busybox-1.17.2/archival/libipkg/ipkg_utils.c 2010-12-01 22:25:23.000000000 +0100
  6417. @@ -0,0 +1,185 @@
  6418. +/* ipkg_utils.c - the itsy package management system
  6419. +
  6420. + Steven M. Ayer
  6421. +
  6422. + Copyright (C) 2002 Compaq Computer Corporation
  6423. +
  6424. + This program is free software; you can redistribute it and/or
  6425. + modify it under the terms of the GNU General Public License as
  6426. + published by the Free Software Foundation; either version 2, or (at
  6427. + your option) any later version.
  6428. +
  6429. + This program is distributed in the hope that it will be useful, but
  6430. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6431. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6432. + General Public License for more details.
  6433. +*/
  6434. +
  6435. +#include "ipkg.h"
  6436. +#include <errno.h>
  6437. +#include <ctype.h>
  6438. +#include <sys/vfs.h>
  6439. +
  6440. +#include "ipkg_utils.h"
  6441. +#include "pkg.h"
  6442. +#include "pkg_hash.h"
  6443. +
  6444. +void push_error_list(struct errlist ** errors, char * msg);
  6445. +void reverse_error_list(struct errlist **errors);
  6446. +void free_error_list(struct errlist **errors);
  6447. +
  6448. +struct errlist* error_list;
  6449. +
  6450. +int get_available_blocks(char * filesystem)
  6451. +{
  6452. + struct statfs sfs;
  6453. +
  6454. + if(statfs(filesystem, &sfs)){
  6455. + fprintf(stderr, "bad statfs\n");
  6456. + return 0;
  6457. + }
  6458. + /* fprintf(stderr, "reported fs type %x\n", sfs.f_type); */
  6459. + return ((sfs.f_bavail * sfs.f_bsize) / 1024);
  6460. +}
  6461. +
  6462. +char **read_raw_pkgs_from_file(const char *file_name)
  6463. +{
  6464. + FILE *fp;
  6465. + char **ret;
  6466. +
  6467. + if(!(fp = fopen(file_name, "r"))){
  6468. + fprintf(stderr, "can't get %s open for read\n", file_name);
  6469. + return NULL;
  6470. + }
  6471. +
  6472. + ret = read_raw_pkgs_from_stream(fp);
  6473. +
  6474. + fclose(fp);
  6475. +
  6476. + return ret;
  6477. +}
  6478. +
  6479. +char **read_raw_pkgs_from_stream(FILE *fp)
  6480. +{
  6481. + char **raw = NULL, *buf, *scout;
  6482. + int count = 0;
  6483. + size_t size = 512;
  6484. +
  6485. + buf = malloc (size);
  6486. +
  6487. + while (fgets(buf, size, fp)) {
  6488. + while (strlen (buf) == (size - 1)
  6489. + && buf[size-2] != '\n') {
  6490. + size_t o = size - 1;
  6491. + size *= 2;
  6492. + buf = realloc (buf, size);
  6493. + if (fgets (buf + o, size - o, fp) == NULL)
  6494. + break;
  6495. + }
  6496. +
  6497. + if(!(count % 50))
  6498. + raw = realloc(raw, (count + 50) * sizeof(char *));
  6499. +
  6500. + if((scout = strchr(buf, '\n')))
  6501. + *scout = '\0';
  6502. +
  6503. + raw[count++] = strdup(buf);
  6504. + }
  6505. +
  6506. + raw = realloc(raw, (count + 1) * sizeof(char *));
  6507. + raw[count] = NULL;
  6508. +
  6509. + free (buf);
  6510. +
  6511. + return raw;
  6512. +}
  6513. +
  6514. +/* something to remove whitespace, a hash pooper */
  6515. +char *trim_alloc(char *line)
  6516. +{
  6517. + char *new;
  6518. + char *dest, *src, *end;
  6519. +
  6520. + new = malloc(strlen(line) + 1);
  6521. + if ( new == NULL ){
  6522. + fprintf(stderr,"%s: Unable to allocate memory\n",__FUNCTION__);
  6523. + return NULL;
  6524. + }
  6525. + dest = new, src = line, end = line + (strlen(line) - 1);
  6526. +
  6527. + /* remove it from the front */
  6528. + while(src &&
  6529. + isspace(*src) &&
  6530. + *src)
  6531. + src++;
  6532. + /* and now from the back */
  6533. + while((end > src) &&
  6534. + isspace(*end))
  6535. + end--;
  6536. + end++;
  6537. + *end = '\0';
  6538. + strcpy(new, src);
  6539. + /* this does from the first space
  6540. + * blasting away any versions stuff in depends
  6541. + while(src &&
  6542. + !isspace(*src) &&
  6543. + *src)
  6544. + *dest++ = *src++;
  6545. + *dest = '\0';
  6546. + */
  6547. +
  6548. + return new;
  6549. +}
  6550. +
  6551. +int line_is_blank(const char *line)
  6552. +{
  6553. + const char *s;
  6554. +
  6555. + for (s = line; *s; s++) {
  6556. + if (!isspace(*s))
  6557. + return 0;
  6558. + }
  6559. + return 1;
  6560. +}
  6561. +
  6562. +void push_error_list(struct errlist ** errors, char * msg){
  6563. + struct errlist *err_lst_tmp;
  6564. +
  6565. +
  6566. + err_lst_tmp = malloc ( sizeof (err_lst_tmp) );
  6567. + err_lst_tmp->errmsg=strdup(msg) ;
  6568. + err_lst_tmp->next = *errors;
  6569. + *errors = err_lst_tmp;
  6570. +}
  6571. +
  6572. +
  6573. +void reverse_error_list(struct errlist **errors){
  6574. + struct errlist *result=NULL;
  6575. + struct errlist *current= *errors;
  6576. + struct errlist *next;
  6577. +
  6578. + while ( current != NULL ) {
  6579. + next = current->next;
  6580. + current->next=result;
  6581. + result=current;
  6582. + current=next;
  6583. + }
  6584. + *errors=result;
  6585. +
  6586. +}
  6587. +
  6588. +
  6589. +void free_error_list(struct errlist **errors){
  6590. + struct errlist *current = *errors;
  6591. +
  6592. + while (current != NULL) {
  6593. + free(current->errmsg);
  6594. + current = (*errors)->next;
  6595. + free(*errors);
  6596. + *errors = current;
  6597. + }
  6598. +
  6599. +
  6600. +}
  6601. +
  6602. +
  6603. diff -Nur busybox-1.17.2.orig/archival/libipkg/ipkg_utils.h busybox-1.17.2/archival/libipkg/ipkg_utils.h
  6604. --- busybox-1.17.2.orig/archival/libipkg/ipkg_utils.h 1970-01-01 01:00:00.000000000 +0100
  6605. +++ busybox-1.17.2/archival/libipkg/ipkg_utils.h 2010-12-01 22:25:23.000000000 +0100
  6606. @@ -0,0 +1,29 @@
  6607. +/* ipkg_utils.h - the itsy package management system
  6608. +
  6609. + Steven M. Ayer
  6610. +
  6611. + Copyright (C) 2002 Compaq Computer Corporation
  6612. +
  6613. + This program is free software; you can redistribute it and/or
  6614. + modify it under the terms of the GNU General Public License as
  6615. + published by the Free Software Foundation; either version 2, or (at
  6616. + your option) any later version.
  6617. +
  6618. + This program is distributed in the hope that it will be useful, but
  6619. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6620. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6621. + General Public License for more details.
  6622. +*/
  6623. +
  6624. +#ifndef IPKG_UTILS_H
  6625. +#define IPKG_UTILS_H
  6626. +
  6627. +#include "pkg.h"
  6628. +
  6629. +int get_available_blocks(char * filesystem);
  6630. +char **read_raw_pkgs_from_file(const char *file_name);
  6631. +char **read_raw_pkgs_from_stream(FILE *fp);
  6632. +char *trim_alloc(char * line);
  6633. +int line_is_blank(const char *line);
  6634. +
  6635. +#endif
  6636. diff -Nur busybox-1.17.2.orig/archival/libipkg/libipkg.c busybox-1.17.2/archival/libipkg/libipkg.c
  6637. --- busybox-1.17.2.orig/archival/libipkg/libipkg.c 1970-01-01 01:00:00.000000000 +0100
  6638. +++ busybox-1.17.2/archival/libipkg/libipkg.c 2010-12-01 22:25:23.000000000 +0100
  6639. @@ -0,0 +1,583 @@
  6640. +/* ipkglib.c - the itsy package management system
  6641. +
  6642. + Florina Boor
  6643. +
  6644. + Copyright (C) 2003 kernel concepts
  6645. +
  6646. + This program is free software; you can redistribute it and/or
  6647. + modify it under the terms of the GNU General Public License as
  6648. + published by the Free Software Foundation; either version 2, or (at
  6649. + your option) any later version.
  6650. +
  6651. + This program is distributed in the hope that it will be useful, but
  6652. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6653. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6654. + General Public License for more details.
  6655. +*/
  6656. +
  6657. +#include "ipkg.h"
  6658. +#include "ipkg_includes.h"
  6659. +#include "libipkg.h"
  6660. +
  6661. +#include "args.h"
  6662. +#include "ipkg_conf.h"
  6663. +#include "ipkg_cmd.h"
  6664. +#include "file_util.h"
  6665. +
  6666. +int ipkg_file_what(args_t *args, const char *file, const char* command);
  6667. +int default_ipkg_message_callback(ipkg_conf_t *conf, message_level_t level,
  6668. + char *msg);
  6669. +int default_ipkg_list_callback(char *name, char *desc, char *version);
  6670. +int default_ipkg_files_callback(char *desc);
  6671. +int default_ipkg_status_callback(char *desc);
  6672. +char* default_ipkg_response_callback(char *question);
  6673. +
  6674. +
  6675. +ipkg_message_callback ipkg_cb_message = NULL;
  6676. +ipkg_response_callback ipkg_cb_response = NULL;
  6677. +ipkg_status_callback ipkg_cb_status = NULL;
  6678. +ipkg_list_callback ipkg_cb_list = NULL;
  6679. +
  6680. +
  6681. +int
  6682. +ipkg_init (ipkg_message_callback mcall,
  6683. + ipkg_response_callback rcall,
  6684. + args_t * args)
  6685. +{
  6686. + ipkg_cb_message = mcall;
  6687. + ipkg_cb_response = rcall;
  6688. +
  6689. + args_init (args);
  6690. +
  6691. + return 0;
  6692. +}
  6693. +
  6694. +
  6695. +int
  6696. +ipkg_deinit (args_t * args)
  6697. +{
  6698. + args_deinit (args);
  6699. + ipkg_cb_message = NULL;
  6700. + ipkg_cb_response = NULL;
  6701. +
  6702. + /* place other cleanup stuff here */
  6703. +
  6704. + return 0;
  6705. +}
  6706. +
  6707. +
  6708. +int
  6709. +ipkg_packages_list(args_t *args,
  6710. + const char *packages,
  6711. + ipkg_list_callback cblist,
  6712. + void *userdata)
  6713. +{
  6714. + ipkg_cmd_t *cmd;
  6715. + ipkg_conf_t ipkg_conf;
  6716. + int err;
  6717. +
  6718. + err = ipkg_conf_init (&ipkg_conf, args);
  6719. + if (err)
  6720. + {
  6721. + return err;
  6722. + }
  6723. +
  6724. + ipkg_cb_list = cblist;
  6725. + /* we need to do this because of static declarations,
  6726. + * maybe a good idea to change */
  6727. + cmd = ipkg_cmd_find ("list");
  6728. + if (packages)
  6729. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
  6730. + else
  6731. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
  6732. + ipkg_cb_list = NULL;
  6733. + ipkg_conf_deinit (&ipkg_conf);
  6734. + return (err);
  6735. +}
  6736. +
  6737. +
  6738. +int
  6739. +ipkg_packages_status(args_t *args,
  6740. + const char *packages,
  6741. + ipkg_status_callback cbstatus,
  6742. + void *userdata)
  6743. +{
  6744. + ipkg_cmd_t *cmd;
  6745. + ipkg_conf_t ipkg_conf;
  6746. + int err;
  6747. +
  6748. + err = ipkg_conf_init (&ipkg_conf, args);
  6749. + if (err)
  6750. + {
  6751. + return err;
  6752. + }
  6753. +
  6754. + ipkg_cb_status = cbstatus;
  6755. +
  6756. + /* we need to do this because of static declarations,
  6757. + * maybe a good idea to change */
  6758. + cmd = ipkg_cmd_find ("status");
  6759. + if (packages)
  6760. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
  6761. + else
  6762. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
  6763. +
  6764. + ipkg_cb_status = NULL;
  6765. + ipkg_conf_deinit (&ipkg_conf);
  6766. + return (err);
  6767. +}
  6768. +
  6769. +
  6770. +int
  6771. +ipkg_packages_info(args_t *args,
  6772. + const char *packages,
  6773. + ipkg_status_callback cbstatus,
  6774. + void *userdata)
  6775. +{
  6776. + ipkg_cmd_t *cmd;
  6777. + ipkg_conf_t ipkg_conf;
  6778. + int err;
  6779. +
  6780. + err = ipkg_conf_init (&ipkg_conf, args);
  6781. + if (err)
  6782. + {
  6783. + return err;
  6784. + }
  6785. +
  6786. + ipkg_cb_status = cbstatus;
  6787. +
  6788. + /* we need to do this because of static declarations,
  6789. + * maybe a good idea to change */
  6790. + cmd = ipkg_cmd_find ("info");
  6791. + if (packages)
  6792. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
  6793. + else
  6794. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
  6795. +
  6796. + ipkg_cb_status = NULL;
  6797. + ipkg_conf_deinit (&ipkg_conf);
  6798. + return (err);
  6799. +}
  6800. +
  6801. +
  6802. +int
  6803. +ipkg_packages_install (args_t * args, const char *name)
  6804. +{
  6805. + ipkg_cmd_t *cmd;
  6806. + ipkg_conf_t ipkg_conf;
  6807. + int err;
  6808. +
  6809. + /* this error should be handled in application */
  6810. + if (!name || !strlen (name))
  6811. + return (-1);
  6812. +
  6813. + err = ipkg_conf_init (&ipkg_conf, args);
  6814. + if (err)
  6815. + {
  6816. + return err;
  6817. + }
  6818. +
  6819. + /* we need to do this because of static declarations,
  6820. + * maybe a good idea to change */
  6821. + cmd = ipkg_cmd_find ("install");
  6822. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
  6823. +
  6824. + ipkg_conf_deinit(&ipkg_conf);
  6825. + return (err);
  6826. +}
  6827. +
  6828. +
  6829. +int
  6830. +ipkg_packages_remove(args_t *args, const char *name, int purge)
  6831. +{
  6832. + ipkg_cmd_t *cmd;
  6833. + ipkg_conf_t ipkg_conf;
  6834. + int err;
  6835. +
  6836. + /* this error should be handled in application */
  6837. + if (!name || !strlen (name))
  6838. + return (-1);
  6839. +
  6840. + err = ipkg_conf_init (&ipkg_conf, args);
  6841. + if (err)
  6842. + {
  6843. + return err;
  6844. + }
  6845. +
  6846. + /* we need to do this because of static declarations,
  6847. + * maybe a good idea to change */
  6848. + if (purge)
  6849. + cmd = ipkg_cmd_find ("purge");
  6850. + else
  6851. + cmd = ipkg_cmd_find ("remove");
  6852. +
  6853. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
  6854. +
  6855. + ipkg_conf_deinit(&ipkg_conf);
  6856. + return (err);
  6857. +}
  6858. +
  6859. +
  6860. +int
  6861. +ipkg_lists_update(args_t *args)
  6862. +{
  6863. + ipkg_cmd_t *cmd;
  6864. + ipkg_conf_t ipkg_conf;
  6865. + int err;
  6866. +
  6867. + err = ipkg_conf_init (&ipkg_conf, args);
  6868. + if (err)
  6869. + {
  6870. + return err;
  6871. + }
  6872. +
  6873. + /* we need to do this because of static declarations,
  6874. + * maybe a good idea to change */
  6875. + cmd = ipkg_cmd_find ("update");
  6876. +
  6877. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, NULL);
  6878. +
  6879. + ipkg_conf_deinit(&ipkg_conf);
  6880. + return (err);
  6881. +}
  6882. +
  6883. +
  6884. +int
  6885. +ipkg_packages_upgrade(args_t *args)
  6886. +{
  6887. + ipkg_cmd_t *cmd;
  6888. + ipkg_conf_t ipkg_conf;
  6889. + int err;
  6890. +
  6891. + err = ipkg_conf_init (&ipkg_conf, args);
  6892. + if (err)
  6893. + {
  6894. + return err;
  6895. + }
  6896. +
  6897. + /* we need to do this because of static declarations,
  6898. + * maybe a good idea to change */
  6899. + cmd = ipkg_cmd_find ("upgrade");
  6900. +
  6901. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, NULL);
  6902. +
  6903. + ipkg_conf_deinit(&ipkg_conf);
  6904. + return (err);
  6905. +}
  6906. +
  6907. +
  6908. +int
  6909. +ipkg_packages_download (args_t * args, const char *name)
  6910. +{
  6911. + ipkg_cmd_t *cmd;
  6912. + ipkg_conf_t ipkg_conf;
  6913. + int err;
  6914. +
  6915. + /* this error should be handled in application */
  6916. + if (!name || !strlen (name))
  6917. + return (-1);
  6918. +
  6919. + err = ipkg_conf_init (&ipkg_conf, args);
  6920. + if (err)
  6921. + {
  6922. + return err;
  6923. + }
  6924. +
  6925. + /* we need to do this because of static declarations,
  6926. + * maybe a good idea to change */
  6927. + cmd = ipkg_cmd_find ("download");
  6928. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
  6929. +
  6930. + ipkg_conf_deinit(&ipkg_conf);
  6931. + return (err);
  6932. +}
  6933. +
  6934. +
  6935. +int
  6936. +ipkg_package_files(args_t *args,
  6937. + const char *name,
  6938. + ipkg_list_callback cblist,
  6939. + void *userdata)
  6940. +{
  6941. + ipkg_cmd_t *cmd;
  6942. + ipkg_conf_t ipkg_conf;
  6943. + int err;
  6944. +
  6945. + /* this error should be handled in application */
  6946. + if (!name || !strlen (name))
  6947. + return (-1);
  6948. +
  6949. + err = ipkg_conf_init (&ipkg_conf, args);
  6950. + if (err)
  6951. + {
  6952. + return err;
  6953. + }
  6954. +
  6955. + ipkg_cb_list = cblist;
  6956. +
  6957. + /* we need to do this because of static declarations,
  6958. + * maybe a good idea to change */
  6959. + cmd = ipkg_cmd_find ("files");
  6960. +
  6961. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, userdata);
  6962. +
  6963. + ipkg_cb_list = NULL;
  6964. + ipkg_conf_deinit(&ipkg_conf);
  6965. + return (err);
  6966. +}
  6967. +
  6968. +
  6969. +int
  6970. +ipkg_file_search(args_t *args,
  6971. + const char *file,
  6972. + ipkg_list_callback cblist,
  6973. + void *userdata)
  6974. +{
  6975. + ipkg_cmd_t *cmd;
  6976. + ipkg_conf_t ipkg_conf;
  6977. + int err;
  6978. +
  6979. + /* this error should be handled in application */
  6980. + if (!file || !strlen (file))
  6981. + return (-1);
  6982. +
  6983. + err = ipkg_conf_init (&ipkg_conf, args);
  6984. + if (err)
  6985. + {
  6986. + return err;
  6987. + }
  6988. +
  6989. + ipkg_cb_list = cblist;
  6990. +
  6991. + /* we need to do this because of static declarations,
  6992. + * maybe a good idea to change */
  6993. + cmd = ipkg_cmd_find ("search");
  6994. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &file, userdata);
  6995. +
  6996. + ipkg_cb_list = NULL;
  6997. + ipkg_conf_deinit(&ipkg_conf);
  6998. + return(err);
  6999. +}
  7000. +
  7001. +
  7002. +int
  7003. +ipkg_file_what(args_t *args, const char *file, const char* command)
  7004. +{
  7005. + ipkg_cmd_t *cmd;
  7006. + ipkg_conf_t ipkg_conf;
  7007. + int err;
  7008. +
  7009. + /* this error should be handled in application */
  7010. + if (!file || !strlen (file))
  7011. + return (-1);
  7012. +
  7013. + err = ipkg_conf_init (&ipkg_conf, args);
  7014. + if (err)
  7015. + {
  7016. + return err;
  7017. + }
  7018. +
  7019. + /* we need to do this because of static declarations,
  7020. + * maybe a good idea to change */
  7021. + cmd = ipkg_cmd_find (command);
  7022. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &file, NULL);
  7023. +
  7024. + ipkg_conf_deinit(&ipkg_conf);
  7025. + return(err);
  7026. +}
  7027. +
  7028. +#define ipkg_package_whatdepends(args,file) ipkg_file_what(args,file,"whatdepends")
  7029. +#define ipkg_package_whatrecommends(args, file) ipkg_file_what(args,file,"whatrecommends")
  7030. +#define ipkg_package_whatprovides(args, file) ipkg_file_what(args,file,"whatprovides")
  7031. +#define ipkg_package_whatconflicts(args, file) ipkg_file_what(args,file,"whatconflicts")
  7032. +#define ipkg_package_whatreplaces(args, file) ipkg_file_what(args,file,"whatreplaces")
  7033. +
  7034. +
  7035. +int default_ipkg_message_callback(ipkg_conf_t *conf, message_level_t level,
  7036. + char *msg)
  7037. +{
  7038. + if (conf && (conf->verbosity < level)) {
  7039. + return 0;
  7040. + } else {
  7041. + if ( level == IPKG_ERROR )
  7042. + push_error_list(&error_list, msg);
  7043. + else
  7044. + printf(msg);
  7045. + }
  7046. + return 0;
  7047. +}
  7048. +
  7049. +int default_ipkg_list_callback(char *name, char *desc, char *version)
  7050. +{
  7051. + if (desc)
  7052. + printf("%s - %s - %s\n", name, version, desc);
  7053. + else
  7054. + printf("%s - %s\n", name, version);
  7055. + return 0;
  7056. +}
  7057. +
  7058. +int default_ipkg_files_callback(char *desc)
  7059. +{
  7060. + if (desc)
  7061. + printf("%s\n", desc);
  7062. + return 0;
  7063. +}
  7064. +
  7065. +int default_ipkg_status_callback(char *desc)
  7066. +{
  7067. + printf("%s\n", desc);
  7068. + return 0;
  7069. +}
  7070. +
  7071. +char* default_ipkg_response_callback(char *question)
  7072. +{
  7073. + char *response = NULL;
  7074. + printf(question);
  7075. + fflush(stdout);
  7076. + do {
  7077. + response = (char *)file_read_line_alloc(stdin);
  7078. + } while (response == NULL);
  7079. + return response;
  7080. +}
  7081. +
  7082. +/* This is used for backward compatibility */
  7083. +int
  7084. +ipkg_op (int argc, char *argv[])
  7085. +{
  7086. + int err, optind_;
  7087. + args_t args;
  7088. + char *cmd_name;
  7089. + ipkg_cmd_t *cmd;
  7090. + ipkg_conf_t ipkg_conf;
  7091. + const char *message = "ipkg must have one sub-command argument";
  7092. + FILE *f;
  7093. + struct mntent *mnt;
  7094. + int remountroot;
  7095. +
  7096. + args_init (&args);
  7097. +
  7098. + optind_ = args_parse (&args, argc, argv);
  7099. + if (optind_ == argc || optind_ < 0)
  7100. + {
  7101. + args_usage(message);
  7102. + }
  7103. +
  7104. + cmd_name = argv[optind_++];
  7105. +/* Pigi: added a flag to disable the checking of structures if the command does not need to
  7106. + read anything from there.
  7107. +*/
  7108. + if ( !strcmp(cmd_name,"print-architecture") ||
  7109. + !strcmp(cmd_name,"print_architecture") ||
  7110. + !strcmp(cmd_name,"print-installation-architecture") ||
  7111. + !strcmp(cmd_name,"print_installation_architecture") )
  7112. + args.nocheckfordirorfile = 1;
  7113. +
  7114. +/* Pigi: added a flag to disable the reading of feed files if the command does not need to
  7115. + read anything from there.
  7116. +*/
  7117. + if ( !strcmp(cmd_name,"flag") ||
  7118. + !strcmp(cmd_name,"configure") ||
  7119. + !strcmp(cmd_name,"remove") ||
  7120. + !strcmp(cmd_name,"files") ||
  7121. + !strcmp(cmd_name,"search") ||
  7122. + !strcmp(cmd_name,"compare_versions") ||
  7123. + !strcmp(cmd_name,"compare-versions") ||
  7124. + !strcmp(cmd_name,"list_installed") ||
  7125. + !strcmp(cmd_name,"list-installed") ||
  7126. + !strcmp(cmd_name,"status") )
  7127. + args.noreadfeedsfile = 1;
  7128. +
  7129. +
  7130. +
  7131. +
  7132. + err = ipkg_conf_init (&ipkg_conf, &args);
  7133. + if (err)
  7134. + {
  7135. + return err;
  7136. + }
  7137. +
  7138. + args_deinit (&args);
  7139. +
  7140. + ipkg_cb_message = default_ipkg_message_callback;
  7141. + ipkg_cb_response = default_ipkg_response_callback;
  7142. + ipkg_cb_status = (ipkg_status_callback)default_ipkg_status_callback;
  7143. + if ( strcmp(cmd_name, "files")==0)
  7144. + ipkg_cb_list = (ipkg_list_callback)default_ipkg_files_callback;
  7145. + else
  7146. + ipkg_cb_list = (ipkg_list_callback)default_ipkg_list_callback;
  7147. +
  7148. + cmd = ipkg_cmd_find (cmd_name);
  7149. + if (cmd == NULL)
  7150. + {
  7151. + fprintf (stderr, "%s: unknown sub-command %s\n", argv[0],
  7152. + cmd_name);
  7153. + args_usage (NULL);
  7154. + }
  7155. +
  7156. + if (cmd->requires_args && optind_ == argc)
  7157. + {
  7158. + fprintf (stderr,
  7159. + "%s: the ``%s'' command requires at least one argument\n",
  7160. + __FUNCTION__, cmd_name);
  7161. + args_usage (NULL);
  7162. + }
  7163. +
  7164. + remountroot = 0;
  7165. + /* check if /dev/root is mounted read-only */
  7166. + if ((f = setmntent("/proc/mounts", "r")) == NULL)
  7167. + fprintf (stderr, "Checking /proc/mounts failed\n");
  7168. +
  7169. + while ((mnt = getmntent(f)) != NULL) {
  7170. + if (strcmp(mnt->mnt_fsname, "/dev/root") == 0 &&
  7171. + hasmntopt(mnt, MNTOPT_RO) != NULL) {
  7172. + remountroot = 1;
  7173. + }
  7174. + }
  7175. +
  7176. + endmntent(f);
  7177. +
  7178. + if (remountroot) {
  7179. + if ( !strcmp(cmd_name,"install") ||
  7180. + !strcmp(cmd_name,"update") ||
  7181. + !strcmp(cmd_name,"upgrade") ||
  7182. + !strcmp(cmd_name,"flag") ||
  7183. + !strcmp(cmd_name,"configure") ||
  7184. + !strcmp(cmd_name,"remove") ) {
  7185. + /* mount rootfs read-write */
  7186. + if (mount("","/",0,MS_REMOUNT,0)<0)
  7187. + fprintf (stderr, "Mounting rootfs read-write failed\n");
  7188. + }
  7189. + }
  7190. +
  7191. + err = ipkg_cmd_exec (cmd, &ipkg_conf, argc - optind_, (const char **) (argv + optind_), NULL);
  7192. +
  7193. + ipkg_conf_deinit (&ipkg_conf);
  7194. +
  7195. + if (remountroot) {
  7196. + if ( !strcmp(cmd_name,"install") ||
  7197. + !strcmp(cmd_name,"update") ||
  7198. + !strcmp(cmd_name,"upgrade") ||
  7199. + !strcmp(cmd_name,"flag") ||
  7200. + !strcmp(cmd_name,"configure") ||
  7201. + !strcmp(cmd_name,"remove") ) {
  7202. + sync();
  7203. + /* mount rootfs read-only */
  7204. + if (mount("","/",0,MS_REMOUNT|MS_RDONLY,0)<0)
  7205. + fprintf (stderr, "Mounting rootfs read-only failed\n");
  7206. + }
  7207. + }
  7208. +
  7209. + /* check if cfgfs exists */
  7210. + if (access("/sbin/cfgfs", X_OK) == 0) {
  7211. + if ( !strcmp(cmd_name,"install") ||
  7212. + !strcmp(cmd_name,"update") ||
  7213. + !strcmp(cmd_name,"upgrade")) {
  7214. + if (system("cfgfs status -q") != 0) {
  7215. + fprintf (stdout, "Updates in /etc, please review changes\n");
  7216. + fprintf (stdout, "You can check via cfgfs status\n");
  7217. + }
  7218. + }
  7219. + }
  7220. +
  7221. + return err;
  7222. +}
  7223. diff -Nur busybox-1.17.2.orig/archival/libipkg/libipkg.h busybox-1.17.2/archival/libipkg/libipkg.h
  7224. --- busybox-1.17.2.orig/archival/libipkg/libipkg.h 1970-01-01 01:00:00.000000000 +0100
  7225. +++ busybox-1.17.2/archival/libipkg/libipkg.h 2010-12-01 22:25:23.000000000 +0100
  7226. @@ -0,0 +1,78 @@
  7227. +/* ipkglib.h - the itsy package management system
  7228. +
  7229. + Florian Boor <florian.boor@kernelconcepts.de>
  7230. +
  7231. + This program is free software; you can redistribute it and/or
  7232. + modify it under the terms of the GNU General Public License as
  7233. + published by the Free Software Foundation; either version 2, or (at
  7234. + your option) any later version.
  7235. +
  7236. + This program is distributed in the hope that it will be useful, but
  7237. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7238. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7239. + General Public License for more details.
  7240. +*/
  7241. +
  7242. +#ifndef IPKGLIB_H
  7243. +#define IPKGLIB_H
  7244. +
  7245. +#include "ipkg_conf.h"
  7246. +#include "ipkg_message.h"
  7247. +
  7248. +#include "args.h"
  7249. +#include "pkg.h"
  7250. +
  7251. +typedef int (*ipkg_message_callback)(ipkg_conf_t *conf, message_level_t level,
  7252. + char *msg);
  7253. +typedef int (*ipkg_list_callback)(char *name, char *desc, char *version,
  7254. + pkg_state_status_t status, void *userdata);
  7255. +typedef int (*ipkg_status_callback)(char *name, int istatus, char *desc,
  7256. + void *userdata);
  7257. +typedef char* (*ipkg_response_callback)(char *question);
  7258. +
  7259. +extern int ipkg_op(int argc, char *argv[]); /* ipkglib.c */
  7260. +extern int ipkg_init (ipkg_message_callback mcall,
  7261. + ipkg_response_callback rcall,
  7262. + args_t * args);
  7263. +
  7264. +extern int ipkg_deinit (args_t *args);
  7265. +extern int ipkg_packages_list(args_t *args,
  7266. + const char *packages,
  7267. + ipkg_list_callback cblist,
  7268. + void *userdata);
  7269. +extern int ipkg_packages_status(args_t *args,
  7270. + const char *packages,
  7271. + ipkg_status_callback cbstatus,
  7272. + void *userdata);
  7273. +extern int ipkg_packages_info(args_t *args,
  7274. + const char *packages,
  7275. + ipkg_status_callback cbstatus,
  7276. + void *userdata);
  7277. +extern int ipkg_packages_install(args_t *args, const char *name);
  7278. +extern int ipkg_packages_remove(args_t *args, const char *name, int purge);
  7279. +extern int ipkg_lists_update(args_t *args);
  7280. +extern int ipkg_packages_upgrade(args_t *args);
  7281. +extern int ipkg_packages_download(args_t *args, const char *name);
  7282. +extern int ipkg_package_files(args_t *args,
  7283. + const char *name,
  7284. + ipkg_list_callback cblist,
  7285. + void *userdata);
  7286. +extern int ipkg_file_search(args_t *args,
  7287. + const char *file,
  7288. + ipkg_list_callback cblist,
  7289. + void *userdata);
  7290. +extern int ipkg_package_whatdepends(args_t *args, const char *file);
  7291. +extern int ipkg_package_whatrecommends(args_t *args, const char *file);
  7292. +extern int ipkg_package_whatprovides(args_t *args, const char *file);
  7293. +extern int ipkg_package_whatconflicts(args_t *args, const char *file);
  7294. +extern int ipkg_package_whatreplaces(args_t *args, const char *file);
  7295. +
  7296. +extern ipkg_message_callback ipkg_cb_message; /* ipkglib.c */
  7297. +extern ipkg_response_callback ipkg_cb_response;
  7298. +extern ipkg_status_callback ipkg_cb_status;
  7299. +extern ipkg_list_callback ipkg_cb_list;
  7300. +extern void push_error_list(struct errlist **errors,char * msg);
  7301. +extern void reverse_error_list(struct errlist **errors);
  7302. +extern void free_error_list(struct errlist **errors);
  7303. +
  7304. +#endif
  7305. diff -Nur busybox-1.17.2.orig/archival/libipkg/nv_pair.c busybox-1.17.2/archival/libipkg/nv_pair.c
  7306. --- busybox-1.17.2.orig/archival/libipkg/nv_pair.c 1970-01-01 01:00:00.000000000 +0100
  7307. +++ busybox-1.17.2/archival/libipkg/nv_pair.c 2010-12-01 22:25:23.000000000 +0100
  7308. @@ -0,0 +1,40 @@
  7309. +/* nv_pair.c - the itsy package management system
  7310. +
  7311. + Carl D. Worth
  7312. +
  7313. + Copyright (C) 2001 University of Southern California
  7314. +
  7315. + This program is free software; you can redistribute it and/or
  7316. + modify it under the terms of the GNU General Public License as
  7317. + published by the Free Software Foundation; either version 2, or (at
  7318. + your option) any later version.
  7319. +
  7320. + This program is distributed in the hope that it will be useful, but
  7321. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7322. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7323. + General Public License for more details.
  7324. +*/
  7325. +
  7326. +#include "ipkg.h"
  7327. +
  7328. +#include "nv_pair.h"
  7329. +#include "str_util.h"
  7330. +
  7331. +int nv_pair_init(nv_pair_t *nv_pair, const char *name, const char *value)
  7332. +{
  7333. + nv_pair->name = str_dup_safe(name);
  7334. + nv_pair->value = str_dup_safe(value);
  7335. +
  7336. + return 0;
  7337. +}
  7338. +
  7339. +void nv_pair_deinit(nv_pair_t *nv_pair)
  7340. +{
  7341. + free(nv_pair->name);
  7342. + nv_pair->name = NULL;
  7343. +
  7344. + free(nv_pair->value);
  7345. + nv_pair->value = NULL;
  7346. +}
  7347. +
  7348. +
  7349. diff -Nur busybox-1.17.2.orig/archival/libipkg/nv_pair.h busybox-1.17.2/archival/libipkg/nv_pair.h
  7350. --- busybox-1.17.2.orig/archival/libipkg/nv_pair.h 1970-01-01 01:00:00.000000000 +0100
  7351. +++ busybox-1.17.2/archival/libipkg/nv_pair.h 2010-12-01 22:25:23.000000000 +0100
  7352. @@ -0,0 +1,32 @@
  7353. +/* nv_pair.h - the itsy package management system
  7354. +
  7355. + Carl D. Worth
  7356. +
  7357. + Copyright (C) 2001 University of Southern California
  7358. +
  7359. + This program is free software; you can redistribute it and/or
  7360. + modify it under the terms of the GNU General Public License as
  7361. + published by the Free Software Foundation; either version 2, or (at
  7362. + your option) any later version.
  7363. +
  7364. + This program is distributed in the hope that it will be useful, but
  7365. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7366. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7367. + General Public License for more details.
  7368. +*/
  7369. +
  7370. +#ifndef NV_PAIR_H
  7371. +#define NV_PAIR_H
  7372. +
  7373. +typedef struct nv_pair nv_pair_t;
  7374. +struct nv_pair
  7375. +{
  7376. + char *name;
  7377. + char *value;
  7378. +};
  7379. +
  7380. +int nv_pair_init(nv_pair_t *nv_pair, const char *name, const char *value);
  7381. +void nv_pair_deinit(nv_pair_t *nv_pair);
  7382. +
  7383. +#endif
  7384. +
  7385. diff -Nur busybox-1.17.2.orig/archival/libipkg/nv_pair_list.c busybox-1.17.2/archival/libipkg/nv_pair_list.c
  7386. --- busybox-1.17.2.orig/archival/libipkg/nv_pair_list.c 1970-01-01 01:00:00.000000000 +0100
  7387. +++ busybox-1.17.2/archival/libipkg/nv_pair_list.c 2010-12-01 22:25:23.000000000 +0100
  7388. @@ -0,0 +1,98 @@
  7389. +/* nv_pair_list.c - the itsy package management system
  7390. +
  7391. + Carl D. Worth
  7392. +
  7393. + Copyright (C) 2001 University of Southern California
  7394. +
  7395. + This program is free software; you can redistribute it and/or
  7396. + modify it under the terms of the GNU General Public License as
  7397. + published by the Free Software Foundation; either version 2, or (at
  7398. + your option) any later version.
  7399. +
  7400. + This program is distributed in the hope that it will be useful, but
  7401. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7402. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7403. + General Public License for more details.
  7404. +*/
  7405. +
  7406. +#include "ipkg.h"
  7407. +
  7408. +#include "nv_pair.h"
  7409. +#include "void_list.h"
  7410. +#include "nv_pair_list.h"
  7411. +
  7412. +int nv_pair_list_elt_init(nv_pair_list_elt_t *elt, nv_pair_t *data)
  7413. +{
  7414. + return void_list_elt_init((void_list_elt_t *) elt, data);
  7415. +}
  7416. +
  7417. +void nv_pair_list_elt_deinit(nv_pair_list_elt_t *elt)
  7418. +{
  7419. + void_list_elt_deinit((void_list_elt_t *) elt);
  7420. +}
  7421. +
  7422. +int nv_pair_list_init(nv_pair_list_t *list)
  7423. +{
  7424. + return void_list_init((void_list_t *) list);
  7425. +}
  7426. +
  7427. +void nv_pair_list_deinit(nv_pair_list_t *list)
  7428. +{
  7429. + nv_pair_list_elt_t *iter;
  7430. + nv_pair_t *nv_pair;
  7431. +
  7432. + for (iter = list->head; iter; iter = iter->next) {
  7433. + nv_pair = iter->data;
  7434. + nv_pair_deinit(nv_pair);
  7435. +
  7436. + /* malloced in nv_pair_list_append */
  7437. + free(nv_pair);
  7438. + iter->data = NULL;
  7439. + }
  7440. + void_list_deinit((void_list_t *) list);
  7441. +}
  7442. +
  7443. +nv_pair_t *nv_pair_list_append(nv_pair_list_t *list, const char *name, const char *value)
  7444. +{
  7445. + int err;
  7446. +
  7447. + /* freed in nv_pair_list_deinit */
  7448. + nv_pair_t *nv_pair = malloc(sizeof(nv_pair_t));
  7449. +
  7450. + if (nv_pair == NULL) {
  7451. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  7452. + return NULL;
  7453. + }
  7454. + nv_pair_init(nv_pair, name, value);
  7455. +
  7456. + err = void_list_append((void_list_t *) list, nv_pair);
  7457. + if (err) {
  7458. + return NULL;
  7459. + }
  7460. +
  7461. + return nv_pair;
  7462. +}
  7463. +
  7464. +int nv_pair_list_push(nv_pair_list_t *list, nv_pair_t *data)
  7465. +{
  7466. + return void_list_push((void_list_t *) list, data);
  7467. +}
  7468. +
  7469. +nv_pair_list_elt_t *nv_pair_list_pop(nv_pair_list_t *list)
  7470. +{
  7471. + return (nv_pair_list_elt_t *) void_list_pop((void_list_t *) list);
  7472. +}
  7473. +
  7474. +char *nv_pair_list_find(nv_pair_list_t *list, char *name)
  7475. +{
  7476. + nv_pair_list_elt_t *iter;
  7477. + nv_pair_t *nv_pair;
  7478. +
  7479. + for (iter = list->head; iter; iter = iter->next) {
  7480. + nv_pair = iter->data;
  7481. + if (strcmp(nv_pair->name, name) == 0) {
  7482. + return nv_pair->value;
  7483. + }
  7484. + }
  7485. + return NULL;
  7486. +}
  7487. diff -Nur busybox-1.17.2.orig/archival/libipkg/nv_pair_list.h busybox-1.17.2/archival/libipkg/nv_pair_list.h
  7488. --- busybox-1.17.2.orig/archival/libipkg/nv_pair_list.h 1970-01-01 01:00:00.000000000 +0100
  7489. +++ busybox-1.17.2/archival/libipkg/nv_pair_list.h 2010-12-01 22:25:23.000000000 +0100
  7490. @@ -0,0 +1,60 @@
  7491. +/* nv_pair_list.h - the itsy package management system
  7492. +
  7493. + Carl D. Worth
  7494. +
  7495. + Copyright (C) 2001 University of Southern California
  7496. +
  7497. + This program is free software; you can redistribute it and/or
  7498. + modify it under the terms of the GNU General Public License as
  7499. + published by the Free Software Foundation; either version 2, or (at
  7500. + your option) any later version.
  7501. +
  7502. + This program is distributed in the hope that it will be useful, but
  7503. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7504. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7505. + General Public License for more details.
  7506. +*/
  7507. +
  7508. +#ifndef NV_PAIR_LIST_H
  7509. +#define NV_PAIR_LIST_H
  7510. +
  7511. +#include "nv_pair.h"
  7512. +#include "void_list.h"
  7513. +
  7514. +typedef struct nv_pair_list_elt nv_pair_list_elt_t;
  7515. +struct nv_pair_list_elt
  7516. +{
  7517. + nv_pair_list_elt_t *next;
  7518. + nv_pair_t *data;
  7519. +};
  7520. +
  7521. +typedef struct nv_pair_list nv_pair_list_t;
  7522. +struct nv_pair_list
  7523. +{
  7524. + nv_pair_list_elt_t pre_head;
  7525. + nv_pair_list_elt_t *head;
  7526. + nv_pair_list_elt_t *tail;
  7527. +};
  7528. +
  7529. +static inline int nv_pair_list_empty(nv_pair_list_t *list)
  7530. +{
  7531. + if (list->head == NULL)
  7532. + return 1;
  7533. + else
  7534. + return 0;
  7535. +}
  7536. +
  7537. +int nv_pair_list_elt_init(nv_pair_list_elt_t *elt, nv_pair_t *data);
  7538. +void nv_pair_list_elt_deinit(nv_pair_list_elt_t *elt);
  7539. +
  7540. +int nv_pair_list_init(nv_pair_list_t *list);
  7541. +void nv_pair_list_deinit(nv_pair_list_t *list);
  7542. +
  7543. +nv_pair_t *nv_pair_list_append(nv_pair_list_t *list,
  7544. + const char *name, const char *value);
  7545. +int nv_pair_list_push(nv_pair_list_t *list, nv_pair_t *data);
  7546. +nv_pair_list_elt_t *nv_pair_list_pop(nv_pair_list_t *list);
  7547. +char *nv_pair_list_find(nv_pair_list_t *list, char *name);
  7548. +
  7549. +#endif
  7550. +
  7551. diff -Nur busybox-1.17.2.orig/archival/libipkg/pkg.c busybox-1.17.2/archival/libipkg/pkg.c
  7552. --- busybox-1.17.2.orig/archival/libipkg/pkg.c 1970-01-01 01:00:00.000000000 +0100
  7553. +++ busybox-1.17.2/archival/libipkg/pkg.c 2010-12-01 22:25:23.000000000 +0100
  7554. @@ -0,0 +1,1757 @@
  7555. +/* pkg.c - the itsy package management system
  7556. +
  7557. + Carl D. Worth
  7558. +
  7559. + Copyright (C) 2001 University of Southern California
  7560. +
  7561. + This program is free software; you can redistribute it and/or
  7562. + modify it under the terms of the GNU General Public License as
  7563. + published by the Free Software Foundation; either version 2, or (at
  7564. + your option) any later version.
  7565. +
  7566. + This program is distributed in the hope that it will be useful, but
  7567. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7568. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7569. + General Public License for more details.
  7570. +*/
  7571. +
  7572. +#include "ipkg.h"
  7573. +#include <ctype.h>
  7574. +#include <string.h>
  7575. +#include <errno.h>
  7576. +
  7577. +#include "pkg.h"
  7578. +
  7579. +#include "pkg_parse.h"
  7580. +#include "pkg_extract.h"
  7581. +#include "ipkg_message.h"
  7582. +#include "ipkg_utils.h"
  7583. +
  7584. +#include "sprintf_alloc.h"
  7585. +#include "file_util.h"
  7586. +#include "str_util.h"
  7587. +#include "xsystem.h"
  7588. +#include "ipkg_conf.h"
  7589. +
  7590. +int pkg_get_arch_priority(ipkg_conf_t *conf, const char *archname);
  7591. +void pkg_write_filelist_helper(const char *key, void *entry_, void *data_);
  7592. +
  7593. +typedef struct enum_map enum_map_t;
  7594. +struct enum_map
  7595. +{
  7596. + int value;
  7597. + const char *str;
  7598. +};
  7599. +
  7600. +static const enum_map_t pkg_state_want_map[] = {
  7601. + { SW_UNKNOWN, "unknown"},
  7602. + { SW_INSTALL, "install"},
  7603. + { SW_DEINSTALL, "deinstall"},
  7604. + { SW_PURGE, "purge"}
  7605. +};
  7606. +
  7607. +static const enum_map_t pkg_state_flag_map[] = {
  7608. + { SF_OK, "ok"},
  7609. + { SF_REINSTREQ, "reinstreq"},
  7610. + { SF_HOLD, "hold"},
  7611. + { SF_REPLACE, "replace"},
  7612. + { SF_NOPRUNE, "noprune"},
  7613. + { SF_PREFER, "prefer"},
  7614. + { SF_OBSOLETE, "obsolete"},
  7615. + { SF_USER, "user"},
  7616. +};
  7617. +
  7618. +static const enum_map_t pkg_state_status_map[] = {
  7619. + { SS_NOT_INSTALLED, "not-installed" },
  7620. + { SS_UNPACKED, "unpacked" },
  7621. + { SS_HALF_CONFIGURED, "half-configured" },
  7622. + { SS_INSTALLED, "installed" },
  7623. + { SS_HALF_INSTALLED, "half-installed" },
  7624. + { SS_CONFIG_FILES, "config-files" },
  7625. + { SS_POST_INST_FAILED, "post-inst-failed" },
  7626. + { SS_REMOVAL_FAILED, "removal-failed" }
  7627. +};
  7628. +
  7629. +static int verrevcmp(const char *val, const char *ref);
  7630. +
  7631. +
  7632. +pkg_t *pkg_new(void)
  7633. +{
  7634. + pkg_t *pkg;
  7635. +
  7636. + pkg = malloc(sizeof(pkg_t));
  7637. + if (pkg == NULL) {
  7638. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  7639. + return NULL;
  7640. + }
  7641. +
  7642. + pkg_init(pkg);
  7643. +
  7644. + return pkg;
  7645. +}
  7646. +
  7647. +int pkg_init(pkg_t *pkg)
  7648. +{
  7649. + memset(pkg, 0, sizeof(pkg_t));
  7650. + pkg->name = NULL;
  7651. + pkg->epoch = 0;
  7652. + pkg->version = NULL;
  7653. + pkg->revision = NULL;
  7654. + pkg->familiar_revision = NULL;
  7655. + pkg->dest = NULL;
  7656. + pkg->src = NULL;
  7657. + pkg->architecture = NULL;
  7658. + pkg->maintainer = NULL;
  7659. + pkg->section = NULL;
  7660. + pkg->description = NULL;
  7661. + pkg->state_want = SW_UNKNOWN;
  7662. + pkg->state_flag = SF_OK;
  7663. + pkg->state_status = SS_NOT_INSTALLED;
  7664. + pkg->depends_str = NULL;
  7665. + pkg->provides_str = NULL;
  7666. + pkg->depends_count = 0;
  7667. + pkg->depends = NULL;
  7668. + pkg->suggests_str = NULL;
  7669. + pkg->recommends_str = NULL;
  7670. + pkg->suggests_count = 0;
  7671. + pkg->recommends_count = 0;
  7672. +
  7673. + /* Abhaya: added init for conflicts fields */
  7674. + pkg->conflicts = NULL;
  7675. + pkg->conflicts_count = 0;
  7676. +
  7677. + /* added for replaces. Jamey 7/23/2002 */
  7678. + pkg->replaces = NULL;
  7679. + pkg->replaces_count = 0;
  7680. +
  7681. + pkg->pre_depends_count = 0;
  7682. + pkg->pre_depends_str = NULL;
  7683. + pkg->provides_count = 0;
  7684. + pkg->provides = NULL;
  7685. + pkg->filename = NULL;
  7686. + pkg->local_filename = NULL;
  7687. + pkg->tmp_unpack_dir = NULL;
  7688. + pkg->md5sum = NULL;
  7689. + pkg->size = NULL;
  7690. + pkg->installed_size = NULL;
  7691. + pkg->priority = NULL;
  7692. + pkg->source = NULL;
  7693. + conffile_list_init(&pkg->conffiles);
  7694. + pkg->installed_files = NULL;
  7695. + pkg->installed_files_ref_cnt = 0;
  7696. + pkg->essential = 0;
  7697. + pkg->provided_by_hand = 0;
  7698. +
  7699. + return 0;
  7700. +}
  7701. +
  7702. +void pkg_deinit(pkg_t *pkg)
  7703. +{
  7704. + free(pkg->name);
  7705. + pkg->name = NULL;
  7706. + pkg->epoch = 0;
  7707. + free(pkg->version);
  7708. + pkg->version = NULL;
  7709. + /* revision and familiar_revision share storage with version, so
  7710. + don't free */
  7711. + pkg->revision = NULL;
  7712. + pkg->familiar_revision = NULL;
  7713. + /* owned by ipkg_conf_t */
  7714. + pkg->dest = NULL;
  7715. + /* owned by ipkg_conf_t */
  7716. + pkg->src = NULL;
  7717. + free(pkg->architecture);
  7718. + pkg->architecture = NULL;
  7719. + free(pkg->maintainer);
  7720. + pkg->maintainer = NULL;
  7721. + free(pkg->section);
  7722. + pkg->section = NULL;
  7723. + free(pkg->description);
  7724. + pkg->description = NULL;
  7725. + pkg->state_want = SW_UNKNOWN;
  7726. + pkg->state_flag = SF_OK;
  7727. + pkg->state_status = SS_NOT_INSTALLED;
  7728. + free(pkg->depends_str);
  7729. + pkg->depends_str = NULL;
  7730. + free(pkg->provides_str);
  7731. + pkg->provides_str = NULL;
  7732. + pkg->depends_count = 0;
  7733. + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->depends ? */
  7734. + pkg->pre_depends_count = 0;
  7735. + free(pkg->pre_depends_str);
  7736. + pkg->pre_depends_str = NULL;
  7737. + pkg->provides_count = 0;
  7738. + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->provides ? */
  7739. + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->suggests ? */
  7740. + free(pkg->filename);
  7741. + pkg->filename = NULL;
  7742. + free(pkg->local_filename);
  7743. + pkg->local_filename = NULL;
  7744. + /* CLEANUP: It'd be nice to pullin the cleanup function from
  7745. + ipkg_install.c here. See comment in
  7746. + ipkg_install.c:cleanup_temporary_files */
  7747. + free(pkg->tmp_unpack_dir);
  7748. + pkg->tmp_unpack_dir = NULL;
  7749. + free(pkg->md5sum);
  7750. + pkg->md5sum = NULL;
  7751. + free(pkg->size);
  7752. + pkg->size = NULL;
  7753. + free(pkg->installed_size);
  7754. + pkg->installed_size = NULL;
  7755. + free(pkg->priority);
  7756. + pkg->priority = NULL;
  7757. + free(pkg->source);
  7758. + pkg->source = NULL;
  7759. + conffile_list_deinit(&pkg->conffiles);
  7760. + /* XXX: QUESTION: Is forcing this to 1 correct? I suppose so,
  7761. + since if they are calling deinit, they should know. Maybe do an
  7762. + assertion here instead? */
  7763. + pkg->installed_files_ref_cnt = 1;
  7764. + pkg_free_installed_files(pkg);
  7765. + pkg->essential = 0;
  7766. +}
  7767. +
  7768. +int pkg_init_from_file(pkg_t *pkg, const char *filename)
  7769. +{
  7770. + int err;
  7771. + char **raw;
  7772. + FILE *control_file;
  7773. +
  7774. + err = pkg_init(pkg);
  7775. + if (err) { return err; }
  7776. +
  7777. + pkg->local_filename = strdup(filename);
  7778. +
  7779. + control_file = tmpfile();
  7780. + err = pkg_extract_control_file_to_stream(pkg, control_file);
  7781. + if (err) { return err; }
  7782. +
  7783. + rewind(control_file);
  7784. + raw = read_raw_pkgs_from_stream(control_file);
  7785. + pkg_parse_raw(pkg, &raw, NULL, NULL);
  7786. +
  7787. + fclose(control_file);
  7788. +
  7789. + return 0;
  7790. +}
  7791. +
  7792. +/* Merge any new information in newpkg into oldpkg */
  7793. +/* XXX: CLEANUP: This function shouldn't actually modify anything in
  7794. + newpkg, but should leave it usable. This rework is so that
  7795. + pkg_hash_insert doesn't clobber the pkg that you pass into it. */
  7796. +/*
  7797. + * uh, i thought that i had originally written this so that it took
  7798. + * two pkgs and returned a new one? we can do that again... -sma
  7799. + */
  7800. +int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status)
  7801. +{
  7802. + if (oldpkg == newpkg) {
  7803. + return 0;
  7804. + }
  7805. +
  7806. + if (!oldpkg->src)
  7807. + oldpkg->src = newpkg->src;
  7808. + if (!oldpkg->dest)
  7809. + oldpkg->dest = newpkg->dest;
  7810. + if (!oldpkg->architecture)
  7811. + oldpkg->architecture = str_dup_safe(newpkg->architecture);
  7812. + if (!oldpkg->arch_priority)
  7813. + oldpkg->arch_priority = newpkg->arch_priority;
  7814. + if (!oldpkg->section)
  7815. + oldpkg->section = str_dup_safe(newpkg->section);
  7816. + if(!oldpkg->maintainer)
  7817. + oldpkg->maintainer = str_dup_safe(newpkg->maintainer);
  7818. + if(!oldpkg->description)
  7819. + oldpkg->description = str_dup_safe(newpkg->description);
  7820. + if (set_status) {
  7821. + /* merge the state_flags from the new package */
  7822. + oldpkg->state_want = newpkg->state_want;
  7823. + oldpkg->state_status = newpkg->state_status;
  7824. + oldpkg->state_flag = newpkg->state_flag;
  7825. + } else {
  7826. + if (oldpkg->state_want == SW_UNKNOWN)
  7827. + oldpkg->state_want = newpkg->state_want;
  7828. + if (oldpkg->state_status == SS_NOT_INSTALLED)
  7829. + oldpkg->state_status = newpkg->state_status;
  7830. + oldpkg->state_flag |= newpkg->state_flag;
  7831. + }
  7832. +
  7833. + if (!oldpkg->depends_str && !oldpkg->pre_depends_str && !oldpkg->recommends_str && !oldpkg->suggests_str) {
  7834. + oldpkg->depends_str = newpkg->depends_str;
  7835. + newpkg->depends_str = NULL;
  7836. + oldpkg->depends_count = newpkg->depends_count;
  7837. + newpkg->depends_count = 0;
  7838. +
  7839. + oldpkg->depends = newpkg->depends;
  7840. + newpkg->depends = NULL;
  7841. +
  7842. + oldpkg->pre_depends_str = newpkg->pre_depends_str;
  7843. + newpkg->pre_depends_str = NULL;
  7844. + oldpkg->pre_depends_count = newpkg->pre_depends_count;
  7845. + newpkg->pre_depends_count = 0;
  7846. +
  7847. + oldpkg->recommends_str = newpkg->recommends_str;
  7848. + newpkg->recommends_str = NULL;
  7849. + oldpkg->recommends_count = newpkg->recommends_count;
  7850. + newpkg->recommends_count = 0;
  7851. +
  7852. + oldpkg->suggests_str = newpkg->suggests_str;
  7853. + newpkg->suggests_str = NULL;
  7854. + oldpkg->suggests_count = newpkg->suggests_count;
  7855. + newpkg->suggests_count = 0;
  7856. + }
  7857. +
  7858. + if (!oldpkg->provides_str) {
  7859. + oldpkg->provides_str = newpkg->provides_str;
  7860. + newpkg->provides_str = NULL;
  7861. + oldpkg->provides_count = newpkg->provides_count;
  7862. + newpkg->provides_count = 0;
  7863. +
  7864. + oldpkg->provides = newpkg->provides;
  7865. + newpkg->provides = NULL;
  7866. + }
  7867. +
  7868. + if (!oldpkg->conflicts_str) {
  7869. + oldpkg->conflicts_str = newpkg->conflicts_str;
  7870. + newpkg->conflicts_str = NULL;
  7871. + oldpkg->conflicts_count = newpkg->conflicts_count;
  7872. + newpkg->conflicts_count = 0;
  7873. +
  7874. + oldpkg->conflicts = newpkg->conflicts;
  7875. + newpkg->conflicts = NULL;
  7876. + }
  7877. +
  7878. + if (!oldpkg->replaces_str) {
  7879. + oldpkg->replaces_str = newpkg->replaces_str;
  7880. + newpkg->replaces_str = NULL;
  7881. + oldpkg->replaces_count = newpkg->replaces_count;
  7882. + newpkg->replaces_count = 0;
  7883. +
  7884. + oldpkg->replaces = newpkg->replaces;
  7885. + newpkg->replaces = NULL;
  7886. + }
  7887. +
  7888. + if (!oldpkg->filename)
  7889. + oldpkg->filename = str_dup_safe(newpkg->filename);
  7890. + if (0)
  7891. + fprintf(stdout, "pkg=%s old local_filename=%s new local_filename=%s\n",
  7892. + oldpkg->name, oldpkg->local_filename, newpkg->local_filename);
  7893. + if (!oldpkg->local_filename)
  7894. + oldpkg->local_filename = str_dup_safe(newpkg->local_filename);
  7895. + if (!oldpkg->tmp_unpack_dir)
  7896. + oldpkg->tmp_unpack_dir = str_dup_safe(newpkg->tmp_unpack_dir);
  7897. + if (!oldpkg->md5sum)
  7898. + oldpkg->md5sum = str_dup_safe(newpkg->md5sum);
  7899. + if (!oldpkg->size)
  7900. + oldpkg->size = str_dup_safe(newpkg->size);
  7901. + if (!oldpkg->installed_size)
  7902. + oldpkg->installed_size = str_dup_safe(newpkg->installed_size);
  7903. + if (!oldpkg->priority)
  7904. + oldpkg->priority = str_dup_safe(newpkg->priority);
  7905. + if (!oldpkg->source)
  7906. + oldpkg->source = str_dup_safe(newpkg->source);
  7907. + if (oldpkg->conffiles.head == NULL){
  7908. + oldpkg->conffiles = newpkg->conffiles;
  7909. + conffile_list_init(&newpkg->conffiles);
  7910. + }
  7911. + if (!oldpkg->installed_files){
  7912. + oldpkg->installed_files = newpkg->installed_files;
  7913. + oldpkg->installed_files_ref_cnt = newpkg->installed_files_ref_cnt;
  7914. + newpkg->installed_files = NULL;
  7915. + }
  7916. + if (!oldpkg->essential)
  7917. + oldpkg->essential = newpkg->essential;
  7918. +
  7919. + return 0;
  7920. +}
  7921. +
  7922. +abstract_pkg_t *abstract_pkg_new(void)
  7923. +{
  7924. + abstract_pkg_t * ab_pkg;
  7925. +
  7926. + ab_pkg = malloc(sizeof(abstract_pkg_t));
  7927. +
  7928. + if (ab_pkg == NULL) {
  7929. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  7930. + return NULL;
  7931. + }
  7932. +
  7933. + if ( abstract_pkg_init(ab_pkg) < 0 )
  7934. + return NULL;
  7935. +
  7936. + return ab_pkg;
  7937. +}
  7938. +
  7939. +int abstract_pkg_init(abstract_pkg_t *ab_pkg)
  7940. +{
  7941. + memset(ab_pkg, 0, sizeof(abstract_pkg_t));
  7942. +
  7943. + ab_pkg->provided_by = abstract_pkg_vec_alloc();
  7944. + if (ab_pkg->provided_by==NULL){
  7945. + return -1;
  7946. + }
  7947. + ab_pkg->dependencies_checked = 0;
  7948. + ab_pkg->state_status = SS_NOT_INSTALLED;
  7949. +
  7950. + return 0;
  7951. +}
  7952. +
  7953. +void set_flags_from_control(ipkg_conf_t *conf, pkg_t *pkg){
  7954. + char * temp_str;
  7955. + char **raw =NULL;
  7956. + char **raw_start=NULL;
  7957. +
  7958. + temp_str = (char *) malloc (strlen(pkg->dest->info_dir)+strlen(pkg->name)+12);
  7959. + if (temp_str == NULL ){
  7960. + ipkg_message(conf, IPKG_INFO, "Out of memory in %s\n", __FUNCTION__);
  7961. + return;
  7962. + }
  7963. + sprintf( temp_str,"%s/%s.control",pkg->dest->info_dir,pkg->name);
  7964. +
  7965. + raw = raw_start = read_raw_pkgs_from_file(temp_str);
  7966. + if (raw == NULL ){
  7967. + ipkg_message(conf, IPKG_ERROR, "Unable to open the control file in %s\n", __FUNCTION__);
  7968. + return;
  7969. + }
  7970. +
  7971. + while(*raw){
  7972. + if (!pkg_valorize_other_field(pkg, &raw ) == 0) {
  7973. + ipkg_message(conf, IPKG_DEBUG, "unable to read control file for %s. May be empty\n", pkg->name);
  7974. + }
  7975. + }
  7976. + raw = raw_start;
  7977. + while (*raw) {
  7978. + if (raw!=NULL)
  7979. + free(*raw++);
  7980. + }
  7981. +
  7982. + free(raw_start);
  7983. + free(temp_str);
  7984. +
  7985. + return ;
  7986. +
  7987. +}
  7988. +
  7989. +char * pkg_formatted_info(pkg_t *pkg )
  7990. +{
  7991. + char *line;
  7992. + char * buff;
  7993. +
  7994. + buff = malloc(8192);
  7995. + if (buff == NULL) {
  7996. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  7997. + return NULL;
  7998. + }
  7999. +
  8000. + buff[0] = '\0';
  8001. +
  8002. + line = pkg_formatted_field(pkg, "Package");
  8003. + strncat(buff ,line, strlen(line));
  8004. + free(line);
  8005. +
  8006. + line = pkg_formatted_field(pkg, "Version");
  8007. + strncat(buff ,line, strlen(line));
  8008. + free(line);
  8009. +
  8010. + line = pkg_formatted_field(pkg, "Depends");
  8011. + strncat(buff ,line, strlen(line));
  8012. + free(line);
  8013. +
  8014. + line = pkg_formatted_field(pkg, "Recommends");
  8015. + strncat(buff ,line, strlen(line));
  8016. + free(line);
  8017. +
  8018. + line = pkg_formatted_field(pkg, "Suggests");
  8019. + strncat(buff ,line, strlen(line));
  8020. + free(line);
  8021. +
  8022. + line = pkg_formatted_field(pkg, "Provides");
  8023. + strncat(buff ,line, strlen(line));
  8024. + free(line);
  8025. +
  8026. + line = pkg_formatted_field(pkg, "Replaces");
  8027. + strncat(buff ,line, strlen(line));
  8028. + free(line);
  8029. +
  8030. + line = pkg_formatted_field(pkg, "Conflicts");
  8031. + strncat(buff ,line, strlen(line));
  8032. + free(line);
  8033. +
  8034. + line = pkg_formatted_field(pkg, "Status");
  8035. + strncat(buff ,line, strlen(line));
  8036. + free(line);
  8037. +
  8038. + line = pkg_formatted_field(pkg, "Section");
  8039. + strncat(buff ,line, strlen(line));
  8040. + free(line);
  8041. +
  8042. + line = pkg_formatted_field(pkg, "Essential"); /* @@@@ should be removed in future release. *//* I do not agree with this Pigi*/
  8043. + strncat(buff ,line, strlen(line));
  8044. + free(line);
  8045. +
  8046. + line = pkg_formatted_field(pkg, "Architecture");
  8047. + strncat(buff ,line, strlen(line));
  8048. + free(line);
  8049. +
  8050. + line = pkg_formatted_field(pkg, "Maintainer");
  8051. + strncat(buff ,line, strlen(line));
  8052. + free(line);
  8053. +
  8054. + line = pkg_formatted_field(pkg, "MD5sum");
  8055. + strncat(buff ,line, strlen(line));
  8056. + free(line);
  8057. +
  8058. + line = pkg_formatted_field(pkg, "Size");
  8059. + strncat(buff ,line, strlen(line));
  8060. + free(line);
  8061. +
  8062. + line = pkg_formatted_field(pkg, "Filename");
  8063. + strncat(buff ,line, strlen(line));
  8064. + free(line);
  8065. +
  8066. + line = pkg_formatted_field(pkg, "Conffiles");
  8067. + strncat(buff ,line, strlen(line));
  8068. + free(line);
  8069. +
  8070. + line = pkg_formatted_field(pkg, "Source");
  8071. + strncat(buff ,line, strlen(line));
  8072. + free(line);
  8073. +
  8074. + line = pkg_formatted_field(pkg, "Description");
  8075. + strncat(buff ,line, strlen(line));
  8076. + free(line);
  8077. +
  8078. + line = pkg_formatted_field(pkg, "Installed-Time");
  8079. + strncat(buff ,line, strlen(line));
  8080. + free(line);
  8081. +
  8082. + return buff;
  8083. +}
  8084. +
  8085. +char * pkg_formatted_field(pkg_t *pkg, const char *field )
  8086. +{
  8087. + static size_t LINE_LEN = 128;
  8088. + char * temp = (char *)malloc(1);
  8089. + int len = 0;
  8090. + int flag_provide_false = 0;
  8091. +
  8092. +/*
  8093. + Pigi: After some discussion with Florian we decided to modify the full procedure in
  8094. + dynamic memory allocation. This should avoid any other segv in this area ( except for bugs )
  8095. +*/
  8096. +
  8097. + if (strlen(field) < PKG_MINIMUM_FIELD_NAME_LEN) {
  8098. + goto UNKNOWN_FMT_FIELD;
  8099. + }
  8100. +
  8101. + temp[0]='\0';
  8102. +
  8103. + switch (field[0])
  8104. + {
  8105. + case 'a':
  8106. + case 'A':
  8107. + if (strcasecmp(field, "Architecture") == 0) {
  8108. + /* Architecture */
  8109. + if (pkg->architecture) {
  8110. + temp = (char *)realloc(temp,strlen(pkg->architecture)+17);
  8111. + if ( temp == NULL ){
  8112. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8113. + return NULL;
  8114. + }
  8115. + temp[0]='\0';
  8116. + snprintf(temp, (strlen(pkg->architecture)+17), "Architecture: %s\n", pkg->architecture);
  8117. + }
  8118. + } else {
  8119. + goto UNKNOWN_FMT_FIELD;
  8120. + }
  8121. + break;
  8122. + case 'c':
  8123. + case 'C':
  8124. + if (strcasecmp(field, "Conffiles") == 0) {
  8125. + /* Conffiles */
  8126. + conffile_list_elt_t *iter;
  8127. + char confstr_[LINE_LEN];
  8128. +
  8129. + if (pkg->conffiles.head == NULL) {
  8130. + return temp;
  8131. + }
  8132. +
  8133. + len = 14 ;
  8134. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  8135. + if (iter->data->name && iter->data->value) {
  8136. + len = len + (strlen(iter->data->name)+strlen(iter->data->value)+5);
  8137. + }
  8138. + }
  8139. + temp = (char *)realloc(temp,len);
  8140. + if ( temp == NULL ){
  8141. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8142. + return NULL;
  8143. + }
  8144. + temp[0]='\0';
  8145. + strncpy(temp, "Conffiles:\n", 12);
  8146. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  8147. + if (iter->data->name && iter->data->value) {
  8148. + snprintf(confstr_, LINE_LEN, "%s %s\n", iter->data->name, iter->data->value);
  8149. + strncat(temp, confstr_, strlen(confstr_));
  8150. + }
  8151. + }
  8152. + } else if (strcasecmp(field, "Conflicts") == 0) {
  8153. + int i;
  8154. +
  8155. + if (pkg->conflicts_count) {
  8156. + char conflictstr[LINE_LEN];
  8157. + len = 14 ;
  8158. + for(i = 0; i < pkg->conflicts_count; i++) {
  8159. + len = len + (strlen(pkg->conflicts_str[i])+5);
  8160. + }
  8161. + temp = (char *)realloc(temp,len);
  8162. + if ( temp == NULL ){
  8163. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8164. + return NULL;
  8165. + }
  8166. + temp[0]='\0';
  8167. + strncpy(temp, "Conflicts:", 11);
  8168. + for(i = 0; i < pkg->conflicts_count; i++) {
  8169. + snprintf(conflictstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->conflicts_str[i]);
  8170. + strncat(temp, conflictstr, strlen(conflictstr));
  8171. + }
  8172. + strncat(temp, "\n", strlen("\n"));
  8173. + }
  8174. + } else {
  8175. + goto UNKNOWN_FMT_FIELD;
  8176. + }
  8177. + break;
  8178. + case 'd':
  8179. + case 'D':
  8180. + if (strcasecmp(field, "Depends") == 0) {
  8181. + /* Depends */
  8182. + int i;
  8183. +
  8184. + if (pkg->depends_count) {
  8185. + char depstr[LINE_LEN];
  8186. + len = 14 ;
  8187. + for(i = 0; i < pkg->depends_count; i++) {
  8188. + len = len + (strlen(pkg->depends_str[i])+4);
  8189. + }
  8190. + temp = (char *)realloc(temp,len);
  8191. + if ( temp == NULL ){
  8192. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8193. + return NULL;
  8194. + }
  8195. + temp[0]='\0';
  8196. + strncpy(temp, "Depends:", 10);
  8197. + for(i = 0; i < pkg->depends_count; i++) {
  8198. + snprintf(depstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->depends_str[i]);
  8199. + strncat(temp, depstr, strlen(depstr));
  8200. + }
  8201. + strncat(temp, "\n", strlen("\n"));
  8202. + }
  8203. + } else if (strcasecmp(field, "Description") == 0) {
  8204. + /* Description */
  8205. + if (pkg->description) {
  8206. + temp = (char *)realloc(temp,strlen(pkg->description)+16);
  8207. + if ( temp == NULL ){
  8208. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8209. + return NULL;
  8210. + }
  8211. + temp[0]='\0';
  8212. + snprintf(temp, (strlen(pkg->description)+16), "Description: %s\n", pkg->description);
  8213. + }
  8214. + } else {
  8215. + goto UNKNOWN_FMT_FIELD;
  8216. + }
  8217. + break;
  8218. + case 'e':
  8219. + case 'E': {
  8220. + /* Essential */
  8221. + if (pkg->essential) {
  8222. + temp = (char *)realloc(temp,16);
  8223. + if ( temp == NULL ){
  8224. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8225. + return NULL;
  8226. + }
  8227. + temp[0]='\0';
  8228. + snprintf(temp, (16), "Essential: yes\n");
  8229. + }
  8230. + }
  8231. + break;
  8232. + case 'f':
  8233. + case 'F': {
  8234. + /* Filename */
  8235. + if (pkg->filename) {
  8236. + temp = (char *)realloc(temp,strlen(pkg->filename)+12);
  8237. + if ( temp == NULL ){
  8238. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8239. + return NULL;
  8240. + }
  8241. + temp[0]='\0';
  8242. + snprintf(temp, (strlen(pkg->filename)+12), "Filename: %s\n", pkg->filename);
  8243. + }
  8244. + }
  8245. + break;
  8246. + case 'i':
  8247. + case 'I': {
  8248. + if (strcasecmp(field, "Installed-Size") == 0) {
  8249. + /* Installed-Size */
  8250. + temp = (char *)realloc(temp,strlen(pkg->installed_size)+17);
  8251. + if ( temp == NULL ){
  8252. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8253. + return NULL;
  8254. + }
  8255. + temp[0]='\0';
  8256. + snprintf(temp, (strlen(pkg->installed_size)+17), "Installed-Size: %s\n", pkg->installed_size);
  8257. + } else if (strcasecmp(field, "Installed-Time") == 0 && pkg->installed_time) {
  8258. + temp = (char *)realloc(temp,29);
  8259. + if ( temp == NULL ){
  8260. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8261. + return NULL;
  8262. + }
  8263. + temp[0]='\0';
  8264. + snprintf(temp, 29, "Installed-Time: %lu\n", pkg->installed_time);
  8265. + }
  8266. + }
  8267. + break;
  8268. + case 'm':
  8269. + case 'M': {
  8270. + /* Maintainer | MD5sum */
  8271. + if (strcasecmp(field, "Maintainer") == 0) {
  8272. + /* Maintainer */
  8273. + if (pkg->maintainer) {
  8274. + temp = (char *)realloc(temp,strlen(pkg->maintainer)+14);
  8275. + if ( temp == NULL ){
  8276. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8277. + return NULL;
  8278. + }
  8279. + temp[0]='\0';
  8280. + snprintf(temp, (strlen(pkg->maintainer)+14), "maintainer: %s\n", pkg->maintainer);
  8281. + }
  8282. + } else if (strcasecmp(field, "MD5sum") == 0) {
  8283. + /* MD5sum */
  8284. + if (pkg->md5sum) {
  8285. + temp = (char *)realloc(temp,strlen(pkg->md5sum)+11);
  8286. + if ( temp == NULL ){
  8287. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8288. + return NULL;
  8289. + }
  8290. + temp[0]='\0';
  8291. + snprintf(temp, (strlen(pkg->md5sum)+11), "MD5Sum: %s\n", pkg->md5sum);
  8292. + }
  8293. + } else {
  8294. + goto UNKNOWN_FMT_FIELD;
  8295. + }
  8296. + }
  8297. + break;
  8298. + case 'p':
  8299. + case 'P': {
  8300. + if (strcasecmp(field, "Package") == 0) {
  8301. + /* Package */
  8302. + temp = (char *)realloc(temp,strlen(pkg->name)+11);
  8303. + if ( temp == NULL ){
  8304. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8305. + return NULL;
  8306. + }
  8307. + temp[0]='\0';
  8308. + snprintf(temp, (strlen(pkg->name)+11), "Package: %s\n", pkg->name);
  8309. + } else if (strcasecmp(field, "Priority") == 0) {
  8310. + /* Priority */
  8311. + temp = (char *)realloc(temp,strlen(pkg->priority)+12);
  8312. + if ( temp == NULL ){
  8313. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8314. + return NULL;
  8315. + }
  8316. + temp[0]='\0';
  8317. + snprintf(temp, (strlen(pkg->priority)+12), "Priority: %s\n", pkg->priority);
  8318. + } else if (strcasecmp(field, "Provides") == 0) {
  8319. + /* Provides */
  8320. + int i;
  8321. +
  8322. + if (pkg->provides_count) {
  8323. + /* Here we check if the ipkg_internal_use_only is used, and we discard it.*/
  8324. + for ( i=0; i < pkg->provides_count; i++ ){
  8325. + if (strstr(pkg->provides_str[i],"ipkg_internal_use_only")!=NULL) {
  8326. + memset (pkg->provides_str[i],'\x0',strlen(pkg->provides_str[i])); /* Pigi clear my trick flag, just in case */
  8327. + flag_provide_false = 1;
  8328. + }
  8329. + }
  8330. + if ( !flag_provide_false || /* Pigi there is not my trick flag */
  8331. + ((flag_provide_false) && (pkg->provides_count > 1))){ /* Pigi There is, but we also have others Provides */
  8332. + char provstr[LINE_LEN];
  8333. + len = 15;
  8334. + for(i = 0; i < pkg->provides_count; i++) {
  8335. + len = len + (strlen(pkg->provides_str[i])+5);
  8336. + }
  8337. + temp = (char *)realloc(temp,len);
  8338. + if ( temp == NULL ){
  8339. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8340. + return NULL;
  8341. + }
  8342. + temp[0]='\0';
  8343. + strncpy(temp, "Provides:", 12);
  8344. + for(i = 0; i < pkg->provides_count; i++) {
  8345. + if (strlen(pkg->provides_str[i])>0){;
  8346. + snprintf(provstr, LINE_LEN, "%s %s", i == 1 ? "" : ",", pkg->provides_str[i]);
  8347. + strncat(temp, provstr, strlen(provstr));
  8348. + }
  8349. + }
  8350. + strncat(temp, "\n", strlen("\n"));
  8351. + }
  8352. + }
  8353. + } else {
  8354. + goto UNKNOWN_FMT_FIELD;
  8355. + }
  8356. + }
  8357. + break;
  8358. + case 'r':
  8359. + case 'R': {
  8360. + int i;
  8361. + /* Replaces | Recommends*/
  8362. + if (strcasecmp (field, "Replaces") == 0) {
  8363. + if (pkg->replaces_count) {
  8364. + char replstr[LINE_LEN];
  8365. + len = 14;
  8366. + for (i = 0; i < pkg->replaces_count; i++) {
  8367. + len = len + (strlen(pkg->replaces_str[i])+5);
  8368. + }
  8369. + temp = (char *)realloc(temp,len);
  8370. + if ( temp == NULL ){
  8371. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8372. + return NULL;
  8373. + }
  8374. + temp[0]='\0';
  8375. + strncpy(temp, "Replaces:", 12);
  8376. + for (i = 0; i < pkg->replaces_count; i++) {
  8377. + snprintf(replstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->replaces_str[i]);
  8378. + strncat(temp, replstr, strlen(replstr));
  8379. + }
  8380. + strncat(temp, "\n", strlen("\n"));
  8381. + }
  8382. + } else if (strcasecmp (field, "Recommends") == 0) {
  8383. + if (pkg->recommends_count) {
  8384. + char recstr[LINE_LEN];
  8385. + len = 15;
  8386. + for(i = 0; i < pkg->recommends_count; i++) {
  8387. + len = len + (strlen( pkg->recommends_str[i])+5);
  8388. + }
  8389. + temp = (char *)realloc(temp,len);
  8390. + if ( temp == NULL ){
  8391. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8392. + return NULL;
  8393. + }
  8394. + temp[0]='\0';
  8395. + strncpy(temp, "Recommends:", 13);
  8396. + for(i = 0; i < pkg->recommends_count; i++) {
  8397. + snprintf(recstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->recommends_str[i]);
  8398. + strncat(temp, recstr, strlen(recstr));
  8399. + }
  8400. + strncat(temp, "\n", strlen("\n"));
  8401. + }
  8402. + } else {
  8403. + goto UNKNOWN_FMT_FIELD;
  8404. + }
  8405. + }
  8406. + break;
  8407. + case 's':
  8408. + case 'S': {
  8409. + /* Section | Size | Source | Status | Suggests */
  8410. + if (strcasecmp(field, "Section") == 0) {
  8411. + /* Section */
  8412. + if (pkg->section) {
  8413. + temp = (char *)realloc(temp,strlen(pkg->section)+11);
  8414. + if ( temp == NULL ){
  8415. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8416. + return NULL;
  8417. + }
  8418. + temp[0]='\0';
  8419. + snprintf(temp, (strlen(pkg->section)+11), "Section: %s\n", pkg->section);
  8420. + }
  8421. + } else if (strcasecmp(field, "Size") == 0) {
  8422. + /* Size */
  8423. + if (pkg->size) {
  8424. + temp = (char *)realloc(temp,strlen(pkg->size)+8);
  8425. + if ( temp == NULL ){
  8426. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8427. + return NULL;
  8428. + }
  8429. + temp[0]='\0';
  8430. + snprintf(temp, (strlen(pkg->size)+8), "Size: %s\n", pkg->size);
  8431. + }
  8432. + } else if (strcasecmp(field, "Source") == 0) {
  8433. + /* Source */
  8434. + if (pkg->source) {
  8435. + temp = (char *)realloc(temp,strlen(pkg->source)+10);
  8436. + if ( temp == NULL ){
  8437. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8438. + return NULL;
  8439. + }
  8440. + temp[0]='\0';
  8441. + snprintf(temp, (strlen(pkg->source)+10), "Source: %s\n", pkg->source);
  8442. + }
  8443. + } else if (strcasecmp(field, "Status") == 0) {
  8444. + /* Status */
  8445. + /* Benjamin Pineau note: we should avoid direct usage of
  8446. + * strlen(arg) without keeping "arg" for later free()
  8447. + */
  8448. + char *pflag=pkg_state_flag_to_str(pkg->state_flag);
  8449. + char *pstat=pkg_state_status_to_str(pkg->state_status);
  8450. + char *pwant=pkg_state_want_to_str(pkg->state_want);
  8451. +
  8452. + size_t sum_of_sizes = (size_t) ( strlen(pwant)+ strlen(pflag)+ strlen(pstat) + 12 );
  8453. + temp = (char *)realloc(temp,sum_of_sizes);
  8454. + if ( temp == NULL ){
  8455. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8456. + return NULL;
  8457. + }
  8458. + temp[0]='\0';
  8459. + snprintf(temp, sum_of_sizes , "Status: %s %s %s\n", pwant, pflag, pstat);
  8460. + free(pflag);
  8461. + free(pwant);
  8462. + if(pstat) /* pfstat can be NULL if ENOMEM */
  8463. + free(pstat);
  8464. + } else if (strcasecmp(field, "Suggests") == 0) {
  8465. + if (pkg->suggests_count) {
  8466. + int i;
  8467. + char sugstr[LINE_LEN];
  8468. + len = 13;
  8469. + for(i = 0; i < pkg->suggests_count; i++) {
  8470. + len = len + (strlen(pkg->suggests_str[i])+5);
  8471. + }
  8472. + temp = (char *)realloc(temp,len);
  8473. + if ( temp == NULL ){
  8474. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8475. + return NULL;
  8476. + }
  8477. + temp[0]='\0';
  8478. + strncpy(temp, "Suggests:", 10);
  8479. + for(i = 0; i < pkg->suggests_count; i++) {
  8480. + snprintf(sugstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->suggests_str[i]);
  8481. + strncat(temp, sugstr, strlen(sugstr));
  8482. + }
  8483. + strncat(temp, "\n", strlen("\n"));
  8484. + }
  8485. + } else {
  8486. + goto UNKNOWN_FMT_FIELD;
  8487. + }
  8488. + }
  8489. + break;
  8490. + case 'v':
  8491. + case 'V': {
  8492. + /* Version */
  8493. + char *version = pkg_version_str_alloc(pkg);
  8494. + temp = (char *)realloc(temp,strlen(version)+14);
  8495. + if ( temp == NULL ){
  8496. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8497. + return NULL;
  8498. + }
  8499. + temp[0]='\0';
  8500. + snprintf(temp, (strlen(version)+12), "Version: %s\n", version);
  8501. + free(version);
  8502. + }
  8503. + break;
  8504. + default:
  8505. + goto UNKNOWN_FMT_FIELD;
  8506. + }
  8507. +
  8508. + if ( strlen(temp)<2 ) {
  8509. + temp[0]='\0';
  8510. + }
  8511. + return temp;
  8512. +
  8513. + UNKNOWN_FMT_FIELD:
  8514. + fprintf(stderr, "%s: ERROR: Unknown field name: %s\n", __FUNCTION__, field);
  8515. + if ( strlen(temp)<2 ) {
  8516. + temp[0]='\0';
  8517. + }
  8518. +
  8519. + return temp;
  8520. +}
  8521. +
  8522. +void pkg_print_info(pkg_t *pkg, FILE *file)
  8523. +{
  8524. + char * buff;
  8525. + if (pkg == NULL) {
  8526. + return;
  8527. + }
  8528. +
  8529. + buff = pkg_formatted_info(pkg);
  8530. + if ( buff == NULL )
  8531. + return;
  8532. + if (strlen(buff)>2){
  8533. + fwrite(buff, 1, strlen(buff), file);
  8534. + }
  8535. + free(buff);
  8536. +}
  8537. +
  8538. +void pkg_print_status(pkg_t * pkg, FILE * file)
  8539. +{
  8540. + if (pkg == NULL) {
  8541. + return;
  8542. + }
  8543. +
  8544. + /* XXX: QUESTION: Do we actually want more fields here? The
  8545. + original idea was to save space by installing only what was
  8546. + needed for actual computation, (package, version, status,
  8547. + essential, conffiles). The assumption is that all other fields
  8548. + can be found in th available file.
  8549. +
  8550. + But, someone proposed the idea to make it possible to
  8551. + reconstruct a .ipk from an installed package, (ie. for beaming
  8552. + from one handheld to another). So, maybe we actually want a few
  8553. + more fields here, (depends, suggests, etc.), so that that would
  8554. + be guaranteed to work even in the absence of more information
  8555. + from the available file.
  8556. +
  8557. + 28-MAR-03: kergoth and I discussed this yesterday. We think
  8558. + the essential info needs to be here for all installed packages
  8559. + because they may not appear in the Packages files on various
  8560. + feeds. Furthermore, one should be able to install from URL or
  8561. + local storage without requiring a Packages file from any feed.
  8562. + -Jamey
  8563. + */
  8564. + pkg_print_field(pkg, file, "Package");
  8565. + pkg_print_field(pkg, file, "Version");
  8566. + pkg_print_field(pkg, file, "Depends");
  8567. + pkg_print_field(pkg, file, "Recommends");
  8568. + pkg_print_field(pkg, file, "Suggests");
  8569. + pkg_print_field(pkg, file, "Provides");
  8570. + pkg_print_field(pkg, file, "Replaces");
  8571. + pkg_print_field(pkg, file, "Conflicts");
  8572. + pkg_print_field(pkg, file, "Status");
  8573. + pkg_print_field(pkg, file, "Essential"); /* @@@@ should be removed in future release. */
  8574. + pkg_print_field(pkg, file, "Architecture");
  8575. + pkg_print_field(pkg, file, "Conffiles");
  8576. + pkg_print_field(pkg, file, "Installed-Time");
  8577. + fputs("\n", file);
  8578. +}
  8579. +
  8580. +void pkg_print_field(pkg_t *pkg, FILE *file, const char *field)
  8581. +{
  8582. + char *buff;
  8583. + if (strlen(field) < PKG_MINIMUM_FIELD_NAME_LEN) {
  8584. + fprintf(stderr, "%s: ERROR: Unknown field name: %s\n",
  8585. + __FUNCTION__, field);
  8586. + }
  8587. + buff = pkg_formatted_field(pkg, field);
  8588. + if (strlen(buff)>2) {
  8589. + fprintf(file, "%s", buff);
  8590. + fflush(file);
  8591. + }
  8592. + free(buff);
  8593. + return;
  8594. +}
  8595. +
  8596. +/*
  8597. + * libdpkg - Debian packaging suite library routines
  8598. + * vercmp.c - comparison of version numbers
  8599. + *
  8600. + * Copyright (C) 1995 Ian Jackson <iwj10@cus.cam.ac.uk>
  8601. + */
  8602. +int pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg)
  8603. +{
  8604. + int r;
  8605. +
  8606. + if (pkg->epoch > ref_pkg->epoch) {
  8607. + return 1;
  8608. + }
  8609. +
  8610. + if (pkg->epoch < ref_pkg->epoch) {
  8611. + return -1;
  8612. + }
  8613. +
  8614. + r = verrevcmp(pkg->version, ref_pkg->version);
  8615. + if (r) {
  8616. + return r;
  8617. + }
  8618. +
  8619. +#ifdef USE_DEBVERSION
  8620. + r = verrevcmp(pkg->revision, ref_pkg->revision);
  8621. + if (r) {
  8622. + return r;
  8623. + }
  8624. +
  8625. + r = verrevcmp(pkg->familiar_revision, ref_pkg->familiar_revision);
  8626. +#endif
  8627. +
  8628. + return r;
  8629. +}
  8630. +
  8631. +int verrevcmp(const char *val, const char *ref)
  8632. +{
  8633. + int vc, rc;
  8634. + long vl, rl;
  8635. + const char *vp, *rp;
  8636. + const char *vsep, *rsep;
  8637. +
  8638. + if (!val) val= "";
  8639. + if (!ref) ref= "";
  8640. + for (;;) {
  8641. + vp= val; while (*vp && !isdigit(*vp)) vp++;
  8642. + rp= ref; while (*rp && !isdigit(*rp)) rp++;
  8643. + for (;;) {
  8644. + vc= (val == vp) ? 0 : *val++;
  8645. + rc= (ref == rp) ? 0 : *ref++;
  8646. + if (!rc && !vc) break;
  8647. + if (vc && !isalpha(vc)) vc += 256; /* assumes ASCII character set */
  8648. + if (rc && !isalpha(rc)) rc += 256;
  8649. + if (vc != rc) return vc - rc;
  8650. + }
  8651. + val= vp;
  8652. + ref= rp;
  8653. + vl=0; if (isdigit(*vp)) vl= strtol(val,(char**)&val,10);
  8654. + rl=0; if (isdigit(*rp)) rl= strtol(ref,(char**)&ref,10);
  8655. + if (vl != rl) return vl - rl;
  8656. +
  8657. + vc = *val;
  8658. + rc = *ref;
  8659. + vsep = strchr(".-", vc);
  8660. + rsep = strchr(".-", rc);
  8661. + if (vsep && !rsep) return -1;
  8662. + if (!vsep && rsep) return +1;
  8663. +
  8664. + if (!*val && !*ref) return 0;
  8665. + if (!*val) return -1;
  8666. + if (!*ref) return +1;
  8667. + }
  8668. +}
  8669. +
  8670. +int pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op)
  8671. +{
  8672. + int r;
  8673. +
  8674. + r = pkg_compare_versions(it, ref);
  8675. +
  8676. + if (strcmp(op, "<=") == 0 || strcmp(op, "<") == 0) {
  8677. + return r <= 0;
  8678. + }
  8679. +
  8680. + if (strcmp(op, ">=") == 0 || strcmp(op, ">") == 0) {
  8681. + return r >= 0;
  8682. + }
  8683. +
  8684. + if (strcmp(op, "<<") == 0) {
  8685. + return r < 0;
  8686. + }
  8687. +
  8688. + if (strcmp(op, ">>") == 0) {
  8689. + return r > 0;
  8690. + }
  8691. +
  8692. + if (strcmp(op, "=") == 0) {
  8693. + return r == 0;
  8694. + }
  8695. +
  8696. + fprintf(stderr, "unknown operator: %s", op);
  8697. + return 0;
  8698. +}
  8699. +
  8700. +int pkg_name_version_and_architecture_compare(pkg_t *p1, pkg_t *p2)
  8701. +{
  8702. + const pkg_t *a = *(const pkg_t **)p1;
  8703. + const pkg_t *b = *(const pkg_t **)p2;
  8704. + int namecmp;
  8705. + int vercmp;
  8706. + if (!a->name || !b->name) {
  8707. + fprintf(stderr, "pkg_name_version_and_architecture_compare: a=%p a->name=%p b=%p b->name=%p\n",
  8708. + a, a->name, b, b->name);
  8709. + return 0;
  8710. + }
  8711. +
  8712. + namecmp = strcmp(a->name, b->name);
  8713. + if (namecmp)
  8714. + return namecmp;
  8715. + vercmp = pkg_compare_versions(a, b);
  8716. + if (vercmp)
  8717. + return vercmp;
  8718. + if (!a->arch_priority || !b->arch_priority) {
  8719. + fprintf(stderr, "pkg_name_version_and_architecture_compare: a=%p a->arch_priority=%i b=%p b->arch_priority=%i\n",
  8720. + a, a->arch_priority, b, b->arch_priority);
  8721. + return 0;
  8722. + }
  8723. + if (a->arch_priority > b->arch_priority)
  8724. + return 1;
  8725. + if (a->arch_priority < b->arch_priority)
  8726. + return -1;
  8727. + return 0;
  8728. +}
  8729. +
  8730. +int abstract_pkg_name_compare(abstract_pkg_t *p1, abstract_pkg_t *p2)
  8731. +{
  8732. + const abstract_pkg_t *a = *(const abstract_pkg_t **)p1;
  8733. + const abstract_pkg_t *b = *(const abstract_pkg_t **)p2;
  8734. + if (!a->name || !b->name) {
  8735. + fprintf(stderr, "abstract_pkg_name_compare: a=%p a->name=%p b=%p b->name=%p\n",
  8736. + a, a->name, b, b->name);
  8737. + return 0;
  8738. + }
  8739. + return strcmp(a->name, b->name);
  8740. +}
  8741. +
  8742. +
  8743. +char *pkg_version_str_alloc(pkg_t *pkg)
  8744. +{
  8745. + char *complete_version;
  8746. + char *epoch_str;
  8747. +#ifdef USE_DEBVERSION
  8748. + char *revision_str;
  8749. + char *familiar_revision_str;
  8750. +#endif
  8751. +
  8752. + if (pkg->epoch) {
  8753. + sprintf_alloc(&epoch_str, "%lu:", (unsigned long)pkg->epoch);
  8754. + } else {
  8755. + epoch_str = strdup("");
  8756. + }
  8757. +
  8758. +#ifdef USE_DEBVERSION
  8759. + if (pkg->revision && strlen(pkg->revision)) {
  8760. + sprintf_alloc(&revision_str, "-%s", pkg->revision);
  8761. + } else {
  8762. + revision_str = strdup("");
  8763. + }
  8764. +
  8765. + if (pkg->familiar_revision && strlen(pkg->familiar_revision)) {
  8766. + sprintf_alloc(&familiar_revision_str, "-fam%s", pkg->familiar_revision);
  8767. + } else {
  8768. + familiar_revision_str = strdup("");
  8769. + }
  8770. +#endif
  8771. +
  8772. +#ifdef USE_DEBVERSION
  8773. + sprintf_alloc(&complete_version, "%s%s%s%s",
  8774. + epoch_str, pkg->version, revision_str, familiar_revision_str);
  8775. +#else
  8776. + sprintf_alloc(&complete_version, "%s%s",
  8777. + epoch_str, pkg->version);
  8778. +#endif
  8779. +
  8780. + free(epoch_str);
  8781. +#ifdef USE_DEBVERSION
  8782. + free(revision_str);
  8783. + free(familiar_revision_str);
  8784. +#endif
  8785. +
  8786. + return complete_version;
  8787. +}
  8788. +
  8789. +str_list_t *pkg_get_installed_files(pkg_t *pkg)
  8790. +{
  8791. + int err;
  8792. + char *list_file_name = NULL;
  8793. + FILE *list_file = NULL;
  8794. + char *line;
  8795. + char *installed_file_name;
  8796. + int rootdirlen;
  8797. +
  8798. + pkg->installed_files_ref_cnt++;
  8799. +
  8800. + if (pkg->installed_files) {
  8801. + return pkg->installed_files;
  8802. + }
  8803. +
  8804. + pkg->installed_files = str_list_alloc();
  8805. + if (pkg->installed_files == NULL) {
  8806. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8807. + return NULL;
  8808. + }
  8809. +
  8810. + /* For uninstalled packages, get the file list firectly from the package.
  8811. + For installed packages, look at the package.list file in the database.
  8812. + */
  8813. + if (pkg->state_status == SS_NOT_INSTALLED || pkg->dest == NULL) {
  8814. + if (pkg->local_filename == NULL) {
  8815. + return pkg->installed_files;
  8816. + }
  8817. + /* XXX: CLEANUP: Maybe rewrite this to avoid using a temporary
  8818. + file. In other words, change deb_extract so that it can
  8819. + simply return the file list as a char *[] rather than
  8820. + insisting on writing in to a FILE * as it does now. */
  8821. + list_file = tmpfile();
  8822. + err = pkg_extract_data_file_names_to_stream(pkg, list_file);
  8823. + if (err) {
  8824. + fclose(list_file);
  8825. + fprintf(stderr, "%s: Error extracting file list from %s: %s\n",
  8826. + __FUNCTION__, pkg->local_filename, strerror(err));
  8827. + return pkg->installed_files;
  8828. + }
  8829. + rewind(list_file);
  8830. + } else {
  8831. + sprintf_alloc(&list_file_name, "%s/%s.list",
  8832. + pkg->dest->info_dir, pkg->name);
  8833. + if (! file_exists(list_file_name)) {
  8834. + free(list_file_name);
  8835. + return pkg->installed_files;
  8836. + }
  8837. +
  8838. + list_file = fopen(list_file_name, "r");
  8839. + if (list_file == NULL) {
  8840. + fprintf(stderr, "WARNING: Cannot open %s: %s\n",
  8841. + list_file_name, strerror(errno));
  8842. + free(list_file_name);
  8843. + return pkg->installed_files;
  8844. + }
  8845. + free(list_file_name);
  8846. + }
  8847. +
  8848. + rootdirlen = strlen( pkg->dest->root_dir );
  8849. + while (1) {
  8850. + char *file_name;
  8851. +
  8852. + line = file_read_line_alloc(list_file);
  8853. + if (line == NULL) {
  8854. + break;
  8855. + }
  8856. + str_chomp(line);
  8857. + file_name = line;
  8858. +
  8859. + /* Take pains to avoid uglies like "/./" in the middle of file_name. */
  8860. + if( strncmp( pkg->dest->root_dir,
  8861. + file_name,
  8862. + rootdirlen ) ) {
  8863. + if (*file_name == '.') {
  8864. + file_name++;
  8865. + }
  8866. + if (*file_name == '/') {
  8867. + file_name++;
  8868. + }
  8869. +
  8870. + /* Freed in pkg_free_installed_files */
  8871. + sprintf_alloc(&installed_file_name, "%s%s", pkg->dest->root_dir, file_name);
  8872. + } else {
  8873. + // already contains root_dir as header -> ABSOLUTE
  8874. + sprintf_alloc(&installed_file_name, "%s", file_name);
  8875. + }
  8876. + str_list_append(pkg->installed_files, installed_file_name);
  8877. + free(line);
  8878. + }
  8879. +
  8880. + fclose(list_file);
  8881. +
  8882. + return pkg->installed_files;
  8883. +}
  8884. +
  8885. +/* XXX: CLEANUP: This function and it's counterpart,
  8886. + (pkg_get_installed_files), do not match our init/deinit naming
  8887. + convention. Nor the alloc/free convention. But, then again, neither
  8888. + of these conventions currrently fit the way these two functions
  8889. + work. */
  8890. +int pkg_free_installed_files(pkg_t *pkg)
  8891. +{
  8892. + str_list_elt_t *iter;
  8893. +
  8894. + pkg->installed_files_ref_cnt--;
  8895. + if (pkg->installed_files_ref_cnt > 0) {
  8896. + return 0;
  8897. + }
  8898. +
  8899. + if (pkg->installed_files) {
  8900. +
  8901. + for (iter = pkg->installed_files->head; iter; iter = iter->next) {
  8902. + /* malloced in pkg_get_installed_files */
  8903. + free (iter->data);
  8904. + iter->data = NULL;
  8905. + }
  8906. +
  8907. + str_list_deinit(pkg->installed_files);
  8908. + }
  8909. +
  8910. + pkg->installed_files = NULL;
  8911. +
  8912. + return 0;
  8913. +}
  8914. +
  8915. +int pkg_remove_installed_files_list(ipkg_conf_t *conf, pkg_t *pkg)
  8916. +{
  8917. + int err;
  8918. + char *list_file_name;
  8919. +
  8920. + //I don't think pkg_free_installed_files should be called here. Jamey
  8921. + //pkg_free_installed_files(pkg);
  8922. +
  8923. + sprintf_alloc(&list_file_name, "%s/%s.list",
  8924. + pkg->dest->info_dir, pkg->name);
  8925. + if (!conf->noaction) {
  8926. + err = unlink(list_file_name);
  8927. + free(list_file_name);
  8928. +
  8929. + if (err) {
  8930. + return errno;
  8931. + }
  8932. + }
  8933. + return 0;
  8934. +}
  8935. +
  8936. +conffile_t *pkg_get_conffile(pkg_t *pkg, const char *file_name)
  8937. +{
  8938. + conffile_list_elt_t *iter;
  8939. + conffile_t *conffile;
  8940. +
  8941. + if (pkg == NULL) {
  8942. + return NULL;
  8943. + }
  8944. +
  8945. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  8946. + conffile = iter->data;
  8947. +
  8948. + if (strcmp(conffile->name, file_name) == 0) {
  8949. + return conffile;
  8950. + }
  8951. + }
  8952. +
  8953. + return NULL;
  8954. +}
  8955. +
  8956. +int pkg_run_script(ipkg_conf_t *conf, pkg_t *pkg,
  8957. + const char *script, const char *args)
  8958. +{
  8959. + int err;
  8960. + char *path;
  8961. + char *cmd;
  8962. +
  8963. + /* XXX: FEATURE: When conf->offline_root is set, we should run the
  8964. + maintainer script within a chroot environment. */
  8965. +
  8966. + /* Installed packages have scripts in pkg->dest->info_dir, uninstalled packages
  8967. + have scripts in pkg->tmp_unpack_dir. */
  8968. + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) {
  8969. + if (pkg->dest == NULL) {
  8970. + fprintf(stderr, "%s: ERROR: installed package %s has a NULL dest\n",
  8971. + __FUNCTION__, pkg->name);
  8972. + return EINVAL;
  8973. + }
  8974. + sprintf_alloc(&path, "%s/%s.%s", pkg->dest->info_dir, pkg->name, script);
  8975. + } else {
  8976. + if (pkg->tmp_unpack_dir == NULL) {
  8977. + fprintf(stderr, "%s: ERROR: uninstalled package %s has a NULL tmp_unpack_dir\n",
  8978. + __FUNCTION__, pkg->name);
  8979. + return EINVAL;
  8980. + }
  8981. + sprintf_alloc(&path, "%s/%s", pkg->tmp_unpack_dir, script);
  8982. + }
  8983. +
  8984. + ipkg_message(conf, IPKG_INFO, "Running script %s\n", path);
  8985. + if (conf->noaction) return 0;
  8986. +
  8987. + /* XXX: CLEANUP: There must be a better way to handle maintainer
  8988. + scripts when running with offline_root mode and/or a dest other
  8989. + than '/'. I've been playing around with some clever chroot
  8990. + tricks and I might come up with something workable. */
  8991. + if (conf->offline_root) {
  8992. + setenv("IPKG_OFFLINE_ROOT", conf->offline_root, 1);
  8993. + }
  8994. +
  8995. + setenv("PKG_ROOT",
  8996. + pkg->dest ? pkg->dest->root_dir : conf->default_dest->root_dir, 1);
  8997. +
  8998. + if (! file_exists(path)) {
  8999. + free(path);
  9000. + return 0;
  9001. + }
  9002. +
  9003. + if (conf->offline_root) {
  9004. + fprintf(stderr, "(offline root mode: not running %s.%s)\n", pkg->name, script);
  9005. + free(path);
  9006. + return 0;
  9007. + }
  9008. +
  9009. + sprintf_alloc(&cmd, "%s %s", path, args);
  9010. + free(path);
  9011. +
  9012. + err = xsystem(cmd);
  9013. + free(cmd);
  9014. +
  9015. + if (err) {
  9016. + fprintf(stderr, "%s script returned status %d\n", script, err);
  9017. + return err;
  9018. + }
  9019. +
  9020. + return 0;
  9021. +}
  9022. +
  9023. +char *pkg_state_want_to_str(pkg_state_want_t sw)
  9024. +{
  9025. + int i;
  9026. +
  9027. + for (i=0; i < ARRAY_SIZE(pkg_state_want_map); i++) {
  9028. + if (pkg_state_want_map[i].value == sw) {
  9029. + return strdup(pkg_state_want_map[i].str);
  9030. + }
  9031. + }
  9032. +
  9033. + fprintf(stderr, "%s: ERROR: Illegal value for state_want: %d\n",
  9034. + __FUNCTION__, sw);
  9035. + return strdup("<STATE_WANT_UNKNOWN>");
  9036. +}
  9037. +
  9038. +pkg_state_want_t pkg_state_want_from_str(char *str)
  9039. +{
  9040. + int i;
  9041. +
  9042. + for (i=0; i < ARRAY_SIZE(pkg_state_want_map); i++) {
  9043. + if (strcmp(str, pkg_state_want_map[i].str) == 0) {
  9044. + return pkg_state_want_map[i].value;
  9045. + }
  9046. + }
  9047. +
  9048. + fprintf(stderr, "%s: ERROR: Illegal value for state_want string: %s\n",
  9049. + __FUNCTION__, str);
  9050. + return SW_UNKNOWN;
  9051. +}
  9052. +
  9053. +char *pkg_state_flag_to_str(pkg_state_flag_t sf)
  9054. +{
  9055. + int i;
  9056. + int len = 3; /* ok\000 is minimum */
  9057. + char *str = NULL;
  9058. +
  9059. + /* clear the temporary flags before converting to string */
  9060. + sf &= SF_NONVOLATILE_FLAGS;
  9061. +
  9062. + if (sf == 0) {
  9063. + return strdup("ok");
  9064. + } else {
  9065. +
  9066. + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
  9067. + if (sf & pkg_state_flag_map[i].value) {
  9068. + len += strlen(pkg_state_flag_map[i].str) + 1;
  9069. + }
  9070. + }
  9071. + str = malloc(len);
  9072. + if ( str == NULL ) {
  9073. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  9074. + return NULL;
  9075. + }
  9076. + str[0] = 0;
  9077. + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
  9078. + if (sf & pkg_state_flag_map[i].value) {
  9079. + strcat(str, pkg_state_flag_map[i].str);
  9080. + strcat(str, ",");
  9081. + }
  9082. + }
  9083. + len = strlen(str);
  9084. + str[len-1] = 0; /* squash last comma */
  9085. + return str;
  9086. + }
  9087. +}
  9088. +
  9089. +pkg_state_flag_t pkg_state_flag_from_str(char *str)
  9090. +{
  9091. + int i;
  9092. + int sf = SF_OK;
  9093. +
  9094. + if (strcmp(str, "ok") == 0) {
  9095. + return SF_OK;
  9096. + }
  9097. + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
  9098. + const char *sfname = pkg_state_flag_map[i].str;
  9099. + int sfname_len = strlen(sfname);
  9100. + if (strncmp(str, sfname, sfname_len) == 0) {
  9101. + sf |= pkg_state_flag_map[i].value;
  9102. + str += sfname_len;
  9103. + if (str[0] == ',') {
  9104. + str++;
  9105. + } else {
  9106. + break;
  9107. + }
  9108. + }
  9109. + }
  9110. +
  9111. + return sf;
  9112. +}
  9113. +
  9114. +char *pkg_state_status_to_str(pkg_state_status_t ss)
  9115. +{
  9116. + int i;
  9117. +
  9118. + for (i=0; i < ARRAY_SIZE(pkg_state_status_map); i++) {
  9119. + if (pkg_state_status_map[i].value == ss) {
  9120. + return strdup(pkg_state_status_map[i].str);
  9121. + }
  9122. + }
  9123. +
  9124. + fprintf(stderr, "%s: ERROR: Illegal value for state_status: %d\n",
  9125. + __FUNCTION__, ss);
  9126. + return strdup("<STATE_STATUS_UNKNOWN>");
  9127. +}
  9128. +
  9129. +pkg_state_status_t pkg_state_status_from_str(char *str)
  9130. +{
  9131. + int i;
  9132. +
  9133. + for (i=0; i < ARRAY_SIZE(pkg_state_status_map); i++) {
  9134. + if (strcmp(str, pkg_state_status_map[i].str) == 0) {
  9135. + return pkg_state_status_map[i].value;
  9136. + }
  9137. + }
  9138. +
  9139. + fprintf(stderr, "%s: ERROR: Illegal value for state_status string: %s\n",
  9140. + __FUNCTION__, str);
  9141. + return SS_NOT_INSTALLED;
  9142. +}
  9143. +
  9144. +int pkg_arch_supported(ipkg_conf_t *conf, pkg_t *pkg)
  9145. +{
  9146. + nv_pair_list_elt_t *l;
  9147. +
  9148. + if (!pkg->architecture)
  9149. + return 1;
  9150. +
  9151. + l = conf->arch_list.head;
  9152. +
  9153. + while (l) {
  9154. + nv_pair_t *nv = l->data;
  9155. + if (strcmp(nv->name, pkg->architecture) == 0) {
  9156. + ipkg_message(conf, IPKG_DEBUG, "arch %s (priority %s) supported for pkg %s\n", nv->name, nv->value, pkg->name);
  9157. + return 1;
  9158. + }
  9159. + l = l->next;
  9160. + }
  9161. +
  9162. + ipkg_message(conf, IPKG_DEBUG, "arch %s unsupported for pkg %s\n", pkg->architecture, pkg->name);
  9163. + return 0;
  9164. +}
  9165. +
  9166. +int pkg_get_arch_priority(ipkg_conf_t *conf, const char *archname)
  9167. +{
  9168. + nv_pair_list_elt_t *l;
  9169. +
  9170. + l = conf->arch_list.head;
  9171. +
  9172. + while (l) {
  9173. + nv_pair_t *nv = l->data;
  9174. + if (strcmp(nv->name, archname) == 0) {
  9175. + int priority = strtol(nv->value, NULL, 0);
  9176. + return priority;
  9177. + }
  9178. + l = l->next;
  9179. + }
  9180. + return 0;
  9181. +}
  9182. +
  9183. +int pkg_info_preinstall_check(ipkg_conf_t *conf)
  9184. +{
  9185. + int i;
  9186. + hash_table_t *pkg_hash = &conf->pkg_hash;
  9187. + pkg_vec_t *available_pkgs = pkg_vec_alloc();
  9188. + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
  9189. +
  9190. + ipkg_message(conf, IPKG_INFO, "pkg_info_preinstall_check: updating arch priority for each package\n");
  9191. + pkg_hash_fetch_available(pkg_hash, available_pkgs);
  9192. + /* update arch_priority for each package */
  9193. + for (i = 0; i < available_pkgs->len; i++) {
  9194. + pkg_t *pkg = available_pkgs->pkgs[i];
  9195. + int arch_priority = 1;
  9196. + if (!pkg)
  9197. + continue;
  9198. + // ipkg_message(conf, IPKG_DEBUG2, " package %s version=%s arch=%p:", pkg->name, pkg->version, pkg->architecture);
  9199. + if (pkg->architecture)
  9200. + arch_priority = pkg_get_arch_priority(conf, pkg->architecture);
  9201. + else
  9202. + ipkg_message(conf, IPKG_ERROR, "pkg_info_preinstall_check: no architecture for package %s\n", pkg->name);
  9203. + // ipkg_message(conf, IPKG_DEBUG2, "%s arch_priority=%d\n", pkg->architecture, arch_priority);
  9204. + pkg->arch_priority = arch_priority;
  9205. + }
  9206. +
  9207. + for (i = 0; i < available_pkgs->len; i++) {
  9208. + pkg_t *pkg = available_pkgs->pkgs[i];
  9209. + if (!pkg->arch_priority && (pkg->state_flag || (pkg->state_want != SW_UNKNOWN))) {
  9210. + /* clear flags and want for any uninstallable package */
  9211. + ipkg_message(conf, IPKG_NOTICE, "Clearing state_want and state_flag for pkg=%s (arch_priority=%d flag=%d want=%d)\n",
  9212. + pkg->name, pkg->arch_priority, pkg->state_flag, pkg->state_want);
  9213. + pkg->state_want = SW_UNKNOWN;
  9214. + pkg->state_flag = 0;
  9215. + }
  9216. + }
  9217. + pkg_vec_free(available_pkgs);
  9218. +
  9219. + /* update the file owner data structure */
  9220. + ipkg_message(conf, IPKG_INFO, "pkg_info_preinstall_check: update file owner list\n");
  9221. + pkg_hash_fetch_all_installed(pkg_hash, installed_pkgs);
  9222. + for (i = 0; i < installed_pkgs->len; i++) {
  9223. + pkg_t *pkg = installed_pkgs->pkgs[i];
  9224. + str_list_t *installed_files = pkg_get_installed_files(pkg); /* this causes installed_files to be cached */
  9225. + str_list_elt_t *iter;
  9226. + if (installed_files == NULL) {
  9227. + ipkg_message(conf, IPKG_ERROR, "No installed files for pkg %s\n", pkg->name);
  9228. + break;
  9229. + }
  9230. + for (iter = installed_files->head; iter; iter = iter->next) {
  9231. + char *installed_file = iter->data;
  9232. + // ipkg_message(conf, IPKG_DEBUG2, "pkg %s: file=%s\n", pkg->name, installed_file);
  9233. + file_hash_set_file_owner(conf, installed_file, pkg);
  9234. + }
  9235. + }
  9236. + pkg_vec_free(installed_pkgs);
  9237. +
  9238. + return 0;
  9239. +}
  9240. +
  9241. +struct pkg_write_filelist_data {
  9242. + ipkg_conf_t *conf;
  9243. + pkg_t *pkg;
  9244. + FILE *stream;
  9245. +};
  9246. +
  9247. +void pkg_write_filelist_helper(const char *key, void *entry_, void *data_)
  9248. +{
  9249. + struct pkg_write_filelist_data *data = data_;
  9250. + pkg_t *entry = entry_;
  9251. + if (entry == data->pkg) {
  9252. + fprintf(data->stream, "%s\n", key);
  9253. + }
  9254. +}
  9255. +
  9256. +int pkg_write_filelist(ipkg_conf_t *conf, pkg_t *pkg)
  9257. +{
  9258. + struct pkg_write_filelist_data data;
  9259. + char *list_file_name = NULL;
  9260. + int err = 0;
  9261. +
  9262. + if (!pkg) {
  9263. + ipkg_message(conf, IPKG_ERROR, "Null pkg\n");
  9264. + return -EINVAL;
  9265. + }
  9266. + ipkg_message(conf, IPKG_INFO,
  9267. + " creating %s.list file\n", pkg->name);
  9268. + sprintf_alloc(&list_file_name, "%s/%s.list", pkg->dest->info_dir, pkg->name);
  9269. + if (!list_file_name) {
  9270. + ipkg_message(conf, IPKG_ERROR, "Failed to alloc list_file_name\n");
  9271. + return -ENOMEM;
  9272. + }
  9273. + ipkg_message(conf, IPKG_INFO,
  9274. + " creating %s file for pkg %s\n", list_file_name, pkg->name);
  9275. + data.stream = fopen(list_file_name, "w");
  9276. + if (!data.stream) {
  9277. + ipkg_message(conf, IPKG_ERROR, "Could not open %s for writing: %s\n",
  9278. + list_file_name, strerror(errno));
  9279. + return errno;
  9280. + }
  9281. + data.pkg = pkg;
  9282. + data.conf = conf;
  9283. + hash_table_foreach(&conf->file_hash, pkg_write_filelist_helper, &data);
  9284. + fclose(data.stream);
  9285. + free(list_file_name);
  9286. +
  9287. + return err;
  9288. +}
  9289. +
  9290. +int pkg_write_changed_filelists(ipkg_conf_t *conf)
  9291. +{
  9292. + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
  9293. + hash_table_t *pkg_hash = &conf->pkg_hash;
  9294. + int i;
  9295. + int err;
  9296. + if (conf->noaction)
  9297. + return 0;
  9298. +
  9299. + ipkg_message(conf, IPKG_INFO, "%s: saving changed filelists\n", __FUNCTION__);
  9300. + pkg_hash_fetch_all_installed(pkg_hash, installed_pkgs);
  9301. + for (i = 0; i < installed_pkgs->len; i++) {
  9302. + pkg_t *pkg = installed_pkgs->pkgs[i];
  9303. + if (pkg->state_flag & SF_FILELIST_CHANGED) {
  9304. + ipkg_message(conf, IPKG_DEBUG, "Calling pkg_write_filelist for pkg=%s from %s\n", pkg->name, __FUNCTION__);
  9305. + err = pkg_write_filelist(conf, pkg);
  9306. + if (err)
  9307. + ipkg_message(conf, IPKG_NOTICE, "pkg_write_filelist pkg=%s returned %d\n", pkg->name, err);
  9308. + }
  9309. + }
  9310. + return 0;
  9311. +}
  9312. diff -Nur busybox-1.17.2.orig/archival/libipkg/pkg.h busybox-1.17.2/archival/libipkg/pkg.h
  9313. --- busybox-1.17.2.orig/archival/libipkg/pkg.h 1970-01-01 01:00:00.000000000 +0100
  9314. +++ busybox-1.17.2/archival/libipkg/pkg.h 2010-12-01 22:25:23.000000000 +0100
  9315. @@ -0,0 +1,229 @@
  9316. +/* pkg.h - the itsy package management system
  9317. +
  9318. + Carl D. Worth
  9319. +
  9320. + Copyright (C) 2001 University of Southern California
  9321. +
  9322. + This program is free software; you can redistribute it and/or
  9323. + modify it under the terms of the GNU General Public License as
  9324. + published by the Free Software Foundation; either version 2, or (at
  9325. + your option) any later version.
  9326. +
  9327. + This program is distributed in the hope that it will be useful, but
  9328. + WITHOUT ANY WARRANTY; without even the implied warranty of
  9329. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  9330. + General Public License for more details.
  9331. +*/
  9332. +
  9333. +#ifndef PKG_H
  9334. +#define PKG_H
  9335. +
  9336. +#include <sys/types.h>
  9337. +#include <sys/stat.h>
  9338. +#include <unistd.h>
  9339. +
  9340. +#include "pkg_vec.h"
  9341. +#include "str_list.h"
  9342. +#include "pkg_src.h"
  9343. +#include "pkg_dest.h"
  9344. +#include "ipkg_conf.h"
  9345. +#include "conffile_list.h"
  9346. +
  9347. +struct ipkg_conf;
  9348. +
  9349. +/* I think "Size" is currently the shortest field name */
  9350. +#define PKG_MINIMUM_FIELD_NAME_LEN 4
  9351. +
  9352. +enum pkg_state_want
  9353. +{
  9354. + SW_UNKNOWN = 1,
  9355. + SW_INSTALL,
  9356. + SW_DEINSTALL,
  9357. + SW_PURGE,
  9358. + SW_LAST_STATE_WANT
  9359. +};
  9360. +typedef enum pkg_state_want pkg_state_want_t;
  9361. +
  9362. +enum pkg_state_flag
  9363. +{
  9364. + SF_OK = 0,
  9365. + SF_REINSTREQ = 1,
  9366. + SF_HOLD = 2, /* do not upgrade version */
  9367. + SF_REPLACE = 4, /* replace this package */
  9368. + SF_NOPRUNE = 8, /* do not remove obsolete files */
  9369. + SF_PREFER = 16, /* prefer this version */
  9370. + SF_OBSOLETE = 32, /* old package in upgrade pair */
  9371. + SF_MARKED = 64, /* temporary mark */
  9372. + SF_FILELIST_CHANGED = 128, /* needs filelist written */
  9373. + SF_USER = 256,
  9374. + SF_LAST_STATE_FLAG
  9375. +};
  9376. +typedef enum pkg_state_flag pkg_state_flag_t;
  9377. +#define SF_NONVOLATILE_FLAGS (SF_HOLD|SF_NOPRUNE|SF_PREFER|SF_OBSOLETE|SF_USER)
  9378. +
  9379. +enum pkg_state_status
  9380. +{
  9381. + SS_NOT_INSTALLED = 1,
  9382. + SS_UNPACKED,
  9383. + SS_HALF_CONFIGURED,
  9384. + SS_INSTALLED,
  9385. + SS_HALF_INSTALLED,
  9386. + SS_CONFIG_FILES,
  9387. + SS_POST_INST_FAILED,
  9388. + SS_REMOVAL_FAILED,
  9389. + SS_LAST_STATE_STATUS
  9390. +};
  9391. +typedef enum pkg_state_status pkg_state_status_t;
  9392. +
  9393. +struct abstract_pkg{
  9394. + char * name;
  9395. + int dependencies_checked;
  9396. + pkg_vec_t * pkgs;
  9397. + pkg_state_status_t state_status;
  9398. + pkg_state_flag_t state_flag;
  9399. + struct abstract_pkg ** depended_upon_by; /* @@@@ this should be abstract_pkg_vec_t -Jamey */
  9400. + abstract_pkg_vec_t * provided_by;
  9401. + abstract_pkg_vec_t * replaced_by;
  9402. +};
  9403. +
  9404. +#include "pkg_depends.h"
  9405. +
  9406. +/* XXX: CLEANUP: I'd like to clean up pkg_t in several ways:
  9407. +
  9408. + The 3 version fields should go into a single version struct. (This
  9409. + is especially important since, currently, pkg->version can easily
  9410. + be mistaken for pkg_verson_str_alloc(pkg) although they are very
  9411. + distinct. This has been the source of multiple bugs.
  9412. +
  9413. + The 3 state fields could possibly also go into their own struct.
  9414. +
  9415. + All fields which deal with lists of packages, (Depends,
  9416. + Pre-Depends, Provides, Suggests, Recommends, Enhances), should each
  9417. + be handled by a single struct in pkg_t
  9418. +
  9419. + All string fields for which there is a small set of possible
  9420. + values, (section, maintainer, architecture, maybe version?), that
  9421. + are reused among different packages -- for all such packages we
  9422. + should move from "char *"s to some atom datatype to share data
  9423. + storage and use less memory. We might even do reference counting,
  9424. + but probably not since most often we only create new pkg_t structs,
  9425. + we don't often free them. */
  9426. +struct pkg
  9427. +{
  9428. + char *name;
  9429. + unsigned long epoch;
  9430. + char *version;
  9431. + char *revision;
  9432. + char *familiar_revision;
  9433. + pkg_src_t *src;
  9434. + pkg_dest_t *dest;
  9435. + char *architecture;
  9436. + char *section;
  9437. + char *maintainer;
  9438. + char *description;
  9439. + pkg_state_want_t state_want;
  9440. + pkg_state_flag_t state_flag;
  9441. + pkg_state_status_t state_status;
  9442. + char **depends_str;
  9443. + int depends_count;
  9444. + char **pre_depends_str;
  9445. + int pre_depends_count;
  9446. + char **recommends_str;
  9447. + int recommends_count;
  9448. + char **suggests_str;
  9449. + int suggests_count;
  9450. + compound_depend_t * depends;
  9451. +
  9452. + /* Abhaya: new conflicts */
  9453. + char **conflicts_str;
  9454. + compound_depend_t * conflicts;
  9455. + int conflicts_count;
  9456. +
  9457. + char **replaces_str;
  9458. + int replaces_count;
  9459. + abstract_pkg_t ** replaces;
  9460. +
  9461. + char **provides_str;
  9462. + int provides_count;
  9463. + abstract_pkg_t ** provides;
  9464. +
  9465. + abstract_pkg_t *parent;
  9466. +
  9467. + pkg_t *old_pkg; /* during upgrade, points from installee to previously installed */
  9468. +
  9469. + char *filename;
  9470. + char *local_filename;
  9471. + char *url;
  9472. + char *tmp_unpack_dir;
  9473. + char *md5sum;
  9474. + char *size;
  9475. + char *installed_size;
  9476. + char *priority;
  9477. + char *source;
  9478. + conffile_list_t conffiles;
  9479. + time_t installed_time;
  9480. + /* As pointer for lazy evaluation */
  9481. + str_list_t *installed_files;
  9482. + /* XXX: CLEANUP: I'd like to perhaps come up with a better
  9483. + mechanism to avoid the problem here, (which is that the
  9484. + installed_files list was being freed from an inner loop while
  9485. + still being used within an outer loop. */
  9486. + int installed_files_ref_cnt;
  9487. + int essential;
  9488. + int arch_priority;
  9489. +/* Adding this flag, to "force" ipkg to choose a "provided_by_hand" package, if there are multiple choice */
  9490. + int provided_by_hand;
  9491. +};
  9492. +
  9493. +pkg_t *pkg_new(void);
  9494. +int pkg_init(pkg_t *pkg);
  9495. +void pkg_deinit(pkg_t *pkg);
  9496. +int pkg_init_from_file(pkg_t *pkg, const char *filename);
  9497. +abstract_pkg_t *abstract_pkg_new(void);
  9498. +int abstract_pkg_init(abstract_pkg_t *ab_pkg);
  9499. +
  9500. +/*
  9501. + * merges fields from newpkg into oldpkg.
  9502. + * Forcibly sets oldpkg state_status, state_want and state_flags if set_status is nonzero
  9503. + */
  9504. +int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status);
  9505. +
  9506. +char *pkg_version_str_alloc(pkg_t *pkg);
  9507. +
  9508. +int pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg);
  9509. +int pkg_name_version_and_architecture_compare(pkg_t *a, pkg_t *b);
  9510. +int abstract_pkg_name_compare(abstract_pkg_t *a, abstract_pkg_t *b);
  9511. +
  9512. +char * pkg_formatted_info(pkg_t *pkg );
  9513. +char * pkg_formatted_field(pkg_t *pkg, const char *field );
  9514. +
  9515. +void set_flags_from_control(ipkg_conf_t *conf, pkg_t *pkg);
  9516. +
  9517. +void pkg_print_info(pkg_t *pkg, FILE *file);
  9518. +void pkg_print_status(pkg_t * pkg, FILE * file);
  9519. +void pkg_print_field(pkg_t *pkg, FILE *file, const char *field);
  9520. +str_list_t *pkg_get_installed_files(pkg_t *pkg);
  9521. +int pkg_free_installed_files(pkg_t *pkg);
  9522. +int pkg_remove_installed_files_list(ipkg_conf_t *conf, pkg_t *pkg);
  9523. +conffile_t *pkg_get_conffile(pkg_t *pkg, const char *file_name);
  9524. +int pkg_run_script(struct ipkg_conf *conf, pkg_t *pkg,
  9525. + const char *script, const char *args);
  9526. +
  9527. +/* enum mappings */
  9528. +char *pkg_state_want_to_str(pkg_state_want_t sw);
  9529. +pkg_state_want_t pkg_state_want_from_str(char *str);
  9530. +char *pkg_state_flag_to_str(pkg_state_flag_t sf);
  9531. +pkg_state_flag_t pkg_state_flag_from_str(char *str);
  9532. +char *pkg_state_status_to_str(pkg_state_status_t ss);
  9533. +pkg_state_status_t pkg_state_status_from_str(char *str);
  9534. +
  9535. +int pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op);
  9536. +
  9537. +int pkg_arch_supported(ipkg_conf_t *conf, pkg_t *pkg);
  9538. +int pkg_info_preinstall_check(ipkg_conf_t *conf);
  9539. +int pkg_free_installed_files(pkg_t *pkg);
  9540. +
  9541. +int pkg_write_filelist(ipkg_conf_t *conf, pkg_t *pkg);
  9542. +int pkg_write_changed_filelists(ipkg_conf_t *conf);
  9543. +
  9544. +#endif
  9545. diff -Nur busybox-1.17.2.orig/archival/libipkg/pkg_depends.c busybox-1.17.2/archival/libipkg/pkg_depends.c
  9546. --- busybox-1.17.2.orig/archival/libipkg/pkg_depends.c 1970-01-01 01:00:00.000000000 +0100
  9547. +++ busybox-1.17.2/archival/libipkg/pkg_depends.c 2010-12-01 22:25:23.000000000 +0100
  9548. @@ -0,0 +1,1032 @@
  9549. +/* pkg_depends.c - the itsy package management system
  9550. +
  9551. + Steven M. Ayer
  9552. +
  9553. + Copyright (C) 2002 Compaq Computer Corporation
  9554. +
  9555. + This program is free software; you can redistribute it and/or
  9556. + modify it under the terms of the GNU General Public License as
  9557. + published by the Free Software Foundation; either version 2, or (at
  9558. + your option) any later version.
  9559. +
  9560. + This program is distributed in the hope that it will be useful, but
  9561. + WITHOUT ANY WARRANTY; without even the implied warranty of
  9562. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  9563. + General Public License for more details.
  9564. +*/
  9565. +
  9566. +#include "ipkg.h"
  9567. +#include <errno.h>
  9568. +#include <ctype.h>
  9569. +
  9570. +#include "pkg.h"
  9571. +#include "ipkg_utils.h"
  9572. +#include "pkg_hash.h"
  9573. +#include "ipkg_message.h"
  9574. +#include "pkg_parse.h"
  9575. +#include "hash_table.h"
  9576. +
  9577. +static int parseDepends(compound_depend_t *compound_depend, hash_table_t * hash, char * depend_str);
  9578. +static depend_t * depend_init(void);
  9579. +static void depend_deinit(depend_t *d);
  9580. +static char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx);
  9581. +static char ** merge_unresolved(char ** oldstuff, char ** newstuff);
  9582. +static int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg);
  9583. +int is_pkg_a_replaces(pkg_t *pkg_scout,pkg_t *pkg);
  9584. +
  9585. +static int pkg_installed_and_constraint_satisfied(pkg_t *pkg, void *cdata)
  9586. +{
  9587. + depend_t *depend = (depend_t *)cdata;
  9588. + if ((pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) && version_constraints_satisfied(depend, pkg))
  9589. + return 1;
  9590. + else
  9591. + return 0;
  9592. +}
  9593. +
  9594. +static int pkg_constraint_satisfied(pkg_t *pkg, void *cdata)
  9595. +{
  9596. + depend_t *depend = (depend_t *)cdata;
  9597. +#if 0
  9598. + pkg_t * temp = pkg_new();
  9599. + int comparison;
  9600. + parseVersion(temp, depend->version);
  9601. + comparison = pkg_compare_versions(pkg, temp);
  9602. + free(temp);
  9603. +
  9604. + fprintf(stderr, "%s: pkg=%s pkg->version=%s constraint=%p type=%d version=%s comparison=%d satisfied=%d\n",
  9605. + __FUNCTION__, pkg->name, pkg->version,
  9606. + depend, depend->constraint, depend->version,
  9607. + comparison, version_constraints_satisfied(depend, pkg));
  9608. +#endif
  9609. + if (version_constraints_satisfied(depend, pkg))
  9610. + return 1;
  9611. + else
  9612. + return 0;
  9613. +}
  9614. +
  9615. +/* returns ndependences or negative error value */
  9616. +int pkg_hash_fetch_unsatisfied_dependencies(ipkg_conf_t *conf, pkg_t * pkg,
  9617. + pkg_vec_t *unsatisfied, char *** unresolved)
  9618. +{
  9619. + pkg_t * satisfier_entry_pkg;
  9620. + register int i, j, k, l;
  9621. + int count, found;
  9622. + char ** the_lost;
  9623. + abstract_pkg_t * ab_pkg;
  9624. +
  9625. + /*
  9626. + * this is a setup to check for redundant/cyclic dependency checks,
  9627. + * which are marked at the abstract_pkg level
  9628. + */
  9629. + if (!(ab_pkg = pkg->parent)) {
  9630. + fprintf(stderr, "%s:%d: something terribly wrong with pkg %s\n", __FUNCTION__, __LINE__, pkg->name);
  9631. + *unresolved = NULL;
  9632. + return 0;
  9633. + }
  9634. + if (ab_pkg->dependencies_checked) { /* avoid duplicate or cyclic checks */
  9635. + *unresolved = NULL;
  9636. + return 0;
  9637. + } else {
  9638. + ab_pkg->dependencies_checked = 1; /* mark it for subsequent visits */
  9639. + }
  9640. + /**/
  9641. +
  9642. + count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count;
  9643. + if (!count){
  9644. + *unresolved = NULL;
  9645. + return 0;
  9646. + }
  9647. +
  9648. + the_lost = NULL;
  9649. +
  9650. + /* foreach dependency */
  9651. + for (i = 0; i < count; i++) {
  9652. + compound_depend_t * compound_depend = &pkg->depends[i];
  9653. + depend_t ** possible_satisfiers = compound_depend->possibilities;;
  9654. + found = 0;
  9655. + satisfier_entry_pkg = NULL;
  9656. +
  9657. + if (compound_depend->type == GREEDY_DEPEND) {
  9658. + /* foreach possible satisfier */
  9659. + for (j = 0; j < compound_depend->possibility_count; j++) {
  9660. + /* foreach provided_by, which includes the abstract_pkg itself */
  9661. + abstract_pkg_t *abpkg = possible_satisfiers[j]->pkg;
  9662. + abstract_pkg_vec_t *ab_provider_vec = abpkg->provided_by;
  9663. + int nposs = ab_provider_vec->len;
  9664. + abstract_pkg_t **ab_providers = ab_provider_vec->pkgs;
  9665. + for (l = 0; l < nposs; l++) {
  9666. + pkg_vec_t *test_vec = ab_providers[l]->pkgs;
  9667. + /* if no depends on this one, try the first package that Provides this one */
  9668. + if (!test_vec){ /* no pkg_vec hooked up to the abstract_pkg! (need another feed?) */
  9669. + continue;
  9670. + }
  9671. +
  9672. + /* cruise this possiblity's pkg_vec looking for an installed version */
  9673. + for (k = 0; k < test_vec->len; k++) {
  9674. + pkg_t *pkg_scout = test_vec->pkgs[k];
  9675. + /* not installed, and not already known about? */
  9676. + if ((pkg_scout->state_want != SW_INSTALL)
  9677. + && !pkg_scout->parent->dependencies_checked
  9678. + && !is_pkg_in_pkg_vec(unsatisfied, pkg_scout)) {
  9679. + char ** newstuff = NULL;
  9680. + int rc;
  9681. + pkg_vec_t *tmp_vec = pkg_vec_alloc ();
  9682. + /* check for not-already-installed dependencies */
  9683. + rc = pkg_hash_fetch_unsatisfied_dependencies(conf,
  9684. + pkg_scout,
  9685. + tmp_vec,
  9686. + &newstuff);
  9687. + if (newstuff == NULL) {
  9688. + int ok = 1;
  9689. + for (i = 0; i < rc; i++) {
  9690. + pkg_t *p = tmp_vec->pkgs[i];
  9691. + if (p->state_want == SW_INSTALL)
  9692. + continue;
  9693. + ipkg_message(conf, IPKG_DEBUG, "not installing %s due to requirement for %s\n", pkg_scout->name, p->name);
  9694. + ok = 0;
  9695. + break;
  9696. + }
  9697. + pkg_vec_free (tmp_vec);
  9698. + if (ok) {
  9699. + /* mark this one for installation */
  9700. + ipkg_message(conf, IPKG_NOTICE, "Adding satisfier for greedy dependence: %s\n", pkg_scout->name);
  9701. + pkg_vec_insert(unsatisfied, pkg_scout);
  9702. + }
  9703. + } else {
  9704. + ipkg_message(conf, IPKG_DEBUG, "not installing %s due to broken depends \n", pkg_scout->name);
  9705. + free (newstuff);
  9706. + }
  9707. + }
  9708. + }
  9709. + }
  9710. + }
  9711. +
  9712. + continue;
  9713. + }
  9714. +
  9715. + /* foreach possible satisfier, look for installed package */
  9716. + for (j = 0; j < compound_depend->possibility_count; j++) {
  9717. + /* foreach provided_by, which includes the abstract_pkg itself */
  9718. + depend_t *dependence_to_satisfy = possible_satisfiers[j];
  9719. + abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg;
  9720. + pkg_t *satisfying_pkg =
  9721. + pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg,
  9722. + pkg_installed_and_constraint_satisfied,
  9723. + dependence_to_satisfy, 1);
  9724. + /* Being that I can't test constraing in pkg_hash, I will test it here */
  9725. + if (satisfying_pkg != NULL) {
  9726. + if (!pkg_installed_and_constraint_satisfied ( satisfying_pkg,dependence_to_satisfy)) {
  9727. + satisfying_pkg = NULL;
  9728. + }
  9729. + }
  9730. + ipkg_message(conf, IPKG_DEBUG, "%s:%d: satisfying_pkg=%p \n", __FILE__, __LINE__, satisfying_pkg);
  9731. + if (satisfying_pkg != NULL) {
  9732. + found = 1;
  9733. + break;
  9734. + }
  9735. +
  9736. + }
  9737. + /* if nothing installed matches, then look for uninstalled satisfier */
  9738. + if (!found) {
  9739. + /* foreach possible satisfier, look for installed package */
  9740. + for (j = 0; j < compound_depend->possibility_count; j++) {
  9741. + /* foreach provided_by, which includes the abstract_pkg itself */
  9742. + depend_t *dependence_to_satisfy = possible_satisfiers[j];
  9743. + abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg;
  9744. + pkg_t *satisfying_pkg =
  9745. + pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg,
  9746. + pkg_constraint_satisfied,
  9747. + dependence_to_satisfy, 1);
  9748. + /* Being that I can't test constraing in pkg_hash, I will test it here too */
  9749. + if (satisfying_pkg != NULL) {
  9750. + if (!pkg_constraint_satisfied ( satisfying_pkg,dependence_to_satisfy)) {
  9751. + satisfying_pkg = NULL;
  9752. + }
  9753. + }
  9754. +
  9755. + /* user request overrides package recommendation */
  9756. + if (satisfying_pkg != NULL
  9757. + && (compound_depend->type == RECOMMEND || compound_depend->type == SUGGEST)
  9758. + && (satisfying_pkg->state_want == SW_DEINSTALL || satisfying_pkg->state_want == SW_PURGE)) {
  9759. + ipkg_message (conf, IPKG_NOTICE, "%s: ignoring recommendation for %s at user request\n",
  9760. + pkg->name, satisfying_pkg->name);
  9761. + continue;
  9762. + }
  9763. +
  9764. + ipkg_message(conf, IPKG_DEBUG, "%s:%d: satisfying_pkg=%p\n", __FILE__, __LINE__, satisfying_pkg);
  9765. + if (satisfying_pkg != NULL) {
  9766. + satisfier_entry_pkg = satisfying_pkg;
  9767. + break;
  9768. + }
  9769. + }
  9770. + }
  9771. +
  9772. + /* we didn't find one, add something to the unsatisfied vector */
  9773. + if (!found) {
  9774. + if (!satisfier_entry_pkg) {
  9775. + /* failure to meet recommendations is not an error */
  9776. + if (compound_depend->type != RECOMMEND && compound_depend->type != SUGGEST)
  9777. + the_lost = add_unresolved_dep(pkg, the_lost, i);
  9778. + else
  9779. + ipkg_message (conf, IPKG_NOTICE, "%s: unsatisfied recommendation for %s\n",
  9780. + pkg->name, compound_depend->possibilities[0]->pkg->name);
  9781. + }
  9782. + else {
  9783. + if (compound_depend->type == SUGGEST) {
  9784. + /* just mention it politely */
  9785. + ipkg_message (conf, IPKG_NOTICE, "package %s suggests installing %s\n",
  9786. + pkg->name, satisfier_entry_pkg->name);
  9787. + } else {
  9788. + char ** newstuff = NULL;
  9789. +
  9790. + if (satisfier_entry_pkg != pkg &&
  9791. + !is_pkg_in_pkg_vec(unsatisfied, satisfier_entry_pkg)) {
  9792. + pkg_vec_insert(unsatisfied, satisfier_entry_pkg);
  9793. + pkg_hash_fetch_unsatisfied_dependencies(conf,
  9794. + satisfier_entry_pkg,
  9795. + unsatisfied,
  9796. + &newstuff);
  9797. + the_lost = merge_unresolved(the_lost, newstuff);
  9798. + }
  9799. + }
  9800. + }
  9801. + }
  9802. + }
  9803. + *unresolved = the_lost;
  9804. +
  9805. + return unsatisfied->len;
  9806. +}
  9807. +
  9808. +/*checking for conflicts !in replaces
  9809. + If a packages conflicts with another but is also replacing it, I should not consider it a
  9810. + really conflicts
  9811. + returns 0 if conflicts <> replaces or 1 if conflicts == replaces
  9812. +*/
  9813. +int is_pkg_a_replaces(pkg_t *pkg_scout,pkg_t *pkg)
  9814. +{
  9815. + int i ;
  9816. + int replaces_count = pkg->replaces_count;
  9817. + abstract_pkg_t **replaces;
  9818. +
  9819. + if (pkg->replaces_count==0) // No replaces, it's surely a conflict
  9820. + return 0;
  9821. +
  9822. + replaces = pkg->replaces;
  9823. +
  9824. + for (i = 0; i < replaces_count; i++) {
  9825. + if (strcmp(pkg_scout->name,pkg->replaces[i]->name)==0) { // Found
  9826. + ipkg_message(NULL, IPKG_DEBUG2, "Seems I've found a replace %s %s \n",pkg_scout->name,pkg->replaces[i]->name);
  9827. + return 1;
  9828. + }
  9829. + }
  9830. + return 0;
  9831. +
  9832. +}
  9833. +
  9834. +
  9835. +/* Abhaya: added support for conflicts */
  9836. +pkg_vec_t * pkg_hash_fetch_conflicts(pkg_t * pkg)
  9837. +{
  9838. + pkg_vec_t * installed_conflicts, * test_vec;
  9839. + compound_depend_t * conflicts;
  9840. + depend_t ** possible_satisfiers;
  9841. + depend_t * possible_satisfier;
  9842. + register int i, j, k;
  9843. + int count;
  9844. + abstract_pkg_t * ab_pkg;
  9845. + pkg_t **pkg_scouts;
  9846. + pkg_t *pkg_scout;
  9847. +
  9848. + /*
  9849. + * this is a setup to check for redundant/cyclic dependency checks,
  9850. + * which are marked at the abstract_pkg level
  9851. + */
  9852. + if(!(ab_pkg = pkg->parent)){
  9853. + fprintf(stderr, "dependency check error. pkg %s isn't in hash table\n", pkg->name);
  9854. + return (pkg_vec_t *)NULL;
  9855. + }
  9856. +
  9857. + conflicts = pkg->conflicts;
  9858. + if(!conflicts){
  9859. + return (pkg_vec_t *)NULL;
  9860. + }
  9861. + installed_conflicts = pkg_vec_alloc();
  9862. +
  9863. + count = pkg->conflicts_count;
  9864. +
  9865. +
  9866. +
  9867. + /* foreach conflict */
  9868. + for(i = 0; i < pkg->conflicts_count; i++){
  9869. +
  9870. + possible_satisfiers = conflicts->possibilities;
  9871. +
  9872. + /* foreach possible satisfier */
  9873. + for(j = 0; j < conflicts->possibility_count; j++){
  9874. + possible_satisfier = possible_satisfiers[j];
  9875. + if (!possible_satisfier)
  9876. + fprintf(stderr, "%s:%d: possible_satisfier is null\n", __FUNCTION__, __LINE__);
  9877. + if (!possible_satisfier->pkg)
  9878. + fprintf(stderr, "%s:%d: possible_satisfier->pkg is null\n", __FUNCTION__, __LINE__);
  9879. + test_vec = possible_satisfier->pkg->pkgs;
  9880. + if (test_vec) {
  9881. + /* pkg_vec found, it is an actual package conflict
  9882. + * cruise this possiblity's pkg_vec looking for an installed version */
  9883. + pkg_scouts = test_vec->pkgs;
  9884. + for(k = 0; k < test_vec->len; k++){
  9885. + pkg_scout = pkg_scouts[k];
  9886. + if (!pkg_scout) {
  9887. + fprintf(stderr, "%s: null pkg scout\n", __FUNCTION__);
  9888. + continue;
  9889. + }
  9890. + if ((pkg_scout->state_status == SS_INSTALLED || pkg_scout->state_want == SW_INSTALL) &&
  9891. + version_constraints_satisfied(possible_satisfier, pkg_scout) && !is_pkg_a_replaces(pkg_scout,pkg)){
  9892. + if (!is_pkg_in_pkg_vec(installed_conflicts, pkg_scout)){
  9893. + pkg_vec_insert(installed_conflicts, pkg_scout);
  9894. + }
  9895. + }
  9896. + }
  9897. + }
  9898. + }
  9899. + conflicts++;
  9900. + }
  9901. +
  9902. + if (installed_conflicts->len)
  9903. + return installed_conflicts;
  9904. + pkg_vec_free(installed_conflicts);
  9905. + return (pkg_vec_t *)NULL;
  9906. +}
  9907. +
  9908. +int version_constraints_satisfied(depend_t * depends, pkg_t * pkg)
  9909. +{
  9910. + pkg_t * temp;
  9911. + int comparison;
  9912. +
  9913. + if(depends->constraint == NONE)
  9914. + return 1;
  9915. +
  9916. + temp = pkg_new();
  9917. +
  9918. + parseVersion(temp, depends->version);
  9919. +
  9920. + comparison = pkg_compare_versions(pkg, temp);
  9921. +
  9922. + free(temp);
  9923. +
  9924. + if((depends->constraint == EARLIER) &&
  9925. + (comparison < 0))
  9926. + return 1;
  9927. + else if((depends->constraint == LATER) &&
  9928. + (comparison > 0))
  9929. + return 1;
  9930. + else if(comparison == 0)
  9931. + return 1;
  9932. + else if((depends->constraint == LATER_EQUAL) &&
  9933. + (comparison >= 0))
  9934. + return 1;
  9935. + else if((depends->constraint == EARLIER_EQUAL) &&
  9936. + (comparison <= 0))
  9937. + return 1;
  9938. +
  9939. + return 0;
  9940. +}
  9941. +
  9942. +int pkg_dependence_satisfiable(depend_t *depend)
  9943. +{
  9944. + abstract_pkg_t *apkg = depend->pkg;
  9945. + abstract_pkg_vec_t *provider_apkgs = apkg->provided_by;
  9946. + int n_providers = provider_apkgs->len;
  9947. + abstract_pkg_t **apkgs = provider_apkgs->pkgs;
  9948. + pkg_vec_t *pkg_vec;
  9949. + int n_pkgs ;
  9950. + int i;
  9951. + int j;
  9952. +
  9953. + for (i = 0; i < n_providers; i++) {
  9954. + abstract_pkg_t *papkg = apkgs[i];
  9955. + pkg_vec = papkg->pkgs;
  9956. + if (pkg_vec) {
  9957. + n_pkgs = pkg_vec->len;
  9958. + for (j = 0; j < n_pkgs; j++) {
  9959. + pkg_t *pkg = pkg_vec->pkgs[j];
  9960. + if (version_constraints_satisfied(depend, pkg)) {
  9961. + return 1;
  9962. + }
  9963. + }
  9964. + }
  9965. + }
  9966. + return 0;
  9967. +}
  9968. +
  9969. +int pkg_dependence_satisfied(depend_t *depend)
  9970. +{
  9971. + abstract_pkg_t *apkg = depend->pkg;
  9972. + abstract_pkg_vec_t *provider_apkgs = apkg->provided_by;
  9973. + int n_providers = provider_apkgs->len;
  9974. + abstract_pkg_t **apkgs = provider_apkgs->pkgs;
  9975. + int i;
  9976. + int n_pkgs;
  9977. + int j;
  9978. +
  9979. + for (i = 0; i < n_providers; i++) {
  9980. + abstract_pkg_t *papkg = apkgs[i];
  9981. + pkg_vec_t *pkg_vec = papkg->pkgs;
  9982. + if (pkg_vec) {
  9983. + n_pkgs = pkg_vec->len;
  9984. + for (j = 0; j < n_pkgs; j++) {
  9985. + pkg_t *pkg = pkg_vec->pkgs[j];
  9986. + if (version_constraints_satisfied(depend, pkg)) {
  9987. + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED)
  9988. + return 1;
  9989. + }
  9990. + }
  9991. + }
  9992. + }
  9993. + return 0;
  9994. +}
  9995. +
  9996. +static int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg)
  9997. +{
  9998. + register int i;
  9999. + pkg_t ** pkgs = vec->pkgs;
  10000. +
  10001. + for(i = 0; i < vec->len; i++)
  10002. + if((strcmp(pkg->name, (*(pkgs + i))->name) == 0)
  10003. + && (pkg_compare_versions(pkg, *(pkgs + i)) == 0)
  10004. + && (strcmp(pkg->architecture, (*(pkgs + i))->architecture) == 0))
  10005. + return 1;
  10006. + return 0;
  10007. +}
  10008. +
  10009. +
  10010. +#ifdef DeadCode
  10011. +/**
  10012. + * pkg_has_common_provides returns 1 if pkg and replacee both provide
  10013. + * the same abstract package and 0 otherwise.
  10014. + */
  10015. +int pkg_has_common_provides(pkg_t *pkg, pkg_t *replacee)
  10016. +{
  10017. + abstract_pkg_t **provides = pkg->provides;
  10018. + int provides_count = pkg->provides_count;
  10019. + abstract_pkg_t **replacee_provides = replacee->provides;
  10020. + int replacee_provides_count = replacee->provides_count;
  10021. + int i, j;
  10022. + for (i = 0; i < provides_count; i++) {
  10023. + abstract_pkg_t *apkg = provides[i];
  10024. + for (j = 0; j < replacee_provides_count; j++) {
  10025. + abstract_pkg_t *replacee_apkg = replacee_provides[i];
  10026. + if (apkg == replacee_apkg)
  10027. + return 1;
  10028. + }
  10029. + }
  10030. + return 0;
  10031. +}
  10032. +#endif
  10033. +
  10034. +/**
  10035. + * pkg_provides_abstract returns 1 if pkg->provides contains providee
  10036. + * and 0 otherwise.
  10037. + */
  10038. +int pkg_provides_abstract(pkg_t *pkg, abstract_pkg_t *providee)
  10039. +{
  10040. + abstract_pkg_t **provides = pkg->provides;
  10041. + int provides_count = pkg->provides_count;
  10042. + int i;
  10043. + for (i = 0; i < provides_count; i++) {
  10044. + if (provides[i] == providee)
  10045. + return 1;
  10046. + }
  10047. + return 0;
  10048. +}
  10049. +
  10050. +/**
  10051. + * pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0
  10052. + * otherwise.
  10053. + */
  10054. +int pkg_replaces(pkg_t *pkg, pkg_t *replacee)
  10055. +{
  10056. + abstract_pkg_t **replaces = pkg->replaces;
  10057. + int replaces_count = pkg->replaces_count;
  10058. + /* abstract_pkg_t **replacee_provides = pkg->provides;
  10059. + int replacee_provides_count = pkg->provides_count; */
  10060. + int i, j;
  10061. + for (i = 0; i < replaces_count; i++) {
  10062. + abstract_pkg_t *abstract_replacee = replaces[i];
  10063. + for (j = 0; j < replaces_count; j++) {
  10064. + /* ipkg_message(NULL, IPKG_DEBUG2, "Searching pkg-name %s repprovname %s absrepname %s \n",
  10065. + pkg->name,replacee->provides[j]->name, abstract_replacee->name); */
  10066. + if (replacee->provides[j] == abstract_replacee)
  10067. + return 1;
  10068. + }
  10069. + }
  10070. + return 0;
  10071. +}
  10072. +
  10073. +
  10074. +/**
  10075. + * pkg_conflicts_abstract returns 1 if pkg->conflicts contains conflictee and 0
  10076. + * otherwise.
  10077. + */
  10078. +int pkg_conflicts_abstract(pkg_t *pkg, abstract_pkg_t *conflictee)
  10079. +{
  10080. + compound_depend_t *conflicts = pkg->conflicts;
  10081. + int conflicts_count = pkg->conflicts_count;
  10082. + int i, j;
  10083. + for (i = 0; i < conflicts_count; i++) {
  10084. + int possibility_count = conflicts[i].possibility_count;
  10085. + struct depend **possibilities = conflicts[i].possibilities;
  10086. + for (j = 0; j < possibility_count; j++) {
  10087. + if (possibilities[j]->pkg == conflictee) {
  10088. + return 1;
  10089. + }
  10090. + }
  10091. + }
  10092. + return 0;
  10093. +}
  10094. +
  10095. +/**
  10096. + * pkg_conflicts returns 1 if pkg->conflicts contains one of
  10097. + * conflictee's provides and 0 otherwise.
  10098. + */
  10099. +int pkg_conflicts(pkg_t *pkg, pkg_t *conflictee)
  10100. +{
  10101. + compound_depend_t *conflicts = pkg->conflicts;
  10102. + int conflicts_count = pkg->conflicts_count;
  10103. + abstract_pkg_t **conflictee_provides = conflictee->provides;
  10104. + int conflictee_provides_count = conflictee->provides_count;
  10105. + int i, j, k;
  10106. + int possibility_count;
  10107. + struct depend **possibilities;
  10108. + abstract_pkg_t *possibility ;
  10109. +
  10110. + for (i = 0; i < conflicts_count; i++) {
  10111. + possibility_count = conflicts[i].possibility_count;
  10112. + possibilities = conflicts[i].possibilities;
  10113. + for (j = 0; j < possibility_count; j++) {
  10114. + possibility = possibilities[j]->pkg;
  10115. + for (k = 0; k < conflictee_provides_count; k++) {
  10116. + if (possibility == conflictee_provides[k]) {
  10117. + return 1;
  10118. + }
  10119. + }
  10120. + }
  10121. + }
  10122. + return 0;
  10123. +}
  10124. +
  10125. +static char ** merge_unresolved(char ** oldstuff, char ** newstuff)
  10126. +{
  10127. + int oldlen = 0, newlen = 0;
  10128. + char ** result;
  10129. + register int i, j;
  10130. +
  10131. + if(!newstuff)
  10132. + return oldstuff;
  10133. +
  10134. + while(oldstuff && oldstuff[oldlen]) oldlen++;
  10135. + while(newstuff && newstuff[newlen]) newlen++;
  10136. +
  10137. + result = (char **)realloc(oldstuff, sizeof(char *) * (oldlen + newlen + 1));
  10138. + if (result == NULL) {
  10139. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10140. + return NULL;
  10141. + }
  10142. +
  10143. + for(i = oldlen, j = 0; i < (oldlen + newlen); i++, j++)
  10144. + *(result + i) = *(newstuff + j);
  10145. +
  10146. + *(result + i) = NULL;
  10147. +
  10148. + return result;
  10149. +}
  10150. +
  10151. +/*
  10152. + * a kinda kludgy way to back out depends str from two different arrays (reg'l'r 'n pre)
  10153. + * this is null terminated, no count is carried around
  10154. + */
  10155. +char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx)
  10156. +{
  10157. + int count;
  10158. + char ** resized;
  10159. + char *depend_str = pkg_depend_str(pkg, ref_ndx);
  10160. +
  10161. + count = 0;
  10162. + while(the_lost && the_lost[count]) count++;
  10163. +
  10164. + count++; /* need one to hold the null */
  10165. + resized = (char **)realloc(the_lost, sizeof(char *) * (count + 1));
  10166. + if (resized == NULL) {
  10167. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10168. + return NULL;
  10169. + }
  10170. + resized[count - 1] = strdup(depend_str);
  10171. + resized[count] = NULL;
  10172. +
  10173. + return resized;
  10174. +}
  10175. +
  10176. +void printDepends(pkg_t * pkg)
  10177. +{
  10178. + register int i, j;
  10179. + compound_depend_t * depend;
  10180. + int count;
  10181. +
  10182. + count = pkg->pre_depends_count + pkg->depends_count;
  10183. +
  10184. + depend = pkg->depends;
  10185. + if(!depend){
  10186. + fprintf(stderr, "Depends pointer is NULL\n");
  10187. + return;
  10188. + }
  10189. + for(i = 0; i < count; i++){
  10190. + fprintf(stderr, "%s has %d possibilities:\n",
  10191. + (depend->type == GREEDY_DEPEND) ? "Greedy-Depend" : ((depend->type == DEPEND) ? "Depend" : "Pre-Depend"),
  10192. + depend->possibility_count);
  10193. + for(j = 0; j < depend->possibility_count; j++)
  10194. + fprintf(stderr, "\t%s version %s (%d)\n",
  10195. + depend->possibilities[j]->pkg->name,
  10196. + depend->possibilities[j]->version,
  10197. + depend->possibilities[j]->constraint);
  10198. + depend++;
  10199. + }
  10200. +}
  10201. +
  10202. +int buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
  10203. +{
  10204. + register int i, j;
  10205. +
  10206. + /* every pkg provides itself */
  10207. + abstract_pkg_vec_insert(ab_pkg->provided_by, ab_pkg);
  10208. +
  10209. + if (!pkg->provides_count)
  10210. + return 0;
  10211. +
  10212. + pkg->provides = (abstract_pkg_t **)malloc(sizeof(abstract_pkg_t *) * (pkg->provides_count + 1));
  10213. + if (pkg->provides == NULL) {
  10214. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10215. + return -1 ;
  10216. + }
  10217. + pkg->provides[0] = ab_pkg;
  10218. +
  10219. + // if (strcmp(ab_pkg->name, pkg->name))
  10220. + // fprintf(stderr, __FUNCTION__ ": ab_pkg=%s pkg=%s\n", ab_pkg->name, pkg->name);
  10221. +
  10222. + for(i = 0; i < pkg->provides_count; i++){
  10223. + abstract_pkg_t *provided_abpkg = ensure_abstract_pkg_by_name(hash, pkg->provides_str[i]);
  10224. +
  10225. + pkg->provides[i+1] = provided_abpkg;
  10226. +
  10227. + j = 0;
  10228. + abstract_pkg_vec_insert(provided_abpkg->provided_by, ab_pkg);
  10229. + }
  10230. + return 0;
  10231. +}
  10232. +
  10233. +/* Abhaya: added conflicts support */
  10234. +int buildConflicts(hash_table_t * hash, pkg_t * pkg)
  10235. +{
  10236. + register int i;
  10237. + compound_depend_t * conflicts;
  10238. +
  10239. + if (!pkg->conflicts_count)
  10240. + return 0;
  10241. +
  10242. + conflicts = pkg->conflicts = malloc(sizeof(compound_depend_t) *
  10243. + pkg->conflicts_count);
  10244. + if (conflicts == NULL) {
  10245. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10246. + return -1;
  10247. + }
  10248. + for (i = 0; i < pkg->conflicts_count; i++) {
  10249. + conflicts->type = CONFLICTS;
  10250. + parseDepends(conflicts, hash,
  10251. + pkg->conflicts_str[i]);
  10252. +#if 0
  10253. + for (j = 0; j < conflicts->possibility_count; j++) {
  10254. + depend_t *possibility = conflicts->possibilities[j];
  10255. + abstract_pkg_t *conflicting_apkg = possibility->pkg;
  10256. + pkg_add_conflict_pair(ab_pkg, conflicting_apkg);
  10257. + }
  10258. +#endif
  10259. + conflicts++;
  10260. + }
  10261. + return 0;
  10262. +}
  10263. +
  10264. +int buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
  10265. +{
  10266. + register int i, j;
  10267. +
  10268. + if (!pkg->replaces_count)
  10269. + return 0;
  10270. +
  10271. + pkg->replaces = (abstract_pkg_t **)malloc(sizeof(abstract_pkg_t *) * pkg->replaces_count);
  10272. + if (pkg->replaces == NULL) {
  10273. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10274. + return -1;
  10275. + }
  10276. +
  10277. + // if (strcmp(ab_pkg->name, pkg->name))
  10278. + // fprintf(stderr, __FUNCTION__ ": ab_pkg=%s pkg=%s\n", ab_pkg->name, pkg->name);
  10279. +
  10280. + for(i = 0; i < pkg->replaces_count; i++){
  10281. + abstract_pkg_t *old_abpkg = ensure_abstract_pkg_by_name(hash, pkg->replaces_str[i]);
  10282. +
  10283. + pkg->replaces[i] = old_abpkg;
  10284. +
  10285. + j = 0;
  10286. + if (!old_abpkg->replaced_by)
  10287. + old_abpkg->replaced_by = abstract_pkg_vec_alloc();
  10288. + if ( old_abpkg->replaced_by == NULL ){
  10289. + return -1;
  10290. + }
  10291. + /* if a package pkg both replaces and conflicts old_abpkg,
  10292. + * then add it to the replaced_by vector so that old_abpkg
  10293. + * will be upgraded to ab_pkg automatically */
  10294. + if (pkg_conflicts_abstract(pkg, old_abpkg))
  10295. + abstract_pkg_vec_insert(old_abpkg->replaced_by, ab_pkg);
  10296. + }
  10297. + return 0;
  10298. +}
  10299. +
  10300. +int buildDepends(hash_table_t * hash, pkg_t * pkg)
  10301. +{
  10302. + int count;
  10303. + register int i;
  10304. + compound_depend_t * depends;
  10305. +
  10306. + if(!(count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count))
  10307. + return 0;
  10308. +
  10309. + if (0 && pkg->pre_depends_count)
  10310. + fprintf(stderr, "pkg=%s pre_depends_count=%d depends_count=%d\n",
  10311. + pkg->name, pkg->pre_depends_count, pkg->depends_count);
  10312. + depends = pkg->depends = malloc(sizeof(compound_depend_t) * count);
  10313. + if (depends == NULL) {
  10314. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10315. + return -1;
  10316. + }
  10317. +
  10318. +
  10319. + for(i = 0; i < pkg->pre_depends_count; i++){
  10320. + parseDepends(depends, hash, pkg->pre_depends_str[i]);
  10321. + if (0 && pkg->pre_depends_count)
  10322. + fprintf(stderr, " pre_depends_str=%s depends=%p possibility_count=%x\n",
  10323. + pkg->pre_depends_str[i], depends, depends->possibility_count);
  10324. + depends->type = PREDEPEND;
  10325. + depends++;
  10326. + }
  10327. +
  10328. + for(i = 0; i < pkg->recommends_count; i++){
  10329. + parseDepends(depends, hash, pkg->recommends_str[i]);
  10330. + if (0 && pkg->recommends_count)
  10331. + fprintf(stderr, " recommends_str=%s depends=%p possibility_count=%x\n",
  10332. + pkg->recommends_str[i], depends, depends->possibility_count);
  10333. + depends->type = RECOMMEND;
  10334. + depends++;
  10335. + }
  10336. +
  10337. + for(i = 0; i < pkg->suggests_count; i++){
  10338. + parseDepends(depends, hash, pkg->suggests_str[i]);
  10339. + if (0 && pkg->suggests_count)
  10340. + fprintf(stderr, " suggests_str=%s depends=%p possibility_count=%x\n",
  10341. + pkg->suggests_str[i], depends, depends->possibility_count);
  10342. + depends->type = SUGGEST;
  10343. + depends++;
  10344. + }
  10345. +
  10346. + for(i = 0; i < pkg->depends_count; i++){
  10347. + parseDepends(depends, hash, pkg->depends_str[i]);
  10348. + if (0 && pkg->depends_count)
  10349. + fprintf(stderr, " depends_str=%s depends=%p possibility_count=%x\n",
  10350. + pkg->depends_str[i], depends, depends->possibility_count);
  10351. + depends++;
  10352. + }
  10353. + return 0;
  10354. +}
  10355. +
  10356. +/*
  10357. + * pkg_depend_string: returns the depends string specified by index_.
  10358. + * All 4 kinds of dependences: dependence, pre-dependence, recommend, and suggest are number starting from 0.
  10359. + * [0,npredepends) -> returns pre_depends_str[index_]
  10360. + * [npredepends,npredepends+nrecommends) -> returns recommends_str[index_]
  10361. + * [npredepends+nrecommends,npredepends+nrecommends+nsuggests) -> returns recommends_str[index_]
  10362. + * [npredepends+nrecommends+nsuggests,npredepends+nrecommends+nsuggests+ndepends) -> returns depends_str[index_]
  10363. + */
  10364. +char *pkg_depend_str(pkg_t *pkg, int index_)
  10365. +{
  10366. + if (index_ < pkg->pre_depends_count) {
  10367. + return pkg->pre_depends_str[index_];
  10368. + }
  10369. + index_ -= pkg->pre_depends_count;
  10370. +
  10371. + if (index_ < pkg->recommends_count) {
  10372. + return pkg->recommends_str[index_];
  10373. + }
  10374. + index_ -= pkg->recommends_count;
  10375. +
  10376. + if (index_ < pkg->suggests_count) {
  10377. + return pkg->suggests_str[index_];
  10378. + }
  10379. + index_ -= pkg->suggests_count;
  10380. +
  10381. + if (index_ < pkg->depends_count) {
  10382. + return pkg->depends_str[index_];
  10383. + }
  10384. + fprintf(stderr, "pkg_depend_str: index_ %d out of range for pkg=%s\n", index_, pkg->name);
  10385. + return NULL;
  10386. +}
  10387. +
  10388. +void freeDepends(pkg_t *pkg)
  10389. +{
  10390. + int i;
  10391. +
  10392. + if (pkg == NULL || pkg->depends == NULL) {
  10393. + return;
  10394. + }
  10395. +
  10396. + fprintf(stderr, "Freeing depends=%p\n", pkg->depends);
  10397. + for (i=0; i < pkg->depends->possibility_count; i++) {
  10398. + depend_deinit(pkg->depends->possibilities[i]);
  10399. + }
  10400. + free(pkg->depends->possibilities);
  10401. + free(pkg->depends);
  10402. + pkg->depends = NULL;
  10403. +}
  10404. +
  10405. +void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg)
  10406. +{
  10407. + compound_depend_t * depends;
  10408. + int count, othercount;
  10409. + register int i, j;
  10410. + abstract_pkg_t * ab_depend;
  10411. + abstract_pkg_t ** temp;
  10412. +
  10413. + count = pkg->pre_depends_count + pkg->depends_count;
  10414. + depends = pkg->depends;
  10415. +
  10416. + if (0 && pkg->pre_depends_count)
  10417. + fprintf(stderr, "pkg=%s pre_depends_count=%d depends_count=%d\n",
  10418. + pkg->name, pkg->pre_depends_count, pkg->depends_count);
  10419. + for (i = 0; i < count; i++) {
  10420. + if (0 && pkg->pre_depends_count)
  10421. + fprintf(stderr, " i=%d possibility_count=%x depends=%p\n", i, depends->possibility_count, depends);
  10422. + for (j = 0; j < depends->possibility_count; j++){
  10423. + ab_depend = depends->possibilities[j]->pkg;
  10424. + if(!ab_depend->depended_upon_by)
  10425. + ab_depend->depended_upon_by = (abstract_pkg_t **)calloc(1, sizeof(abstract_pkg_t *));
  10426. +
  10427. + temp = ab_depend->depended_upon_by;
  10428. + othercount = 1;
  10429. + while(*temp){
  10430. + temp++;
  10431. + othercount++;
  10432. + }
  10433. + *temp = ab_pkg;
  10434. +
  10435. + ab_depend->depended_upon_by = (abstract_pkg_t **)realloc(ab_depend->depended_upon_by,
  10436. + (othercount + 1) * sizeof(abstract_pkg_t *));
  10437. + /* the array may have moved */
  10438. + temp = ab_depend->depended_upon_by + othercount;
  10439. + *temp = NULL;
  10440. + }
  10441. + depends++;
  10442. + }
  10443. +}
  10444. +
  10445. +static depend_t * depend_init(void)
  10446. +{
  10447. + depend_t * d = (depend_t *)malloc(sizeof(depend_t));
  10448. + if ( d==NULL ){
  10449. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10450. + return NULL;
  10451. + }
  10452. + d->constraint = NONE;
  10453. + d->version = NULL;
  10454. + d->pkg = NULL;
  10455. +
  10456. + return d;
  10457. +}
  10458. +
  10459. +static void depend_deinit(depend_t *d)
  10460. +{
  10461. + free(d);
  10462. +}
  10463. +
  10464. +static int parseDepends(compound_depend_t *compound_depend,
  10465. + hash_table_t * hash, char * depend_str)
  10466. +{
  10467. + char * pkg_name, buffer[2048];
  10468. + int num_of_ors = 0;
  10469. + register int i;
  10470. + register char * src, * dest;
  10471. + depend_t ** possibilities;
  10472. +
  10473. + /* first count the number of ored possibilities for satisfying dependency */
  10474. + src = depend_str;
  10475. + while(*src)
  10476. + if(*src++ == '|')
  10477. + num_of_ors++;
  10478. +
  10479. + compound_depend->type = DEPEND;
  10480. +
  10481. + compound_depend->possibility_count = num_of_ors + 1;
  10482. + possibilities = (depend_t **)malloc(sizeof(depend_t *) * (num_of_ors + 1));
  10483. + if (!possibilities)
  10484. + return -ENOMEM;
  10485. + compound_depend->possibilities = possibilities;
  10486. +
  10487. + src = depend_str;
  10488. + for(i = 0; i < num_of_ors + 1; i++){
  10489. + possibilities[i] = depend_init();
  10490. + if (!possibilities[i])
  10491. + return -ENOMEM;
  10492. + /* gobble up just the name first */
  10493. + dest = buffer;
  10494. + while(*src &&
  10495. + !isspace(*src) &&
  10496. + (*src != '(') &&
  10497. + (*src != '*') &&
  10498. + (*src != '|'))
  10499. + *dest++ = *src++;
  10500. + *dest = '\0';
  10501. + pkg_name = trim_alloc(buffer);
  10502. + if (pkg_name == NULL )
  10503. + return -ENOMEM;
  10504. +
  10505. + /* now look at possible version info */
  10506. +
  10507. + /* skip to next chars */
  10508. + if(isspace(*src))
  10509. + while(*src && isspace(*src)) src++;
  10510. +
  10511. + /* extract constraint and version */
  10512. + if(*src == '('){
  10513. + src++;
  10514. + if(!strncmp(src, "<<", 2)){
  10515. + possibilities[i]->constraint = EARLIER;
  10516. + src += 2;
  10517. + }
  10518. + else if(!strncmp(src, "<=", 2)){
  10519. + possibilities[i]->constraint = EARLIER_EQUAL;
  10520. + src += 2;
  10521. + }
  10522. + else if(!strncmp(src, ">=", 2)){
  10523. + possibilities[i]->constraint = LATER_EQUAL;
  10524. + src += 2;
  10525. + }
  10526. + else if(!strncmp(src, ">>", 2)){
  10527. + possibilities[i]->constraint = LATER;
  10528. + src += 2;
  10529. + }
  10530. + else if(!strncmp(src, "=", 1)){
  10531. + possibilities[i]->constraint = EQUAL;
  10532. + src++;
  10533. + }
  10534. + /* should these be here to support deprecated designations; dpkg does */
  10535. + else if(!strncmp(src, "<", 1)){
  10536. + possibilities[i]->constraint = EARLIER_EQUAL;
  10537. + src++;
  10538. + }
  10539. + else if(!strncmp(src, ">", 1)){
  10540. + possibilities[i]->constraint = LATER_EQUAL;
  10541. + src++;
  10542. + }
  10543. +
  10544. + /* now we have any constraint, pass space to version string */
  10545. + while(isspace(*src)) src++;
  10546. +
  10547. + /* this would be the version string */
  10548. + dest = buffer;
  10549. + while(*src && *src != ')')
  10550. + *dest++ = *src++;
  10551. + *dest = '\0';
  10552. +
  10553. + possibilities[i]->version = trim_alloc(buffer);
  10554. + /* fprintf(stderr, "let's print the depends version string:");
  10555. + fprintf(stderr, "version %s\n", possibilities[i]->version);*/
  10556. + if (possibilities[i]->version == NULL )
  10557. + return -ENOMEM;
  10558. +
  10559. +
  10560. + }
  10561. + /* hook up the dependency to its abstract pkg */
  10562. + possibilities[i]->pkg = ensure_abstract_pkg_by_name(hash, pkg_name);
  10563. +
  10564. + free(pkg_name);
  10565. +
  10566. + /* now get past the ) and any possible | chars */
  10567. + while(*src &&
  10568. + (isspace(*src) ||
  10569. + (*src == ')') ||
  10570. + (*src == '|')))
  10571. + src++;
  10572. + if (*src == '*')
  10573. + {
  10574. + compound_depend->type = GREEDY_DEPEND;
  10575. + src++;
  10576. + }
  10577. + }
  10578. +
  10579. + return 0;
  10580. +}
  10581. diff -Nur busybox-1.17.2.orig/archival/libipkg/pkg_depends.h busybox-1.17.2/archival/libipkg/pkg_depends.h
  10582. --- busybox-1.17.2.orig/archival/libipkg/pkg_depends.h 1970-01-01 01:00:00.000000000 +0100
  10583. +++ busybox-1.17.2/archival/libipkg/pkg_depends.h 2010-12-01 22:25:23.000000000 +0100
  10584. @@ -0,0 +1,105 @@
  10585. +/* pkg_depends.h - the itsy package management system
  10586. +
  10587. + Steven M. Ayer
  10588. +
  10589. + Copyright (C) 2002 Compaq Computer Corporation
  10590. +
  10591. + This program is free software; you can redistribute it and/or
  10592. + modify it under the terms of the GNU General Public License as
  10593. + published by the Free Software Foundation; either version 2, or (at
  10594. + your option) any later version.
  10595. +
  10596. + This program is distributed in the hope that it will be useful, but
  10597. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10598. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10599. + General Public License for more details.
  10600. +*/
  10601. +
  10602. +#ifndef PKG_DEPENDS_H
  10603. +#define PKG_DEPENDS_H
  10604. +
  10605. +#include "pkg.h"
  10606. +#include "pkg_hash.h"
  10607. +
  10608. +enum depend_type {
  10609. + PREDEPEND,
  10610. + DEPEND,
  10611. + CONFLICTS,
  10612. + GREEDY_DEPEND,
  10613. + RECOMMEND,
  10614. + SUGGEST
  10615. +};
  10616. +typedef enum depend_type depend_type_t;
  10617. +
  10618. +enum version_constraint {
  10619. + NONE,
  10620. + EARLIER,
  10621. + EARLIER_EQUAL,
  10622. + EQUAL,
  10623. + LATER_EQUAL,
  10624. + LATER
  10625. +};
  10626. +typedef enum version_constraint version_constraint_t;
  10627. +
  10628. +struct depend{
  10629. + version_constraint_t constraint;
  10630. + char * version;
  10631. + abstract_pkg_t * pkg;
  10632. +};
  10633. +typedef struct depend depend_t;
  10634. +
  10635. +struct compound_depend{
  10636. + depend_type_t type;
  10637. + int possibility_count;
  10638. + struct depend ** possibilities;
  10639. +};
  10640. +typedef struct compound_depend compound_depend_t;
  10641. +
  10642. +#include "hash_table.h"
  10643. +
  10644. +int buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
  10645. +int buildConflicts(hash_table_t * hash, pkg_t * pkg);
  10646. +int buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
  10647. +int buildDepends(hash_table_t * hash, pkg_t * pkg);
  10648. +
  10649. +/**
  10650. + * pkg_has_common_provides returns 1 if pkg and replacee both provide
  10651. + * the same abstract package and 0 otherwise.
  10652. + */
  10653. +int pkg_has_common_provides(pkg_t *pkg, pkg_t *replacee);
  10654. +
  10655. +/**
  10656. + * pkg_provides returns 1 if pkg->provides contains providee and 0
  10657. + * otherwise.
  10658. + */
  10659. +int pkg_provides_abstract(pkg_t *pkg, abstract_pkg_t *providee);
  10660. +
  10661. +/**
  10662. + * pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0
  10663. + * otherwise.
  10664. + */
  10665. +int pkg_replaces(pkg_t *pkg, pkg_t *replacee);
  10666. +
  10667. +/**
  10668. + * pkg_conflicts_abstract returns 1 if pkg->conflicts contains conflictee provides and 0
  10669. + * otherwise.
  10670. + */
  10671. +int pkg_conflicts_abstract(pkg_t *pkg, abstract_pkg_t *conflicts);
  10672. +
  10673. +/**
  10674. + * pkg_conflicts returns 1 if pkg->conflicts contains one of conflictee's provides and 0
  10675. + * otherwise.
  10676. + */
  10677. +int pkg_conflicts(pkg_t *pkg, pkg_t *conflicts);
  10678. +
  10679. +char *pkg_depend_str(pkg_t *pkg, int index_);
  10680. +void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg);
  10681. +void freeDepends(pkg_t *pkg);
  10682. +void printDepends(pkg_t * pkg);
  10683. +int version_constraints_satisfied(depend_t * depends, pkg_t * pkg);
  10684. +int pkg_hash_fetch_unsatisfied_dependencies(ipkg_conf_t *conf, pkg_t * pkg, pkg_vec_t *depends, char *** unresolved);
  10685. +pkg_vec_t * pkg_hash_fetch_conflicts(pkg_t * pkg);
  10686. +int pkg_dependence_satisfiable(depend_t *depend);
  10687. +int pkg_dependence_satisfied(depend_t *depend);
  10688. +
  10689. +#endif
  10690. diff -Nur busybox-1.17.2.orig/archival/libipkg/pkg_dest.c busybox-1.17.2/archival/libipkg/pkg_dest.c
  10691. --- busybox-1.17.2.orig/archival/libipkg/pkg_dest.c 1970-01-01 01:00:00.000000000 +0100
  10692. +++ busybox-1.17.2/archival/libipkg/pkg_dest.c 2010-12-01 22:25:23.000000000 +0100
  10693. @@ -0,0 +1,92 @@
  10694. +/* pkg_dest.c - the itsy package management system
  10695. +
  10696. + Carl D. Worth
  10697. +
  10698. + Copyright (C) 2001 University of Southern California
  10699. +
  10700. + This program is free software; you can redistribute it and/or
  10701. + modify it under the terms of the GNU General Public License as
  10702. + published by the Free Software Foundation; either version 2, or (at
  10703. + your option) any later version.
  10704. +
  10705. + This program is distributed in the hope that it will be useful, but
  10706. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10707. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10708. + General Public License for more details.
  10709. +*/
  10710. +
  10711. +#include "ipkg.h"
  10712. +
  10713. +#include "pkg_dest.h"
  10714. +#include "file_util.h"
  10715. +#include "str_util.h"
  10716. +#include "sprintf_alloc.h"
  10717. +
  10718. +int pkg_dest_init(pkg_dest_t *dest, const char *name, const char *root_dir,const char * lists_dir)
  10719. +{
  10720. + dest->name = strdup(name);
  10721. +
  10722. + /* Guarantee that dest->root_dir ends with a '/' */
  10723. + if (str_ends_with(root_dir, "/")) {
  10724. + dest->root_dir = strdup(root_dir);
  10725. + } else {
  10726. + sprintf_alloc(&dest->root_dir, "%s/", root_dir);
  10727. + }
  10728. + file_mkdir_hier(dest->root_dir, 0755);
  10729. +
  10730. + sprintf_alloc(&dest->ipkg_dir, "%s%s",
  10731. + dest->root_dir, IPKG_STATE_DIR_PREFIX);
  10732. + file_mkdir_hier(dest->ipkg_dir, 0755);
  10733. +
  10734. + if (str_starts_with (lists_dir, "/"))
  10735. + sprintf_alloc(&dest->lists_dir, "%s", lists_dir);
  10736. + else
  10737. + sprintf_alloc(&dest->lists_dir, "/%s", lists_dir);
  10738. +
  10739. + file_mkdir_hier(dest->lists_dir, 0755);
  10740. +
  10741. + sprintf_alloc(&dest->info_dir, "%s/%s",
  10742. + dest->ipkg_dir, IPKG_INFO_DIR_SUFFIX);
  10743. + file_mkdir_hier(dest->info_dir, 0755);
  10744. +
  10745. + sprintf_alloc(&dest->status_file_name, "%s/%s",
  10746. + dest->ipkg_dir, IPKG_STATUS_FILE_SUFFIX);
  10747. +
  10748. + sprintf_alloc(&dest->status_file_tmp_name, "%s/%s.tmp",
  10749. + dest->ipkg_dir, IPKG_STATUS_FILE_SUFFIX);
  10750. +
  10751. + dest->status_file = NULL;
  10752. +
  10753. + return 0;
  10754. +}
  10755. +
  10756. +void pkg_dest_deinit(pkg_dest_t *dest)
  10757. +{
  10758. + free(dest->name);
  10759. + dest->name = NULL;
  10760. +
  10761. + free(dest->root_dir);
  10762. + dest->root_dir = NULL;
  10763. +
  10764. + free(dest->ipkg_dir);
  10765. + dest->ipkg_dir = NULL;
  10766. +
  10767. + free(dest->lists_dir);
  10768. + dest->lists_dir = NULL;
  10769. +
  10770. + free(dest->info_dir);
  10771. + dest->info_dir = NULL;
  10772. +
  10773. + free(dest->status_file_name);
  10774. + dest->status_file_name = NULL;
  10775. +
  10776. + free(dest->status_file_tmp_name);
  10777. + dest->status_file_tmp_name = NULL;
  10778. +
  10779. + if (dest->status_file) {
  10780. + fclose(dest->status_file);
  10781. + }
  10782. + dest->status_file = NULL;
  10783. +
  10784. + dest->root_dir = NULL;
  10785. +}
  10786. diff -Nur busybox-1.17.2.orig/archival/libipkg/pkg_dest.h busybox-1.17.2/archival/libipkg/pkg_dest.h
  10787. --- busybox-1.17.2.orig/archival/libipkg/pkg_dest.h 1970-01-01 01:00:00.000000000 +0100
  10788. +++ busybox-1.17.2/archival/libipkg/pkg_dest.h 2010-12-01 22:25:23.000000000 +0100
  10789. @@ -0,0 +1,38 @@
  10790. +/* pkg_dest.h - the itsy package management system
  10791. +
  10792. + Carl D. Worth
  10793. +
  10794. + Copyright (C) 2001 University of Southern California
  10795. +
  10796. + This program is free software; you can redistribute it and/or
  10797. + modify it under the terms of the GNU General Public License as
  10798. + published by the Free Software Foundation; either version 2, or (at
  10799. + your option) any later version.
  10800. +
  10801. + This program is distributed in the hope that it will be useful, but
  10802. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10803. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10804. + General Public License for more details.
  10805. +*/
  10806. +
  10807. +#ifndef PKG_DEST_H
  10808. +#define PKG_DEST_H
  10809. +
  10810. +typedef struct pkg_dest pkg_dest_t;
  10811. +struct pkg_dest
  10812. +{
  10813. + char *name;
  10814. + char *root_dir;
  10815. + char *ipkg_dir;
  10816. + char *lists_dir;
  10817. + char *info_dir;
  10818. + char *status_file_name;
  10819. + char *status_file_tmp_name;
  10820. + FILE *status_file;
  10821. +};
  10822. +
  10823. +int pkg_dest_init(pkg_dest_t *dest, const char *name, const char *root_dir,const char *lists_dir);
  10824. +void pkg_dest_deinit(pkg_dest_t *dest);
  10825. +
  10826. +#endif
  10827. +
  10828. diff -Nur busybox-1.17.2.orig/archival/libipkg/pkg_dest_list.c busybox-1.17.2/archival/libipkg/pkg_dest_list.c
  10829. --- busybox-1.17.2.orig/archival/libipkg/pkg_dest_list.c 1970-01-01 01:00:00.000000000 +0100
  10830. +++ busybox-1.17.2/archival/libipkg/pkg_dest_list.c 2010-12-01 22:25:23.000000000 +0100
  10831. @@ -0,0 +1,85 @@
  10832. +/* pkg_dest_list.c - the itsy package management system
  10833. +
  10834. + Carl D. Worth
  10835. +
  10836. + Copyright (C) 2001 University of Southern California
  10837. +
  10838. + This program is free software; you can redistribute it and/or
  10839. + modify it under the terms of the GNU General Public License as
  10840. + published by the Free Software Foundation; either version 2, or (at
  10841. + your option) any later version.
  10842. +
  10843. + This program is distributed in the hope that it will be useful, but
  10844. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10845. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10846. + General Public License for more details.
  10847. +*/
  10848. +
  10849. +#include "ipkg.h"
  10850. +
  10851. +#include "pkg_dest.h"
  10852. +#include "void_list.h"
  10853. +#include "pkg_dest_list.h"
  10854. +
  10855. +int pkg_dest_list_elt_init(pkg_dest_list_elt_t *elt, pkg_dest_t *data)
  10856. +{
  10857. + return void_list_elt_init((void_list_elt_t *) elt, data);
  10858. +}
  10859. +
  10860. +void pkg_dest_list_elt_deinit(pkg_dest_list_elt_t *elt)
  10861. +{
  10862. + void_list_elt_deinit((void_list_elt_t *) elt);
  10863. +}
  10864. +
  10865. +int pkg_dest_list_init(pkg_dest_list_t *list)
  10866. +{
  10867. + return void_list_init((void_list_t *) list);
  10868. +}
  10869. +
  10870. +void pkg_dest_list_deinit(pkg_dest_list_t *list)
  10871. +{
  10872. + pkg_dest_list_elt_t *iter;
  10873. + pkg_dest_t *pkg_dest;
  10874. +
  10875. + for (iter = list->head; iter; iter = iter->next) {
  10876. + pkg_dest = iter->data;
  10877. + pkg_dest_deinit(pkg_dest);
  10878. +
  10879. + /* malloced in pkg_dest_list_append */
  10880. + free(pkg_dest);
  10881. + iter->data = NULL;
  10882. + }
  10883. + void_list_deinit((void_list_t *) list);
  10884. +}
  10885. +
  10886. +pkg_dest_t *pkg_dest_list_append(pkg_dest_list_t *list, const char *name,
  10887. + const char *root_dir,const char *lists_dir)
  10888. +{
  10889. + int err;
  10890. + pkg_dest_t *pkg_dest;
  10891. +
  10892. + /* freed in plg_dest_list_deinit */
  10893. + pkg_dest = malloc(sizeof(pkg_dest_t));
  10894. + if (pkg_dest == NULL) {
  10895. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10896. + return NULL;
  10897. + }
  10898. +
  10899. + pkg_dest_init(pkg_dest, name, root_dir,lists_dir);
  10900. + err = void_list_append((void_list_t *) list, pkg_dest);
  10901. + if (err) {
  10902. + return NULL;
  10903. + }
  10904. +
  10905. + return pkg_dest;
  10906. +}
  10907. +
  10908. +int pkg_dest_list_push(pkg_dest_list_t *list, pkg_dest_t *data)
  10909. +{
  10910. + return void_list_push((void_list_t *) list, data);
  10911. +}
  10912. +
  10913. +pkg_dest_list_elt_t *pkg_dest_list_pop(pkg_dest_list_t *list)
  10914. +{
  10915. + return (pkg_dest_list_elt_t *) void_list_pop((void_list_t *) list);
  10916. +}
  10917. diff -Nur busybox-1.17.2.orig/archival/libipkg/pkg_dest_list.h busybox-1.17.2/archival/libipkg/pkg_dest_list.h
  10918. --- busybox-1.17.2.orig/archival/libipkg/pkg_dest_list.h 1970-01-01 01:00:00.000000000 +0100
  10919. +++ busybox-1.17.2/archival/libipkg/pkg_dest_list.h 2010-12-01 22:25:23.000000000 +0100
  10920. @@ -0,0 +1,50 @@
  10921. +/* pkg_dest_list.h - the itsy package management system
  10922. +
  10923. + Carl D. Worth
  10924. +
  10925. + Copyright (C) 2001 University of Southern California
  10926. +
  10927. + This program is free software; you can redistribute it and/or
  10928. + modify it under the terms of the GNU General Public License as
  10929. + published by the Free Software Foundation; either version 2, or (at
  10930. + your option) any later version.
  10931. +
  10932. + This program is distributed in the hope that it will be useful, but
  10933. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10934. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10935. + General Public License for more details.
  10936. +*/
  10937. +
  10938. +#ifndef PKG_DEST_LIST_H
  10939. +#define PKG_DEST_LIST_H
  10940. +
  10941. +#include "pkg_dest.h"
  10942. +
  10943. +typedef struct pkg_dest_list_elt pkg_dest_list_elt_t;
  10944. +struct pkg_dest_list_elt
  10945. +{
  10946. + pkg_dest_list_elt_t *next;
  10947. + pkg_dest_t *data;
  10948. +};
  10949. +
  10950. +typedef struct pkg_dest_list pkg_dest_list_t;
  10951. +struct pkg_dest_list
  10952. +{
  10953. + pkg_dest_list_elt_t pre_head;
  10954. + pkg_dest_list_elt_t *head;
  10955. + pkg_dest_list_elt_t *tail;
  10956. +};
  10957. +
  10958. +int pkg_dest_list_elt_init(pkg_dest_list_elt_t *elt, pkg_dest_t *data);
  10959. +void pkg_dest_list_elt_deinit(pkg_dest_list_elt_t *elt);
  10960. +
  10961. +int pkg_dest_list_init(pkg_dest_list_t *list);
  10962. +void pkg_dest_list_deinit(pkg_dest_list_t *list);
  10963. +
  10964. +pkg_dest_t *pkg_dest_list_append(pkg_dest_list_t *list, const char *name,
  10965. + const char *root_dir,const char* lists_dir);
  10966. +int pkg_dest_list_push(pkg_dest_list_t *list, pkg_dest_t *data);
  10967. +pkg_dest_list_elt_t *pkg_dest_list_pop(pkg_dest_list_t *list);
  10968. +
  10969. +#endif
  10970. +
  10971. diff -Nur busybox-1.17.2.orig/archival/libipkg/pkg_extract.c busybox-1.17.2/archival/libipkg/pkg_extract.c
  10972. --- busybox-1.17.2.orig/archival/libipkg/pkg_extract.c 1970-01-01 01:00:00.000000000 +0100
  10973. +++ busybox-1.17.2/archival/libipkg/pkg_extract.c 2010-12-01 22:27:00.000000000 +0100
  10974. @@ -0,0 +1,255 @@
  10975. +/* pkg_extract.c - the itsy package management system
  10976. +
  10977. + Carl D. Worth
  10978. +
  10979. + Copyright (C) 2001 University of Southern California
  10980. +
  10981. + This program is free software; you can redistribute it and/or
  10982. + modify it under the terms of the GNU General Public License as
  10983. + published by the Free Software Foundation; either version 2, or (at
  10984. + your option) any later version.
  10985. +
  10986. + This program is distributed in the hope that it will be useful, but
  10987. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10988. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10989. + General Public License for more details.
  10990. +*/
  10991. +
  10992. +#include "ipkg.h"
  10993. +#include <errno.h>
  10994. +#include <fcntl.h>
  10995. +#include <stdio.h>
  10996. +
  10997. +#include "pkg_extract.h"
  10998. +
  10999. +#include "libbb.h"
  11000. +#include "file_util.h"
  11001. +#include "sprintf_alloc.h"
  11002. +#include "unarchive.h"
  11003. +
  11004. +#define IPKG_CONTROL_ARCHIVE "control.tar.gz"
  11005. +#define IPKG_DATA_ARCHIVE "data.tar.gz"
  11006. +#define IPKG_CONTROL_FILE "control"
  11007. +
  11008. +static void FAST_FUNC ipkg_data_extract_all_prefix(archive_handle_t *archive_handle)
  11009. +{
  11010. + char *name_ptr = archive_handle->file_header->name;
  11011. +
  11012. + /* Skip all leading "/" */
  11013. + while (*name_ptr == '/')
  11014. + name_ptr++;
  11015. + /* Skip all leading "./" and "../" */
  11016. + while (name_ptr[0] == '.') {
  11017. + if (name_ptr[1] == '.' && name_ptr[2] == '/')
  11018. + name_ptr++;
  11019. + if (name_ptr[1] != '/')
  11020. + break;
  11021. + name_ptr += 2;
  11022. + }
  11023. +
  11024. + if (name_ptr[0] != '\0') {
  11025. + archive_handle->file_header->name = xasprintf("%s%s", archive_handle->dpkg__buffer, name_ptr);
  11026. + data_extract_all(archive_handle);
  11027. + }
  11028. +}
  11029. +
  11030. +static void FAST_FUNC ipkg_data_extract_to_buffer(archive_handle_t *archive_handle)
  11031. +{
  11032. + unsigned size = archive_handle->file_header->size;
  11033. +
  11034. + archive_handle->dpkg__buffer = xzalloc(size + 1);
  11035. + xread(archive_handle->src_fd, archive_handle->dpkg__buffer, size);
  11036. +}
  11037. +
  11038. +static void extract_ipkg_file_to_dir(pkg_t *pkg, const char *dir, const char *filename)
  11039. +{
  11040. + archive_handle_t *archive;
  11041. + char *path;
  11042. +
  11043. + sprintf_alloc(&path, "%s/", dir);
  11044. + archive = init_handle();
  11045. + archive->src_fd = xopen(pkg->local_filename, O_RDONLY);
  11046. + archive->filter = filter_accept_list;
  11047. + llist_add_to(&(archive->accept), (char *)filename);
  11048. + archive->dpkg__buffer = path;
  11049. + archive->action_data = ipkg_data_extract_all_prefix;
  11050. + archive->ah_flags |= ARCHIVE_UNLINK_OLD;
  11051. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  11052. + close(archive->src_fd);
  11053. + free(archive->accept);
  11054. + free(archive);
  11055. + free(path);
  11056. +}
  11057. +
  11058. +static void FAST_FUNC data_extract_file_name_to_buffer(archive_handle_t *archive)
  11059. +{
  11060. + unsigned int size = strlen(archive->file_header->name) + 2;
  11061. +
  11062. + if (archive->dpkg__buffer == NULL) {
  11063. + archive->dpkg__buffer = xmalloc(size);
  11064. + strcpy(archive->dpkg__buffer, archive->file_header->name);
  11065. + } else {
  11066. + size += strlen(archive->dpkg__buffer);
  11067. + archive->dpkg__buffer = xrealloc(archive->dpkg__buffer, size);
  11068. + strcat(archive->dpkg__buffer, archive->file_header->name);
  11069. + }
  11070. + strcat(archive->dpkg__buffer, "\n");
  11071. + data_skip(archive);
  11072. +}
  11073. +
  11074. +int pkg_extract_control_file_to_stream(pkg_t *pkg, FILE *stream)
  11075. +{
  11076. + archive_handle_t *archive;
  11077. + char *name;
  11078. + const char *filename = IPKG_CONTROL_FILE;
  11079. +
  11080. + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_CONTROL_ARCHIVE);
  11081. + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_CONTROL_ARCHIVE);
  11082. + archive = init_handle();
  11083. + archive->src_fd = xopen(name, O_RDONLY);
  11084. + archive->filter = filter_accept_list;
  11085. + llist_add_to(&(archive->accept), (char *)filename);
  11086. + archive->action_data = ipkg_data_extract_to_buffer;
  11087. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  11088. + close(archive->src_fd);
  11089. + fputs(archive->dpkg__buffer, stream);
  11090. + free(archive->dpkg__buffer);
  11091. + free(archive->accept);
  11092. + free(archive);
  11093. + free(name);
  11094. +
  11095. + return 0;
  11096. +}
  11097. +
  11098. +int pkg_extract_control_files_to_dir(pkg_t *pkg, const char *dir)
  11099. +{
  11100. + return pkg_extract_control_files_to_dir_with_prefix(pkg, dir, "");
  11101. +}
  11102. +
  11103. +int pkg_extract_control_files_to_dir_with_prefix(pkg_t *pkg, const char *dir, const char *prefix)
  11104. +{
  11105. + archive_handle_t *archive;
  11106. + char *name;
  11107. + char *path;
  11108. +
  11109. + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_CONTROL_ARCHIVE);
  11110. + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_CONTROL_ARCHIVE);
  11111. + sprintf_alloc(&path, "%s/%s", dir, prefix);
  11112. + archive = init_handle();
  11113. + archive->src_fd = xopen(name, O_RDONLY);
  11114. + archive->filter = filter_accept_all;
  11115. + archive->dpkg__buffer = path;
  11116. + archive->action_data = ipkg_data_extract_all_prefix;
  11117. + archive->ah_flags |= ARCHIVE_CREATE_LEADING_DIRS | ARCHIVE_RESTORE_DATE | ARCHIVE_UNLINK_OLD;
  11118. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  11119. + close(archive->src_fd);
  11120. + free(archive);
  11121. + free(path);
  11122. + free(name);
  11123. +
  11124. + return 0;
  11125. +}
  11126. +
  11127. +int pkg_extract_data_files_to_dir(pkg_t *pkg, const char *dir)
  11128. +{
  11129. + archive_handle_t *archive;
  11130. + char *name;
  11131. + char *path;
  11132. +
  11133. + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_DATA_ARCHIVE);
  11134. + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_DATA_ARCHIVE);
  11135. + sprintf_alloc(&path, "%s/", dir);
  11136. + archive = init_handle();
  11137. + archive->src_fd = xopen(name, O_RDONLY);
  11138. + archive->filter = filter_accept_all;
  11139. + archive->dpkg__buffer = path;
  11140. + archive->action_data = ipkg_data_extract_all_prefix;
  11141. + archive->ah_flags |= ARCHIVE_CREATE_LEADING_DIRS | ARCHIVE_RESTORE_DATE | ARCHIVE_UNLINK_OLD;
  11142. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  11143. + close(archive->src_fd);
  11144. + free(archive);
  11145. + free(path);
  11146. + free(name);
  11147. +
  11148. + return 0;
  11149. +}
  11150. +
  11151. +int pkg_extract_data_file_names_to_file(pkg_t *pkg, const char *file_name)
  11152. +{
  11153. + int err=0;
  11154. + char *line, *data_file;
  11155. + FILE *file;
  11156. + FILE *tmp;
  11157. +
  11158. + file = fopen(file_name, "w");
  11159. + if (file == NULL) {
  11160. + fprintf(stderr, "%s: ERROR: Failed to open %s for writing.\n",
  11161. + __FUNCTION__, file_name);
  11162. + return EINVAL;
  11163. + }
  11164. +
  11165. + tmp = tmpfile();
  11166. + if (pkg->installed_files) {
  11167. + str_list_elt_t *elt;
  11168. + for (elt = pkg->installed_files->head; elt; elt = elt->next) {
  11169. + fprintf(file, "%s\n", elt->data);
  11170. + }
  11171. + } else {
  11172. + err = pkg_extract_data_file_names_to_stream(pkg, tmp);
  11173. + if (err) {
  11174. + fclose(file);
  11175. + fclose(tmp);
  11176. + return err;
  11177. + }
  11178. +
  11179. + /* Fixup data file names by removing the initial '.' */
  11180. + rewind(tmp);
  11181. + while (1) {
  11182. + line = file_read_line_alloc(tmp);
  11183. + if (line == NULL) {
  11184. + break;
  11185. + }
  11186. +
  11187. + data_file = line;
  11188. + if (*data_file == '.') {
  11189. + data_file++;
  11190. + }
  11191. +
  11192. + if (*data_file != '/') {
  11193. + fputs("/", file);
  11194. + }
  11195. +
  11196. + /* I have no idea why, but this is what dpkg does */
  11197. + if (strcmp(data_file, "/\n") == 0) {
  11198. + fputs("/.\n", file);
  11199. + } else {
  11200. + fputs(data_file, file);
  11201. + }
  11202. + }
  11203. + }
  11204. + fclose(tmp);
  11205. + fclose(file);
  11206. +
  11207. + return err;
  11208. +}
  11209. +
  11210. +int pkg_extract_data_file_names_to_stream(pkg_t *pkg, FILE *file)
  11211. +{
  11212. + archive_handle_t *archive;
  11213. + char *name;
  11214. +
  11215. + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_DATA_ARCHIVE);
  11216. + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_DATA_ARCHIVE);
  11217. + archive = init_handle();
  11218. + archive->src_fd = xopen(name, O_RDONLY);
  11219. + archive->filter = filter_accept_all;
  11220. + archive->action_data = data_extract_file_name_to_buffer;
  11221. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  11222. + close(archive->src_fd);
  11223. + fputs(archive->dpkg__buffer, file);
  11224. + free(archive->dpkg__buffer);
  11225. + free(archive);
  11226. + free(name);
  11227. +
  11228. + return 0;
  11229. +}
  11230. diff -Nur busybox-1.17.2.orig/archival/libipkg/pkg_extract.h busybox-1.17.2/archival/libipkg/pkg_extract.h
  11231. --- busybox-1.17.2.orig/archival/libipkg/pkg_extract.h 1970-01-01 01:00:00.000000000 +0100
  11232. +++ busybox-1.17.2/archival/libipkg/pkg_extract.h 2010-12-01 22:25:23.000000000 +0100
  11233. @@ -0,0 +1,32 @@
  11234. +/* pkg_extract.c - the itsy package management system
  11235. +
  11236. + Carl D. Worth
  11237. +
  11238. + Copyright (C) 2001 University of Southern California
  11239. +
  11240. + This program is free software; you can redistribute it and/or
  11241. + modify it under the terms of the GNU General Public License as
  11242. + published by the Free Software Foundation; either version 2, or (at
  11243. + your option) any later version.
  11244. +
  11245. + This program is distributed in the hope that it will be useful, but
  11246. + WITHOUT ANY WARRANTY; without even the implied warranty of
  11247. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11248. + General Public License for more details.
  11249. +*/
  11250. +
  11251. +#ifndef PKG_EXTRACT_H
  11252. +#define PKG_EXTRACT_H
  11253. +
  11254. +#include "pkg.h"
  11255. +
  11256. +int pkg_extract_control_file_to_stream(pkg_t *pkg, FILE *stream);
  11257. +int pkg_extract_control_files_to_dir(pkg_t *pkg, const char *dir);
  11258. +int pkg_extract_control_files_to_dir_with_prefix(pkg_t *pkg,
  11259. + const char *dir,
  11260. + const char *prefix);
  11261. +int pkg_extract_data_files_to_dir(pkg_t *pkg, const char *dir);
  11262. +int pkg_extract_data_file_names_to_file(pkg_t *pkg, const char *file_name);
  11263. +int pkg_extract_data_file_names_to_stream(pkg_t *pkg, FILE *file);
  11264. +
  11265. +#endif
  11266. diff -Nur busybox-1.17.2.orig/archival/libipkg/pkg_hash.c busybox-1.17.2/archival/libipkg/pkg_hash.c
  11267. --- busybox-1.17.2.orig/archival/libipkg/pkg_hash.c 1970-01-01 01:00:00.000000000 +0100
  11268. +++ busybox-1.17.2/archival/libipkg/pkg_hash.c 2010-12-01 22:25:23.000000000 +0100
  11269. @@ -0,0 +1,623 @@
  11270. +/* ipkg_hash.c - the itsy package management system
  11271. +
  11272. + Steven M. Ayer
  11273. +
  11274. + Copyright (C) 2002 Compaq Computer Corporation
  11275. +
  11276. + This program is free software; you can redistribute it and/or
  11277. + modify it under the terms of the GNU General Public License as
  11278. + published by the Free Software Foundation; either version 2, or (at
  11279. + your option) any later version.
  11280. +
  11281. + This program is distributed in the hope that it will be useful, but
  11282. + WITHOUT ANY WARRANTY; without even the implied warranty of
  11283. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11284. + General Public License for more details.
  11285. +*/
  11286. +
  11287. +#include "ipkg.h"
  11288. +#include <errno.h>
  11289. +#include <ctype.h>
  11290. +#include <stdlib.h>
  11291. +#include <string.h>
  11292. +
  11293. +#include "hash_table.h"
  11294. +#include "pkg.h"
  11295. +#include "ipkg_message.h"
  11296. +#include "pkg_vec.h"
  11297. +#include "pkg_hash.h"
  11298. +#include "pkg_parse.h"
  11299. +#include "ipkg_utils.h"
  11300. +
  11301. +static abstract_pkg_t * add_new_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name);
  11302. +
  11303. +/*
  11304. + * this will talk to both feeds-lists files and installed status files
  11305. + * example api:
  11306. + *
  11307. + * hash_table_t hash;
  11308. + * pkg_hash_init(name, &hash, 1000);
  11309. + * pkg_hash_add_from_file(<feed filename>);
  11310. + *
  11311. + * the query function is just there as a shell to prove to me that this
  11312. + * sort of works, but isn't far from doing something useful
  11313. + *
  11314. + * -sma, 12/21/01
  11315. + * modified: CDW 3 Jan. 2002
  11316. + */
  11317. +
  11318. +
  11319. +
  11320. +int pkg_hash_init(const char *name, hash_table_t *hash, int len)
  11321. +{
  11322. + return hash_table_init(name, hash, len);
  11323. +}
  11324. +
  11325. +void pkg_hash_deinit(hash_table_t *hash)
  11326. +{
  11327. + hash_table_deinit(hash);
  11328. +}
  11329. +
  11330. +
  11331. +/* Find the default arch for a given package status file if none is given. */
  11332. +static char *pkg_get_default_arch(ipkg_conf_t *conf)
  11333. +{
  11334. + nv_pair_list_elt_t *l;
  11335. + const char *def_arch = HOST_CPU_STR; /* Default arch */
  11336. + int def_prio = 0; /* Other archs override this */
  11337. +
  11338. + l = conf->arch_list.head;
  11339. +
  11340. + while (l) {
  11341. + nv_pair_t *nv = l->data;
  11342. + int priority = strtol(nv->value, NULL, 0);
  11343. +
  11344. + /* Check if this arch has higher priority, and is valid */
  11345. + if ((priority > def_prio) &&
  11346. + (strcmp(nv->name, "all")) && (strcmp(nv->name, "noarch"))) {
  11347. + /* Our new default */
  11348. + def_prio = priority;
  11349. + def_arch = nv->name;
  11350. + }
  11351. + l = l->next;
  11352. + }
  11353. +
  11354. + return strdup(def_arch);
  11355. +}
  11356. +
  11357. +int pkg_hash_add_from_file(ipkg_conf_t *conf, const char *file_name,
  11358. + pkg_src_t *src, pkg_dest_t *dest, int is_status_file)
  11359. +{
  11360. + hash_table_t *hash = &conf->pkg_hash;
  11361. + char **raw;
  11362. + char **raw_start;
  11363. + pkg_t *pkg;
  11364. +
  11365. + raw = raw_start = read_raw_pkgs_from_file(file_name);
  11366. + if (!raw)
  11367. + return -ENOMEM;
  11368. +
  11369. + while(*raw){ /* don't worry, we'll increment raw in the parsing function */
  11370. + pkg = pkg_new();
  11371. + if (!pkg)
  11372. + return -ENOMEM;
  11373. +
  11374. + if (pkg_parse_raw(pkg, &raw, src, dest) == 0) {
  11375. + if (!pkg->architecture) {
  11376. + char *version_str = pkg_version_str_alloc(pkg);
  11377. + pkg->architecture = pkg_get_default_arch(conf);
  11378. + ipkg_message(conf, IPKG_ERROR, "Package %s version %s has no architecture specified, defaulting to %s.\n",
  11379. + pkg->name, version_str, pkg->architecture);
  11380. + free(version_str);
  11381. + }
  11382. + hash_insert_pkg(hash, pkg, is_status_file,conf);
  11383. + } else {
  11384. + free(pkg);
  11385. + }
  11386. + }
  11387. +
  11388. + /* XXX: CLEANUP: I'd like a cleaner interface for cleaning up
  11389. + memory after read_raw_pkgs_from_file */
  11390. + raw = raw_start;
  11391. + while (*raw) {
  11392. + free(*raw++);
  11393. + }
  11394. + free(raw_start);
  11395. + return 0;
  11396. +}
  11397. +
  11398. +abstract_pkg_t * abstract_pkg_fetch_by_name(hash_table_t * hash, const char * pkg_name)
  11399. +{
  11400. + return (abstract_pkg_t *)hash_table_get(hash, pkg_name);
  11401. +}
  11402. +
  11403. +abstract_pkg_vec_t *pkg_hash_fetch_all_installation_candidates(hash_table_t *hash, const char *name)
  11404. +{
  11405. + abstract_pkg_t *apkg = abstract_pkg_fetch_by_name(hash, name);
  11406. + if (apkg)
  11407. + return NULL;
  11408. + return apkg->provided_by;
  11409. +}
  11410. +
  11411. +
  11412. +pkg_t *pkg_hash_fetch_best_installation_candidate(ipkg_conf_t *conf, abstract_pkg_t *apkg,
  11413. + int (*constraint_fcn)(pkg_t *pkg, void *cdata), void *cdata, int quiet)
  11414. +{
  11415. + int i;
  11416. + int nprovides = 0;
  11417. + int nmatching = 0;
  11418. + pkg_vec_t *matching_pkgs = pkg_vec_alloc();
  11419. + abstract_pkg_vec_t *matching_apkgs = abstract_pkg_vec_alloc();
  11420. + abstract_pkg_vec_t *provided_apkg_vec;
  11421. + abstract_pkg_t **provided_apkgs;
  11422. + abstract_pkg_vec_t *providers = abstract_pkg_vec_alloc();
  11423. + pkg_t *latest_installed_parent = NULL;
  11424. + pkg_t *latest_matching = NULL;
  11425. + pkg_t *held_pkg = NULL;
  11426. + pkg_t *good_pkg_by_name = NULL;
  11427. +
  11428. + if (matching_apkgs == NULL || providers == NULL ||
  11429. + apkg == NULL || apkg->provided_by == NULL || (apkg->provided_by->len == 0))
  11430. + return NULL;
  11431. +
  11432. + ipkg_message(conf, IPKG_DEBUG, "best installation candidate for %s\n", apkg->name);
  11433. +
  11434. + provided_apkg_vec = apkg->provided_by;
  11435. + nprovides = provided_apkg_vec->len;
  11436. + provided_apkgs = provided_apkg_vec->pkgs;
  11437. + if (nprovides > 1)
  11438. + ipkg_message(conf, IPKG_DEBUG, " apkg=%s nprovides=%d\n", apkg->name, nprovides);
  11439. +
  11440. + /* accumulate all the providers */
  11441. + for (i = 0; i < nprovides; i++) {
  11442. + abstract_pkg_t *provider_apkg = provided_apkgs[i];
  11443. + ipkg_message(conf, IPKG_DEBUG, " adding %s to providers\n", provider_apkg->name);
  11444. + abstract_pkg_vec_insert(providers, provider_apkg);
  11445. + }
  11446. + nprovides = providers->len;
  11447. +
  11448. + for (i = 0; i < nprovides; i++) {
  11449. + abstract_pkg_t *provider_apkg = abstract_pkg_vec_get(providers, i);
  11450. + abstract_pkg_t *replacement_apkg = NULL;
  11451. + pkg_vec_t *vec;
  11452. +
  11453. + if (provider_apkg->replaced_by && provider_apkg->replaced_by->len) {
  11454. + replacement_apkg = provider_apkg->replaced_by->pkgs[0];
  11455. + if (provider_apkg->replaced_by->len > 1) {
  11456. + ipkg_message(conf, IPKG_NOTICE, "Multiple replacers for %s, using first one (%s)\n",
  11457. + provider_apkg->name, replacement_apkg->name);
  11458. + }
  11459. + }
  11460. +
  11461. + if (replacement_apkg)
  11462. + ipkg_message(conf, IPKG_DEBUG, " replacement_apkg=%s for provider_apkg=%s\n",
  11463. + replacement_apkg->name, provider_apkg->name);
  11464. +
  11465. + if (replacement_apkg && (replacement_apkg != provider_apkg)) {
  11466. + if (abstract_pkg_vec_contains(providers, replacement_apkg))
  11467. + continue;
  11468. + else
  11469. + provider_apkg = replacement_apkg;
  11470. + }
  11471. +
  11472. + if (!(vec = provider_apkg->pkgs)) {
  11473. + ipkg_message(conf, IPKG_DEBUG, " no pkgs for provider_apkg %s\n", provider_apkg->name);
  11474. + continue;
  11475. + }
  11476. +
  11477. +
  11478. + /* now check for supported architecture */
  11479. + {
  11480. + int max_count = 0;
  11481. + int j;
  11482. +
  11483. + /* count packages matching max arch priority and keep track of last one */
  11484. + for (j = 0; j < vec->len; j++) {
  11485. + pkg_t *maybe = vec->pkgs[j];
  11486. + ipkg_message(conf, IPKG_DEBUG, " %s arch=%s arch_priority=%d version=%s \n",
  11487. + maybe->name, maybe->architecture, maybe->arch_priority, maybe->version);
  11488. + if (maybe->arch_priority > 0) {
  11489. + max_count++;
  11490. + abstract_pkg_vec_insert(matching_apkgs, maybe->parent);
  11491. + pkg_vec_insert(matching_pkgs, maybe);
  11492. + }
  11493. + }
  11494. + }
  11495. + }
  11496. +
  11497. + if (matching_pkgs->len > 1)
  11498. + pkg_vec_sort(matching_pkgs, pkg_name_version_and_architecture_compare);
  11499. + if (matching_apkgs->len > 1)
  11500. + abstract_pkg_vec_sort(matching_pkgs, abstract_pkg_name_compare);
  11501. +
  11502. +/* Here it is usefull, if ( matching_apkgs->len > 1 ), to test if one of this matching packages has the same name of the
  11503. + needed package. In this case, I would return it for install, otherwise I will continue with the procedure */
  11504. +/* The problem is what to do when there are more than a mathing package, with the same name and several version ?
  11505. + Until now I always got the latest, but that breaks the downgrade option.
  11506. + If I stop at the first one, I would probably miss the new ones
  11507. + Maybe the way is to have some kind of flag somewhere, to see if the package been asked to install is from a file,
  11508. + or from a Packages feed.
  11509. + 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*/
  11510. +/*Pigi*/
  11511. +
  11512. + for (i = 0; i < matching_pkgs->len; i++) {
  11513. + pkg_t *matching = matching_pkgs->pkgs[i];
  11514. + if (constraint_fcn(matching, cdata)) { /* We found it */
  11515. + ipkg_message(conf, IPKG_DEBUG, " Found a valid candidate for the install: %s %s \n", matching->name, matching->version) ;
  11516. + good_pkg_by_name = matching;
  11517. + if ( matching->provided_by_hand == 1 ) /* It has been provided by hand, so it is what user want */
  11518. + break;
  11519. + }
  11520. + }
  11521. +
  11522. +
  11523. + for (i = 0; i < matching_pkgs->len; i++) {
  11524. + pkg_t *matching = matching_pkgs->pkgs[i];
  11525. + latest_matching = matching;
  11526. + if (matching->parent->state_status == SS_INSTALLED || matching->parent->state_status == SS_UNPACKED)
  11527. + latest_installed_parent = matching;
  11528. + if (matching->state_flag & (SF_HOLD|SF_PREFER)) {
  11529. + if (held_pkg)
  11530. + ipkg_message(conf, IPKG_ERROR, "Multiple packages (%s and %s) providing same name marked HOLD or PREFER. Using latest.\n",
  11531. + held_pkg->name, matching->name);
  11532. + held_pkg = matching;
  11533. + }
  11534. + }
  11535. +
  11536. + if (!good_pkg_by_name && !held_pkg && !latest_installed_parent && matching_apkgs->len > 1 && !quiet) {
  11537. + ipkg_message(conf, IPKG_ERROR, "Package=%s, %d matching providers\n",
  11538. + apkg->name, matching_apkgs->len);
  11539. + for (i = 0; i < matching_apkgs->len; i++) {
  11540. + abstract_pkg_t *matching = matching_apkgs->pkgs[i];
  11541. + ipkg_message(conf, IPKG_ERROR, " %s\n", matching->name);
  11542. + }
  11543. + ipkg_message(conf, IPKG_ERROR, "Please select one with ipkg install or ipkg flag prefer\n");
  11544. + }
  11545. +
  11546. + if (matching_apkgs->len > 1 && conf->verbosity > 1) {
  11547. + ipkg_message(conf, IPKG_NOTICE, "%s: for apkg=%s, %d matching pkgs\n",
  11548. + __FUNCTION__, apkg->name, matching_pkgs->len);
  11549. + for (i = 0; i < matching_pkgs->len; i++) {
  11550. + pkg_t *matching = matching_pkgs->pkgs[i];
  11551. + ipkg_message(conf, IPKG_INFO, " %s %s %s\n",
  11552. + matching->name, matching->version, matching->architecture);
  11553. + }
  11554. + }
  11555. +
  11556. + nmatching = matching_apkgs->len;
  11557. +
  11558. + pkg_vec_free(matching_pkgs);
  11559. + abstract_pkg_vec_free(matching_apkgs);
  11560. + abstract_pkg_vec_free(providers);
  11561. +
  11562. + if (good_pkg_by_name) { /* We found a good candidate, we will install it */
  11563. + return good_pkg_by_name;
  11564. + }
  11565. + if (held_pkg) {
  11566. + ipkg_message(conf, IPKG_INFO, " using held package %s\n", held_pkg->name);
  11567. + return held_pkg;
  11568. + }
  11569. + if (latest_installed_parent) {
  11570. + ipkg_message(conf, IPKG_INFO, " using latest version of installed package %s\n", latest_installed_parent->name);
  11571. + return latest_installed_parent;
  11572. + }
  11573. + if (nmatching > 1) {
  11574. + ipkg_message(conf, IPKG_INFO, " no matching pkg out of matching_apkgs=%d\n", nmatching);
  11575. + return NULL;
  11576. + }
  11577. + if (latest_matching) {
  11578. + ipkg_message(conf, IPKG_INFO, " using latest matching %s %s %s\n",
  11579. + latest_matching->name, latest_matching->version, latest_matching->architecture);
  11580. + return latest_matching;
  11581. + }
  11582. + return NULL;
  11583. +}
  11584. +
  11585. +static int pkg_name_constraint_fcn(pkg_t *pkg, void *cdata)
  11586. +{
  11587. + const char *name = (const char *)cdata;
  11588. + if (strcmp(pkg->name, name) == 0)
  11589. + return 1;
  11590. + else
  11591. + return 0;
  11592. +}
  11593. +
  11594. +pkg_t *pkg_hash_fetch_best_installation_candidate_by_name(ipkg_conf_t *conf, const char *name)
  11595. +{
  11596. + hash_table_t *hash = &conf->pkg_hash;
  11597. + abstract_pkg_t *apkg = NULL;
  11598. +
  11599. + if (!(apkg = abstract_pkg_fetch_by_name(hash, name)))
  11600. + return NULL;
  11601. +
  11602. + return pkg_hash_fetch_best_installation_candidate(conf, apkg, pkg_name_constraint_fcn, apkg->name, 0);
  11603. +}
  11604. +
  11605. +
  11606. +pkg_t * pkg_hash_fetch_by_name_version(hash_table_t *hash,
  11607. + const char *pkg_name,
  11608. + const char * version)
  11609. +{
  11610. + pkg_vec_t * vec;
  11611. + register int i;
  11612. + char *version_str = NULL;
  11613. +
  11614. + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name)))
  11615. + return NULL;
  11616. +
  11617. + for(i = 0; i < vec->len; i++) {
  11618. + version_str = pkg_version_str_alloc(vec->pkgs[i]);
  11619. + if(!strcmp(version_str, version)) {
  11620. + free(version_str);
  11621. + break;
  11622. + }
  11623. + free(version_str);
  11624. + }
  11625. +
  11626. + if(i == vec->len)
  11627. + return NULL;
  11628. +
  11629. + return vec->pkgs[i];
  11630. +}
  11631. +
  11632. +pkg_t *pkg_hash_fetch_installed_by_name_dest(hash_table_t *hash,
  11633. + const char *pkg_name,
  11634. + pkg_dest_t *dest)
  11635. +{
  11636. + pkg_vec_t * vec;
  11637. + register int i;
  11638. +
  11639. + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name))) {
  11640. + return NULL;
  11641. + }
  11642. +
  11643. + for(i = 0; i < vec->len; i++)
  11644. + if((vec->pkgs[i]->state_status == SS_INSTALLED || vec->pkgs[i]->state_status == SS_UNPACKED) && vec->pkgs[i]->dest == dest) {
  11645. + return vec->pkgs[i];
  11646. + }
  11647. + return NULL;
  11648. +}
  11649. +
  11650. +pkg_t *pkg_hash_fetch_installed_by_name(hash_table_t *hash,
  11651. + const char *pkg_name)
  11652. +{
  11653. + pkg_vec_t * vec;
  11654. + register int i;
  11655. +
  11656. + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name))){
  11657. + return NULL;
  11658. + }
  11659. +
  11660. + for(i = 0; i < vec->len; i++)
  11661. + if (vec->pkgs[i]->state_status == SS_INSTALLED || vec->pkgs[i]->state_status == SS_UNPACKED){
  11662. + return vec->pkgs[i];
  11663. + }
  11664. +
  11665. + return NULL;
  11666. +}
  11667. +
  11668. +pkg_vec_t *pkg_vec_fetch_by_name(hash_table_t *hash, const char *pkg_name)
  11669. +{
  11670. + abstract_pkg_t * ab_pkg;
  11671. +
  11672. + if(!(ab_pkg = abstract_pkg_fetch_by_name(hash, pkg_name))){
  11673. + return NULL;
  11674. + }
  11675. +
  11676. + if (ab_pkg->pkgs) {
  11677. + return ab_pkg->pkgs;
  11678. + } else if (ab_pkg->provided_by) {
  11679. + abstract_pkg_t *abpkg = abstract_pkg_vec_get(ab_pkg->provided_by, 0);
  11680. + if (abpkg != NULL){
  11681. + return abpkg->pkgs;
  11682. + } else {
  11683. + return ab_pkg->pkgs;
  11684. + }
  11685. + } else {
  11686. + return NULL;
  11687. + }
  11688. +}
  11689. +
  11690. +static int pkg_compare_names(const void *p1, const void *p2)
  11691. +{
  11692. + const pkg_t *pkg1 = *(const pkg_t **)p1;
  11693. + const pkg_t *pkg2 = *(const pkg_t **)p2;
  11694. + if (pkg1->name == NULL)
  11695. + return 1;
  11696. + if (pkg2->name == NULL)
  11697. + return -1;
  11698. + return(strcmp(pkg1->name, pkg2->name));
  11699. +}
  11700. +
  11701. +
  11702. +static void pkg_hash_fetch_available_helper(const char *pkg_name, void *entry, void *data)
  11703. +{
  11704. + int j;
  11705. + const char *name;
  11706. + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
  11707. + pkg_vec_t *all = (pkg_vec_t *)data;
  11708. + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
  11709. + name = pkg_name;
  11710. + if (pkg_vec) {
  11711. + for (j = 0; j < pkg_vec->len; j++) {
  11712. + pkg_t *pkg = pkg_vec->pkgs[j];
  11713. + pkg_vec_insert(all, pkg);
  11714. + }
  11715. + }
  11716. +}
  11717. +
  11718. +void pkg_hash_fetch_available(hash_table_t *hash, pkg_vec_t *all)
  11719. +{
  11720. + hash_table_foreach(hash, pkg_hash_fetch_available_helper, all);
  11721. + qsort(all->pkgs, all->len, sizeof(pkg_t *), pkg_compare_names);
  11722. +}
  11723. +
  11724. +static void pkg_hash_fetch_all_installed_helper(const char *pkg_name, void *entry, void *data)
  11725. +{
  11726. + const char *name;
  11727. + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
  11728. + pkg_vec_t *all = (pkg_vec_t *)data;
  11729. + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
  11730. + int j;
  11731. + name = pkg_name;
  11732. + if (pkg_vec) {
  11733. + for (j = 0; j < pkg_vec->len; j++) {
  11734. + pkg_t *pkg = pkg_vec->pkgs[j];
  11735. + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) {
  11736. + pkg_vec_insert(all, pkg);
  11737. + }
  11738. + }
  11739. + }
  11740. +}
  11741. +void pkg_hash_fetch_all_installed(hash_table_t *hash, pkg_vec_t *all)
  11742. +{
  11743. + hash_table_foreach(hash, pkg_hash_fetch_all_installed_helper, all);
  11744. + qsort(all->pkgs, all->len, sizeof(void*), pkg_compare_names);
  11745. +}
  11746. +
  11747. +static void pkg_hash_dump_helper(const char *pkg_name, void *entry, void *data)
  11748. +{
  11749. + int i;
  11750. + pkg_t *pkg;
  11751. + const char *name;
  11752. + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
  11753. + ipkg_conf_t *conf = (ipkg_conf_t *)data;
  11754. + abstract_pkg_t ** dependents = ab_pkg->depended_upon_by;
  11755. + name = pkg_name;
  11756. + fprintf(stdout, "%s\n", ab_pkg->name);
  11757. + i = 0;
  11758. + if (dependents != NULL)
  11759. + while (dependents [i] != NULL)
  11760. + printf ("\tdepended upon by - %s\n", dependents [i ++]->name);
  11761. + dependents = ab_pkg->provided_by->pkgs;
  11762. + i = 0;
  11763. + if (dependents != NULL)
  11764. + while (dependents [i] != NULL && i < ab_pkg->provided_by->len)
  11765. + printf ("\tprovided by - %s\n", dependents [i ++]->name);
  11766. + pkg = pkg_hash_fetch_best_installation_candidate_by_name (conf, ab_pkg->name);
  11767. + if (pkg) {
  11768. + i = 0;
  11769. + while (i < pkg->depends_count)
  11770. + printf ("\tdepends on - %s\n", pkg->depends_str [i ++]);
  11771. + }
  11772. +}
  11773. +void pkg_hash_dump(hash_table_t *hash, void *data)
  11774. +{
  11775. +
  11776. + printf ("\n\n+=+%s+=+\n\n", __FUNCTION__);
  11777. + hash_table_foreach(hash, pkg_hash_dump_helper, data);
  11778. + printf ("\n+=+%s+=+\n\n", __FUNCTION__);
  11779. +}
  11780. +
  11781. +abstract_pkg_t * ensure_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name)
  11782. +{
  11783. + abstract_pkg_t * ab_pkg;
  11784. +
  11785. + if(!(ab_pkg = abstract_pkg_fetch_by_name(hash, pkg_name)))
  11786. + ab_pkg = add_new_abstract_pkg_by_name(hash, pkg_name);
  11787. +
  11788. + return ab_pkg;
  11789. +}
  11790. +
  11791. +pkg_t *hash_insert_pkg(hash_table_t *hash, pkg_t *pkg, int set_status,ipkg_conf_t *conf)
  11792. +{
  11793. + abstract_pkg_t * ab_pkg;
  11794. + int arch_priority;
  11795. +
  11796. + if(!pkg)
  11797. + return pkg;
  11798. +
  11799. + arch_priority = pkg->arch_priority;
  11800. +
  11801. + if (buildDepends(hash, pkg)<0){
  11802. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  11803. + return NULL;
  11804. + }
  11805. + ab_pkg = ensure_abstract_pkg_by_name(hash, pkg->name);
  11806. +
  11807. + if (set_status) {
  11808. + if (pkg->state_status == SS_INSTALLED) {
  11809. + ab_pkg->state_status = SS_INSTALLED;
  11810. + } else if (pkg->state_status == SS_UNPACKED) {
  11811. + ab_pkg->state_status = SS_UNPACKED;
  11812. + }
  11813. + }
  11814. +
  11815. + if(!ab_pkg->pkgs)
  11816. + ab_pkg->pkgs = pkg_vec_alloc();
  11817. +
  11818. + /* pkg_vec_insert_merge might munge package, but it returns an unmunged pkg */
  11819. + pkg = pkg_vec_insert_merge(ab_pkg->pkgs, pkg, set_status,conf );
  11820. + pkg->parent = ab_pkg;
  11821. +
  11822. + if (buildProvides(hash, ab_pkg, pkg)<0){
  11823. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  11824. + return NULL;
  11825. + }
  11826. + /* need to build the conflicts graph before replaces for correct calculation of replaced_by relation */
  11827. + if (buildConflicts(hash, pkg)<0){
  11828. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  11829. + return NULL;
  11830. + }
  11831. + if (buildReplaces(hash, ab_pkg, pkg)<0) {
  11832. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  11833. + return NULL;
  11834. + }
  11835. +
  11836. + buildDependedUponBy(pkg, ab_pkg);
  11837. + return pkg;
  11838. +}
  11839. +
  11840. +/*
  11841. + * this will assume that we've already determined that
  11842. + * the abstract pkg doesn't exist, 'cause we should know these things...
  11843. + */
  11844. +static abstract_pkg_t * add_new_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name)
  11845. +{
  11846. + abstract_pkg_t * ab_pkg;
  11847. +
  11848. + ab_pkg = abstract_pkg_new();
  11849. + if (ab_pkg == NULL) { return NULL; }
  11850. +
  11851. + ab_pkg->name = strdup(pkg_name);
  11852. + hash_table_insert(hash, pkg_name, ab_pkg);
  11853. +
  11854. + return ab_pkg;
  11855. +}
  11856. +
  11857. +
  11858. +pkg_t *file_hash_get_file_owner(ipkg_conf_t *conf, const char *file_name)
  11859. +{
  11860. + hash_table_t *file_hash = &conf->file_hash;
  11861. +
  11862. + return hash_table_get(file_hash, file_name);
  11863. +}
  11864. +
  11865. +int file_hash_set_file_owner(ipkg_conf_t *conf, const char *file_name, pkg_t *owning_pkg)
  11866. +{
  11867. + hash_table_t *file_hash = &conf->file_hash;
  11868. + pkg_t *old_owning_pkg = hash_table_get(file_hash, file_name);
  11869. + int file_name_len = strlen(file_name);
  11870. +
  11871. + if (file_name[file_name_len -1] == '/')
  11872. + return 0;
  11873. +
  11874. + if (conf->offline_root) {
  11875. + int len = strlen(conf->offline_root);
  11876. + if (strncmp(file_name, conf->offline_root, len) == 0) {
  11877. + file_name += len;
  11878. + }
  11879. + }
  11880. +
  11881. + // ipkg_message(conf, IPKG_DEBUG2, "owning_pkg=%s filename=%s\n", owning_pkg->name, file_name);
  11882. + hash_table_insert(file_hash, file_name, owning_pkg);
  11883. + if (old_owning_pkg) {
  11884. + str_list_remove_elt(old_owning_pkg->installed_files, file_name);
  11885. + /* mark this package to have its filelist written */
  11886. + old_owning_pkg->state_flag |= SF_FILELIST_CHANGED;
  11887. + owning_pkg->state_flag |= SF_FILELIST_CHANGED;
  11888. + }
  11889. + return 0;
  11890. +}
  11891. +
  11892. +
  11893. diff -Nur busybox-1.17.2.orig/archival/libipkg/pkg_hash.h busybox-1.17.2/archival/libipkg/pkg_hash.h
  11894. --- busybox-1.17.2.orig/archival/libipkg/pkg_hash.h 1970-01-01 01:00:00.000000000 +0100
  11895. +++ busybox-1.17.2/archival/libipkg/pkg_hash.h 2010-12-01 22:25:23.000000000 +0100
  11896. @@ -0,0 +1,61 @@
  11897. +/* pkg_hash.h - the itsy package management system
  11898. +
  11899. + Steven M. Ayer
  11900. +
  11901. + Copyright (C) 2002 Compaq Computer Corporation
  11902. +
  11903. + This program is free software; you can redistribute it and/or
  11904. + modify it under the terms of the GNU General Public License as
  11905. + published by the Free Software Foundation; either version 2, or (at
  11906. + your option) any later version.
  11907. +
  11908. + This program is distributed in the hope that it will be useful, but
  11909. + WITHOUT ANY WARRANTY; without even the implied warranty of
  11910. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11911. + General Public License for more details.
  11912. +*/
  11913. +
  11914. +#ifndef PKG_HASH_H
  11915. +#define PKG_HASH_H
  11916. +
  11917. +#include "pkg.h"
  11918. +#include "pkg_vec.h"
  11919. +#include "hash_table.h"
  11920. +
  11921. +
  11922. +int pkg_hash_init(const char *name, hash_table_t *hash, int len);
  11923. +void pkg_hash_deinit(hash_table_t *hash);
  11924. +void pkg_hash_map(hash_table_t *hash, void (*f)(void *data, void *entry), void *data);
  11925. +
  11926. +void pkg_hash_dump(hash_table_t *hash, void *data);
  11927. +void pkg_hash_fetch_available(hash_table_t *hash, pkg_vec_t *available);
  11928. +
  11929. +int pkg_hash_add_from_file(ipkg_conf_t *conf, const char *file_name,
  11930. + pkg_src_t *src, pkg_dest_t *dest, int is_status_file);
  11931. +pkg_t *hash_insert_pkg(hash_table_t *hash, pkg_t *pkg, int set_status,ipkg_conf_t *conf);
  11932. +
  11933. +abstract_pkg_t * ensure_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name);
  11934. +abstract_pkg_t * abstract_pkg_fetch_by_name(hash_table_t * hash, const char * pkg_name);
  11935. +pkg_vec_t *pkg_hash_fetch_by_name(hash_table_t *hash, const char *pkg_name);
  11936. +void pkg_hash_fetch_all_installed(hash_table_t *hash, pkg_vec_t *installed);
  11937. +pkg_t * pkg_hash_fetch_by_name_version(hash_table_t *hash,
  11938. + const char *pkg_name,
  11939. + const char * version);
  11940. +abstract_pkg_vec_t *pkg_hash_fetch_all_installation_candidates(hash_table_t *hash, const char *name);
  11941. +pkg_t *pkg_hash_fetch_best_installation_candidate(ipkg_conf_t *conf, abstract_pkg_t *apkg,
  11942. + int (*constraint_fcn)(pkg_t *pkg, void *data), void *cdata, int quiet);
  11943. +pkg_t *pkg_hash_fetch_best_installation_candidate_by_name(ipkg_conf_t *conf, const char *name);
  11944. +pkg_t *pkg_hash_fetch_installed_by_name(hash_table_t *hash,
  11945. + const char *pkg_name);
  11946. +pkg_t *pkg_hash_fetch_installed_by_name_dest(hash_table_t *hash,
  11947. + const char *pkg_name,
  11948. + pkg_dest_t *dest);
  11949. +
  11950. +pkg_t *file_hash_get_file_owner(ipkg_conf_t *conf, const char *file_name);
  11951. +int file_hash_set_file_owner(ipkg_conf_t *conf, const char *file_name, pkg_t *pkg);
  11952. +
  11953. +/* XXX: shouldn't this go in pkg_vec.[ch]? */
  11954. +pkg_vec_t *pkg_vec_fetch_by_name(hash_table_t *hash, const char *pkg_name);
  11955. +
  11956. +#endif
  11957. +
  11958. diff -Nur busybox-1.17.2.orig/archival/libipkg/pkg_parse.c busybox-1.17.2/archival/libipkg/pkg_parse.c
  11959. --- busybox-1.17.2.orig/archival/libipkg/pkg_parse.c 1970-01-01 01:00:00.000000000 +0100
  11960. +++ busybox-1.17.2/archival/libipkg/pkg_parse.c 2010-12-01 22:25:23.000000000 +0100
  11961. @@ -0,0 +1,368 @@
  11962. +/* pkg_parse.c - the itsy package management system
  11963. +
  11964. + Steven M. Ayer
  11965. +
  11966. + Copyright (C) 2002 Compaq Computer Corporation
  11967. +
  11968. + This program is free software; you can redistribute it and/or
  11969. + modify it under the terms of the GNU General Public License as
  11970. + published by the Free Software Foundation; either version 2, or (at
  11971. + your option) any later version.
  11972. +
  11973. + This program is distributed in the hope that it will be useful, but
  11974. + WITHOUT ANY WARRANTY; without even the implied warranty of
  11975. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11976. + General Public License for more details.
  11977. +*/
  11978. +
  11979. +#include "ipkg.h"
  11980. +#include <errno.h>
  11981. +#include <ctype.h>
  11982. +
  11983. +#include "pkg.h"
  11984. +#include "ipkg_utils.h"
  11985. +#include "pkg_parse.h"
  11986. +
  11987. +int alterProvidesLine(char *raw, char *temp);
  11988. +
  11989. +int isGenericFieldType(char * type, char * line)
  11990. +{
  11991. + if(!strncmp(line, type, strlen(type)))
  11992. + return 1;
  11993. + return 0;
  11994. +}
  11995. +
  11996. +char * parseGenericFieldType(char * type, char * raw)
  11997. +{
  11998. + char * field_value = raw + (strlen(type) + 1);
  11999. + return trim_alloc(field_value);
  12000. +}
  12001. +
  12002. +void parseStatus(pkg_t *pkg, char * raw)
  12003. +{
  12004. + char sw_str[64], sf_str[64], ss_str[64];
  12005. +
  12006. + sscanf(raw, "Status: %s %s %s", sw_str, sf_str, ss_str);
  12007. + pkg->state_want = pkg_state_want_from_str(sw_str);
  12008. + pkg->state_flag = pkg_state_flag_from_str(sf_str);
  12009. + pkg->state_status = pkg_state_status_from_str(ss_str);
  12010. +}
  12011. +
  12012. +char ** parseDependsString(char * raw, int * depends_count)
  12013. +{
  12014. + char ** depends = NULL;
  12015. + int line_count = 0;
  12016. + char buff[2048], * dest;
  12017. +
  12018. + while(raw && *raw && !isspace(*raw)) {
  12019. + raw++;
  12020. + }
  12021. +
  12022. + if(line_is_blank(raw)){
  12023. + *depends_count = line_count;
  12024. + return NULL;
  12025. + }
  12026. + while(raw && *raw){
  12027. + depends = (char **)realloc(depends, sizeof(char *) * (line_count + 1));
  12028. +
  12029. + while(isspace(*raw)) raw++;
  12030. +
  12031. + dest = buff;
  12032. + while((*raw != ',') && *raw)
  12033. + *dest++ = *raw++;
  12034. +
  12035. + *dest = '\0';
  12036. + depends[line_count] = trim_alloc(buff);
  12037. + if(depends[line_count] ==NULL)
  12038. + return NULL;
  12039. + line_count++;
  12040. + if(*raw == ',')
  12041. + raw++;
  12042. + }
  12043. + *depends_count = line_count;
  12044. + return depends;
  12045. +}
  12046. +
  12047. +void parseConffiles(pkg_t * pkg, char * raw)
  12048. +{
  12049. + char file_name[1048], md5sum[1048]; /* please tell me there aren't any longer that 1k */
  12050. +
  12051. + if(!strncmp(raw, "Conffiles:", 10))
  12052. + raw += strlen("Conffiles:");
  12053. +
  12054. + while(*raw && (sscanf(raw, "%s%s", file_name, md5sum) == 2)){
  12055. + conffile_list_append(&pkg->conffiles, file_name, md5sum);
  12056. + /* fprintf(stderr, "%s %s ", file_name, md5sum);*/
  12057. + while (*raw && isspace(*raw)) {
  12058. + raw++;
  12059. + }
  12060. + raw += strlen(file_name);
  12061. + while (*raw && isspace(*raw)) {
  12062. + raw++;
  12063. + }
  12064. + raw += strlen(md5sum);
  12065. + }
  12066. +}
  12067. +
  12068. +int parseVersion(pkg_t *pkg, char *raw)
  12069. +{
  12070. + char *colon, *eepochcolon;
  12071. +#ifdef USE_DEBVERSION
  12072. + char *hyphen;
  12073. +#endif
  12074. + unsigned long epoch;
  12075. +
  12076. + if (!*raw) {
  12077. + fprintf(stderr, "%s: ERROR: version string is empty", __FUNCTION__);
  12078. + return EINVAL;
  12079. + }
  12080. +
  12081. + if (strncmp(raw, "Version:", 8) == 0) {
  12082. + raw += 8;
  12083. + }
  12084. + while (*raw && isspace(*raw)) {
  12085. + raw++;
  12086. + }
  12087. +
  12088. + colon= strchr(raw,':');
  12089. + if (colon) {
  12090. + epoch= strtoul(raw,&eepochcolon,10);
  12091. + if (colon != eepochcolon) {
  12092. + fprintf(stderr, "%s: ERROR: epoch in version is not number", __FUNCTION__);
  12093. + return EINVAL;
  12094. + }
  12095. + if (!*++colon) {
  12096. + fprintf(stderr, "%s: ERROR: nothing after colon in version number", __FUNCTION__);
  12097. + return EINVAL;
  12098. + }
  12099. + raw= colon;
  12100. + pkg->epoch= epoch;
  12101. + } else {
  12102. + pkg->epoch= 0;
  12103. + }
  12104. +
  12105. + pkg->revision = (char *)"";
  12106. + pkg->familiar_revision = (char *)"";
  12107. +
  12108. + pkg->version= malloc(strlen(raw)+1);
  12109. + if ( pkg->version == NULL ) {
  12110. + fprintf(stderr, "%s: out of memory \n", __FUNCTION__);
  12111. + return ENOMEM;
  12112. + }
  12113. + strcpy(pkg->version, raw);
  12114. +
  12115. +#ifdef USE_DEBVERSION
  12116. + hyphen= strrchr(pkg->version,'-');
  12117. +
  12118. + if (hyphen) {
  12119. + *hyphen++= 0;
  12120. + if (strncmp("fam", hyphen, 3) == 0) {
  12121. + pkg->familiar_revision=hyphen+3;
  12122. + hyphen= strrchr(pkg->version,'-');
  12123. + if (hyphen) {
  12124. + *hyphen++= 0;
  12125. + pkg->revision = hyphen;
  12126. + }
  12127. + } else {
  12128. + pkg->revision = hyphen;
  12129. + }
  12130. + }
  12131. +#endif
  12132. +
  12133. +/*
  12134. + fprintf(stderr,"Parsed version: %lu, %s, %s, %s\n",
  12135. + pkg->epoch,
  12136. + pkg->version,
  12137. + pkg->revision,
  12138. + pkg->familiar_revision);
  12139. +*/
  12140. +
  12141. + return 0;
  12142. +}
  12143. +
  12144. +
  12145. +/* This code is needed to insert in first position the keyword for the aligning bug */
  12146. +
  12147. +int alterProvidesLine(char *raw, char *temp)
  12148. +{
  12149. +
  12150. +
  12151. + if (!*raw) {
  12152. + fprintf(stderr, "%s: ERROR: Provides string is empty", __FUNCTION__);
  12153. + return -EINVAL;
  12154. + }
  12155. +
  12156. + if ( temp == NULL ) {
  12157. + fprintf(stderr, "%s: out of memory \n", __FUNCTION__);
  12158. + return -ENOMEM;
  12159. + }
  12160. +
  12161. + if (strncmp(raw, "Provides:", 9) == 0) {
  12162. + raw += 9;
  12163. + }
  12164. + while (*raw && isspace(*raw)) {
  12165. + raw++;
  12166. + }
  12167. +
  12168. + snprintf ( temp, 35, "Provides: ipkg_internal_use_only, "); /* First part of the line */
  12169. + while (*raw) {
  12170. + strncat( temp, raw++, 1);
  12171. + }
  12172. + return 0;
  12173. +
  12174. +}
  12175. +
  12176. +/* Some random thoughts from Carl:
  12177. +
  12178. + This function could be considerably simplified if we just kept
  12179. + an array of all the generic string-valued field names, and looped
  12180. + through those looking for a match. Also, these fields could perhaps
  12181. + be stored in the package as an array as well, (or, probably better,
  12182. + as an nv_pair_list_t).
  12183. +
  12184. + Fields which require special parsing or storage, (such as Depends:
  12185. + and Status:) could be handled as they are now.
  12186. +*/
  12187. +/* XXX: FEATURE: The Suggests: field needs to be changed from a string
  12188. + to a dependency list. And, since we already have
  12189. + Depends/Pre-Depends and need to add Conflicts, Recommends, and
  12190. + Enhances, perhaps we could generalize all of these and save some
  12191. + code duplication.
  12192. +*/
  12193. +int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest)
  12194. +{
  12195. + int reading_conffiles, reading_description;
  12196. + int pkg_false_provides=1;
  12197. + char ** lines;
  12198. + char * provide=NULL;
  12199. +
  12200. + pkg->src = src;
  12201. + pkg->dest = dest;
  12202. +
  12203. + reading_conffiles = reading_description = 0;
  12204. +
  12205. + for (lines = *raw; *lines; lines++) {
  12206. + /* fprintf(stderr, "PARSING %s\n", *lines);*/
  12207. + if(isGenericFieldType((char *)"Package:", *lines))
  12208. + pkg->name = parseGenericFieldType((char *)"Package", *lines);
  12209. + else if(isGenericFieldType((char *)"Architecture:", *lines))
  12210. + pkg->architecture = parseGenericFieldType((char *)"Architecture", *lines);
  12211. + else if(isGenericFieldType((char *)"Filename:", *lines))
  12212. + pkg->filename = parseGenericFieldType((char *)"Filename", *lines);
  12213. + else if(isGenericFieldType((char *)"Section:", *lines))
  12214. + pkg->section = parseGenericFieldType((char *)"Section", *lines);
  12215. + else if(isGenericFieldType((char *)"MD5sum:", *lines))
  12216. + pkg->md5sum = parseGenericFieldType((char *)"MD5sum", *lines);
  12217. + /* The old ipkg wrote out status files with the wrong case for MD5sum,
  12218. + let's parse it either way */
  12219. + else if(isGenericFieldType((char *)"MD5Sum:", *lines))
  12220. + pkg->md5sum = parseGenericFieldType((char *)"MD5Sum", *lines);
  12221. + else if(isGenericFieldType((char *)"Size:", *lines))
  12222. + pkg->size = parseGenericFieldType((char *)"Size", *lines);
  12223. + else if(isGenericFieldType((char *)"Source:", *lines))
  12224. + pkg->source = parseGenericFieldType((char *)"Source", *lines);
  12225. + else if(isGenericFieldType((char *)"Installed-Size:", *lines))
  12226. + pkg->installed_size = parseGenericFieldType((char *)"Installed-Size", *lines);
  12227. + else if(isGenericFieldType((char *)"Installed-Time:", *lines)) {
  12228. + char *time_str = parseGenericFieldType((char *)"Installed-Time", *lines);
  12229. + pkg->installed_time = strtoul(time_str, NULL, 0);
  12230. + } else if(isGenericFieldType((char *)"Priority:", *lines))
  12231. + pkg->priority = parseGenericFieldType((char *)"Priority", *lines);
  12232. + else if(isGenericFieldType((char *)"Essential:", *lines)) {
  12233. + char *essential_value;
  12234. + essential_value = parseGenericFieldType((char *)"Essential", *lines);
  12235. + if (strcmp(essential_value, "yes") == 0) {
  12236. + pkg->essential = 1;
  12237. + }
  12238. + free(essential_value);
  12239. + }
  12240. + else if(isGenericFieldType((char *)"Status", *lines))
  12241. + parseStatus(pkg, *lines);
  12242. + else if(isGenericFieldType((char *)"Version", *lines))
  12243. + parseVersion(pkg, *lines);
  12244. + else if(isGenericFieldType((char *)"Maintainer", *lines))
  12245. + pkg->maintainer = parseGenericFieldType((char *)"Maintainer", *lines);
  12246. + else if(isGenericFieldType((char *)"Conffiles", *lines)){
  12247. + parseConffiles(pkg, *lines);
  12248. + reading_conffiles = 1;
  12249. + }
  12250. + else if(isGenericFieldType((char *)"Description", *lines)) {
  12251. + pkg->description = parseGenericFieldType((char *)"Description", *lines);
  12252. + reading_conffiles = 0;
  12253. + reading_description = 1;
  12254. + }
  12255. +
  12256. + else if(isGenericFieldType((char *)"Provides", *lines)){
  12257. +/* Here we add the internal_use to align the off by one problem between provides_str and provides */
  12258. + provide = (char * ) malloc(strlen(*lines)+ 35 ); /* Preparing the space for the new ipkg_internal_use_only */
  12259. + if ( alterProvidesLine(*lines,provide) ){
  12260. + return EINVAL;
  12261. + }
  12262. + pkg->provides_str = parseDependsString( provide, &pkg->provides_count);
  12263. +/* Let's try to hack a bit here.
  12264. + The idea is that if a package has no Provides, we would add one generic, to permit the check of dependencies
  12265. + in alot of other places. We will remove it before writing down the status database */
  12266. + pkg_false_provides=0;
  12267. + free(provide);
  12268. + }
  12269. +
  12270. + else if(isGenericFieldType((char *)"Depends", *lines))
  12271. + pkg->depends_str = parseDependsString(*lines, &pkg->depends_count);
  12272. + else if(isGenericFieldType((char *)"Pre-Depends", *lines))
  12273. + pkg->pre_depends_str = parseDependsString(*lines, &pkg->pre_depends_count);
  12274. + else if(isGenericFieldType((char *)"Recommends", *lines))
  12275. + pkg->recommends_str = parseDependsString(*lines, &pkg->recommends_count);
  12276. + else if(isGenericFieldType((char *)"Suggests", *lines))
  12277. + pkg->suggests_str = parseDependsString(*lines, &pkg->suggests_count);
  12278. + /* Abhaya: support for conflicts */
  12279. + else if(isGenericFieldType((char *)"Conflicts", *lines))
  12280. + pkg->conflicts_str = parseDependsString(*lines, &pkg->conflicts_count);
  12281. + else if(isGenericFieldType((char *)"Replaces", *lines))
  12282. + pkg->replaces_str = parseDependsString(*lines, &pkg->replaces_count);
  12283. + else if(line_is_blank(*lines)) {
  12284. + lines++;
  12285. + break;
  12286. + }
  12287. + else if(**lines == ' '){
  12288. + if(reading_description) {
  12289. + /* we already know it's not blank, so the rest of description */
  12290. + pkg->description = realloc(pkg->description,
  12291. + strlen(pkg->description)
  12292. + + 1 + strlen(*lines) + 1);
  12293. + strcat(pkg->description, "\n");
  12294. + strcat(pkg->description, (*lines));
  12295. + }
  12296. + else if(reading_conffiles)
  12297. + parseConffiles(pkg, *lines);
  12298. + }
  12299. + }
  12300. + *raw = lines;
  12301. +/* If the ipk has not a Provides line, we insert our false line */
  12302. + if ( pkg_false_provides==1)
  12303. + pkg->provides_str = parseDependsString ((char *)"Provides: ipkg_internal_use_only ", &pkg->provides_count);
  12304. +
  12305. + if (pkg->name) {
  12306. + return 0;
  12307. + } else {
  12308. + return EINVAL;
  12309. + }
  12310. +}
  12311. +
  12312. +int pkg_valorize_other_field(pkg_t *pkg, char ***raw)
  12313. +{
  12314. + char ** lines;
  12315. +
  12316. + for (lines = *raw; *lines; lines++) {
  12317. + if(isGenericFieldType((char *)"Essential:", *lines)) {
  12318. + char *essential_value;
  12319. + essential_value = parseGenericFieldType((char *)"Essential", *lines);
  12320. + if (strcmp(essential_value, "yes") == 0) {
  12321. + pkg->essential = 1;
  12322. + }
  12323. + free(essential_value);
  12324. + }
  12325. + }
  12326. + *raw = lines;
  12327. +
  12328. + return 0;
  12329. +}
  12330. diff -Nur busybox-1.17.2.orig/archival/libipkg/pkg_parse.h busybox-1.17.2/archival/libipkg/pkg_parse.h
  12331. --- busybox-1.17.2.orig/archival/libipkg/pkg_parse.h 1970-01-01 01:00:00.000000000 +0100
  12332. +++ busybox-1.17.2/archival/libipkg/pkg_parse.h 2010-12-01 22:25:23.000000000 +0100
  12333. @@ -0,0 +1,31 @@
  12334. +/* pkg_parse.h - the itsy package management system
  12335. +
  12336. + Steven M. Ayer
  12337. +
  12338. + Copyright (C) 2002 Compaq Computer Corporation
  12339. +
  12340. + This program is free software; you can redistribute it and/or
  12341. + modify it under the terms of the GNU General Public License as
  12342. + published by the Free Software Foundation; either version 2, or (at
  12343. + your option) any later version.
  12344. +
  12345. + This program is distributed in the hope that it will be useful, but
  12346. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12347. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12348. + General Public License for more details.
  12349. +*/
  12350. +
  12351. +#ifndef PKG_PARSE_H
  12352. +#define PKG_PARSE_H
  12353. +
  12354. +int isGenericFieldType(char * type, char * line);
  12355. +char * parseGenericFieldType(char * type, char * raw);
  12356. +void parseStatus(pkg_t *pkg, char * raw);
  12357. +int parseVersion(pkg_t *pkg, char *raw);
  12358. +char ** parseDependsString(char * raw, int * depends_count);
  12359. +int parseVersion(pkg_t *pkg, char *raw);
  12360. +void parseConffiles(pkg_t * pkg, char * raw);
  12361. +int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest);
  12362. +int pkg_valorize_other_field(pkg_t *pkg, char ***raw);
  12363. +
  12364. +#endif
  12365. diff -Nur busybox-1.17.2.orig/archival/libipkg/pkg_src.c busybox-1.17.2/archival/libipkg/pkg_src.c
  12366. --- busybox-1.17.2.orig/archival/libipkg/pkg_src.c 1970-01-01 01:00:00.000000000 +0100
  12367. +++ busybox-1.17.2/archival/libipkg/pkg_src.c 2010-12-01 22:25:23.000000000 +0100
  12368. @@ -0,0 +1,43 @@
  12369. +/* pkg_src.c - the itsy package management system
  12370. +
  12371. + Carl D. Worth
  12372. +
  12373. + Copyright (C) 2001 University of Southern California
  12374. +
  12375. + This program is free software; you can redistribute it and/or
  12376. + modify it under the terms of the GNU General Public License as
  12377. + published by the Free Software Foundation; either version 2, or (at
  12378. + your option) any later version.
  12379. +
  12380. + This program is distributed in the hope that it will be useful, but
  12381. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12382. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12383. + General Public License for more details.
  12384. +*/
  12385. +
  12386. +#include "ipkg.h"
  12387. +
  12388. +#include "pkg_src.h"
  12389. +#include "str_util.h"
  12390. +
  12391. +int pkg_src_init(pkg_src_t *src, const char *name, const char *base_url, const char *extra_data, int gzip)
  12392. +{
  12393. + src->gzip = gzip;
  12394. + src->name = str_dup_safe (name);
  12395. + src->value = str_dup_safe (base_url);
  12396. + if (extra_data)
  12397. + src->extra_data = str_dup_safe (extra_data);
  12398. + else
  12399. + src->extra_data = NULL;
  12400. + return 0;
  12401. +}
  12402. +
  12403. +void pkg_src_deinit(pkg_src_t *src)
  12404. +{
  12405. + free (src->name);
  12406. + free (src->value);
  12407. + if (src->extra_data)
  12408. + free (src->extra_data);
  12409. +}
  12410. +
  12411. +
  12412. diff -Nur busybox-1.17.2.orig/archival/libipkg/pkg_src.h busybox-1.17.2/archival/libipkg/pkg_src.h
  12413. --- busybox-1.17.2.orig/archival/libipkg/pkg_src.h 1970-01-01 01:00:00.000000000 +0100
  12414. +++ busybox-1.17.2/archival/libipkg/pkg_src.h 2010-12-01 22:25:23.000000000 +0100
  12415. @@ -0,0 +1,34 @@
  12416. +/* pkg_src.h - the itsy package management system
  12417. +
  12418. + Carl D. Worth
  12419. +
  12420. + Copyright (C) 2001 University of Southern California
  12421. +
  12422. + This program is free software; you can redistribute it and/or
  12423. + modify it under the terms of the GNU General Public License as
  12424. + published by the Free Software Foundation; either version 2, or (at
  12425. + your option) any later version.
  12426. +
  12427. + This program is distributed in the hope that it will be useful, but
  12428. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12429. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12430. + General Public License for more details.
  12431. +*/
  12432. +
  12433. +#ifndef PKG_SRC_H
  12434. +#define PKG_SRC_H
  12435. +
  12436. +#include "nv_pair.h"
  12437. +
  12438. +typedef struct
  12439. +{
  12440. + char *name;
  12441. + char *value;
  12442. + char *extra_data;
  12443. + int gzip;
  12444. +} pkg_src_t;
  12445. +
  12446. +int pkg_src_init(pkg_src_t *src, const char *name, const char *base_url, const char *extra_data, int gzip);
  12447. +void pkg_src_deinit(pkg_src_t *src);
  12448. +
  12449. +#endif
  12450. diff -Nur busybox-1.17.2.orig/archival/libipkg/pkg_src_list.c busybox-1.17.2/archival/libipkg/pkg_src_list.c
  12451. --- busybox-1.17.2.orig/archival/libipkg/pkg_src_list.c 1970-01-01 01:00:00.000000000 +0100
  12452. +++ busybox-1.17.2/archival/libipkg/pkg_src_list.c 2010-12-01 22:25:23.000000000 +0100
  12453. @@ -0,0 +1,75 @@
  12454. +/* pkg_src_list.c - the itsy package management system
  12455. +
  12456. + Carl D. Worth
  12457. +
  12458. + Copyright (C) 2001 University of Southern California
  12459. +
  12460. + This program is free software; you can redistribute it and/or
  12461. + modify it under the terms of the GNU General Public License as
  12462. + published by the Free Software Foundation; either version 2, or (at
  12463. + your option) any later version.
  12464. +
  12465. + This program is distributed in the hope that it will be useful, but
  12466. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12467. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12468. + General Public License for more details.
  12469. +*/
  12470. +
  12471. +#include "ipkg.h"
  12472. +
  12473. +#include "pkg_src_list.h"
  12474. +#include "void_list.h"
  12475. +
  12476. +int pkg_src_list_init(pkg_src_list_t *list)
  12477. +{
  12478. + return void_list_init((void_list_t *) list);
  12479. +}
  12480. +
  12481. +void pkg_src_list_deinit(pkg_src_list_t *list)
  12482. +{
  12483. + pkg_src_list_elt_t *iter;
  12484. + pkg_src_t *pkg_src;
  12485. +
  12486. + for (iter = list->head; iter; iter = iter->next) {
  12487. + pkg_src = iter->data;
  12488. + pkg_src_deinit(pkg_src);
  12489. +
  12490. + /* malloced in pkg_src_list_append */
  12491. + free(pkg_src);
  12492. + iter->data = NULL;
  12493. + }
  12494. + void_list_deinit((void_list_t *) list);
  12495. +}
  12496. +
  12497. +pkg_src_t *pkg_src_list_append(pkg_src_list_t *list,
  12498. + const char *name, const char *base_url, const char *extra_data,
  12499. + int gzip)
  12500. +{
  12501. + int err;
  12502. +
  12503. + /* freed in pkg_src_list_deinit */
  12504. + pkg_src_t *pkg_src = malloc(sizeof(pkg_src_t));
  12505. +
  12506. + if (pkg_src == NULL) {
  12507. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  12508. + return NULL;
  12509. + }
  12510. + pkg_src_init(pkg_src, name, base_url, extra_data, gzip);
  12511. +
  12512. + err = void_list_append((void_list_t *) list, pkg_src);
  12513. + if (err) {
  12514. + return NULL;
  12515. + }
  12516. +
  12517. + return pkg_src;
  12518. +}
  12519. +
  12520. +int pkg_src_list_push(pkg_src_list_t *list, pkg_src_t *data)
  12521. +{
  12522. + return void_list_push((void_list_t *) list, data);
  12523. +}
  12524. +
  12525. +pkg_src_list_elt_t *pkg_src_list_pop(pkg_src_list_t *list)
  12526. +{
  12527. + return (pkg_src_list_elt_t *) void_list_pop((void_list_t *) list);
  12528. +}
  12529. diff -Nur busybox-1.17.2.orig/archival/libipkg/pkg_src_list.h busybox-1.17.2/archival/libipkg/pkg_src_list.h
  12530. --- busybox-1.17.2.orig/archival/libipkg/pkg_src_list.h 1970-01-01 01:00:00.000000000 +0100
  12531. +++ busybox-1.17.2/archival/libipkg/pkg_src_list.h 2010-12-01 22:25:23.000000000 +0100
  12532. @@ -0,0 +1,57 @@
  12533. +/* pkg_src_list.h - the itsy package management system
  12534. +
  12535. + Carl D. Worth
  12536. +
  12537. + Copyright (C) 2001 University of Southern California
  12538. +
  12539. + This program is free software; you can redistribute it and/or
  12540. + modify it under the terms of the GNU General Public License as
  12541. + published by the Free Software Foundation; either version 2, or (at
  12542. + your option) any later version.
  12543. +
  12544. + This program is distributed in the hope that it will be useful, but
  12545. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12546. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12547. + General Public License for more details.
  12548. +*/
  12549. +
  12550. +#ifndef PKG_SRC_LIST_H
  12551. +#define PKG_SRC_LIST_H
  12552. +
  12553. +#include "pkg_src.h"
  12554. +
  12555. +typedef struct pkg_src_list_elt pkg_src_list_elt_t;
  12556. +struct pkg_src_list_elt
  12557. +{
  12558. + pkg_src_list_elt_t *next;
  12559. + pkg_src_t *data;
  12560. +};
  12561. +
  12562. +typedef struct pkg_src_list pkg_src_list_t;
  12563. +struct pkg_src_list
  12564. +{
  12565. + pkg_src_list_elt_t pre_head;
  12566. + pkg_src_list_elt_t *head;
  12567. + pkg_src_list_elt_t *tail;
  12568. +};
  12569. +
  12570. +static inline int pkg_src_list_empty(pkg_src_list_t *list)
  12571. +{
  12572. + if (list->head == NULL)
  12573. + return 1;
  12574. + else
  12575. + return 0;
  12576. +}
  12577. +
  12578. +int pkg_src_list_elt_init(pkg_src_list_elt_t *elt, nv_pair_t *data);
  12579. +void pkg_src_list_elt_deinit(pkg_src_list_elt_t *elt);
  12580. +
  12581. +int pkg_src_list_init(pkg_src_list_t *list);
  12582. +void pkg_src_list_deinit(pkg_src_list_t *list);
  12583. +
  12584. +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);
  12585. +int pkg_src_list_push(pkg_src_list_t *list, pkg_src_t *data);
  12586. +pkg_src_list_elt_t *pkg_src_list_pop(pkg_src_list_t *list);
  12587. +
  12588. +#endif
  12589. +
  12590. diff -Nur busybox-1.17.2.orig/archival/libipkg/pkg_vec.c busybox-1.17.2/archival/libipkg/pkg_vec.c
  12591. --- busybox-1.17.2.orig/archival/libipkg/pkg_vec.c 1970-01-01 01:00:00.000000000 +0100
  12592. +++ busybox-1.17.2/archival/libipkg/pkg_vec.c 2010-12-01 22:25:23.000000000 +0100
  12593. @@ -0,0 +1,231 @@
  12594. +/* pkg_vec.c - the itsy package management system
  12595. +
  12596. + Steven M. Ayer
  12597. +
  12598. + Copyright (C) 2002 Compaq Computer Corporation
  12599. +
  12600. + This program is free software; you can redistribute it and/or
  12601. + modify it under the terms of the GNU General Public License as
  12602. + published by the Free Software Foundation; either version 2, or (at
  12603. + your option) any later version.
  12604. +
  12605. + This program is distributed in the hope that it will be useful, but
  12606. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12607. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12608. + General Public License for more details.
  12609. +*/
  12610. +
  12611. +#include <stdlib.h>
  12612. +#include <fnmatch.h>
  12613. +#include "libbb.h"
  12614. +#include "xregex.h"
  12615. +#include "ipkg.h"
  12616. +#include "pkg.h"
  12617. +
  12618. +pkg_vec_t * pkg_vec_alloc(void)
  12619. +{
  12620. + pkg_vec_t * vec = (pkg_vec_t *)malloc(sizeof(pkg_vec_t));
  12621. + if (!vec) {
  12622. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  12623. + return NULL;
  12624. + }
  12625. + vec->pkgs = NULL;
  12626. + vec->len = 0;
  12627. +
  12628. + return vec;
  12629. +}
  12630. +
  12631. +void pkg_vec_free(pkg_vec_t *vec)
  12632. +{
  12633. + free(vec->pkgs);
  12634. + free(vec);
  12635. +}
  12636. +
  12637. +/*
  12638. + * assumption: all names in a vector are identical
  12639. + * assumption: all version strings are trimmed,
  12640. + * so identical versions have identical version strings,
  12641. + * implying identical packages; let's marry these
  12642. + */
  12643. +pkg_t *pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status,ipkg_conf_t *conf)
  12644. +{
  12645. + int i;
  12646. + int found = 0;
  12647. +
  12648. + /* look for a duplicate pkg by name, version, and architecture */
  12649. + for (i = 0; i < vec->len; i++){
  12650. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Found pkg=%s version=%s arch=%s cmp=%s version=%s arch=%s \n",
  12651. + __FUNCTION__, pkg->name, pkg->version, pkg->architecture,
  12652. + vec->pkgs[i]->name, vec->pkgs[i]->version,vec->pkgs[i]->architecture );
  12653. + if ((strcmp(pkg->name, vec->pkgs[i]->name) == 0)
  12654. + && (pkg_compare_versions(pkg, vec->pkgs[i]) == 0)
  12655. + && (strcmp(pkg->architecture, vec->pkgs[i]->architecture) == 0)) {
  12656. + found = 1;
  12657. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Found duplicate for pkg=%s version=%s arch=%s\n",
  12658. + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
  12659. + break;
  12660. + }
  12661. + }
  12662. +
  12663. + /* we didn't find one, add it */
  12664. + if (!found){
  12665. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Adding new pkg=%s version=%s arch=%s\n",
  12666. + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
  12667. +
  12668. + vec->pkgs = (pkg_t **)realloc(vec->pkgs, (vec->len + 1) * sizeof(pkg_t *));
  12669. + vec->pkgs[vec->len] = pkg;
  12670. + vec->len++;
  12671. + return pkg;
  12672. + }
  12673. + /* update the one that we have */
  12674. + else {
  12675. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. calling pkg_merge for pkg=%s version=%s arch=%s",
  12676. + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
  12677. + if (set_status) {
  12678. + /* this is from the status file, so need to merge with existing database */
  12679. + ipkg_message(conf, IPKG_DEBUG2, " with set_status\n");
  12680. + pkg_merge(vec->pkgs[i], pkg, set_status);
  12681. + /* XXX: CLEANUP: It's not so polite to free something here
  12682. + that was passed in from above. */
  12683. + pkg_deinit(pkg);
  12684. + free(pkg);
  12685. + } else {
  12686. + ipkg_message(conf, IPKG_DEBUG2, " WITHOUT set_status\n");
  12687. + /* just overwrite the old one */
  12688. + pkg_deinit(vec->pkgs[i]);
  12689. + free(vec->pkgs[i]);
  12690. + vec->pkgs[i] = pkg;
  12691. + }
  12692. + return vec->pkgs[i];
  12693. + }
  12694. +}
  12695. +
  12696. +void pkg_vec_insert(pkg_vec_t *vec, const pkg_t *pkg)
  12697. +{
  12698. + int i;
  12699. + int found = 0;
  12700. +
  12701. + /* look for a duplicate pkg by name, version, and architecture */
  12702. + for (i = 0; i < vec->len; i++)
  12703. + if ((strcmp(pkg->name, vec->pkgs[i]->name) == 0)
  12704. + && (pkg_compare_versions(pkg, vec->pkgs[i]) == 0)
  12705. + && (strcmp(pkg->architecture, vec->pkgs[i]->name) == 0)) {
  12706. + found = 1;
  12707. + break;
  12708. + }
  12709. +
  12710. + /* we didn't find one, add it */
  12711. + if(!found){
  12712. + vec->pkgs = (pkg_t **)realloc(vec->pkgs, (vec->len + 1) * sizeof(pkg_t *));
  12713. + *(const pkg_t **)&vec->pkgs[vec->len] = pkg;
  12714. + vec->len++;
  12715. + }
  12716. +}
  12717. +
  12718. +int pkg_vec_contains(pkg_vec_t *vec, pkg_t *apkg)
  12719. +{
  12720. + int i;
  12721. + for (i = 0; i < vec->len; i++)
  12722. + if (vec->pkgs[i] == apkg)
  12723. + return 1;
  12724. + return 0;
  12725. +}
  12726. +
  12727. +typedef int (*compare_fcn_t)(const void *, const void *);
  12728. +void pkg_vec_sort(pkg_vec_t *vec, int (*compar)(pkg_t *, pkg_t *))
  12729. +{
  12730. + qsort(vec->pkgs, vec->len, sizeof(pkg_t *), (compare_fcn_t)compar);
  12731. +}
  12732. +
  12733. +int pkg_vec_clear_marks(pkg_vec_t *vec)
  12734. +{
  12735. + int npkgs = vec->len;
  12736. + int i;
  12737. + for (i = 0; i < npkgs; i++) {
  12738. + pkg_t *pkg = vec->pkgs[i];
  12739. + pkg->state_flag &= ~SF_MARKED;
  12740. + }
  12741. + return 0;
  12742. +}
  12743. +
  12744. +int pkg_vec_mark_if_matches(pkg_vec_t *vec, const char *pattern)
  12745. +{
  12746. + int matching_count = 0;
  12747. + pkg_t **pkgs = vec->pkgs;
  12748. + int npkgs = vec->len;
  12749. + int i;
  12750. + for (i = 0; i < npkgs; i++) {
  12751. + pkg_t *pkg = pkgs[i];
  12752. + if (fnmatch(pattern, pkg->name, 0)==0) {
  12753. + pkg->state_flag |= SF_MARKED;
  12754. + matching_count++;
  12755. + }
  12756. + }
  12757. + return matching_count;
  12758. +}
  12759. +
  12760. +
  12761. +abstract_pkg_vec_t * abstract_pkg_vec_alloc(void)
  12762. +{
  12763. + abstract_pkg_vec_t * vec ;
  12764. + vec = (abstract_pkg_vec_t *)malloc(sizeof(abstract_pkg_vec_t));
  12765. + if (!vec) {
  12766. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  12767. + return NULL;
  12768. + }
  12769. + vec->pkgs = NULL;
  12770. + vec->len = 0;
  12771. +
  12772. + return vec;
  12773. +}
  12774. +
  12775. +void abstract_pkg_vec_free(abstract_pkg_vec_t *vec)
  12776. +{
  12777. + free(vec->pkgs);
  12778. + free(vec);
  12779. +}
  12780. +
  12781. +/*
  12782. + * assumption: all names in a vector are unique
  12783. + */
  12784. +void abstract_pkg_vec_insert(abstract_pkg_vec_t *vec, abstract_pkg_t *pkg)
  12785. +{
  12786. + int i;
  12787. +
  12788. + /* look for a duplicate pkg by name */
  12789. + for(i = 0; i < vec->len; i++)
  12790. + if (strcmp(pkg->name, vec->pkgs[i]->name) == 0)
  12791. + break;
  12792. +
  12793. + /* we didn't find one, add it */
  12794. + if(i == vec->len){
  12795. + vec->pkgs =
  12796. + (abstract_pkg_t **)
  12797. + realloc(vec->pkgs, (vec->len + 1) * sizeof(abstract_pkg_t *));
  12798. + vec->pkgs[vec->len] = pkg;
  12799. + vec->len++;
  12800. + }
  12801. +}
  12802. +
  12803. +abstract_pkg_t * abstract_pkg_vec_get(abstract_pkg_vec_t *vec, int i)
  12804. +{
  12805. + if (vec->len > i)
  12806. + return vec->pkgs[i];
  12807. + else
  12808. + return NULL;
  12809. +}
  12810. +
  12811. +int abstract_pkg_vec_contains(abstract_pkg_vec_t *vec, abstract_pkg_t *apkg)
  12812. +{
  12813. + int i;
  12814. + for (i = 0; i < vec->len; i++)
  12815. + if (vec->pkgs[i] == apkg)
  12816. + return 1;
  12817. + return 0;
  12818. +}
  12819. +
  12820. +void abstract_pkg_vec_sort(pkg_vec_t *vec, int (*compar)(abstract_pkg_t *, abstract_pkg_t *))
  12821. +{
  12822. + qsort(vec->pkgs, vec->len, sizeof(pkg_t *), (compare_fcn_t)compar);
  12823. +}
  12824. +
  12825. diff -Nur busybox-1.17.2.orig/archival/libipkg/pkg_vec.h busybox-1.17.2/archival/libipkg/pkg_vec.h
  12826. --- busybox-1.17.2.orig/archival/libipkg/pkg_vec.h 1970-01-01 01:00:00.000000000 +0100
  12827. +++ busybox-1.17.2/archival/libipkg/pkg_vec.h 2010-12-01 22:25:23.000000000 +0100
  12828. @@ -0,0 +1,62 @@
  12829. +/* pkg_vec.h - the itsy package management system
  12830. +
  12831. + Steven M. Ayer
  12832. +
  12833. + Copyright (C) 2002 Compaq Computer Corporation
  12834. +
  12835. + This program is free software; you can redistribute it and/or
  12836. + modify it under the terms of the GNU General Public License as
  12837. + published by the Free Software Foundation; either version 2, or (at
  12838. + your option) any later version.
  12839. +
  12840. + This program is distributed in the hope that it will be useful, but
  12841. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12842. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12843. + General Public License for more details.
  12844. +*/
  12845. +
  12846. +#ifndef PKG_VEC_H
  12847. +#define PKG_VEC_H
  12848. +
  12849. +typedef struct pkg pkg_t;
  12850. +typedef struct abstract_pkg abstract_pkg_t;
  12851. +
  12852. +struct pkg_vec
  12853. +{
  12854. + pkg_t **pkgs;
  12855. + int len;
  12856. +};
  12857. +typedef struct pkg_vec pkg_vec_t;
  12858. +
  12859. +struct abstract_pkg_vec
  12860. +{
  12861. + abstract_pkg_t **pkgs;
  12862. + int len;
  12863. +};
  12864. +typedef struct abstract_pkg_vec abstract_pkg_vec_t;
  12865. +
  12866. +
  12867. +pkg_vec_t * pkg_vec_alloc(void);
  12868. +void pkg_vec_free(pkg_vec_t *vec);
  12869. +void marry_two_packages(pkg_t * newpkg, pkg_t * oldpkg);
  12870. +
  12871. +void pkg_vec_add(pkg_vec_t *vec, pkg_t *pkg);
  12872. +/* pkg_vec_insert_merge: might munge pkg.
  12873. +* returns the pkg that is in the pkg graph */
  12874. +pkg_t *pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status, ipkg_conf_t *conf);
  12875. +/* this one never munges pkg */
  12876. +void pkg_vec_insert(pkg_vec_t *vec, const pkg_t *pkg);
  12877. +int pkg_vec_contains(pkg_vec_t *vec, pkg_t *apkg);
  12878. +void pkg_vec_sort(pkg_vec_t *vec, int (*compar)(pkg_t *, pkg_t *));
  12879. +
  12880. +int pkg_vec_clear_marks(pkg_vec_t *vec);
  12881. +int pkg_vec_mark_if_matches(pkg_vec_t *vec, const char *pattern);
  12882. +
  12883. +abstract_pkg_vec_t * abstract_pkg_vec_alloc(void);
  12884. +void abstract_pkg_vec_free(abstract_pkg_vec_t *vec);
  12885. +void abstract_pkg_vec_insert(abstract_pkg_vec_t *vec, abstract_pkg_t *pkg);
  12886. +abstract_pkg_t * abstract_pkg_vec_get(abstract_pkg_vec_t *vec, int i);
  12887. +int abstract_pkg_vec_contains(abstract_pkg_vec_t *vec, abstract_pkg_t *apkg);
  12888. +void abstract_pkg_vec_sort(pkg_vec_t *vec, int (*compar)(abstract_pkg_t *, abstract_pkg_t *));
  12889. +#endif
  12890. +
  12891. diff -Nur busybox-1.17.2.orig/archival/libipkg/sprintf_alloc.h busybox-1.17.2/archival/libipkg/sprintf_alloc.h
  12892. --- busybox-1.17.2.orig/archival/libipkg/sprintf_alloc.h 1970-01-01 01:00:00.000000000 +0100
  12893. +++ busybox-1.17.2/archival/libipkg/sprintf_alloc.h 2010-12-01 22:25:23.000000000 +0100
  12894. @@ -0,0 +1,25 @@
  12895. +/* sprintf_alloca.c -- like sprintf with memory allocation
  12896. +
  12897. + Carl D. Worth
  12898. +
  12899. + Copyright (C) 2001 University of Southern California
  12900. +
  12901. + This program is free software; you can redistribute it and/or modify
  12902. + it under the terms of the GNU General Public License as published by
  12903. + the Free Software Foundation; either version 2, or (at your option)
  12904. + any later version.
  12905. +
  12906. + This program is distributed in the hope that it will be useful,
  12907. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  12908. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12909. + GNU General Public License for more details.
  12910. +*/
  12911. +
  12912. +#ifndef SPRINTF_ALLOC_H
  12913. +#define SPRINTF_ALLOC_H
  12914. +
  12915. +#include "libbb.h"
  12916. +
  12917. +#define sprintf_alloc(str, fmt, args...) *str = xasprintf(fmt, ## args)
  12918. +
  12919. +#endif
  12920. diff -Nur busybox-1.17.2.orig/archival/libipkg/str_list.c busybox-1.17.2/archival/libipkg/str_list.c
  12921. --- busybox-1.17.2.orig/archival/libipkg/str_list.c 1970-01-01 01:00:00.000000000 +0100
  12922. +++ busybox-1.17.2/archival/libipkg/str_list.c 2010-12-01 22:25:23.000000000 +0100
  12923. @@ -0,0 +1,76 @@
  12924. +/* str_list.c - the itsy package management system
  12925. +
  12926. + Carl D. Worth
  12927. +
  12928. + Copyright (C) 2001 University of Southern California
  12929. +
  12930. + This program is free software; you can redistribute it and/or
  12931. + modify it under the terms of the GNU General Public License as
  12932. + published by the Free Software Foundation; either version 2, or (at
  12933. + your option) any later version.
  12934. +
  12935. + This program is distributed in the hope that it will be useful, but
  12936. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12937. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12938. + General Public License for more details.
  12939. +*/
  12940. +
  12941. +#include "ipkg.h"
  12942. +
  12943. +#include "str_list.h"
  12944. +
  12945. +int str_list_elt_init(str_list_elt_t *elt, char *data)
  12946. +{
  12947. + return void_list_elt_init((void_list_elt_t *) elt, data);
  12948. +}
  12949. +
  12950. +void str_list_elt_deinit(str_list_elt_t *elt)
  12951. +{
  12952. + void_list_elt_deinit((void_list_elt_t *) elt);
  12953. +}
  12954. +
  12955. +str_list_t *str_list_alloc(void)
  12956. +{
  12957. + str_list_t *list = (str_list_t *)malloc(sizeof(str_list_t));
  12958. + if (list)
  12959. + str_list_init(list);
  12960. + return list;
  12961. +}
  12962. +
  12963. +int str_list_init(str_list_t *list)
  12964. +{
  12965. + return void_list_init((void_list_t *) list);
  12966. +}
  12967. +
  12968. +void str_list_deinit(str_list_t *list)
  12969. +{
  12970. + void_list_deinit((void_list_t *) list);
  12971. +}
  12972. +
  12973. +int str_list_append(str_list_t *list, char *data)
  12974. +{
  12975. + return void_list_append((void_list_t *) list, data);
  12976. +}
  12977. +
  12978. +int str_list_push(str_list_t *list, char *data)
  12979. +{
  12980. + return void_list_push((void_list_t *) list, data);
  12981. +}
  12982. +
  12983. +str_list_elt_t *str_list_pop(str_list_t *list)
  12984. +{
  12985. + return (str_list_elt_t *) void_list_pop((void_list_t *) list);
  12986. +}
  12987. +
  12988. +str_list_elt_t *str_list_remove(str_list_t *list, str_list_elt_t **iter)
  12989. +{
  12990. + return (str_list_elt_t *) void_list_remove((void_list_t *) list,
  12991. + (void_list_elt_t **) iter);
  12992. +}
  12993. +
  12994. +char *str_list_remove_elt(str_list_t *list, const char *target_str)
  12995. +{
  12996. + return (char *)void_list_remove_elt((void_list_t *) list,
  12997. + (void *)target_str,
  12998. + (void_list_cmp_t)strcmp);
  12999. +}
  13000. diff -Nur busybox-1.17.2.orig/archival/libipkg/str_list.h busybox-1.17.2/archival/libipkg/str_list.h
  13001. --- busybox-1.17.2.orig/archival/libipkg/str_list.h 1970-01-01 01:00:00.000000000 +0100
  13002. +++ busybox-1.17.2/archival/libipkg/str_list.h 2010-12-01 22:25:23.000000000 +0100
  13003. @@ -0,0 +1,51 @@
  13004. +/* str_list.h - the itsy package management system
  13005. +
  13006. + Carl D. Worth
  13007. +
  13008. + Copyright (C) 2001 University of Southern California
  13009. +
  13010. + This program is free software; you can redistribute it and/or
  13011. + modify it under the terms of the GNU General Public License as
  13012. + published by the Free Software Foundation; either version 2, or (at
  13013. + your option) any later version.
  13014. +
  13015. + This program is distributed in the hope that it will be useful, but
  13016. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13017. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13018. + General Public License for more details.
  13019. +*/
  13020. +
  13021. +#ifndef STR_LIST_H
  13022. +#define STR_LIST_H
  13023. +
  13024. +#include "void_list.h"
  13025. +
  13026. +typedef struct str_list_elt str_list_elt_t;
  13027. +struct str_list_elt
  13028. +{
  13029. + str_list_elt_t *next;
  13030. + char *data;
  13031. +};
  13032. +
  13033. +typedef struct xstr_list str_list_t;
  13034. +struct xstr_list
  13035. +{
  13036. + str_list_elt_t pre_head;
  13037. + str_list_elt_t *head;
  13038. + str_list_elt_t *tail;
  13039. +};
  13040. +
  13041. +int str_list_elt_init(str_list_elt_t *elt, char *data);
  13042. +void str_list_elt_deinit(str_list_elt_t *elt);
  13043. +
  13044. +str_list_t *str_list_alloc(void);
  13045. +int str_list_init(str_list_t *list);
  13046. +void str_list_deinit(str_list_t *list);
  13047. +
  13048. +int str_list_append(str_list_t *list, char *data);
  13049. +int str_list_push(str_list_t *list, char *data);
  13050. +str_list_elt_t *str_list_pop(str_list_t *list);
  13051. +str_list_elt_t *str_list_remove(str_list_t *list, str_list_elt_t **iter);
  13052. +char *str_list_remove_elt(str_list_t *list, const char *target_str);
  13053. +
  13054. +#endif
  13055. diff -Nur busybox-1.17.2.orig/archival/libipkg/str_util.c busybox-1.17.2/archival/libipkg/str_util.c
  13056. --- busybox-1.17.2.orig/archival/libipkg/str_util.c 1970-01-01 01:00:00.000000000 +0100
  13057. +++ busybox-1.17.2/archival/libipkg/str_util.c 2010-12-01 22:25:23.000000000 +0100
  13058. @@ -0,0 +1,69 @@
  13059. +/* str_utils.c - the itsy package management system
  13060. +
  13061. + Carl D. Worth
  13062. +
  13063. + Copyright (C) 2001 University of Southern California
  13064. +
  13065. + This program is free software; you can redistribute it and/or
  13066. + modify it under the terms of the GNU General Public License as
  13067. + published by the Free Software Foundation; either version 2, or (at
  13068. + your option) any later version.
  13069. +
  13070. + This program is distributed in the hope that it will be useful, but
  13071. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13072. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13073. + General Public License for more details.
  13074. +*/
  13075. +
  13076. +#include "ipkg.h"
  13077. +
  13078. +int str_starts_with(const char *str, const char *prefix);
  13079. +int str_ends_with(const char *str, const char *suffix);
  13080. +int str_chomp(char *str);
  13081. +int str_toupper(char *str);
  13082. +char *str_dup_safe(const char *str);
  13083. +
  13084. +int str_starts_with(const char *str, const char *prefix)
  13085. +{
  13086. + return (strncmp(str, prefix, strlen(prefix)) == 0);
  13087. +}
  13088. +
  13089. +int str_ends_with(const char *str, const char *suffix)
  13090. +{
  13091. + int suffix_len;
  13092. + int str_len;
  13093. +
  13094. + str_len = strlen(str);
  13095. + suffix_len = strlen(suffix);
  13096. +
  13097. + if (str_len < suffix_len) {
  13098. + return 0;
  13099. + }
  13100. +
  13101. + return (strcmp(str + str_len - suffix_len, suffix) == 0);
  13102. +}
  13103. +
  13104. +int str_chomp(char *str)
  13105. +{
  13106. + if (str[strlen(str) - 1] == '\n') {
  13107. + str[strlen(str) - 1] = '\0';
  13108. + return 1;
  13109. + }
  13110. + return 0;
  13111. +}
  13112. +
  13113. +int str_toupper(char *str)
  13114. +{
  13115. + while (*str) {
  13116. + *str = toupper(*str);
  13117. + str++;
  13118. + }
  13119. +
  13120. + return 0;
  13121. +}
  13122. +
  13123. +char *str_dup_safe(const char *str)
  13124. +{
  13125. + return str ? strdup(str) : NULL;
  13126. +}
  13127. +
  13128. diff -Nur busybox-1.17.2.orig/archival/libipkg/str_util.h busybox-1.17.2/archival/libipkg/str_util.h
  13129. --- busybox-1.17.2.orig/archival/libipkg/str_util.h 1970-01-01 01:00:00.000000000 +0100
  13130. +++ busybox-1.17.2/archival/libipkg/str_util.h 2010-12-01 22:25:23.000000000 +0100
  13131. @@ -0,0 +1,27 @@
  13132. +/* str_utils.h - the itsy package management system
  13133. +
  13134. + Carl D. Worth
  13135. +
  13136. + Copyright (C) 2001 University of Southern California
  13137. +
  13138. + This program is free software; you can redistribute it and/or
  13139. + modify it under the terms of the GNU General Public License as
  13140. + published by the Free Software Foundation; either version 2, or (at
  13141. + your option) any later version.
  13142. +
  13143. + This program is distributed in the hope that it will be useful, but
  13144. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13145. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13146. + General Public License for more details.
  13147. +*/
  13148. +
  13149. +#ifndef STR_UTILS_H
  13150. +#define STR_UTILS_H
  13151. +
  13152. +int str_starts_with(const char *str, const char *prefix);
  13153. +int str_ends_with(const char *str, const char *suffix);
  13154. +int str_chomp(char *str);
  13155. +int str_toupper(char *str);
  13156. +char *str_dup_safe(const char *str);
  13157. +
  13158. +#endif
  13159. diff -Nur busybox-1.17.2.orig/archival/libipkg/user.c busybox-1.17.2/archival/libipkg/user.c
  13160. --- busybox-1.17.2.orig/archival/libipkg/user.c 1970-01-01 01:00:00.000000000 +0100
  13161. +++ busybox-1.17.2/archival/libipkg/user.c 2010-12-01 22:25:23.000000000 +0100
  13162. @@ -0,0 +1,49 @@
  13163. +/* user.c - the itsy package management system
  13164. +
  13165. + Jamey Hicks
  13166. +
  13167. + Copyright (C) 2002 Hewlett Packard Company
  13168. + Copyright (C) 2001 University of Southern California
  13169. +
  13170. + This program is free software; you can redistribute it and/or
  13171. + modify it under the terms of the GNU General Public License as
  13172. + published by the Free Software Foundation; either version 2, or (at
  13173. + your option) any later version.
  13174. +
  13175. + This program is distributed in the hope that it will be useful, but
  13176. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13177. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13178. + General Public License for more details.
  13179. +*/
  13180. +
  13181. +#include <stdio.h>
  13182. +#include <stdarg.h>
  13183. +#include "libbb.h"
  13184. +#include "file_util.h"
  13185. +#include "str_util.h"
  13186. +#include "libipkg.h"
  13187. +
  13188. +char *get_user_response(const char *format, ...);
  13189. +static char *question = NULL;
  13190. +static int question_len = 255;
  13191. +
  13192. +char *get_user_response(const char *format, ...)
  13193. +{
  13194. + int len = question_len;
  13195. + va_list ap;
  13196. + char *response;
  13197. + va_start(ap, format);
  13198. +
  13199. + do {
  13200. + if (question == NULL || len > question_len) {
  13201. + question = realloc(question, len + 1);
  13202. + question_len = len;
  13203. + }
  13204. + len = vsnprintf(question,question_len,format,ap);
  13205. + } while (len > question_len);
  13206. + response = strdup(ipkg_cb_response(question));
  13207. + str_chomp(response);
  13208. + str_tolower(response);
  13209. +
  13210. + return response;
  13211. +}
  13212. diff -Nur busybox-1.17.2.orig/archival/libipkg/user.h busybox-1.17.2/archival/libipkg/user.h
  13213. --- busybox-1.17.2.orig/archival/libipkg/user.h 1970-01-01 01:00:00.000000000 +0100
  13214. +++ busybox-1.17.2/archival/libipkg/user.h 2010-12-01 22:25:23.000000000 +0100
  13215. @@ -0,0 +1,23 @@
  13216. +/* user.c - the itsy package management system
  13217. +
  13218. + Jamey Hicks
  13219. +
  13220. + Copyright (C) 2002 Hewlett Packard Company
  13221. + Copyright (C) 2001 University of Southern California
  13222. +
  13223. + This program is free software; you can redistribute it and/or
  13224. + modify it under the terms of the GNU General Public License as
  13225. + published by the Free Software Foundation; either version 2, or (at
  13226. + your option) any later version.
  13227. +
  13228. + This program is distributed in the hope that it will be useful, but
  13229. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13230. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13231. + General Public License for more details.
  13232. +*/
  13233. +
  13234. +#include <stdio.h>
  13235. +#include <stdarg.h>
  13236. +
  13237. +char *get_user_response(const char *format, ...);
  13238. +
  13239. diff -Nur busybox-1.17.2.orig/archival/libipkg/void_list.c busybox-1.17.2/archival/libipkg/void_list.c
  13240. --- busybox-1.17.2.orig/archival/libipkg/void_list.c 1970-01-01 01:00:00.000000000 +0100
  13241. +++ busybox-1.17.2/archival/libipkg/void_list.c 2010-12-01 22:25:23.000000000 +0100
  13242. @@ -0,0 +1,194 @@
  13243. +/* void_list.c - the itsy package management system
  13244. +
  13245. + Carl D. Worth
  13246. +
  13247. + Copyright (C) 2001 University of Southern California
  13248. +
  13249. + This program is free software; you can redistribute it and/or
  13250. + modify it under the terms of the GNU General Public License as
  13251. + published by the Free Software Foundation; either version 2, or (at
  13252. + your option) any later version.
  13253. +
  13254. + This program is distributed in the hope that it will be useful, but
  13255. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13256. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13257. + General Public License for more details.
  13258. +*/
  13259. +
  13260. +#include "ipkg.h"
  13261. +#include <errno.h>
  13262. +
  13263. +#include "void_list.h"
  13264. +
  13265. +int void_list_elt_init(void_list_elt_t *elt, void *data)
  13266. +{
  13267. + elt->next = NULL;
  13268. + elt->data = data;
  13269. +
  13270. + return 0;
  13271. +}
  13272. +
  13273. +void void_list_elt_deinit(void_list_elt_t *elt)
  13274. +{
  13275. + void_list_elt_init(elt, NULL);
  13276. +}
  13277. +
  13278. +int void_list_init(void_list_t *list)
  13279. +{
  13280. + void_list_elt_init(&list->pre_head, NULL);
  13281. + list->head = NULL;
  13282. + list->pre_head.next = list->head;
  13283. + list->tail = NULL;
  13284. +
  13285. + return 0;
  13286. +}
  13287. +
  13288. +void void_list_deinit(void_list_t *list)
  13289. +{
  13290. + void_list_elt_t *elt;
  13291. +
  13292. + while (list->head) {
  13293. + elt = void_list_pop(list);
  13294. + void_list_elt_deinit(elt);
  13295. + /* malloced in void_list_append */
  13296. + free(elt);
  13297. + }
  13298. +}
  13299. +
  13300. +int void_list_append(void_list_t *list, void *data)
  13301. +{
  13302. + void_list_elt_t *elt;
  13303. +
  13304. + /* freed in void_list_deinit */
  13305. + elt = malloc(sizeof(void_list_elt_t));
  13306. + if (elt == NULL) {
  13307. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  13308. + return ENOMEM;
  13309. + }
  13310. +
  13311. + void_list_elt_init(elt, data);
  13312. +
  13313. + if (list->tail) {
  13314. + list->tail->next = elt;
  13315. + list->tail = elt;
  13316. + } else {
  13317. + list->head = elt;
  13318. + list->pre_head.next = list->head;
  13319. + list->tail = elt;
  13320. + }
  13321. +
  13322. + return 0;
  13323. +}
  13324. +
  13325. +int void_list_push(void_list_t *list, void *data)
  13326. +{
  13327. + void_list_elt_t *elt;
  13328. +
  13329. + elt = malloc(sizeof(void_list_elt_t));
  13330. + if (elt == NULL) {
  13331. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  13332. + return ENOMEM;
  13333. + }
  13334. +
  13335. + void_list_elt_init(elt, data);
  13336. +
  13337. + elt->next = list->head;
  13338. + list->head->next = elt;
  13339. + if (list->tail == NULL) {
  13340. + list->tail = list->head;
  13341. + }
  13342. +
  13343. + return 0;
  13344. +}
  13345. +
  13346. +void_list_elt_t *void_list_pop(void_list_t *list)
  13347. +{
  13348. + void_list_elt_t *elt;
  13349. +
  13350. + elt = list->head;
  13351. +
  13352. + if (list->head) {
  13353. + list->head = list->head->next;
  13354. + list->pre_head.next = list->head;
  13355. + if (list->head == NULL) {
  13356. + list->tail = NULL;
  13357. + }
  13358. + }
  13359. +
  13360. + return elt;
  13361. +}
  13362. +
  13363. +void *void_list_remove(void_list_t *list, void_list_elt_t **iter)
  13364. +{
  13365. + void_list_elt_t *prior;
  13366. + void_list_elt_t *old_elt;
  13367. + void *old_data;
  13368. +
  13369. + old_elt = *iter;
  13370. + old_data = old_elt->data;
  13371. +
  13372. + if (old_elt == list->head) {
  13373. + prior = &list->pre_head;
  13374. + void_list_pop(list);
  13375. + } else {
  13376. + for (prior = list->head; prior; prior = prior->next) {
  13377. + if (prior->next == old_elt) {
  13378. + break;
  13379. + }
  13380. + }
  13381. + if (prior == NULL || prior->next != old_elt) {
  13382. + fprintf(stderr, "%s: ERROR: element not found in list\n", __FUNCTION__);
  13383. + return NULL;
  13384. + }
  13385. + prior->next = old_elt->next;
  13386. +
  13387. + if (old_elt == list->tail) {
  13388. + list->tail = prior;
  13389. + }
  13390. + }
  13391. +
  13392. + void_list_elt_deinit(old_elt);
  13393. + *iter = prior;
  13394. +
  13395. + return old_data;
  13396. +}
  13397. +
  13398. +/* remove element containing elt data, using cmp(elt->data, target_data) == 0. */
  13399. +void *void_list_remove_elt(void_list_t *list, const void *target_data, void_list_cmp_t cmp)
  13400. +{
  13401. + void_list_elt_t *prior;
  13402. + void_list_elt_t *old_elt = NULL;
  13403. + void *old_data = NULL;
  13404. +
  13405. + /* first element */
  13406. + if (list->head && list->head->data && (cmp(list->head->data, target_data) == 0)) {
  13407. + old_elt = list->head;
  13408. + old_data = list->head->data;
  13409. + void_list_pop(list);
  13410. + } else {
  13411. + int found = 0;
  13412. + for (prior = list->head; prior && prior->next; prior = prior->next) {
  13413. + if (prior->next->data && (cmp(prior->next->data, target_data) == 0)) {
  13414. + old_elt = prior->next;
  13415. + old_data = old_elt->data;
  13416. + found = 1;
  13417. + break;
  13418. + }
  13419. + }
  13420. + if (!found) {
  13421. + return NULL;
  13422. + }
  13423. + prior->next = old_elt->next;
  13424. +
  13425. + if (old_elt == list->tail) {
  13426. + list->tail = prior;
  13427. + }
  13428. + }
  13429. + if (old_elt)
  13430. + void_list_elt_deinit(old_elt);
  13431. +
  13432. + if (old_data)
  13433. + return old_data;
  13434. + else
  13435. + return NULL;
  13436. +}
  13437. diff -Nur busybox-1.17.2.orig/archival/libipkg/void_list.h busybox-1.17.2/archival/libipkg/void_list.h
  13438. --- busybox-1.17.2.orig/archival/libipkg/void_list.h 1970-01-01 01:00:00.000000000 +0100
  13439. +++ busybox-1.17.2/archival/libipkg/void_list.h 2010-12-01 22:25:23.000000000 +0100
  13440. @@ -0,0 +1,59 @@
  13441. +/* void_list.h - the itsy package management system
  13442. +
  13443. + Carl D. Worth
  13444. +
  13445. + Copyright (C) 2001 University of Southern California
  13446. +
  13447. + This program is free software; you can redistribute it and/or
  13448. + modify it under the terms of the GNU General Public License as
  13449. + published by the Free Software Foundation; either version 2, or (at
  13450. + your option) any later version.
  13451. +
  13452. + This program is distributed in the hope that it will be useful, but
  13453. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13454. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13455. + General Public License for more details.
  13456. +*/
  13457. +
  13458. +#ifndef VOID_LIST_H
  13459. +#define VOID_LIST_H
  13460. +
  13461. +typedef struct void_list_elt void_list_elt_t;
  13462. +struct void_list_elt
  13463. +{
  13464. + void_list_elt_t *next;
  13465. + void *data;
  13466. +};
  13467. +
  13468. +typedef struct void_list void_list_t;
  13469. +struct void_list
  13470. +{
  13471. + void_list_elt_t pre_head;
  13472. + void_list_elt_t *head;
  13473. + void_list_elt_t *tail;
  13474. +};
  13475. +
  13476. +static inline int void_list_empty(void_list_t *list)
  13477. +{
  13478. + if (list->head == NULL)
  13479. + return 1;
  13480. + else
  13481. + return 0;
  13482. +}
  13483. +
  13484. +int void_list_elt_init(void_list_elt_t *elt, void *data);
  13485. +void void_list_elt_deinit(void_list_elt_t *elt);
  13486. +
  13487. +int void_list_init(void_list_t *list);
  13488. +void void_list_deinit(void_list_t *list);
  13489. +
  13490. +int void_list_append(void_list_t *list, void *data);
  13491. +int void_list_push(void_list_t *list, void *data);
  13492. +void_list_elt_t *void_list_pop(void_list_t *list);
  13493. +
  13494. +void *void_list_remove(void_list_t *list, void_list_elt_t **iter);
  13495. +/* remove element containing elt data, using cmp(elt->data, target_data) == 0. */
  13496. +typedef int (*void_list_cmp_t)(const void *, const void *);
  13497. +void *void_list_remove_elt(void_list_t *list, const void *target_data, void_list_cmp_t cmp);
  13498. +
  13499. +#endif
  13500. diff -Nur busybox-1.17.2.orig/archival/libipkg/xsystem.c busybox-1.17.2/archival/libipkg/xsystem.c
  13501. --- busybox-1.17.2.orig/archival/libipkg/xsystem.c 1970-01-01 01:00:00.000000000 +0100
  13502. +++ busybox-1.17.2/archival/libipkg/xsystem.c 2010-12-01 22:25:23.000000000 +0100
  13503. @@ -0,0 +1,64 @@
  13504. +/* xsystem.c - system(3) with error messages
  13505. +
  13506. + Carl D. Worth
  13507. +
  13508. + Copyright (C) 2001 University of Southern California
  13509. +
  13510. + This program is free software; you can redistribute it and/or
  13511. + modify it under the terms of the GNU General Public License as
  13512. + published by the Free Software Foundation; either version 2, or (at
  13513. + your option) any later version.
  13514. +
  13515. + This program is distributed in the hope that it will be useful, but
  13516. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13517. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13518. + General Public License for more details.
  13519. +*/
  13520. +
  13521. +#include "ipkg.h"
  13522. +#include <sys/wait.h>
  13523. +
  13524. +#include "xsystem.h"
  13525. +
  13526. +/* XXX: FEATURE: I shouldn't actually use system(3) at all. I don't
  13527. + really need the /bin/sh invocation which takes resources and
  13528. + introduces security problems. I should switch all of this to a sort
  13529. + of execl() or execv() interface/implementation.
  13530. +*/
  13531. +
  13532. +/* Like system(3), but with error messages printed if the fork fails
  13533. + or if the child process dies due to an uncaught signal. Also, the
  13534. + return value is a bit simpler:
  13535. +
  13536. + -1 if there was any problem
  13537. + Otherwise, the 8-bit return value of the program ala WEXITSTATUS
  13538. + as defined in <sys/wait.h>.
  13539. +*/
  13540. +int xsystem(const char *cmd)
  13541. +{
  13542. + int err;
  13543. +
  13544. + err = system(cmd);
  13545. +
  13546. + if (err == -1) {
  13547. + fprintf(stderr, "%s: ERROR: fork failed before execution: `%s'\n",
  13548. + __FUNCTION__, cmd);
  13549. + return -1;
  13550. + }
  13551. +
  13552. + if (WIFSIGNALED(err)) {
  13553. + fprintf(stderr, "%s: ERROR: Child process died due to signal %d: `%s'\n",
  13554. + __FUNCTION__, WTERMSIG(err), cmd);
  13555. + return -1;
  13556. + }
  13557. +
  13558. + if (WIFEXITED(err)) {
  13559. + /* Normal child exit */
  13560. + return WEXITSTATUS(err);
  13561. + }
  13562. +
  13563. + fprintf(stderr, "%s: ERROR: Received unintelligible return value from system: %d",
  13564. + __FUNCTION__, err);
  13565. + return -1;
  13566. +}
  13567. +
  13568. diff -Nur busybox-1.17.2.orig/archival/libipkg/xsystem.h busybox-1.17.2/archival/libipkg/xsystem.h
  13569. --- busybox-1.17.2.orig/archival/libipkg/xsystem.h 1970-01-01 01:00:00.000000000 +0100
  13570. +++ busybox-1.17.2/archival/libipkg/xsystem.h 2010-12-01 22:25:23.000000000 +0100
  13571. @@ -0,0 +1,34 @@
  13572. +/* xsystem.h - system(3) with error messages
  13573. +
  13574. + Carl D. Worth
  13575. +
  13576. + Copyright (C) 2001 University of Southern California
  13577. +
  13578. + This program is free software; you can redistribute it and/or
  13579. + modify it under the terms of the GNU General Public License as
  13580. + published by the Free Software Foundation; either version 2, or (at
  13581. + your option) any later version.
  13582. +
  13583. + This program is distributed in the hope that it will be useful, but
  13584. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13585. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13586. + General Public License for more details.
  13587. +*/
  13588. +
  13589. +#ifndef XSYSTEM_H
  13590. +#define XSYSTEM_H
  13591. +
  13592. +#include <stdlib.h>
  13593. +
  13594. +/* Like system(3), but with error messages printed if the fork fails
  13595. + or if the child process dies due to an uncaught signal. Also, the
  13596. + return value is a bit simpler:
  13597. +
  13598. + -1 if there was any problem
  13599. + Otherwise, the 8-bit return value of the program ala WEXITSTATUS
  13600. + as defined in <sys/wait.h>.
  13601. +*/
  13602. +int xsystem(const char *cmd);
  13603. +
  13604. +#endif
  13605. +
  13606. diff -Nur busybox-1.17.2.orig/archival/libunarchive/Kbuild.src busybox-1.17.2/archival/libunarchive/Kbuild.src
  13607. --- busybox-1.17.2.orig/archival/libunarchive/Kbuild.src 2010-08-23 02:44:35.000000000 +0200
  13608. +++ busybox-1.17.2/archival/libunarchive/Kbuild.src 2010-12-01 22:25:23.000000000 +0100
  13609. @@ -43,6 +43,7 @@
  13610. lib-$(CONFIG_DPKG) += $(DPKG_FILES)
  13611. lib-$(CONFIG_DPKG_DEB) += $(DPKG_FILES)
  13612. lib-$(CONFIG_GUNZIP) += decompress_unzip.o
  13613. +lib-$(CONFIG_IPKG) += open_transformer.o get_header_tar.o get_header_tar_gz.o
  13614. lib-$(CONFIG_RPM2CPIO) += decompress_unzip.o get_header_cpio.o
  13615. lib-$(CONFIG_RPM) += open_transformer.o decompress_unzip.o get_header_cpio.o
  13616. lib-$(CONFIG_TAR) += get_header_tar.o
  13617. diff -Nur busybox-1.17.2.orig/include/applets.src.h busybox-1.17.2/include/applets.src.h
  13618. --- busybox-1.17.2.orig/include/applets.src.h 2010-08-23 02:44:35.000000000 +0200
  13619. +++ busybox-1.17.2/include/applets.src.h 2010-12-01 22:25:23.000000000 +0100
  13620. @@ -209,6 +209,7 @@
  13621. IF_IPCALC(APPLET(ipcalc, _BB_DIR_BIN, _BB_SUID_DROP))
  13622. IF_IPCRM(APPLET(ipcrm, _BB_DIR_USR_BIN, _BB_SUID_REQUIRE))
  13623. IF_IPCS(APPLET(ipcs, _BB_DIR_USR_BIN, _BB_SUID_REQUIRE))
  13624. +IF_IPKG(APPLET(ipkg, _BB_DIR_USR_BIN, _BB_SUID_DROP))
  13625. IF_IPLINK(APPLET(iplink, _BB_DIR_BIN, _BB_SUID_DROP))
  13626. IF_IPROUTE(APPLET(iproute, _BB_DIR_BIN, _BB_SUID_DROP))
  13627. IF_IPRULE(APPLET(iprule, _BB_DIR_BIN, _BB_SUID_DROP))
  13628. diff -Nur busybox-1.17.2.orig/include/unarchive.h busybox-1.17.2/include/unarchive.h
  13629. --- busybox-1.17.2.orig/include/unarchive.h 2010-08-22 10:21:38.000000000 +0200
  13630. +++ busybox-1.17.2/include/unarchive.h 2010-12-01 22:25:23.000000000 +0100
  13631. @@ -76,7 +76,7 @@
  13632. off_t offset;
  13633. /* Archiver specific. Can make it a union if it ever gets big */
  13634. -#if ENABLE_TAR || ENABLE_DPKG || ENABLE_DPKG_DEB
  13635. +#if ENABLE_TAR || ENABLE_DPKG || ENABLE_DPKG_DEB || ENABLE_IPKG
  13636. smallint tar__end;
  13637. # if ENABLE_FEATURE_TAR_GNU_EXTENSIONS
  13638. char* tar__longname;
  13639. @@ -95,7 +95,7 @@
  13640. struct hardlinks_t *cpio__hardlinks_to_create;
  13641. struct hardlinks_t *cpio__created_hardlinks;
  13642. #endif
  13643. -#if ENABLE_DPKG || ENABLE_DPKG_DEB
  13644. +#if ENABLE_DPKG || ENABLE_DPKG_DEB || ENABLE_IPKG
  13645. /* Temporary storage */
  13646. char *dpkg__buffer;
  13647. /* How to process any sub archive, e.g. get_header_tar_gz */
  13648. diff -Nur busybox-1.17.2.orig/include/usage.src.h busybox-1.17.2/include/usage.src.h
  13649. --- busybox-1.17.2.orig/include/usage.src.h 2010-08-23 02:44:35.000000000 +0200
  13650. +++ busybox-1.17.2/include/usage.src.h 2010-12-01 22:25:23.000000000 +0100
  13651. @@ -1556,6 +1556,82 @@
  13652. "$ ls -la /tmp/busybox*\n" \
  13653. "-rw-rw-r-- 1 andersen andersen 554058 Apr 14 17:49 /tmp/busybox.tar.gz\n"
  13654. +#define ipkg_trivial_usage \
  13655. + "[options]... sub-command [arguments]..."
  13656. +#define ipkg_full_usage \
  13657. + "ipkg is an utility to install, remove and manage .ipk packages.\n" \
  13658. + "\n" \
  13659. + "Sub-commands:\n" \
  13660. + "\nPackage Manipulation:\n" \
  13661. + "\tupdate Update list of available packages\n" \
  13662. + "\tupgrade Upgrade all installed packages to latest version\n" \
  13663. + "\tinstall <pkg> Download and install <pkg> (and dependencies)\n" \
  13664. + "\tinstall <file.ipk> Install package <file.ipk>\n" \
  13665. + "\tconfigure [<pkg>] Configure unpacked packages\n" \
  13666. + "\tremove <pkg|regexp> Remove package <pkg|packages following regexp>\n" \
  13667. + "\tflag <flag> <pkg> ... Flag package(s) <pkg>\n" \
  13668. + "\t <flag>=hold|noprune|user|ok|installed|unpacked (one per invocation) \n" \
  13669. + "\n" \
  13670. + "Informational Commands:\n" \
  13671. + "\tlist List available packages and descriptions\n" \
  13672. + "\tlist_installed List all and only the installed packages and description \n" \
  13673. + "\tfiles <pkg> List all files belonging to <pkg>\n" \
  13674. + "\tsearch <file|regexp> Search for a package providing <file>\n" \
  13675. + "\tinfo [pkg|regexp [<field>]] Display all/some info fields for <pkg> or all\n" \
  13676. + "\tstatus [pkg|regexp [<field>]] Display all/some status fields for <pkg> or all\n" \
  13677. + "\tdownload <pkg> Download <pkg> to current directory.\n" \
  13678. + "\tcompare_versions <v1> <op> <v2>\n" \
  13679. + "\t compare versions using <= < > >= = << >>\n" \
  13680. + "\tprint_architecture prints the architecture.\n" \
  13681. + "\tprint_installation_architecture\n" \
  13682. + "\twhatdepends [-A] [pkgname|pat]+\n" \
  13683. + "\twhatdependsrec [-A] [pkgname|pat]+\n" \
  13684. + "\twhatprovides [-A] [pkgname|pat]+\n" \
  13685. + "\twhatconflicts [-A] [pkgname|pat]+\n" \
  13686. + "\twhatreplaces [-A] [pkgname|pat]+\n" \
  13687. + "\t prints the installation architecture.\n" \
  13688. + "\n" \
  13689. + "\nOptions:\n" \
  13690. + "\t-A Query all packages with whatdepends, whatprovides, whatreplaces, whatconflicts\n" \
  13691. + "\t-V <level> Set verbosity level to <level>. If no value is\n" \
  13692. + "\t--verbosity <level> provided increase verbosity by one. Verbosity levels:\n" \
  13693. + "\t 0 errors only\n" \
  13694. + "\t 1 normal messages (default)\n" \
  13695. + "\t 2 informative messages\n" \
  13696. + "\t 3 debug output\n" \
  13697. + "\t-f <conf_file> Use <conf_file> as the ipkg configuration file\n" \
  13698. + "\t-conf <conf_file> Default configuration file location\n" \
  13699. + " is /etc/ipkg.conf\n" \
  13700. + "\t-d <dest_name> Use <dest_name> as the the root directory for\n" \
  13701. + "\t-dest <dest_name> package installation, removal, upgrading.\n" \
  13702. + " <dest_name> should be a defined dest name from\n" \
  13703. + " the configuration file, (but can also be a\n" \
  13704. + " directory name in a pinch).\n" \
  13705. + "\t-o <offline_root> Use <offline_root> as the root directory for\n" \
  13706. + "\t-offline <offline_root> offline installation of packages.\n" \
  13707. + "\t-verbose_wget more wget messages\n" \
  13708. + "\n" \
  13709. + "Force Options (use when ipkg is too smart for its own good):\n" \
  13710. + "\t-force-depends Make dependency checks warnings instead of errors\n" \
  13711. + "\t Install/remove package in spite of failed dependences\n" \
  13712. + "\t-force-defaults Use default options for questions asked by ipkg.\n" \
  13713. + " (no prompts). Note that this will not prevent\n" \
  13714. + " package installation scripts from prompting.\n" \
  13715. + "\t-force-reinstall Allow ipkg to reinstall a package.\n" \
  13716. + "\t-force-overwrite Allow ipkg to overwrite files from another package during an install.\n" \
  13717. + "\t-force-downgrade Allow ipkg to downgrade packages.\n" \
  13718. + "\t-force_space Install even if there does not seem to be enough space.\n" \
  13719. + "\t-noaction No action -- test only\n" \
  13720. + "\t-nodeps Do not follow dependences\n" \
  13721. + "\t-force-removal-of-dependent-packages\n" \
  13722. + "\t-recursive Allow ipkg to remove package and all that depend on it.\n" \
  13723. + "\t-test No action -- test only\n" \
  13724. + "\t-t Specify tmp-dir.\n" \
  13725. + "\t--tmp-dir Specify tmp-dir.\n" \
  13726. + "\n" \
  13727. + "\tregexp could be something like 'pkgname*' '*file*' or similar\n" \
  13728. + "\teg: ipkg info 'libstd*' or ipkg search '*libop*' or ipkg remove 'libncur*'\n"
  13729. +
  13730. #define halt_trivial_usage \
  13731. "[-d DELAY] [-n] [-f]" IF_FEATURE_WTMP(" [-w]")
  13732. #define halt_full_usage "\n\n" \