001-ipkg.patch 426 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797
  1. diff -Nur busybox-1.12.1.orig/archival/Config.in busybox-1.12.1/archival/Config.in
  2. --- busybox-1.12.1.orig/archival/Config.in 2008-09-28 20:04:15.000000000 +0200
  3. +++ busybox-1.12.1/archival/Config.in 2008-10-23 11:41:37.000000000 +0200
  4. @@ -157,6 +157,14 @@
  5. gzip is used to compress files.
  6. It's probably the most widely used UNIX compression program.
  7. +config IPKG
  8. + bool "ipkg"
  9. + default n
  10. + select MD5SUM
  11. + select WGET
  12. + help
  13. + ipkg is the itsy package management system.
  14. +
  15. config RPM2CPIO
  16. bool "rpm2cpio"
  17. default n
  18. diff -Nur busybox-1.12.1.orig/archival/dpkg.c busybox-1.12.1/archival/dpkg.c
  19. --- busybox-1.12.1.orig/archival/dpkg.c 2008-09-28 20:04:15.000000000 +0200
  20. +++ busybox-1.12.1/archival/dpkg.c 2008-10-23 11:53:33.000000000 +0200
  21. @@ -1481,16 +1481,7 @@
  22. return ar_handle->sub_archive->buffer;
  23. }
  24. -static void FAST_FUNC data_extract_all_prefix(archive_handle_t *archive_handle)
  25. -{
  26. - char *name_ptr = archive_handle->file_header->name;
  27. -
  28. - name_ptr += strspn(name_ptr, "./");
  29. - if (name_ptr[0] != '\0') {
  30. - archive_handle->file_header->name = xasprintf("%s%s", archive_handle->buffer, name_ptr);
  31. - data_extract_all(archive_handle);
  32. - }
  33. -}
  34. +/* remove data_extract_all_prefix */
  35. static void unpack_package(deb_file_t *deb_file)
  36. {
  37. diff -Nur busybox-1.12.1.orig/archival/ipkg.c busybox-1.12.1/archival/ipkg.c
  38. --- busybox-1.12.1.orig/archival/ipkg.c 1970-01-01 01:00:00.000000000 +0100
  39. +++ busybox-1.12.1/archival/ipkg.c 2008-10-23 12:14:28.000000000 +0200
  40. @@ -0,0 +1,28 @@
  41. +/* ipkg.c - the itsy package management system
  42. +
  43. + Florina Boor
  44. +
  45. + Copyright (C) 2003 kernel concepts
  46. +
  47. + This program is free software; you can redistribute it and/or
  48. + modify it under the terms of the GNU General Public License as
  49. + published by the Free Software Foundation; either version 2, or (at
  50. + your option) any later version.
  51. +
  52. + This program is distributed in the hope that it will be useful, but
  53. + WITHOUT ANY WARRANTY; without even the implied warranty of
  54. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  55. + General Public License for more details.
  56. +
  57. + ipkg command line frontend using libipkg
  58. +
  59. +*/
  60. +
  61. +#include "libbb.h"
  62. +#include "libipkg/libipkg.h"
  63. +
  64. +int ipkg_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  65. +int ipkg_main(int argc, char **argv)
  66. +{
  67. + return ipkg_op(argc, argv);
  68. +}
  69. diff -Nur busybox-1.12.1.orig/archival/Kbuild busybox-1.12.1/archival/Kbuild
  70. --- busybox-1.12.1.orig/archival/Kbuild 2008-09-28 20:04:15.000000000 +0200
  71. +++ busybox-1.12.1/archival/Kbuild 2008-10-23 11:41:37.000000000 +0200
  72. @@ -16,6 +16,7 @@
  73. lib-$(CONFIG_DPKG_DEB) += dpkg_deb.o
  74. lib-$(CONFIG_GUNZIP) += bbunzip.o
  75. lib-$(CONFIG_GZIP) += gzip.o bbunzip.o
  76. +lib-$(CONFIG_IPKG) += ipkg.o
  77. lib-$(CONFIG_RPM2CPIO) += rpm2cpio.o
  78. lib-$(CONFIG_RPM) += rpm.o
  79. lib-$(CONFIG_TAR) += tar.o
  80. diff -Nur busybox-1.12.1.orig/archival/libipkg/args.c busybox-1.12.1/archival/libipkg/args.c
  81. --- busybox-1.12.1.orig/archival/libipkg/args.c 1970-01-01 01:00:00.000000000 +0100
  82. +++ busybox-1.12.1/archival/libipkg/args.c 2008-10-23 15:00:11.000000000 +0200
  83. @@ -0,0 +1,242 @@
  84. +/* args.c - parse command-line args
  85. +
  86. + Carl D. Worth
  87. +
  88. + Copyright 2001 University of Southern California
  89. +
  90. + This program is free software; you can redistribute it and/or modify
  91. + it under the terms of the GNU General Public License as published by
  92. + the Free Software Foundation; either version 2, or (at your option)
  93. + any later version.
  94. +
  95. + This program is distributed in the hope that it will be useful,
  96. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  97. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  98. + GNU General Public License for more details.
  99. + */
  100. +
  101. +#include <getopt.h>
  102. +#include <stdlib.h>
  103. +#include <string.h>
  104. +#include <unistd.h>
  105. +
  106. +#include "ipkg.h"
  107. +#include "ipkg_message.h"
  108. +
  109. +#include "args.h"
  110. +#include "sprintf_alloc.h"
  111. +
  112. +#include "libbb.h"
  113. +
  114. +
  115. +static void print_version(void);
  116. +
  117. +enum long_args_opt
  118. +{
  119. + ARGS_OPT_FORCE_DEFAULTS = 129,
  120. + ARGS_OPT_FORCE_DEPENDS,
  121. + ARGS_OPT_FORCE_OVERWRITE,
  122. + ARGS_OPT_FORCE_DOWNGRADE,
  123. + ARGS_OPT_FORCE_REINSTALL,
  124. + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES,
  125. + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES,
  126. + ARGS_OPT_FORCE_SPACE,
  127. + ARGS_OPT_NOACTION,
  128. + ARGS_OPT_NODEPS,
  129. + ARGS_OPT_VERBOSE_WGET,
  130. + ARGS_OPT_VERBOSITY,
  131. + ARGS_OPT_MULTIPLE_PROVIDERS
  132. +};
  133. +
  134. +int args_init(args_t *args)
  135. +{
  136. + const char *conf_file_dir;
  137. +
  138. + memset(args, 0, sizeof(args_t));
  139. +
  140. + args->dest = ARGS_DEFAULT_DEST;
  141. +
  142. + conf_file_dir = getenv("IPKG_CONF_DIR");
  143. + if (conf_file_dir == NULL || conf_file_dir[0] == '\0') {
  144. + conf_file_dir = ARGS_DEFAULT_CONF_FILE_DIR;
  145. + }
  146. + sprintf_alloc(&args->conf_file, "%s/%s", conf_file_dir,
  147. + ARGS_DEFAULT_CONF_FILE_NAME);
  148. +
  149. + args->force_defaults = ARGS_DEFAULT_FORCE_DEFAULTS;
  150. + args->force_depends = ARGS_DEFAULT_FORCE_DEPENDS;
  151. + args->force_overwrite = ARGS_DEFAULT_FORCE_OVERWRITE;
  152. + args->force_downgrade = ARGS_DEFAULT_FORCE_DOWNGRADE;
  153. + args->force_reinstall = ARGS_DEFAULT_FORCE_REINSTALL;
  154. + args->force_removal_of_dependent_packages = ARGS_DEFAULT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES;
  155. + args->force_removal_of_essential_packages = ARGS_DEFAULT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES;
  156. + args->noaction = ARGS_DEFAULT_NOACTION;
  157. + args->nodeps = ARGS_DEFAULT_NODEPS;
  158. + args->verbose_wget = ARGS_DEFAULT_VERBOSE_WGET;
  159. + args->verbosity = ARGS_DEFAULT_VERBOSITY;
  160. + args->offline_root = ARGS_DEFAULT_OFFLINE_ROOT;
  161. + args->offline_root_pre_script_cmd = ARGS_DEFAULT_OFFLINE_ROOT_PRE_SCRIPT_CMD;
  162. + args->offline_root_post_script_cmd = ARGS_DEFAULT_OFFLINE_ROOT_POST_SCRIPT_CMD;
  163. + args->multiple_providers = 0;
  164. + args->nocheckfordirorfile = 0;
  165. + args->noreadfeedsfile = 0;
  166. +
  167. + return 1;
  168. +}
  169. +
  170. +void args_deinit(args_t *args)
  171. +{
  172. + free(args->conf_file);
  173. + args->conf_file = NULL;
  174. +}
  175. +
  176. +int args_parse(args_t *args, int argc, char *argv[])
  177. +{
  178. + int c;
  179. + int option_index = 0;
  180. + int parse_err = 0;
  181. + static struct option long_options[] = {
  182. + {"query-all", 0, 0, 'A'},
  183. + {"conf-file", 1, 0, 'f'},
  184. + {"conf", 1, 0, 'f'},
  185. + {"dest", 1, 0, 'd'},
  186. + {"force-defaults", 0, 0, ARGS_OPT_FORCE_DEFAULTS},
  187. + {"force_defaults", 0, 0, ARGS_OPT_FORCE_DEFAULTS},
  188. + {"force-depends", 0, 0, ARGS_OPT_FORCE_DEPENDS},
  189. + {"force_depends", 0, 0, ARGS_OPT_FORCE_DEPENDS},
  190. + {"force-overwrite", 0, 0, ARGS_OPT_FORCE_OVERWRITE},
  191. + {"force_overwrite", 0, 0, ARGS_OPT_FORCE_OVERWRITE},
  192. + {"force_downgrade", 0, 0, ARGS_OPT_FORCE_DOWNGRADE},
  193. + {"force-downgrade", 0, 0, ARGS_OPT_FORCE_DOWNGRADE},
  194. + {"force-reinstall", 0, 0, ARGS_OPT_FORCE_REINSTALL},
  195. + {"force_reinstall", 0, 0, ARGS_OPT_FORCE_REINSTALL},
  196. + {"force-space", 0, 0, ARGS_OPT_FORCE_SPACE},
  197. + {"force_space", 0, 0, ARGS_OPT_FORCE_SPACE},
  198. + {"recursive", 0, 0,
  199. + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
  200. + {"force-removal-of-dependent-packages", 0, 0,
  201. + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
  202. + {"force_removal_of_dependent_packages", 0, 0,
  203. + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
  204. + {"force-removal-of-essential-packages", 0, 0,
  205. + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES},
  206. + {"force_removal_of_essential_packages", 0, 0,
  207. + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES},
  208. + {"multiple-providers", 0, 0, ARGS_OPT_MULTIPLE_PROVIDERS},
  209. + {"multiple_providers", 0, 0, ARGS_OPT_MULTIPLE_PROVIDERS},
  210. + {"noaction", 0, 0, ARGS_OPT_NOACTION},
  211. + {"nodeps", 0, 0, ARGS_OPT_NODEPS},
  212. + {"offline", 1, 0, 'o'},
  213. + {"offline-root", 1, 0, 'o'},
  214. + {"test", 0, 0, ARGS_OPT_NOACTION},
  215. + {"tmp-dir", 1, 0, 't'},
  216. + {"verbose-wget", 0, 0, ARGS_OPT_VERBOSE_WGET},
  217. + {"verbose_wget", 0, 0, ARGS_OPT_VERBOSE_WGET},
  218. + {"verbosity", 2, 0, 'V'},
  219. + {"version", 0, 0, 'v'},
  220. + {0, 0, 0, 0}
  221. + };
  222. +
  223. + while (1) {
  224. + c = getopt_long_only(argc, argv, "Ad:f:no:t:vV:", long_options, &option_index);
  225. + if (c == -1)
  226. + break;
  227. +
  228. + switch (c) {
  229. + case 'A':
  230. + args->query_all = 1;
  231. + break;
  232. + case 'd':
  233. + args->dest = optarg;
  234. + break;
  235. + case 'f':
  236. + free(args->conf_file);
  237. + args->conf_file = strdup(optarg);
  238. + break;
  239. + case 'o':
  240. + args->offline_root = optarg;
  241. + break;
  242. + case 'n':
  243. + args->noaction = 1;
  244. + break;
  245. + case 't':
  246. + args->tmp_dir = strdup(optarg);
  247. + break;
  248. + case 'v':
  249. + print_version();
  250. + exit(0);
  251. + case 'V':
  252. + case ARGS_OPT_VERBOSITY:
  253. + if (optarg)
  254. + args->verbosity = atoi(optarg);
  255. + else
  256. + args->verbosity += 1;
  257. + break;
  258. + case ARGS_OPT_FORCE_DEFAULTS:
  259. + args->force_defaults = 1;
  260. + break;
  261. + case ARGS_OPT_FORCE_DEPENDS:
  262. + args->force_depends = 1;
  263. + break;
  264. + case ARGS_OPT_FORCE_OVERWRITE:
  265. + args->force_overwrite = 1;
  266. + break;
  267. + case ARGS_OPT_FORCE_DOWNGRADE:
  268. + args->force_downgrade = 1;
  269. + break;
  270. + case ARGS_OPT_FORCE_REINSTALL:
  271. + args->force_reinstall = 1;
  272. + break;
  273. + case ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES:
  274. + args->force_removal_of_essential_packages = 1;
  275. + break;
  276. + case ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES:
  277. + args->force_removal_of_dependent_packages = 1;
  278. + break;
  279. + case ARGS_OPT_FORCE_SPACE:
  280. + args->force_space = 1;
  281. + break;
  282. + case ARGS_OPT_VERBOSE_WGET:
  283. + args->verbose_wget = 1;
  284. + break;
  285. + case ARGS_OPT_MULTIPLE_PROVIDERS:
  286. + args->multiple_providers = 1;
  287. + break;
  288. + case ARGS_OPT_NODEPS:
  289. + args->nodeps = 1;
  290. + break;
  291. + case ARGS_OPT_NOACTION:
  292. + args->noaction = 1;
  293. + break;
  294. + case ':':
  295. + parse_err++;
  296. + break;
  297. + case '?':
  298. + parse_err++;
  299. + break;
  300. + default:
  301. + bb_error_msg("Confusion: getopt_long returned %d\n", c);
  302. + }
  303. + }
  304. +
  305. + if (parse_err) {
  306. + return -parse_err;
  307. + } else {
  308. + return optind;
  309. + }
  310. +}
  311. +
  312. +void args_usage(const char *complaint)
  313. +{
  314. + if (complaint) {
  315. + bb_error_msg("%s\n", complaint);
  316. + }
  317. + print_version();
  318. + bb_show_usage();
  319. + exit(1);
  320. +}
  321. +
  322. +static void print_version(void)
  323. +{
  324. + bb_error_msg("version %s\n", IPKG_VERSION);
  325. +}
  326. diff -Nur busybox-1.12.1.orig/archival/libipkg/args.h busybox-1.12.1/archival/libipkg/args.h
  327. --- busybox-1.12.1.orig/archival/libipkg/args.h 1970-01-01 01:00:00.000000000 +0100
  328. +++ busybox-1.12.1/archival/libipkg/args.h 2008-10-23 14:59:44.000000000 +0200
  329. @@ -0,0 +1,72 @@
  330. +/* args.h - parse command-line args
  331. +
  332. + Carl D. Worth
  333. +
  334. + Copyright 2001 University of Southern California
  335. +
  336. + This program is free software; you can redistribute it and/or modify
  337. + it under the terms of the GNU General Public License as published by
  338. + the Free Software Foundation; either version 2, or (at your option)
  339. + any later version.
  340. +
  341. + This program is distributed in the hope that it will be useful,
  342. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  343. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  344. + GNU General Public License for more details.
  345. +*/
  346. +
  347. +#ifndef ARGS_H
  348. +#define ARGS_H
  349. +
  350. +struct args
  351. +{
  352. + char *conf_file;
  353. + char *dest;
  354. + char *tmp_dir;
  355. + int force_defaults;
  356. + int force_depends;
  357. + int force_overwrite;
  358. + int force_downgrade;
  359. + int force_reinstall;
  360. + int force_removal_of_essential_packages;
  361. + int force_removal_of_dependent_packages;
  362. + int force_space;
  363. + int noaction;
  364. + int nodeps;
  365. + int multiple_providers;
  366. + int query_all;
  367. + int verbose_wget;
  368. + int verbosity;
  369. + int nocheckfordirorfile;
  370. + int noreadfeedsfile;
  371. + char *offline_root;
  372. + char *offline_root_pre_script_cmd;
  373. + char *offline_root_post_script_cmd;
  374. +};
  375. +typedef struct args args_t;
  376. +
  377. +#define ARGS_DEFAULT_CONF_FILE_DIR "/etc"
  378. +#define ARGS_DEFAULT_CONF_FILE_NAME "ipkg.conf"
  379. +#define ARGS_DEFAULT_DEST NULL
  380. +#define ARGS_DEFAULT_FORCE_DEFAULTS 0
  381. +#define ARGS_DEFAULT_FORCE_DEPENDS 0
  382. +#define ARGS_DEFAULT_FORCE_OVERWRITE 0
  383. +#define ARGS_DEFAULT_FORCE_DOWNGRADE 0
  384. +#define ARGS_DEFAULT_FORCE_REINSTALL 0
  385. +#define ARGS_DEFAULT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES 0
  386. +#define ARGS_DEFAULT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES 0
  387. +#define ARGS_DEFAULT_FORCE_SPACE 0
  388. +#define ARGS_DEFAULT_OFFLINE_ROOT NULL
  389. +#define ARGS_DEFAULT_OFFLINE_ROOT_PRE_SCRIPT_CMD NULL
  390. +#define ARGS_DEFAULT_OFFLINE_ROOT_POST_SCRIPT_CMD NULL
  391. +#define ARGS_DEFAULT_NOACTION 0
  392. +#define ARGS_DEFAULT_NODEPS 0
  393. +#define ARGS_DEFAULT_VERBOSE_WGET 0
  394. +#define ARGS_DEFAULT_VERBOSITY 1
  395. +
  396. +int args_init(args_t *args);
  397. +void args_deinit(args_t *args);
  398. +int args_parse(args_t *args, int argc, char *argv[]);
  399. +void args_usage(const char *complaint);
  400. +
  401. +#endif
  402. diff -Nur busybox-1.12.1.orig/archival/libipkg/conffile.c busybox-1.12.1/archival/libipkg/conffile.c
  403. --- busybox-1.12.1.orig/archival/libipkg/conffile.c 1970-01-01 01:00:00.000000000 +0100
  404. +++ busybox-1.12.1/archival/libipkg/conffile.c 2008-10-23 12:48:24.000000000 +0200
  405. @@ -0,0 +1,65 @@
  406. +/* conffile.c - the itsy package management system
  407. +
  408. + Carl D. Worth
  409. +
  410. + Copyright (C) 2001 University of Southern California
  411. +
  412. + This program is free software; you can redistribute it and/or
  413. + modify it under the terms of the GNU General Public License as
  414. + published by the Free Software Foundation; either version 2, or (at
  415. + your option) any later version.
  416. +
  417. + This program is distributed in the hope that it will be useful, but
  418. + WITHOUT ANY WARRANTY; without even the implied warranty of
  419. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  420. + General Public License for more details.
  421. +*/
  422. +
  423. +#include <string.h>
  424. +#include <stdlib.h>
  425. +
  426. +#include "libbb.h"
  427. +#include "ipkg.h"
  428. +#include "ipkg_message.h"
  429. +
  430. +#include "conffile.h"
  431. +#include "file_util.h"
  432. +#include "sprintf_alloc.h"
  433. +
  434. +int conffile_init(conffile_t *conffile, const char *file_name, const uint8_t *md5sum)
  435. +{
  436. + return nv_pair_init(conffile, file_name, (char *)md5sum);
  437. +}
  438. +
  439. +void conffile_deinit(conffile_t *conffile)
  440. +{
  441. + nv_pair_deinit(conffile);
  442. +}
  443. +
  444. +int conffile_has_been_modified(ipkg_conf_t *conf, conffile_t *conffile)
  445. +{
  446. + uint8_t *md5sum;
  447. + char *filename = conffile->name;
  448. + char *root_filename;
  449. + int ret;
  450. +
  451. + if (conffile->value == NULL) {
  452. + ipkg_message(conf, IPKG_NOTICE, "%s: conffile %s has no md5sum\n", __FUNCTION__, conffile->name);
  453. + return 1;
  454. + }
  455. +
  456. + root_filename = root_filename_alloc(conf, filename);
  457. +
  458. + md5sum = file_md5sum_alloc(root_filename);
  459. +
  460. + ret = strcmp((char *)md5sum, conffile->value);
  461. + if (ret) {
  462. + ipkg_message(conf, IPKG_NOTICE, "%s: conffile %s: \t\nold md5=%s \t\nnew md5=%s\n", __FUNCTION__,
  463. + conffile->name, md5sum, conffile->value);
  464. + }
  465. +
  466. + free(root_filename);
  467. + free(md5sum);
  468. +
  469. + return ret;
  470. +}
  471. diff -Nur busybox-1.12.1.orig/archival/libipkg/conffile.h busybox-1.12.1/archival/libipkg/conffile.h
  472. --- busybox-1.12.1.orig/archival/libipkg/conffile.h 1970-01-01 01:00:00.000000000 +0100
  473. +++ busybox-1.12.1/archival/libipkg/conffile.h 2008-10-23 12:40:12.000000000 +0200
  474. @@ -0,0 +1,30 @@
  475. +/* conffile.h - the itsy package management system
  476. +
  477. + Carl D. Worth
  478. +
  479. + Copyright (C) 2001 University of Southern California
  480. +
  481. + This program is free software; you can redistribute it and/or
  482. + modify it under the terms of the GNU General Public License as
  483. + published by the Free Software Foundation; either version 2, or (at
  484. + your option) any later version.
  485. +
  486. + This program is distributed in the hope that it will be useful, but
  487. + WITHOUT ANY WARRANTY; without even the implied warranty of
  488. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  489. + General Public License for more details.
  490. +*/
  491. +
  492. +#ifndef CONFFILE_H
  493. +#define CONFFILE_H
  494. +
  495. +#include "nv_pair.h"
  496. +
  497. +typedef struct nv_pair conffile_t;
  498. +
  499. +int conffile_init(conffile_t *conffile, const char *file_name, const uint8_t *md5sum);
  500. +void conffile_deinit(conffile_t *conffile);
  501. +int conffile_has_been_modified(struct ipkg_conf *conf, conffile_t *conffile);
  502. +
  503. +#endif
  504. +
  505. diff -Nur busybox-1.12.1.orig/archival/libipkg/conffile_list.c busybox-1.12.1/archival/libipkg/conffile_list.c
  506. --- busybox-1.12.1.orig/archival/libipkg/conffile_list.c 1970-01-01 01:00:00.000000000 +0100
  507. +++ busybox-1.12.1/archival/libipkg/conffile_list.c 2008-10-23 11:41:37.000000000 +0200
  508. @@ -0,0 +1,47 @@
  509. +/* conffile_list.c - the itsy package management system
  510. +
  511. + Carl D. Worth
  512. +
  513. + Copyright (C) 2001 University of Southern California
  514. +
  515. + This program is free software; you can redistribute it and/or
  516. + modify it under the terms of the GNU General Public License as
  517. + published by the Free Software Foundation; either version 2, or (at
  518. + your option) any later version.
  519. +
  520. + This program is distributed in the hope that it will be useful, but
  521. + WITHOUT ANY WARRANTY; without even the implied warranty of
  522. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  523. + General Public License for more details.
  524. +*/
  525. +
  526. +#include "ipkg.h"
  527. +
  528. +#include "conffile_list.h"
  529. +
  530. +int conffile_list_init(conffile_list_t *list)
  531. +{
  532. + return nv_pair_list_init(list);
  533. +}
  534. +
  535. +void conffile_list_deinit(conffile_list_t *list)
  536. +{
  537. + nv_pair_list_deinit(list);
  538. +}
  539. +
  540. +conffile_t *conffile_list_append(conffile_list_t *list, const char *file_name,
  541. + const char *md5sum)
  542. +{
  543. + return nv_pair_list_append(list, file_name, md5sum);
  544. +}
  545. +
  546. +int conffile_list_push(conffile_list_t *list, conffile_t *data)
  547. +{
  548. + return nv_pair_list_push(list, data);
  549. +}
  550. +
  551. +conffile_list_elt_t *conffile_list_pop(conffile_list_t *list)
  552. +{
  553. + return nv_pair_list_pop(list);
  554. +}
  555. +
  556. diff -Nur busybox-1.12.1.orig/archival/libipkg/conffile_list.h busybox-1.12.1/archival/libipkg/conffile_list.h
  557. --- busybox-1.12.1.orig/archival/libipkg/conffile_list.h 1970-01-01 01:00:00.000000000 +0100
  558. +++ busybox-1.12.1/archival/libipkg/conffile_list.h 2008-10-23 11:41:37.000000000 +0200
  559. @@ -0,0 +1,36 @@
  560. +/* conffile_list.h - the itsy package management system
  561. +
  562. + Carl D. Worth
  563. +
  564. + Copyright (C) 2001 University of Southern California
  565. +
  566. + This program is free software; you can redistribute it and/or
  567. + modify it under the terms of the GNU General Public License as
  568. + published by the Free Software Foundation; either version 2, or (at
  569. + your option) any later version.
  570. +
  571. + This program is distributed in the hope that it will be useful, but
  572. + WITHOUT ANY WARRANTY; without even the implied warranty of
  573. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  574. + General Public License for more details.
  575. +*/
  576. +
  577. +#ifndef CONFFILE_LIST_H
  578. +#define CONFFILE_LIST_H
  579. +
  580. +#include "conffile.h"
  581. +#include "nv_pair_list.h"
  582. +
  583. +typedef struct nv_pair_list_elt conffile_list_elt_t;
  584. +typedef struct nv_pair_list conffile_list_t;
  585. +
  586. +int conffile_list_init(conffile_list_t *list);
  587. +void conffile_list_deinit(conffile_list_t *list);
  588. +
  589. +conffile_t *conffile_list_append(conffile_list_t *list, const char *name,
  590. + const char *root_dir);
  591. +int conffile_list_push(conffile_list_t *list, conffile_t *data);
  592. +conffile_list_elt_t *conffile_list_pop(conffile_list_t *list);
  593. +
  594. +#endif
  595. +
  596. diff -Nur busybox-1.12.1.orig/archival/libipkg/file_util.c busybox-1.12.1/archival/libipkg/file_util.c
  597. --- busybox-1.12.1.orig/archival/libipkg/file_util.c 1970-01-01 01:00:00.000000000 +0100
  598. +++ busybox-1.12.1/archival/libipkg/file_util.c 2008-10-23 12:34:37.000000000 +0200
  599. @@ -0,0 +1,132 @@
  600. +/* file_util.c - convenience routines for common stat operations
  601. +
  602. + Carl D. Worth
  603. +
  604. + Copyright (C) 2001 University of Southern California
  605. +
  606. + This program is free software; you can redistribute it and/or
  607. + modify it under the terms of the GNU General Public License as
  608. + published by the Free Software Foundation; either version 2, or (at
  609. + your option) any later version.
  610. +
  611. + This program is distributed in the hope that it will be useful, but
  612. + WITHOUT ANY WARRANTY; without even the implied warranty of
  613. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  614. + General Public License for more details.
  615. +*/
  616. +
  617. +#include "ipkg.h"
  618. +#include <sys/types.h>
  619. +#include <sys/stat.h>
  620. +
  621. +#include "sprintf_alloc.h"
  622. +#include "file_util.h"
  623. +#include "libbb.h"
  624. +#undef strlen
  625. +
  626. +int file_exists(const char *file_name)
  627. +{
  628. + int err;
  629. + struct stat stat_buf;
  630. +
  631. + err = stat(file_name, &stat_buf);
  632. + if (err == 0) {
  633. + return 1;
  634. + } else {
  635. + return 0;
  636. + }
  637. +}
  638. +
  639. +int file_is_dir(const char *file_name)
  640. +{
  641. + int err;
  642. + struct stat stat_buf;
  643. +
  644. + err = stat(file_name, &stat_buf);
  645. + if (err) {
  646. + return 0;
  647. + }
  648. +
  649. + return S_ISDIR(stat_buf.st_mode);
  650. +}
  651. +
  652. +/* read a single line from a file, stopping at a newline or EOF.
  653. + If a newline is read, it will appear in the resulting string.
  654. + Return value is a malloc'ed char * which should be freed at
  655. + some point by the caller.
  656. +
  657. + Return value is NULL if the file is at EOF when called.
  658. +*/
  659. +#define FILE_READ_LINE_BUF_SIZE 1024
  660. +char *file_read_line_alloc(FILE *file)
  661. +{
  662. + char buf[FILE_READ_LINE_BUF_SIZE];
  663. + int buf_len;
  664. + char *line = NULL;
  665. + int line_size = 0;
  666. +
  667. + memset(buf, 0, FILE_READ_LINE_BUF_SIZE);
  668. + while (fgets(buf, FILE_READ_LINE_BUF_SIZE, file)) {
  669. + buf_len = strlen(buf);
  670. + if (line) {
  671. + line_size += buf_len;
  672. + line = realloc(line, line_size);
  673. + if (line == NULL) {
  674. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  675. + break;
  676. + }
  677. + strcat(line, buf);
  678. + } else {
  679. + line_size = buf_len + 1;
  680. + line = strdup(buf);
  681. + }
  682. + if (buf[buf_len - 1] == '\n') {
  683. + break;
  684. + }
  685. + }
  686. +
  687. + return line;
  688. +}
  689. +
  690. +int file_move(const char *src, const char *dest)
  691. +{
  692. + int err;
  693. +
  694. + err = rename(src, dest);
  695. +
  696. + if (err && errno == EXDEV) {
  697. + err = file_copy(src, dest);
  698. + unlink(src);
  699. + } else if (err) {
  700. + fprintf(stderr, "%s: ERROR: failed to rename %s to %s: %s\n",
  701. + __FUNCTION__, src, dest, strerror(errno));
  702. + }
  703. +
  704. + return err;
  705. +}
  706. +
  707. +/* I put these here to keep libbb dependencies from creeping all over
  708. + the ipkg code */
  709. +int file_copy(const char *src, const char *dest)
  710. +{
  711. + int err;
  712. +
  713. + err = copy_file(src, dest, FILEUTILS_FORCE | FILEUTILS_PRESERVE_STATUS);
  714. + if (err) {
  715. + fprintf(stderr, "%s: ERROR: failed to copy %s to %s\n",
  716. + __FUNCTION__, src, dest);
  717. + }
  718. +
  719. + return err;
  720. +}
  721. +
  722. +int file_mkdir_hier(char *path, long mode)
  723. +{
  724. + return bb_make_directory(path, mode, FILEUTILS_RECUR);
  725. +}
  726. +
  727. +uint8_t *file_md5sum_alloc(const char *file_name)
  728. +{
  729. + return hash_file(file_name, HASH_MD5);
  730. +}
  731. +
  732. diff -Nur busybox-1.12.1.orig/archival/libipkg/file_util.h busybox-1.12.1/archival/libipkg/file_util.h
  733. --- busybox-1.12.1.orig/archival/libipkg/file_util.h 1970-01-01 01:00:00.000000000 +0100
  734. +++ busybox-1.12.1/archival/libipkg/file_util.h 2008-10-23 12:30:58.000000000 +0200
  735. @@ -0,0 +1,29 @@
  736. +/* file_util.h - convenience routines for common file operations
  737. +
  738. + Carl D. Worth
  739. +
  740. + Copyright (C) 2001 University of Southern California
  741. +
  742. + This program is free software; you can redistribute it and/or
  743. + modify it under the terms of the GNU General Public License as
  744. + published by the Free Software Foundation; either version 2, or (at
  745. + your option) any later version.
  746. +
  747. + This program is distributed in the hope that it will be useful, but
  748. + WITHOUT ANY WARRANTY; without even the implied warranty of
  749. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  750. + General Public License for more details.
  751. +*/
  752. +
  753. +#ifndef FILE_UTIL_H
  754. +#define FILE_UTIL_H
  755. +
  756. +int file_exists(const char *file_name);
  757. +int file_is_dir(const char *file_name);
  758. +char *file_read_line_alloc(FILE *file);
  759. +int file_move(const char *src, const char *dest);
  760. +int file_copy(const char *src, const char *dest);
  761. +int file_mkdir_hier(char *path, long mode);
  762. +uint8_t *file_md5sum_alloc(const char *file_name);
  763. +
  764. +#endif
  765. diff -Nur busybox-1.12.1.orig/archival/libipkg/hash_table.c busybox-1.12.1/archival/libipkg/hash_table.c
  766. --- busybox-1.12.1.orig/archival/libipkg/hash_table.c 1970-01-01 01:00:00.000000000 +0100
  767. +++ busybox-1.12.1/archival/libipkg/hash_table.c 2008-10-23 16:12:57.000000000 +0200
  768. @@ -0,0 +1,155 @@
  769. +/* hash.c - hash tables for ipkg
  770. +
  771. + Steven M. Ayer, Jamey Hicks
  772. +
  773. + Copyright (C) 2002 Compaq Computer Corporation
  774. +
  775. + This program is free software; you can redistribute it and/or
  776. + modify it under the terms of the GNU General Public License as
  777. + published by the Free Software Foundation; either version 2, or (at
  778. + your option) any later version.
  779. +
  780. + This program is distributed in the hope that it will be useful, but
  781. + WITHOUT ANY WARRANTY; without even the implied warranty of
  782. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  783. + General Public License for more details.
  784. +*/
  785. +
  786. +#include <errno.h>
  787. +#include <stdio.h>
  788. +#include <stdlib.h>
  789. +#include <string.h>
  790. +#include "hash_table.h"
  791. +#include "ipkg_message.h"
  792. +
  793. +
  794. +static int hash_index(hash_table_t *hash, const char *pkg_name);
  795. +static int rotating(const char *key, int len, int prime);
  796. +
  797. +static int hash_index(hash_table_t *hash, const char *pkg_name)
  798. +{
  799. + return rotating(pkg_name, strlen(pkg_name), hash->n_entries);
  800. +}
  801. +
  802. +static int rotating(const char *key, int len, int prime)
  803. +{
  804. + unsigned int hash, i;
  805. + for (hash=len, i=0; i<len; ++i)
  806. + hash = (hash<<4)^(hash>>28)^key[i];
  807. + return (hash % prime);
  808. +}
  809. +
  810. +
  811. +/*
  812. + * this is an open table keyed by strings
  813. + */
  814. +int hash_table_init(const char *name, hash_table_t *hash, int len)
  815. +{
  816. + static int primes_table[] = {
  817. + 379, 761, 983, 1423, 2711, 3361, 3931, 4679, 5519, 6701, 9587,
  818. + 19471, 23143, 33961, 46499, 49727, 99529, 0
  819. + };
  820. + int *picker;
  821. +
  822. + if (hash->entries != NULL) {
  823. + /* we have been here already */
  824. + return 0;
  825. + }
  826. +
  827. + hash->name = name;
  828. + hash->entries = NULL;
  829. + hash->n_entries = 0;
  830. + hash->hash_entry_key = NULL;
  831. +
  832. + picker = primes_table;
  833. + while(*picker && (*picker++ < len));
  834. + if(!*picker)
  835. + fprintf(stderr, "%s: primes table might not be big enough (! << %d)\n", __FUNCTION__, len);
  836. + --picker;
  837. +
  838. + hash->n_entries = *picker;
  839. + hash->entries = (hash_entry_t *)calloc(hash->n_entries, sizeof(hash_entry_t));
  840. + if (hash->entries == NULL) {
  841. + fprintf(stderr, "%s: Out of memory.\n", __FUNCTION__);
  842. + return ENOMEM;
  843. + }
  844. + return 0;
  845. +}
  846. +
  847. +void hash_table_deinit(hash_table_t *hash)
  848. +{
  849. + free(hash->entries);
  850. + hash->entries = NULL;
  851. + hash->n_entries = 0;
  852. +}
  853. +
  854. +void *hash_table_get(hash_table_t *hash, const char *key)
  855. +{
  856. + int ndx= hash_index(hash, key);
  857. + hash_entry_t *hash_entry = hash->entries + ndx;
  858. + while (hash_entry)
  859. + {
  860. + if (hash_entry->key)
  861. + {
  862. + if (strcmp(key, hash_entry->key) == 0) {
  863. + // ipkg_message(NULL, IPKG_DEBUG, "Function: %s. Key found for '%s' \n", __FUNCTION__, key);
  864. + return hash_entry->data;
  865. + }
  866. + }
  867. + hash_entry = hash_entry->next;
  868. + }
  869. + return NULL;
  870. +}
  871. +
  872. +int hash_table_insert(hash_table_t *hash, const char *key, void *value)
  873. +{
  874. + int ndx= hash_index(hash, key);
  875. + hash_entry_t *hash_entry = hash->entries + ndx;
  876. + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Inserting in hash for '%s' \n", __FUNCTION__, key);
  877. + if (hash_entry->key) {
  878. + if (strcmp(hash_entry->key, key) == 0) {
  879. + /* alread in table, update the value */
  880. + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Value already in hash for '%s' \n", __FUNCTION__, key);
  881. + hash_entry->data = value;
  882. + return 0;
  883. + } else {
  884. + /*
  885. + * if this is a collision, we have to go to the end of the ll,
  886. + * then add a new entry
  887. + * before we can hook up the value
  888. + */
  889. + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Value already in hash by collision for '%s' \n", __FUNCTION__, key);
  890. + while (hash_entry->next)
  891. + hash_entry = hash_entry->next;
  892. + hash_entry->next = (hash_entry_t *)malloc(sizeof(hash_entry_t));
  893. + if (!hash_entry->next) {
  894. + return -ENOMEM;
  895. + }
  896. + hash_entry = hash_entry->next;
  897. + hash_entry->next = NULL;
  898. + }
  899. + }
  900. + hash->n_elements++;
  901. + hash_entry->key = strdup(key);
  902. + hash_entry->data = value;
  903. +
  904. + return 0;
  905. +}
  906. +
  907. +
  908. +void hash_table_foreach(hash_table_t *hash, void (*f)(const char *key, void *entry, void *data), void *data)
  909. +{
  910. + int i;
  911. + if (!hash || !f)
  912. + return;
  913. +
  914. + for (i = 0; i < hash->n_entries; i++) {
  915. + hash_entry_t *hash_entry = (hash->entries + i);
  916. + do {
  917. + if(hash_entry->key) {
  918. + f(hash_entry->key, hash_entry->data, data);
  919. + }
  920. + } while((hash_entry = hash_entry->next));
  921. + }
  922. +}
  923. +
  924. diff -Nur busybox-1.12.1.orig/archival/libipkg/hash_table.h busybox-1.12.1/archival/libipkg/hash_table.h
  925. --- busybox-1.12.1.orig/archival/libipkg/hash_table.h 1970-01-01 01:00:00.000000000 +0100
  926. +++ busybox-1.12.1/archival/libipkg/hash_table.h 2008-10-23 16:13:18.000000000 +0200
  927. @@ -0,0 +1,44 @@
  928. +/* hash.h - hash tables for ipkg
  929. +
  930. + Steven M. Ayer, Jamey Hicks
  931. +
  932. + Copyright (C) 2002 Compaq Computer Corporation
  933. +
  934. + This program is free software; you can redistribute it and/or
  935. + modify it under the terms of the GNU General Public License as
  936. + published by the Free Software Foundation; either version 2, or (at
  937. + your option) any later version.
  938. +
  939. + This program is distributed in the hope that it will be useful, but
  940. + WITHOUT ANY WARRANTY; without even the implied warranty of
  941. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  942. + General Public License for more details.
  943. +*/
  944. +
  945. +#ifndef _HASH_TABLE_H_
  946. +#define _HASH_TABLE_H_
  947. +
  948. +typedef struct hash_entry hash_entry_t;
  949. +typedef struct hash_table hash_table_t;
  950. +
  951. +struct hash_entry {
  952. + const char * key;
  953. + void * data;
  954. + struct hash_entry * next;
  955. +};
  956. +
  957. +struct hash_table {
  958. + const char *name;
  959. + hash_entry_t * entries;
  960. + int n_entries; /* number of buckets */
  961. + int n_elements;
  962. + const char * (*hash_entry_key)(void * data);
  963. +};
  964. +
  965. +int hash_table_init(const char *name, hash_table_t *hash, int len);
  966. +void hash_table_deinit(hash_table_t *hash);
  967. +void *hash_table_get(hash_table_t *hash, const char *key);
  968. +int hash_table_insert(hash_table_t *hash, const char *key, void *value);
  969. +void hash_table_foreach(hash_table_t *hash, void (*f)(const char *key, void *entry, void *data), void *data);
  970. +
  971. +#endif /* _HASH_TABLE_H_ */
  972. diff -Nur busybox-1.12.1.orig/archival/libipkg/ipkg_cmd.c busybox-1.12.1/archival/libipkg/ipkg_cmd.c
  973. --- busybox-1.12.1.orig/archival/libipkg/ipkg_cmd.c 1970-01-01 01:00:00.000000000 +0100
  974. +++ busybox-1.12.1/archival/libipkg/ipkg_cmd.c 2008-10-23 15:06:37.000000000 +0200
  975. @@ -0,0 +1,1433 @@
  976. +/* ipkg_cmd.c - the itsy package management system
  977. +
  978. + Carl D. Worth
  979. +
  980. + Copyright (C) 2001 University of Southern California
  981. +
  982. + This program is free software; you can redistribute it and/or
  983. + modify it under the terms of the GNU General Public License as
  984. + published by the Free Software Foundation; either version 2, or (at
  985. + your option) any later version.
  986. +
  987. + This program is distributed in the hope that it will be useful, but
  988. + WITHOUT ANY WARRANTY; without even the implied warranty of
  989. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  990. + General Public License for more details.
  991. +*/
  992. +
  993. +#include <string.h>
  994. +
  995. +#include "ipkg.h"
  996. +#include <libgen.h>
  997. +#include <glob.h>
  998. +#include <errno.h>
  999. +#include <stdlib.h>
  1000. +#include <unistd.h>
  1001. +#include <signal.h>
  1002. +#include <stdio.h>
  1003. +#include <dirent.h>
  1004. +
  1005. +#include "ipkg_conf.h"
  1006. +#include "ipkg_cmd.h"
  1007. +#include "ipkg_message.h"
  1008. +#include "pkg.h"
  1009. +#include "pkg_dest.h"
  1010. +#include "pkg_parse.h"
  1011. +#include "sprintf_alloc.h"
  1012. +#include "pkg.h"
  1013. +#include "file_util.h"
  1014. +#include "str_util.h"
  1015. +#include "unarchive.h"
  1016. +
  1017. +#include <fnmatch.h>
  1018. +
  1019. +
  1020. +#include "ipkg_download.h"
  1021. +#include "ipkg_install.h"
  1022. +#include "ipkg_upgrade.h"
  1023. +#include "ipkg_remove.h"
  1024. +#include "ipkg_configure.h"
  1025. +#include "ipkg_message.h"
  1026. +
  1027. +#ifdef IPKG_LIB
  1028. +#include "libipkg.h"
  1029. +static void *p_userdata = NULL;
  1030. +#endif
  1031. +
  1032. +static int ipkg_update_cmd(ipkg_conf_t *conf);
  1033. +static int ipkg_upgrade_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1034. +static int ipkg_list_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1035. +static int ipkg_info_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1036. +static int ipkg_status_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1037. +static int ipkg_install_pending_cmd(ipkg_conf_t *conf);
  1038. +static int ipkg_install_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1039. +static int ipkg_list_installed_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1040. +static int ipkg_remove_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1041. +static int ipkg_purge_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1042. +static int ipkg_flag_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1043. +static int ipkg_files_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1044. +static int ipkg_search_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1045. +static int ipkg_download_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1046. +static int ipkg_depends_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1047. +static int ipkg_whatdepends_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1048. +static int ipkg_whatdepends_recursively_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1049. +static int ipkg_whatsuggests_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1050. +static int ipkg_whatrecommends_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1051. +static int ipkg_whatprovides_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1052. +static int ipkg_whatconflicts_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1053. +static int ipkg_whatreplaces_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1054. +static int ipkg_compare_versions_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1055. +static int ipkg_print_architecture_cmd(ipkg_conf_t *conf);
  1056. +static int ipkg_configure_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1057. +
  1058. +/* XXX: CLEANUP: The usage strings should be incorporated into this
  1059. + array for easier maintenance */
  1060. +static ipkg_cmd_t cmds[] = {
  1061. + {"update", 0, (ipkg_cmd_fun_t)ipkg_update_cmd},
  1062. + {"upgrade", 0, (ipkg_cmd_fun_t)ipkg_upgrade_cmd},
  1063. + {"list", 0, (ipkg_cmd_fun_t)ipkg_list_cmd},
  1064. + {"list_installed", 0, (ipkg_cmd_fun_t)ipkg_list_installed_cmd},
  1065. + {"info", 0, (ipkg_cmd_fun_t)ipkg_info_cmd},
  1066. + {"flag", 1, (ipkg_cmd_fun_t)ipkg_flag_cmd},
  1067. + {"status", 0, (ipkg_cmd_fun_t)ipkg_status_cmd},
  1068. + {"install_pending", 0, (ipkg_cmd_fun_t)ipkg_install_pending_cmd},
  1069. + {"install", 1, (ipkg_cmd_fun_t)ipkg_install_cmd},
  1070. + {"remove", 1, (ipkg_cmd_fun_t)ipkg_remove_cmd},
  1071. + {"purge", 1, (ipkg_cmd_fun_t)ipkg_purge_cmd},
  1072. + {"configure", 0, (ipkg_cmd_fun_t)ipkg_configure_cmd},
  1073. + {"files", 1, (ipkg_cmd_fun_t)ipkg_files_cmd},
  1074. + {"search", 1, (ipkg_cmd_fun_t)ipkg_search_cmd},
  1075. + {"download", 1, (ipkg_cmd_fun_t)ipkg_download_cmd},
  1076. + {"compare_versions", 1, (ipkg_cmd_fun_t)ipkg_compare_versions_cmd},
  1077. + {"compare-versions", 1, (ipkg_cmd_fun_t)ipkg_compare_versions_cmd},
  1078. + {"print-architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
  1079. + {"print_architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
  1080. + {"print-installation-architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
  1081. + {"print_installation_architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
  1082. + {"depends", 1, (ipkg_cmd_fun_t)ipkg_depends_cmd},
  1083. + {"whatdepends", 1, (ipkg_cmd_fun_t)ipkg_whatdepends_cmd},
  1084. + {"whatdependsrec", 1, (ipkg_cmd_fun_t)ipkg_whatdepends_recursively_cmd},
  1085. + {"whatrecommends", 1, (ipkg_cmd_fun_t)ipkg_whatrecommends_cmd},
  1086. + {"whatsuggests", 1, (ipkg_cmd_fun_t)ipkg_whatsuggests_cmd},
  1087. + {"whatprovides", 1, (ipkg_cmd_fun_t)ipkg_whatprovides_cmd},
  1088. + {"whatreplaces", 1, (ipkg_cmd_fun_t)ipkg_whatreplaces_cmd},
  1089. + {"whatconflicts", 1, (ipkg_cmd_fun_t)ipkg_whatconflicts_cmd},
  1090. +};
  1091. +
  1092. +int ipkg_state_changed;
  1093. +static void write_status_files_if_changed(ipkg_conf_t *conf)
  1094. +{
  1095. + if (ipkg_state_changed && !conf->noaction) {
  1096. + ipkg_message(conf, IPKG_INFO,
  1097. + " writing status file\n");
  1098. + ipkg_conf_write_status_files(conf);
  1099. + pkg_write_changed_filelists(conf);
  1100. + } else {
  1101. + ipkg_message(conf, IPKG_NOTICE, "Nothing to be done\n");
  1102. + }
  1103. +}
  1104. +
  1105. +
  1106. +static int num_cmds = sizeof(cmds) / sizeof(ipkg_cmd_t);
  1107. +
  1108. +ipkg_cmd_t *ipkg_cmd_find(const char *name)
  1109. +{
  1110. + int i;
  1111. + ipkg_cmd_t *cmd;
  1112. +
  1113. + for (i=0; i < num_cmds; i++) {
  1114. + cmd = &cmds[i];
  1115. + if (strcmp(name, cmd->name) == 0) {
  1116. + return cmd;
  1117. + }
  1118. + }
  1119. +
  1120. + return NULL;
  1121. +}
  1122. +
  1123. +#ifdef IPKG_LIB
  1124. +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc, const char **argv, void *userdata)
  1125. +{
  1126. + int result;
  1127. + p_userdata = userdata;
  1128. +
  1129. +
  1130. + result = (cmd->fun)(conf, argc, argv);
  1131. + if ( result == 0 ) {
  1132. + ipkg_message(conf, IPKG_NOTICE, "Done.\n");
  1133. + } else {
  1134. + ipkg_message(conf, IPKG_NOTICE, "An error ocurred, return value: %d.\n", result);
  1135. +
  1136. + }
  1137. + if ( error_list ) {
  1138. + reverse_error_list(&error_list);
  1139. +
  1140. + ipkg_message(conf, IPKG_NOTICE, "Collected errors:\n");
  1141. + /* Here we print the errors collected and free the list */
  1142. + while (error_list != NULL) {
  1143. + ipkg_message(conf, IPKG_NOTICE, "%s",error_list->errmsg);
  1144. + error_list = error_list->next;
  1145. +
  1146. + }
  1147. + free_error_list(&error_list);
  1148. +
  1149. + }
  1150. +
  1151. + p_userdata = NULL;
  1152. + return result;
  1153. +}
  1154. +#else
  1155. +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc, const char **argv)
  1156. +{
  1157. + return (cmd->fun)(conf, argc, argv);
  1158. +}
  1159. +#endif
  1160. +
  1161. +static int ipkg_update_cmd(ipkg_conf_t *conf)
  1162. +{
  1163. + int err;
  1164. + int failures;
  1165. + char *lists_dir;
  1166. + pkg_src_list_elt_t *iter;
  1167. + pkg_src_t *src;
  1168. +
  1169. +
  1170. + sprintf_alloc(&lists_dir, "%s", conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir);
  1171. +
  1172. + if (! file_is_dir(lists_dir)) {
  1173. + if (file_exists(lists_dir)) {
  1174. + ipkg_message(conf, IPKG_ERROR,
  1175. + "%s: ERROR: %s exists, but is not a directory\n",
  1176. + __FUNCTION__, lists_dir);
  1177. + free(lists_dir);
  1178. + return EINVAL;
  1179. + }
  1180. + err = file_mkdir_hier(lists_dir, 0755);
  1181. + if (err) {
  1182. + ipkg_message(conf, IPKG_ERROR,
  1183. + "%s: ERROR: failed to make directory %s: %s\n",
  1184. + __FUNCTION__, lists_dir, strerror(errno));
  1185. + free(lists_dir);
  1186. + return EINVAL;
  1187. + }
  1188. + }
  1189. +
  1190. + failures = 0;
  1191. + for (iter = conf->pkg_src_list.head; iter; iter = iter->next) {
  1192. + char *url, *list_file_name;
  1193. +
  1194. + src = iter->data;
  1195. +
  1196. + if (src->extra_data) /* debian style? */
  1197. + sprintf_alloc(&url, "%s/%s/%s", src->value, src->extra_data,
  1198. + src->gzip ? "Packages.gz" : "Packages");
  1199. + else
  1200. + sprintf_alloc(&url, "%s/%s", src->value, src->gzip ? "Packages.gz" : "Packages");
  1201. +
  1202. + sprintf_alloc(&list_file_name, "%s/%s", lists_dir, src->name);
  1203. + if (src->gzip) {
  1204. + char *tmp;
  1205. + char *tmp_file_name;
  1206. + FILE *in, *out;
  1207. +
  1208. + tmp = strdup ("/tmp/ipkg.XXXXXX");
  1209. +
  1210. + if (mkdtemp (tmp) == NULL) {
  1211. + perror ("mkdtemp");
  1212. + failures++;
  1213. + continue;
  1214. + }
  1215. +
  1216. + sprintf_alloc (&tmp_file_name, "%s/%s.gz", tmp, src->name);
  1217. + err = ipkg_download(conf, url, tmp_file_name);
  1218. + if (err == 0) {
  1219. + ipkg_message (conf, IPKG_NOTICE, "Inflating %s\n", url);
  1220. + in = fopen (tmp_file_name, "r");
  1221. + out = fopen (list_file_name, "w");
  1222. + if (in && out) {
  1223. + inflate_unzip_result res;
  1224. + inflate_unzip (&res, 0x8000, fileno(in), fileno(out));
  1225. + } else
  1226. + err = 1;
  1227. + if (in)
  1228. + fclose (in);
  1229. + if (out)
  1230. + fclose (out);
  1231. + unlink (tmp_file_name);
  1232. + rmdir (tmp);
  1233. + free (tmp);
  1234. + }
  1235. + } else
  1236. + err = ipkg_download(conf, url, list_file_name);
  1237. + if (err) {
  1238. + failures++;
  1239. + } else {
  1240. + ipkg_message(conf, IPKG_NOTICE,
  1241. + "Updated list of available packages in %s\n",
  1242. + list_file_name);
  1243. + }
  1244. + free(url);
  1245. + free(list_file_name);
  1246. + }
  1247. + free(lists_dir);
  1248. +
  1249. +#ifdef CONFIG_CLEAR_SW_INSTALL_FLAG
  1250. +#warning here
  1251. + /* clear SW_INSTALL on any package where state is SS_NOT_INSTALLED.
  1252. + * this is a hack to work around poor bookkeeping in old ipkg upgrade code
  1253. + * -Jamey 3/1/03
  1254. + */
  1255. + {
  1256. + int i;
  1257. + int changed = 0;
  1258. + pkg_vec_t *available = pkg_vec_alloc();
  1259. + pkg_hash_fetch_available(&conf->pkg_hash, available);
  1260. + ipkg_message(conf, IPKG_DEBUG, "Clearing SW_INSTALL for SS_NOT_INSTALLED packages.\n");
  1261. + for (i = 0; i < available->len; i++) {
  1262. + pkg_t *pkg = available->pkgs[i];
  1263. + if (pkg->state_want == SW_INSTALL && pkg->state_status == SS_NOT_INSTALLED) {
  1264. + ipkg_message(conf, IPKG_DEBUG, "Clearing SW_INSTALL on package %s.\n", pkg->name);
  1265. + pkg->state_want = SW_UNKNOWN;
  1266. + changed = 1;
  1267. + }
  1268. + }
  1269. + pkg_vec_free(available);
  1270. + if (changed) {
  1271. + write_status_files_if_changed(conf);
  1272. + }
  1273. + }
  1274. +#endif
  1275. +
  1276. + return failures;
  1277. +}
  1278. +
  1279. +
  1280. +/* scan the args passed and cache the local filenames of the packages */
  1281. +int ipkg_multiple_files_scan(ipkg_conf_t *conf, int argc, char **argv)
  1282. +{
  1283. + int i;
  1284. + int err;
  1285. +
  1286. + /*
  1287. + * First scan through package names/urls
  1288. + * For any urls, download the packages and install in database.
  1289. + * For any files, install package info in database.
  1290. + */
  1291. + for (i = 0; i < argc; i ++) {
  1292. + char *filename = argv [i];
  1293. + //char *tmp = basename (tmp);
  1294. + //int tmplen = strlen (tmp);
  1295. +
  1296. + //if (strcmp (tmp + (tmplen - strlen (IPKG_PKG_EXTENSION)), IPKG_PKG_EXTENSION) != 0)
  1297. + // continue;
  1298. + //if (strcmp (tmp + (tmplen - strlen (DPKG_PKG_EXTENSION)), DPKG_PKG_EXTENSION) != 0)
  1299. + // continue;
  1300. +
  1301. + ipkg_message(conf, IPKG_DEBUG2, "Debug mfs: %s \n",filename );
  1302. +
  1303. + err = ipkg_prepare_url_for_install(conf, filename, &argv[i]);
  1304. + if (err)
  1305. + return err;
  1306. + }
  1307. + return 0;
  1308. +}
  1309. +
  1310. +struct ipkg_intercept
  1311. +{
  1312. + char *oldpath;
  1313. + char *statedir;
  1314. +};
  1315. +
  1316. +typedef struct ipkg_intercept *ipkg_intercept_t;
  1317. +ipkg_intercept_t ipkg_prep_intercepts(void);
  1318. +
  1319. +ipkg_intercept_t ipkg_prep_intercepts(void)
  1320. +{
  1321. + ipkg_intercept_t ctx;
  1322. + char *newpath;
  1323. + int gen;
  1324. +
  1325. + ctx = malloc (sizeof (*ctx));
  1326. + ctx->oldpath = strdup (getenv ("PATH"));
  1327. +
  1328. + sprintf_alloc (&newpath, "%s/ipkg/intercept:%s", IPKGLIBDIR, ctx->oldpath);
  1329. + setenv ("PATH", newpath, 1);
  1330. + free (newpath);
  1331. +
  1332. + gen = 0;
  1333. + retry:
  1334. + sprintf_alloc (&ctx->statedir, "/tmp/ipkg-intercept-%d-%d", getpid (), gen);
  1335. + if (mkdir (ctx->statedir, 0770) < 0) {
  1336. + if (errno == EEXIST) {
  1337. + free (ctx->statedir);
  1338. + gen++;
  1339. + goto retry;
  1340. + }
  1341. + perror (ctx->statedir);
  1342. + return NULL;
  1343. + }
  1344. + setenv ("IPKG_INTERCEPT_DIR", ctx->statedir, 1);
  1345. + return ctx;
  1346. +}
  1347. +
  1348. +int ipkg_finalize_intercepts(ipkg_intercept_t ctx);
  1349. +
  1350. +int ipkg_finalize_intercepts(ipkg_intercept_t ctx)
  1351. +{
  1352. + char *cmd;
  1353. + DIR *dir;
  1354. + int err = 0;
  1355. +
  1356. + setenv ("PATH", ctx->oldpath, 1);
  1357. + free (ctx->oldpath);
  1358. +
  1359. + dir = opendir (ctx->statedir);
  1360. + if (dir) {
  1361. + struct dirent *de;
  1362. + while (de = readdir (dir), de != NULL) {
  1363. + char *path;
  1364. +
  1365. + if (de->d_name[0] == '.')
  1366. + continue;
  1367. +
  1368. + sprintf_alloc (&path, "%s/%s", ctx->statedir, de->d_name);
  1369. + if (access (path, X_OK) == 0) {
  1370. + if (system (path)) {
  1371. + err = errno;
  1372. + perror (de->d_name);
  1373. + }
  1374. + }
  1375. + free (path);
  1376. + }
  1377. + } else
  1378. + perror (ctx->statedir);
  1379. +
  1380. + sprintf_alloc (&cmd, "rm -rf %s", ctx->statedir);
  1381. + system (cmd);
  1382. + free (cmd);
  1383. +
  1384. + free (ctx->statedir);
  1385. + free (ctx);
  1386. +
  1387. + return err;
  1388. +}
  1389. +
  1390. +int ipkg_configure_packages(ipkg_conf_t *conf, char *pkg_name)
  1391. +{
  1392. + pkg_vec_t *all;
  1393. + int i;
  1394. + pkg_t *pkg;
  1395. + ipkg_intercept_t ic;
  1396. + int r, err = 0;
  1397. +
  1398. + ipkg_message(conf, IPKG_INFO,
  1399. + "Configuring unpacked packages\n");
  1400. + fflush( stdout );
  1401. +
  1402. + all = pkg_vec_alloc();
  1403. + pkg_hash_fetch_available(&conf->pkg_hash, all);
  1404. +
  1405. + ic = ipkg_prep_intercepts();
  1406. +
  1407. + for(i = 0; i < all->len; i++) {
  1408. + pkg = all->pkgs[i];
  1409. +
  1410. + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
  1411. + continue;
  1412. +
  1413. + if (pkg->state_status == SS_UNPACKED) {
  1414. + ipkg_message(conf, IPKG_NOTICE,
  1415. + "Configuring %s\n", pkg->name);
  1416. + fflush( stdout );
  1417. + r = ipkg_configure(conf, pkg);
  1418. + if (r == 0) {
  1419. + pkg->state_status = SS_INSTALLED;
  1420. + pkg->parent->state_status = SS_INSTALLED;
  1421. + pkg->state_flag &= ~SF_PREFER;
  1422. + } else {
  1423. + if (!err)
  1424. + err = r;
  1425. + }
  1426. + }
  1427. + }
  1428. +
  1429. + r = ipkg_finalize_intercepts (ic);
  1430. + if (r && !err)
  1431. + err = r;
  1432. +
  1433. + pkg_vec_free(all);
  1434. + return err;
  1435. +}
  1436. +
  1437. +static void sigint_handler(int sig)
  1438. +{
  1439. + signal(sig, SIG_DFL);
  1440. + ipkg_message(NULL, IPKG_NOTICE,
  1441. + "ipkg: interrupted. writing out status database\n");
  1442. + write_status_files_if_changed(global_conf);
  1443. + exit(128 + sig);
  1444. +}
  1445. +
  1446. +static int ipkg_install_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1447. +{
  1448. + int i;
  1449. + char *arg;
  1450. + int err=0;
  1451. +
  1452. + global_conf = conf;
  1453. + signal(SIGINT, sigint_handler);
  1454. +
  1455. + /*
  1456. + * Now scan through package names and install
  1457. + */
  1458. + for (i=0; i < argc; i++) {
  1459. + arg = argv[i];
  1460. +
  1461. + ipkg_message(conf, IPKG_DEBUG2, "Debug install_cmd: %s \n",arg );
  1462. + err = ipkg_prepare_url_for_install(conf, arg, &argv[i]);
  1463. + if (err != EINVAL && err != 0)
  1464. + return err;
  1465. + }
  1466. + pkg_info_preinstall_check(conf);
  1467. +
  1468. + for (i=0; i < argc; i++) {
  1469. + arg = argv[i];
  1470. + if (conf->multiple_providers)
  1471. + err = ipkg_install_multi_by_name(conf, arg);
  1472. + else{
  1473. + err = ipkg_install_by_name(conf, arg);
  1474. + }
  1475. + if (err == IPKG_PKG_HAS_NO_CANDIDATE) {
  1476. + ipkg_message(conf, IPKG_ERROR,
  1477. + "Cannot find package %s.\n"
  1478. + "Check the spelling or perhaps run 'ipkg update'\n",
  1479. + arg);
  1480. + }
  1481. + }
  1482. +
  1483. + /* recheck to verify that all dependences are satisfied */
  1484. + if (0) ipkg_satisfy_all_dependences(conf);
  1485. +
  1486. + ipkg_configure_packages(conf, NULL);
  1487. +
  1488. + write_status_files_if_changed(conf);
  1489. +
  1490. + return err;
  1491. +}
  1492. +
  1493. +static int ipkg_upgrade_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1494. +{
  1495. + int i;
  1496. + pkg_t *pkg;
  1497. + int err;
  1498. +
  1499. + global_conf = conf;
  1500. + signal(SIGINT, sigint_handler);
  1501. +
  1502. + if (argc) {
  1503. + for (i=0; i < argc; i++) {
  1504. + char *arg = argv[i];
  1505. +
  1506. + err = ipkg_prepare_url_for_install(conf, arg, &arg);
  1507. + if (err != EINVAL && err != 0)
  1508. + return err;
  1509. + }
  1510. + pkg_info_preinstall_check(conf);
  1511. +
  1512. + for (i=0; i < argc; i++) {
  1513. + char *arg = argv[i];
  1514. + if (conf->restrict_to_default_dest) {
  1515. + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
  1516. + argv[i],
  1517. + conf->default_dest);
  1518. + if (pkg == NULL) {
  1519. + ipkg_message(conf, IPKG_NOTICE,
  1520. + "Package %s not installed in %s\n",
  1521. + argv[i], conf->default_dest->name);
  1522. + continue;
  1523. + }
  1524. + } else {
  1525. + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash,
  1526. + argv[i]);
  1527. + }
  1528. + if (pkg)
  1529. + ipkg_upgrade_pkg(conf, pkg);
  1530. + else {
  1531. + ipkg_install_by_name(conf, arg);
  1532. + }
  1533. + }
  1534. + } else {
  1535. + pkg_vec_t *installed = pkg_vec_alloc();
  1536. +
  1537. + pkg_info_preinstall_check(conf);
  1538. +
  1539. + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
  1540. + for (i = 0; i < installed->len; i++) {
  1541. + pkg = installed->pkgs[i];
  1542. + ipkg_upgrade_pkg(conf, pkg);
  1543. + }
  1544. + pkg_vec_free(installed);
  1545. + }
  1546. +
  1547. + /* recheck to verify that all dependences are satisfied */
  1548. + if (0) ipkg_satisfy_all_dependences(conf);
  1549. +
  1550. + ipkg_configure_packages(conf, NULL);
  1551. +
  1552. + write_status_files_if_changed(conf);
  1553. +
  1554. + return 0;
  1555. +}
  1556. +
  1557. +static int ipkg_download_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1558. +{
  1559. + int i, err;
  1560. + char *arg;
  1561. + pkg_t *pkg;
  1562. +
  1563. + pkg_info_preinstall_check(conf);
  1564. + for (i = 0; i < argc; i++) {
  1565. + arg = argv[i];
  1566. +
  1567. + pkg = pkg_hash_fetch_best_installation_candidate_by_name(conf, arg);
  1568. + if (pkg == NULL) {
  1569. + ipkg_message(conf, IPKG_ERROR,
  1570. + "Cannot find package %s.\n"
  1571. + "Check the spelling or perhaps run 'ipkg update'\n",
  1572. + arg);
  1573. + continue;
  1574. + }
  1575. +
  1576. + err = ipkg_download_pkg(conf, pkg, ".");
  1577. +
  1578. + if (err) {
  1579. + ipkg_message(conf, IPKG_ERROR,
  1580. + "Failed to download %s\n", pkg->name);
  1581. + } else {
  1582. + ipkg_message(conf, IPKG_NOTICE,
  1583. + "Downloaded %s as %s\n",
  1584. + pkg->name, pkg->local_filename);
  1585. + }
  1586. + }
  1587. +
  1588. + return 0;
  1589. +}
  1590. +
  1591. +
  1592. +static int ipkg_list_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1593. +{
  1594. + int i ;
  1595. + pkg_vec_t *available;
  1596. + pkg_t *pkg;
  1597. + char desc_short[IPKG_LIST_DESCRIPTION_LENGTH];
  1598. + char *newline;
  1599. + char *pkg_name = NULL;
  1600. + char *version_str;
  1601. +
  1602. + if (argc > 0) {
  1603. + pkg_name = argv[0];
  1604. + }
  1605. + available = pkg_vec_alloc();
  1606. + pkg_hash_fetch_available(&conf->pkg_hash, available);
  1607. + for (i=0; i < available->len; i++) {
  1608. + pkg = available->pkgs[i];
  1609. + /* if we have package name or pattern and pkg does not match, then skip it */
  1610. + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
  1611. + continue;
  1612. + if (pkg->description) {
  1613. + strncpy(desc_short, pkg->description, IPKG_LIST_DESCRIPTION_LENGTH);
  1614. + } else {
  1615. + desc_short[0] = '\0';
  1616. + }
  1617. + desc_short[IPKG_LIST_DESCRIPTION_LENGTH - 1] = '\0';
  1618. + newline = strchr(desc_short, '\n');
  1619. + if (newline) {
  1620. + *newline = '\0';
  1621. + }
  1622. +#ifndef IPKG_LIB
  1623. + printf("%s - %s\n", pkg->name, desc_short);
  1624. +#else
  1625. + if (ipkg_cb_list) {
  1626. + version_str = pkg_version_str_alloc(pkg);
  1627. + ipkg_cb_list(pkg->name,desc_short,
  1628. + version_str,
  1629. + pkg->state_status,
  1630. + p_userdata);
  1631. + free(version_str);
  1632. + }
  1633. +#endif
  1634. + }
  1635. + pkg_vec_free(available);
  1636. +
  1637. + return 0;
  1638. +}
  1639. +
  1640. +
  1641. +static int ipkg_list_installed_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1642. +{
  1643. + int i ;
  1644. + pkg_vec_t *available;
  1645. + pkg_t *pkg;
  1646. + char desc_short[IPKG_LIST_DESCRIPTION_LENGTH];
  1647. + char *newline;
  1648. + char *pkg_name = NULL;
  1649. + char *version_str;
  1650. +
  1651. + if (argc > 0) {
  1652. + pkg_name = argv[0];
  1653. + }
  1654. + available = pkg_vec_alloc();
  1655. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
  1656. + for (i=0; i < available->len; i++) {
  1657. + pkg = available->pkgs[i];
  1658. + /* if we have package name or pattern and pkg does not match, then skip it */
  1659. + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
  1660. + continue;
  1661. + if (pkg->description) {
  1662. + strncpy(desc_short, pkg->description, IPKG_LIST_DESCRIPTION_LENGTH);
  1663. + } else {
  1664. + desc_short[0] = '\0';
  1665. + }
  1666. + desc_short[IPKG_LIST_DESCRIPTION_LENGTH - 1] = '\0';
  1667. + newline = strchr(desc_short, '\n');
  1668. + if (newline) {
  1669. + *newline = '\0';
  1670. + }
  1671. +#ifndef IPKG_LIB
  1672. + printf("%s - %s\n", pkg->name, desc_short);
  1673. +#else
  1674. + if (ipkg_cb_list) {
  1675. + version_str = pkg_version_str_alloc(pkg);
  1676. + ipkg_cb_list(pkg->name,desc_short,
  1677. + version_str,
  1678. + pkg->state_status,
  1679. + p_userdata);
  1680. + free(version_str);
  1681. + }
  1682. +#endif
  1683. + }
  1684. +
  1685. + return 0;
  1686. +}
  1687. +
  1688. +static int ipkg_info_status_cmd(ipkg_conf_t *conf, int argc, char **argv, int installed_only)
  1689. +{
  1690. + int i;
  1691. + pkg_vec_t *available;
  1692. + pkg_t *pkg;
  1693. + char *pkg_name = NULL;
  1694. + char **pkg_fields = NULL;
  1695. + int n_fields = 0;
  1696. + char *buff ; // = (char *)malloc(1);
  1697. +
  1698. + if (argc > 0) {
  1699. + pkg_name = argv[0];
  1700. + }
  1701. + if (argc > 1) {
  1702. + pkg_fields = &argv[1];
  1703. + n_fields = argc - 1;
  1704. + }
  1705. +
  1706. + available = pkg_vec_alloc();
  1707. + if (installed_only)
  1708. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
  1709. + else
  1710. + pkg_hash_fetch_available(&conf->pkg_hash, available);
  1711. + for (i=0; i < available->len; i++) {
  1712. + pkg = available->pkgs[i];
  1713. + if (pkg_name && fnmatch(pkg_name, pkg->name, 0)) {
  1714. + continue;
  1715. + }
  1716. +#ifndef IPKG_LIB
  1717. + if (n_fields) {
  1718. + for (j = 0; j < n_fields; j++)
  1719. + pkg_print_field(pkg, stdout, pkg_fields[j]);
  1720. + } else {
  1721. + pkg_print_info(pkg, stdout);
  1722. + }
  1723. +#else
  1724. +
  1725. + buff = pkg_formatted_info(pkg);
  1726. + if ( buff ) {
  1727. + if (ipkg_cb_status) ipkg_cb_status(pkg->name,
  1728. + pkg->state_status,
  1729. + buff,
  1730. + p_userdata);
  1731. +/*
  1732. + We should not forget that actually the pointer is allocated.
  1733. + We need to free it :) ( Thanks florian for seeing the error )
  1734. +*/
  1735. + free(buff);
  1736. + }
  1737. +#endif
  1738. + if (conf->verbosity > 1) {
  1739. + conffile_list_elt_t *iter;
  1740. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  1741. + conffile_t *cf = iter->data;
  1742. + int modified = conffile_has_been_modified(conf, cf);
  1743. + ipkg_message(conf, IPKG_NOTICE, "conffile=%s md5sum=%s modified=%d\n",
  1744. + cf->name, cf->value, modified);
  1745. + }
  1746. + }
  1747. + }
  1748. +#ifndef IPKG_LIB
  1749. + if (buff)
  1750. + free(buff);
  1751. +#endif
  1752. + pkg_vec_free(available);
  1753. +
  1754. + return 0;
  1755. +}
  1756. +
  1757. +static int ipkg_info_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1758. +{
  1759. + return ipkg_info_status_cmd(conf, argc, argv, 0);
  1760. +}
  1761. +
  1762. +static int ipkg_status_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1763. +{
  1764. + return ipkg_info_status_cmd(conf, argc, argv, 1);
  1765. +}
  1766. +
  1767. +static int ipkg_configure_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1768. +{
  1769. +
  1770. + int err;
  1771. + if (argc > 0) {
  1772. + char *pkg_name = NULL;
  1773. +
  1774. + pkg_name = argv[0];
  1775. +
  1776. + err = ipkg_configure_packages (conf, pkg_name);
  1777. +
  1778. + } else {
  1779. + err = ipkg_configure_packages (conf, NULL);
  1780. + }
  1781. +
  1782. + write_status_files_if_changed(conf);
  1783. +
  1784. + return err;
  1785. +}
  1786. +
  1787. +static int ipkg_install_pending_cmd(ipkg_conf_t *conf)
  1788. +{
  1789. + int i, err;
  1790. + char *globpattern;
  1791. + glob_t globbuf;
  1792. +
  1793. + sprintf_alloc(&globpattern, "%s/*" IPKG_PKG_EXTENSION, conf->pending_dir);
  1794. + err = glob(globpattern, 0, NULL, &globbuf);
  1795. + free(globpattern);
  1796. + if (err) {
  1797. + return 0;
  1798. + }
  1799. +
  1800. + ipkg_message(conf, IPKG_NOTICE,
  1801. + "The following packages in %s will now be installed.\n",
  1802. + conf->pending_dir);
  1803. + for (i = 0; i < globbuf.gl_pathc; i++) {
  1804. + ipkg_message(conf, IPKG_NOTICE,
  1805. + "%s%s", i == 0 ? "" : " ", globbuf.gl_pathv[i]);
  1806. + }
  1807. + ipkg_message(conf, IPKG_NOTICE, "\n");
  1808. + for (i = 0; i < globbuf.gl_pathc; i++) {
  1809. + err = ipkg_install_from_file(conf, globbuf.gl_pathv[i]);
  1810. + if (err == 0) {
  1811. + err = unlink(globbuf.gl_pathv[i]);
  1812. + if (err) {
  1813. + ipkg_message(conf, IPKG_ERROR,
  1814. + "%s: ERROR: failed to unlink %s: %s\n",
  1815. + __FUNCTION__, globbuf.gl_pathv[i], strerror(err));
  1816. + return err;
  1817. + }
  1818. + }
  1819. + }
  1820. + globfree(&globbuf);
  1821. +
  1822. + return err;
  1823. +}
  1824. +
  1825. +static int ipkg_remove_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1826. +{
  1827. + int i,a,done;
  1828. + pkg_t *pkg;
  1829. + pkg_t *pkg_to_remove;
  1830. + pkg_vec_t *available;
  1831. + char *pkg_name = NULL;
  1832. + global_conf = conf;
  1833. + signal(SIGINT, sigint_handler);
  1834. +
  1835. +// ENH: Add the "no pkg removed" just in case.
  1836. +
  1837. + done = 0;
  1838. +
  1839. + available = pkg_vec_alloc();
  1840. + pkg_info_preinstall_check(conf);
  1841. + if ( argc > 0 ) {
  1842. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
  1843. + for (i=0; i < argc; i++) {
  1844. + pkg_name = malloc(strlen(argv[i])+2);
  1845. + strcpy(pkg_name,argv[i]);
  1846. + for (a=0; a < available->len; a++) {
  1847. + pkg = available->pkgs[a];
  1848. + if (pkg_name && fnmatch(pkg_name, pkg->name, 0)) {
  1849. + continue;
  1850. + }
  1851. + if (conf->restrict_to_default_dest) {
  1852. + pkg_to_remove = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
  1853. + pkg->name,
  1854. + conf->default_dest);
  1855. + } else {
  1856. + pkg_to_remove = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name );
  1857. + }
  1858. +
  1859. + if (pkg == NULL) {
  1860. + ipkg_message(conf, IPKG_ERROR, "Package %s is not installed.\n", pkg->name);
  1861. + continue;
  1862. + }
  1863. + if (pkg->state_status == SS_NOT_INSTALLED) { // Added the control, so every already removed package could be skipped
  1864. + ipkg_message(conf, IPKG_ERROR, "Package seems to be %s not installed (STATUS = NOT_INSTALLED).\n", pkg->name);
  1865. + continue;
  1866. + }
  1867. + ipkg_remove_pkg(conf, pkg_to_remove,0);
  1868. + done = 1;
  1869. + }
  1870. + free (pkg_name);
  1871. + }
  1872. + pkg_vec_free(available);
  1873. + } else {
  1874. + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
  1875. + int flagged_pkg_count = 0;
  1876. + int removed;
  1877. +
  1878. + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed_pkgs);
  1879. +
  1880. + for (i = 0; i < installed_pkgs->len; i++) {
  1881. + pkg = installed_pkgs->pkgs[i];
  1882. + if (pkg->state_flag & SF_USER) {
  1883. + flagged_pkg_count++;
  1884. + } else {
  1885. + if (!pkg_has_installed_dependents(pkg, NULL))
  1886. + ipkg_message(conf, IPKG_NOTICE, "Non-user leaf package: %s\n", pkg->name);
  1887. + }
  1888. + }
  1889. + if (!flagged_pkg_count) {
  1890. + ipkg_message(conf, IPKG_NOTICE, "No packages flagged as installed by user, \n"
  1891. + "so refusing to uninstall unflagged non-leaf packages\n");
  1892. + return 0;
  1893. + }
  1894. +
  1895. + /* find packages not flagged SF_USER (i.e., installed to
  1896. + * satisfy a dependence) and not having any dependents, and
  1897. + * remove them */
  1898. + do {
  1899. + removed = 0;
  1900. + for (i = 0; i < installed_pkgs->len; i++) {
  1901. + pkg = installed_pkgs->pkgs[i];
  1902. + if (!(pkg->state_flag & SF_USER)
  1903. + && !pkg_has_installed_dependents(pkg, NULL)) {
  1904. + removed++;
  1905. + ipkg_message(conf, IPKG_NOTICE, "Removing non-user leaf package %s\n");
  1906. + ipkg_remove_pkg(conf, pkg,0);
  1907. + done = 1;
  1908. + }
  1909. + }
  1910. + } while (removed);
  1911. + pkg_vec_free(installed_pkgs);
  1912. + }
  1913. +
  1914. + if ( done == 0 )
  1915. + ipkg_message(conf, IPKG_NOTICE, "No packages removed.\n");
  1916. +
  1917. + write_status_files_if_changed(conf);
  1918. + return 0;
  1919. +}
  1920. +
  1921. +static int ipkg_purge_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1922. +{
  1923. + int i;
  1924. + pkg_t *pkg;
  1925. +
  1926. + global_conf = conf;
  1927. + signal(SIGINT, sigint_handler);
  1928. +
  1929. + pkg_info_preinstall_check(conf);
  1930. +
  1931. + for (i=0; i < argc; i++) {
  1932. + if (conf->restrict_to_default_dest) {
  1933. + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
  1934. + argv[i],
  1935. + conf->default_dest);
  1936. + } else {
  1937. + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, argv[i]);
  1938. + }
  1939. +
  1940. + if (pkg == NULL) {
  1941. + ipkg_message(conf, IPKG_ERROR,
  1942. + "Package %s is not installed.\n", argv[i]);
  1943. + continue;
  1944. + }
  1945. + ipkg_purge_pkg(conf, pkg);
  1946. + }
  1947. +
  1948. + write_status_files_if_changed(conf);
  1949. + return 0;
  1950. +}
  1951. +
  1952. +static int ipkg_flag_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1953. +{
  1954. + int i;
  1955. + pkg_t *pkg;
  1956. + char *flags = argv[0];
  1957. +
  1958. + global_conf = conf;
  1959. + signal(SIGINT, sigint_handler);
  1960. +
  1961. + for (i=1; i < argc; i++) {
  1962. + if (conf->restrict_to_default_dest) {
  1963. + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
  1964. + argv[i],
  1965. + conf->default_dest);
  1966. + } else {
  1967. + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, argv[i]);
  1968. + }
  1969. +
  1970. + if (pkg == NULL) {
  1971. + ipkg_message(conf, IPKG_ERROR,
  1972. + "Package %s is not installed.\n", argv[i]);
  1973. + continue;
  1974. + }
  1975. + if (( strcmp(flags,"hold")==0)||( strcmp(flags,"noprune")==0)||
  1976. + ( strcmp(flags,"user")==0)||( strcmp(flags,"ok")==0)) {
  1977. + pkg->state_flag = pkg_state_flag_from_str(flags);
  1978. + }
  1979. +/* pb_ asked this feature 03292004 */
  1980. +/* Actually I will use only this two, but this is an open for various status */
  1981. + if (( strcmp(flags,"installed")==0)||( strcmp(flags,"unpacked")==0)){
  1982. + pkg->state_status = pkg_state_status_from_str(flags);
  1983. + }
  1984. + ipkg_state_changed++;
  1985. + ipkg_message(conf, IPKG_NOTICE,
  1986. + "Setting flags for package %s to %s\n",
  1987. + pkg->name, flags);
  1988. + }
  1989. +
  1990. + write_status_files_if_changed(conf);
  1991. + return 0;
  1992. +}
  1993. +
  1994. +static int ipkg_files_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1995. +{
  1996. + pkg_t *pkg;
  1997. + str_list_t *installed_files;
  1998. + str_list_elt_t *iter;
  1999. + char *pkg_version;
  2000. + size_t buff_len = 8192;
  2001. + size_t used_len;
  2002. + char *buff ;
  2003. +
  2004. + buff = (char *)malloc(buff_len);
  2005. + if ( buff == NULL ) {
  2006. + fprintf( stderr,"%s: Unable to allocate memory \n",__FUNCTION__);
  2007. + return ENOMEM;
  2008. + }
  2009. +
  2010. + if (argc < 1) {
  2011. + return EINVAL;
  2012. + }
  2013. +
  2014. + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash,
  2015. + argv[0]);
  2016. + if (pkg == NULL) {
  2017. + ipkg_message(conf, IPKG_ERROR,
  2018. + "Package %s not installed.\n", argv[0]);
  2019. + return 0;
  2020. + }
  2021. +
  2022. + installed_files = pkg_get_installed_files(pkg);
  2023. + pkg_version = pkg_version_str_alloc(pkg);
  2024. +
  2025. +#ifndef IPKG_LIB
  2026. + printf("Package %s (%s) is installed on %s and has the following files:\n",
  2027. + pkg->name, pkg_version, pkg->dest->name);
  2028. + for (iter = installed_files->head; iter; iter = iter->next) {
  2029. + puts(iter->data);
  2030. + }
  2031. +#else
  2032. + if (buff) {
  2033. + try_again:
  2034. + used_len = snprintf(buff, buff_len, "Package %s (%s) is installed on %s and has the following files:\n",
  2035. + pkg->name, pkg_version, pkg->dest->name) + 1;
  2036. + if (used_len > buff_len) {
  2037. + buff_len *= 2;
  2038. + buff = realloc (buff, buff_len);
  2039. + goto try_again;
  2040. + }
  2041. + for (iter = installed_files->head; iter; iter = iter->next) {
  2042. + used_len += strlen (iter->data) + 1;
  2043. + while (buff_len <= used_len) {
  2044. + buff_len *= 2;
  2045. + buff = realloc (buff, buff_len);
  2046. + }
  2047. + strncat(buff, iter->data, buff_len);
  2048. + strncat(buff, "\n", buff_len);
  2049. + }
  2050. + if (ipkg_cb_list) ipkg_cb_list(pkg->name,
  2051. + buff,
  2052. + pkg_version_str_alloc(pkg),
  2053. + pkg->state_status,
  2054. + p_userdata);
  2055. + free(buff);
  2056. + }
  2057. +#endif
  2058. +
  2059. + free(pkg_version);
  2060. + pkg_free_installed_files(pkg);
  2061. +
  2062. + return 0;
  2063. +}
  2064. +
  2065. +static int ipkg_depends_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2066. +{
  2067. +
  2068. + if (argc > 0) {
  2069. + pkg_vec_t *available_pkgs = pkg_vec_alloc();
  2070. + const char *rel_str = "depends on";
  2071. + int i;
  2072. +
  2073. + pkg_info_preinstall_check(conf);
  2074. +
  2075. + if (conf->query_all)
  2076. + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
  2077. + else
  2078. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
  2079. + for (i = 0; i < argc; i++) {
  2080. + const char *target = argv[i];
  2081. + int j;
  2082. +
  2083. + ipkg_message(conf, IPKG_ERROR, "target=%s\n", target);
  2084. +
  2085. + for (j = 0; j < available_pkgs->len; j++) {
  2086. + pkg_t *pkg = available_pkgs->pkgs[j];
  2087. + if (fnmatch(target, pkg->name, 0) == 0) {
  2088. + int k;
  2089. + int count = pkg->depends_count + pkg->pre_depends_count;
  2090. + ipkg_message(conf, IPKG_ERROR, "What %s (arch=%s) %s\n",
  2091. + target, pkg->architecture, rel_str);
  2092. + for (k = 0; k < count; k++) {
  2093. + compound_depend_t *cdepend = &pkg->depends[k];
  2094. + int l;
  2095. + for (l = 0; l < cdepend->possibility_count; l++) {
  2096. + depend_t *possibility = cdepend->possibilities[l];
  2097. + ipkg_message(conf, IPKG_ERROR, " %s", possibility->pkg->name);
  2098. + if (conf->verbosity > 0) {
  2099. + // char *ver = abstract_pkg_version_str_alloc(possibility->pkg);
  2100. + ipkg_message(conf, IPKG_NOTICE, " %s", possibility->version);
  2101. + if (possibility->version) {
  2102. + const char *typestr = NULL;
  2103. + switch (possibility->constraint) {
  2104. + case NONE: typestr = "none"; break;
  2105. + case EARLIER: typestr = "<"; break;
  2106. + case EARLIER_EQUAL: typestr = "<="; break;
  2107. + case EQUAL: typestr = "="; break;
  2108. + case LATER_EQUAL: typestr = ">="; break;
  2109. + case LATER: typestr = ">"; break;
  2110. + }
  2111. + ipkg_message(conf, IPKG_NOTICE, " (%s %s)", typestr, possibility->version);
  2112. + }
  2113. + // free(ver);
  2114. + }
  2115. + ipkg_message(conf, IPKG_ERROR, "\n");
  2116. + }
  2117. + }
  2118. + }
  2119. + }
  2120. + }
  2121. + pkg_vec_free(available_pkgs);
  2122. + }
  2123. + return 0;
  2124. +}
  2125. +
  2126. +enum what_field_type {
  2127. + WHATDEPENDS,
  2128. + WHATCONFLICTS,
  2129. + WHATPROVIDES,
  2130. + WHATREPLACES,
  2131. + WHATRECOMMENDS,
  2132. + WHATSUGGESTS
  2133. +};
  2134. +
  2135. +static int ipkg_what_depends_conflicts_cmd(ipkg_conf_t *conf, enum what_field_type what_field_type, int recursive, int argc, char **argv)
  2136. +{
  2137. +
  2138. + if (argc > 0) {
  2139. + pkg_vec_t *available_pkgs = pkg_vec_alloc();
  2140. + const char *rel_str = NULL;
  2141. + int i;
  2142. + int changed;
  2143. +
  2144. + switch (what_field_type) {
  2145. + case WHATDEPENDS: rel_str = "depends on"; break;
  2146. + case WHATCONFLICTS: rel_str = "conflicts with"; break;
  2147. + case WHATSUGGESTS: rel_str = "suggests"; break;
  2148. + case WHATRECOMMENDS: rel_str = "recommends"; break;
  2149. + case WHATPROVIDES: rel_str = "provides"; break;
  2150. + case WHATREPLACES: rel_str = "replaces"; break;
  2151. + }
  2152. +
  2153. + if (conf->query_all)
  2154. + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
  2155. + else
  2156. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
  2157. +
  2158. + /* mark the root set */
  2159. + pkg_vec_clear_marks(available_pkgs);
  2160. + ipkg_message(conf, IPKG_NOTICE, "Root set:\n");
  2161. + for (i = 0; i < argc; i++) {
  2162. + const char *dependee_pattern = argv[i];
  2163. + pkg_vec_mark_if_matches(available_pkgs, dependee_pattern);
  2164. + }
  2165. + for (i = 0; i < available_pkgs->len; i++) {
  2166. + pkg_t *pkg = available_pkgs->pkgs[i];
  2167. + if (pkg->state_flag & SF_MARKED) {
  2168. + /* mark the parent (abstract) package */
  2169. + pkg_mark_provides(pkg);
  2170. + ipkg_message(conf, IPKG_NOTICE, " %s\n", pkg->name);
  2171. + }
  2172. + }
  2173. +
  2174. + ipkg_message(conf, IPKG_NOTICE, "What %s root set\n", rel_str);
  2175. + do {
  2176. + int j;
  2177. + changed = 0;
  2178. +
  2179. + for (j = 0; j < available_pkgs->len; j++) {
  2180. + pkg_t *pkg = available_pkgs->pkgs[j];
  2181. + int k;
  2182. + int count = ((what_field_type == WHATCONFLICTS)
  2183. + ? pkg->conflicts_count
  2184. + : pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count);
  2185. + /* skip this package if it is already marked */
  2186. + if (pkg->parent->state_flag & SF_MARKED) {
  2187. + continue;
  2188. + }
  2189. + for (k = 0; k < count; k++) {
  2190. + compound_depend_t *cdepend =
  2191. + (what_field_type == WHATCONFLICTS) ? &pkg->conflicts[k] : &pkg->depends[k];
  2192. + int l;
  2193. + for (l = 0; l < cdepend->possibility_count; l++) {
  2194. + depend_t *possibility = cdepend->possibilities[l];
  2195. + if (possibility->pkg->state_flag & SF_MARKED) {
  2196. + /* mark the depending package so we won't visit it again */
  2197. + pkg->state_flag |= SF_MARKED;
  2198. + pkg_mark_provides(pkg);
  2199. + changed++;
  2200. +
  2201. + ipkg_message(conf, IPKG_NOTICE, " %s", pkg->name);
  2202. + if (conf->verbosity > 0) {
  2203. + char *ver = pkg_version_str_alloc(pkg);
  2204. + ipkg_message(conf, IPKG_NOTICE, " %s", ver);
  2205. + ipkg_message(conf, IPKG_NOTICE, "\t%s %s", rel_str, possibility->pkg->name);
  2206. + if (possibility->version) {
  2207. + const char *typestr = NULL;
  2208. + switch (possibility->constraint) {
  2209. + case NONE: typestr = "none"; break;
  2210. + case EARLIER: typestr = "<"; break;
  2211. + case EARLIER_EQUAL: typestr = "<="; break;
  2212. + case EQUAL: typestr = "="; break;
  2213. + case LATER_EQUAL: typestr = ">="; break;
  2214. + case LATER: typestr = ">"; break;
  2215. + }
  2216. + ipkg_message(conf, IPKG_NOTICE, " (%s %s)", typestr, possibility->version);
  2217. + }
  2218. + free(ver);
  2219. + if (!pkg_dependence_satisfiable(possibility))
  2220. + ipkg_message(conf, IPKG_NOTICE, " unsatisfiable");
  2221. + }
  2222. + ipkg_message(conf, IPKG_NOTICE, "\n");
  2223. + goto next_package;
  2224. + }
  2225. + }
  2226. + }
  2227. + next_package:
  2228. + ;
  2229. + }
  2230. + } while (changed && recursive);
  2231. + pkg_vec_free(available_pkgs);
  2232. + }
  2233. +
  2234. + return 0;
  2235. +}
  2236. +
  2237. +int pkg_mark_provides(pkg_t *pkg)
  2238. +{
  2239. + int provides_count = pkg->provides_count;
  2240. + abstract_pkg_t **provides = pkg->provides;
  2241. + int i;
  2242. + pkg->parent->state_flag |= SF_MARKED;
  2243. + for (i = 0; i < provides_count; i++) {
  2244. + provides[i]->state_flag |= SF_MARKED;
  2245. + }
  2246. + return 0;
  2247. +}
  2248. +
  2249. +static int ipkg_whatdepends_recursively_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2250. +{
  2251. + return ipkg_what_depends_conflicts_cmd(conf, WHATDEPENDS, 1, argc, argv);
  2252. +}
  2253. +static int ipkg_whatdepends_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2254. +{
  2255. + return ipkg_what_depends_conflicts_cmd(conf, WHATDEPENDS, 0, argc, argv);
  2256. +}
  2257. +
  2258. +static int ipkg_whatsuggests_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2259. +{
  2260. + return ipkg_what_depends_conflicts_cmd(conf, WHATSUGGESTS, 0, argc, argv);
  2261. +}
  2262. +
  2263. +static int ipkg_whatrecommends_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2264. +{
  2265. + return ipkg_what_depends_conflicts_cmd(conf, WHATRECOMMENDS, 0, argc, argv);
  2266. +}
  2267. +
  2268. +static int ipkg_whatconflicts_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2269. +{
  2270. + return ipkg_what_depends_conflicts_cmd(conf, WHATCONFLICTS, 0, argc, argv);
  2271. +}
  2272. +
  2273. +static int ipkg_what_provides_replaces_cmd(ipkg_conf_t *conf, enum what_field_type what_field_type, int argc, char **argv)
  2274. +{
  2275. +
  2276. + if (argc > 0) {
  2277. + pkg_vec_t *available_pkgs = pkg_vec_alloc();
  2278. + const char *rel_str = (what_field_type == WHATPROVIDES ? "provides" : "replaces");
  2279. + int i;
  2280. +
  2281. + pkg_info_preinstall_check(conf);
  2282. +
  2283. + if (conf->query_all)
  2284. + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
  2285. + else
  2286. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
  2287. + for (i = 0; i < argc; i++) {
  2288. + const char *target = argv[i];
  2289. + int j;
  2290. +
  2291. + ipkg_message(conf, IPKG_ERROR, "What %s %s\n",
  2292. + rel_str, target);
  2293. + for (j = 0; j < available_pkgs->len; j++) {
  2294. + pkg_t *pkg = available_pkgs->pkgs[j];
  2295. + int k;
  2296. + int count = (what_field_type == WHATPROVIDES) ? pkg->provides_count : pkg->replaces_count;
  2297. + for (k = 0; k < count; k++) {
  2298. + abstract_pkg_t *apkg =
  2299. + ((what_field_type == WHATPROVIDES)
  2300. + ? pkg->provides[k]
  2301. + : pkg->replaces[k]);
  2302. + if (fnmatch(target, apkg->name, 0) == 0) {
  2303. + ipkg_message(conf, IPKG_ERROR, " %s", pkg->name);
  2304. + if (strcmp(target, apkg->name) != 0)
  2305. + ipkg_message(conf, IPKG_ERROR, "\t%s %s\n", rel_str, apkg->name);
  2306. + ipkg_message(conf, IPKG_ERROR, "\n");
  2307. + }
  2308. + }
  2309. + }
  2310. + }
  2311. + pkg_vec_free(available_pkgs);
  2312. + }
  2313. + return 0;
  2314. +}
  2315. +
  2316. +static int ipkg_whatprovides_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2317. +{
  2318. + return ipkg_what_provides_replaces_cmd(conf, WHATPROVIDES, argc, argv);
  2319. +}
  2320. +
  2321. +static int ipkg_whatreplaces_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2322. +{
  2323. + return ipkg_what_provides_replaces_cmd(conf, WHATREPLACES, argc, argv);
  2324. +}
  2325. +
  2326. +static int ipkg_search_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2327. +{
  2328. + int i;
  2329. +
  2330. + pkg_vec_t *installed;
  2331. + pkg_t *pkg;
  2332. + str_list_t *installed_files;
  2333. + str_list_elt_t *iter;
  2334. + char *installed_file;
  2335. +
  2336. + if (argc < 1) {
  2337. + return EINVAL;
  2338. + }
  2339. +
  2340. + installed = pkg_vec_alloc();
  2341. + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
  2342. +
  2343. + for (i=0; i < installed->len; i++) {
  2344. + pkg = installed->pkgs[i];
  2345. +
  2346. + installed_files = pkg_get_installed_files(pkg);
  2347. +
  2348. + for (iter = installed_files->head; iter; iter = iter->next) {
  2349. + installed_file = iter->data;
  2350. + if (fnmatch(argv[0], installed_file, 0)==0) {
  2351. +#ifndef IPKG_LIB
  2352. + printf("%s: %s\n", pkg->name, installed_file);
  2353. +#else
  2354. + if (ipkg_cb_list) ipkg_cb_list(pkg->name,
  2355. + installed_file,
  2356. + pkg_version_str_alloc(pkg),
  2357. + pkg->state_status, p_userdata);
  2358. +#endif
  2359. + }
  2360. + }
  2361. +
  2362. + pkg_free_installed_files(pkg);
  2363. + }
  2364. +
  2365. + /* XXX: CLEANUP: It's not obvious from the name of
  2366. + pkg_hash_fetch_all_installed that we need to call
  2367. + pkg_vec_free to avoid a memory leak. */
  2368. + pkg_vec_free(installed);
  2369. +
  2370. + return 0;
  2371. +}
  2372. +
  2373. +static int ipkg_compare_versions_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2374. +{
  2375. + if (argc == 3) {
  2376. + /* this is a bit gross */
  2377. + struct pkg p1, p2;
  2378. + parseVersion(&p1, argv[0]);
  2379. + parseVersion(&p2, argv[2]);
  2380. + return pkg_version_satisfied(&p1, &p2, argv[1]);
  2381. + } else {
  2382. + ipkg_message(conf, IPKG_ERROR,
  2383. + "ipkg compare_versions <v1> <op> <v2>\n"
  2384. + "<op> is one of <= >= << >> =\n");
  2385. + return -1;
  2386. + }
  2387. +}
  2388. +
  2389. +#ifndef HOST_CPU_STR
  2390. +#define HOST_CPU_STR__(X) #X
  2391. +#define HOST_CPU_STR_(X) HOST_CPU_STR__(X)
  2392. +#define HOST_CPU_STR HOST_CPU_STR_(HOST_CPU_FOO)
  2393. +#endif
  2394. +
  2395. +static int ipkg_print_architecture_cmd(ipkg_conf_t *conf)
  2396. +{
  2397. + nv_pair_list_elt_t *l;
  2398. +
  2399. + l = conf->arch_list.head;
  2400. + while (l) {
  2401. + nv_pair_t *nv = l->data;
  2402. + printf("arch %s %s\n", nv->name, nv->value);
  2403. + l = l->next;
  2404. + }
  2405. + return 0;
  2406. +}
  2407. +
  2408. +
  2409. diff -Nur busybox-1.12.1.orig/archival/libipkg/ipkg_cmd.h busybox-1.12.1/archival/libipkg/ipkg_cmd.h
  2410. --- busybox-1.12.1.orig/archival/libipkg/ipkg_cmd.h 1970-01-01 01:00:00.000000000 +0100
  2411. +++ busybox-1.12.1/archival/libipkg/ipkg_cmd.h 2008-10-23 13:46:55.000000000 +0200
  2412. @@ -0,0 +1,46 @@
  2413. +/* ipkg_cmd.h - the itsy package management system
  2414. +
  2415. + Carl D. Worth
  2416. +
  2417. + Copyright (C) 2001 University of Southern California
  2418. +
  2419. + This program is free software; you can redistribute it and/or
  2420. + modify it under the terms of the GNU General Public License as
  2421. + published by the Free Software Foundation; either version 2, or (at
  2422. + your option) any later version.
  2423. +
  2424. + This program is distributed in the hope that it will be useful, but
  2425. + WITHOUT ANY WARRANTY; without even the implied warranty of
  2426. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  2427. + General Public License for more details.
  2428. +*/
  2429. +
  2430. +#ifndef IPKG_CMD_H
  2431. +#define IPKG_CMD_H
  2432. +
  2433. +typedef int (*ipkg_cmd_fun_t)(ipkg_conf_t *conf, int argc, const char **argv);
  2434. +
  2435. +struct ipkg_cmd
  2436. +{
  2437. + const char *name;
  2438. + int requires_args;
  2439. + ipkg_cmd_fun_t fun;
  2440. +};
  2441. +typedef struct ipkg_cmd ipkg_cmd_t;
  2442. +
  2443. +ipkg_cmd_t *ipkg_cmd_find(const char *name);
  2444. +#ifdef IPKG_LIB
  2445. +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc,
  2446. + const char **argv, void *userdata);
  2447. +#else
  2448. +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc, const char **argv);
  2449. +#endif
  2450. +int ipkg_multiple_files_scan (ipkg_conf_t *conf, int argc, char *argv[]);
  2451. +/* install any packges with state_want == SW_INSTALL */
  2452. +int ipkg_install_wanted_packages(ipkg_conf_t *conf);
  2453. +/* ensure that all dependences are satisfied */
  2454. +int ipkg_configure_packages(ipkg_conf_t *conf, char *pkg_name);
  2455. +
  2456. +int pkg_mark_provides(pkg_t *pkg);
  2457. +
  2458. +#endif
  2459. diff -Nur busybox-1.12.1.orig/archival/libipkg/ipkg_conf.c busybox-1.12.1/archival/libipkg/ipkg_conf.c
  2460. --- busybox-1.12.1.orig/archival/libipkg/ipkg_conf.c 1970-01-01 01:00:00.000000000 +0100
  2461. +++ busybox-1.12.1/archival/libipkg/ipkg_conf.c 2008-10-23 13:45:16.000000000 +0200
  2462. @@ -0,0 +1,711 @@
  2463. +/* ipkg_conf.c - the itsy package management system
  2464. +
  2465. + Carl D. Worth
  2466. +
  2467. + Copyright (C) 2001 University of Southern California
  2468. +
  2469. + This program is free software; you can redistribute it and/or
  2470. + modify it under the terms of the GNU General Public License as
  2471. + published by the Free Software Foundation; either version 2, or (at
  2472. + your option) any later version.
  2473. +
  2474. + This program is distributed in the hope that it will be useful, but
  2475. + WITHOUT ANY WARRANTY; without even the implied warranty of
  2476. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  2477. + General Public License for more details.
  2478. +*/
  2479. +
  2480. +#include <glob.h>
  2481. +
  2482. +#include "ipkg.h"
  2483. +#include "ipkg_conf.h"
  2484. +
  2485. +#include "xregex.h"
  2486. +#include "sprintf_alloc.h"
  2487. +#include "ipkg_conf.h"
  2488. +#include "ipkg_message.h"
  2489. +#include "file_util.h"
  2490. +#include "str_util.h"
  2491. +#include "xsystem.h"
  2492. +
  2493. +
  2494. +ipkg_conf_t *global_conf;
  2495. +
  2496. +static int ipkg_conf_parse_file(ipkg_conf_t *conf, const char *filename,
  2497. + pkg_src_list_t *pkg_src_list,
  2498. + nv_pair_list_t *tmp_dest_nv_pair_list,
  2499. + char **tmp_lists_dir);
  2500. +static int ipkg_init_options_array(const ipkg_conf_t *conf, ipkg_option_t **options);
  2501. +static int ipkg_conf_set_option(const ipkg_option_t *options,
  2502. + const char *name, const char *value);
  2503. +static int ipkg_conf_set_default_dest(ipkg_conf_t *conf,
  2504. + const char *default_dest_name);
  2505. +static int set_and_load_pkg_src_list(ipkg_conf_t *conf,
  2506. + pkg_src_list_t *nv_pair_list);
  2507. +static int set_and_load_pkg_dest_list(ipkg_conf_t *conf,
  2508. + nv_pair_list_t *nv_pair_list, char * lists_dir);
  2509. +
  2510. +int ipkg_init_options_array(const ipkg_conf_t *conf, ipkg_option_t **options)
  2511. +{
  2512. + ipkg_option_t tmp[] = {
  2513. + { "force_defaults", IPKG_OPT_TYPE_BOOL, &conf->force_defaults },
  2514. + { "force_depends", IPKG_OPT_TYPE_BOOL, &conf->force_depends },
  2515. + { "force_overwrite", IPKG_OPT_TYPE_BOOL, &conf->force_overwrite },
  2516. + { "force_downgrade", IPKG_OPT_TYPE_BOOL, &conf->force_downgrade },
  2517. + { "force_reinstall", IPKG_OPT_TYPE_BOOL, &conf->force_reinstall },
  2518. + { "force_space", IPKG_OPT_TYPE_BOOL, &conf->force_space },
  2519. + { "ftp_proxy", IPKG_OPT_TYPE_STRING, &conf->ftp_proxy },
  2520. + { "http_proxy", IPKG_OPT_TYPE_STRING, &conf->http_proxy },
  2521. + { "multiple_providers", IPKG_OPT_TYPE_BOOL, &conf->multiple_providers },
  2522. + { "no_proxy", IPKG_OPT_TYPE_STRING, &conf->no_proxy },
  2523. + { "test", IPKG_OPT_TYPE_INT, &conf->noaction },
  2524. + { "noaction", IPKG_OPT_TYPE_INT, &conf->noaction },
  2525. + { "nodeps", IPKG_OPT_TYPE_BOOL, &conf->nodeps },
  2526. + { "offline_root", IPKG_OPT_TYPE_STRING, &conf->offline_root },
  2527. + { "offline_root_post_script_cmd", IPKG_OPT_TYPE_STRING, &conf->offline_root_post_script_cmd },
  2528. + { "offline_root_pre_script_cmd", IPKG_OPT_TYPE_STRING, &conf->offline_root_pre_script_cmd },
  2529. + { "proxy_passwd", IPKG_OPT_TYPE_STRING, &conf->proxy_passwd },
  2530. + { "proxy_user", IPKG_OPT_TYPE_STRING, &conf->proxy_user },
  2531. + { "query-all", IPKG_OPT_TYPE_BOOL, &conf->query_all },
  2532. + { "verbose-wget", IPKG_OPT_TYPE_BOOL, &conf->verbose_wget },
  2533. + { "verbosity", IPKG_OPT_TYPE_BOOL, &conf->verbosity },
  2534. + { NULL }
  2535. + };
  2536. +
  2537. + *options = (ipkg_option_t *)malloc(sizeof(tmp));
  2538. + if ( options == NULL ){
  2539. + fprintf(stderr,"%s: Unable to allocate memory\n",__FUNCTION__);
  2540. + return -1;
  2541. + }
  2542. +
  2543. + memcpy(*options, tmp, sizeof(tmp));
  2544. + return 0;
  2545. +};
  2546. +
  2547. +static void ipkg_conf_override_string(char **conf_str, char *arg_str)
  2548. +{
  2549. + if (arg_str) {
  2550. + if (*conf_str) {
  2551. + free(*conf_str);
  2552. + }
  2553. + *conf_str = strdup(arg_str);
  2554. + }
  2555. +}
  2556. +
  2557. +static void ipkg_conf_free_string(char **conf_str)
  2558. +{
  2559. + if (*conf_str) {
  2560. + free(*conf_str);
  2561. + *conf_str = NULL;
  2562. + }
  2563. +}
  2564. +
  2565. +int ipkg_conf_init(ipkg_conf_t *conf, const args_t *args)
  2566. +{
  2567. + int err;
  2568. + char *tmp_dir_base;
  2569. + nv_pair_list_t tmp_dest_nv_pair_list;
  2570. + char * lists_dir =NULL;
  2571. + glob_t globbuf;
  2572. + const char *etc_ipkg_conf_pattern = "/etc/ipkg/*.conf";
  2573. + char *pending_dir =NULL;
  2574. +
  2575. + memset(conf, 0, sizeof(ipkg_conf_t));
  2576. +
  2577. + pkg_src_list_init(&conf->pkg_src_list);
  2578. +
  2579. + nv_pair_list_init(&tmp_dest_nv_pair_list);
  2580. + pkg_dest_list_init(&conf->pkg_dest_list);
  2581. +
  2582. + nv_pair_list_init(&conf->arch_list);
  2583. +
  2584. + conf->restrict_to_default_dest = 0;
  2585. + conf->default_dest = NULL;
  2586. +
  2587. +
  2588. + if (args->tmp_dir)
  2589. + tmp_dir_base = args->tmp_dir;
  2590. + else
  2591. + tmp_dir_base = getenv("TMPDIR");
  2592. + sprintf_alloc(&conf->tmp_dir, "%s/%s",
  2593. + tmp_dir_base ? tmp_dir_base : IPKG_CONF_DEFAULT_TMP_DIR_BASE,
  2594. + IPKG_CONF_TMP_DIR_SUFFIX);
  2595. + conf->tmp_dir = mkdtemp(conf->tmp_dir);
  2596. + if (conf->tmp_dir == NULL) {
  2597. + fprintf(stderr, "%s: Failed to create temporary directory `%s': %s\n",
  2598. + __FUNCTION__, conf->tmp_dir, strerror(errno));
  2599. + return errno;
  2600. + }
  2601. +
  2602. + conf->force_depends = 0;
  2603. + conf->force_defaults = 0;
  2604. + conf->force_overwrite = 0;
  2605. + conf->force_downgrade = 0;
  2606. + conf->force_reinstall = 0;
  2607. + conf->force_space = 0;
  2608. + conf->force_removal_of_essential_packages = 0;
  2609. + conf->force_removal_of_dependent_packages = 0;
  2610. + conf->nodeps = 0;
  2611. + conf->verbose_wget = 0;
  2612. + conf->offline_root = NULL;
  2613. + conf->offline_root_pre_script_cmd = NULL;
  2614. + conf->offline_root_post_script_cmd = NULL;
  2615. + conf->multiple_providers = 0;
  2616. + conf->verbosity = 1;
  2617. + conf->noaction = 0;
  2618. +
  2619. + conf->http_proxy = NULL;
  2620. + conf->ftp_proxy = NULL;
  2621. + conf->no_proxy = NULL;
  2622. + conf->proxy_user = NULL;
  2623. + conf->proxy_passwd = NULL;
  2624. +
  2625. + pkg_hash_init("pkg-hash", &conf->pkg_hash, IPKG_CONF_DEFAULT_HASH_LEN);
  2626. + hash_table_init("file-hash", &conf->file_hash, IPKG_CONF_DEFAULT_HASH_LEN);
  2627. + hash_table_init("obs-file-hash", &conf->obs_file_hash, IPKG_CONF_DEFAULT_HASH_LEN);
  2628. + lists_dir=(char *)malloc(1);
  2629. + lists_dir[0]='\0';
  2630. + if (args->conf_file) {
  2631. + struct stat stat_buf;
  2632. + err = stat(args->conf_file, &stat_buf);
  2633. + if (err == 0)
  2634. + if (ipkg_conf_parse_file(conf, args->conf_file,
  2635. + &conf->pkg_src_list, &tmp_dest_nv_pair_list,&lists_dir)<0) {
  2636. + /* Memory leakage from ipkg_conf_parse-file */
  2637. + return -1;
  2638. + }
  2639. +
  2640. + }
  2641. +
  2642. + /* if (!lists_dir ){*/
  2643. + if (strlen(lists_dir)<=1 ){
  2644. + lists_dir = realloc(lists_dir,strlen(IPKG_CONF_LISTS_DIR)+2);
  2645. + sprintf (lists_dir,"%s",IPKG_CONF_LISTS_DIR);
  2646. + }
  2647. +
  2648. + if (args->offline_root) {
  2649. + char *tmp = malloc(strlen(lists_dir) + strlen(args->offline_root) + 1);
  2650. + sprintf_alloc(&tmp, "%s/%s",args->offline_root,lists_dir);
  2651. + free(lists_dir);
  2652. + lists_dir = tmp;
  2653. + }
  2654. +
  2655. + pending_dir = malloc(strlen(lists_dir)+strlen("/pending")+5);
  2656. + snprintf(pending_dir,strlen(lists_dir)+strlen("/pending") ,"%s%s",lists_dir,"/pending");
  2657. +
  2658. + conf->lists_dir = strdup(lists_dir);
  2659. + conf->pending_dir = strdup(pending_dir);
  2660. +
  2661. + if (args->offline_root)
  2662. + sprintf_alloc(&etc_ipkg_conf_pattern, "%s/etc/ipkg/*.conf", args->offline_root);
  2663. + memset(&globbuf, 0, sizeof(globbuf));
  2664. + err = glob(etc_ipkg_conf_pattern, 0, NULL, &globbuf);
  2665. + if (!err) {
  2666. + int i;
  2667. + for (i = 0; i < globbuf.gl_pathc; i++) {
  2668. + if (globbuf.gl_pathv[i])
  2669. + if ( ipkg_conf_parse_file(conf, globbuf.gl_pathv[i],
  2670. + &conf->pkg_src_list, &tmp_dest_nv_pair_list,&lists_dir)<0) {
  2671. + /* Memory leakage from ipkg_conf_parse-file */
  2672. + return -1;
  2673. + }
  2674. + }
  2675. + }
  2676. + globfree(&globbuf);
  2677. +
  2678. + /* if no architectures were defined, then default all, noarch, and host architecture */
  2679. + if (nv_pair_list_empty(&conf->arch_list)) {
  2680. + nv_pair_list_append(&conf->arch_list, "all", "1");
  2681. + nv_pair_list_append(&conf->arch_list, "noarch", "1");
  2682. + nv_pair_list_append(&conf->arch_list, HOST_CPU_STR, "10");
  2683. + }
  2684. +
  2685. + /* Even if there is no conf file, we'll need at least one dest. */
  2686. + if (tmp_dest_nv_pair_list.head == NULL) {
  2687. + nv_pair_list_append(&tmp_dest_nv_pair_list,
  2688. + IPKG_CONF_DEFAULT_DEST_NAME,
  2689. + IPKG_CONF_DEFAULT_DEST_ROOT_DIR);
  2690. + }
  2691. +
  2692. + /* After parsing the file, set options from command-line, (so that
  2693. + command-line arguments take precedence) */
  2694. + /* XXX: CLEANUP: The interaction between args.c and ipkg_conf.c
  2695. + really needs to be cleaned up. There is so much duplication
  2696. + right now it is ridiculous. Maybe ipkg_conf_t should just save
  2697. + a pointer to args_t (which could then not be freed), rather
  2698. + than duplicating every field here? */
  2699. + if (args->force_depends) {
  2700. + conf->force_depends = 1;
  2701. + }
  2702. + if (args->force_defaults) {
  2703. + conf->force_defaults = 1;
  2704. + }
  2705. + if (args->force_overwrite) {
  2706. + conf->force_overwrite = 1;
  2707. + }
  2708. + if (args->force_downgrade) {
  2709. + conf->force_downgrade = 1;
  2710. + }
  2711. + if (args->force_reinstall) {
  2712. + conf->force_reinstall = 1;
  2713. + }
  2714. + if (args->force_removal_of_dependent_packages) {
  2715. + conf->force_removal_of_dependent_packages = 1;
  2716. + }
  2717. + if (args->force_removal_of_essential_packages) {
  2718. + conf->force_removal_of_essential_packages = 1;
  2719. + }
  2720. + if (args->nodeps) {
  2721. + conf->nodeps = 1;
  2722. + }
  2723. + if (args->noaction) {
  2724. + conf->noaction = 1;
  2725. + }
  2726. + if (args->query_all) {
  2727. + conf->query_all = 1;
  2728. + }
  2729. + if (args->verbose_wget) {
  2730. + conf->verbose_wget = 1;
  2731. + }
  2732. + if (args->multiple_providers) {
  2733. + conf->multiple_providers = 1;
  2734. + }
  2735. + if (args->verbosity != conf->verbosity) {
  2736. + conf->verbosity = args->verbosity;
  2737. + }
  2738. +
  2739. + ipkg_conf_override_string(&conf->offline_root,
  2740. + args->offline_root);
  2741. + ipkg_conf_override_string(&conf->offline_root_pre_script_cmd,
  2742. + args->offline_root_pre_script_cmd);
  2743. + ipkg_conf_override_string(&conf->offline_root_post_script_cmd,
  2744. + args->offline_root_post_script_cmd);
  2745. +
  2746. +/* Pigi: added a flag to disable the checking of structures if the command does not need to
  2747. + read anything from there.
  2748. +*/
  2749. + if ( !(args->nocheckfordirorfile)){
  2750. + /* need to run load the source list before dest list -Jamey */
  2751. + if ( !(args->noreadfeedsfile))
  2752. + set_and_load_pkg_src_list(conf, &conf->pkg_src_list);
  2753. +
  2754. + /* Now that we have resolved conf->offline_root, we can commit to
  2755. + the directory names for the dests and load in all the package
  2756. + lists. */
  2757. + set_and_load_pkg_dest_list(conf, &tmp_dest_nv_pair_list,lists_dir);
  2758. +
  2759. + if (args->dest) {
  2760. + err = ipkg_conf_set_default_dest(conf, args->dest);
  2761. + if (err) {
  2762. + return err;
  2763. + }
  2764. + }
  2765. + }
  2766. + nv_pair_list_deinit(&tmp_dest_nv_pair_list);
  2767. + free(lists_dir);
  2768. + free(pending_dir);
  2769. +
  2770. + return 0;
  2771. +}
  2772. +
  2773. +void ipkg_conf_deinit(ipkg_conf_t *conf)
  2774. +{
  2775. +#ifdef IPKG_DEBUG_NO_TMP_CLEANUP
  2776. +#error
  2777. + fprintf(stderr, "%s: Not cleaning up %s since ipkg compiled "
  2778. + "with IPKG_DEBUG_NO_TMP_CLEANUP\n",
  2779. + __FUNCTION__, conf->tmp_dir);
  2780. +#else
  2781. + int err;
  2782. +
  2783. + err = rmdir(conf->tmp_dir);
  2784. + if (err) {
  2785. + if (errno == ENOTEMPTY) {
  2786. + char *cmd;
  2787. + sprintf_alloc(&cmd, "rm -fr %s\n", conf->tmp_dir);
  2788. + err = xsystem(cmd);
  2789. + free(cmd);
  2790. + }
  2791. + if (err)
  2792. + fprintf(stderr, "WARNING: Unable to remove temporary directory: %s: %s\n", conf->tmp_dir, strerror(errno));
  2793. + }
  2794. +#endif /* IPKG_DEBUG_NO_TMP_CLEANUP */
  2795. +
  2796. + free(conf->tmp_dir); /*XXX*/
  2797. +
  2798. + pkg_src_list_deinit(&conf->pkg_src_list);
  2799. + pkg_dest_list_deinit(&conf->pkg_dest_list);
  2800. + nv_pair_list_deinit(&conf->arch_list);
  2801. + if (&conf->pkg_hash)
  2802. + pkg_hash_deinit(&conf->pkg_hash);
  2803. + if (&conf->file_hash)
  2804. + hash_table_deinit(&conf->file_hash);
  2805. + if (&conf->obs_file_hash)
  2806. + hash_table_deinit(&conf->obs_file_hash);
  2807. +
  2808. + ipkg_conf_free_string(&conf->offline_root);
  2809. + ipkg_conf_free_string(&conf->offline_root_pre_script_cmd);
  2810. + ipkg_conf_free_string(&conf->offline_root_post_script_cmd);
  2811. +
  2812. + if (conf->verbosity > 1) {
  2813. + int i;
  2814. + hash_table_t *hashes[] = {
  2815. + &conf->pkg_hash,
  2816. + &conf->file_hash,
  2817. + &conf->obs_file_hash };
  2818. + for (i = 0; i < 3; i++) {
  2819. + hash_table_t *hash = hashes[i];
  2820. + int c = 0;
  2821. + int n_conflicts = 0;
  2822. + int j;
  2823. + for (j = 0; j < hash->n_entries; j++) {
  2824. + int len = 0;
  2825. + hash_entry_t *e = &hash->entries[j];
  2826. + if (e->next)
  2827. + n_conflicts++;
  2828. + while (e && e->key) {
  2829. + len++;
  2830. + e = e->next;
  2831. + }
  2832. + if (len > c)
  2833. + c = len;
  2834. + }
  2835. + ipkg_message(conf, IPKG_DEBUG, "hash_table[%s] n_buckets=%d n_elements=%d max_conflicts=%d n_conflicts=%d\n",
  2836. + hash->name, hash->n_entries, hash->n_elements, c, n_conflicts);
  2837. + hash_table_deinit(hash);
  2838. + }
  2839. + }
  2840. +}
  2841. +
  2842. +static int ipkg_conf_set_default_dest(ipkg_conf_t *conf,
  2843. + const char *default_dest_name)
  2844. +{
  2845. + pkg_dest_list_elt_t *iter;
  2846. + pkg_dest_t *dest;
  2847. +
  2848. + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
  2849. + dest = iter->data;
  2850. + if (strcmp(dest->name, default_dest_name) == 0) {
  2851. + conf->default_dest = dest;
  2852. + conf->restrict_to_default_dest = 1;
  2853. + return 0;
  2854. + }
  2855. + }
  2856. +
  2857. + fprintf(stderr, "ERROR: Unknown dest name: `%s'\n", default_dest_name);
  2858. +
  2859. + return 1;
  2860. +}
  2861. +
  2862. +static int set_and_load_pkg_src_list(ipkg_conf_t *conf, pkg_src_list_t *pkg_src_list)
  2863. +{
  2864. + pkg_src_list_elt_t *iter;
  2865. + pkg_src_t *src;
  2866. + char *list_file;
  2867. +
  2868. + for (iter = pkg_src_list->head; iter; iter = iter->next) {
  2869. + src = iter->data;
  2870. + if (src == NULL) {
  2871. + continue;
  2872. + }
  2873. +
  2874. + sprintf_alloc(&list_file, "%s/%s",
  2875. + conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir,
  2876. + src->name);
  2877. +
  2878. + if (file_exists(list_file)) {
  2879. + pkg_hash_add_from_file(conf, list_file, src, NULL, 0);
  2880. + }
  2881. + free(list_file);
  2882. + }
  2883. +
  2884. + return 0;
  2885. +}
  2886. +
  2887. +static int set_and_load_pkg_dest_list(ipkg_conf_t *conf, nv_pair_list_t *nv_pair_list, char *lists_dir )
  2888. +{
  2889. + nv_pair_list_elt_t *iter;
  2890. + nv_pair_t *nv_pair;
  2891. + pkg_dest_t *dest;
  2892. + char *root_dir;
  2893. +
  2894. + for (iter = nv_pair_list->head; iter; iter = iter->next) {
  2895. + nv_pair = iter->data;
  2896. +
  2897. + if (conf->offline_root) {
  2898. + sprintf_alloc(&root_dir, "%s%s", conf->offline_root, nv_pair->value);
  2899. + } else {
  2900. + root_dir = strdup(nv_pair->value);
  2901. + }
  2902. + dest = pkg_dest_list_append(&conf->pkg_dest_list, nv_pair->name, root_dir, lists_dir);
  2903. + free(root_dir);
  2904. + if (dest == NULL) {
  2905. + continue;
  2906. + }
  2907. + if (conf->default_dest == NULL) {
  2908. + conf->default_dest = dest;
  2909. + }
  2910. + if (file_exists(dest->status_file_name)) {
  2911. + pkg_hash_add_from_file(conf, dest->status_file_name,
  2912. + NULL, dest, 1);
  2913. + }
  2914. + }
  2915. +
  2916. + return 0;
  2917. +}
  2918. +
  2919. +static int ipkg_conf_parse_file(ipkg_conf_t *conf, const char *filename,
  2920. + pkg_src_list_t *pkg_src_list,
  2921. + nv_pair_list_t *tmp_dest_nv_pair_list,
  2922. + char **lists_dir)
  2923. +{
  2924. + ipkg_option_t * options;
  2925. + FILE *file = fopen(filename, "r");
  2926. + regex_t valid_line_re, comment_re;
  2927. +#define regmatch_size 12
  2928. + regmatch_t regmatch[regmatch_size];
  2929. +
  2930. + if (ipkg_init_options_array(conf, &options)<0)
  2931. + return ENOMEM;
  2932. +
  2933. + if (file == NULL) {
  2934. + fprintf(stderr, "%s: failed to open %s: %s\n",
  2935. + __FUNCTION__, filename, strerror(errno));
  2936. + free(options);
  2937. + return errno;
  2938. + }
  2939. + ipkg_message(conf, IPKG_NOTICE, "loading conf file %s\n", filename);
  2940. +
  2941. + xregcomp(&comment_re,
  2942. + "^[[:space:]]*(#.*|[[:space:]]*)$",
  2943. + REG_EXTENDED);
  2944. + xregcomp(&valid_line_re, "^[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))([[:space:]]+([^[:space:]]+))?[[:space:]]*$", REG_EXTENDED);
  2945. +
  2946. + while(1) {
  2947. + int line_num = 0;
  2948. + char *line;
  2949. + char *type, *name, *value, *extra;
  2950. +
  2951. + line = file_read_line_alloc(file);
  2952. + line_num++;
  2953. + if (line == NULL) {
  2954. + break;
  2955. + }
  2956. +
  2957. + str_chomp(line);
  2958. +
  2959. + if (regexec(&comment_re, line, 0, 0, 0) == 0) {
  2960. + goto NEXT_LINE;
  2961. + }
  2962. +
  2963. + if (regexec(&valid_line_re, line, regmatch_size, regmatch, 0) == REG_NOMATCH) {
  2964. + str_chomp(line);
  2965. + fprintf(stderr, "%s:%d: Ignoring invalid line: `%s'\n",
  2966. + filename, line_num, line);
  2967. + goto NEXT_LINE;
  2968. + }
  2969. +
  2970. + /* This has to be so ugly to deal with optional quotation marks */
  2971. + if (regmatch[2].rm_so > 0) {
  2972. + type = strndup(line + regmatch[2].rm_so,
  2973. + regmatch[2].rm_eo - regmatch[2].rm_so);
  2974. + } else {
  2975. + type = strndup(line + regmatch[3].rm_so,
  2976. + regmatch[3].rm_eo - regmatch[3].rm_so);
  2977. + }
  2978. + if (regmatch[5].rm_so > 0) {
  2979. + name = strndup(line + regmatch[5].rm_so,
  2980. + regmatch[5].rm_eo - regmatch[5].rm_so);
  2981. + } else {
  2982. + name = strndup(line + regmatch[6].rm_so,
  2983. + regmatch[6].rm_eo - regmatch[6].rm_so);
  2984. + }
  2985. + if (regmatch[8].rm_so > 0) {
  2986. + value = strndup(line + regmatch[8].rm_so,
  2987. + regmatch[8].rm_eo - regmatch[8].rm_so);
  2988. + } else {
  2989. + value = strndup(line + regmatch[9].rm_so,
  2990. + regmatch[9].rm_eo - regmatch[9].rm_so);
  2991. + }
  2992. + extra = NULL;
  2993. + if (regmatch[11].rm_so > 0) {
  2994. + extra = strndup (line + regmatch[11].rm_so,
  2995. + regmatch[11].rm_eo - regmatch[11].rm_so);
  2996. + }
  2997. +
  2998. + /* We use the tmp_dest_nv_pair_list below instead of
  2999. + conf->pkg_dest_list because we might encounter an
  3000. + offline_root option later and that would invalidate the
  3001. + directories we would have computed in
  3002. + pkg_dest_list_init. (We do a similar thing with
  3003. + tmp_src_nv_pair_list for sake of symmetry.) */
  3004. + if (strcmp(type, "option") == 0) {
  3005. + ipkg_conf_set_option(options, name, value);
  3006. + } else if (strcmp(type, "src") == 0) {
  3007. + if (!nv_pair_list_find((nv_pair_list_t *)pkg_src_list, name)) {
  3008. + pkg_src_list_append (pkg_src_list, name, value, extra, 0);
  3009. + } else {
  3010. + ipkg_message(conf, IPKG_ERROR, "ERROR: duplicate src declaration. Skipping:\n\t src %s %s\n",
  3011. + name, value);
  3012. + }
  3013. + } else if (strcmp(type, "src/gz") == 0) {
  3014. + if (!nv_pair_list_find((nv_pair_list_t *)pkg_src_list, name)) {
  3015. + pkg_src_list_append (pkg_src_list, name, value, extra, 1);
  3016. + } else {
  3017. + ipkg_message(conf, IPKG_ERROR, "ERROR: duplicate src declaration. Skipping:\n\t src %s %s\n",
  3018. + name, value);
  3019. + }
  3020. + } else if (strcmp(type, "dest") == 0) {
  3021. + nv_pair_list_append(tmp_dest_nv_pair_list, name, value);
  3022. + } else if (strcmp(type, "lists_dir") == 0) {
  3023. + *lists_dir = realloc(*lists_dir,strlen(value)+1);
  3024. + if (*lists_dir == NULL) {
  3025. + ipkg_message(conf, IPKG_ERROR, "ERROR: Not enough memory\n");
  3026. + free(options);
  3027. + return EINVAL;
  3028. + }
  3029. + sprintf (*lists_dir,"%s",value);
  3030. + } else if (strcmp(type, "arch") == 0) {
  3031. + ipkg_message(conf, IPKG_INFO, "supported arch %s priority (%s)\n", name, value);
  3032. + if (!value) {
  3033. + ipkg_message(conf, IPKG_NOTICE, "defaulting architecture %s priority to 10\n", name);
  3034. + value = strdup("10");
  3035. + }
  3036. + nv_pair_list_append(&conf->arch_list, strdup(name), strdup(value));
  3037. + } else {
  3038. + fprintf(stderr, "WARNING: Ignoring unknown configuration "
  3039. + "parameter: %s %s %s\n", type, name, value);
  3040. + free(options);
  3041. + return EINVAL;
  3042. + }
  3043. +
  3044. + free(type);
  3045. + free(name);
  3046. + free(value);
  3047. + if (extra)
  3048. + free (extra);
  3049. +
  3050. + NEXT_LINE:
  3051. + free(line);
  3052. + }
  3053. +
  3054. + free(options);
  3055. + regfree(&comment_re);
  3056. + regfree(&valid_line_re);
  3057. + fclose(file);
  3058. +
  3059. + return 0;
  3060. +}
  3061. +
  3062. +static int ipkg_conf_set_option(const ipkg_option_t *options,
  3063. + const char *name, const char *value)
  3064. +{
  3065. + int i = 0;
  3066. + while (options[i].name) {
  3067. + if (strcmp(options[i].name, name) == 0) {
  3068. + switch (options[i].type) {
  3069. + case IPKG_OPT_TYPE_BOOL:
  3070. + *((int *)options[i].value) = 1;
  3071. + return 0;
  3072. + case IPKG_OPT_TYPE_INT:
  3073. + if (value) {
  3074. + *((int *)options[i].value) = atoi(value);
  3075. + return 0;
  3076. + } else {
  3077. + printf("%s: Option %s need an argument\n",
  3078. + __FUNCTION__, name);
  3079. + return EINVAL;
  3080. + }
  3081. + case IPKG_OPT_TYPE_STRING:
  3082. + if (value) {
  3083. + *((char **)options[i].value) = strdup(value);
  3084. + return 0;
  3085. + } else {
  3086. + printf("%s: Option %s need an argument\n",
  3087. + __FUNCTION__, name);
  3088. + return EINVAL;
  3089. + }
  3090. + }
  3091. + }
  3092. + i++;
  3093. + }
  3094. +
  3095. + fprintf(stderr, "%s: Unrecognized option: %s=%s\n",
  3096. + __FUNCTION__, name, value);
  3097. + return EINVAL;
  3098. +}
  3099. +
  3100. +int ipkg_conf_write_status_files(ipkg_conf_t *conf)
  3101. +{
  3102. + pkg_dest_list_elt_t *iter;
  3103. + pkg_dest_t *dest;
  3104. + pkg_vec_t *all;
  3105. + pkg_t *pkg;
  3106. + register int i;
  3107. + int err;
  3108. +
  3109. + if (conf->noaction)
  3110. + return 0;
  3111. + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
  3112. + dest = iter->data;
  3113. + dest->status_file = fopen(dest->status_file_tmp_name, "w");
  3114. + if (dest->status_file == NULL) {
  3115. + fprintf(stderr, "%s: Can't open status file: %s for writing: %s\n",
  3116. + __FUNCTION__, dest->status_file_name, strerror(errno));
  3117. + }
  3118. + }
  3119. +
  3120. + all = pkg_vec_alloc();
  3121. + pkg_hash_fetch_available(&conf->pkg_hash, all);
  3122. +
  3123. + for(i = 0; i < all->len; i++) {
  3124. + pkg = all->pkgs[i];
  3125. + /* We don't need most uninstalled packages in the status file */
  3126. + if (pkg->state_status == SS_NOT_INSTALLED
  3127. + && (pkg->state_want == SW_UNKNOWN
  3128. + || pkg->state_want == SW_DEINSTALL
  3129. + || pkg->state_want == SW_PURGE)) {
  3130. + continue;
  3131. + }
  3132. + if (!pkg) {
  3133. + fprintf(stderr, "Null package\n");
  3134. + }
  3135. + if (pkg->dest == NULL) {
  3136. + fprintf(stderr, "%s: ERROR: Can't write status for "
  3137. + "package %s since it has a NULL dest\n",
  3138. + __FUNCTION__, pkg->name);
  3139. + continue;
  3140. + }
  3141. + if (pkg->dest->status_file) {
  3142. + pkg_print_status(pkg, pkg->dest->status_file);
  3143. + }
  3144. + }
  3145. +
  3146. + pkg_vec_free(all);
  3147. +
  3148. + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
  3149. + dest = iter->data;
  3150. + if (dest->status_file) {
  3151. + err = ferror(dest->status_file);
  3152. + fclose(dest->status_file);
  3153. + dest->status_file = NULL;
  3154. + if (!err) {
  3155. + file_move(dest->status_file_tmp_name, dest->status_file_name);
  3156. + } else {
  3157. + fprintf(stderr, "%s: ERROR: An error has occurred writing %s, "
  3158. + "retaining old %s\n", __FUNCTION__,
  3159. + dest->status_file_tmp_name, dest->status_file_name);
  3160. + }
  3161. + }
  3162. + }
  3163. +
  3164. + return 0;
  3165. +}
  3166. +
  3167. +
  3168. +char *root_filename_alloc(ipkg_conf_t *conf, char *filename)
  3169. +{
  3170. + char *root_filename;
  3171. + sprintf_alloc(&root_filename, "%s%s", (conf->offline_root ? conf->offline_root : ""), filename);
  3172. + return root_filename;
  3173. +}
  3174. diff -Nur busybox-1.12.1.orig/archival/libipkg/ipkg_conf.h busybox-1.12.1/archival/libipkg/ipkg_conf.h
  3175. --- busybox-1.12.1.orig/archival/libipkg/ipkg_conf.h 1970-01-01 01:00:00.000000000 +0100
  3176. +++ busybox-1.12.1/archival/libipkg/ipkg_conf.h 2008-10-23 13:41:34.000000000 +0200
  3177. @@ -0,0 +1,107 @@
  3178. +/* ipkg_conf.h - the itsy package management system
  3179. +
  3180. + Carl D. Worth
  3181. +
  3182. + Copyright (C) 2001 University of Southern California
  3183. +
  3184. + This program is free software; you can redistribute it and/or
  3185. + modify it under the terms of the GNU General Public License as
  3186. + published by the Free Software Foundation; either version 2, or (at
  3187. + your option) any later version.
  3188. +
  3189. + This program is distributed in the hope that it will be useful, but
  3190. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3191. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3192. + General Public License for more details.
  3193. +*/
  3194. +
  3195. +#ifndef IPKG_CONF_H
  3196. +#define IPKG_CONF_H
  3197. +
  3198. +typedef struct ipkg_conf ipkg_conf_t;
  3199. +
  3200. +#include "hash_table.h"
  3201. +#include "ipkg.h"
  3202. +#include "args.h"
  3203. +#include "pkg.h"
  3204. +#include "pkg_hash.h"
  3205. +#include "pkg_src_list.h"
  3206. +#include "pkg_dest_list.h"
  3207. +#include "nv_pair_list.h"
  3208. +
  3209. +#define IPKG_CONF_DEFAULT_TMP_DIR_BASE "/tmp"
  3210. +#define IPKG_CONF_TMP_DIR_SUFFIX "ipkg-XXXXXX"
  3211. +#define IPKG_CONF_LISTS_DIR IPKG_STATE_DIR_PREFIX "/lists"
  3212. +#define IPKG_CONF_PENDING_DIR IPKG_STATE_DIR_PREFIX "/pending"
  3213. +
  3214. +/* In case the config file defines no dest */
  3215. +#define IPKG_CONF_DEFAULT_DEST_NAME "root"
  3216. +#define IPKG_CONF_DEFAULT_DEST_ROOT_DIR "/"
  3217. +
  3218. +#define IPKG_CONF_DEFAULT_HASH_LEN 1024
  3219. +
  3220. +struct ipkg_conf
  3221. +{
  3222. + pkg_src_list_t pkg_src_list;
  3223. + pkg_dest_list_t pkg_dest_list;
  3224. + nv_pair_list_t arch_list;
  3225. +
  3226. + int restrict_to_default_dest;
  3227. + pkg_dest_t *default_dest;
  3228. +
  3229. + char *tmp_dir;
  3230. + char *lists_dir;
  3231. + char *pending_dir;
  3232. +
  3233. + /* options */
  3234. + int force_depends;
  3235. + int force_defaults;
  3236. + int force_overwrite;
  3237. + int force_downgrade;
  3238. + int force_reinstall;
  3239. + int force_space;
  3240. + int force_removal_of_dependent_packages;
  3241. + int force_removal_of_essential_packages;
  3242. + int nodeps; /* do not follow dependences */
  3243. + int verbose_wget;
  3244. + int multiple_providers;
  3245. + char *offline_root;
  3246. + char *offline_root_pre_script_cmd;
  3247. + char *offline_root_post_script_cmd;
  3248. + int query_all;
  3249. + int verbosity;
  3250. + int noaction;
  3251. +
  3252. + /* proxy options */
  3253. + char *http_proxy;
  3254. + char *ftp_proxy;
  3255. + char *no_proxy;
  3256. + char *proxy_user;
  3257. + char *proxy_passwd;
  3258. +
  3259. + hash_table_t pkg_hash;
  3260. + hash_table_t file_hash;
  3261. + hash_table_t obs_file_hash;
  3262. +};
  3263. +
  3264. +enum ipkg_option_type {
  3265. + IPKG_OPT_TYPE_BOOL,
  3266. + IPKG_OPT_TYPE_INT,
  3267. + IPKG_OPT_TYPE_STRING
  3268. +};
  3269. +typedef enum ipkg_option_type ipkg_option_type_t;
  3270. +
  3271. +typedef struct ipkg_option ipkg_option_t;
  3272. +struct ipkg_option {
  3273. + const char *name;
  3274. + const ipkg_option_type_t type;
  3275. + const void *value;
  3276. +};
  3277. +
  3278. +int ipkg_conf_init(ipkg_conf_t *conf, const args_t *args);
  3279. +void ipkg_conf_deinit(ipkg_conf_t *conf);
  3280. +
  3281. +int ipkg_conf_write_status_files(ipkg_conf_t *conf);
  3282. +char *root_filename_alloc(ipkg_conf_t *conf, char *filename);
  3283. +
  3284. +#endif
  3285. diff -Nur busybox-1.12.1.orig/archival/libipkg/ipkg_configure.c busybox-1.12.1/archival/libipkg/ipkg_configure.c
  3286. --- busybox-1.12.1.orig/archival/libipkg/ipkg_configure.c 1970-01-01 01:00:00.000000000 +0100
  3287. +++ busybox-1.12.1/archival/libipkg/ipkg_configure.c 2008-10-23 11:41:37.000000000 +0200
  3288. @@ -0,0 +1,40 @@
  3289. +/* ipkg_configure.c - the itsy package management system
  3290. +
  3291. + Carl D. Worth
  3292. +
  3293. + Copyright (C) 2001 University of Southern California
  3294. +
  3295. + This program is free software; you can redistribute it and/or
  3296. + modify it under the terms of the GNU General Public License as
  3297. + published by the Free Software Foundation; either version 2, or (at
  3298. + your option) any later version.
  3299. +
  3300. + This program is distributed in the hope that it will be useful, but
  3301. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3302. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3303. + General Public License for more details.
  3304. +*/
  3305. +
  3306. +#include "ipkg.h"
  3307. +
  3308. +#include "ipkg_configure.h"
  3309. +
  3310. +int ipkg_configure(ipkg_conf_t *conf, pkg_t *pkg)
  3311. +{
  3312. + int err;
  3313. +
  3314. + /* DPKG_INCOMPATIBILITY:
  3315. + dpkg actually does some conffile handling here, rather than at the
  3316. + end of ipkg_install(). Do we care? */
  3317. + /* DPKG_INCOMPATIBILITY:
  3318. + dpkg actually includes a version number to this script call */
  3319. + err = pkg_run_script(conf, pkg, "postinst", "configure");
  3320. + if (err) {
  3321. + printf("ERROR: %s.postinst returned %d\n", pkg->name, err);
  3322. + return err;
  3323. + }
  3324. +
  3325. + ipkg_state_changed++;
  3326. + return 0;
  3327. +}
  3328. +
  3329. diff -Nur busybox-1.12.1.orig/archival/libipkg/ipkg_configure.h busybox-1.12.1/archival/libipkg/ipkg_configure.h
  3330. --- busybox-1.12.1.orig/archival/libipkg/ipkg_configure.h 1970-01-01 01:00:00.000000000 +0100
  3331. +++ busybox-1.12.1/archival/libipkg/ipkg_configure.h 2008-10-23 11:41:37.000000000 +0200
  3332. @@ -0,0 +1,25 @@
  3333. +/* ipkg_configure.h - the itsy package management system
  3334. +
  3335. + Carl D. Worth
  3336. +
  3337. + Copyright (C) 2001 University of Southern California
  3338. +
  3339. + This program is free software; you can redistribute it and/or
  3340. + modify it under the terms of the GNU General Public License as
  3341. + published by the Free Software Foundation; either version 2, or (at
  3342. + your option) any later version.
  3343. +
  3344. + This program is distributed in the hope that it will be useful, but
  3345. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3346. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3347. + General Public License for more details.
  3348. +*/
  3349. +
  3350. +#ifndef IPKG_CONFIGURE_H
  3351. +#define IPKG_CONFIGURE_H
  3352. +
  3353. +#include "ipkg_conf.h"
  3354. +
  3355. +int ipkg_configure(ipkg_conf_t *ipkg_conf, pkg_t *pkg);
  3356. +
  3357. +#endif
  3358. diff -Nur busybox-1.12.1.orig/archival/libipkg/ipkg_download.c busybox-1.12.1/archival/libipkg/ipkg_download.c
  3359. --- busybox-1.12.1.orig/archival/libipkg/ipkg_download.c 1970-01-01 01:00:00.000000000 +0100
  3360. +++ busybox-1.12.1/archival/libipkg/ipkg_download.c 2008-10-23 11:41:37.000000000 +0200
  3361. @@ -0,0 +1,195 @@
  3362. +/* ipkg_download.c - the itsy package management system
  3363. +
  3364. + Carl D. Worth
  3365. +
  3366. + Copyright (C) 2001 University of Southern California
  3367. +
  3368. + This program is free software; you can redistribute it and/or
  3369. + modify it under the terms of the GNU General Public License as
  3370. + published by the Free Software Foundation; either version 2, or (at
  3371. + your option) any later version.
  3372. +
  3373. + This program is distributed in the hope that it will be useful, but
  3374. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3375. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3376. + General Public License for more details.
  3377. +*/
  3378. +
  3379. +#include "ipkg.h"
  3380. +#include "ipkg_download.h"
  3381. +#include "ipkg_message.h"
  3382. +
  3383. +#include "sprintf_alloc.h"
  3384. +#include "xsystem.h"
  3385. +#include "file_util.h"
  3386. +#include "str_util.h"
  3387. +
  3388. +int ipkg_download(ipkg_conf_t *conf, const char *src, const char *dest_file_name)
  3389. +{
  3390. + int err = 0;
  3391. +
  3392. + char *src_basec = strdup(src);
  3393. + char *src_base = basename(src_basec);
  3394. + char *tmp_file_location;
  3395. + char *cmd;
  3396. +
  3397. + ipkg_message(conf,IPKG_NOTICE,"Downloading %s\n", src);
  3398. +
  3399. + fflush(stdout);
  3400. +
  3401. + if (str_starts_with(src, "file:")) {
  3402. + int ret;
  3403. + const char *file_src = src + 5;
  3404. + ipkg_message(conf,IPKG_INFO,"Copying %s to %s...", file_src, dest_file_name);
  3405. + ret = file_copy(src + 5, dest_file_name);
  3406. + ipkg_message(conf,IPKG_INFO,"Done.\n");
  3407. + return ret;
  3408. + }
  3409. +
  3410. + sprintf_alloc(&tmp_file_location, "%s/%s", conf->tmp_dir, src_base);
  3411. + err = unlink(tmp_file_location);
  3412. + if (err && errno != ENOENT) {
  3413. + ipkg_message(conf,IPKG_ERROR, "%s: ERROR: failed to unlink %s: %s\n",
  3414. + __FUNCTION__, tmp_file_location, strerror(errno));
  3415. + free(tmp_file_location);
  3416. + return errno;
  3417. + }
  3418. +
  3419. + if (conf->http_proxy) {
  3420. + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: http_proxy = %s\n", conf->http_proxy);
  3421. + setenv("http_proxy", conf->http_proxy, 1);
  3422. + }
  3423. + if (conf->ftp_proxy) {
  3424. + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: ftp_proxy = %s\n", conf->ftp_proxy);
  3425. + setenv("ftp_proxy", conf->ftp_proxy, 1);
  3426. + }
  3427. + if (conf->no_proxy) {
  3428. + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: no_proxy = %s\n", conf->no_proxy);
  3429. + setenv("no_proxy", conf->no_proxy, 1);
  3430. + }
  3431. +
  3432. + /* XXX: BUG rewrite to use execvp or else busybox's internal wget -Jamey 7/23/2002 */
  3433. + sprintf_alloc(&cmd, "wget --passive-ftp %s %s%s %s%s %s -P %s %s",
  3434. + (conf->http_proxy || conf->ftp_proxy) ? "--proxy=on" : "",
  3435. + conf->proxy_user ? "--proxy-user=" : "",
  3436. + conf->proxy_user ? conf->proxy_user : "",
  3437. + conf->proxy_passwd ? "--proxy-passwd=" : "",
  3438. + conf->proxy_passwd ? conf->proxy_passwd : "",
  3439. + conf->verbose_wget ? "" : "-q",
  3440. + conf->tmp_dir,
  3441. + src);
  3442. + err = xsystem(cmd);
  3443. + if (err) {
  3444. + if (err != -1) {
  3445. + ipkg_message(conf,IPKG_ERROR, "%s: ERROR: Command failed with return value %d: `%s'\n",
  3446. + __FUNCTION__, err, cmd);
  3447. + }
  3448. + unlink(tmp_file_location);
  3449. + free(tmp_file_location);
  3450. + free(src_basec);
  3451. + free(cmd);
  3452. + return EINVAL;
  3453. + }
  3454. + free(cmd);
  3455. +
  3456. + err = file_move(tmp_file_location, dest_file_name);
  3457. +
  3458. + free(tmp_file_location);
  3459. + free(src_basec);
  3460. +
  3461. + if (err) {
  3462. + return err;
  3463. + }
  3464. +
  3465. + return 0;
  3466. +}
  3467. +
  3468. +int ipkg_download_pkg(ipkg_conf_t *conf, pkg_t *pkg, const char *dir)
  3469. +{
  3470. + int err;
  3471. + char *url;
  3472. +
  3473. + if (pkg->src == NULL) {
  3474. + ipkg_message(conf,IPKG_ERROR, "ERROR: Package %s (parent %s) is not available from any configured src.\n",
  3475. + pkg->name, pkg->parent->name);
  3476. + return -1;
  3477. + }
  3478. +
  3479. + sprintf_alloc(&url, "%s/%s", pkg->src->value, pkg->filename);
  3480. +
  3481. + /* XXX: BUG: The pkg->filename might be something like
  3482. + "../../foo.ipk". While this is correct, and exactly what we
  3483. + want to use to construct url above, here we actually need to
  3484. + use just the filename part, without any directory. */
  3485. + sprintf_alloc(&pkg->local_filename, "%s/%s", dir, pkg->filename);
  3486. +
  3487. + err = ipkg_download(conf, url, pkg->local_filename);
  3488. + free(url);
  3489. +
  3490. + return err;
  3491. +}
  3492. +
  3493. +/*
  3494. + * Downloads file from url, installs in package database, return package name.
  3495. + */
  3496. +int ipkg_prepare_url_for_install(ipkg_conf_t *conf, const char *url, char **namep)
  3497. +{
  3498. + int err = 0;
  3499. + pkg_t *pkg;
  3500. + pkg = pkg_new();
  3501. + if (pkg == NULL)
  3502. + return ENOMEM;
  3503. +
  3504. + if (str_starts_with(url, "http://")
  3505. + || str_starts_with(url, "ftp://")) {
  3506. + char *tmp_file;
  3507. + char *file_basec = strdup(url);
  3508. + char *file_base = basename(file_basec);
  3509. +
  3510. + sprintf_alloc(&tmp_file, "%s/%s", conf->tmp_dir, file_base);
  3511. + err = ipkg_download(conf, url, tmp_file);
  3512. + if (err)
  3513. + return err;
  3514. +
  3515. + err = pkg_init_from_file(pkg, tmp_file);
  3516. + if (err)
  3517. + return err;
  3518. + pkg->local_filename = strdup(tmp_file);
  3519. +
  3520. + free(tmp_file);
  3521. + free(file_basec);
  3522. +
  3523. + } else if (strcmp(&url[strlen(url) - 4], IPKG_PKG_EXTENSION) == 0
  3524. + || strcmp(&url[strlen(url) - 4], DPKG_PKG_EXTENSION) == 0) {
  3525. +
  3526. + err = pkg_init_from_file(pkg, url);
  3527. + if (err)
  3528. + return err;
  3529. + pkg->local_filename = strdup(url);
  3530. + ipkg_message(conf, IPKG_DEBUG2, "Package %s provided by hand (%s).\n", pkg->name,pkg->local_filename);
  3531. + pkg->provided_by_hand = 1;
  3532. +
  3533. + } else {
  3534. + pkg_deinit(pkg);
  3535. + free(pkg);
  3536. + return 0;
  3537. + }
  3538. +
  3539. + if (!pkg->architecture) {
  3540. + ipkg_message(conf, IPKG_ERROR, "Package %s has no Architecture defined.\n", pkg->name);
  3541. + return -EINVAL;
  3542. + }
  3543. +
  3544. + pkg->dest = conf->default_dest;
  3545. + pkg->state_want = SW_INSTALL;
  3546. + pkg->state_flag |= SF_PREFER;
  3547. + pkg = hash_insert_pkg(&conf->pkg_hash, pkg, 1,conf);
  3548. + if ( pkg == NULL ){
  3549. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  3550. + return 0;
  3551. + }
  3552. + if (namep) {
  3553. + *namep = strdup(pkg->name);
  3554. + }
  3555. + return 0;
  3556. +}
  3557. diff -Nur busybox-1.12.1.orig/archival/libipkg/ipkg_download.h busybox-1.12.1/archival/libipkg/ipkg_download.h
  3558. --- busybox-1.12.1.orig/archival/libipkg/ipkg_download.h 1970-01-01 01:00:00.000000000 +0100
  3559. +++ busybox-1.12.1/archival/libipkg/ipkg_download.h 2008-10-23 11:41:37.000000000 +0200
  3560. @@ -0,0 +1,30 @@
  3561. +/* ipkg_download.h - the itsy package management system
  3562. +
  3563. + Carl D. Worth
  3564. +
  3565. + Copyright (C) 2001 University of Southern California
  3566. +
  3567. + This program is free software; you can redistribute it and/or
  3568. + modify it under the terms of the GNU General Public License as
  3569. + published by the Free Software Foundation; either version 2, or (at
  3570. + your option) any later version.
  3571. +
  3572. + This program is distributed in the hope that it will be useful, but
  3573. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3574. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3575. + General Public License for more details.
  3576. +*/
  3577. +
  3578. +#ifndef IPKG_DOWNLOAD_H
  3579. +#define IPKG_DOWNLOAD_H
  3580. +
  3581. +#include "ipkg_conf.h"
  3582. +
  3583. +int ipkg_download(ipkg_conf_t *conf, const char *src, const char *dest_file_name);
  3584. +int ipkg_download_pkg(ipkg_conf_t *conf, pkg_t *pkg, const char *dir);
  3585. +/*
  3586. + * Downloads file from url, installs in package database, return package name.
  3587. + */
  3588. +int ipkg_prepare_url_for_install(ipkg_conf_t *conf, const char *url, char **namep);
  3589. +
  3590. +#endif
  3591. diff -Nur busybox-1.12.1.orig/archival/libipkg/ipkg.h busybox-1.12.1/archival/libipkg/ipkg.h
  3592. --- busybox-1.12.1.orig/archival/libipkg/ipkg.h 1970-01-01 01:00:00.000000000 +0100
  3593. +++ busybox-1.12.1/archival/libipkg/ipkg.h 2008-10-23 13:40:24.000000000 +0200
  3594. @@ -0,0 +1,66 @@
  3595. +/* ipkg.h - the itsy package management system
  3596. +
  3597. + Carl D. Worth
  3598. +
  3599. + Copyright (C) 2001 University of Southern California
  3600. +
  3601. + This program is free software; you can redistribute it and/or
  3602. + modify it under the terms of the GNU General Public License as
  3603. + published by the Free Software Foundation; either version 2, or (at
  3604. + your option) any later version.
  3605. +
  3606. + This program is distributed in the hope that it will be useful, but
  3607. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3608. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3609. + General Public License for more details.
  3610. +*/
  3611. +
  3612. +#ifndef IPKG_H
  3613. +#define IPKG_H
  3614. +
  3615. +#include "libbb.h"
  3616. +
  3617. +#include "ipkg_includes.h"
  3618. +#include "ipkg_conf.h"
  3619. +#include "ipkg_message.h"
  3620. +
  3621. +#define IPKG_PKG_EXTENSION ".ipk"
  3622. +#define DPKG_PKG_EXTENSION ".deb"
  3623. +
  3624. +#define IPKG_LEGAL_PKG_NAME_CHARS "abcdefghijklmnopqrstuvwxyz0123456789.+-"
  3625. +#define IPKG_PKG_VERSION_SEP_CHAR '_'
  3626. +
  3627. +#define IPKG_STATE_DIR_PREFIX IPKGLIBDIR"/ipkg"
  3628. +#define IPKG_LISTS_DIR_SUFFIX "lists"
  3629. +#define IPKG_INFO_DIR_SUFFIX "info"
  3630. +#define IPKG_STATUS_FILE_SUFFIX "status"
  3631. +
  3632. +#define IPKG_BACKUP_SUFFIX "-ipkg.backup"
  3633. +
  3634. +#define IPKG_LIST_DESCRIPTION_LENGTH 128
  3635. +
  3636. +#define IPKG_VERSION "1.00"
  3637. +
  3638. +
  3639. +enum ipkg_error {
  3640. + IPKG_SUCCESS = 0,
  3641. + IPKG_PKG_DEPS_UNSATISFIED,
  3642. + IPKG_PKG_IS_ESSENTIAL,
  3643. + IPKG_PKG_HAS_DEPENDENTS,
  3644. + IPKG_PKG_HAS_NO_CANDIDATE
  3645. +};
  3646. +typedef enum ipkg_error ipkg_error_t;
  3647. +
  3648. +extern int ipkg_state_changed;
  3649. +
  3650. +
  3651. +struct errlist {
  3652. + char * errmsg;
  3653. + struct errlist * next;
  3654. +} ;
  3655. +
  3656. +extern struct errlist* error_list;
  3657. +
  3658. +extern ipkg_conf_t *global_conf;
  3659. +
  3660. +#endif
  3661. diff -Nur busybox-1.12.1.orig/archival/libipkg/ipkg_includes.h busybox-1.12.1/archival/libipkg/ipkg_includes.h
  3662. --- busybox-1.12.1.orig/archival/libipkg/ipkg_includes.h 1970-01-01 01:00:00.000000000 +0100
  3663. +++ busybox-1.12.1/archival/libipkg/ipkg_includes.h 2008-10-23 11:41:37.000000000 +0200
  3664. @@ -0,0 +1,79 @@
  3665. +#ifndef IPKG_INCLUDES_H
  3666. +#define IPKG_INCLUDES_H
  3667. +
  3668. +/* Define to 1 if you have the <memory.h> header file. */
  3669. +#define HAVE_MEMORY_H 1
  3670. +
  3671. +/* Define to 1 if you have the <regex.h> header file. */
  3672. +#define HAVE_REGEX_H 1
  3673. +
  3674. +/* Define to 1 if you have the <stdlib.h> header file. */
  3675. +#define HAVE_STDLIB_H 1
  3676. +
  3677. +/* Define to 1 if you have the <strings.h> header file. */
  3678. +#define HAVE_STRINGS_H 1
  3679. +
  3680. +/* Define to 1 if you have the <string.h> header file. */
  3681. +#define HAVE_STRING_H 1
  3682. +
  3683. +/* Define to 1 if you have the <sys/stat.h> header file. */
  3684. +#define HAVE_SYS_STAT_H 1
  3685. +
  3686. +/* Define to 1 if you have <sys/wait.h> that is POSIX.1 compatible. */
  3687. +#define HAVE_SYS_WAIT_H 1
  3688. +
  3689. +/* Define to 1 if you have the <unistd.h> header file. */
  3690. +#define HAVE_UNISTD_H 1
  3691. +
  3692. +/* Define to 1 if you have the ANSI C header files. */
  3693. +#define STDC_HEADERS 1
  3694. +
  3695. +
  3696. +#include <stdio.h>
  3697. +
  3698. +#if STDC_HEADERS
  3699. +# include <stdlib.h>
  3700. +# include <stdarg.h>
  3701. +# include <stddef.h>
  3702. +# include <ctype.h>
  3703. +# include <errno.h>
  3704. +#else
  3705. +# if HAVE_STDLIB_H
  3706. +# include <stdlib.h>
  3707. +# endif
  3708. +#endif
  3709. +
  3710. +#if HAVE_REGEX_H
  3711. +# include <regex.h>
  3712. +#endif
  3713. +
  3714. +#if HAVE_STRING_H
  3715. +# if !STDC_HEADERS && HAVE_MEMORY_H
  3716. +# include <memory.h>
  3717. +# endif
  3718. +/* XXX: What's the right way to pick up GNU's strndup declaration? */
  3719. +# if __GNUC__
  3720. +# define __USE_GNU 1
  3721. +# endif
  3722. +# include <string.h>
  3723. +# undef __USE_GNU
  3724. +#endif
  3725. +
  3726. +#if HAVE_STRINGS_H
  3727. +# include <strings.h>
  3728. +#endif
  3729. +
  3730. +#if HAVE_SYS_STAT_H
  3731. +# include <sys/stat.h>
  3732. +#endif
  3733. +
  3734. +#if HAVE_SYS_WAIT_H
  3735. +# include <sys/wait.h>
  3736. +#endif
  3737. +
  3738. +#if HAVE_UNISTD_H
  3739. +# include <sys/types.h>
  3740. +# include <unistd.h>
  3741. +#endif
  3742. +
  3743. +#endif /* IPKG_INCLUDES_H */
  3744. diff -Nur busybox-1.12.1.orig/archival/libipkg/ipkg_install.c busybox-1.12.1/archival/libipkg/ipkg_install.c
  3745. --- busybox-1.12.1.orig/archival/libipkg/ipkg_install.c 1970-01-01 01:00:00.000000000 +0100
  3746. +++ busybox-1.12.1/archival/libipkg/ipkg_install.c 2008-10-23 15:07:04.000000000 +0200
  3747. @@ -0,0 +1,1982 @@
  3748. +/* ipkg_install.c - the itsy package management system
  3749. +
  3750. + Carl D. Worth
  3751. +
  3752. + Copyright (C) 2001 University of Southern California
  3753. +
  3754. + This program is free software; you can redistribute it and/or
  3755. + modify it under the terms of the GNU General Public License as
  3756. + published by the Free Software Foundation; either version 2, or (at
  3757. + your option) any later version.
  3758. +
  3759. + This program is distributed in the hope that it will be useful, but
  3760. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3761. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3762. + General Public License for more details.
  3763. +*/
  3764. +
  3765. +#include "ipkg.h"
  3766. +#include <errno.h>
  3767. +#include <dirent.h>
  3768. +#include <glob.h>
  3769. +#include <time.h>
  3770. +#include <signal.h>
  3771. +typedef void (*sighandler_t)(int);
  3772. +
  3773. +#include "pkg.h"
  3774. +#include "pkg_hash.h"
  3775. +#include "pkg_extract.h"
  3776. +
  3777. +#include "ipkg_install.h"
  3778. +#include "ipkg_configure.h"
  3779. +#include "ipkg_download.h"
  3780. +#include "ipkg_remove.h"
  3781. +
  3782. +#include "ipkg_utils.h"
  3783. +#include "ipkg_message.h"
  3784. +
  3785. +#include "sprintf_alloc.h"
  3786. +#include "file_util.h"
  3787. +#include "str_util.h"
  3788. +#include "xsystem.h"
  3789. +#include "user.h"
  3790. +
  3791. +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg);
  3792. +static int verify_pkg_installable(ipkg_conf_t *conf, pkg_t *pkg);
  3793. +static int unpack_pkg_control_files(ipkg_conf_t *conf, pkg_t *pkg);
  3794. +
  3795. +/*
  3796. +static int prerm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3797. +static int prerm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3798. +static int prerm_deconfigure_conflictors(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors);
  3799. +static int prerm_deconfigure_conflictors_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors);
  3800. +static int preinst_configure_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3801. +static int check_data_file_clashes_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3802. +static int postrm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3803. +static int remove_disappeared(ipkg_conf_t *conf, pkg_t *pkg);
  3804. +static int postrm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3805. +*/
  3806. +static int preinst_configure(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3807. +static int check_data_file_clashes(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3808. +static int check_data_file_clashes_change(ipkg_conf_t *conf, pkg_t *pkg);
  3809. +static int backup_modified_conffiles(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3810. +static int backup_modified_conffiles_unwind(pkg_t *pkg, pkg_t *old_pkg);
  3811. +
  3812. +static int remove_obsolesced_files(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3813. +static int install_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3814. +static int install_data_files(ipkg_conf_t *conf, pkg_t *pkg);
  3815. +static int resolve_conffiles(ipkg_conf_t *conf, pkg_t *pkg);
  3816. +
  3817. +static int cleanup_temporary_files(ipkg_conf_t *conf, pkg_t *pkg);
  3818. +
  3819. +static int user_prefers_old_conffile(const char *file, const char *backup);
  3820. +
  3821. +static char *backup_filename_alloc(const char *file_name);
  3822. +static int backup_make_backup(ipkg_conf_t *conf, const char *file_name);
  3823. +static int backup_exists_for(const char *file_name);
  3824. +static int backup_remove(const char *file_name);
  3825. +
  3826. +int pkg_get_installed_replacees(pkg_t *pkg, pkg_vec_t *installed_replacees);
  3827. +int pkg_remove_installed_replacees(ipkg_conf_t *conf, pkg_vec_t *replacees);
  3828. +int pkg_remove_installed_replacees_unwind(ipkg_conf_t *conf, pkg_vec_t *replacees);
  3829. +
  3830. +int ipkg_install_from_file(ipkg_conf_t *conf, const char *filename)
  3831. +{
  3832. + int err, cmp;
  3833. + pkg_t *pkg, *old;
  3834. + char *old_version, *new_version;
  3835. +
  3836. + pkg = pkg_new();
  3837. + if (pkg == NULL) {
  3838. + return ENOMEM;
  3839. + }
  3840. +
  3841. + err = pkg_init_from_file(pkg, filename);
  3842. + if (err) {
  3843. + return err;
  3844. + }
  3845. +
  3846. + if (!pkg->architecture) {
  3847. + ipkg_message(conf, IPKG_ERROR, "Package %s has no Architecture defined.\n", pkg->name);
  3848. + return -EINVAL;
  3849. + }
  3850. +
  3851. + /* XXX: CLEANUP: hash_insert_pkg has a nasty side effect of possibly
  3852. + freeing the pkg that we pass in. It might be nice to clean this up
  3853. + if possible. */
  3854. + pkg = hash_insert_pkg(&conf->pkg_hash, pkg, 1,conf);
  3855. + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name);
  3856. +
  3857. + pkg->local_filename = strdup(filename);
  3858. +
  3859. + if (old) {
  3860. + old_version = pkg_version_str_alloc(old);
  3861. + new_version = pkg_version_str_alloc(pkg);
  3862. +
  3863. + cmp = pkg_compare_versions(old, pkg);
  3864. + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
  3865. + cmp = -1 ; /* then we force ipkg to downgrade */
  3866. + /* We need to use a value < 0 because in the 0 case we are asking to */
  3867. + /* reinstall, and some check could fail asking the "force-reinstall" option */
  3868. + }
  3869. + if (cmp > 0) {
  3870. + ipkg_message(conf, IPKG_NOTICE,
  3871. + "Not downgrading package %s on %s from %s to %s.\n",
  3872. + old->name, old->dest->name, old_version, new_version);
  3873. + pkg->state_want = SW_DEINSTALL;
  3874. + pkg->state_flag |= SF_OBSOLETE;
  3875. + free(old_version);
  3876. + free(new_version);
  3877. + return 0;
  3878. + } else {
  3879. + free(old_version);
  3880. + free(new_version);
  3881. + }
  3882. + }
  3883. +
  3884. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
  3885. + return ipkg_install_pkg(conf, pkg,0);
  3886. +}
  3887. +
  3888. +ipkg_error_t ipkg_install_by_name(ipkg_conf_t *conf, const char *pkg_name)
  3889. +{
  3890. + int cmp;
  3891. + pkg_t *old, *new;
  3892. + char *old_version, *new_version;
  3893. +
  3894. + ipkg_message(conf, IPKG_DEBUG2, " Getting old from pkg_hash_fetch \n" );
  3895. + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg_name);
  3896. + if ( old )
  3897. + ipkg_message(conf, IPKG_DEBUG2, " Old versions from pkg_hash_fetch %s \n", old->version );
  3898. +
  3899. + ipkg_message(conf, IPKG_DEBUG2, " Getting new from pkg_hash_fetch \n" );
  3900. + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, pkg_name);
  3901. + if ( new )
  3902. + ipkg_message(conf, IPKG_DEBUG2, " New versions from pkg_hash_fetch %s \n", new->version );
  3903. +
  3904. +/* Pigi Basically here is broken the version stuff.
  3905. + What's happening is that nothing provide the version to differents
  3906. + functions, so the returned struct is always the latest.
  3907. + That's why the install by name don't work.
  3908. +*/
  3909. + ipkg_message(conf, IPKG_DEBUG2, " Versions from pkg_hash_fetch in %s ", __FUNCTION__ );
  3910. +
  3911. + if ( old )
  3912. + ipkg_message(conf, IPKG_DEBUG2, " old %s ", old->version );
  3913. + if ( new )
  3914. + ipkg_message(conf, IPKG_DEBUG2, " new %s ", new->version );
  3915. + ipkg_message(conf, IPKG_DEBUG2, " \n");
  3916. +
  3917. + if (new == NULL) {
  3918. + return IPKG_PKG_HAS_NO_CANDIDATE;
  3919. + }
  3920. +
  3921. + new->state_flag |= SF_USER;
  3922. + if (old) {
  3923. + old_version = pkg_version_str_alloc(old);
  3924. + new_version = pkg_version_str_alloc(new);
  3925. +
  3926. + cmp = pkg_compare_versions(old, new);
  3927. + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
  3928. + ipkg_message(conf, IPKG_DEBUG, " Forcing downgrade \n");
  3929. + cmp = -1 ; /* then we force ipkg to downgrade */
  3930. + /* We need to use a value < 0 because in the 0 case we are asking to */
  3931. + /* reinstall, and some check could fail asking the "force-reinstall" option */
  3932. + }
  3933. + ipkg_message(conf, IPKG_DEBUG,
  3934. + "Comparing visible versions of pkg %s:"
  3935. + "\n\t%s is installed "
  3936. + "\n\t%s is available "
  3937. + "\n\t%d was comparison result\n",
  3938. + pkg_name, old_version, new_version, cmp);
  3939. + if (cmp == 0 && !conf->force_reinstall) {
  3940. + ipkg_message(conf, IPKG_NOTICE,
  3941. + "Package %s (%s) installed in %s is up to date.\n",
  3942. + old->name, old_version, old->dest->name);
  3943. + free(old_version);
  3944. + free(new_version);
  3945. + return 0;
  3946. + } else if (cmp > 0) {
  3947. + ipkg_message(conf, IPKG_NOTICE,
  3948. + "Not downgrading package %s on %s from %s to %s.\n",
  3949. + old->name, old->dest->name, old_version, new_version);
  3950. + free(old_version);
  3951. + free(new_version);
  3952. + return 0;
  3953. + } else if (cmp < 0) {
  3954. + new->dest = old->dest;
  3955. + old->state_want = SW_DEINSTALL; /* Here probably the problem for bug 1277 */
  3956. + }
  3957. + }
  3958. +
  3959. + /* XXX: CLEANUP: The error code of ipkg_install_by_name is really
  3960. + supposed to be an ipkg_error_t, but ipkg_install_pkg could
  3961. + return any kind of integer, (might be errno from a syscall,
  3962. + etc.). This is a real mess and will need to be cleaned up if
  3963. + anyone ever wants to make a nice libipkg. */
  3964. +
  3965. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
  3966. + return ipkg_install_pkg(conf, new,0);
  3967. +}
  3968. +
  3969. +ipkg_error_t ipkg_install_multi_by_name(ipkg_conf_t *conf, const char *pkg_name)
  3970. +{
  3971. + abstract_pkg_vec_t *providers = pkg_hash_fetch_all_installation_candidates (&conf->pkg_hash, pkg_name);
  3972. + int i;
  3973. + ipkg_error_t err;
  3974. + abstract_pkg_t *ppkg ;
  3975. +
  3976. + if (providers == NULL)
  3977. + return IPKG_PKG_HAS_NO_CANDIDATE;
  3978. +
  3979. + for (i = 0; i < providers->len; i++) {
  3980. + ppkg = abstract_pkg_vec_get(providers, i);
  3981. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_by_name %d \n",__FUNCTION__, i);
  3982. + err = ipkg_install_by_name(conf, ppkg->name);
  3983. + if (err)
  3984. + return err;
  3985. +/* XXX Maybe ppkg should be freed ? */
  3986. + }
  3987. + return 0;
  3988. +}
  3989. +
  3990. +/*
  3991. + * Walk dependence graph starting with pkg, collect packages to be
  3992. + * installed into pkgs_needed, in dependence order.
  3993. + */
  3994. +int pkg_mark_dependencies_for_installation(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *pkgs_needed)
  3995. +{
  3996. + int i, err;
  3997. + pkg_vec_t *depends = pkg_vec_alloc();
  3998. + char **unresolved = NULL;
  3999. + int ndepends;
  4000. +
  4001. + ndepends = pkg_hash_fetch_unsatisfied_dependencies(conf,
  4002. + pkg, depends,
  4003. + &unresolved);
  4004. +
  4005. + if (unresolved) {
  4006. + ipkg_message(conf, IPKG_ERROR,
  4007. + "%s: Cannot satisfy the following dependencies for %s:\n\t",
  4008. + conf->force_depends ? "Warning" : "ERROR", pkg->name);
  4009. + while (*unresolved) {
  4010. + ipkg_message(conf, IPKG_ERROR, " %s", *unresolved);
  4011. + unresolved++;
  4012. + }
  4013. + ipkg_message(conf, IPKG_ERROR, "\n");
  4014. + if (! conf->force_depends) {
  4015. + ipkg_message(conf, IPKG_INFO,
  4016. + "This could mean that your package list is out of date or that the packages\n"
  4017. + "mentioned above do not yet exist (try 'ipkg update'). To proceed in spite\n"
  4018. + "of this problem try again with the '-force-depends' option.\n");
  4019. + pkg_vec_free(depends);
  4020. + return IPKG_PKG_DEPS_UNSATISFIED;
  4021. + }
  4022. + }
  4023. +
  4024. + if (ndepends <= 0) {
  4025. + pkg_vec_free(depends);
  4026. + return 0;
  4027. + }
  4028. +
  4029. + for (i = 0; i < depends->len; i++) {
  4030. + pkg_t *dep = depends->pkgs[i];
  4031. + /* The package was uninstalled when we started, but another
  4032. + dep earlier in this loop may have depended on it and pulled
  4033. + it in, so check first. */
  4034. + if ((dep->state_status != SS_INSTALLED)
  4035. + && (dep->state_status != SS_UNPACKED)
  4036. + && (dep->state_want != SW_INSTALL)) {
  4037. +
  4038. + /* Mark packages as to-be-installed */
  4039. + dep->state_want = SW_INSTALL;
  4040. +
  4041. + /* Dependencies should be installed the same place as pkg */
  4042. + if (dep->dest == NULL) {
  4043. + dep->dest = pkg->dest;
  4044. + }
  4045. +
  4046. + err = pkg_mark_dependencies_for_installation(conf, dep, pkgs_needed);
  4047. + if (err) {
  4048. + pkg_vec_free(depends);
  4049. + return err;
  4050. + }
  4051. + }
  4052. + }
  4053. + if (pkgs_needed)
  4054. + pkg_vec_insert(pkgs_needed, pkg);
  4055. +
  4056. + pkg_vec_free(depends);
  4057. +
  4058. + return 0;
  4059. +}
  4060. +
  4061. +int name_mark_dependencies_for_installation(ipkg_conf_t *conf, const char *pkg_name, pkg_vec_t *pkgs_needed)
  4062. +{
  4063. + int cmp;
  4064. + pkg_t *old, *new;
  4065. + char *old_version, *new_version;
  4066. +
  4067. + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg_name);
  4068. +
  4069. + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, pkg_name);
  4070. + if (new == NULL) {
  4071. + return IPKG_PKG_HAS_NO_CANDIDATE;
  4072. + }
  4073. + if (old) {
  4074. + old_version = pkg_version_str_alloc(old);
  4075. + new_version = pkg_version_str_alloc(new);
  4076. +
  4077. + cmp = pkg_compare_versions(old, new);
  4078. + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
  4079. + ipkg_message(conf, IPKG_DEBUG, " Forcing downgrade ");
  4080. + cmp = -1 ; /* then we force ipkg to downgrade */
  4081. + /* We need to use a value < 0 because in the 0 case we are asking to */
  4082. + /* reinstall, and some check could fail asking the "force-reinstall" option */
  4083. + }
  4084. + ipkg_message(conf, IPKG_DEBUG,
  4085. + "comparing visible versions of pkg %s:"
  4086. + "\n\t%s is installed "
  4087. + "\n\t%s is available "
  4088. + "\n\t%d was comparison result\n",
  4089. + pkg_name, old_version, new_version, cmp);
  4090. + if (cmp == 0 && !conf->force_reinstall) {
  4091. + ipkg_message(conf, IPKG_NOTICE,
  4092. + "Package %s (%s) installed in %s is up to date.\n",
  4093. + old->name, old_version, old->dest->name);
  4094. + free(old_version);
  4095. + free(new_version);
  4096. + return 0;
  4097. + } else if (cmp > 0) {
  4098. + ipkg_message(conf, IPKG_NOTICE,
  4099. + "Not downgrading package %s on %s from %s to %s.\n",
  4100. + old->name, old->dest->name, old_version, new_version);
  4101. + free(old_version);
  4102. + free(new_version);
  4103. + return 0;
  4104. + } else if (cmp < 0) {
  4105. + new->dest = old->dest;
  4106. + old->state_want = SW_DEINSTALL;
  4107. + old->state_flag |= SF_OBSOLETE;
  4108. + }
  4109. + }
  4110. + return pkg_mark_dependencies_for_installation(conf, new, pkgs_needed);
  4111. +}
  4112. +
  4113. +
  4114. +
  4115. +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg)
  4116. +{
  4117. + int i, err;
  4118. + pkg_vec_t *depends = pkg_vec_alloc();
  4119. + pkg_t *dep;
  4120. + char **unresolved = NULL;
  4121. + int ndepends;
  4122. +
  4123. + ndepends = pkg_hash_fetch_unsatisfied_dependencies(conf,
  4124. + pkg, depends,
  4125. + &unresolved);
  4126. +
  4127. + if (unresolved) {
  4128. + ipkg_message(conf, IPKG_ERROR,
  4129. + "%s: Cannot satisfy the following dependencies for %s:\n\t",
  4130. + conf->force_depends ? "Warning" : "ERROR", pkg->name);
  4131. + while (*unresolved) {
  4132. + ipkg_message(conf, IPKG_ERROR, " %s", *unresolved);
  4133. + unresolved++;
  4134. + }
  4135. + ipkg_message(conf, IPKG_ERROR, "\n");
  4136. + if (! conf->force_depends) {
  4137. + ipkg_message(conf, IPKG_INFO,
  4138. + "This could mean that your package list is out of date or that the packages\n"
  4139. + "mentioned above do not yet exist (try 'ipkg update'). To proceed in spite\n"
  4140. + "of this problem try again with the '-force-depends' option.\n");
  4141. + pkg_vec_free(depends);
  4142. + return IPKG_PKG_DEPS_UNSATISFIED;
  4143. + }
  4144. + }
  4145. +
  4146. + if (ndepends <= 0) {
  4147. + return 0;
  4148. + }
  4149. +
  4150. + /* Mark packages as to-be-installed */
  4151. + for (i=0; i < depends->len; i++) {
  4152. + /* Dependencies should be installed the same place as pkg */
  4153. + if (depends->pkgs[i]->dest == NULL) {
  4154. + depends->pkgs[i]->dest = pkg->dest;
  4155. + }
  4156. + depends->pkgs[i]->state_want = SW_INSTALL;
  4157. + }
  4158. +
  4159. + for (i = 0; i < depends->len; i++) {
  4160. + dep = depends->pkgs[i];
  4161. + /* The package was uninstalled when we started, but another
  4162. + dep earlier in this loop may have depended on it and pulled
  4163. + it in, so check first. */
  4164. + if ((dep->state_status != SS_INSTALLED)
  4165. + && (dep->state_status != SS_UNPACKED)) {
  4166. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
  4167. + err = ipkg_install_pkg(conf, dep,0);
  4168. + if (err) {
  4169. + pkg_vec_free(depends);
  4170. + return err;
  4171. + }
  4172. + }
  4173. + }
  4174. +
  4175. + pkg_vec_free(depends);
  4176. +
  4177. + return 0;
  4178. +}
  4179. +
  4180. +
  4181. +/* check all packages have their dependences satisfied, e.g., in case an upgraded package split */
  4182. +int ipkg_satisfy_all_dependences(ipkg_conf_t *conf)
  4183. +{
  4184. + if (conf->nodeps == 0) {
  4185. + int i;
  4186. + pkg_vec_t *installed = pkg_vec_alloc();
  4187. + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
  4188. + for (i = 0; i < installed->len; i++) {
  4189. + pkg_t *pkg = installed->pkgs[i];
  4190. + satisfy_dependencies_for(conf, pkg);
  4191. + }
  4192. + pkg_vec_free(installed);
  4193. + }
  4194. + return 0;
  4195. +}
  4196. +
  4197. +
  4198. +
  4199. +static int check_conflicts_for(ipkg_conf_t *conf, pkg_t *pkg)
  4200. +{
  4201. + int i;
  4202. + pkg_vec_t *conflicts = NULL;
  4203. + int level;
  4204. + const char *prefix;
  4205. + if (conf->force_depends) {
  4206. + level = IPKG_NOTICE;
  4207. + prefix = "Warning";
  4208. + } else {
  4209. + level = IPKG_ERROR;
  4210. + prefix = "ERROR";
  4211. + }
  4212. +
  4213. + if (!conf->force_depends)
  4214. + conflicts = (pkg_vec_t *)pkg_hash_fetch_conflicts(pkg);
  4215. +
  4216. + if (conflicts) {
  4217. + ipkg_message(conf, level,
  4218. + "%s: The following packages conflict with %s:\n\t", prefix, pkg->name);
  4219. + i = 0;
  4220. + while (i < conflicts->len)
  4221. + ipkg_message(conf, level, " %s", conflicts->pkgs[i++]->name);
  4222. + ipkg_message(conf, level, "\n");
  4223. + pkg_vec_free(conflicts);
  4224. + return IPKG_PKG_DEPS_UNSATISFIED;
  4225. + }
  4226. + return 0;
  4227. +}
  4228. +
  4229. +static int update_file_ownership(ipkg_conf_t *conf, pkg_t *new_pkg, pkg_t *old_pkg)
  4230. +{
  4231. + str_list_t *new_list = pkg_get_installed_files(new_pkg);
  4232. + str_list_elt_t *iter;
  4233. +
  4234. + for (iter = new_list->head; iter; iter = iter->next) {
  4235. + char *new_file = iter->data;
  4236. + pkg_t *owner = file_hash_get_file_owner(conf, new_file);
  4237. + if (!new_file)
  4238. + ipkg_message(conf, IPKG_ERROR, "Null new_file for new_pkg=%s\n", new_pkg->name);
  4239. + if (!owner || (owner == old_pkg))
  4240. + file_hash_set_file_owner(conf, new_file, new_pkg);
  4241. + }
  4242. + if (old_pkg) {
  4243. + str_list_t *old_list = pkg_get_installed_files(old_pkg);
  4244. + for (iter = old_list->head; iter; iter = iter->next) {
  4245. + char *old_file = iter->data;
  4246. + pkg_t *owner = file_hash_get_file_owner(conf, old_file);
  4247. + if (owner == old_pkg) {
  4248. + /* obsolete */
  4249. + hash_table_insert(&conf->obs_file_hash, old_file, old_pkg);
  4250. + }
  4251. + }
  4252. + }
  4253. + return 0;
  4254. +}
  4255. +
  4256. +static int verify_pkg_installable(ipkg_conf_t *conf, pkg_t *pkg)
  4257. +{
  4258. + /* XXX: FEATURE: Anything else needed here? Maybe a check on free space? */
  4259. +
  4260. + /* sma 6.20.02: yup; here's the first bit */
  4261. + /*
  4262. + * XXX: BUG easy for cworth
  4263. + * 1) please point the call below to the correct current root destination
  4264. + * 2) we need to resolve how to check the required space for a pending pkg,
  4265. + * my diddling with the .ipk file size below isn't going to cut it.
  4266. + * 3) return a proper error code instead of 1
  4267. + */
  4268. + int comp_size, blocks_available;
  4269. +
  4270. + if (!conf->force_space && pkg->installed_size != NULL) {
  4271. + blocks_available = get_available_blocks(conf->default_dest->root_dir);
  4272. +
  4273. + comp_size = strtoul(pkg->installed_size, NULL, 0);
  4274. + /* round up a blocks count without doing fancy-but-slow casting jazz */
  4275. + comp_size = (int)((comp_size + 1023) / 1024);
  4276. +
  4277. + if (comp_size >= blocks_available) {
  4278. + ipkg_message(conf, IPKG_ERROR,
  4279. + "Only have %d available blocks on filesystem %s, pkg %s needs %d\n",
  4280. + blocks_available, conf->default_dest->root_dir, pkg->name, comp_size);
  4281. + return ENOSPC;
  4282. + }
  4283. + }
  4284. + return 0;
  4285. +}
  4286. +
  4287. +static int unpack_pkg_control_files(ipkg_conf_t *conf, pkg_t *pkg)
  4288. +{
  4289. + int err;
  4290. + char *conffiles_file_name;
  4291. + char *root_dir;
  4292. + FILE *conffiles_file;
  4293. +
  4294. + sprintf_alloc(&pkg->tmp_unpack_dir, "%s/%s-XXXXXX", conf->tmp_dir, pkg->name);
  4295. +
  4296. + pkg->tmp_unpack_dir = mkdtemp(pkg->tmp_unpack_dir);
  4297. + if (pkg->tmp_unpack_dir == NULL) {
  4298. + ipkg_message(conf, IPKG_ERROR,
  4299. + "%s: Failed to create temporary directory '%s': %s\n",
  4300. + __FUNCTION__, pkg->tmp_unpack_dir, strerror(errno));
  4301. + return errno;
  4302. + }
  4303. +
  4304. + err = pkg_extract_control_files_to_dir(pkg, pkg->tmp_unpack_dir);
  4305. + if (err) {
  4306. + return err;
  4307. + }
  4308. +
  4309. + /* XXX: CLEANUP: There might be a cleaner place to read in the
  4310. + conffiles. Seems like I should be able to get everything to go
  4311. + through pkg_init_from_file. If so, maybe it would make sense to
  4312. + move all of unpack_pkg_control_files to that function. */
  4313. +
  4314. + /* Don't need to re-read conffiles if we already have it */
  4315. + if (pkg->conffiles.head) {
  4316. + return 0;
  4317. + }
  4318. +
  4319. + sprintf_alloc(&conffiles_file_name, "%s/conffiles", pkg->tmp_unpack_dir);
  4320. + if (! file_exists(conffiles_file_name)) {
  4321. + free(conffiles_file_name);
  4322. + return 0;
  4323. + }
  4324. +
  4325. + conffiles_file = fopen(conffiles_file_name, "r");
  4326. + if (conffiles_file == NULL) {
  4327. + fprintf(stderr, "%s: failed to open %s: %s\n",
  4328. + __FUNCTION__, conffiles_file_name, strerror(errno));
  4329. + free(conffiles_file_name);
  4330. + return errno;
  4331. + }
  4332. + free(conffiles_file_name);
  4333. +
  4334. + while (1) {
  4335. + char *cf_name;
  4336. + char *cf_name_in_dest;
  4337. +
  4338. + cf_name = file_read_line_alloc(conffiles_file);
  4339. + if (cf_name == NULL) {
  4340. + break;
  4341. + }
  4342. + str_chomp(cf_name);
  4343. + if (cf_name[0] == '\0') {
  4344. + continue;
  4345. + }
  4346. +
  4347. + /* Prepend dest->root_dir to conffile name.
  4348. + Take pains to avoid multiple slashes. */
  4349. + root_dir = pkg->dest->root_dir;
  4350. + if (conf->offline_root)
  4351. + /* skip the offline_root prefix */
  4352. + root_dir = pkg->dest->root_dir + strlen(conf->offline_root);
  4353. + sprintf_alloc(&cf_name_in_dest, "%s%s", root_dir,
  4354. + cf_name[0] == '/' ? (cf_name + 1) : cf_name);
  4355. +
  4356. + /* Can't get an md5sum now, (file isn't extracted yet).
  4357. + We'll wait until resolve_conffiles */
  4358. + conffile_list_append(&pkg->conffiles, cf_name_in_dest, NULL);
  4359. +
  4360. + free(cf_name);
  4361. + free(cf_name_in_dest);
  4362. + }
  4363. +
  4364. + fclose(conffiles_file);
  4365. +
  4366. + return 0;
  4367. +}
  4368. +
  4369. +/* returns number of installed replacees */
  4370. +int pkg_get_installed_replacees(pkg_t *pkg, pkg_vec_t *installed_replacees)
  4371. +{
  4372. + abstract_pkg_t **replaces = pkg->replaces;
  4373. + int replaces_count = pkg->replaces_count;
  4374. + int i, j;
  4375. + for (i = 0; i < replaces_count; i++) {
  4376. + abstract_pkg_t *ab_pkg = replaces[i];
  4377. + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
  4378. + if (pkg_vec) {
  4379. + for (j = 0; j < pkg_vec->len; j++) {
  4380. + pkg_t *replacee = pkg_vec->pkgs[j];
  4381. + if (!pkg_conflicts(pkg, replacee))
  4382. + continue;
  4383. + if (replacee->state_status == SS_INSTALLED) {
  4384. + pkg_vec_insert(installed_replacees, replacee);
  4385. + }
  4386. + }
  4387. + }
  4388. + }
  4389. + return installed_replacees->len;
  4390. +}
  4391. +
  4392. +int pkg_remove_installed_replacees(ipkg_conf_t *conf, pkg_vec_t *replacees)
  4393. +{
  4394. + int i;
  4395. + int replaces_count = replacees->len;
  4396. + for (i = 0; i < replaces_count; i++) {
  4397. + pkg_t *replacee = replacees->pkgs[i];
  4398. + int err;
  4399. + replacee->state_flag |= SF_REPLACE; /* flag it so remove won't complain */
  4400. + err = ipkg_remove_pkg(conf, replacee,0);
  4401. + if (err)
  4402. + return err;
  4403. + }
  4404. + return 0;
  4405. +}
  4406. +
  4407. +/* to unwind the removal: make sure they are installed */
  4408. +int pkg_remove_installed_replacees_unwind(ipkg_conf_t *conf, pkg_vec_t *replacees)
  4409. +{
  4410. + int i, err;
  4411. + int replaces_count = replacees->len;
  4412. + for (i = 0; i < replaces_count; i++) {
  4413. + pkg_t *replacee = replacees->pkgs[i];
  4414. + if (replacee->state_status != SS_INSTALLED) {
  4415. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
  4416. + err = ipkg_install_pkg(conf, replacee,0);
  4417. + if (err)
  4418. + return err;
  4419. + }
  4420. + }
  4421. + return 0;
  4422. +}
  4423. +
  4424. +int caught_sigint = 0;
  4425. +static void ipkg_install_pkg_sigint_handler(int sig)
  4426. +{
  4427. + caught_sigint = sig;
  4428. +}
  4429. +
  4430. +/* compares versions of pkg and old_pkg, returns 0 if OK to proceed with installation of pkg, 1 otherwise */
  4431. +static int ipkg_install_check_downgrade(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg, int message)
  4432. +{
  4433. + if (old_pkg) {
  4434. + char message_out[15];
  4435. + char *old_version = pkg_version_str_alloc(old_pkg);
  4436. + char *new_version = pkg_version_str_alloc(pkg);
  4437. + int cmp = pkg_compare_versions(old_pkg, pkg);
  4438. + int rc = 0;
  4439. +
  4440. + memset(message_out,'\x0',15);
  4441. + strncpy (message_out,"Upgrading ",strlen("Upgrading "));
  4442. + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
  4443. + cmp = -1 ; /* then we force ipkg to downgrade */
  4444. + strncpy (message_out,"Downgrading ",strlen("Downgrading ")); /* We need to use a value < 0 because in the 0 case we are asking to */
  4445. + /* reinstall, and some check could fail asking the "force-reinstall" option */
  4446. + }
  4447. +
  4448. + if (cmp > 0) {
  4449. + ipkg_message(conf, IPKG_NOTICE,
  4450. + "Not downgrading package %s on %s from %s to %s.\n",
  4451. + old_pkg->name, old_pkg->dest->name, old_version, new_version);
  4452. + rc = 1;
  4453. + } else if (cmp < 0) {
  4454. + ipkg_message(conf, IPKG_NOTICE,
  4455. + "%s%s on %s from %s to %s...\n",
  4456. + message_out, pkg->name, old_pkg->dest->name, old_version, new_version);
  4457. + pkg->dest = old_pkg->dest;
  4458. + rc = 0;
  4459. + } else /* cmp == 0 */ {
  4460. + if (conf->force_reinstall) {
  4461. + ipkg_message(conf, IPKG_NOTICE,
  4462. + "Reinstalling %s (%s) on %s...\n",
  4463. + pkg->name, new_version, old_pkg->dest->name);
  4464. + pkg->dest = old_pkg->dest;
  4465. + rc = 0;
  4466. + } else {
  4467. + ipkg_message(conf, IPKG_NOTICE,
  4468. + "Not installing %s (%s) on %s -- already installed.\n",
  4469. + pkg->name, new_version, old_pkg->dest->name);
  4470. + rc = 1;
  4471. + }
  4472. + }
  4473. + free(old_version);
  4474. + free(new_version);
  4475. + return rc;
  4476. + } else {
  4477. + char message_out[15], *version ;
  4478. + memset(message_out,'\x0',15);
  4479. + if ( message )
  4480. + strncpy( message_out,"Upgrading ",strlen("Upgrading ") );
  4481. + else
  4482. + strncpy( message_out,"Installing ",strlen("Installing ") );
  4483. + version = pkg_version_str_alloc(pkg);
  4484. +
  4485. + ipkg_message(conf, IPKG_NOTICE,
  4486. + "%s%s (%s) to %s...\n", message_out,
  4487. + pkg->name, version, pkg->dest->name);
  4488. + free(version);
  4489. + return 0;
  4490. + }
  4491. +}
  4492. +
  4493. +/* and now the meat... */
  4494. +int ipkg_install_pkg(ipkg_conf_t *conf, pkg_t *pkg, int from_upgrade)
  4495. +{
  4496. + int err = 0;
  4497. + int message = 0;
  4498. + pkg_t *old_pkg = NULL;
  4499. + pkg_vec_t *replacees;
  4500. + abstract_pkg_t *ab_pkg = NULL;
  4501. + int old_state_flag;
  4502. + uint8_t *file_md5;
  4503. +
  4504. +
  4505. + if ( from_upgrade )
  4506. + message = 1; /* Coming from an upgrade, and should change the output message */
  4507. +
  4508. + if (!pkg) {
  4509. + ipkg_message(conf, IPKG_ERROR,
  4510. + "INTERNAL ERROR: null pkg passed to ipkg_install_pkg\n");
  4511. + return -EINVAL;
  4512. + }
  4513. +
  4514. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s calling pkg_arch_supported %s \n", __FUNCTION__, __FUNCTION__);
  4515. +
  4516. + if (!pkg_arch_supported(conf, pkg)) {
  4517. + ipkg_message(conf, IPKG_ERROR, "INTERNAL ERROR: architecture %s for pkg %s is unsupported.\n",
  4518. + pkg->architecture, pkg->name);
  4519. + return -EINVAL;
  4520. + }
  4521. + if (pkg->state_status == SS_INSTALLED && conf->force_reinstall == 0 && conf->nodeps == 0) {
  4522. + err = satisfy_dependencies_for(conf, pkg);
  4523. + if (err) { return err; }
  4524. +
  4525. + ipkg_message(conf, IPKG_NOTICE,
  4526. + "Package %s is already installed in %s.\n",
  4527. + pkg->name, pkg->dest->name);
  4528. + return 0;
  4529. + }
  4530. +
  4531. + if (pkg->dest == NULL) {
  4532. + pkg->dest = conf->default_dest;
  4533. + }
  4534. +
  4535. + old_pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name);
  4536. +
  4537. + err = ipkg_install_check_downgrade(conf, pkg, old_pkg, message);
  4538. + if (err) { return err; }
  4539. +
  4540. + pkg->state_want = SW_INSTALL;
  4541. + if (old_pkg){
  4542. + old_pkg->state_want = SW_DEINSTALL; /* needed for check_data_file_clashes of dependences */
  4543. + }
  4544. +
  4545. +
  4546. + /* Abhaya: conflicts check */
  4547. + err = check_conflicts_for(conf, pkg);
  4548. + if (err) { return err; }
  4549. +
  4550. + /* this setup is to remove the upgrade scenario in the end when
  4551. + installing pkg A, A deps B & B deps on A. So both B and A are
  4552. + installed. Then A's installation is started resulting in an
  4553. + uncecessary upgrade */
  4554. + if (pkg->state_status == SS_INSTALLED
  4555. + && conf->force_reinstall == 0) return 0;
  4556. +
  4557. + err = verify_pkg_installable(conf, pkg);
  4558. + if (err) { return err; }
  4559. +
  4560. + if (pkg->local_filename == NULL) {
  4561. + err = ipkg_download_pkg(conf, pkg, conf->tmp_dir);
  4562. + if (err) {
  4563. + ipkg_message(conf, IPKG_ERROR,
  4564. + "Failed to download %s. Perhaps you need to run 'ipkg update'?\n",
  4565. + pkg->name);
  4566. + return err;
  4567. + }
  4568. + }
  4569. +
  4570. +/* Check for md5 values */
  4571. + if (pkg->md5sum)
  4572. + {
  4573. + file_md5 = file_md5sum_alloc(pkg->local_filename);
  4574. + if (strcmp((char *)file_md5, pkg->md5sum))
  4575. + {
  4576. + ipkg_message(conf, IPKG_ERROR,
  4577. + "Package %s md5sum mismatch. Either the ipkg or the package index are corrupt. Try 'ipkg update'.\n",
  4578. + pkg->name);
  4579. + free(file_md5);
  4580. + return err;
  4581. + }
  4582. + free(file_md5);
  4583. + }
  4584. +
  4585. + if (pkg->tmp_unpack_dir == NULL) {
  4586. + unpack_pkg_control_files(conf, pkg);
  4587. + }
  4588. +
  4589. + /* We should update the filelist here, so that upgrades of packages that split will not fail. -Jamey 27-MAR-03 */
  4590. +/* Pigi: check if it will pass from here when replacing. It seems to fail */
  4591. +/* That's rather strange that files don't change owner. Investigate !!!!!!*/
  4592. + err = update_file_ownership(conf, pkg, old_pkg);
  4593. + if (err) { return err; }
  4594. +
  4595. + if (conf->nodeps == 0) {
  4596. + err = satisfy_dependencies_for(conf, pkg);
  4597. + if (err) { return err; }
  4598. + }
  4599. +
  4600. + replacees = pkg_vec_alloc();
  4601. + pkg_get_installed_replacees(pkg, replacees);
  4602. +
  4603. + /* this next section we do with SIGINT blocked to prevent inconsistency between ipkg database and filesystem */
  4604. + {
  4605. + sigset_t newset, oldset;
  4606. + sighandler_t old_handler = NULL;
  4607. + int use_signal = 0;
  4608. + caught_sigint = 0;
  4609. + if (use_signal) {
  4610. + old_handler = signal(SIGINT, ipkg_install_pkg_sigint_handler);
  4611. + } else {
  4612. + sigemptyset(&newset);
  4613. + sigaddset(&newset, SIGINT);
  4614. + sigprocmask(SIG_BLOCK, &newset, &oldset);
  4615. + }
  4616. +
  4617. + ipkg_state_changed++;
  4618. + pkg->state_flag |= SF_FILELIST_CHANGED;
  4619. +
  4620. + /* XXX: BUG: we really should treat replacement more like an upgrade
  4621. + * Instead, we're going to remove the replacees
  4622. + */
  4623. + err = pkg_remove_installed_replacees(conf, replacees);
  4624. + if (err) goto UNWIND_REMOVE_INSTALLED_REPLACEES;
  4625. +
  4626. + /*
  4627. + err = prerm_upgrade_old_pkg(conf, pkg, old_pkg);
  4628. + if (err) goto UNWIND_PRERM_UPGRADE_OLD_PKG;
  4629. +
  4630. + err = prerm_deconfigure_conflictors(conf, pkg, replacees);
  4631. + if (err) goto UNWIND_PRERM_DECONFIGURE_CONFLICTORS;
  4632. + */
  4633. +
  4634. + err = preinst_configure(conf, pkg, old_pkg);
  4635. + /*
  4636. + if (err) goto UNWIND_PREINST_CONFIGURE;
  4637. + */
  4638. +
  4639. + err = backup_modified_conffiles(conf, pkg, old_pkg);
  4640. + if (err) goto UNWIND_BACKUP_MODIFIED_CONFFILES;
  4641. +
  4642. + err = check_data_file_clashes(conf, pkg, old_pkg);
  4643. + /*
  4644. + if (err) goto UNWIND_CHECK_DATA_FILE_CLASHES;
  4645. +
  4646. + err = postrm_upgrade_old_pkg(conf, pkg, old_pkg);
  4647. + if (err) goto UNWIND_POSTRM_UPGRADE_OLD_PKG;
  4648. + */
  4649. +
  4650. + if (conf->noaction) return 0;
  4651. +
  4652. + /* point of no return: no unwinding after this */
  4653. + if (old_pkg && !conf->force_reinstall) {
  4654. + old_pkg->state_want = SW_DEINSTALL;
  4655. +
  4656. + if (old_pkg->state_flag & SF_NOPRUNE) {
  4657. + ipkg_message(conf, IPKG_INFO,
  4658. + " not removing obsolesced files because package marked noprune\n");
  4659. + } else {
  4660. + ipkg_message(conf, IPKG_INFO,
  4661. + " removing obsolesced files\n");
  4662. + remove_obsolesced_files(conf, pkg, old_pkg);
  4663. + }
  4664. + /* removing files from old package, to avoid ghost files */
  4665. + remove_data_files_and_list(conf, old_pkg);
  4666. +/* Pigi : It should be better to remove also maintainer and postrem scripts here, just in case*/
  4667. + remove_maintainer_scripts_except_postrm(conf, old_pkg);
  4668. + remove_postrm(conf, old_pkg);
  4669. +/* Pigi */
  4670. +
  4671. + }
  4672. +
  4673. +
  4674. + ipkg_message(conf, IPKG_INFO,
  4675. + " installing maintainer scripts\n");
  4676. + install_maintainer_scripts(conf, pkg, old_pkg);
  4677. +
  4678. + /* the following just returns 0
  4679. + remove_disappeared(conf, pkg);
  4680. + */
  4681. +
  4682. + ipkg_message(conf, IPKG_INFO,
  4683. + " installing data files\n");
  4684. + install_data_files(conf, pkg);
  4685. +
  4686. +/* read comments from function for detail but I will execute this here as all other tests are ok.*/
  4687. + err = check_data_file_clashes_change(conf, pkg);
  4688. +
  4689. + ipkg_message(conf, IPKG_INFO,
  4690. + " resolving conf files\n");
  4691. + resolve_conffiles(conf, pkg);
  4692. +
  4693. + pkg->state_status = SS_UNPACKED;
  4694. + old_state_flag = pkg->state_flag;
  4695. + pkg->state_flag &= ~SF_PREFER;
  4696. + ipkg_message(conf, IPKG_DEBUG, " pkg=%s old_state_flag=%x state_flag=%x\n", pkg->name, old_state_flag, pkg->state_flag);
  4697. +
  4698. + if (old_pkg && !conf->force_reinstall) {
  4699. + old_pkg->state_status = SS_NOT_INSTALLED;
  4700. + }
  4701. +
  4702. + time(&pkg->installed_time);
  4703. +
  4704. + ipkg_message(conf, IPKG_INFO,
  4705. + " cleanup temp files\n");
  4706. + cleanup_temporary_files(conf, pkg);
  4707. +
  4708. + ab_pkg = pkg->parent;
  4709. + if (ab_pkg)
  4710. + ab_pkg->state_status = pkg->state_status;
  4711. +
  4712. + ipkg_message(conf, IPKG_INFO, "Done.\n");
  4713. +
  4714. + if (use_signal)
  4715. + signal(SIGINT, old_handler);
  4716. + else
  4717. + sigprocmask(SIG_UNBLOCK, &newset, &oldset);
  4718. +
  4719. + return 0;
  4720. +
  4721. +
  4722. + /*
  4723. + UNWIND_POSTRM_UPGRADE_OLD_PKG:
  4724. + postrm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
  4725. + UNWIND_CHECK_DATA_FILE_CLASHES:
  4726. + check_data_file_clashes_unwind(conf, pkg, old_pkg);
  4727. + */
  4728. + UNWIND_BACKUP_MODIFIED_CONFFILES:
  4729. + backup_modified_conffiles_unwind(pkg, old_pkg);
  4730. + /*
  4731. + UNWIND_PREINST_CONFIGURE:
  4732. + preinst_configure_unwind(conf, pkg, old_pkg);
  4733. + UNWIND_PRERM_DECONFIGURE_CONFLICTORS:
  4734. + prerm_deconfigure_conflictors_unwind(conf, pkg, replacees);
  4735. + UNWIND_PRERM_UPGRADE_OLD_PKG:
  4736. + prerm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
  4737. + */
  4738. + UNWIND_REMOVE_INSTALLED_REPLACEES:
  4739. + pkg_remove_installed_replacees_unwind(conf, replacees);
  4740. +
  4741. + ipkg_message(conf, IPKG_INFO,
  4742. + " cleanup temp files\n");
  4743. + cleanup_temporary_files(conf, pkg);
  4744. +
  4745. + ipkg_message(conf, IPKG_INFO,
  4746. + "Failed.\n");
  4747. + if (use_signal)
  4748. + signal(SIGINT, old_handler);
  4749. + else
  4750. + sigprocmask(SIG_UNBLOCK, &newset, &oldset);
  4751. +
  4752. + return err;
  4753. + }
  4754. +}
  4755. +
  4756. +/*
  4757. +static int prerm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4758. +{
  4759. + DPKG_INCOMPATIBILITY:
  4760. + dpkg does some things here that we don't do yet. Do we care?
  4761. +
  4762. + 1. If a version of the package is already installed, call
  4763. + old-prerm upgrade new-version
  4764. + 2. If the script runs but exits with a non-zero exit status
  4765. + new-prerm failed-upgrade old-version
  4766. + Error unwind, for both the above cases:
  4767. + old-postinst abort-upgrade new-version
  4768. + return 0;
  4769. +}
  4770. +*/
  4771. +
  4772. +/*
  4773. +static int prerm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4774. +{
  4775. + DPKG_INCOMPATIBILITY:
  4776. + dpkg does some things here that we don't do yet. Do we care?
  4777. + (See prerm_upgrade_old_package for details)
  4778. +
  4779. + return 0;
  4780. +}
  4781. +*/
  4782. +
  4783. +/*
  4784. +static int prerm_deconfigure_conflictors(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors)
  4785. +{
  4786. + DPKG_INCOMPATIBILITY:
  4787. + dpkg does some things here that we don't do yet. Do we care?
  4788. + 2. If a 'conflicting' package is being removed at the same time:
  4789. + 1. If any packages depended on that conflicting package and
  4790. + --auto-deconfigure is specified, call, for each such package:
  4791. + deconfigured's-prerm deconfigure \
  4792. + in-favour package-being-installed version \
  4793. + removing conflicting-package version
  4794. + Error unwind:
  4795. + deconfigured's-postinst abort-deconfigure \
  4796. + in-favour package-being-installed-but-failed version \
  4797. + removing conflicting-package version
  4798. +
  4799. + The deconfigured packages are marked as requiring
  4800. + configuration, so that if --install is used they will be
  4801. + configured again if possible.
  4802. + 2. To prepare for removal of the conflicting package, call:
  4803. + conflictor's-prerm remove in-favour package new-version
  4804. + Error unwind:
  4805. + conflictor's-postinst abort-remove in-favour package new-version
  4806. + return 0;
  4807. +}
  4808. +*/
  4809. +
  4810. +/*
  4811. +static int prerm_deconfigure_conflictors_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors)
  4812. +{
  4813. + DPKG_INCOMPATIBILITY: dpkg does some things here that we don't
  4814. + do yet. Do we care? (See prerm_deconfigure_conflictors for
  4815. + details)
  4816. + return 0;
  4817. +}
  4818. +*/
  4819. +
  4820. +static int preinst_configure(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4821. +{
  4822. + int err;
  4823. + char *preinst_args;
  4824. +
  4825. + if (old_pkg) {
  4826. + char *old_version = pkg_version_str_alloc(old_pkg);
  4827. + sprintf_alloc(&preinst_args, "upgrade %s", old_version);
  4828. + free(old_version);
  4829. + } else if (pkg->state_status == SS_CONFIG_FILES) {
  4830. + char *pkg_version = pkg_version_str_alloc(pkg);
  4831. + sprintf_alloc(&preinst_args, "install %s", pkg_version);
  4832. + free(pkg_version);
  4833. + } else {
  4834. + preinst_args = strdup("install");
  4835. + }
  4836. +
  4837. + err = pkg_run_script(conf, pkg, "preinst", preinst_args);
  4838. + if (err) {
  4839. + ipkg_message(conf, IPKG_ERROR,
  4840. + "Aborting installation of %s\n", pkg->name);
  4841. + return 1;
  4842. + }
  4843. +
  4844. + free(preinst_args);
  4845. +
  4846. + return 0;
  4847. +}
  4848. +
  4849. +/*
  4850. +static int preinst_configure_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4851. +{
  4852. + DPKG_INCOMPATIBILITY:
  4853. + dpkg does the following error unwind, should we?
  4854. + pkg->postrm abort-upgrade old-version
  4855. + OR pkg->postrm abort-install old-version
  4856. + OR pkg->postrm abort-install
  4857. + return 0;
  4858. +}
  4859. +*/
  4860. +
  4861. +static int backup_modified_conffiles(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4862. +{
  4863. + int err;
  4864. + conffile_list_elt_t *iter;
  4865. + conffile_t *cf;
  4866. +
  4867. + if (conf->noaction) return 0;
  4868. +
  4869. + /* Backup all modified conffiles */
  4870. + if (old_pkg) {
  4871. + for (iter = old_pkg->conffiles.head; iter; iter = iter->next) {
  4872. + char *cf_name;
  4873. +
  4874. + cf = iter->data;
  4875. + cf_name = root_filename_alloc(conf, cf->name);
  4876. +
  4877. + /* Don't worry if the conffile is just plain gone */
  4878. + if (file_exists(cf_name) && conffile_has_been_modified(conf, cf)) {
  4879. + err = backup_make_backup(conf, cf_name);
  4880. + if (err) {
  4881. + return err;
  4882. + }
  4883. + }
  4884. + free(cf_name);
  4885. + }
  4886. + }
  4887. +
  4888. + /* Backup all conffiles that were not conffiles in old_pkg */
  4889. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  4890. + char *cf_name;
  4891. + cf = iter->data;
  4892. + cf_name = root_filename_alloc(conf, cf->name);
  4893. + /* Ignore if this was a conffile in old_pkg as well */
  4894. + if (pkg_get_conffile(old_pkg, cf->name)) {
  4895. + continue;
  4896. + }
  4897. +
  4898. + if (file_exists(cf_name) && (! backup_exists_for(cf_name))) {
  4899. + err = backup_make_backup(conf, cf_name);
  4900. + if (err) {
  4901. + return err;
  4902. + }
  4903. + }
  4904. + free(cf_name);
  4905. + }
  4906. +
  4907. + return 0;
  4908. +}
  4909. +
  4910. +static int backup_modified_conffiles_unwind(pkg_t *pkg, pkg_t *old_pkg)
  4911. +{
  4912. + conffile_list_elt_t *iter;
  4913. +
  4914. + if (old_pkg) {
  4915. + for (iter = old_pkg->conffiles.head; iter; iter = iter->next) {
  4916. + backup_remove(iter->data->name);
  4917. + }
  4918. + }
  4919. +
  4920. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  4921. + backup_remove(iter->data->name);
  4922. + }
  4923. +
  4924. + return 0;
  4925. +}
  4926. +
  4927. +
  4928. +static int check_data_file_clashes(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4929. +{
  4930. + /* DPKG_INCOMPATIBILITY:
  4931. + ipkg takes a slightly different approach than dpkg at this
  4932. + point. dpkg installs each file in the new package while
  4933. + creating a backup for any file that is replaced, (so that it
  4934. + can unwind if necessary). To avoid complexity and redundant
  4935. + storage, ipkg doesn't do any installation until later, (at the
  4936. + point at which dpkg removes the backups.
  4937. +
  4938. + But, we do have to check for data file clashes, since after
  4939. + installing a package with a file clash, removing either of the
  4940. + packages involved in the clash has the potential to break the
  4941. + other package.
  4942. + */
  4943. + str_list_t *files_list;
  4944. + str_list_elt_t *iter;
  4945. +
  4946. + int clashes = 0;
  4947. +
  4948. + files_list = pkg_get_installed_files(pkg);
  4949. + for (iter = files_list->head; iter; iter = iter->next) {
  4950. + char *root_filename;
  4951. + char *filename = iter->data;
  4952. + root_filename = root_filename_alloc(conf, filename);
  4953. + if (file_exists(root_filename) && (! file_is_dir(root_filename))) {
  4954. + pkg_t *owner;
  4955. + pkg_t *obs;
  4956. + /* Pre-existing conffiles are OK */
  4957. + /* @@@@ should have way to check that it is a conffile -Jamey */
  4958. + if (backup_exists_for(root_filename)) {
  4959. + continue;
  4960. + }
  4961. +
  4962. + /* Pre-existing files are OK if force-overwrite was asserted. */
  4963. + if (conf->force_overwrite) {
  4964. + /* but we need to change who owns this file */
  4965. + file_hash_set_file_owner(conf, filename, pkg);
  4966. + continue;
  4967. + }
  4968. +
  4969. + owner = file_hash_get_file_owner(conf, filename);
  4970. +
  4971. + /* Pre-existing files are OK if owned by the pkg being upgraded. */
  4972. + if (owner && old_pkg) {
  4973. + if (strcmp(owner->name, old_pkg->name) == 0) {
  4974. + continue;
  4975. + }
  4976. + }
  4977. +
  4978. + /* Pre-existing files are OK if owned by a package replaced by new pkg. */
  4979. + if (owner) {
  4980. + ipkg_message(conf, IPKG_DEBUG2, "Checking for replaces for %s in package %s\n", filename, owner->name);
  4981. + if (pkg_replaces(pkg, owner)) {
  4982. + continue;
  4983. + }
  4984. +/* If the file that would be installed is owned by the same package, ( as per a reinstall or similar )
  4985. + then it's ok to overwrite. */
  4986. + if (strcmp(owner->name,pkg->name)==0){
  4987. + ipkg_message(conf, IPKG_INFO, "Replacing pre-existing file %s owned by package %s\n", filename, owner->name);
  4988. + continue;
  4989. + }
  4990. + }
  4991. +
  4992. + /* Pre-existing files are OK if they are obsolete */
  4993. + obs = hash_table_get(&conf->obs_file_hash, filename);
  4994. + if (obs) {
  4995. + ipkg_message(conf, IPKG_INFO, "Pre-exiting file %s is obsolete. obs_pkg=%s\n", filename, obs->name);
  4996. + continue;
  4997. + }
  4998. +
  4999. + /* We have found a clash. */
  5000. + ipkg_message(conf, IPKG_ERROR,
  5001. + "Package %s wants to install file %s\n"
  5002. + "\tBut that file is already provided by package ",
  5003. + pkg->name, filename);
  5004. + if (owner) {
  5005. + ipkg_message(conf, IPKG_ERROR,
  5006. + "%s\n", owner->name);
  5007. + } else {
  5008. + ipkg_message(conf, IPKG_ERROR,
  5009. + "<no package>\nPlease move this file out of the way and try again.\n");
  5010. + }
  5011. + clashes++;
  5012. + }
  5013. + free(root_filename);
  5014. + }
  5015. + pkg_free_installed_files(pkg);
  5016. +
  5017. + return clashes;
  5018. +}
  5019. +
  5020. +static int check_data_file_clashes_change(ipkg_conf_t *conf, pkg_t *pkg)
  5021. +{
  5022. + /* Basically that's the worst hack I could do to be able to change ownership of
  5023. + file list, but, being that we have no way to unwind the mods, due to structure
  5024. + of hash table, probably is the quickest hack too, whishing it would not slow-up thing too much.
  5025. + What we do here is change the ownership of file in hash if a replace ( or similar events
  5026. + happens )
  5027. + Only the action that are needed to change name should be considered.
  5028. + @@@ To change after 1.0 release.
  5029. + */
  5030. + str_list_t *files_list;
  5031. + str_list_elt_t *iter;
  5032. +
  5033. + int clashes = 0;
  5034. +
  5035. + files_list = pkg_get_installed_files(pkg);
  5036. + for (iter = files_list->head; iter; iter = iter->next) {
  5037. + char *root_filename;
  5038. + char *filename = iter->data;
  5039. + root_filename = root_filename_alloc(conf, filename);
  5040. + if (file_exists(root_filename) && (! file_is_dir(root_filename))) {
  5041. + pkg_t *owner;
  5042. +
  5043. + if (conf->force_overwrite) {
  5044. + /* but we need to change who owns this file */
  5045. + file_hash_set_file_owner(conf, filename, pkg);
  5046. + continue;
  5047. + }
  5048. +
  5049. + owner = file_hash_get_file_owner(conf, filename);
  5050. +
  5051. + /* Pre-existing files are OK if owned by a package replaced by new pkg. */
  5052. + if (owner) {
  5053. + if (pkg_replaces(pkg, owner)) {
  5054. +/* It's now time to change the owner of that file.
  5055. + It has been "replaced" from the new "Replaces", then I need to inform lists file about that. */
  5056. + ipkg_message(conf, IPKG_INFO, "Replacing pre-existing file %s owned by package %s\n", filename, owner->name);
  5057. + file_hash_set_file_owner(conf, filename, pkg);
  5058. + continue;
  5059. + }
  5060. + }
  5061. +
  5062. + }
  5063. + free(root_filename);
  5064. + }
  5065. + pkg_free_installed_files(pkg);
  5066. +
  5067. + return clashes;
  5068. +}
  5069. +
  5070. +/*
  5071. +static int check_data_file_clashes_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5072. +{
  5073. + Nothing to do since check_data_file_clashes doesn't change state
  5074. + return 0;
  5075. +}
  5076. +*/
  5077. +
  5078. +/*
  5079. +static int postrm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5080. +{
  5081. + DPKG_INCOMPATIBILITY: dpkg does the following here, should we?
  5082. + 1. If the package is being upgraded, call
  5083. + old-postrm upgrade new-version
  5084. + 2. If this fails, attempt:
  5085. + new-postrm failed-upgrade old-version
  5086. + Error unwind, for both cases:
  5087. + old-preinst abort-upgrade new-version
  5088. + return 0;
  5089. +}
  5090. +*/
  5091. +
  5092. +/*
  5093. +static int postrm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5094. +{
  5095. + DPKG_INCOMPATIBILITY:
  5096. + dpkg does some things here that we don't do yet. Do we care?
  5097. + (See postrm_upgrade_old_pkg for details)
  5098. + return 0;
  5099. +}
  5100. +*/
  5101. +
  5102. +static int remove_obsolesced_files(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5103. +{
  5104. + int err;
  5105. + str_list_t *old_files;
  5106. + str_list_elt_t *of;
  5107. + str_list_t *new_files;
  5108. + str_list_elt_t *nf;
  5109. +
  5110. + if (old_pkg == NULL) {
  5111. + return 0;
  5112. + }
  5113. +
  5114. + old_files = pkg_get_installed_files(old_pkg);
  5115. + new_files = pkg_get_installed_files(pkg);
  5116. +
  5117. + for (of = old_files->head; of; of = of->next) {
  5118. + pkg_t *owner;
  5119. + char *old, *new;
  5120. + old = of->data;
  5121. + for (nf = new_files->head; nf; nf = nf->next) {
  5122. + new = nf->data;
  5123. + if (strcmp(old, new) == 0) {
  5124. + goto NOT_OBSOLETE;
  5125. + }
  5126. + }
  5127. + if (file_is_dir(old)) {
  5128. + continue;
  5129. + }
  5130. + owner = file_hash_get_file_owner(conf, old);
  5131. + if (owner != old_pkg) {
  5132. + /* in case obsolete file no longer belongs to old_pkg */
  5133. + continue;
  5134. + }
  5135. +
  5136. + /* old file is obsolete */
  5137. + ipkg_message(conf, IPKG_INFO,
  5138. + " removing obsolete file %s\n", old);
  5139. + if (!conf->noaction) {
  5140. + err = unlink(old);
  5141. + if (err) {
  5142. + ipkg_message(conf, IPKG_ERROR, " Warning: remove %s failed: %s\n", old,
  5143. + strerror(errno));
  5144. + }
  5145. + }
  5146. +
  5147. + NOT_OBSOLETE:
  5148. + ;
  5149. + }
  5150. +
  5151. + pkg_free_installed_files(old_pkg);
  5152. + pkg_free_installed_files(pkg);
  5153. +
  5154. + return 0;
  5155. +}
  5156. +
  5157. +static int remove_obsolete_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5158. +{
  5159. + int i;
  5160. + int err = 0;
  5161. + char *globpattern;
  5162. + glob_t globbuf;
  5163. + if (0) {
  5164. + if (!pkg->dest) {
  5165. + ipkg_message(conf, IPKG_ERROR, "%s: no dest for package %s\n", __FUNCTION__, pkg->name);
  5166. + return -1;
  5167. + }
  5168. + sprintf_alloc(&globpattern, "%s/%s.*", pkg->dest->info_dir, pkg->name);
  5169. + err = glob(globpattern, 0, NULL, &globbuf);
  5170. + free(globpattern);
  5171. + if (err) {
  5172. + return err;
  5173. + }
  5174. + /* XXXX this should perhaps only remove the ones that are not overwritten in new package. Jamey 11/11/2003 */
  5175. + for (i = 0; i < globbuf.gl_pathc; i++) {
  5176. + ipkg_message(conf, IPKG_DEBUG, "Removing control file %s from old_pkg %s\n",
  5177. + globbuf.gl_pathv[i], old_pkg->name);
  5178. + if (!conf->noaction)
  5179. + unlink(globbuf.gl_pathv[i]);
  5180. + }
  5181. + globfree(&globbuf);
  5182. + }
  5183. + return err;
  5184. +}
  5185. +
  5186. +static int install_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5187. +{
  5188. + int ret;
  5189. + char *prefix;
  5190. +
  5191. + if (old_pkg)
  5192. + remove_obsolete_maintainer_scripts(conf, pkg, old_pkg);
  5193. + sprintf_alloc(&prefix, "%s.", pkg->name);
  5194. + ret = pkg_extract_control_files_to_dir_with_prefix(pkg,
  5195. + pkg->dest->info_dir,
  5196. + prefix);
  5197. + free(prefix);
  5198. + return ret;
  5199. +}
  5200. +
  5201. +/*
  5202. +static int remove_disappeared(ipkg_conf_t *conf, pkg_t *pkg)
  5203. +{
  5204. + DPKG_INCOMPATIBILITY:
  5205. + This is a fairly sophisticated dpkg operation. Shall we
  5206. + skip it?
  5207. +
  5208. + Any packages all of whose files have been overwritten during the
  5209. + installation, and which aren't required for dependencies, are
  5210. + considered to have been removed. For each such package
  5211. + 1. disappearer's-postrm disappear overwriter overwriter-version
  5212. + 2. The package's maintainer scripts are removed
  5213. + 3. It is noted in the status database as being in a sane state,
  5214. + namely not installed (any conffiles it may have are ignored,
  5215. + rather than being removed by dpkg). Note that disappearing
  5216. + packages do not have their prerm called, because dpkg doesn't
  5217. + know in advance that the package is going to vanish.
  5218. +
  5219. +
  5220. + return 0;
  5221. +}
  5222. +*/
  5223. +
  5224. +static int install_data_files(ipkg_conf_t *conf, pkg_t *pkg)
  5225. +{
  5226. + int err;
  5227. +
  5228. + /* ipkg takes a slightly different approach to data file backups
  5229. + than dpkg. Rather than removing backups at this point, we
  5230. + actually do the data file installation now. See comments in
  5231. + check_data_file_clashes() for more details. */
  5232. +
  5233. + ipkg_message(conf, IPKG_INFO,
  5234. + " extracting data files to %s\n", pkg->dest->root_dir);
  5235. + err = pkg_extract_data_files_to_dir(pkg, pkg->dest->root_dir);
  5236. + if (err) {
  5237. + return err;
  5238. + }
  5239. +
  5240. + /* XXX: BUG or FEATURE : We are actually loosing the Essential flag,
  5241. + so we can't save ourself from removing important packages
  5242. + At this point we (should) have extracted the .control file, so it
  5243. + would be a good idea to reload the data in it, and set the Essential
  5244. + state in *pkg. From now on the Essential is back in status file and
  5245. + we can protect again.
  5246. + We should operate this way:
  5247. + fopen the file ( pkg->dest->root_dir/pkg->name.control )
  5248. + check for "Essential" in it
  5249. + set the value in pkg->essential.
  5250. + This new routine could be useful also for every other flag
  5251. + Pigi: 16/03/2004 */
  5252. + set_flags_from_control(conf, pkg) ;
  5253. +
  5254. + ipkg_message(conf, IPKG_DEBUG, " Calling pkg_write_filelist from %s\n", __FUNCTION__);
  5255. + err = pkg_write_filelist(conf, pkg);
  5256. + if (err)
  5257. + return err;
  5258. +
  5259. + /* XXX: FEATURE: ipkg should identify any files which existed
  5260. + before installation and which were overwritten, (see
  5261. + check_data_file_clashes()). What it must do is remove any such
  5262. + files from the filelist of the old package which provided the
  5263. + file. Otherwise, if the old package were removed at some point
  5264. + it would break the new package. Removing the new package will
  5265. + also break the old one, but this cannot be helped since the old
  5266. + package's file has already been deleted. This is the importance
  5267. + of check_data_file_clashes(), and only allowing ipkg to install
  5268. + a clashing package with a user force. */
  5269. +
  5270. + return 0;
  5271. +}
  5272. +
  5273. +static int resolve_conffiles(ipkg_conf_t *conf, pkg_t *pkg)
  5274. +{
  5275. + conffile_list_elt_t *iter;
  5276. + conffile_t *cf;
  5277. + char *cf_backup;
  5278. + uint8_t *md5sum;
  5279. +
  5280. +
  5281. + if (conf->noaction) return 0;
  5282. +
  5283. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  5284. + char *root_filename;
  5285. + cf = iter->data;
  5286. + root_filename = root_filename_alloc(conf, cf->name);
  5287. +
  5288. + /* Might need to initialize the md5sum for each conffile */
  5289. + if (cf->value == NULL) {
  5290. + cf->value = (char *)file_md5sum_alloc(root_filename);
  5291. + }
  5292. +
  5293. + if (!file_exists(root_filename)) {
  5294. + free(root_filename);
  5295. + continue;
  5296. + }
  5297. +
  5298. + cf_backup = backup_filename_alloc(root_filename);
  5299. +
  5300. +
  5301. + if (file_exists(cf_backup)) {
  5302. + /* Let's compute md5 to test if files are changed */
  5303. + md5sum = file_md5sum_alloc(cf_backup);
  5304. + if (strcmp( cf->value, (char *)md5sum) != 0 ) {
  5305. + if (conf->force_defaults
  5306. + || user_prefers_old_conffile(cf->name, cf_backup) ) {
  5307. + rename(cf_backup, root_filename);
  5308. + }
  5309. + }
  5310. + unlink(cf_backup);
  5311. + free(md5sum);
  5312. + }
  5313. +
  5314. + free(cf_backup);
  5315. + free(root_filename);
  5316. + }
  5317. +
  5318. + return 0;
  5319. +}
  5320. +
  5321. +static int user_prefers_old_conffile(const char *file_name, const char *backup)
  5322. +{
  5323. + char *response;
  5324. + const char *short_file_name;
  5325. +
  5326. + short_file_name = strrchr(file_name, '/');
  5327. + if (short_file_name) {
  5328. + short_file_name++;
  5329. + } else {
  5330. + short_file_name = file_name;
  5331. + }
  5332. +
  5333. + while (1) {
  5334. + response = get_user_response(" Configuration file '%s'\n"
  5335. + " ==> File on system created by you or by a script.\n"
  5336. + " ==> File also in package provided by package maintainer.\n"
  5337. + " What would you like to do about it ? Your options are:\n"
  5338. + " Y or I : install the package maintainer's version\n"
  5339. + " N or O : keep your currently-installed version\n"
  5340. +#ifdef CONFIG_DIFF
  5341. + " D : show the differences between the versions\n"
  5342. +#endif
  5343. + " The default action is to keep your current version.\n"
  5344. + " *** %s (Y/I/N/O"
  5345. +#ifdef CONFIG_DIFF
  5346. + "/D"
  5347. +#endif
  5348. + ") [default=N] ? ", file_name, short_file_name);
  5349. + if (strcmp(response, "y") == 0
  5350. + || strcmp(response, "i") == 0
  5351. + || strcmp(response, "yes") == 0) {
  5352. + free(response);
  5353. + return 0;
  5354. + }
  5355. +
  5356. +#ifdef CONFIG_DIFF
  5357. + if (strcmp(response, "d") == 0) {
  5358. + char *cmd;
  5359. +
  5360. + free(response);
  5361. + /* XXX: BUG rewrite to use exec or busybox's internal diff */
  5362. + sprintf_alloc(&cmd, "diff -u %s %s", backup, file_name);
  5363. + xsystem(cmd);
  5364. + free(cmd);
  5365. + printf(" [Press ENTER to continue]\n");
  5366. + response = file_read_line_alloc(stdin);
  5367. + free(response);
  5368. + continue;
  5369. + }
  5370. +#endif
  5371. +
  5372. + free(response);
  5373. + return 1;
  5374. + }
  5375. +}
  5376. +
  5377. +/* XXX: CLEANUP: I'd like to move all of the code for
  5378. + creating/cleaning pkg->tmp_unpack_dir directly into pkg.c. (Then,
  5379. + it would make sense to cleanup pkg->tmp_unpack_dir directly from
  5380. + pkg_deinit for example). */
  5381. +static int cleanup_temporary_files(ipkg_conf_t *conf, pkg_t *pkg)
  5382. +{
  5383. + DIR *tmp_dir;
  5384. + struct dirent *dirent;
  5385. + char *tmp_file;
  5386. +
  5387. +#ifdef IPKG_DEBUG_NO_TMP_CLEANUP
  5388. +#error
  5389. + ipkg_message(conf, IPKG_DEBUG,
  5390. + "%s: Not cleaning up %s since ipkg compiled with IPKG_DEBUG_NO_TMP_CLEANUP\n",
  5391. + __FUNCTION__, pkg->tmp_unpack_dir);
  5392. + return 0;
  5393. +#endif
  5394. +
  5395. + if (pkg->tmp_unpack_dir && file_is_dir(pkg->tmp_unpack_dir)) {
  5396. + tmp_dir = opendir(pkg->tmp_unpack_dir);
  5397. + if (tmp_dir) {
  5398. + while (1) {
  5399. + dirent = readdir(tmp_dir);
  5400. + if (dirent == NULL) {
  5401. + break;
  5402. + }
  5403. + sprintf_alloc(&tmp_file, "%s/%s",
  5404. + pkg->tmp_unpack_dir, dirent->d_name);
  5405. + if (! file_is_dir(tmp_file)) {
  5406. + unlink(tmp_file);
  5407. + }
  5408. + free(tmp_file);
  5409. + }
  5410. + closedir(tmp_dir);
  5411. + rmdir(pkg->tmp_unpack_dir);
  5412. + free(pkg->tmp_unpack_dir);
  5413. + pkg->tmp_unpack_dir = NULL;
  5414. + }
  5415. + }
  5416. +
  5417. + ipkg_message(conf, IPKG_INFO, "cleanup_temporary_files: pkg=%s local_filename=%s tmp_dir=%s\n",
  5418. + pkg->name, pkg->local_filename, conf->tmp_dir);
  5419. + if (pkg->local_filename && strncmp(pkg->local_filename, conf->tmp_dir, strlen(conf->tmp_dir)) == 0) {
  5420. + unlink(pkg->local_filename);
  5421. + free(pkg->local_filename);
  5422. + pkg->local_filename = NULL;
  5423. + }
  5424. +
  5425. + return 0;
  5426. +}
  5427. +
  5428. +static char *backup_filename_alloc(const char *file_name)
  5429. +{
  5430. + char *backup;
  5431. +
  5432. + sprintf_alloc(&backup, "%s%s", file_name, IPKG_BACKUP_SUFFIX);
  5433. +
  5434. + return backup;
  5435. +}
  5436. +
  5437. +int backup_make_backup(ipkg_conf_t *conf, const char *file_name)
  5438. +{
  5439. + int err;
  5440. + char *backup;
  5441. +
  5442. + backup = backup_filename_alloc(file_name);
  5443. + err = file_copy(file_name, backup);
  5444. + if (err) {
  5445. + ipkg_message(conf, IPKG_ERROR,
  5446. + "%s: Failed to copy %s to %s\n",
  5447. + __FUNCTION__, file_name, backup);
  5448. + }
  5449. +
  5450. + free(backup);
  5451. +
  5452. + return err;
  5453. +}
  5454. +
  5455. +static int backup_exists_for(const char *file_name)
  5456. +{
  5457. + int ret;
  5458. + char *backup;
  5459. +
  5460. + backup = backup_filename_alloc(file_name);
  5461. +
  5462. + ret = file_exists(backup);
  5463. +
  5464. + free(backup);
  5465. +
  5466. + return ret;
  5467. +}
  5468. +
  5469. +static int backup_remove(const char *file_name)
  5470. +{
  5471. + char *backup;
  5472. +
  5473. + backup = backup_filename_alloc(file_name);
  5474. + unlink(backup);
  5475. + free(backup);
  5476. +
  5477. + return 0;
  5478. +}
  5479. +
  5480. +
  5481. +
  5482. +#ifdef CONFIG_IPKG_PROCESS_ACTIONS
  5483. +
  5484. +int ipkg_remove_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove)
  5485. +{
  5486. + /* first, remove the packages that need removing */
  5487. + for (i = 0 ; i < pkgs_to_remove->len; i++ ) {
  5488. + pkg_t *pkg = pkgs_to_remove->pkgs[i];
  5489. + err = ipkg_remove_pkg(conf, pkg,0);
  5490. + if (err) return err;
  5491. + }
  5492. + return 0;
  5493. +}
  5494. +
  5495. +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)
  5496. +{
  5497. + int i;
  5498. + /* now one more pass checking on the ones that need to be installed */
  5499. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5500. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5501. + if (pkg->dest == NULL)
  5502. + pkg->dest = conf->default_dest;
  5503. +
  5504. + pkg->state_want = SW_INSTALL;
  5505. +
  5506. + /* Abhaya: conflicts check */
  5507. + err = check_conflicts_for(conf, pkg);
  5508. + if (err) { return err; }
  5509. + }
  5510. + return 0;
  5511. +}
  5512. +
  5513. +int ipkg_process_actions_unpack_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_to_install)
  5514. +{
  5515. + int i;
  5516. + /* now one more pass checking on the ones that need to be installed */
  5517. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5518. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5519. +
  5520. + /* XXX: FEATURE: Need to really support Provides/Replaces: here at some point */
  5521. + pkg_vec_t *replacees = pkg_vec_alloc();
  5522. + pkg_get_installed_replacees(pkg, replacees);
  5523. +
  5524. + /* XXX: BUG: we really should treat replacement more like an upgrade
  5525. + * Instead, we're going to remove the replacees
  5526. + */
  5527. + err = pkg_remove_installed_replacees(conf, replacees);
  5528. + if (err) return err;
  5529. + pkg->state_flag |= SF_REMOVED_REPLACEES;
  5530. + }
  5531. + return 0;
  5532. +}
  5533. +
  5534. +int ipkg_process_actions_unpack_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, 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->local_filename == NULL) {
  5541. + err = ipkg_download_pkg(conf, pkg, conf->tmp_dir);
  5542. + if (err) {
  5543. + ipkg_message(conf, IPKG_ERROR,
  5544. + "Failed to download %s. Perhaps you need to run 'ipkg update'?\n",
  5545. + pkg->name);
  5546. + return err;
  5547. + }
  5548. + }
  5549. + if (pkg->tmp_unpack_dir == NULL) {
  5550. + err = unpack_pkg_control_files(conf, pkg);
  5551. + if (err) return err;
  5552. + }
  5553. + }
  5554. + return 0;
  5555. +}
  5556. +
  5557. +int ipkg_process_actions_prerm(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
  5558. +{
  5559. + int i;
  5560. + /* now one more pass checking on the ones that need to be installed */
  5561. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5562. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5563. + pkg_t *old_pkg = pkg->old_pkg;
  5564. +
  5565. + err = prerm_upgrade_old_pkg(conf, pkg, old_pkg);
  5566. + if (err) return err;
  5567. +
  5568. + err = prerm_deconfigure_conflictors(conf, pkg, replacees);
  5569. + if (err) return err;
  5570. +
  5571. + err = preinst_configure(conf, pkg, old_pkg);
  5572. + if (err) return err;
  5573. +
  5574. + err = backup_modified_conffiles(conf, pkg, old_pkg);
  5575. + if (err) return err;
  5576. +
  5577. + err = postrm_upgrade_old_pkg(conf, pkg, old_pkg);
  5578. + if (err) return err;
  5579. + }
  5580. + return 0;
  5581. +}
  5582. +
  5583. +int ipkg_process_actions_install(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
  5584. +{
  5585. + int i;
  5586. + /* now one more pass checking on the ones that need to be installed */
  5587. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5588. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5589. + pkg_t *old_pkg = pkg->old_pkg;
  5590. +
  5591. + if (old_pkg) {
  5592. + old_pkg->state_want = SW_DEINSTALL;
  5593. +
  5594. + if (old_pkg->state_flag & SF_NOPRUNE) {
  5595. + ipkg_message(conf, IPKG_INFO,
  5596. + " not removing obsolesced files because package marked noprune\n");
  5597. + } else {
  5598. + ipkg_message(conf, IPKG_INFO,
  5599. + " removing obsolesced files\n");
  5600. + remove_obsolesced_files(conf, pkg, old_pkg);
  5601. + }
  5602. + }
  5603. +
  5604. + ipkg_message(conf, IPKG_INFO,
  5605. + " installing maintainer scripts\n");
  5606. + install_maintainer_scripts(conf, pkg, old_pkg);
  5607. +
  5608. + /* the following just returns 0 */
  5609. + remove_disappeared(conf, pkg);
  5610. +
  5611. + ipkg_message(conf, IPKG_INFO,
  5612. + " installing data files\n");
  5613. + install_data_files(conf, pkg);
  5614. +
  5615. + ipkg_message(conf, IPKG_INFO,
  5616. + " resolving conf files\n");
  5617. + resolve_conffiles(conf, pkg);
  5618. +
  5619. + pkg->state_status = SS_UNPACKED;
  5620. +
  5621. + if (old_pkg) {
  5622. + old_pkg->state_status = SS_NOT_INSTALLED;
  5623. + }
  5624. +
  5625. + time(&pkg->installed_time);
  5626. +
  5627. + ipkg_message(conf, IPKG_INFO,
  5628. + " cleanup temp files\n");
  5629. + cleanup_temporary_files(conf, pkg);
  5630. +
  5631. + if (pkg->parent)
  5632. + pkg->parent->state_status = pkg->state_status;
  5633. + }
  5634. + return 0;
  5635. +}
  5636. +
  5637. +int ipkg_process_actions_unwind_prerm(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
  5638. +{
  5639. + int i;
  5640. + /* now one more pass checking on the ones that need to be installed */
  5641. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5642. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5643. + pkg_t *old_pkg = pkg->old_pkg;
  5644. +
  5645. + if (old_pkg) {
  5646. + if (old_pkg->state_flags & SF_POSTRM_UPGRADE)
  5647. + postrm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
  5648. + if (old_pkg->state_flags & SF_CHECK_DATA_FILE_CLASHES)
  5649. + check_data_file_clashes_unwind(conf, pkg, old_pkg);
  5650. + if (old_pkg->state_flags & SF_BACKUP_MODIFIED_CONFFILES)
  5651. + backup_modified_conffiles_unwind(pkg, old_pkg);
  5652. + */
  5653. + if (old_pkg->state_flags & SF_PREINST_CONFIGURE)
  5654. + preinst_configure_unwind(conf, pkg, old_pkg);
  5655. + if (old_pkg->state_flags & SF_DECONFIGURE_CONFLICTORS)
  5656. + prerm_deconfigure_conflictors_unwind(conf, pkg, replacees);
  5657. + if (old_pkg->state_flags & SF_PRERM_UPGRADE)
  5658. + prerm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
  5659. + */
  5660. +
  5661. + if (old_pkg->state_flags & SF_REMOVED_REPLACEES)
  5662. + remove_installed_replacees_unwind(conf, pkg, old_pkg);
  5663. +
  5664. + }
  5665. + }
  5666. + return 0;
  5667. +}
  5668. +
  5669. +/*
  5670. + * Perform all the actions.
  5671. + *
  5672. + * pkgs_to_remove are packages marked for removal.
  5673. + * pkgs_superseded are the old packages being replaced by upgrades.
  5674. + *
  5675. + * Assumes pkgs_to_install includes all dependences, recursively, sorted in installable order.
  5676. + */
  5677. +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)
  5678. +{
  5679. + int err;
  5680. + int i;
  5681. +
  5682. + err = ipkg_remove_packages(conf, pkgs_to_remove);
  5683. + if (err) return err;
  5684. +
  5685. + err = ipkg_process_actions_sanity_check(conf, pkgs_superseded, pkgs_to_install);
  5686. + if (err) return err;
  5687. +
  5688. + err = ipkg_process_actions_remove_replacees(conf, pkgs_to_install);
  5689. + if (err) goto UNWIND;
  5690. +
  5691. + /* @@@@ look at ipkg_install_pkg for handling replacements */
  5692. + err = ipkg_process_actions_unpack_packages(conf, pkgs_to_install);
  5693. + if (err) goto UNWIND;
  5694. +
  5695. + /*
  5696. + * Now that we have the packages unpacked, we can look for data
  5697. + * file clashes. First, we mark the files from the superseded
  5698. + * packages as obsolete. Then we scan the files in
  5699. + * pkgs_to_install, and only complain about clashes with
  5700. + * non-obsolete files.
  5701. + */
  5702. +
  5703. + err = ipkg_process_actions_check_data_file_clashes(conf, pkgs_superseded, pkgs_to_install);
  5704. + if (err) goto UNWIND;
  5705. +
  5706. + /* this was before checking data file clashes */
  5707. + err = ipkg_process_actions_prerm(conf, pkgs_superseded, pkgs_to_install);
  5708. + if (err) goto UNWIND;
  5709. +
  5710. + /* point of no return: no unwinding after this */
  5711. + err = ipkg_process_actions_install(conf, pkgs_to_install);
  5712. + if (err) return err;
  5713. +
  5714. + ipkg_message(conf, IPKG_INFO, "Done.\n");
  5715. + return 0;
  5716. +
  5717. + UNWIND:
  5718. + ipkg_process_actions_unwind(conf, pkgs_to_install);
  5719. +
  5720. + ipkg_message(conf, IPKG_INFO,
  5721. + " cleanup temp files\n");
  5722. + cleanup_temporary_files(conf, pkg);
  5723. +
  5724. + ipkg_message(conf, IPKG_INFO,
  5725. + "Failed.\n");
  5726. + return err;
  5727. +}
  5728. +
  5729. +#endif
  5730. diff -Nur busybox-1.12.1.orig/archival/libipkg/ipkg_install.h busybox-1.12.1/archival/libipkg/ipkg_install.h
  5731. --- busybox-1.12.1.orig/archival/libipkg/ipkg_install.h 1970-01-01 01:00:00.000000000 +0100
  5732. +++ busybox-1.12.1/archival/libipkg/ipkg_install.h 2008-10-23 11:41:37.000000000 +0200
  5733. @@ -0,0 +1,35 @@
  5734. +/* ipkg_install.h - the itsy package management system
  5735. +
  5736. + Carl D. Worth
  5737. +
  5738. + Copyright (C) 2001 University of Southern California
  5739. +
  5740. + This program is free software; you can redistribute it and/or
  5741. + modify it under the terms of the GNU General Public License as
  5742. + published by the Free Software Foundation; either version 2, or (at
  5743. + your option) any later version.
  5744. +
  5745. + This program is distributed in the hope that it will be useful, but
  5746. + WITHOUT ANY WARRANTY; without even the implied warranty of
  5747. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  5748. + General Public License for more details.
  5749. +*/
  5750. +
  5751. +#ifndef IPKG_INSTALL_H
  5752. +#define IPKG_INSTALL_H
  5753. +
  5754. +#include "pkg.h"
  5755. +#include "ipkg_conf.h"
  5756. +
  5757. +ipkg_error_t ipkg_install_by_name(ipkg_conf_t *conf, const char *pkg_name);
  5758. +ipkg_error_t ipkg_install_multi_by_name(ipkg_conf_t *conf, const char *pkg_name);
  5759. +int ipkg_install_from_file(ipkg_conf_t *conf, const char *filename);
  5760. +int ipkg_install_pkg(ipkg_conf_t *conf, pkg_t *pkg,int from_upgrading);
  5761. +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg);
  5762. +
  5763. +int ipkg_satisfy_all_dependences(ipkg_conf_t *conf);
  5764. +
  5765. +int pkg_mark_dependencies_for_installation(ipkg_conf_t *conf, pkg_t *pkg_name, pkg_vec_t *pkgs_needed);
  5766. +int name_mark_dependencies_for_installation(ipkg_conf_t *conf, const char *pkg_name, pkg_vec_t *pkgs_needed);
  5767. +
  5768. +#endif
  5769. diff -Nur busybox-1.12.1.orig/archival/libipkg/ipkg_message.c busybox-1.12.1/archival/libipkg/ipkg_message.c
  5770. --- busybox-1.12.1.orig/archival/libipkg/ipkg_message.c 1970-01-01 01:00:00.000000000 +0100
  5771. +++ busybox-1.12.1/archival/libipkg/ipkg_message.c 2008-10-23 11:41:37.000000000 +0200
  5772. @@ -0,0 +1,61 @@
  5773. +/* ipkg_message.c - the itsy package management system
  5774. +
  5775. + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
  5776. +
  5777. + This program is free software; you can redistribute it and/or
  5778. + modify it under the terms of the GNU General Public License as
  5779. + published by the Free Software Foundation; either version 2, or (at
  5780. + your option) any later version.
  5781. +
  5782. + This program is distributed in the hope that it will be useful, but
  5783. + WITHOUT ANY WARRANTY; without even the implied warranty of
  5784. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  5785. + General Public License for more details.
  5786. +*/
  5787. +
  5788. +
  5789. +#include "ipkg.h"
  5790. +#include "ipkg_conf.h"
  5791. +#include "ipkg_message.h"
  5792. +
  5793. +#ifndef IPKG_LIB
  5794. +
  5795. +void
  5796. +ipkg_message (ipkg_conf_t * conf, message_level_t level, char *fmt, ...)
  5797. +{
  5798. + va_list ap;
  5799. +
  5800. + if (conf && (conf->verbosity < level))
  5801. + {
  5802. + return;
  5803. + }
  5804. + else
  5805. + {
  5806. +
  5807. + va_start (ap, fmt);
  5808. + vprintf (fmt, ap);
  5809. + va_end (ap);
  5810. + }
  5811. +}
  5812. +
  5813. +#else
  5814. +
  5815. +#include "libipkg.h"
  5816. +
  5817. +//#define ipkg_message(conf, level, fmt, arg...) ipkg_cb_message(conf, level, fmt, ## arg)
  5818. +
  5819. +void
  5820. +ipkg_message (ipkg_conf_t * conf, message_level_t level, const char *fmt, ...)
  5821. +{
  5822. + va_list ap;
  5823. + char ts[256];
  5824. +
  5825. + if (ipkg_cb_message)
  5826. + {
  5827. + va_start (ap, fmt);
  5828. + vsnprintf (ts,256,fmt, ap);
  5829. + va_end (ap);
  5830. + ipkg_cb_message(conf,level,ts);
  5831. + }
  5832. +}
  5833. +#endif
  5834. diff -Nur busybox-1.12.1.orig/archival/libipkg/ipkg_message.h busybox-1.12.1/archival/libipkg/ipkg_message.h
  5835. --- busybox-1.12.1.orig/archival/libipkg/ipkg_message.h 1970-01-01 01:00:00.000000000 +0100
  5836. +++ busybox-1.12.1/archival/libipkg/ipkg_message.h 2008-10-23 11:41:37.000000000 +0200
  5837. @@ -0,0 +1,32 @@
  5838. +/* ipkg_message.h - the itsy package management system
  5839. +
  5840. + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
  5841. +
  5842. + This program is free software; you can redistribute it and/or
  5843. + modify it under the terms of the GNU General Public License as
  5844. + published by the Free Software Foundation; either version 2, or (at
  5845. + your option) any later version.
  5846. +
  5847. + This program is distributed in the hope that it will be useful, but
  5848. + WITHOUT ANY WARRANTY; without even the implied warranty of
  5849. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  5850. + General Public License for more details.
  5851. +*/
  5852. +
  5853. +#ifndef _IPKG_MESSAGE_H_
  5854. +#define _IPKG_MESSAGE_H_
  5855. +
  5856. +#include "ipkg.h"
  5857. +#include "ipkg_conf.h"
  5858. +
  5859. +typedef enum {
  5860. + IPKG_ERROR, /* error conditions */
  5861. + IPKG_NOTICE, /* normal but significant condition */
  5862. + IPKG_INFO, /* informational message */
  5863. + IPKG_DEBUG, /* debug level message */
  5864. + IPKG_DEBUG2, /* more debug level message */
  5865. +} message_level_t;
  5866. +
  5867. +extern void ipkg_message(ipkg_conf_t *conf, message_level_t level, const char *fmt, ...);
  5868. +
  5869. +#endif /* _IPKG_MESSAGE_H_ */
  5870. diff -Nur busybox-1.12.1.orig/archival/libipkg/ipkg_remove.c busybox-1.12.1/archival/libipkg/ipkg_remove.c
  5871. --- busybox-1.12.1.orig/archival/libipkg/ipkg_remove.c 1970-01-01 01:00:00.000000000 +0100
  5872. +++ busybox-1.12.1/archival/libipkg/ipkg_remove.c 2008-10-23 14:42:08.000000000 +0200
  5873. @@ -0,0 +1,385 @@
  5874. +/* ipkg_remove.c - the itsy package management system
  5875. +
  5876. + Carl D. Worth
  5877. +
  5878. + Copyright (C) 2001 University of Southern California
  5879. +
  5880. + This program is free software; you can redistribute it and/or
  5881. + modify it under the terms of the GNU General Public License as
  5882. + published by the Free Software Foundation; either version 2, or (at
  5883. + your option) any later version.
  5884. +
  5885. + This program is distributed in the hope that it will be useful, but
  5886. + WITHOUT ANY WARRANTY; without even the implied warranty of
  5887. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  5888. + General Public License for more details.
  5889. +*/
  5890. +
  5891. +#include "ipkg.h"
  5892. +#include "ipkg_message.h"
  5893. +
  5894. +#include <glob.h>
  5895. +
  5896. +#include "ipkg_remove.h"
  5897. +
  5898. +#include "file_util.h"
  5899. +#include "sprintf_alloc.h"
  5900. +#include "str_util.h"
  5901. +
  5902. +#include "ipkg_cmd.h"
  5903. +
  5904. +int ipkg_remove_dependent_pkgs (ipkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **dependents);
  5905. +
  5906. +/*
  5907. + * Returns number of the number of packages depending on the packages provided by this package.
  5908. + * Every package implicitly provides itself.
  5909. + */
  5910. +int pkg_has_installed_dependents(pkg_t *pkg, abstract_pkg_t *** pdependents)
  5911. +{
  5912. + int nprovides = pkg->provides_count;
  5913. + abstract_pkg_t **provides = pkg->provides;
  5914. + int n_installed_dependents = 0;
  5915. + int i;
  5916. + for (i = 0; i <= nprovides; i++) {
  5917. + abstract_pkg_t *providee = provides[i];
  5918. + abstract_pkg_t **dependers = providee->depended_upon_by;
  5919. + abstract_pkg_t *dep_ab_pkg;
  5920. + if (dependers == NULL)
  5921. + continue;
  5922. + while ((dep_ab_pkg = *dependers++) != NULL) {
  5923. + if (dep_ab_pkg->state_status == SS_INSTALLED){
  5924. + n_installed_dependents++;
  5925. + }
  5926. + }
  5927. +
  5928. + }
  5929. + /* if caller requested the set of installed dependents */
  5930. + if (pdependents) {
  5931. + int p = 0;
  5932. + abstract_pkg_t **dependents = (abstract_pkg_t **)malloc((n_installed_dependents+1)*sizeof(abstract_pkg_t *));
  5933. +
  5934. + if ( dependents == NULL ){
  5935. + fprintf(stderr,"%s Unable to allocate memory. REPORT THIS BUG IN BUGZILLA PLEASE\n", __FUNCTION__);
  5936. + return -1;
  5937. + }
  5938. +
  5939. + *pdependents = dependents;
  5940. + for (i = 0; i <= nprovides; i++) {
  5941. + abstract_pkg_t *providee = provides[i];
  5942. + abstract_pkg_t **dependers = providee->depended_upon_by;
  5943. + abstract_pkg_t *dep_ab_pkg;
  5944. + if (dependers == NULL)
  5945. + continue;
  5946. + while ((dep_ab_pkg = *dependers++) != NULL) {
  5947. + if (dep_ab_pkg->state_status == SS_INSTALLED && !(dep_ab_pkg->state_flag & SF_MARKED)) {
  5948. + dependents[p++] = dep_ab_pkg;
  5949. + dep_ab_pkg->state_flag |= SF_MARKED;
  5950. + }
  5951. + }
  5952. + }
  5953. + dependents[p] = NULL;
  5954. + /* now clear the marks */
  5955. + for (i = 0; i < p; i++) {
  5956. + abstract_pkg_t *dep_ab_pkg = dependents[i];
  5957. + dep_ab_pkg->state_flag &= ~SF_MARKED;
  5958. + }
  5959. + }
  5960. + return n_installed_dependents;
  5961. +}
  5962. +
  5963. +int ipkg_remove_dependent_pkgs (ipkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **dependents)
  5964. +{
  5965. + int i;
  5966. + int a;
  5967. + int count;
  5968. + pkg_vec_t *dependent_pkgs = pkg_vec_alloc();
  5969. + abstract_pkg_t * ab_pkg;
  5970. +
  5971. + if((ab_pkg = pkg->parent) == NULL){
  5972. + fprintf(stderr, "%s: unable to get dependent pkgs. pkg %s isn't in hash table\n",
  5973. + __FUNCTION__, pkg->name);
  5974. + return 0;
  5975. + }
  5976. +
  5977. + if (dependents == NULL)
  5978. + return 0;
  5979. +
  5980. + // here i am using the dependencies_checked
  5981. + if (ab_pkg->dependencies_checked == 2) // variable to make out whether this package
  5982. + return 0; // has already been encountered in the process
  5983. + // of marking packages for removal - Karthik
  5984. + ab_pkg->dependencies_checked = 2;
  5985. +
  5986. + i = 0;
  5987. + count = 1;
  5988. + while (dependents [i] != NULL) {
  5989. + abstract_pkg_t *dep_ab_pkg = dependents[i];
  5990. +
  5991. + if (dep_ab_pkg->dependencies_checked == 2){
  5992. + i++;
  5993. + continue;
  5994. + }
  5995. + if (dep_ab_pkg->state_status == SS_INSTALLED) {
  5996. + for (a = 0; a < dep_ab_pkg->pkgs->len; a++) {
  5997. + pkg_t *dep_pkg = dep_ab_pkg->pkgs->pkgs[a];
  5998. + if (dep_pkg->state_status == SS_INSTALLED) {
  5999. + pkg_vec_insert(dependent_pkgs, dep_pkg);
  6000. + count++;
  6001. + }
  6002. + }
  6003. + }
  6004. + i++;
  6005. + /* 1 - to keep track of visited ab_pkgs when checking for possiblility of a broken removal of pkgs.
  6006. + * 2 - to keep track of pkgs whose deps have been checked alrdy - Karthik */
  6007. + }
  6008. +
  6009. + if (count == 1)
  6010. + return 0;
  6011. +
  6012. +
  6013. + for (i = 0; i < dependent_pkgs->len; i++) {
  6014. + int err = ipkg_remove_pkg(conf, dependent_pkgs->pkgs[i],0);
  6015. + if (err)
  6016. + return err;
  6017. + }
  6018. + return 0;
  6019. +}
  6020. +
  6021. +static int user_prefers_removing_dependents(ipkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **dependents)
  6022. +{
  6023. + abstract_pkg_t *dep_ab_pkg;
  6024. + ipkg_message(conf, IPKG_ERROR, "Package %s is depended upon by packages:\n", pkg->name);
  6025. + while ((dep_ab_pkg = *dependents++) != NULL) {
  6026. + if (dep_ab_pkg->state_status == SS_INSTALLED)
  6027. + ipkg_message(conf, IPKG_ERROR, "\t%s\n", dep_ab_pkg->name);
  6028. + }
  6029. + ipkg_message(conf, IPKG_ERROR, "These might cease to work if package %s is removed.\n\n", pkg->name);
  6030. + ipkg_message(conf, IPKG_ERROR, "");
  6031. + ipkg_message(conf, IPKG_ERROR, "You can force removal of this package with -force-depends.\n");
  6032. + ipkg_message(conf, IPKG_ERROR, "You can force removal of this package and its dependents\n");
  6033. + ipkg_message(conf, IPKG_ERROR, "with -force-removal-of-dependent-packages or -recursive\n");
  6034. + ipkg_message(conf, IPKG_ERROR, "or by setting option force_removal_of_dependent_packages\n");
  6035. + ipkg_message(conf, IPKG_ERROR, "in ipkg.conf.\n");
  6036. + return 0;
  6037. +}
  6038. +
  6039. +int ipkg_remove_pkg(ipkg_conf_t *conf, pkg_t *pkg,int message)
  6040. +{
  6041. +/* Actually, when "message == 1" I have been called from an upgrade, and not from a normal remove
  6042. + thus I wan't check for essential, as I'm upgrading.
  6043. + I hope it won't break anything :)
  6044. +*/
  6045. + int err;
  6046. + abstract_pkg_t *parent_pkg = NULL;
  6047. +
  6048. + if (pkg->essential && !message) {
  6049. + if (conf->force_removal_of_essential_packages) {
  6050. + fprintf(stderr, "WARNING: Removing essential package %s under your coercion.\n"
  6051. + "\tIf your system breaks, you get to keep both pieces\n",
  6052. + pkg->name);
  6053. + } else {
  6054. + fprintf(stderr, "ERROR: Refusing to remove essential package %s.\n"
  6055. + "\tRemoving an essential package may lead to an unusable system, but if\n"
  6056. + "\tyou enjoy that kind of pain, you can force ipkg to proceed against\n"
  6057. + "\tits will with the option: -force-removal-of-essential-packages\n",
  6058. + pkg->name);
  6059. + return IPKG_PKG_IS_ESSENTIAL;
  6060. + }
  6061. + }
  6062. +
  6063. + if ((parent_pkg = pkg->parent) == NULL)
  6064. + return 0;
  6065. +
  6066. + /* only attempt to remove dependent installed packages if
  6067. + * force_depends is not specified or the package is being
  6068. + * replaced.
  6069. + */
  6070. + if (!conf->force_depends
  6071. + && !(pkg->state_flag & SF_REPLACE)) {
  6072. + abstract_pkg_t **dependents;
  6073. + int has_installed_dependents =
  6074. + pkg_has_installed_dependents(pkg, &dependents);
  6075. +
  6076. + if (has_installed_dependents) {
  6077. + /*
  6078. + * if this package is depended up by others, then either we should
  6079. + * not remove it or we should remove it and all of its dependents
  6080. + */
  6081. +
  6082. + if (!conf->force_removal_of_dependent_packages
  6083. + && !user_prefers_removing_dependents(conf, pkg, dependents)) {
  6084. + return IPKG_PKG_HAS_DEPENDENTS;
  6085. + }
  6086. +
  6087. + /* remove packages depending on this package - Karthik */
  6088. + err = ipkg_remove_dependent_pkgs (conf, pkg, dependents);
  6089. + free(dependents);
  6090. + if (err) return err;
  6091. + }
  6092. + }
  6093. +
  6094. + if ( message==0 ){
  6095. + printf("Removing package %s from %s...\n", pkg->name, pkg->dest->name);
  6096. + fflush(stdout);
  6097. + }
  6098. + pkg->state_flag |= SF_FILELIST_CHANGED;
  6099. +
  6100. + pkg->state_want = SW_DEINSTALL;
  6101. + ipkg_state_changed++;
  6102. +
  6103. + pkg_run_script(conf, pkg, "prerm", "remove");
  6104. +
  6105. + /* DPKG_INCOMPATIBILITY: dpkg is slightly different here. It
  6106. + maintains an empty filelist rather than deleting it. That seems
  6107. + like a big pain, and I don't see that that should make a big
  6108. + difference, but for anyone who wants tighter compatibility,
  6109. + feel free to fix this. */
  6110. + remove_data_files_and_list(conf, pkg);
  6111. +
  6112. + pkg_run_script(conf, pkg, "postrm", "remove");
  6113. +
  6114. + remove_maintainer_scripts_except_postrm(conf, pkg);
  6115. +
  6116. + /* Aman Gupta - Since ipkg is made for handheld devices with limited
  6117. + * space, it doesn't make sense to leave extra configurations, files,
  6118. + * and maintainer scripts left around. So, we make remove like purge,
  6119. + * and take out all the crap :) */
  6120. +
  6121. + remove_postrm(conf, pkg);
  6122. + pkg->state_status = SS_NOT_INSTALLED;
  6123. +
  6124. + if (parent_pkg)
  6125. + parent_pkg->state_status = SS_NOT_INSTALLED;
  6126. +
  6127. + return 0;
  6128. +}
  6129. +
  6130. +int ipkg_purge_pkg(ipkg_conf_t *conf, pkg_t *pkg)
  6131. +{
  6132. + ipkg_remove_pkg(conf, pkg,0);
  6133. + return 0;
  6134. +}
  6135. +
  6136. +int remove_data_files_and_list(ipkg_conf_t *conf, pkg_t *pkg)
  6137. +{
  6138. + str_list_t installed_dirs;
  6139. + str_list_t *installed_files;
  6140. + str_list_elt_t *iter;
  6141. + char *file_name;
  6142. + conffile_t *conffile;
  6143. + int removed_a_dir;
  6144. + pkg_t *owner;
  6145. +
  6146. + str_list_init(&installed_dirs);
  6147. + installed_files = pkg_get_installed_files(pkg);
  6148. +
  6149. + for (iter = installed_files->head; iter; iter = iter->next) {
  6150. + file_name = iter->data;
  6151. +
  6152. + if (file_is_dir(file_name)) {
  6153. + str_list_append(&installed_dirs, strdup(file_name));
  6154. + continue;
  6155. + }
  6156. +
  6157. + conffile = pkg_get_conffile(pkg, file_name);
  6158. + if (conffile) {
  6159. + /* XXX: QUESTION: Is this right? I figure we only need to
  6160. + save the conffile if it has been modified. Is that what
  6161. + dpkg does? Or does dpkg preserve all conffiles? If so,
  6162. + this seems like a better thing to do to conserve
  6163. + space. */
  6164. + if (conffile_has_been_modified(conf, conffile)) {
  6165. + printf(" not deleting modified conffile %s\n", file_name);
  6166. + fflush(stdout);
  6167. + continue;
  6168. + }
  6169. + }
  6170. +
  6171. + ipkg_message(conf, IPKG_INFO, " deleting %s (noaction=%d)\n", file_name, conf->noaction);
  6172. + if (!conf->noaction)
  6173. + unlink(file_name);
  6174. + }
  6175. +
  6176. + if (!conf->noaction) {
  6177. + do {
  6178. + removed_a_dir = 0;
  6179. + for (iter = installed_dirs.head; iter; iter = iter->next) {
  6180. + file_name = iter->data;
  6181. +
  6182. + if (rmdir(file_name) == 0) {
  6183. + ipkg_message(conf, IPKG_INFO, " deleting %s\n", file_name);
  6184. + removed_a_dir = 1;
  6185. + str_list_remove(&installed_dirs, &iter);
  6186. + }
  6187. + }
  6188. + } while (removed_a_dir);
  6189. + }
  6190. +
  6191. + pkg_free_installed_files(pkg);
  6192. + /* We have to remove the file list now, so that
  6193. + find_pkg_owning_file does not always just report this package */
  6194. + pkg_remove_installed_files_list(conf, pkg);
  6195. +
  6196. + /* Don't print warning for dirs that are provided by other packages */
  6197. + for (iter = installed_dirs.head; iter; iter = iter->next) {
  6198. + file_name = iter->data;
  6199. +
  6200. + owner = file_hash_get_file_owner(conf, file_name);
  6201. + if (owner) {
  6202. + free(iter->data);
  6203. + iter->data = NULL;
  6204. + str_list_remove(&installed_dirs, &iter);
  6205. + }
  6206. + }
  6207. +
  6208. + /* cleanup */
  6209. + for (iter = installed_dirs.head; iter; iter = iter->next) {
  6210. + free(iter->data);
  6211. + iter->data = NULL;
  6212. + }
  6213. + str_list_deinit(&installed_dirs);
  6214. +
  6215. + return 0;
  6216. +}
  6217. +
  6218. +int remove_maintainer_scripts_except_postrm(ipkg_conf_t *conf, pkg_t *pkg)
  6219. +{
  6220. + int i, err;
  6221. + char *globpattern;
  6222. + glob_t globbuf;
  6223. +
  6224. + if (conf->noaction) return 0;
  6225. +
  6226. + sprintf_alloc(&globpattern, "%s/%s.*",
  6227. + pkg->dest->info_dir, pkg->name);
  6228. + err = glob(globpattern, 0, NULL, &globbuf);
  6229. + free(globpattern);
  6230. + if (err) {
  6231. + return 0;
  6232. + }
  6233. +
  6234. + for (i = 0; i < globbuf.gl_pathc; i++) {
  6235. + if (str_ends_with(globbuf.gl_pathv[i], ".postrm")) {
  6236. + continue;
  6237. + }
  6238. + ipkg_message(conf, IPKG_INFO, " deleting %s\n", globbuf.gl_pathv[i]);
  6239. + unlink(globbuf.gl_pathv[i]);
  6240. + }
  6241. + globfree(&globbuf);
  6242. +
  6243. + return 0;
  6244. +}
  6245. +
  6246. +int remove_postrm(ipkg_conf_t *conf, pkg_t *pkg)
  6247. +{
  6248. + char *postrm_file_name;
  6249. +
  6250. + if (conf->noaction) return 0;
  6251. +
  6252. + sprintf_alloc(&postrm_file_name, "%s/%s.postrm",
  6253. + pkg->dest->info_dir, pkg->name);
  6254. + unlink(postrm_file_name);
  6255. + free(postrm_file_name);
  6256. +
  6257. + return 0;
  6258. +}
  6259. diff -Nur busybox-1.12.1.orig/archival/libipkg/ipkg_remove.h busybox-1.12.1/archival/libipkg/ipkg_remove.h
  6260. --- busybox-1.12.1.orig/archival/libipkg/ipkg_remove.h 1970-01-01 01:00:00.000000000 +0100
  6261. +++ busybox-1.12.1/archival/libipkg/ipkg_remove.h 2008-10-23 14:42:20.000000000 +0200
  6262. @@ -0,0 +1,33 @@
  6263. +/* ipkg_remove.h - the itsy package management system
  6264. +
  6265. + Carl D. Worth
  6266. +
  6267. + Copyright (C) 2001 University of Southern California
  6268. +
  6269. + This program is free software; you can redistribute it and/or
  6270. + modify it under the terms of the GNU General Public License as
  6271. + published by the Free Software Foundation; either version 2, or (at
  6272. + your option) any later version.
  6273. +
  6274. + This program is distributed in the hope that it will be useful, but
  6275. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6276. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6277. + General Public License for more details.
  6278. +*/
  6279. +
  6280. +#ifndef IPKG_REMOVE_H
  6281. +#define IPKG_REMOVE_H
  6282. +
  6283. +#include "pkg.h"
  6284. +#include "ipkg_conf.h"
  6285. +
  6286. +int ipkg_remove_pkg(ipkg_conf_t *conf, pkg_t *pkg,int message);
  6287. +int ipkg_purge_pkg(ipkg_conf_t *conf, pkg_t *pkg);
  6288. +int possible_broken_removal_of_packages (ipkg_conf_t *conf, pkg_t *pkg);
  6289. +int pkg_has_installed_dependents(pkg_t *pkg, abstract_pkg_t *** pdependents);
  6290. +int remove_data_files_and_list(ipkg_conf_t *conf, pkg_t *pkg);
  6291. +int remove_maintainer_scripts_except_postrm (ipkg_conf_t *conf, pkg_t *pkg);
  6292. +int remove_postrm (ipkg_conf_t *conf, pkg_t *pkg);
  6293. +
  6294. +
  6295. +#endif
  6296. diff -Nur busybox-1.12.1.orig/archival/libipkg/ipkg_upgrade.c busybox-1.12.1/archival/libipkg/ipkg_upgrade.c
  6297. --- busybox-1.12.1.orig/archival/libipkg/ipkg_upgrade.c 1970-01-01 01:00:00.000000000 +0100
  6298. +++ busybox-1.12.1/archival/libipkg/ipkg_upgrade.c 2008-10-23 14:43:14.000000000 +0200
  6299. @@ -0,0 +1,79 @@
  6300. +/* ipkg_upgrade.c - the itsy package management system
  6301. +
  6302. + Carl D. Worth
  6303. + Copyright (C) 2001 University of Southern California
  6304. +
  6305. + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
  6306. +
  6307. + This program is free software; you can redistribute it and/or
  6308. + modify it under the terms of the GNU General Public License as
  6309. + published by the Free Software Foundation; either version 2, or (at
  6310. + your option) any later version.
  6311. +
  6312. + This program is distributed in the hope that it will be useful, but
  6313. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6314. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6315. + General Public License for more details.
  6316. +*/
  6317. +
  6318. +#include "ipkg.h"
  6319. +#include "ipkg_install.h"
  6320. +#include "ipkg_message.h"
  6321. +
  6322. +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old);
  6323. +
  6324. +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old)
  6325. +{
  6326. + pkg_t *new;
  6327. + int cmp;
  6328. + char *old_version, *new_version;
  6329. +
  6330. + if (old->state_flag & SF_HOLD) {
  6331. + ipkg_message(conf, IPKG_NOTICE,
  6332. + "Not upgrading package %s which is marked "
  6333. + "hold (flags=%#x)\n", old->name, old->state_flag);
  6334. + return 0;
  6335. + }
  6336. +
  6337. + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, old->name);
  6338. + if (new == NULL) {
  6339. + old_version = pkg_version_str_alloc(old);
  6340. + ipkg_message(conf, IPKG_NOTICE,
  6341. + "Assuming locally installed package %s (%s) "
  6342. + "is up to date.\n", old->name, old_version);
  6343. + free(old_version);
  6344. + return 0;
  6345. + }
  6346. +
  6347. + old_version = pkg_version_str_alloc(old);
  6348. + new_version = pkg_version_str_alloc(new);
  6349. +
  6350. + cmp = pkg_compare_versions(old, new);
  6351. + ipkg_message(conf, IPKG_DEBUG,
  6352. + "comparing visible versions of pkg %s:"
  6353. + "\n\t%s is installed "
  6354. + "\n\t%s is available "
  6355. + "\n\t%d was comparison result\n",
  6356. + old->name, old_version, new_version, cmp);
  6357. + if (cmp == 0) {
  6358. + ipkg_message(conf, IPKG_INFO,
  6359. + "Package %s (%s) installed in %s is up to date.\n",
  6360. + old->name, old_version, old->dest->name);
  6361. + free(old_version);
  6362. + free(new_version);
  6363. + return 0;
  6364. + } else if (cmp > 0) {
  6365. + ipkg_message(conf, IPKG_NOTICE,
  6366. + "Not downgrading package %s on %s from %s to %s.\n",
  6367. + old->name, old->dest->name, old_version, new_version);
  6368. + free(old_version);
  6369. + free(new_version);
  6370. + return 0;
  6371. + } else if (cmp < 0) {
  6372. + new->dest = old->dest;
  6373. + old->state_want = SW_DEINSTALL;
  6374. + }
  6375. +
  6376. + new->state_flag |= SF_USER;
  6377. + return ipkg_install_pkg(conf, new,1);
  6378. +}
  6379. diff -Nur busybox-1.12.1.orig/archival/libipkg/ipkg_upgrade.h busybox-1.12.1/archival/libipkg/ipkg_upgrade.h
  6380. --- busybox-1.12.1.orig/archival/libipkg/ipkg_upgrade.h 1970-01-01 01:00:00.000000000 +0100
  6381. +++ busybox-1.12.1/archival/libipkg/ipkg_upgrade.h 2008-10-23 11:41:37.000000000 +0200
  6382. @@ -0,0 +1,18 @@
  6383. +/* ipkg_upgrade.c - the itsy package management system
  6384. +
  6385. + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
  6386. +
  6387. + This program is free software; you can redistribute it and/or
  6388. + modify it under the terms of the GNU General Public License as
  6389. + published by the Free Software Foundation; either version 2, or (at
  6390. + your option) any later version.
  6391. +
  6392. + This program is distributed in the hope that it will be useful, but
  6393. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6394. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6395. + General Public License for more details.
  6396. +*/
  6397. +
  6398. +#include "ipkg.h"
  6399. +
  6400. +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old);
  6401. diff -Nur busybox-1.12.1.orig/archival/libipkg/ipkg_utils.c busybox-1.12.1/archival/libipkg/ipkg_utils.c
  6402. --- busybox-1.12.1.orig/archival/libipkg/ipkg_utils.c 1970-01-01 01:00:00.000000000 +0100
  6403. +++ busybox-1.12.1/archival/libipkg/ipkg_utils.c 2008-10-23 14:44:05.000000000 +0200
  6404. @@ -0,0 +1,185 @@
  6405. +/* ipkg_utils.c - the itsy package management system
  6406. +
  6407. + Steven M. Ayer
  6408. +
  6409. + Copyright (C) 2002 Compaq Computer Corporation
  6410. +
  6411. + This program is free software; you can redistribute it and/or
  6412. + modify it under the terms of the GNU General Public License as
  6413. + published by the Free Software Foundation; either version 2, or (at
  6414. + your option) any later version.
  6415. +
  6416. + This program is distributed in the hope that it will be useful, but
  6417. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6418. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6419. + General Public License for more details.
  6420. +*/
  6421. +
  6422. +#include "ipkg.h"
  6423. +#include <errno.h>
  6424. +#include <ctype.h>
  6425. +#include <sys/vfs.h>
  6426. +
  6427. +#include "ipkg_utils.h"
  6428. +#include "pkg.h"
  6429. +#include "pkg_hash.h"
  6430. +
  6431. +void push_error_list(struct errlist ** errors, char * msg);
  6432. +void reverse_error_list(struct errlist **errors);
  6433. +void free_error_list(struct errlist **errors);
  6434. +
  6435. +struct errlist* error_list;
  6436. +
  6437. +int get_available_blocks(char * filesystem)
  6438. +{
  6439. + struct statfs sfs;
  6440. +
  6441. + if(statfs(filesystem, &sfs)){
  6442. + fprintf(stderr, "bad statfs\n");
  6443. + return 0;
  6444. + }
  6445. + /* fprintf(stderr, "reported fs type %x\n", sfs.f_type); */
  6446. + return ((sfs.f_bavail * sfs.f_bsize) / 1024);
  6447. +}
  6448. +
  6449. +char **read_raw_pkgs_from_file(const char *file_name)
  6450. +{
  6451. + FILE *fp;
  6452. + char **ret;
  6453. +
  6454. + if(!(fp = fopen(file_name, "r"))){
  6455. + fprintf(stderr, "can't get %s open for read\n", file_name);
  6456. + return NULL;
  6457. + }
  6458. +
  6459. + ret = read_raw_pkgs_from_stream(fp);
  6460. +
  6461. + fclose(fp);
  6462. +
  6463. + return ret;
  6464. +}
  6465. +
  6466. +char **read_raw_pkgs_from_stream(FILE *fp)
  6467. +{
  6468. + char **raw = NULL, *buf, *scout;
  6469. + int count = 0;
  6470. + size_t size = 512;
  6471. +
  6472. + buf = malloc (size);
  6473. +
  6474. + while (fgets(buf, size, fp)) {
  6475. + while (strlen (buf) == (size - 1)
  6476. + && buf[size-2] != '\n') {
  6477. + size_t o = size - 1;
  6478. + size *= 2;
  6479. + buf = realloc (buf, size);
  6480. + if (fgets (buf + o, size - o, fp) == NULL)
  6481. + break;
  6482. + }
  6483. +
  6484. + if(!(count % 50))
  6485. + raw = realloc(raw, (count + 50) * sizeof(char *));
  6486. +
  6487. + if((scout = strchr(buf, '\n')))
  6488. + *scout = '\0';
  6489. +
  6490. + raw[count++] = strdup(buf);
  6491. + }
  6492. +
  6493. + raw = realloc(raw, (count + 1) * sizeof(char *));
  6494. + raw[count] = NULL;
  6495. +
  6496. + free (buf);
  6497. +
  6498. + return raw;
  6499. +}
  6500. +
  6501. +/* something to remove whitespace, a hash pooper */
  6502. +char *trim_alloc(char *line)
  6503. +{
  6504. + char *new;
  6505. + char *dest, *src, *end;
  6506. +
  6507. + new = malloc(strlen(line) + 1);
  6508. + if ( new == NULL ){
  6509. + fprintf(stderr,"%s: Unable to allocate memory\n",__FUNCTION__);
  6510. + return NULL;
  6511. + }
  6512. + dest = new, src = line, end = line + (strlen(line) - 1);
  6513. +
  6514. + /* remove it from the front */
  6515. + while(src &&
  6516. + isspace(*src) &&
  6517. + *src)
  6518. + src++;
  6519. + /* and now from the back */
  6520. + while((end > src) &&
  6521. + isspace(*end))
  6522. + end--;
  6523. + end++;
  6524. + *end = '\0';
  6525. + strcpy(new, src);
  6526. + /* this does from the first space
  6527. + * blasting away any versions stuff in depends
  6528. + while(src &&
  6529. + !isspace(*src) &&
  6530. + *src)
  6531. + *dest++ = *src++;
  6532. + *dest = '\0';
  6533. + */
  6534. +
  6535. + return new;
  6536. +}
  6537. +
  6538. +int line_is_blank(const char *line)
  6539. +{
  6540. + const char *s;
  6541. +
  6542. + for (s = line; *s; s++) {
  6543. + if (!isspace(*s))
  6544. + return 0;
  6545. + }
  6546. + return 1;
  6547. +}
  6548. +
  6549. +void push_error_list(struct errlist ** errors, char * msg){
  6550. + struct errlist *err_lst_tmp;
  6551. +
  6552. +
  6553. + err_lst_tmp = malloc ( sizeof (err_lst_tmp) );
  6554. + err_lst_tmp->errmsg=strdup(msg) ;
  6555. + err_lst_tmp->next = *errors;
  6556. + *errors = err_lst_tmp;
  6557. +}
  6558. +
  6559. +
  6560. +void reverse_error_list(struct errlist **errors){
  6561. + struct errlist *result=NULL;
  6562. + struct errlist *current= *errors;
  6563. + struct errlist *next;
  6564. +
  6565. + while ( current != NULL ) {
  6566. + next = current->next;
  6567. + current->next=result;
  6568. + result=current;
  6569. + current=next;
  6570. + }
  6571. + *errors=result;
  6572. +
  6573. +}
  6574. +
  6575. +
  6576. +void free_error_list(struct errlist **errors){
  6577. + struct errlist *current = *errors;
  6578. +
  6579. + while (current != NULL) {
  6580. + free(current->errmsg);
  6581. + current = (*errors)->next;
  6582. + free(*errors);
  6583. + *errors = current;
  6584. + }
  6585. +
  6586. +
  6587. +}
  6588. +
  6589. +
  6590. diff -Nur busybox-1.12.1.orig/archival/libipkg/ipkg_utils.h busybox-1.12.1/archival/libipkg/ipkg_utils.h
  6591. --- busybox-1.12.1.orig/archival/libipkg/ipkg_utils.h 1970-01-01 01:00:00.000000000 +0100
  6592. +++ busybox-1.12.1/archival/libipkg/ipkg_utils.h 2008-10-23 11:41:37.000000000 +0200
  6593. @@ -0,0 +1,29 @@
  6594. +/* ipkg_utils.h - the itsy package management system
  6595. +
  6596. + Steven M. Ayer
  6597. +
  6598. + Copyright (C) 2002 Compaq Computer Corporation
  6599. +
  6600. + This program is free software; you can redistribute it and/or
  6601. + modify it under the terms of the GNU General Public License as
  6602. + published by the Free Software Foundation; either version 2, or (at
  6603. + your option) any later version.
  6604. +
  6605. + This program is distributed in the hope that it will be useful, but
  6606. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6607. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6608. + General Public License for more details.
  6609. +*/
  6610. +
  6611. +#ifndef IPKG_UTILS_H
  6612. +#define IPKG_UTILS_H
  6613. +
  6614. +#include "pkg.h"
  6615. +
  6616. +int get_available_blocks(char * filesystem);
  6617. +char **read_raw_pkgs_from_file(const char *file_name);
  6618. +char **read_raw_pkgs_from_stream(FILE *fp);
  6619. +char *trim_alloc(char * line);
  6620. +int line_is_blank(const char *line);
  6621. +
  6622. +#endif
  6623. diff -Nur busybox-1.12.1.orig/archival/libipkg/Kbuild busybox-1.12.1/archival/libipkg/Kbuild
  6624. --- busybox-1.12.1.orig/archival/libipkg/Kbuild 1970-01-01 01:00:00.000000000 +0100
  6625. +++ busybox-1.12.1/archival/libipkg/Kbuild 2008-10-23 11:41:37.000000000 +0200
  6626. @@ -0,0 +1,60 @@
  6627. +# Makefile for busybox
  6628. +#
  6629. +# Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
  6630. +# Copyright (C) 2006 OpenWrt.org
  6631. +#
  6632. +# Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
  6633. +
  6634. +LIBIPKG_CORE_OBJS:= \
  6635. + args.o \
  6636. + libipkg.o \
  6637. + user.o \
  6638. +
  6639. +LIBIPKG_CMD_OBJS:= \
  6640. + ipkg_cmd.o \
  6641. + ipkg_configure.o \
  6642. + ipkg_download.o \
  6643. + ipkg_install.o \
  6644. + ipkg_remove.o \
  6645. + ipkg_upgrade.o \
  6646. +
  6647. +LIBIPKG_DB_OBJS:= \
  6648. + hash_table.o \
  6649. + ipkg_conf.o \
  6650. + ipkg_utils.o \
  6651. + pkg.o \
  6652. + pkg_depends.o \
  6653. + pkg_extract.o \
  6654. + pkg_hash.o \
  6655. + pkg_parse.o \
  6656. + pkg_vec.o \
  6657. +
  6658. +LIBIPKG_LIST_OBJS:= \
  6659. + conffile.o \
  6660. + conffile_list.o \
  6661. + nv_pair.o \
  6662. + nv_pair_list.o \
  6663. + pkg_dest.o \
  6664. + pkg_dest_list.o \
  6665. + pkg_src.o \
  6666. + pkg_src_list.o \
  6667. + str_list.o \
  6668. + void_list.o \
  6669. +
  6670. +LIBIPKG_UTIL_OBJS:= \
  6671. + file_util.o \
  6672. + ipkg_message.o \
  6673. + str_util.o \
  6674. + xsystem.o \
  6675. +
  6676. +lib-y :=
  6677. +lib-$(CONFIG_IPKG) += $(LIBIPKG_CORE_OBJS)
  6678. +lib-$(CONFIG_IPKG) += $(LIBIPKG_CMD_OBJS)
  6679. +lib-$(CONFIG_IPKG) += $(LIBIPKG_DB_OBJS)
  6680. +lib-$(CONFIG_IPKG) += $(LIBIPKG_LIST_OBJS)
  6681. +lib-$(CONFIG_IPKG) += $(LIBIPKG_UTIL_OBJS)
  6682. +
  6683. +ifeq ($(strip $(IPKG_ARCH)),)
  6684. +IPKG_ARCH:=$(TARGET_ARCH)
  6685. +endif
  6686. +CFLAGS += -DIPKG_LIB -DIPKGLIBDIR="\"/usr/lib\"" -DHOST_CPU_STR="\"$(IPKG_ARCH)\""
  6687. diff -Nur busybox-1.12.1.orig/archival/libipkg/libipkg.c busybox-1.12.1/archival/libipkg/libipkg.c
  6688. --- busybox-1.12.1.orig/archival/libipkg/libipkg.c 1970-01-01 01:00:00.000000000 +0100
  6689. +++ busybox-1.12.1/archival/libipkg/libipkg.c 2008-10-23 14:59:01.000000000 +0200
  6690. @@ -0,0 +1,532 @@
  6691. +/* ipkglib.c - the itsy package management system
  6692. +
  6693. + Florina Boor
  6694. +
  6695. + Copyright (C) 2003 kernel concepts
  6696. +
  6697. + This program is free software; you can redistribute it and/or
  6698. + modify it under the terms of the GNU General Public License as
  6699. + published by the Free Software Foundation; either version 2, or (at
  6700. + your option) any later version.
  6701. +
  6702. + This program is distributed in the hope that it will be useful, but
  6703. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6704. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6705. + General Public License for more details.
  6706. +*/
  6707. +
  6708. +#ifdef IPKG_LIB
  6709. +
  6710. +#include "ipkg.h"
  6711. +#include "ipkg_includes.h"
  6712. +#include "libipkg.h"
  6713. +
  6714. +#include "args.h"
  6715. +#include "ipkg_conf.h"
  6716. +#include "ipkg_cmd.h"
  6717. +#include "file_util.h"
  6718. +
  6719. +int ipkg_file_what(args_t *args, const char *file, const char* command);
  6720. +int default_ipkg_message_callback(ipkg_conf_t *conf, message_level_t level,
  6721. + char *msg);
  6722. +int default_ipkg_list_callback(char *name, char *desc, char *version);
  6723. +int default_ipkg_files_callback(char *desc);
  6724. +int default_ipkg_status_callback(char *desc);
  6725. +char* default_ipkg_response_callback(char *question);
  6726. +
  6727. +
  6728. +ipkg_message_callback ipkg_cb_message = NULL;
  6729. +ipkg_response_callback ipkg_cb_response = NULL;
  6730. +ipkg_status_callback ipkg_cb_status = NULL;
  6731. +ipkg_list_callback ipkg_cb_list = NULL;
  6732. +
  6733. +
  6734. +int
  6735. +ipkg_init (ipkg_message_callback mcall,
  6736. + ipkg_response_callback rcall,
  6737. + args_t * args)
  6738. +{
  6739. + ipkg_cb_message = mcall;
  6740. + ipkg_cb_response = rcall;
  6741. +
  6742. + args_init (args);
  6743. +
  6744. + return 0;
  6745. +}
  6746. +
  6747. +
  6748. +int
  6749. +ipkg_deinit (args_t * args)
  6750. +{
  6751. + args_deinit (args);
  6752. + ipkg_cb_message = NULL;
  6753. + ipkg_cb_response = NULL;
  6754. +
  6755. + /* place other cleanup stuff here */
  6756. +
  6757. + return 0;
  6758. +}
  6759. +
  6760. +
  6761. +int
  6762. +ipkg_packages_list(args_t *args,
  6763. + const char *packages,
  6764. + ipkg_list_callback cblist,
  6765. + void *userdata)
  6766. +{
  6767. + ipkg_cmd_t *cmd;
  6768. + ipkg_conf_t ipkg_conf;
  6769. + int err;
  6770. +
  6771. + err = ipkg_conf_init (&ipkg_conf, args);
  6772. + if (err)
  6773. + {
  6774. + return err;
  6775. + }
  6776. +
  6777. + ipkg_cb_list = cblist;
  6778. + /* we need to do this because of static declarations,
  6779. + * maybe a good idea to change */
  6780. + cmd = ipkg_cmd_find ("list");
  6781. + if (packages)
  6782. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
  6783. + else
  6784. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
  6785. + ipkg_cb_list = NULL;
  6786. + ipkg_conf_deinit (&ipkg_conf);
  6787. + return (err);
  6788. +}
  6789. +
  6790. +
  6791. +int
  6792. +ipkg_packages_status(args_t *args,
  6793. + const char *packages,
  6794. + ipkg_status_callback cbstatus,
  6795. + void *userdata)
  6796. +{
  6797. + ipkg_cmd_t *cmd;
  6798. + ipkg_conf_t ipkg_conf;
  6799. + int err;
  6800. +
  6801. + err = ipkg_conf_init (&ipkg_conf, args);
  6802. + if (err)
  6803. + {
  6804. + return err;
  6805. + }
  6806. +
  6807. + ipkg_cb_status = cbstatus;
  6808. +
  6809. + /* we need to do this because of static declarations,
  6810. + * maybe a good idea to change */
  6811. + cmd = ipkg_cmd_find ("status");
  6812. + if (packages)
  6813. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
  6814. + else
  6815. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
  6816. +
  6817. + ipkg_cb_status = NULL;
  6818. + ipkg_conf_deinit (&ipkg_conf);
  6819. + return (err);
  6820. +}
  6821. +
  6822. +
  6823. +int
  6824. +ipkg_packages_info(args_t *args,
  6825. + const char *packages,
  6826. + ipkg_status_callback cbstatus,
  6827. + void *userdata)
  6828. +{
  6829. + ipkg_cmd_t *cmd;
  6830. + ipkg_conf_t ipkg_conf;
  6831. + int err;
  6832. +
  6833. + err = ipkg_conf_init (&ipkg_conf, args);
  6834. + if (err)
  6835. + {
  6836. + return err;
  6837. + }
  6838. +
  6839. + ipkg_cb_status = cbstatus;
  6840. +
  6841. + /* we need to do this because of static declarations,
  6842. + * maybe a good idea to change */
  6843. + cmd = ipkg_cmd_find ("info");
  6844. + if (packages)
  6845. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
  6846. + else
  6847. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
  6848. +
  6849. + ipkg_cb_status = NULL;
  6850. + ipkg_conf_deinit (&ipkg_conf);
  6851. + return (err);
  6852. +}
  6853. +
  6854. +
  6855. +int
  6856. +ipkg_packages_install (args_t * args, const char *name)
  6857. +{
  6858. + ipkg_cmd_t *cmd;
  6859. + ipkg_conf_t ipkg_conf;
  6860. + int err;
  6861. +
  6862. + /* this error should be handled in application */
  6863. + if (!name || !strlen (name))
  6864. + return (-1);
  6865. +
  6866. + err = ipkg_conf_init (&ipkg_conf, args);
  6867. + if (err)
  6868. + {
  6869. + return err;
  6870. + }
  6871. +
  6872. + /* we need to do this because of static declarations,
  6873. + * maybe a good idea to change */
  6874. + cmd = ipkg_cmd_find ("install");
  6875. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
  6876. +
  6877. + ipkg_conf_deinit(&ipkg_conf);
  6878. + return (err);
  6879. +}
  6880. +
  6881. +
  6882. +int
  6883. +ipkg_packages_remove(args_t *args, const char *name, int purge)
  6884. +{
  6885. + ipkg_cmd_t *cmd;
  6886. + ipkg_conf_t ipkg_conf;
  6887. + int err;
  6888. +
  6889. + /* this error should be handled in application */
  6890. + if (!name || !strlen (name))
  6891. + return (-1);
  6892. +
  6893. + err = ipkg_conf_init (&ipkg_conf, args);
  6894. + if (err)
  6895. + {
  6896. + return err;
  6897. + }
  6898. +
  6899. + /* we need to do this because of static declarations,
  6900. + * maybe a good idea to change */
  6901. + if (purge)
  6902. + cmd = ipkg_cmd_find ("purge");
  6903. + else
  6904. + cmd = ipkg_cmd_find ("remove");
  6905. +
  6906. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
  6907. +
  6908. + ipkg_conf_deinit(&ipkg_conf);
  6909. + return (err);
  6910. +}
  6911. +
  6912. +
  6913. +int
  6914. +ipkg_lists_update(args_t *args)
  6915. +{
  6916. + ipkg_cmd_t *cmd;
  6917. + ipkg_conf_t ipkg_conf;
  6918. + int err;
  6919. +
  6920. + err = ipkg_conf_init (&ipkg_conf, args);
  6921. + if (err)
  6922. + {
  6923. + return err;
  6924. + }
  6925. +
  6926. + /* we need to do this because of static declarations,
  6927. + * maybe a good idea to change */
  6928. + cmd = ipkg_cmd_find ("update");
  6929. +
  6930. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, NULL);
  6931. +
  6932. + ipkg_conf_deinit(&ipkg_conf);
  6933. + return (err);
  6934. +}
  6935. +
  6936. +
  6937. +int
  6938. +ipkg_packages_upgrade(args_t *args)
  6939. +{
  6940. + ipkg_cmd_t *cmd;
  6941. + ipkg_conf_t ipkg_conf;
  6942. + int err;
  6943. +
  6944. + err = ipkg_conf_init (&ipkg_conf, args);
  6945. + if (err)
  6946. + {
  6947. + return err;
  6948. + }
  6949. +
  6950. + /* we need to do this because of static declarations,
  6951. + * maybe a good idea to change */
  6952. + cmd = ipkg_cmd_find ("upgrade");
  6953. +
  6954. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, NULL);
  6955. +
  6956. + ipkg_conf_deinit(&ipkg_conf);
  6957. + return (err);
  6958. +}
  6959. +
  6960. +
  6961. +int
  6962. +ipkg_packages_download (args_t * args, const char *name)
  6963. +{
  6964. + ipkg_cmd_t *cmd;
  6965. + ipkg_conf_t ipkg_conf;
  6966. + int err;
  6967. +
  6968. + /* this error should be handled in application */
  6969. + if (!name || !strlen (name))
  6970. + return (-1);
  6971. +
  6972. + err = ipkg_conf_init (&ipkg_conf, args);
  6973. + if (err)
  6974. + {
  6975. + return err;
  6976. + }
  6977. +
  6978. + /* we need to do this because of static declarations,
  6979. + * maybe a good idea to change */
  6980. + cmd = ipkg_cmd_find ("download");
  6981. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
  6982. +
  6983. + ipkg_conf_deinit(&ipkg_conf);
  6984. + return (err);
  6985. +}
  6986. +
  6987. +
  6988. +int
  6989. +ipkg_package_files(args_t *args,
  6990. + const char *name,
  6991. + ipkg_list_callback cblist,
  6992. + void *userdata)
  6993. +{
  6994. + ipkg_cmd_t *cmd;
  6995. + ipkg_conf_t ipkg_conf;
  6996. + int err;
  6997. +
  6998. + /* this error should be handled in application */
  6999. + if (!name || !strlen (name))
  7000. + return (-1);
  7001. +
  7002. + err = ipkg_conf_init (&ipkg_conf, args);
  7003. + if (err)
  7004. + {
  7005. + return err;
  7006. + }
  7007. +
  7008. + ipkg_cb_list = cblist;
  7009. +
  7010. + /* we need to do this because of static declarations,
  7011. + * maybe a good idea to change */
  7012. + cmd = ipkg_cmd_find ("files");
  7013. +
  7014. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, userdata);
  7015. +
  7016. + ipkg_cb_list = NULL;
  7017. + ipkg_conf_deinit(&ipkg_conf);
  7018. + return (err);
  7019. +}
  7020. +
  7021. +
  7022. +int
  7023. +ipkg_file_search(args_t *args,
  7024. + const char *file,
  7025. + ipkg_list_callback cblist,
  7026. + void *userdata)
  7027. +{
  7028. + ipkg_cmd_t *cmd;
  7029. + ipkg_conf_t ipkg_conf;
  7030. + int err;
  7031. +
  7032. + /* this error should be handled in application */
  7033. + if (!file || !strlen (file))
  7034. + return (-1);
  7035. +
  7036. + err = ipkg_conf_init (&ipkg_conf, args);
  7037. + if (err)
  7038. + {
  7039. + return err;
  7040. + }
  7041. +
  7042. + ipkg_cb_list = cblist;
  7043. +
  7044. + /* we need to do this because of static declarations,
  7045. + * maybe a good idea to change */
  7046. + cmd = ipkg_cmd_find ("search");
  7047. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &file, userdata);
  7048. +
  7049. + ipkg_cb_list = NULL;
  7050. + ipkg_conf_deinit(&ipkg_conf);
  7051. + return(err);
  7052. +}
  7053. +
  7054. +
  7055. +int
  7056. +ipkg_file_what(args_t *args, const char *file, const char* command)
  7057. +{
  7058. + ipkg_cmd_t *cmd;
  7059. + ipkg_conf_t ipkg_conf;
  7060. + int err;
  7061. +
  7062. + /* this error should be handled in application */
  7063. + if (!file || !strlen (file))
  7064. + return (-1);
  7065. +
  7066. + err = ipkg_conf_init (&ipkg_conf, args);
  7067. + if (err)
  7068. + {
  7069. + return err;
  7070. + }
  7071. +
  7072. + /* we need to do this because of static declarations,
  7073. + * maybe a good idea to change */
  7074. + cmd = ipkg_cmd_find (command);
  7075. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &file, NULL);
  7076. +
  7077. + ipkg_conf_deinit(&ipkg_conf);
  7078. + return(err);
  7079. +}
  7080. +
  7081. +#define ipkg_package_whatdepends(args,file) ipkg_file_what(args,file,"whatdepends")
  7082. +#define ipkg_package_whatrecommends(args, file) ipkg_file_what(args,file,"whatrecommends")
  7083. +#define ipkg_package_whatprovides(args, file) ipkg_file_what(args,file,"whatprovides")
  7084. +#define ipkg_package_whatconflicts(args, file) ipkg_file_what(args,file,"whatconflicts")
  7085. +#define ipkg_package_whatreplaces(args, file) ipkg_file_what(args,file,"whatreplaces")
  7086. +
  7087. +
  7088. +int default_ipkg_message_callback(ipkg_conf_t *conf, message_level_t level,
  7089. + char *msg)
  7090. +{
  7091. + if (conf && (conf->verbosity < level)) {
  7092. + return 0;
  7093. + } else {
  7094. +#ifdef IPKG_LIB
  7095. + if ( level == IPKG_ERROR ){
  7096. + push_error_list(&error_list, msg);
  7097. +// printf(msg);
  7098. + } else
  7099. +#endif
  7100. + printf(msg);
  7101. + }
  7102. + return 0;
  7103. +}
  7104. +
  7105. +int default_ipkg_list_callback(char *name, char *desc, char *version)
  7106. +{
  7107. + if (desc)
  7108. + printf("%s - %s - %s\n", name, version, desc);
  7109. + else
  7110. + printf("%s - %s\n", name, version);
  7111. + return 0;
  7112. +}
  7113. +
  7114. +int default_ipkg_files_callback(char *desc)
  7115. +{
  7116. + if (desc)
  7117. + printf("%s\n", desc);
  7118. + return 0;
  7119. +}
  7120. +
  7121. +int default_ipkg_status_callback(char *desc)
  7122. +{
  7123. + printf("%s\n", desc);
  7124. + return 0;
  7125. +}
  7126. +
  7127. +char* default_ipkg_response_callback(char *question)
  7128. +{
  7129. + char *response = NULL;
  7130. + printf(question);
  7131. + fflush(stdout);
  7132. + do {
  7133. + response = (char *)file_read_line_alloc(stdin);
  7134. + } while (response == NULL);
  7135. + return response;
  7136. +}
  7137. +
  7138. +/* This is used for backward compatibility */
  7139. +int
  7140. +ipkg_op (int argc, char *argv[])
  7141. +{
  7142. + int err, optind_;
  7143. + args_t args;
  7144. + char *cmd_name;
  7145. + ipkg_cmd_t *cmd;
  7146. + ipkg_conf_t ipkg_conf;
  7147. + const char *message = "ipkg must have one sub-command argument";
  7148. +
  7149. + args_init (&args);
  7150. +
  7151. + optind_ = args_parse (&args, argc, argv);
  7152. + if (optind_ == argc || optind_ < 0)
  7153. + {
  7154. + args_usage(message);
  7155. + }
  7156. +
  7157. + cmd_name = argv[optind_++];
  7158. +/* Pigi: added a flag to disable the checking of structures if the command does not need to
  7159. + read anything from there.
  7160. +*/
  7161. + if ( !strcmp(cmd_name,"print-architecture") ||
  7162. + !strcmp(cmd_name,"print_architecture") ||
  7163. + !strcmp(cmd_name,"print-installation-architecture") ||
  7164. + !strcmp(cmd_name,"print_installation_architecture") )
  7165. + args.nocheckfordirorfile = 1;
  7166. +
  7167. +/* Pigi: added a flag to disable the reading of feed files if the command does not need to
  7168. + read anything from there.
  7169. +*/
  7170. + if ( !strcmp(cmd_name,"flag") ||
  7171. + !strcmp(cmd_name,"configure") ||
  7172. + !strcmp(cmd_name,"remove") ||
  7173. + !strcmp(cmd_name,"files") ||
  7174. + !strcmp(cmd_name,"search") ||
  7175. + !strcmp(cmd_name,"compare_versions") ||
  7176. + !strcmp(cmd_name,"compare-versions") ||
  7177. + !strcmp(cmd_name,"list_installed") ||
  7178. + !strcmp(cmd_name,"list-installed") ||
  7179. + !strcmp(cmd_name,"status") )
  7180. + args.noreadfeedsfile = 1;
  7181. +
  7182. +
  7183. + err = ipkg_conf_init (&ipkg_conf, &args);
  7184. + if (err)
  7185. + {
  7186. + return err;
  7187. + }
  7188. +
  7189. + args_deinit (&args);
  7190. +
  7191. + ipkg_cb_message = default_ipkg_message_callback;
  7192. + ipkg_cb_response = default_ipkg_response_callback;
  7193. + ipkg_cb_status = (ipkg_status_callback)default_ipkg_status_callback;
  7194. + if ( strcmp(cmd_name, "files")==0)
  7195. + ipkg_cb_list = (ipkg_list_callback)default_ipkg_files_callback;
  7196. + else
  7197. + ipkg_cb_list = (ipkg_list_callback)default_ipkg_list_callback;
  7198. +
  7199. + cmd = ipkg_cmd_find (cmd_name);
  7200. + if (cmd == NULL)
  7201. + {
  7202. + fprintf (stderr, "%s: unknown sub-command %s\n", argv[0],
  7203. + cmd_name);
  7204. + args_usage (NULL);
  7205. + }
  7206. +
  7207. + if (cmd->requires_args && optind_ == argc)
  7208. + {
  7209. + fprintf (stderr,
  7210. + "%s: the ``%s'' command requires at least one argument\n",
  7211. + __FUNCTION__, cmd_name);
  7212. + args_usage (NULL);
  7213. + }
  7214. +
  7215. + err = ipkg_cmd_exec (cmd, &ipkg_conf, argc - optind_, (const char **) (argv + optind_), NULL);
  7216. +
  7217. + ipkg_conf_deinit (&ipkg_conf);
  7218. +
  7219. + return err;
  7220. +}
  7221. +
  7222. +#endif /* IPKG_LIB */
  7223. diff -Nur busybox-1.12.1.orig/archival/libipkg/libipkg.h busybox-1.12.1/archival/libipkg/libipkg.h
  7224. --- busybox-1.12.1.orig/archival/libipkg/libipkg.h 1970-01-01 01:00:00.000000000 +0100
  7225. +++ busybox-1.12.1/archival/libipkg/libipkg.h 2008-10-23 11:41:37.000000000 +0200
  7226. @@ -0,0 +1,87 @@
  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. +#ifdef IPKG_LIB
  7246. +
  7247. +#include "ipkg_conf.h"
  7248. +#include "ipkg_message.h"
  7249. +
  7250. +#include "args.h"
  7251. +#include "pkg.h"
  7252. +
  7253. +typedef int (*ipkg_message_callback)(ipkg_conf_t *conf, message_level_t level,
  7254. + char *msg);
  7255. +typedef int (*ipkg_list_callback)(char *name, char *desc, char *version,
  7256. + pkg_state_status_t status, void *userdata);
  7257. +typedef int (*ipkg_status_callback)(char *name, int istatus, char *desc,
  7258. + void *userdata);
  7259. +typedef char* (*ipkg_response_callback)(char *question);
  7260. +
  7261. +extern int ipkg_op(int argc, char *argv[]); /* ipkglib.c */
  7262. +extern int ipkg_init (ipkg_message_callback mcall,
  7263. + ipkg_response_callback rcall,
  7264. + args_t * args);
  7265. +
  7266. +extern int ipkg_deinit (args_t *args);
  7267. +extern int ipkg_packages_list(args_t *args,
  7268. + const char *packages,
  7269. + ipkg_list_callback cblist,
  7270. + void *userdata);
  7271. +extern int ipkg_packages_status(args_t *args,
  7272. + const char *packages,
  7273. + ipkg_status_callback cbstatus,
  7274. + void *userdata);
  7275. +extern int ipkg_packages_info(args_t *args,
  7276. + const char *packages,
  7277. + ipkg_status_callback cbstatus,
  7278. + void *userdata);
  7279. +extern int ipkg_packages_install(args_t *args, const char *name);
  7280. +extern int ipkg_packages_remove(args_t *args, const char *name, int purge);
  7281. +extern int ipkg_lists_update(args_t *args);
  7282. +extern int ipkg_packages_upgrade(args_t *args);
  7283. +extern int ipkg_packages_download(args_t *args, const char *name);
  7284. +extern int ipkg_package_files(args_t *args,
  7285. + const char *name,
  7286. + ipkg_list_callback cblist,
  7287. + void *userdata);
  7288. +extern int ipkg_file_search(args_t *args,
  7289. + const char *file,
  7290. + ipkg_list_callback cblist,
  7291. + void *userdata);
  7292. +extern int ipkg_package_whatdepends(args_t *args, const char *file);
  7293. +extern int ipkg_package_whatrecommends(args_t *args, const char *file);
  7294. +extern int ipkg_package_whatprovides(args_t *args, const char *file);
  7295. +extern int ipkg_package_whatconflicts(args_t *args, const char *file);
  7296. +extern int ipkg_package_whatreplaces(args_t *args, const char *file);
  7297. +
  7298. +extern ipkg_message_callback ipkg_cb_message; /* ipkglib.c */
  7299. +extern ipkg_response_callback ipkg_cb_response;
  7300. +extern ipkg_status_callback ipkg_cb_status;
  7301. +extern ipkg_list_callback ipkg_cb_list;
  7302. +extern void push_error_list(struct errlist **errors,char * msg);
  7303. +extern void reverse_error_list(struct errlist **errors);
  7304. +extern void free_error_list(struct errlist **errors);
  7305. +
  7306. +#else
  7307. +
  7308. +extern int ipkg_op(int argc, char *argv[]);
  7309. +
  7310. +#endif
  7311. +
  7312. +
  7313. +#endif
  7314. diff -Nur busybox-1.12.1.orig/archival/libipkg/nv_pair.c busybox-1.12.1/archival/libipkg/nv_pair.c
  7315. --- busybox-1.12.1.orig/archival/libipkg/nv_pair.c 1970-01-01 01:00:00.000000000 +0100
  7316. +++ busybox-1.12.1/archival/libipkg/nv_pair.c 2008-10-23 11:41:37.000000000 +0200
  7317. @@ -0,0 +1,40 @@
  7318. +/* nv_pair.c - the itsy package management system
  7319. +
  7320. + Carl D. Worth
  7321. +
  7322. + Copyright (C) 2001 University of Southern California
  7323. +
  7324. + This program is free software; you can redistribute it and/or
  7325. + modify it under the terms of the GNU General Public License as
  7326. + published by the Free Software Foundation; either version 2, or (at
  7327. + your option) any later version.
  7328. +
  7329. + This program is distributed in the hope that it will be useful, but
  7330. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7331. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7332. + General Public License for more details.
  7333. +*/
  7334. +
  7335. +#include "ipkg.h"
  7336. +
  7337. +#include "nv_pair.h"
  7338. +#include "str_util.h"
  7339. +
  7340. +int nv_pair_init(nv_pair_t *nv_pair, const char *name, const char *value)
  7341. +{
  7342. + nv_pair->name = str_dup_safe(name);
  7343. + nv_pair->value = str_dup_safe(value);
  7344. +
  7345. + return 0;
  7346. +}
  7347. +
  7348. +void nv_pair_deinit(nv_pair_t *nv_pair)
  7349. +{
  7350. + free(nv_pair->name);
  7351. + nv_pair->name = NULL;
  7352. +
  7353. + free(nv_pair->value);
  7354. + nv_pair->value = NULL;
  7355. +}
  7356. +
  7357. +
  7358. diff -Nur busybox-1.12.1.orig/archival/libipkg/nv_pair.h busybox-1.12.1/archival/libipkg/nv_pair.h
  7359. --- busybox-1.12.1.orig/archival/libipkg/nv_pair.h 1970-01-01 01:00:00.000000000 +0100
  7360. +++ busybox-1.12.1/archival/libipkg/nv_pair.h 2008-10-23 11:41:37.000000000 +0200
  7361. @@ -0,0 +1,32 @@
  7362. +/* nv_pair.h - the itsy package management system
  7363. +
  7364. + Carl D. Worth
  7365. +
  7366. + Copyright (C) 2001 University of Southern California
  7367. +
  7368. + This program is free software; you can redistribute it and/or
  7369. + modify it under the terms of the GNU General Public License as
  7370. + published by the Free Software Foundation; either version 2, or (at
  7371. + your option) any later version.
  7372. +
  7373. + This program is distributed in the hope that it will be useful, but
  7374. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7375. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7376. + General Public License for more details.
  7377. +*/
  7378. +
  7379. +#ifndef NV_PAIR_H
  7380. +#define NV_PAIR_H
  7381. +
  7382. +typedef struct nv_pair nv_pair_t;
  7383. +struct nv_pair
  7384. +{
  7385. + char *name;
  7386. + char *value;
  7387. +};
  7388. +
  7389. +int nv_pair_init(nv_pair_t *nv_pair, const char *name, const char *value);
  7390. +void nv_pair_deinit(nv_pair_t *nv_pair);
  7391. +
  7392. +#endif
  7393. +
  7394. diff -Nur busybox-1.12.1.orig/archival/libipkg/nv_pair_list.c busybox-1.12.1/archival/libipkg/nv_pair_list.c
  7395. --- busybox-1.12.1.orig/archival/libipkg/nv_pair_list.c 1970-01-01 01:00:00.000000000 +0100
  7396. +++ busybox-1.12.1/archival/libipkg/nv_pair_list.c 2008-10-23 11:41:37.000000000 +0200
  7397. @@ -0,0 +1,98 @@
  7398. +/* nv_pair_list.c - the itsy package management system
  7399. +
  7400. + Carl D. Worth
  7401. +
  7402. + Copyright (C) 2001 University of Southern California
  7403. +
  7404. + This program is free software; you can redistribute it and/or
  7405. + modify it under the terms of the GNU General Public License as
  7406. + published by the Free Software Foundation; either version 2, or (at
  7407. + your option) any later version.
  7408. +
  7409. + This program is distributed in the hope that it will be useful, but
  7410. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7411. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7412. + General Public License for more details.
  7413. +*/
  7414. +
  7415. +#include "ipkg.h"
  7416. +
  7417. +#include "nv_pair.h"
  7418. +#include "void_list.h"
  7419. +#include "nv_pair_list.h"
  7420. +
  7421. +int nv_pair_list_elt_init(nv_pair_list_elt_t *elt, nv_pair_t *data)
  7422. +{
  7423. + return void_list_elt_init((void_list_elt_t *) elt, data);
  7424. +}
  7425. +
  7426. +void nv_pair_list_elt_deinit(nv_pair_list_elt_t *elt)
  7427. +{
  7428. + void_list_elt_deinit((void_list_elt_t *) elt);
  7429. +}
  7430. +
  7431. +int nv_pair_list_init(nv_pair_list_t *list)
  7432. +{
  7433. + return void_list_init((void_list_t *) list);
  7434. +}
  7435. +
  7436. +void nv_pair_list_deinit(nv_pair_list_t *list)
  7437. +{
  7438. + nv_pair_list_elt_t *iter;
  7439. + nv_pair_t *nv_pair;
  7440. +
  7441. + for (iter = list->head; iter; iter = iter->next) {
  7442. + nv_pair = iter->data;
  7443. + nv_pair_deinit(nv_pair);
  7444. +
  7445. + /* malloced in nv_pair_list_append */
  7446. + free(nv_pair);
  7447. + iter->data = NULL;
  7448. + }
  7449. + void_list_deinit((void_list_t *) list);
  7450. +}
  7451. +
  7452. +nv_pair_t *nv_pair_list_append(nv_pair_list_t *list, const char *name, const char *value)
  7453. +{
  7454. + int err;
  7455. +
  7456. + /* freed in nv_pair_list_deinit */
  7457. + nv_pair_t *nv_pair = malloc(sizeof(nv_pair_t));
  7458. +
  7459. + if (nv_pair == NULL) {
  7460. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  7461. + return NULL;
  7462. + }
  7463. + nv_pair_init(nv_pair, name, value);
  7464. +
  7465. + err = void_list_append((void_list_t *) list, nv_pair);
  7466. + if (err) {
  7467. + return NULL;
  7468. + }
  7469. +
  7470. + return nv_pair;
  7471. +}
  7472. +
  7473. +int nv_pair_list_push(nv_pair_list_t *list, nv_pair_t *data)
  7474. +{
  7475. + return void_list_push((void_list_t *) list, data);
  7476. +}
  7477. +
  7478. +nv_pair_list_elt_t *nv_pair_list_pop(nv_pair_list_t *list)
  7479. +{
  7480. + return (nv_pair_list_elt_t *) void_list_pop((void_list_t *) list);
  7481. +}
  7482. +
  7483. +char *nv_pair_list_find(nv_pair_list_t *list, char *name)
  7484. +{
  7485. + nv_pair_list_elt_t *iter;
  7486. + nv_pair_t *nv_pair;
  7487. +
  7488. + for (iter = list->head; iter; iter = iter->next) {
  7489. + nv_pair = iter->data;
  7490. + if (strcmp(nv_pair->name, name) == 0) {
  7491. + return nv_pair->value;
  7492. + }
  7493. + }
  7494. + return NULL;
  7495. +}
  7496. diff -Nur busybox-1.12.1.orig/archival/libipkg/nv_pair_list.h busybox-1.12.1/archival/libipkg/nv_pair_list.h
  7497. --- busybox-1.12.1.orig/archival/libipkg/nv_pair_list.h 1970-01-01 01:00:00.000000000 +0100
  7498. +++ busybox-1.12.1/archival/libipkg/nv_pair_list.h 2008-10-23 11:41:37.000000000 +0200
  7499. @@ -0,0 +1,60 @@
  7500. +/* nv_pair_list.h - the itsy package management system
  7501. +
  7502. + Carl D. Worth
  7503. +
  7504. + Copyright (C) 2001 University of Southern California
  7505. +
  7506. + This program is free software; you can redistribute it and/or
  7507. + modify it under the terms of the GNU General Public License as
  7508. + published by the Free Software Foundation; either version 2, or (at
  7509. + your option) any later version.
  7510. +
  7511. + This program is distributed in the hope that it will be useful, but
  7512. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7513. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7514. + General Public License for more details.
  7515. +*/
  7516. +
  7517. +#ifndef NV_PAIR_LIST_H
  7518. +#define NV_PAIR_LIST_H
  7519. +
  7520. +#include "nv_pair.h"
  7521. +#include "void_list.h"
  7522. +
  7523. +typedef struct nv_pair_list_elt nv_pair_list_elt_t;
  7524. +struct nv_pair_list_elt
  7525. +{
  7526. + nv_pair_list_elt_t *next;
  7527. + nv_pair_t *data;
  7528. +};
  7529. +
  7530. +typedef struct nv_pair_list nv_pair_list_t;
  7531. +struct nv_pair_list
  7532. +{
  7533. + nv_pair_list_elt_t pre_head;
  7534. + nv_pair_list_elt_t *head;
  7535. + nv_pair_list_elt_t *tail;
  7536. +};
  7537. +
  7538. +static inline int nv_pair_list_empty(nv_pair_list_t *list)
  7539. +{
  7540. + if (list->head == NULL)
  7541. + return 1;
  7542. + else
  7543. + return 0;
  7544. +}
  7545. +
  7546. +int nv_pair_list_elt_init(nv_pair_list_elt_t *elt, nv_pair_t *data);
  7547. +void nv_pair_list_elt_deinit(nv_pair_list_elt_t *elt);
  7548. +
  7549. +int nv_pair_list_init(nv_pair_list_t *list);
  7550. +void nv_pair_list_deinit(nv_pair_list_t *list);
  7551. +
  7552. +nv_pair_t *nv_pair_list_append(nv_pair_list_t *list,
  7553. + const char *name, const char *value);
  7554. +int nv_pair_list_push(nv_pair_list_t *list, nv_pair_t *data);
  7555. +nv_pair_list_elt_t *nv_pair_list_pop(nv_pair_list_t *list);
  7556. +char *nv_pair_list_find(nv_pair_list_t *list, char *name);
  7557. +
  7558. +#endif
  7559. +
  7560. diff -Nur busybox-1.12.1.orig/archival/libipkg/pkg.c busybox-1.12.1/archival/libipkg/pkg.c
  7561. --- busybox-1.12.1.orig/archival/libipkg/pkg.c 1970-01-01 01:00:00.000000000 +0100
  7562. +++ busybox-1.12.1/archival/libipkg/pkg.c 2008-10-23 15:02:19.000000000 +0200
  7563. @@ -0,0 +1,1757 @@
  7564. +/* pkg.c - the itsy package management system
  7565. +
  7566. + Carl D. Worth
  7567. +
  7568. + Copyright (C) 2001 University of Southern California
  7569. +
  7570. + This program is free software; you can redistribute it and/or
  7571. + modify it under the terms of the GNU General Public License as
  7572. + published by the Free Software Foundation; either version 2, or (at
  7573. + your option) any later version.
  7574. +
  7575. + This program is distributed in the hope that it will be useful, but
  7576. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7577. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7578. + General Public License for more details.
  7579. +*/
  7580. +
  7581. +#include "ipkg.h"
  7582. +#include <ctype.h>
  7583. +#include <string.h>
  7584. +#include <errno.h>
  7585. +
  7586. +#include "pkg.h"
  7587. +
  7588. +#include "pkg_parse.h"
  7589. +#include "pkg_extract.h"
  7590. +#include "ipkg_message.h"
  7591. +#include "ipkg_utils.h"
  7592. +
  7593. +#include "sprintf_alloc.h"
  7594. +#include "file_util.h"
  7595. +#include "str_util.h"
  7596. +#include "xsystem.h"
  7597. +#include "ipkg_conf.h"
  7598. +
  7599. +int pkg_get_arch_priority(ipkg_conf_t *conf, const char *archname);
  7600. +void pkg_write_filelist_helper(const char *key, void *entry_, void *data_);
  7601. +
  7602. +typedef struct enum_map enum_map_t;
  7603. +struct enum_map
  7604. +{
  7605. + int value;
  7606. + const char *str;
  7607. +};
  7608. +
  7609. +static const enum_map_t pkg_state_want_map[] = {
  7610. + { SW_UNKNOWN, "unknown"},
  7611. + { SW_INSTALL, "install"},
  7612. + { SW_DEINSTALL, "deinstall"},
  7613. + { SW_PURGE, "purge"}
  7614. +};
  7615. +
  7616. +static const enum_map_t pkg_state_flag_map[] = {
  7617. + { SF_OK, "ok"},
  7618. + { SF_REINSTREQ, "reinstreq"},
  7619. + { SF_HOLD, "hold"},
  7620. + { SF_REPLACE, "replace"},
  7621. + { SF_NOPRUNE, "noprune"},
  7622. + { SF_PREFER, "prefer"},
  7623. + { SF_OBSOLETE, "obsolete"},
  7624. + { SF_USER, "user"},
  7625. +};
  7626. +
  7627. +static const enum_map_t pkg_state_status_map[] = {
  7628. + { SS_NOT_INSTALLED, "not-installed" },
  7629. + { SS_UNPACKED, "unpacked" },
  7630. + { SS_HALF_CONFIGURED, "half-configured" },
  7631. + { SS_INSTALLED, "installed" },
  7632. + { SS_HALF_INSTALLED, "half-installed" },
  7633. + { SS_CONFIG_FILES, "config-files" },
  7634. + { SS_POST_INST_FAILED, "post-inst-failed" },
  7635. + { SS_REMOVAL_FAILED, "removal-failed" }
  7636. +};
  7637. +
  7638. +static int verrevcmp(const char *val, const char *ref);
  7639. +
  7640. +
  7641. +pkg_t *pkg_new(void)
  7642. +{
  7643. + pkg_t *pkg;
  7644. +
  7645. + pkg = malloc(sizeof(pkg_t));
  7646. + if (pkg == NULL) {
  7647. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  7648. + return NULL;
  7649. + }
  7650. +
  7651. + pkg_init(pkg);
  7652. +
  7653. + return pkg;
  7654. +}
  7655. +
  7656. +int pkg_init(pkg_t *pkg)
  7657. +{
  7658. + memset(pkg, 0, sizeof(pkg_t));
  7659. + pkg->name = NULL;
  7660. + pkg->epoch = 0;
  7661. + pkg->version = NULL;
  7662. + pkg->revision = NULL;
  7663. + pkg->familiar_revision = NULL;
  7664. + pkg->dest = NULL;
  7665. + pkg->src = NULL;
  7666. + pkg->architecture = NULL;
  7667. + pkg->maintainer = NULL;
  7668. + pkg->section = NULL;
  7669. + pkg->description = NULL;
  7670. + pkg->state_want = SW_UNKNOWN;
  7671. + pkg->state_flag = SF_OK;
  7672. + pkg->state_status = SS_NOT_INSTALLED;
  7673. + pkg->depends_str = NULL;
  7674. + pkg->provides_str = NULL;
  7675. + pkg->depends_count = 0;
  7676. + pkg->depends = NULL;
  7677. + pkg->suggests_str = NULL;
  7678. + pkg->recommends_str = NULL;
  7679. + pkg->suggests_count = 0;
  7680. + pkg->recommends_count = 0;
  7681. +
  7682. + /* Abhaya: added init for conflicts fields */
  7683. + pkg->conflicts = NULL;
  7684. + pkg->conflicts_count = 0;
  7685. +
  7686. + /* added for replaces. Jamey 7/23/2002 */
  7687. + pkg->replaces = NULL;
  7688. + pkg->replaces_count = 0;
  7689. +
  7690. + pkg->pre_depends_count = 0;
  7691. + pkg->pre_depends_str = NULL;
  7692. + pkg->provides_count = 0;
  7693. + pkg->provides = NULL;
  7694. + pkg->filename = NULL;
  7695. + pkg->local_filename = NULL;
  7696. + pkg->tmp_unpack_dir = NULL;
  7697. + pkg->md5sum = NULL;
  7698. + pkg->size = NULL;
  7699. + pkg->installed_size = NULL;
  7700. + pkg->priority = NULL;
  7701. + pkg->source = NULL;
  7702. + conffile_list_init(&pkg->conffiles);
  7703. + pkg->installed_files = NULL;
  7704. + pkg->installed_files_ref_cnt = 0;
  7705. + pkg->essential = 0;
  7706. + pkg->provided_by_hand = 0;
  7707. +
  7708. + return 0;
  7709. +}
  7710. +
  7711. +void pkg_deinit(pkg_t *pkg)
  7712. +{
  7713. + free(pkg->name);
  7714. + pkg->name = NULL;
  7715. + pkg->epoch = 0;
  7716. + free(pkg->version);
  7717. + pkg->version = NULL;
  7718. + /* revision and familiar_revision share storage with version, so
  7719. + don't free */
  7720. + pkg->revision = NULL;
  7721. + pkg->familiar_revision = NULL;
  7722. + /* owned by ipkg_conf_t */
  7723. + pkg->dest = NULL;
  7724. + /* owned by ipkg_conf_t */
  7725. + pkg->src = NULL;
  7726. + free(pkg->architecture);
  7727. + pkg->architecture = NULL;
  7728. + free(pkg->maintainer);
  7729. + pkg->maintainer = NULL;
  7730. + free(pkg->section);
  7731. + pkg->section = NULL;
  7732. + free(pkg->description);
  7733. + pkg->description = NULL;
  7734. + pkg->state_want = SW_UNKNOWN;
  7735. + pkg->state_flag = SF_OK;
  7736. + pkg->state_status = SS_NOT_INSTALLED;
  7737. + free(pkg->depends_str);
  7738. + pkg->depends_str = NULL;
  7739. + free(pkg->provides_str);
  7740. + pkg->provides_str = NULL;
  7741. + pkg->depends_count = 0;
  7742. + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->depends ? */
  7743. + pkg->pre_depends_count = 0;
  7744. + free(pkg->pre_depends_str);
  7745. + pkg->pre_depends_str = NULL;
  7746. + pkg->provides_count = 0;
  7747. + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->provides ? */
  7748. + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->suggests ? */
  7749. + free(pkg->filename);
  7750. + pkg->filename = NULL;
  7751. + free(pkg->local_filename);
  7752. + pkg->local_filename = NULL;
  7753. + /* CLEANUP: It'd be nice to pullin the cleanup function from
  7754. + ipkg_install.c here. See comment in
  7755. + ipkg_install.c:cleanup_temporary_files */
  7756. + free(pkg->tmp_unpack_dir);
  7757. + pkg->tmp_unpack_dir = NULL;
  7758. + free(pkg->md5sum);
  7759. + pkg->md5sum = NULL;
  7760. + free(pkg->size);
  7761. + pkg->size = NULL;
  7762. + free(pkg->installed_size);
  7763. + pkg->installed_size = NULL;
  7764. + free(pkg->priority);
  7765. + pkg->priority = NULL;
  7766. + free(pkg->source);
  7767. + pkg->source = NULL;
  7768. + conffile_list_deinit(&pkg->conffiles);
  7769. + /* XXX: QUESTION: Is forcing this to 1 correct? I suppose so,
  7770. + since if they are calling deinit, they should know. Maybe do an
  7771. + assertion here instead? */
  7772. + pkg->installed_files_ref_cnt = 1;
  7773. + pkg_free_installed_files(pkg);
  7774. + pkg->essential = 0;
  7775. +}
  7776. +
  7777. +int pkg_init_from_file(pkg_t *pkg, const char *filename)
  7778. +{
  7779. + int err;
  7780. + char **raw;
  7781. + FILE *control_file;
  7782. +
  7783. + err = pkg_init(pkg);
  7784. + if (err) { return err; }
  7785. +
  7786. + pkg->local_filename = strdup(filename);
  7787. +
  7788. + control_file = tmpfile();
  7789. + err = pkg_extract_control_file_to_stream(pkg, control_file);
  7790. + if (err) { return err; }
  7791. +
  7792. + rewind(control_file);
  7793. + raw = read_raw_pkgs_from_stream(control_file);
  7794. + pkg_parse_raw(pkg, &raw, NULL, NULL);
  7795. +
  7796. + fclose(control_file);
  7797. +
  7798. + return 0;
  7799. +}
  7800. +
  7801. +/* Merge any new information in newpkg into oldpkg */
  7802. +/* XXX: CLEANUP: This function shouldn't actually modify anything in
  7803. + newpkg, but should leave it usable. This rework is so that
  7804. + pkg_hash_insert doesn't clobber the pkg that you pass into it. */
  7805. +/*
  7806. + * uh, i thought that i had originally written this so that it took
  7807. + * two pkgs and returned a new one? we can do that again... -sma
  7808. + */
  7809. +int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status)
  7810. +{
  7811. + if (oldpkg == newpkg) {
  7812. + return 0;
  7813. + }
  7814. +
  7815. + if (!oldpkg->src)
  7816. + oldpkg->src = newpkg->src;
  7817. + if (!oldpkg->dest)
  7818. + oldpkg->dest = newpkg->dest;
  7819. + if (!oldpkg->architecture)
  7820. + oldpkg->architecture = str_dup_safe(newpkg->architecture);
  7821. + if (!oldpkg->arch_priority)
  7822. + oldpkg->arch_priority = newpkg->arch_priority;
  7823. + if (!oldpkg->section)
  7824. + oldpkg->section = str_dup_safe(newpkg->section);
  7825. + if(!oldpkg->maintainer)
  7826. + oldpkg->maintainer = str_dup_safe(newpkg->maintainer);
  7827. + if(!oldpkg->description)
  7828. + oldpkg->description = str_dup_safe(newpkg->description);
  7829. + if (set_status) {
  7830. + /* merge the state_flags from the new package */
  7831. + oldpkg->state_want = newpkg->state_want;
  7832. + oldpkg->state_status = newpkg->state_status;
  7833. + oldpkg->state_flag = newpkg->state_flag;
  7834. + } else {
  7835. + if (oldpkg->state_want == SW_UNKNOWN)
  7836. + oldpkg->state_want = newpkg->state_want;
  7837. + if (oldpkg->state_status == SS_NOT_INSTALLED)
  7838. + oldpkg->state_status = newpkg->state_status;
  7839. + oldpkg->state_flag |= newpkg->state_flag;
  7840. + }
  7841. +
  7842. + if (!oldpkg->depends_str && !oldpkg->pre_depends_str && !oldpkg->recommends_str && !oldpkg->suggests_str) {
  7843. + oldpkg->depends_str = newpkg->depends_str;
  7844. + newpkg->depends_str = NULL;
  7845. + oldpkg->depends_count = newpkg->depends_count;
  7846. + newpkg->depends_count = 0;
  7847. +
  7848. + oldpkg->depends = newpkg->depends;
  7849. + newpkg->depends = NULL;
  7850. +
  7851. + oldpkg->pre_depends_str = newpkg->pre_depends_str;
  7852. + newpkg->pre_depends_str = NULL;
  7853. + oldpkg->pre_depends_count = newpkg->pre_depends_count;
  7854. + newpkg->pre_depends_count = 0;
  7855. +
  7856. + oldpkg->recommends_str = newpkg->recommends_str;
  7857. + newpkg->recommends_str = NULL;
  7858. + oldpkg->recommends_count = newpkg->recommends_count;
  7859. + newpkg->recommends_count = 0;
  7860. +
  7861. + oldpkg->suggests_str = newpkg->suggests_str;
  7862. + newpkg->suggests_str = NULL;
  7863. + oldpkg->suggests_count = newpkg->suggests_count;
  7864. + newpkg->suggests_count = 0;
  7865. + }
  7866. +
  7867. + if (!oldpkg->provides_str) {
  7868. + oldpkg->provides_str = newpkg->provides_str;
  7869. + newpkg->provides_str = NULL;
  7870. + oldpkg->provides_count = newpkg->provides_count;
  7871. + newpkg->provides_count = 0;
  7872. +
  7873. + oldpkg->provides = newpkg->provides;
  7874. + newpkg->provides = NULL;
  7875. + }
  7876. +
  7877. + if (!oldpkg->conflicts_str) {
  7878. + oldpkg->conflicts_str = newpkg->conflicts_str;
  7879. + newpkg->conflicts_str = NULL;
  7880. + oldpkg->conflicts_count = newpkg->conflicts_count;
  7881. + newpkg->conflicts_count = 0;
  7882. +
  7883. + oldpkg->conflicts = newpkg->conflicts;
  7884. + newpkg->conflicts = NULL;
  7885. + }
  7886. +
  7887. + if (!oldpkg->replaces_str) {
  7888. + oldpkg->replaces_str = newpkg->replaces_str;
  7889. + newpkg->replaces_str = NULL;
  7890. + oldpkg->replaces_count = newpkg->replaces_count;
  7891. + newpkg->replaces_count = 0;
  7892. +
  7893. + oldpkg->replaces = newpkg->replaces;
  7894. + newpkg->replaces = NULL;
  7895. + }
  7896. +
  7897. + if (!oldpkg->filename)
  7898. + oldpkg->filename = str_dup_safe(newpkg->filename);
  7899. + if (0)
  7900. + fprintf(stdout, "pkg=%s old local_filename=%s new local_filename=%s\n",
  7901. + oldpkg->name, oldpkg->local_filename, newpkg->local_filename);
  7902. + if (!oldpkg->local_filename)
  7903. + oldpkg->local_filename = str_dup_safe(newpkg->local_filename);
  7904. + if (!oldpkg->tmp_unpack_dir)
  7905. + oldpkg->tmp_unpack_dir = str_dup_safe(newpkg->tmp_unpack_dir);
  7906. + if (!oldpkg->md5sum)
  7907. + oldpkg->md5sum = str_dup_safe(newpkg->md5sum);
  7908. + if (!oldpkg->size)
  7909. + oldpkg->size = str_dup_safe(newpkg->size);
  7910. + if (!oldpkg->installed_size)
  7911. + oldpkg->installed_size = str_dup_safe(newpkg->installed_size);
  7912. + if (!oldpkg->priority)
  7913. + oldpkg->priority = str_dup_safe(newpkg->priority);
  7914. + if (!oldpkg->source)
  7915. + oldpkg->source = str_dup_safe(newpkg->source);
  7916. + if (oldpkg->conffiles.head == NULL){
  7917. + oldpkg->conffiles = newpkg->conffiles;
  7918. + conffile_list_init(&newpkg->conffiles);
  7919. + }
  7920. + if (!oldpkg->installed_files){
  7921. + oldpkg->installed_files = newpkg->installed_files;
  7922. + oldpkg->installed_files_ref_cnt = newpkg->installed_files_ref_cnt;
  7923. + newpkg->installed_files = NULL;
  7924. + }
  7925. + if (!oldpkg->essential)
  7926. + oldpkg->essential = newpkg->essential;
  7927. +
  7928. + return 0;
  7929. +}
  7930. +
  7931. +abstract_pkg_t *abstract_pkg_new(void)
  7932. +{
  7933. + abstract_pkg_t * ab_pkg;
  7934. +
  7935. + ab_pkg = malloc(sizeof(abstract_pkg_t));
  7936. +
  7937. + if (ab_pkg == NULL) {
  7938. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  7939. + return NULL;
  7940. + }
  7941. +
  7942. + if ( abstract_pkg_init(ab_pkg) < 0 )
  7943. + return NULL;
  7944. +
  7945. + return ab_pkg;
  7946. +}
  7947. +
  7948. +int abstract_pkg_init(abstract_pkg_t *ab_pkg)
  7949. +{
  7950. + memset(ab_pkg, 0, sizeof(abstract_pkg_t));
  7951. +
  7952. + ab_pkg->provided_by = abstract_pkg_vec_alloc();
  7953. + if (ab_pkg->provided_by==NULL){
  7954. + return -1;
  7955. + }
  7956. + ab_pkg->dependencies_checked = 0;
  7957. + ab_pkg->state_status = SS_NOT_INSTALLED;
  7958. +
  7959. + return 0;
  7960. +}
  7961. +
  7962. +void set_flags_from_control(ipkg_conf_t *conf, pkg_t *pkg){
  7963. + char * temp_str;
  7964. + char **raw =NULL;
  7965. + char **raw_start=NULL;
  7966. +
  7967. + temp_str = (char *) malloc (strlen(pkg->dest->info_dir)+strlen(pkg->name)+12);
  7968. + if (temp_str == NULL ){
  7969. + ipkg_message(conf, IPKG_INFO, "Out of memory in %s\n", __FUNCTION__);
  7970. + return;
  7971. + }
  7972. + sprintf( temp_str,"%s/%s.control",pkg->dest->info_dir,pkg->name);
  7973. +
  7974. + raw = raw_start = read_raw_pkgs_from_file(temp_str);
  7975. + if (raw == NULL ){
  7976. + ipkg_message(conf, IPKG_ERROR, "Unable to open the control file in %s\n", __FUNCTION__);
  7977. + return;
  7978. + }
  7979. +
  7980. + while(*raw){
  7981. + if (!pkg_valorize_other_field(pkg, &raw ) == 0) {
  7982. + ipkg_message(conf, IPKG_DEBUG, "unable to read control file for %s. May be empty\n", pkg->name);
  7983. + }
  7984. + }
  7985. + raw = raw_start;
  7986. + while (*raw) {
  7987. + if (raw!=NULL)
  7988. + free(*raw++);
  7989. + }
  7990. +
  7991. + free(raw_start);
  7992. + free(temp_str);
  7993. +
  7994. + return ;
  7995. +
  7996. +}
  7997. +
  7998. +char * pkg_formatted_info(pkg_t *pkg )
  7999. +{
  8000. + char *line;
  8001. + char * buff;
  8002. +
  8003. + buff = malloc(8192);
  8004. + if (buff == NULL) {
  8005. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8006. + return NULL;
  8007. + }
  8008. +
  8009. + buff[0] = '\0';
  8010. +
  8011. + line = pkg_formatted_field(pkg, "Package");
  8012. + strncat(buff ,line, strlen(line));
  8013. + free(line);
  8014. +
  8015. + line = pkg_formatted_field(pkg, "Version");
  8016. + strncat(buff ,line, strlen(line));
  8017. + free(line);
  8018. +
  8019. + line = pkg_formatted_field(pkg, "Depends");
  8020. + strncat(buff ,line, strlen(line));
  8021. + free(line);
  8022. +
  8023. + line = pkg_formatted_field(pkg, "Recommends");
  8024. + strncat(buff ,line, strlen(line));
  8025. + free(line);
  8026. +
  8027. + line = pkg_formatted_field(pkg, "Suggests");
  8028. + strncat(buff ,line, strlen(line));
  8029. + free(line);
  8030. +
  8031. + line = pkg_formatted_field(pkg, "Provides");
  8032. + strncat(buff ,line, strlen(line));
  8033. + free(line);
  8034. +
  8035. + line = pkg_formatted_field(pkg, "Replaces");
  8036. + strncat(buff ,line, strlen(line));
  8037. + free(line);
  8038. +
  8039. + line = pkg_formatted_field(pkg, "Conflicts");
  8040. + strncat(buff ,line, strlen(line));
  8041. + free(line);
  8042. +
  8043. + line = pkg_formatted_field(pkg, "Status");
  8044. + strncat(buff ,line, strlen(line));
  8045. + free(line);
  8046. +
  8047. + line = pkg_formatted_field(pkg, "Section");
  8048. + strncat(buff ,line, strlen(line));
  8049. + free(line);
  8050. +
  8051. + line = pkg_formatted_field(pkg, "Essential"); /* @@@@ should be removed in future release. *//* I do not agree with this Pigi*/
  8052. + strncat(buff ,line, strlen(line));
  8053. + free(line);
  8054. +
  8055. + line = pkg_formatted_field(pkg, "Architecture");
  8056. + strncat(buff ,line, strlen(line));
  8057. + free(line);
  8058. +
  8059. + line = pkg_formatted_field(pkg, "Maintainer");
  8060. + strncat(buff ,line, strlen(line));
  8061. + free(line);
  8062. +
  8063. + line = pkg_formatted_field(pkg, "MD5sum");
  8064. + strncat(buff ,line, strlen(line));
  8065. + free(line);
  8066. +
  8067. + line = pkg_formatted_field(pkg, "Size");
  8068. + strncat(buff ,line, strlen(line));
  8069. + free(line);
  8070. +
  8071. + line = pkg_formatted_field(pkg, "Filename");
  8072. + strncat(buff ,line, strlen(line));
  8073. + free(line);
  8074. +
  8075. + line = pkg_formatted_field(pkg, "Conffiles");
  8076. + strncat(buff ,line, strlen(line));
  8077. + free(line);
  8078. +
  8079. + line = pkg_formatted_field(pkg, "Source");
  8080. + strncat(buff ,line, strlen(line));
  8081. + free(line);
  8082. +
  8083. + line = pkg_formatted_field(pkg, "Description");
  8084. + strncat(buff ,line, strlen(line));
  8085. + free(line);
  8086. +
  8087. + line = pkg_formatted_field(pkg, "Installed-Time");
  8088. + strncat(buff ,line, strlen(line));
  8089. + free(line);
  8090. +
  8091. + return buff;
  8092. +}
  8093. +
  8094. +char * pkg_formatted_field(pkg_t *pkg, const char *field )
  8095. +{
  8096. + static size_t LINE_LEN = 128;
  8097. + char * temp = (char *)malloc(1);
  8098. + int len = 0;
  8099. + int flag_provide_false = 0;
  8100. +
  8101. +/*
  8102. + Pigi: After some discussion with Florian we decided to modify the full procedure in
  8103. + dynamic memory allocation. This should avoid any other segv in this area ( except for bugs )
  8104. +*/
  8105. +
  8106. + if (strlen(field) < PKG_MINIMUM_FIELD_NAME_LEN) {
  8107. + goto UNKNOWN_FMT_FIELD;
  8108. + }
  8109. +
  8110. + temp[0]='\0';
  8111. +
  8112. + switch (field[0])
  8113. + {
  8114. + case 'a':
  8115. + case 'A':
  8116. + if (strcasecmp(field, "Architecture") == 0) {
  8117. + /* Architecture */
  8118. + if (pkg->architecture) {
  8119. + temp = (char *)realloc(temp,strlen(pkg->architecture)+17);
  8120. + if ( temp == NULL ){
  8121. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8122. + return NULL;
  8123. + }
  8124. + temp[0]='\0';
  8125. + snprintf(temp, (strlen(pkg->architecture)+17), "Architecture: %s\n", pkg->architecture);
  8126. + }
  8127. + } else {
  8128. + goto UNKNOWN_FMT_FIELD;
  8129. + }
  8130. + break;
  8131. + case 'c':
  8132. + case 'C':
  8133. + if (strcasecmp(field, "Conffiles") == 0) {
  8134. + /* Conffiles */
  8135. + conffile_list_elt_t *iter;
  8136. + char confstr_[LINE_LEN];
  8137. +
  8138. + if (pkg->conffiles.head == NULL) {
  8139. + return temp;
  8140. + }
  8141. +
  8142. + len = 14 ;
  8143. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  8144. + if (iter->data->name && iter->data->value) {
  8145. + len = len + (strlen(iter->data->name)+strlen(iter->data->value)+5);
  8146. + }
  8147. + }
  8148. + temp = (char *)realloc(temp,len);
  8149. + if ( temp == NULL ){
  8150. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8151. + return NULL;
  8152. + }
  8153. + temp[0]='\0';
  8154. + strncpy(temp, "Conffiles:\n", 12);
  8155. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  8156. + if (iter->data->name && iter->data->value) {
  8157. + snprintf(confstr_, LINE_LEN, "%s %s\n", iter->data->name, iter->data->value);
  8158. + strncat(temp, confstr_, strlen(confstr_));
  8159. + }
  8160. + }
  8161. + } else if (strcasecmp(field, "Conflicts") == 0) {
  8162. + int i;
  8163. +
  8164. + if (pkg->conflicts_count) {
  8165. + char conflictstr[LINE_LEN];
  8166. + len = 14 ;
  8167. + for(i = 0; i < pkg->conflicts_count; i++) {
  8168. + len = len + (strlen(pkg->conflicts_str[i])+5);
  8169. + }
  8170. + temp = (char *)realloc(temp,len);
  8171. + if ( temp == NULL ){
  8172. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8173. + return NULL;
  8174. + }
  8175. + temp[0]='\0';
  8176. + strncpy(temp, "Conflicts:", 11);
  8177. + for(i = 0; i < pkg->conflicts_count; i++) {
  8178. + snprintf(conflictstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->conflicts_str[i]);
  8179. + strncat(temp, conflictstr, strlen(conflictstr));
  8180. + }
  8181. + strncat(temp, "\n", strlen("\n"));
  8182. + }
  8183. + } else {
  8184. + goto UNKNOWN_FMT_FIELD;
  8185. + }
  8186. + break;
  8187. + case 'd':
  8188. + case 'D':
  8189. + if (strcasecmp(field, "Depends") == 0) {
  8190. + /* Depends */
  8191. + int i;
  8192. +
  8193. + if (pkg->depends_count) {
  8194. + char depstr[LINE_LEN];
  8195. + len = 14 ;
  8196. + for(i = 0; i < pkg->depends_count; i++) {
  8197. + len = len + (strlen(pkg->depends_str[i])+4);
  8198. + }
  8199. + temp = (char *)realloc(temp,len);
  8200. + if ( temp == NULL ){
  8201. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8202. + return NULL;
  8203. + }
  8204. + temp[0]='\0';
  8205. + strncpy(temp, "Depends:", 10);
  8206. + for(i = 0; i < pkg->depends_count; i++) {
  8207. + snprintf(depstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->depends_str[i]);
  8208. + strncat(temp, depstr, strlen(depstr));
  8209. + }
  8210. + strncat(temp, "\n", strlen("\n"));
  8211. + }
  8212. + } else if (strcasecmp(field, "Description") == 0) {
  8213. + /* Description */
  8214. + if (pkg->description) {
  8215. + temp = (char *)realloc(temp,strlen(pkg->description)+16);
  8216. + if ( temp == NULL ){
  8217. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8218. + return NULL;
  8219. + }
  8220. + temp[0]='\0';
  8221. + snprintf(temp, (strlen(pkg->description)+16), "Description: %s\n", pkg->description);
  8222. + }
  8223. + } else {
  8224. + goto UNKNOWN_FMT_FIELD;
  8225. + }
  8226. + break;
  8227. + case 'e':
  8228. + case 'E': {
  8229. + /* Essential */
  8230. + if (pkg->essential) {
  8231. + temp = (char *)realloc(temp,16);
  8232. + if ( temp == NULL ){
  8233. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8234. + return NULL;
  8235. + }
  8236. + temp[0]='\0';
  8237. + snprintf(temp, (16), "Essential: yes\n");
  8238. + }
  8239. + }
  8240. + break;
  8241. + case 'f':
  8242. + case 'F': {
  8243. + /* Filename */
  8244. + if (pkg->filename) {
  8245. + temp = (char *)realloc(temp,strlen(pkg->filename)+12);
  8246. + if ( temp == NULL ){
  8247. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8248. + return NULL;
  8249. + }
  8250. + temp[0]='\0';
  8251. + snprintf(temp, (strlen(pkg->filename)+12), "Filename: %s\n", pkg->filename);
  8252. + }
  8253. + }
  8254. + break;
  8255. + case 'i':
  8256. + case 'I': {
  8257. + if (strcasecmp(field, "Installed-Size") == 0) {
  8258. + /* Installed-Size */
  8259. + temp = (char *)realloc(temp,strlen(pkg->installed_size)+17);
  8260. + if ( temp == NULL ){
  8261. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8262. + return NULL;
  8263. + }
  8264. + temp[0]='\0';
  8265. + snprintf(temp, (strlen(pkg->installed_size)+17), "Installed-Size: %s\n", pkg->installed_size);
  8266. + } else if (strcasecmp(field, "Installed-Time") == 0 && pkg->installed_time) {
  8267. + temp = (char *)realloc(temp,29);
  8268. + if ( temp == NULL ){
  8269. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8270. + return NULL;
  8271. + }
  8272. + temp[0]='\0';
  8273. + snprintf(temp, 29, "Installed-Time: %lu\n", pkg->installed_time);
  8274. + }
  8275. + }
  8276. + break;
  8277. + case 'm':
  8278. + case 'M': {
  8279. + /* Maintainer | MD5sum */
  8280. + if (strcasecmp(field, "Maintainer") == 0) {
  8281. + /* Maintainer */
  8282. + if (pkg->maintainer) {
  8283. + temp = (char *)realloc(temp,strlen(pkg->maintainer)+14);
  8284. + if ( temp == NULL ){
  8285. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8286. + return NULL;
  8287. + }
  8288. + temp[0]='\0';
  8289. + snprintf(temp, (strlen(pkg->maintainer)+14), "maintainer: %s\n", pkg->maintainer);
  8290. + }
  8291. + } else if (strcasecmp(field, "MD5sum") == 0) {
  8292. + /* MD5sum */
  8293. + if (pkg->md5sum) {
  8294. + temp = (char *)realloc(temp,strlen(pkg->md5sum)+11);
  8295. + if ( temp == NULL ){
  8296. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8297. + return NULL;
  8298. + }
  8299. + temp[0]='\0';
  8300. + snprintf(temp, (strlen(pkg->md5sum)+11), "MD5Sum: %s\n", pkg->md5sum);
  8301. + }
  8302. + } else {
  8303. + goto UNKNOWN_FMT_FIELD;
  8304. + }
  8305. + }
  8306. + break;
  8307. + case 'p':
  8308. + case 'P': {
  8309. + if (strcasecmp(field, "Package") == 0) {
  8310. + /* Package */
  8311. + temp = (char *)realloc(temp,strlen(pkg->name)+11);
  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->name)+11), "Package: %s\n", pkg->name);
  8318. + } else if (strcasecmp(field, "Priority") == 0) {
  8319. + /* Priority */
  8320. + temp = (char *)realloc(temp,strlen(pkg->priority)+12);
  8321. + if ( temp == NULL ){
  8322. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8323. + return NULL;
  8324. + }
  8325. + temp[0]='\0';
  8326. + snprintf(temp, (strlen(pkg->priority)+12), "Priority: %s\n", pkg->priority);
  8327. + } else if (strcasecmp(field, "Provides") == 0) {
  8328. + /* Provides */
  8329. + int i;
  8330. +
  8331. + if (pkg->provides_count) {
  8332. + /* Here we check if the ipkg_internal_use_only is used, and we discard it.*/
  8333. + for ( i=0; i < pkg->provides_count; i++ ){
  8334. + if (strstr(pkg->provides_str[i],"ipkg_internal_use_only")!=NULL) {
  8335. + memset (pkg->provides_str[i],'\x0',strlen(pkg->provides_str[i])); /* Pigi clear my trick flag, just in case */
  8336. + flag_provide_false = 1;
  8337. + }
  8338. + }
  8339. + if ( !flag_provide_false || /* Pigi there is not my trick flag */
  8340. + ((flag_provide_false) && (pkg->provides_count > 1))){ /* Pigi There is, but we also have others Provides */
  8341. + char provstr[LINE_LEN];
  8342. + len = 15;
  8343. + for(i = 0; i < pkg->provides_count; i++) {
  8344. + len = len + (strlen(pkg->provides_str[i])+5);
  8345. + }
  8346. + temp = (char *)realloc(temp,len);
  8347. + if ( temp == NULL ){
  8348. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8349. + return NULL;
  8350. + }
  8351. + temp[0]='\0';
  8352. + strncpy(temp, "Provides:", 12);
  8353. + for(i = 0; i < pkg->provides_count; i++) {
  8354. + if (strlen(pkg->provides_str[i])>0){;
  8355. + snprintf(provstr, LINE_LEN, "%s %s", i == 1 ? "" : ",", pkg->provides_str[i]);
  8356. + strncat(temp, provstr, strlen(provstr));
  8357. + }
  8358. + }
  8359. + strncat(temp, "\n", strlen("\n"));
  8360. + }
  8361. + }
  8362. + } else {
  8363. + goto UNKNOWN_FMT_FIELD;
  8364. + }
  8365. + }
  8366. + break;
  8367. + case 'r':
  8368. + case 'R': {
  8369. + int i;
  8370. + /* Replaces | Recommends*/
  8371. + if (strcasecmp (field, "Replaces") == 0) {
  8372. + if (pkg->replaces_count) {
  8373. + char replstr[LINE_LEN];
  8374. + len = 14;
  8375. + for (i = 0; i < pkg->replaces_count; i++) {
  8376. + len = len + (strlen(pkg->replaces_str[i])+5);
  8377. + }
  8378. + temp = (char *)realloc(temp,len);
  8379. + if ( temp == NULL ){
  8380. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8381. + return NULL;
  8382. + }
  8383. + temp[0]='\0';
  8384. + strncpy(temp, "Replaces:", 12);
  8385. + for (i = 0; i < pkg->replaces_count; i++) {
  8386. + snprintf(replstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->replaces_str[i]);
  8387. + strncat(temp, replstr, strlen(replstr));
  8388. + }
  8389. + strncat(temp, "\n", strlen("\n"));
  8390. + }
  8391. + } else if (strcasecmp (field, "Recommends") == 0) {
  8392. + if (pkg->recommends_count) {
  8393. + char recstr[LINE_LEN];
  8394. + len = 15;
  8395. + for(i = 0; i < pkg->recommends_count; i++) {
  8396. + len = len + (strlen( pkg->recommends_str[i])+5);
  8397. + }
  8398. + temp = (char *)realloc(temp,len);
  8399. + if ( temp == NULL ){
  8400. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8401. + return NULL;
  8402. + }
  8403. + temp[0]='\0';
  8404. + strncpy(temp, "Recommends:", 13);
  8405. + for(i = 0; i < pkg->recommends_count; i++) {
  8406. + snprintf(recstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->recommends_str[i]);
  8407. + strncat(temp, recstr, strlen(recstr));
  8408. + }
  8409. + strncat(temp, "\n", strlen("\n"));
  8410. + }
  8411. + } else {
  8412. + goto UNKNOWN_FMT_FIELD;
  8413. + }
  8414. + }
  8415. + break;
  8416. + case 's':
  8417. + case 'S': {
  8418. + /* Section | Size | Source | Status | Suggests */
  8419. + if (strcasecmp(field, "Section") == 0) {
  8420. + /* Section */
  8421. + if (pkg->section) {
  8422. + temp = (char *)realloc(temp,strlen(pkg->section)+11);
  8423. + if ( temp == NULL ){
  8424. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8425. + return NULL;
  8426. + }
  8427. + temp[0]='\0';
  8428. + snprintf(temp, (strlen(pkg->section)+11), "Section: %s\n", pkg->section);
  8429. + }
  8430. + } else if (strcasecmp(field, "Size") == 0) {
  8431. + /* Size */
  8432. + if (pkg->size) {
  8433. + temp = (char *)realloc(temp,strlen(pkg->size)+8);
  8434. + if ( temp == NULL ){
  8435. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8436. + return NULL;
  8437. + }
  8438. + temp[0]='\0';
  8439. + snprintf(temp, (strlen(pkg->size)+8), "Size: %s\n", pkg->size);
  8440. + }
  8441. + } else if (strcasecmp(field, "Source") == 0) {
  8442. + /* Source */
  8443. + if (pkg->source) {
  8444. + temp = (char *)realloc(temp,strlen(pkg->source)+10);
  8445. + if ( temp == NULL ){
  8446. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8447. + return NULL;
  8448. + }
  8449. + temp[0]='\0';
  8450. + snprintf(temp, (strlen(pkg->source)+10), "Source: %s\n", pkg->source);
  8451. + }
  8452. + } else if (strcasecmp(field, "Status") == 0) {
  8453. + /* Status */
  8454. + /* Benjamin Pineau note: we should avoid direct usage of
  8455. + * strlen(arg) without keeping "arg" for later free()
  8456. + */
  8457. + char *pflag=pkg_state_flag_to_str(pkg->state_flag);
  8458. + char *pstat=pkg_state_status_to_str(pkg->state_status);
  8459. + char *pwant=pkg_state_want_to_str(pkg->state_want);
  8460. +
  8461. + size_t sum_of_sizes = (size_t) ( strlen(pwant)+ strlen(pflag)+ strlen(pstat) + 12 );
  8462. + temp = (char *)realloc(temp,sum_of_sizes);
  8463. + if ( temp == NULL ){
  8464. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8465. + return NULL;
  8466. + }
  8467. + temp[0]='\0';
  8468. + snprintf(temp, sum_of_sizes , "Status: %s %s %s\n", pwant, pflag, pstat);
  8469. + free(pflag);
  8470. + free(pwant);
  8471. + if(pstat) /* pfstat can be NULL if ENOMEM */
  8472. + free(pstat);
  8473. + } else if (strcasecmp(field, "Suggests") == 0) {
  8474. + if (pkg->suggests_count) {
  8475. + int i;
  8476. + char sugstr[LINE_LEN];
  8477. + len = 13;
  8478. + for(i = 0; i < pkg->suggests_count; i++) {
  8479. + len = len + (strlen(pkg->suggests_str[i])+5);
  8480. + }
  8481. + temp = (char *)realloc(temp,len);
  8482. + if ( temp == NULL ){
  8483. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8484. + return NULL;
  8485. + }
  8486. + temp[0]='\0';
  8487. + strncpy(temp, "Suggests:", 10);
  8488. + for(i = 0; i < pkg->suggests_count; i++) {
  8489. + snprintf(sugstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->suggests_str[i]);
  8490. + strncat(temp, sugstr, strlen(sugstr));
  8491. + }
  8492. + strncat(temp, "\n", strlen("\n"));
  8493. + }
  8494. + } else {
  8495. + goto UNKNOWN_FMT_FIELD;
  8496. + }
  8497. + }
  8498. + break;
  8499. + case 'v':
  8500. + case 'V': {
  8501. + /* Version */
  8502. + char *version = pkg_version_str_alloc(pkg);
  8503. + temp = (char *)realloc(temp,strlen(version)+14);
  8504. + if ( temp == NULL ){
  8505. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8506. + return NULL;
  8507. + }
  8508. + temp[0]='\0';
  8509. + snprintf(temp, (strlen(version)+12), "Version: %s\n", version);
  8510. + free(version);
  8511. + }
  8512. + break;
  8513. + default:
  8514. + goto UNKNOWN_FMT_FIELD;
  8515. + }
  8516. +
  8517. + if ( strlen(temp)<2 ) {
  8518. + temp[0]='\0';
  8519. + }
  8520. + return temp;
  8521. +
  8522. + UNKNOWN_FMT_FIELD:
  8523. + fprintf(stderr, "%s: ERROR: Unknown field name: %s\n", __FUNCTION__, field);
  8524. + if ( strlen(temp)<2 ) {
  8525. + temp[0]='\0';
  8526. + }
  8527. +
  8528. + return temp;
  8529. +}
  8530. +
  8531. +void pkg_print_info(pkg_t *pkg, FILE *file)
  8532. +{
  8533. + char * buff;
  8534. + if (pkg == NULL) {
  8535. + return;
  8536. + }
  8537. +
  8538. + buff = pkg_formatted_info(pkg);
  8539. + if ( buff == NULL )
  8540. + return;
  8541. + if (strlen(buff)>2){
  8542. + fwrite(buff, 1, strlen(buff), file);
  8543. + }
  8544. + free(buff);
  8545. +}
  8546. +
  8547. +void pkg_print_status(pkg_t * pkg, FILE * file)
  8548. +{
  8549. + if (pkg == NULL) {
  8550. + return;
  8551. + }
  8552. +
  8553. + /* XXX: QUESTION: Do we actually want more fields here? The
  8554. + original idea was to save space by installing only what was
  8555. + needed for actual computation, (package, version, status,
  8556. + essential, conffiles). The assumption is that all other fields
  8557. + can be found in th available file.
  8558. +
  8559. + But, someone proposed the idea to make it possible to
  8560. + reconstruct a .ipk from an installed package, (ie. for beaming
  8561. + from one handheld to another). So, maybe we actually want a few
  8562. + more fields here, (depends, suggests, etc.), so that that would
  8563. + be guaranteed to work even in the absence of more information
  8564. + from the available file.
  8565. +
  8566. + 28-MAR-03: kergoth and I discussed this yesterday. We think
  8567. + the essential info needs to be here for all installed packages
  8568. + because they may not appear in the Packages files on various
  8569. + feeds. Furthermore, one should be able to install from URL or
  8570. + local storage without requiring a Packages file from any feed.
  8571. + -Jamey
  8572. + */
  8573. + pkg_print_field(pkg, file, "Package");
  8574. + pkg_print_field(pkg, file, "Version");
  8575. + pkg_print_field(pkg, file, "Depends");
  8576. + pkg_print_field(pkg, file, "Recommends");
  8577. + pkg_print_field(pkg, file, "Suggests");
  8578. + pkg_print_field(pkg, file, "Provides");
  8579. + pkg_print_field(pkg, file, "Replaces");
  8580. + pkg_print_field(pkg, file, "Conflicts");
  8581. + pkg_print_field(pkg, file, "Status");
  8582. + pkg_print_field(pkg, file, "Essential"); /* @@@@ should be removed in future release. */
  8583. + pkg_print_field(pkg, file, "Architecture");
  8584. + pkg_print_field(pkg, file, "Conffiles");
  8585. + pkg_print_field(pkg, file, "Installed-Time");
  8586. + fputs("\n", file);
  8587. +}
  8588. +
  8589. +void pkg_print_field(pkg_t *pkg, FILE *file, const char *field)
  8590. +{
  8591. + char *buff;
  8592. + if (strlen(field) < PKG_MINIMUM_FIELD_NAME_LEN) {
  8593. + fprintf(stderr, "%s: ERROR: Unknown field name: %s\n",
  8594. + __FUNCTION__, field);
  8595. + }
  8596. + buff = pkg_formatted_field(pkg, field);
  8597. + if (strlen(buff)>2) {
  8598. + fprintf(file, "%s", buff);
  8599. + fflush(file);
  8600. + }
  8601. + free(buff);
  8602. + return;
  8603. +}
  8604. +
  8605. +/*
  8606. + * libdpkg - Debian packaging suite library routines
  8607. + * vercmp.c - comparison of version numbers
  8608. + *
  8609. + * Copyright (C) 1995 Ian Jackson <iwj10@cus.cam.ac.uk>
  8610. + */
  8611. +int pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg)
  8612. +{
  8613. + int r;
  8614. +
  8615. + if (pkg->epoch > ref_pkg->epoch) {
  8616. + return 1;
  8617. + }
  8618. +
  8619. + if (pkg->epoch < ref_pkg->epoch) {
  8620. + return -1;
  8621. + }
  8622. +
  8623. + r = verrevcmp(pkg->version, ref_pkg->version);
  8624. + if (r) {
  8625. + return r;
  8626. + }
  8627. +
  8628. +#ifdef USE_DEBVERSION
  8629. + r = verrevcmp(pkg->revision, ref_pkg->revision);
  8630. + if (r) {
  8631. + return r;
  8632. + }
  8633. +
  8634. + r = verrevcmp(pkg->familiar_revision, ref_pkg->familiar_revision);
  8635. +#endif
  8636. +
  8637. + return r;
  8638. +}
  8639. +
  8640. +int verrevcmp(const char *val, const char *ref)
  8641. +{
  8642. + int vc, rc;
  8643. + long vl, rl;
  8644. + const char *vp, *rp;
  8645. + const char *vsep, *rsep;
  8646. +
  8647. + if (!val) val= "";
  8648. + if (!ref) ref= "";
  8649. + for (;;) {
  8650. + vp= val; while (*vp && !isdigit(*vp)) vp++;
  8651. + rp= ref; while (*rp && !isdigit(*rp)) rp++;
  8652. + for (;;) {
  8653. + vc= (val == vp) ? 0 : *val++;
  8654. + rc= (ref == rp) ? 0 : *ref++;
  8655. + if (!rc && !vc) break;
  8656. + if (vc && !isalpha(vc)) vc += 256; /* assumes ASCII character set */
  8657. + if (rc && !isalpha(rc)) rc += 256;
  8658. + if (vc != rc) return vc - rc;
  8659. + }
  8660. + val= vp;
  8661. + ref= rp;
  8662. + vl=0; if (isdigit(*vp)) vl= strtol(val,(char**)&val,10);
  8663. + rl=0; if (isdigit(*rp)) rl= strtol(ref,(char**)&ref,10);
  8664. + if (vl != rl) return vl - rl;
  8665. +
  8666. + vc = *val;
  8667. + rc = *ref;
  8668. + vsep = strchr(".-", vc);
  8669. + rsep = strchr(".-", rc);
  8670. + if (vsep && !rsep) return -1;
  8671. + if (!vsep && rsep) return +1;
  8672. +
  8673. + if (!*val && !*ref) return 0;
  8674. + if (!*val) return -1;
  8675. + if (!*ref) return +1;
  8676. + }
  8677. +}
  8678. +
  8679. +int pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op)
  8680. +{
  8681. + int r;
  8682. +
  8683. + r = pkg_compare_versions(it, ref);
  8684. +
  8685. + if (strcmp(op, "<=") == 0 || strcmp(op, "<") == 0) {
  8686. + return r <= 0;
  8687. + }
  8688. +
  8689. + if (strcmp(op, ">=") == 0 || strcmp(op, ">") == 0) {
  8690. + return r >= 0;
  8691. + }
  8692. +
  8693. + if (strcmp(op, "<<") == 0) {
  8694. + return r < 0;
  8695. + }
  8696. +
  8697. + if (strcmp(op, ">>") == 0) {
  8698. + return r > 0;
  8699. + }
  8700. +
  8701. + if (strcmp(op, "=") == 0) {
  8702. + return r == 0;
  8703. + }
  8704. +
  8705. + fprintf(stderr, "unknown operator: %s", op);
  8706. + return 0;
  8707. +}
  8708. +
  8709. +int pkg_name_version_and_architecture_compare(pkg_t *p1, pkg_t *p2)
  8710. +{
  8711. + const pkg_t *a = *(const pkg_t **)p1;
  8712. + const pkg_t *b = *(const pkg_t **)p2;
  8713. + int namecmp;
  8714. + int vercmp;
  8715. + if (!a->name || !b->name) {
  8716. + fprintf(stderr, "pkg_name_version_and_architecture_compare: a=%p a->name=%p b=%p b->name=%p\n",
  8717. + a, a->name, b, b->name);
  8718. + return 0;
  8719. + }
  8720. +
  8721. + namecmp = strcmp(a->name, b->name);
  8722. + if (namecmp)
  8723. + return namecmp;
  8724. + vercmp = pkg_compare_versions(a, b);
  8725. + if (vercmp)
  8726. + return vercmp;
  8727. + if (!a->arch_priority || !b->arch_priority) {
  8728. + fprintf(stderr, "pkg_name_version_and_architecture_compare: a=%p a->arch_priority=%i b=%p b->arch_priority=%i\n",
  8729. + a, a->arch_priority, b, b->arch_priority);
  8730. + return 0;
  8731. + }
  8732. + if (a->arch_priority > b->arch_priority)
  8733. + return 1;
  8734. + if (a->arch_priority < b->arch_priority)
  8735. + return -1;
  8736. + return 0;
  8737. +}
  8738. +
  8739. +int abstract_pkg_name_compare(abstract_pkg_t *p1, abstract_pkg_t *p2)
  8740. +{
  8741. + const abstract_pkg_t *a = *(const abstract_pkg_t **)p1;
  8742. + const abstract_pkg_t *b = *(const abstract_pkg_t **)p2;
  8743. + if (!a->name || !b->name) {
  8744. + fprintf(stderr, "abstract_pkg_name_compare: a=%p a->name=%p b=%p b->name=%p\n",
  8745. + a, a->name, b, b->name);
  8746. + return 0;
  8747. + }
  8748. + return strcmp(a->name, b->name);
  8749. +}
  8750. +
  8751. +
  8752. +char *pkg_version_str_alloc(pkg_t *pkg)
  8753. +{
  8754. + char *complete_version;
  8755. + char *epoch_str;
  8756. +#ifdef USE_DEBVERSION
  8757. + char *revision_str;
  8758. + char *familiar_revision_str;
  8759. +#endif
  8760. +
  8761. + if (pkg->epoch) {
  8762. + sprintf_alloc(&epoch_str, "%lu:", (unsigned long)pkg->epoch);
  8763. + } else {
  8764. + epoch_str = strdup("");
  8765. + }
  8766. +
  8767. +#ifdef USE_DEBVERSION
  8768. + if (pkg->revision && strlen(pkg->revision)) {
  8769. + sprintf_alloc(&revision_str, "-%s", pkg->revision);
  8770. + } else {
  8771. + revision_str = strdup("");
  8772. + }
  8773. +
  8774. + if (pkg->familiar_revision && strlen(pkg->familiar_revision)) {
  8775. + sprintf_alloc(&familiar_revision_str, "-fam%s", pkg->familiar_revision);
  8776. + } else {
  8777. + familiar_revision_str = strdup("");
  8778. + }
  8779. +#endif
  8780. +
  8781. +#ifdef USE_DEBVERSION
  8782. + sprintf_alloc(&complete_version, "%s%s%s%s",
  8783. + epoch_str, pkg->version, revision_str, familiar_revision_str);
  8784. +#else
  8785. + sprintf_alloc(&complete_version, "%s%s",
  8786. + epoch_str, pkg->version);
  8787. +#endif
  8788. +
  8789. + free(epoch_str);
  8790. +#ifdef USE_DEBVERSION
  8791. + free(revision_str);
  8792. + free(familiar_revision_str);
  8793. +#endif
  8794. +
  8795. + return complete_version;
  8796. +}
  8797. +
  8798. +str_list_t *pkg_get_installed_files(pkg_t *pkg)
  8799. +{
  8800. + int err;
  8801. + char *list_file_name = NULL;
  8802. + FILE *list_file = NULL;
  8803. + char *line;
  8804. + char *installed_file_name;
  8805. + int rootdirlen;
  8806. +
  8807. + pkg->installed_files_ref_cnt++;
  8808. +
  8809. + if (pkg->installed_files) {
  8810. + return pkg->installed_files;
  8811. + }
  8812. +
  8813. + pkg->installed_files = str_list_alloc();
  8814. + if (pkg->installed_files == NULL) {
  8815. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8816. + return NULL;
  8817. + }
  8818. +
  8819. + /* For uninstalled packages, get the file list firectly from the package.
  8820. + For installed packages, look at the package.list file in the database.
  8821. + */
  8822. + if (pkg->state_status == SS_NOT_INSTALLED || pkg->dest == NULL) {
  8823. + if (pkg->local_filename == NULL) {
  8824. + return pkg->installed_files;
  8825. + }
  8826. + /* XXX: CLEANUP: Maybe rewrite this to avoid using a temporary
  8827. + file. In other words, change deb_extract so that it can
  8828. + simply return the file list as a char *[] rather than
  8829. + insisting on writing in to a FILE * as it does now. */
  8830. + list_file = tmpfile();
  8831. + err = pkg_extract_data_file_names_to_stream(pkg, list_file);
  8832. + if (err) {
  8833. + fclose(list_file);
  8834. + fprintf(stderr, "%s: Error extracting file list from %s: %s\n",
  8835. + __FUNCTION__, pkg->local_filename, strerror(err));
  8836. + return pkg->installed_files;
  8837. + }
  8838. + rewind(list_file);
  8839. + } else {
  8840. + sprintf_alloc(&list_file_name, "%s/%s.list",
  8841. + pkg->dest->info_dir, pkg->name);
  8842. + if (! file_exists(list_file_name)) {
  8843. + free(list_file_name);
  8844. + return pkg->installed_files;
  8845. + }
  8846. +
  8847. + list_file = fopen(list_file_name, "r");
  8848. + if (list_file == NULL) {
  8849. + fprintf(stderr, "WARNING: Cannot open %s: %s\n",
  8850. + list_file_name, strerror(errno));
  8851. + free(list_file_name);
  8852. + return pkg->installed_files;
  8853. + }
  8854. + free(list_file_name);
  8855. + }
  8856. +
  8857. + rootdirlen = strlen( pkg->dest->root_dir );
  8858. + while (1) {
  8859. + char *file_name;
  8860. +
  8861. + line = file_read_line_alloc(list_file);
  8862. + if (line == NULL) {
  8863. + break;
  8864. + }
  8865. + str_chomp(line);
  8866. + file_name = line;
  8867. +
  8868. + /* Take pains to avoid uglies like "/./" in the middle of file_name. */
  8869. + if( strncmp( pkg->dest->root_dir,
  8870. + file_name,
  8871. + rootdirlen ) ) {
  8872. + if (*file_name == '.') {
  8873. + file_name++;
  8874. + }
  8875. + if (*file_name == '/') {
  8876. + file_name++;
  8877. + }
  8878. +
  8879. + /* Freed in pkg_free_installed_files */
  8880. + sprintf_alloc(&installed_file_name, "%s%s", pkg->dest->root_dir, file_name);
  8881. + } else {
  8882. + // already contains root_dir as header -> ABSOLUTE
  8883. + sprintf_alloc(&installed_file_name, "%s", file_name);
  8884. + }
  8885. + str_list_append(pkg->installed_files, installed_file_name);
  8886. + free(line);
  8887. + }
  8888. +
  8889. + fclose(list_file);
  8890. +
  8891. + return pkg->installed_files;
  8892. +}
  8893. +
  8894. +/* XXX: CLEANUP: This function and it's counterpart,
  8895. + (pkg_get_installed_files), do not match our init/deinit naming
  8896. + convention. Nor the alloc/free convention. But, then again, neither
  8897. + of these conventions currrently fit the way these two functions
  8898. + work. */
  8899. +int pkg_free_installed_files(pkg_t *pkg)
  8900. +{
  8901. + str_list_elt_t *iter;
  8902. +
  8903. + pkg->installed_files_ref_cnt--;
  8904. + if (pkg->installed_files_ref_cnt > 0) {
  8905. + return 0;
  8906. + }
  8907. +
  8908. + if (pkg->installed_files) {
  8909. +
  8910. + for (iter = pkg->installed_files->head; iter; iter = iter->next) {
  8911. + /* malloced in pkg_get_installed_files */
  8912. + free (iter->data);
  8913. + iter->data = NULL;
  8914. + }
  8915. +
  8916. + str_list_deinit(pkg->installed_files);
  8917. + }
  8918. +
  8919. + pkg->installed_files = NULL;
  8920. +
  8921. + return 0;
  8922. +}
  8923. +
  8924. +int pkg_remove_installed_files_list(ipkg_conf_t *conf, pkg_t *pkg)
  8925. +{
  8926. + int err;
  8927. + char *list_file_name;
  8928. +
  8929. + //I don't think pkg_free_installed_files should be called here. Jamey
  8930. + //pkg_free_installed_files(pkg);
  8931. +
  8932. + sprintf_alloc(&list_file_name, "%s/%s.list",
  8933. + pkg->dest->info_dir, pkg->name);
  8934. + if (!conf->noaction) {
  8935. + err = unlink(list_file_name);
  8936. + free(list_file_name);
  8937. +
  8938. + if (err) {
  8939. + return errno;
  8940. + }
  8941. + }
  8942. + return 0;
  8943. +}
  8944. +
  8945. +conffile_t *pkg_get_conffile(pkg_t *pkg, const char *file_name)
  8946. +{
  8947. + conffile_list_elt_t *iter;
  8948. + conffile_t *conffile;
  8949. +
  8950. + if (pkg == NULL) {
  8951. + return NULL;
  8952. + }
  8953. +
  8954. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  8955. + conffile = iter->data;
  8956. +
  8957. + if (strcmp(conffile->name, file_name) == 0) {
  8958. + return conffile;
  8959. + }
  8960. + }
  8961. +
  8962. + return NULL;
  8963. +}
  8964. +
  8965. +int pkg_run_script(ipkg_conf_t *conf, pkg_t *pkg,
  8966. + const char *script, const char *args)
  8967. +{
  8968. + int err;
  8969. + char *path;
  8970. + char *cmd;
  8971. +
  8972. + /* XXX: FEATURE: When conf->offline_root is set, we should run the
  8973. + maintainer script within a chroot environment. */
  8974. +
  8975. + /* Installed packages have scripts in pkg->dest->info_dir, uninstalled packages
  8976. + have scripts in pkg->tmp_unpack_dir. */
  8977. + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) {
  8978. + if (pkg->dest == NULL) {
  8979. + fprintf(stderr, "%s: ERROR: installed package %s has a NULL dest\n",
  8980. + __FUNCTION__, pkg->name);
  8981. + return EINVAL;
  8982. + }
  8983. + sprintf_alloc(&path, "%s/%s.%s", pkg->dest->info_dir, pkg->name, script);
  8984. + } else {
  8985. + if (pkg->tmp_unpack_dir == NULL) {
  8986. + fprintf(stderr, "%s: ERROR: uninstalled package %s has a NULL tmp_unpack_dir\n",
  8987. + __FUNCTION__, pkg->name);
  8988. + return EINVAL;
  8989. + }
  8990. + sprintf_alloc(&path, "%s/%s", pkg->tmp_unpack_dir, script);
  8991. + }
  8992. +
  8993. + ipkg_message(conf, IPKG_INFO, "Running script %s\n", path);
  8994. + if (conf->noaction) return 0;
  8995. +
  8996. + /* XXX: CLEANUP: There must be a better way to handle maintainer
  8997. + scripts when running with offline_root mode and/or a dest other
  8998. + than '/'. I've been playing around with some clever chroot
  8999. + tricks and I might come up with something workable. */
  9000. + if (conf->offline_root) {
  9001. + setenv("IPKG_OFFLINE_ROOT", conf->offline_root, 1);
  9002. + }
  9003. +
  9004. + setenv("PKG_ROOT",
  9005. + pkg->dest ? pkg->dest->root_dir : conf->default_dest->root_dir, 1);
  9006. +
  9007. + if (! file_exists(path)) {
  9008. + free(path);
  9009. + return 0;
  9010. + }
  9011. +
  9012. + if (conf->offline_root) {
  9013. + fprintf(stderr, "(offline root mode: not running %s.%s)\n", pkg->name, script);
  9014. + free(path);
  9015. + return 0;
  9016. + }
  9017. +
  9018. + sprintf_alloc(&cmd, "%s %s", path, args);
  9019. + free(path);
  9020. +
  9021. + err = xsystem(cmd);
  9022. + free(cmd);
  9023. +
  9024. + if (err) {
  9025. + fprintf(stderr, "%s script returned status %d\n", script, err);
  9026. + return err;
  9027. + }
  9028. +
  9029. + return 0;
  9030. +}
  9031. +
  9032. +char *pkg_state_want_to_str(pkg_state_want_t sw)
  9033. +{
  9034. + int i;
  9035. +
  9036. + for (i=0; i < ARRAY_SIZE(pkg_state_want_map); i++) {
  9037. + if (pkg_state_want_map[i].value == sw) {
  9038. + return strdup(pkg_state_want_map[i].str);
  9039. + }
  9040. + }
  9041. +
  9042. + fprintf(stderr, "%s: ERROR: Illegal value for state_want: %d\n",
  9043. + __FUNCTION__, sw);
  9044. + return strdup("<STATE_WANT_UNKNOWN>");
  9045. +}
  9046. +
  9047. +pkg_state_want_t pkg_state_want_from_str(char *str)
  9048. +{
  9049. + int i;
  9050. +
  9051. + for (i=0; i < ARRAY_SIZE(pkg_state_want_map); i++) {
  9052. + if (strcmp(str, pkg_state_want_map[i].str) == 0) {
  9053. + return pkg_state_want_map[i].value;
  9054. + }
  9055. + }
  9056. +
  9057. + fprintf(stderr, "%s: ERROR: Illegal value for state_want string: %s\n",
  9058. + __FUNCTION__, str);
  9059. + return SW_UNKNOWN;
  9060. +}
  9061. +
  9062. +char *pkg_state_flag_to_str(pkg_state_flag_t sf)
  9063. +{
  9064. + int i;
  9065. + int len = 3; /* ok\000 is minimum */
  9066. + char *str = NULL;
  9067. +
  9068. + /* clear the temporary flags before converting to string */
  9069. + sf &= SF_NONVOLATILE_FLAGS;
  9070. +
  9071. + if (sf == 0) {
  9072. + return strdup("ok");
  9073. + } else {
  9074. +
  9075. + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
  9076. + if (sf & pkg_state_flag_map[i].value) {
  9077. + len += strlen(pkg_state_flag_map[i].str) + 1;
  9078. + }
  9079. + }
  9080. + str = malloc(len);
  9081. + if ( str == NULL ) {
  9082. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  9083. + return NULL;
  9084. + }
  9085. + str[0] = 0;
  9086. + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
  9087. + if (sf & pkg_state_flag_map[i].value) {
  9088. + strcat(str, pkg_state_flag_map[i].str);
  9089. + strcat(str, ",");
  9090. + }
  9091. + }
  9092. + len = strlen(str);
  9093. + str[len-1] = 0; /* squash last comma */
  9094. + return str;
  9095. + }
  9096. +}
  9097. +
  9098. +pkg_state_flag_t pkg_state_flag_from_str(char *str)
  9099. +{
  9100. + int i;
  9101. + int sf = SF_OK;
  9102. +
  9103. + if (strcmp(str, "ok") == 0) {
  9104. + return SF_OK;
  9105. + }
  9106. + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
  9107. + const char *sfname = pkg_state_flag_map[i].str;
  9108. + int sfname_len = strlen(sfname);
  9109. + if (strncmp(str, sfname, sfname_len) == 0) {
  9110. + sf |= pkg_state_flag_map[i].value;
  9111. + str += sfname_len;
  9112. + if (str[0] == ',') {
  9113. + str++;
  9114. + } else {
  9115. + break;
  9116. + }
  9117. + }
  9118. + }
  9119. +
  9120. + return sf;
  9121. +}
  9122. +
  9123. +char *pkg_state_status_to_str(pkg_state_status_t ss)
  9124. +{
  9125. + int i;
  9126. +
  9127. + for (i=0; i < ARRAY_SIZE(pkg_state_status_map); i++) {
  9128. + if (pkg_state_status_map[i].value == ss) {
  9129. + return strdup(pkg_state_status_map[i].str);
  9130. + }
  9131. + }
  9132. +
  9133. + fprintf(stderr, "%s: ERROR: Illegal value for state_status: %d\n",
  9134. + __FUNCTION__, ss);
  9135. + return strdup("<STATE_STATUS_UNKNOWN>");
  9136. +}
  9137. +
  9138. +pkg_state_status_t pkg_state_status_from_str(char *str)
  9139. +{
  9140. + int i;
  9141. +
  9142. + for (i=0; i < ARRAY_SIZE(pkg_state_status_map); i++) {
  9143. + if (strcmp(str, pkg_state_status_map[i].str) == 0) {
  9144. + return pkg_state_status_map[i].value;
  9145. + }
  9146. + }
  9147. +
  9148. + fprintf(stderr, "%s: ERROR: Illegal value for state_status string: %s\n",
  9149. + __FUNCTION__, str);
  9150. + return SS_NOT_INSTALLED;
  9151. +}
  9152. +
  9153. +int pkg_arch_supported(ipkg_conf_t *conf, pkg_t *pkg)
  9154. +{
  9155. + nv_pair_list_elt_t *l;
  9156. +
  9157. + if (!pkg->architecture)
  9158. + return 1;
  9159. +
  9160. + l = conf->arch_list.head;
  9161. +
  9162. + while (l) {
  9163. + nv_pair_t *nv = l->data;
  9164. + if (strcmp(nv->name, pkg->architecture) == 0) {
  9165. + ipkg_message(conf, IPKG_DEBUG, "arch %s (priority %s) supported for pkg %s\n", nv->name, nv->value, pkg->name);
  9166. + return 1;
  9167. + }
  9168. + l = l->next;
  9169. + }
  9170. +
  9171. + ipkg_message(conf, IPKG_DEBUG, "arch %s unsupported for pkg %s\n", pkg->architecture, pkg->name);
  9172. + return 0;
  9173. +}
  9174. +
  9175. +int pkg_get_arch_priority(ipkg_conf_t *conf, const char *archname)
  9176. +{
  9177. + nv_pair_list_elt_t *l;
  9178. +
  9179. + l = conf->arch_list.head;
  9180. +
  9181. + while (l) {
  9182. + nv_pair_t *nv = l->data;
  9183. + if (strcmp(nv->name, archname) == 0) {
  9184. + int priority = strtol(nv->value, NULL, 0);
  9185. + return priority;
  9186. + }
  9187. + l = l->next;
  9188. + }
  9189. + return 0;
  9190. +}
  9191. +
  9192. +int pkg_info_preinstall_check(ipkg_conf_t *conf)
  9193. +{
  9194. + int i;
  9195. + hash_table_t *pkg_hash = &conf->pkg_hash;
  9196. + pkg_vec_t *available_pkgs = pkg_vec_alloc();
  9197. + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
  9198. +
  9199. + ipkg_message(conf, IPKG_INFO, "pkg_info_preinstall_check: updating arch priority for each package\n");
  9200. + pkg_hash_fetch_available(pkg_hash, available_pkgs);
  9201. + /* update arch_priority for each package */
  9202. + for (i = 0; i < available_pkgs->len; i++) {
  9203. + pkg_t *pkg = available_pkgs->pkgs[i];
  9204. + int arch_priority = 1;
  9205. + if (!pkg)
  9206. + continue;
  9207. + // ipkg_message(conf, IPKG_DEBUG2, " package %s version=%s arch=%p:", pkg->name, pkg->version, pkg->architecture);
  9208. + if (pkg->architecture)
  9209. + arch_priority = pkg_get_arch_priority(conf, pkg->architecture);
  9210. + else
  9211. + ipkg_message(conf, IPKG_ERROR, "pkg_info_preinstall_check: no architecture for package %s\n", pkg->name);
  9212. + // ipkg_message(conf, IPKG_DEBUG2, "%s arch_priority=%d\n", pkg->architecture, arch_priority);
  9213. + pkg->arch_priority = arch_priority;
  9214. + }
  9215. +
  9216. + for (i = 0; i < available_pkgs->len; i++) {
  9217. + pkg_t *pkg = available_pkgs->pkgs[i];
  9218. + if (!pkg->arch_priority && (pkg->state_flag || (pkg->state_want != SW_UNKNOWN))) {
  9219. + /* clear flags and want for any uninstallable package */
  9220. + ipkg_message(conf, IPKG_NOTICE, "Clearing state_want and state_flag for pkg=%s (arch_priority=%d flag=%d want=%d)\n",
  9221. + pkg->name, pkg->arch_priority, pkg->state_flag, pkg->state_want);
  9222. + pkg->state_want = SW_UNKNOWN;
  9223. + pkg->state_flag = 0;
  9224. + }
  9225. + }
  9226. + pkg_vec_free(available_pkgs);
  9227. +
  9228. + /* update the file owner data structure */
  9229. + ipkg_message(conf, IPKG_INFO, "pkg_info_preinstall_check: update file owner list\n");
  9230. + pkg_hash_fetch_all_installed(pkg_hash, installed_pkgs);
  9231. + for (i = 0; i < installed_pkgs->len; i++) {
  9232. + pkg_t *pkg = installed_pkgs->pkgs[i];
  9233. + str_list_t *installed_files = pkg_get_installed_files(pkg); /* this causes installed_files to be cached */
  9234. + str_list_elt_t *iter;
  9235. + if (installed_files == NULL) {
  9236. + ipkg_message(conf, IPKG_ERROR, "No installed files for pkg %s\n", pkg->name);
  9237. + break;
  9238. + }
  9239. + for (iter = installed_files->head; iter; iter = iter->next) {
  9240. + char *installed_file = iter->data;
  9241. + // ipkg_message(conf, IPKG_DEBUG2, "pkg %s: file=%s\n", pkg->name, installed_file);
  9242. + file_hash_set_file_owner(conf, installed_file, pkg);
  9243. + }
  9244. + }
  9245. + pkg_vec_free(installed_pkgs);
  9246. +
  9247. + return 0;
  9248. +}
  9249. +
  9250. +struct pkg_write_filelist_data {
  9251. + ipkg_conf_t *conf;
  9252. + pkg_t *pkg;
  9253. + FILE *stream;
  9254. +};
  9255. +
  9256. +void pkg_write_filelist_helper(const char *key, void *entry_, void *data_)
  9257. +{
  9258. + struct pkg_write_filelist_data *data = data_;
  9259. + pkg_t *entry = entry_;
  9260. + if (entry == data->pkg) {
  9261. + fprintf(data->stream, "%s\n", key);
  9262. + }
  9263. +}
  9264. +
  9265. +int pkg_write_filelist(ipkg_conf_t *conf, pkg_t *pkg)
  9266. +{
  9267. + struct pkg_write_filelist_data data;
  9268. + char *list_file_name = NULL;
  9269. + int err = 0;
  9270. +
  9271. + if (!pkg) {
  9272. + ipkg_message(conf, IPKG_ERROR, "Null pkg\n");
  9273. + return -EINVAL;
  9274. + }
  9275. + ipkg_message(conf, IPKG_INFO,
  9276. + " creating %s.list file\n", pkg->name);
  9277. + sprintf_alloc(&list_file_name, "%s/%s.list", pkg->dest->info_dir, pkg->name);
  9278. + if (!list_file_name) {
  9279. + ipkg_message(conf, IPKG_ERROR, "Failed to alloc list_file_name\n");
  9280. + return -ENOMEM;
  9281. + }
  9282. + ipkg_message(conf, IPKG_INFO,
  9283. + " creating %s file for pkg %s\n", list_file_name, pkg->name);
  9284. + data.stream = fopen(list_file_name, "w");
  9285. + if (!data.stream) {
  9286. + ipkg_message(conf, IPKG_ERROR, "Could not open %s for writing: %s\n",
  9287. + list_file_name, strerror(errno));
  9288. + return errno;
  9289. + }
  9290. + data.pkg = pkg;
  9291. + data.conf = conf;
  9292. + hash_table_foreach(&conf->file_hash, pkg_write_filelist_helper, &data);
  9293. + fclose(data.stream);
  9294. + free(list_file_name);
  9295. +
  9296. + return err;
  9297. +}
  9298. +
  9299. +int pkg_write_changed_filelists(ipkg_conf_t *conf)
  9300. +{
  9301. + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
  9302. + hash_table_t *pkg_hash = &conf->pkg_hash;
  9303. + int i;
  9304. + int err;
  9305. + if (conf->noaction)
  9306. + return 0;
  9307. +
  9308. + ipkg_message(conf, IPKG_INFO, "%s: saving changed filelists\n", __FUNCTION__);
  9309. + pkg_hash_fetch_all_installed(pkg_hash, installed_pkgs);
  9310. + for (i = 0; i < installed_pkgs->len; i++) {
  9311. + pkg_t *pkg = installed_pkgs->pkgs[i];
  9312. + if (pkg->state_flag & SF_FILELIST_CHANGED) {
  9313. + ipkg_message(conf, IPKG_DEBUG, "Calling pkg_write_filelist for pkg=%s from %s\n", pkg->name, __FUNCTION__);
  9314. + err = pkg_write_filelist(conf, pkg);
  9315. + if (err)
  9316. + ipkg_message(conf, IPKG_NOTICE, "pkg_write_filelist pkg=%s returned %d\n", pkg->name, err);
  9317. + }
  9318. + }
  9319. + return 0;
  9320. +}
  9321. diff -Nur busybox-1.12.1.orig/archival/libipkg/pkg_depends.c busybox-1.12.1/archival/libipkg/pkg_depends.c
  9322. --- busybox-1.12.1.orig/archival/libipkg/pkg_depends.c 1970-01-01 01:00:00.000000000 +0100
  9323. +++ busybox-1.12.1/archival/libipkg/pkg_depends.c 2008-10-23 15:05:10.000000000 +0200
  9324. @@ -0,0 +1,1032 @@
  9325. +/* pkg_depends.c - the itsy package management system
  9326. +
  9327. + Steven M. Ayer
  9328. +
  9329. + Copyright (C) 2002 Compaq Computer Corporation
  9330. +
  9331. + This program is free software; you can redistribute it and/or
  9332. + modify it under the terms of the GNU General Public License as
  9333. + published by the Free Software Foundation; either version 2, or (at
  9334. + your option) any later version.
  9335. +
  9336. + This program is distributed in the hope that it will be useful, but
  9337. + WITHOUT ANY WARRANTY; without even the implied warranty of
  9338. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  9339. + General Public License for more details.
  9340. +*/
  9341. +
  9342. +#include "ipkg.h"
  9343. +#include <errno.h>
  9344. +#include <ctype.h>
  9345. +
  9346. +#include "pkg.h"
  9347. +#include "ipkg_utils.h"
  9348. +#include "pkg_hash.h"
  9349. +#include "ipkg_message.h"
  9350. +#include "pkg_parse.h"
  9351. +#include "hash_table.h"
  9352. +
  9353. +static int parseDepends(compound_depend_t *compound_depend, hash_table_t * hash, char * depend_str);
  9354. +static depend_t * depend_init(void);
  9355. +static void depend_deinit(depend_t *d);
  9356. +static char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx);
  9357. +static char ** merge_unresolved(char ** oldstuff, char ** newstuff);
  9358. +static int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg);
  9359. +int is_pkg_a_replaces(pkg_t *pkg_scout,pkg_t *pkg);
  9360. +
  9361. +static int pkg_installed_and_constraint_satisfied(pkg_t *pkg, void *cdata)
  9362. +{
  9363. + depend_t *depend = (depend_t *)cdata;
  9364. + if ((pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) && version_constraints_satisfied(depend, pkg))
  9365. + return 1;
  9366. + else
  9367. + return 0;
  9368. +}
  9369. +
  9370. +static int pkg_constraint_satisfied(pkg_t *pkg, void *cdata)
  9371. +{
  9372. + depend_t *depend = (depend_t *)cdata;
  9373. +#if 0
  9374. + pkg_t * temp = pkg_new();
  9375. + int comparison;
  9376. + parseVersion(temp, depend->version);
  9377. + comparison = pkg_compare_versions(pkg, temp);
  9378. + free(temp);
  9379. +
  9380. + fprintf(stderr, "%s: pkg=%s pkg->version=%s constraint=%p type=%d version=%s comparison=%d satisfied=%d\n",
  9381. + __FUNCTION__, pkg->name, pkg->version,
  9382. + depend, depend->constraint, depend->version,
  9383. + comparison, version_constraints_satisfied(depend, pkg));
  9384. +#endif
  9385. + if (version_constraints_satisfied(depend, pkg))
  9386. + return 1;
  9387. + else
  9388. + return 0;
  9389. +}
  9390. +
  9391. +/* returns ndependences or negative error value */
  9392. +int pkg_hash_fetch_unsatisfied_dependencies(ipkg_conf_t *conf, pkg_t * pkg,
  9393. + pkg_vec_t *unsatisfied, char *** unresolved)
  9394. +{
  9395. + pkg_t * satisfier_entry_pkg;
  9396. + register int i, j, k, l;
  9397. + int count, found;
  9398. + char ** the_lost;
  9399. + abstract_pkg_t * ab_pkg;
  9400. +
  9401. + /*
  9402. + * this is a setup to check for redundant/cyclic dependency checks,
  9403. + * which are marked at the abstract_pkg level
  9404. + */
  9405. + if (!(ab_pkg = pkg->parent)) {
  9406. + fprintf(stderr, "%s:%d: something terribly wrong with pkg %s\n", __FUNCTION__, __LINE__, pkg->name);
  9407. + *unresolved = NULL;
  9408. + return 0;
  9409. + }
  9410. + if (ab_pkg->dependencies_checked) { /* avoid duplicate or cyclic checks */
  9411. + *unresolved = NULL;
  9412. + return 0;
  9413. + } else {
  9414. + ab_pkg->dependencies_checked = 1; /* mark it for subsequent visits */
  9415. + }
  9416. + /**/
  9417. +
  9418. + count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count;
  9419. + if (!count){
  9420. + *unresolved = NULL;
  9421. + return 0;
  9422. + }
  9423. +
  9424. + the_lost = NULL;
  9425. +
  9426. + /* foreach dependency */
  9427. + for (i = 0; i < count; i++) {
  9428. + compound_depend_t * compound_depend = &pkg->depends[i];
  9429. + depend_t ** possible_satisfiers = compound_depend->possibilities;;
  9430. + found = 0;
  9431. + satisfier_entry_pkg = NULL;
  9432. +
  9433. + if (compound_depend->type == GREEDY_DEPEND) {
  9434. + /* foreach possible satisfier */
  9435. + for (j = 0; j < compound_depend->possibility_count; j++) {
  9436. + /* foreach provided_by, which includes the abstract_pkg itself */
  9437. + abstract_pkg_t *abpkg = possible_satisfiers[j]->pkg;
  9438. + abstract_pkg_vec_t *ab_provider_vec = abpkg->provided_by;
  9439. + int nposs = ab_provider_vec->len;
  9440. + abstract_pkg_t **ab_providers = ab_provider_vec->pkgs;
  9441. + for (l = 0; l < nposs; l++) {
  9442. + pkg_vec_t *test_vec = ab_providers[l]->pkgs;
  9443. + /* if no depends on this one, try the first package that Provides this one */
  9444. + if (!test_vec){ /* no pkg_vec hooked up to the abstract_pkg! (need another feed?) */
  9445. + continue;
  9446. + }
  9447. +
  9448. + /* cruise this possiblity's pkg_vec looking for an installed version */
  9449. + for (k = 0; k < test_vec->len; k++) {
  9450. + pkg_t *pkg_scout = test_vec->pkgs[k];
  9451. + /* not installed, and not already known about? */
  9452. + if ((pkg_scout->state_want != SW_INSTALL)
  9453. + && !pkg_scout->parent->dependencies_checked
  9454. + && !is_pkg_in_pkg_vec(unsatisfied, pkg_scout)) {
  9455. + char ** newstuff = NULL;
  9456. + int rc;
  9457. + pkg_vec_t *tmp_vec = pkg_vec_alloc ();
  9458. + /* check for not-already-installed dependencies */
  9459. + rc = pkg_hash_fetch_unsatisfied_dependencies(conf,
  9460. + pkg_scout,
  9461. + tmp_vec,
  9462. + &newstuff);
  9463. + if (newstuff == NULL) {
  9464. + int ok = 1;
  9465. + for (i = 0; i < rc; i++) {
  9466. + pkg_t *p = tmp_vec->pkgs[i];
  9467. + if (p->state_want == SW_INSTALL)
  9468. + continue;
  9469. + ipkg_message(conf, IPKG_DEBUG, "not installing %s due to requirement for %s\n", pkg_scout->name, p->name);
  9470. + ok = 0;
  9471. + break;
  9472. + }
  9473. + pkg_vec_free (tmp_vec);
  9474. + if (ok) {
  9475. + /* mark this one for installation */
  9476. + ipkg_message(conf, IPKG_NOTICE, "Adding satisfier for greedy dependence: %s\n", pkg_scout->name);
  9477. + pkg_vec_insert(unsatisfied, pkg_scout);
  9478. + }
  9479. + } else {
  9480. + ipkg_message(conf, IPKG_DEBUG, "not installing %s due to broken depends \n", pkg_scout->name);
  9481. + free (newstuff);
  9482. + }
  9483. + }
  9484. + }
  9485. + }
  9486. + }
  9487. +
  9488. + continue;
  9489. + }
  9490. +
  9491. + /* foreach possible satisfier, look for installed package */
  9492. + for (j = 0; j < compound_depend->possibility_count; j++) {
  9493. + /* foreach provided_by, which includes the abstract_pkg itself */
  9494. + depend_t *dependence_to_satisfy = possible_satisfiers[j];
  9495. + abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg;
  9496. + pkg_t *satisfying_pkg =
  9497. + pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg,
  9498. + pkg_installed_and_constraint_satisfied,
  9499. + dependence_to_satisfy, 1);
  9500. + /* Being that I can't test constraing in pkg_hash, I will test it here */
  9501. + if (satisfying_pkg != NULL) {
  9502. + if (!pkg_installed_and_constraint_satisfied ( satisfying_pkg,dependence_to_satisfy)) {
  9503. + satisfying_pkg = NULL;
  9504. + }
  9505. + }
  9506. + ipkg_message(conf, IPKG_DEBUG, "%s:%d: satisfying_pkg=%p \n", __FILE__, __LINE__, satisfying_pkg);
  9507. + if (satisfying_pkg != NULL) {
  9508. + found = 1;
  9509. + break;
  9510. + }
  9511. +
  9512. + }
  9513. + /* if nothing installed matches, then look for uninstalled satisfier */
  9514. + if (!found) {
  9515. + /* foreach possible satisfier, look for installed package */
  9516. + for (j = 0; j < compound_depend->possibility_count; j++) {
  9517. + /* foreach provided_by, which includes the abstract_pkg itself */
  9518. + depend_t *dependence_to_satisfy = possible_satisfiers[j];
  9519. + abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg;
  9520. + pkg_t *satisfying_pkg =
  9521. + pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg,
  9522. + pkg_constraint_satisfied,
  9523. + dependence_to_satisfy, 1);
  9524. + /* Being that I can't test constraing in pkg_hash, I will test it here too */
  9525. + if (satisfying_pkg != NULL) {
  9526. + if (!pkg_constraint_satisfied ( satisfying_pkg,dependence_to_satisfy)) {
  9527. + satisfying_pkg = NULL;
  9528. + }
  9529. + }
  9530. +
  9531. + /* user request overrides package recommendation */
  9532. + if (satisfying_pkg != NULL
  9533. + && (compound_depend->type == RECOMMEND || compound_depend->type == SUGGEST)
  9534. + && (satisfying_pkg->state_want == SW_DEINSTALL || satisfying_pkg->state_want == SW_PURGE)) {
  9535. + ipkg_message (conf, IPKG_NOTICE, "%s: ignoring recommendation for %s at user request\n",
  9536. + pkg->name, satisfying_pkg->name);
  9537. + continue;
  9538. + }
  9539. +
  9540. + ipkg_message(conf, IPKG_DEBUG, "%s:%d: satisfying_pkg=%p\n", __FILE__, __LINE__, satisfying_pkg);
  9541. + if (satisfying_pkg != NULL) {
  9542. + satisfier_entry_pkg = satisfying_pkg;
  9543. + break;
  9544. + }
  9545. + }
  9546. + }
  9547. +
  9548. + /* we didn't find one, add something to the unsatisfied vector */
  9549. + if (!found) {
  9550. + if (!satisfier_entry_pkg) {
  9551. + /* failure to meet recommendations is not an error */
  9552. + if (compound_depend->type != RECOMMEND && compound_depend->type != SUGGEST)
  9553. + the_lost = add_unresolved_dep(pkg, the_lost, i);
  9554. + else
  9555. + ipkg_message (conf, IPKG_NOTICE, "%s: unsatisfied recommendation for %s\n",
  9556. + pkg->name, compound_depend->possibilities[0]->pkg->name);
  9557. + }
  9558. + else {
  9559. + if (compound_depend->type == SUGGEST) {
  9560. + /* just mention it politely */
  9561. + ipkg_message (conf, IPKG_NOTICE, "package %s suggests installing %s\n",
  9562. + pkg->name, satisfier_entry_pkg->name);
  9563. + } else {
  9564. + char ** newstuff = NULL;
  9565. +
  9566. + if (satisfier_entry_pkg != pkg &&
  9567. + !is_pkg_in_pkg_vec(unsatisfied, satisfier_entry_pkg)) {
  9568. + pkg_vec_insert(unsatisfied, satisfier_entry_pkg);
  9569. + pkg_hash_fetch_unsatisfied_dependencies(conf,
  9570. + satisfier_entry_pkg,
  9571. + unsatisfied,
  9572. + &newstuff);
  9573. + the_lost = merge_unresolved(the_lost, newstuff);
  9574. + }
  9575. + }
  9576. + }
  9577. + }
  9578. + }
  9579. + *unresolved = the_lost;
  9580. +
  9581. + return unsatisfied->len;
  9582. +}
  9583. +
  9584. +/*checking for conflicts !in replaces
  9585. + If a packages conflicts with another but is also replacing it, I should not consider it a
  9586. + really conflicts
  9587. + returns 0 if conflicts <> replaces or 1 if conflicts == replaces
  9588. +*/
  9589. +int is_pkg_a_replaces(pkg_t *pkg_scout,pkg_t *pkg)
  9590. +{
  9591. + int i ;
  9592. + int replaces_count = pkg->replaces_count;
  9593. + abstract_pkg_t **replaces;
  9594. +
  9595. + if (pkg->replaces_count==0) // No replaces, it's surely a conflict
  9596. + return 0;
  9597. +
  9598. + replaces = pkg->replaces;
  9599. +
  9600. + for (i = 0; i < replaces_count; i++) {
  9601. + if (strcmp(pkg_scout->name,pkg->replaces[i]->name)==0) { // Found
  9602. + ipkg_message(NULL, IPKG_DEBUG2, "Seems I've found a replace %s %s \n",pkg_scout->name,pkg->replaces[i]->name);
  9603. + return 1;
  9604. + }
  9605. + }
  9606. + return 0;
  9607. +
  9608. +}
  9609. +
  9610. +
  9611. +/* Abhaya: added support for conflicts */
  9612. +pkg_vec_t * pkg_hash_fetch_conflicts(pkg_t * pkg)
  9613. +{
  9614. + pkg_vec_t * installed_conflicts, * test_vec;
  9615. + compound_depend_t * conflicts;
  9616. + depend_t ** possible_satisfiers;
  9617. + depend_t * possible_satisfier;
  9618. + register int i, j, k;
  9619. + int count;
  9620. + abstract_pkg_t * ab_pkg;
  9621. + pkg_t **pkg_scouts;
  9622. + pkg_t *pkg_scout;
  9623. +
  9624. + /*
  9625. + * this is a setup to check for redundant/cyclic dependency checks,
  9626. + * which are marked at the abstract_pkg level
  9627. + */
  9628. + if(!(ab_pkg = pkg->parent)){
  9629. + fprintf(stderr, "dependency check error. pkg %s isn't in hash table\n", pkg->name);
  9630. + return (pkg_vec_t *)NULL;
  9631. + }
  9632. +
  9633. + conflicts = pkg->conflicts;
  9634. + if(!conflicts){
  9635. + return (pkg_vec_t *)NULL;
  9636. + }
  9637. + installed_conflicts = pkg_vec_alloc();
  9638. +
  9639. + count = pkg->conflicts_count;
  9640. +
  9641. +
  9642. +
  9643. + /* foreach conflict */
  9644. + for(i = 0; i < pkg->conflicts_count; i++){
  9645. +
  9646. + possible_satisfiers = conflicts->possibilities;
  9647. +
  9648. + /* foreach possible satisfier */
  9649. + for(j = 0; j < conflicts->possibility_count; j++){
  9650. + possible_satisfier = possible_satisfiers[j];
  9651. + if (!possible_satisfier)
  9652. + fprintf(stderr, "%s:%d: possible_satisfier is null\n", __FUNCTION__, __LINE__);
  9653. + if (!possible_satisfier->pkg)
  9654. + fprintf(stderr, "%s:%d: possible_satisfier->pkg is null\n", __FUNCTION__, __LINE__);
  9655. + test_vec = possible_satisfier->pkg->pkgs;
  9656. + if (test_vec) {
  9657. + /* pkg_vec found, it is an actual package conflict
  9658. + * cruise this possiblity's pkg_vec looking for an installed version */
  9659. + pkg_scouts = test_vec->pkgs;
  9660. + for(k = 0; k < test_vec->len; k++){
  9661. + pkg_scout = pkg_scouts[k];
  9662. + if (!pkg_scout) {
  9663. + fprintf(stderr, "%s: null pkg scout\n", __FUNCTION__);
  9664. + continue;
  9665. + }
  9666. + if ((pkg_scout->state_status == SS_INSTALLED || pkg_scout->state_want == SW_INSTALL) &&
  9667. + version_constraints_satisfied(possible_satisfier, pkg_scout) && !is_pkg_a_replaces(pkg_scout,pkg)){
  9668. + if (!is_pkg_in_pkg_vec(installed_conflicts, pkg_scout)){
  9669. + pkg_vec_insert(installed_conflicts, pkg_scout);
  9670. + }
  9671. + }
  9672. + }
  9673. + }
  9674. + }
  9675. + conflicts++;
  9676. + }
  9677. +
  9678. + if (installed_conflicts->len)
  9679. + return installed_conflicts;
  9680. + pkg_vec_free(installed_conflicts);
  9681. + return (pkg_vec_t *)NULL;
  9682. +}
  9683. +
  9684. +int version_constraints_satisfied(depend_t * depends, pkg_t * pkg)
  9685. +{
  9686. + pkg_t * temp;
  9687. + int comparison;
  9688. +
  9689. + if(depends->constraint == NONE)
  9690. + return 1;
  9691. +
  9692. + temp = pkg_new();
  9693. +
  9694. + parseVersion(temp, depends->version);
  9695. +
  9696. + comparison = pkg_compare_versions(pkg, temp);
  9697. +
  9698. + free(temp);
  9699. +
  9700. + if((depends->constraint == EARLIER) &&
  9701. + (comparison < 0))
  9702. + return 1;
  9703. + else if((depends->constraint == LATER) &&
  9704. + (comparison > 0))
  9705. + return 1;
  9706. + else if(comparison == 0)
  9707. + return 1;
  9708. + else if((depends->constraint == LATER_EQUAL) &&
  9709. + (comparison >= 0))
  9710. + return 1;
  9711. + else if((depends->constraint == EARLIER_EQUAL) &&
  9712. + (comparison <= 0))
  9713. + return 1;
  9714. +
  9715. + return 0;
  9716. +}
  9717. +
  9718. +int pkg_dependence_satisfiable(depend_t *depend)
  9719. +{
  9720. + abstract_pkg_t *apkg = depend->pkg;
  9721. + abstract_pkg_vec_t *provider_apkgs = apkg->provided_by;
  9722. + int n_providers = provider_apkgs->len;
  9723. + abstract_pkg_t **apkgs = provider_apkgs->pkgs;
  9724. + pkg_vec_t *pkg_vec;
  9725. + int n_pkgs ;
  9726. + int i;
  9727. + int j;
  9728. +
  9729. + for (i = 0; i < n_providers; i++) {
  9730. + abstract_pkg_t *papkg = apkgs[i];
  9731. + pkg_vec = papkg->pkgs;
  9732. + if (pkg_vec) {
  9733. + n_pkgs = pkg_vec->len;
  9734. + for (j = 0; j < n_pkgs; j++) {
  9735. + pkg_t *pkg = pkg_vec->pkgs[j];
  9736. + if (version_constraints_satisfied(depend, pkg)) {
  9737. + return 1;
  9738. + }
  9739. + }
  9740. + }
  9741. + }
  9742. + return 0;
  9743. +}
  9744. +
  9745. +int pkg_dependence_satisfied(depend_t *depend)
  9746. +{
  9747. + abstract_pkg_t *apkg = depend->pkg;
  9748. + abstract_pkg_vec_t *provider_apkgs = apkg->provided_by;
  9749. + int n_providers = provider_apkgs->len;
  9750. + abstract_pkg_t **apkgs = provider_apkgs->pkgs;
  9751. + int i;
  9752. + int n_pkgs;
  9753. + int j;
  9754. +
  9755. + for (i = 0; i < n_providers; i++) {
  9756. + abstract_pkg_t *papkg = apkgs[i];
  9757. + pkg_vec_t *pkg_vec = papkg->pkgs;
  9758. + if (pkg_vec) {
  9759. + n_pkgs = pkg_vec->len;
  9760. + for (j = 0; j < n_pkgs; j++) {
  9761. + pkg_t *pkg = pkg_vec->pkgs[j];
  9762. + if (version_constraints_satisfied(depend, pkg)) {
  9763. + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED)
  9764. + return 1;
  9765. + }
  9766. + }
  9767. + }
  9768. + }
  9769. + return 0;
  9770. +}
  9771. +
  9772. +static int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg)
  9773. +{
  9774. + register int i;
  9775. + pkg_t ** pkgs = vec->pkgs;
  9776. +
  9777. + for(i = 0; i < vec->len; i++)
  9778. + if((strcmp(pkg->name, (*(pkgs + i))->name) == 0)
  9779. + && (pkg_compare_versions(pkg, *(pkgs + i)) == 0)
  9780. + && (strcmp(pkg->architecture, (*(pkgs + i))->architecture) == 0))
  9781. + return 1;
  9782. + return 0;
  9783. +}
  9784. +
  9785. +
  9786. +#ifdef DeadCode
  9787. +/**
  9788. + * pkg_has_common_provides returns 1 if pkg and replacee both provide
  9789. + * the same abstract package and 0 otherwise.
  9790. + */
  9791. +int pkg_has_common_provides(pkg_t *pkg, pkg_t *replacee)
  9792. +{
  9793. + abstract_pkg_t **provides = pkg->provides;
  9794. + int provides_count = pkg->provides_count;
  9795. + abstract_pkg_t **replacee_provides = replacee->provides;
  9796. + int replacee_provides_count = replacee->provides_count;
  9797. + int i, j;
  9798. + for (i = 0; i < provides_count; i++) {
  9799. + abstract_pkg_t *apkg = provides[i];
  9800. + for (j = 0; j < replacee_provides_count; j++) {
  9801. + abstract_pkg_t *replacee_apkg = replacee_provides[i];
  9802. + if (apkg == replacee_apkg)
  9803. + return 1;
  9804. + }
  9805. + }
  9806. + return 0;
  9807. +}
  9808. +#endif
  9809. +
  9810. +/**
  9811. + * pkg_provides_abstract returns 1 if pkg->provides contains providee
  9812. + * and 0 otherwise.
  9813. + */
  9814. +int pkg_provides_abstract(pkg_t *pkg, abstract_pkg_t *providee)
  9815. +{
  9816. + abstract_pkg_t **provides = pkg->provides;
  9817. + int provides_count = pkg->provides_count;
  9818. + int i;
  9819. + for (i = 0; i < provides_count; i++) {
  9820. + if (provides[i] == providee)
  9821. + return 1;
  9822. + }
  9823. + return 0;
  9824. +}
  9825. +
  9826. +/**
  9827. + * pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0
  9828. + * otherwise.
  9829. + */
  9830. +int pkg_replaces(pkg_t *pkg, pkg_t *replacee)
  9831. +{
  9832. + abstract_pkg_t **replaces = pkg->replaces;
  9833. + int replaces_count = pkg->replaces_count;
  9834. + /* abstract_pkg_t **replacee_provides = pkg->provides;
  9835. + int replacee_provides_count = pkg->provides_count; */
  9836. + int i, j;
  9837. + for (i = 0; i < replaces_count; i++) {
  9838. + abstract_pkg_t *abstract_replacee = replaces[i];
  9839. + for (j = 0; j < replaces_count; j++) {
  9840. + /* ipkg_message(NULL, IPKG_DEBUG2, "Searching pkg-name %s repprovname %s absrepname %s \n",
  9841. + pkg->name,replacee->provides[j]->name, abstract_replacee->name); */
  9842. + if (replacee->provides[j] == abstract_replacee)
  9843. + return 1;
  9844. + }
  9845. + }
  9846. + return 0;
  9847. +}
  9848. +
  9849. +
  9850. +/**
  9851. + * pkg_conflicts_abstract returns 1 if pkg->conflicts contains conflictee and 0
  9852. + * otherwise.
  9853. + */
  9854. +int pkg_conflicts_abstract(pkg_t *pkg, abstract_pkg_t *conflictee)
  9855. +{
  9856. + compound_depend_t *conflicts = pkg->conflicts;
  9857. + int conflicts_count = pkg->conflicts_count;
  9858. + int i, j;
  9859. + for (i = 0; i < conflicts_count; i++) {
  9860. + int possibility_count = conflicts[i].possibility_count;
  9861. + struct depend **possibilities = conflicts[i].possibilities;
  9862. + for (j = 0; j < possibility_count; j++) {
  9863. + if (possibilities[j]->pkg == conflictee) {
  9864. + return 1;
  9865. + }
  9866. + }
  9867. + }
  9868. + return 0;
  9869. +}
  9870. +
  9871. +/**
  9872. + * pkg_conflicts returns 1 if pkg->conflicts contains one of
  9873. + * conflictee's provides and 0 otherwise.
  9874. + */
  9875. +int pkg_conflicts(pkg_t *pkg, pkg_t *conflictee)
  9876. +{
  9877. + compound_depend_t *conflicts = pkg->conflicts;
  9878. + int conflicts_count = pkg->conflicts_count;
  9879. + abstract_pkg_t **conflictee_provides = conflictee->provides;
  9880. + int conflictee_provides_count = conflictee->provides_count;
  9881. + int i, j, k;
  9882. + int possibility_count;
  9883. + struct depend **possibilities;
  9884. + abstract_pkg_t *possibility ;
  9885. +
  9886. + for (i = 0; i < conflicts_count; i++) {
  9887. + possibility_count = conflicts[i].possibility_count;
  9888. + possibilities = conflicts[i].possibilities;
  9889. + for (j = 0; j < possibility_count; j++) {
  9890. + possibility = possibilities[j]->pkg;
  9891. + for (k = 0; k < conflictee_provides_count; k++) {
  9892. + if (possibility == conflictee_provides[k]) {
  9893. + return 1;
  9894. + }
  9895. + }
  9896. + }
  9897. + }
  9898. + return 0;
  9899. +}
  9900. +
  9901. +static char ** merge_unresolved(char ** oldstuff, char ** newstuff)
  9902. +{
  9903. + int oldlen = 0, newlen = 0;
  9904. + char ** result;
  9905. + register int i, j;
  9906. +
  9907. + if(!newstuff)
  9908. + return oldstuff;
  9909. +
  9910. + while(oldstuff && oldstuff[oldlen]) oldlen++;
  9911. + while(newstuff && newstuff[newlen]) newlen++;
  9912. +
  9913. + result = (char **)realloc(oldstuff, sizeof(char *) * (oldlen + newlen + 1));
  9914. + if (result == NULL) {
  9915. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  9916. + return NULL;
  9917. + }
  9918. +
  9919. + for(i = oldlen, j = 0; i < (oldlen + newlen); i++, j++)
  9920. + *(result + i) = *(newstuff + j);
  9921. +
  9922. + *(result + i) = NULL;
  9923. +
  9924. + return result;
  9925. +}
  9926. +
  9927. +/*
  9928. + * a kinda kludgy way to back out depends str from two different arrays (reg'l'r 'n pre)
  9929. + * this is null terminated, no count is carried around
  9930. + */
  9931. +char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx)
  9932. +{
  9933. + int count;
  9934. + char ** resized;
  9935. + char *depend_str = pkg_depend_str(pkg, ref_ndx);
  9936. +
  9937. + count = 0;
  9938. + while(the_lost && the_lost[count]) count++;
  9939. +
  9940. + count++; /* need one to hold the null */
  9941. + resized = (char **)realloc(the_lost, sizeof(char *) * (count + 1));
  9942. + if (resized == NULL) {
  9943. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  9944. + return NULL;
  9945. + }
  9946. + resized[count - 1] = strdup(depend_str);
  9947. + resized[count] = NULL;
  9948. +
  9949. + return resized;
  9950. +}
  9951. +
  9952. +void printDepends(pkg_t * pkg)
  9953. +{
  9954. + register int i, j;
  9955. + compound_depend_t * depend;
  9956. + int count;
  9957. +
  9958. + count = pkg->pre_depends_count + pkg->depends_count;
  9959. +
  9960. + depend = pkg->depends;
  9961. + if(!depend){
  9962. + fprintf(stderr, "Depends pointer is NULL\n");
  9963. + return;
  9964. + }
  9965. + for(i = 0; i < count; i++){
  9966. + fprintf(stderr, "%s has %d possibilities:\n",
  9967. + (depend->type == GREEDY_DEPEND) ? "Greedy-Depend" : ((depend->type == DEPEND) ? "Depend" : "Pre-Depend"),
  9968. + depend->possibility_count);
  9969. + for(j = 0; j < depend->possibility_count; j++)
  9970. + fprintf(stderr, "\t%s version %s (%d)\n",
  9971. + depend->possibilities[j]->pkg->name,
  9972. + depend->possibilities[j]->version,
  9973. + depend->possibilities[j]->constraint);
  9974. + depend++;
  9975. + }
  9976. +}
  9977. +
  9978. +int buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
  9979. +{
  9980. + register int i, j;
  9981. +
  9982. + /* every pkg provides itself */
  9983. + abstract_pkg_vec_insert(ab_pkg->provided_by, ab_pkg);
  9984. +
  9985. + if (!pkg->provides_count)
  9986. + return 0;
  9987. +
  9988. + pkg->provides = (abstract_pkg_t **)malloc(sizeof(abstract_pkg_t *) * (pkg->provides_count + 1));
  9989. + if (pkg->provides == NULL) {
  9990. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  9991. + return -1 ;
  9992. + }
  9993. + pkg->provides[0] = ab_pkg;
  9994. +
  9995. + // if (strcmp(ab_pkg->name, pkg->name))
  9996. + // fprintf(stderr, __FUNCTION__ ": ab_pkg=%s pkg=%s\n", ab_pkg->name, pkg->name);
  9997. +
  9998. + for(i = 0; i < pkg->provides_count; i++){
  9999. + abstract_pkg_t *provided_abpkg = ensure_abstract_pkg_by_name(hash, pkg->provides_str[i]);
  10000. +
  10001. + pkg->provides[i+1] = provided_abpkg;
  10002. +
  10003. + j = 0;
  10004. + abstract_pkg_vec_insert(provided_abpkg->provided_by, ab_pkg);
  10005. + }
  10006. + return 0;
  10007. +}
  10008. +
  10009. +/* Abhaya: added conflicts support */
  10010. +int buildConflicts(hash_table_t * hash, pkg_t * pkg)
  10011. +{
  10012. + register int i;
  10013. + compound_depend_t * conflicts;
  10014. +
  10015. + if (!pkg->conflicts_count)
  10016. + return 0;
  10017. +
  10018. + conflicts = pkg->conflicts = malloc(sizeof(compound_depend_t) *
  10019. + pkg->conflicts_count);
  10020. + if (conflicts == NULL) {
  10021. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10022. + return -1;
  10023. + }
  10024. + for (i = 0; i < pkg->conflicts_count; i++) {
  10025. + conflicts->type = CONFLICTS;
  10026. + parseDepends(conflicts, hash,
  10027. + pkg->conflicts_str[i]);
  10028. +#if 0
  10029. + for (j = 0; j < conflicts->possibility_count; j++) {
  10030. + depend_t *possibility = conflicts->possibilities[j];
  10031. + abstract_pkg_t *conflicting_apkg = possibility->pkg;
  10032. + pkg_add_conflict_pair(ab_pkg, conflicting_apkg);
  10033. + }
  10034. +#endif
  10035. + conflicts++;
  10036. + }
  10037. + return 0;
  10038. +}
  10039. +
  10040. +int buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
  10041. +{
  10042. + register int i, j;
  10043. +
  10044. + if (!pkg->replaces_count)
  10045. + return 0;
  10046. +
  10047. + pkg->replaces = (abstract_pkg_t **)malloc(sizeof(abstract_pkg_t *) * pkg->replaces_count);
  10048. + if (pkg->replaces == NULL) {
  10049. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10050. + return -1;
  10051. + }
  10052. +
  10053. + // if (strcmp(ab_pkg->name, pkg->name))
  10054. + // fprintf(stderr, __FUNCTION__ ": ab_pkg=%s pkg=%s\n", ab_pkg->name, pkg->name);
  10055. +
  10056. + for(i = 0; i < pkg->replaces_count; i++){
  10057. + abstract_pkg_t *old_abpkg = ensure_abstract_pkg_by_name(hash, pkg->replaces_str[i]);
  10058. +
  10059. + pkg->replaces[i] = old_abpkg;
  10060. +
  10061. + j = 0;
  10062. + if (!old_abpkg->replaced_by)
  10063. + old_abpkg->replaced_by = abstract_pkg_vec_alloc();
  10064. + if ( old_abpkg->replaced_by == NULL ){
  10065. + return -1;
  10066. + }
  10067. + /* if a package pkg both replaces and conflicts old_abpkg,
  10068. + * then add it to the replaced_by vector so that old_abpkg
  10069. + * will be upgraded to ab_pkg automatically */
  10070. + if (pkg_conflicts_abstract(pkg, old_abpkg))
  10071. + abstract_pkg_vec_insert(old_abpkg->replaced_by, ab_pkg);
  10072. + }
  10073. + return 0;
  10074. +}
  10075. +
  10076. +int buildDepends(hash_table_t * hash, pkg_t * pkg)
  10077. +{
  10078. + int count;
  10079. + register int i;
  10080. + compound_depend_t * depends;
  10081. +
  10082. + if(!(count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count))
  10083. + return 0;
  10084. +
  10085. + if (0 && pkg->pre_depends_count)
  10086. + fprintf(stderr, "pkg=%s pre_depends_count=%d depends_count=%d\n",
  10087. + pkg->name, pkg->pre_depends_count, pkg->depends_count);
  10088. + depends = pkg->depends = malloc(sizeof(compound_depend_t) * count);
  10089. + if (depends == NULL) {
  10090. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10091. + return -1;
  10092. + }
  10093. +
  10094. +
  10095. + for(i = 0; i < pkg->pre_depends_count; i++){
  10096. + parseDepends(depends, hash, pkg->pre_depends_str[i]);
  10097. + if (0 && pkg->pre_depends_count)
  10098. + fprintf(stderr, " pre_depends_str=%s depends=%p possibility_count=%x\n",
  10099. + pkg->pre_depends_str[i], depends, depends->possibility_count);
  10100. + depends->type = PREDEPEND;
  10101. + depends++;
  10102. + }
  10103. +
  10104. + for(i = 0; i < pkg->recommends_count; i++){
  10105. + parseDepends(depends, hash, pkg->recommends_str[i]);
  10106. + if (0 && pkg->recommends_count)
  10107. + fprintf(stderr, " recommends_str=%s depends=%p possibility_count=%x\n",
  10108. + pkg->recommends_str[i], depends, depends->possibility_count);
  10109. + depends->type = RECOMMEND;
  10110. + depends++;
  10111. + }
  10112. +
  10113. + for(i = 0; i < pkg->suggests_count; i++){
  10114. + parseDepends(depends, hash, pkg->suggests_str[i]);
  10115. + if (0 && pkg->suggests_count)
  10116. + fprintf(stderr, " suggests_str=%s depends=%p possibility_count=%x\n",
  10117. + pkg->suggests_str[i], depends, depends->possibility_count);
  10118. + depends->type = SUGGEST;
  10119. + depends++;
  10120. + }
  10121. +
  10122. + for(i = 0; i < pkg->depends_count; i++){
  10123. + parseDepends(depends, hash, pkg->depends_str[i]);
  10124. + if (0 && pkg->depends_count)
  10125. + fprintf(stderr, " depends_str=%s depends=%p possibility_count=%x\n",
  10126. + pkg->depends_str[i], depends, depends->possibility_count);
  10127. + depends++;
  10128. + }
  10129. + return 0;
  10130. +}
  10131. +
  10132. +/*
  10133. + * pkg_depend_string: returns the depends string specified by index_.
  10134. + * All 4 kinds of dependences: dependence, pre-dependence, recommend, and suggest are number starting from 0.
  10135. + * [0,npredepends) -> returns pre_depends_str[index_]
  10136. + * [npredepends,npredepends+nrecommends) -> returns recommends_str[index_]
  10137. + * [npredepends+nrecommends,npredepends+nrecommends+nsuggests) -> returns recommends_str[index_]
  10138. + * [npredepends+nrecommends+nsuggests,npredepends+nrecommends+nsuggests+ndepends) -> returns depends_str[index_]
  10139. + */
  10140. +char *pkg_depend_str(pkg_t *pkg, int index_)
  10141. +{
  10142. + if (index_ < pkg->pre_depends_count) {
  10143. + return pkg->pre_depends_str[index_];
  10144. + }
  10145. + index_ -= pkg->pre_depends_count;
  10146. +
  10147. + if (index_ < pkg->recommends_count) {
  10148. + return pkg->recommends_str[index_];
  10149. + }
  10150. + index_ -= pkg->recommends_count;
  10151. +
  10152. + if (index_ < pkg->suggests_count) {
  10153. + return pkg->suggests_str[index_];
  10154. + }
  10155. + index_ -= pkg->suggests_count;
  10156. +
  10157. + if (index_ < pkg->depends_count) {
  10158. + return pkg->depends_str[index_];
  10159. + }
  10160. + fprintf(stderr, "pkg_depend_str: index_ %d out of range for pkg=%s\n", index_, pkg->name);
  10161. + return NULL;
  10162. +}
  10163. +
  10164. +void freeDepends(pkg_t *pkg)
  10165. +{
  10166. + int i;
  10167. +
  10168. + if (pkg == NULL || pkg->depends == NULL) {
  10169. + return;
  10170. + }
  10171. +
  10172. + fprintf(stderr, "Freeing depends=%p\n", pkg->depends);
  10173. + for (i=0; i < pkg->depends->possibility_count; i++) {
  10174. + depend_deinit(pkg->depends->possibilities[i]);
  10175. + }
  10176. + free(pkg->depends->possibilities);
  10177. + free(pkg->depends);
  10178. + pkg->depends = NULL;
  10179. +}
  10180. +
  10181. +void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg)
  10182. +{
  10183. + compound_depend_t * depends;
  10184. + int count, othercount;
  10185. + register int i, j;
  10186. + abstract_pkg_t * ab_depend;
  10187. + abstract_pkg_t ** temp;
  10188. +
  10189. + count = pkg->pre_depends_count + pkg->depends_count;
  10190. + depends = pkg->depends;
  10191. +
  10192. + if (0 && pkg->pre_depends_count)
  10193. + fprintf(stderr, "pkg=%s pre_depends_count=%d depends_count=%d\n",
  10194. + pkg->name, pkg->pre_depends_count, pkg->depends_count);
  10195. + for (i = 0; i < count; i++) {
  10196. + if (0 && pkg->pre_depends_count)
  10197. + fprintf(stderr, " i=%d possibility_count=%x depends=%p\n", i, depends->possibility_count, depends);
  10198. + for (j = 0; j < depends->possibility_count; j++){
  10199. + ab_depend = depends->possibilities[j]->pkg;
  10200. + if(!ab_depend->depended_upon_by)
  10201. + ab_depend->depended_upon_by = (abstract_pkg_t **)calloc(1, sizeof(abstract_pkg_t *));
  10202. +
  10203. + temp = ab_depend->depended_upon_by;
  10204. + othercount = 1;
  10205. + while(*temp){
  10206. + temp++;
  10207. + othercount++;
  10208. + }
  10209. + *temp = ab_pkg;
  10210. +
  10211. + ab_depend->depended_upon_by = (abstract_pkg_t **)realloc(ab_depend->depended_upon_by,
  10212. + (othercount + 1) * sizeof(abstract_pkg_t *));
  10213. + /* the array may have moved */
  10214. + temp = ab_depend->depended_upon_by + othercount;
  10215. + *temp = NULL;
  10216. + }
  10217. + depends++;
  10218. + }
  10219. +}
  10220. +
  10221. +static depend_t * depend_init(void)
  10222. +{
  10223. + depend_t * d = (depend_t *)malloc(sizeof(depend_t));
  10224. + if ( d==NULL ){
  10225. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10226. + return NULL;
  10227. + }
  10228. + d->constraint = NONE;
  10229. + d->version = NULL;
  10230. + d->pkg = NULL;
  10231. +
  10232. + return d;
  10233. +}
  10234. +
  10235. +static void depend_deinit(depend_t *d)
  10236. +{
  10237. + free(d);
  10238. +}
  10239. +
  10240. +static int parseDepends(compound_depend_t *compound_depend,
  10241. + hash_table_t * hash, char * depend_str)
  10242. +{
  10243. + char * pkg_name, buffer[2048];
  10244. + int num_of_ors = 0;
  10245. + register int i;
  10246. + register char * src, * dest;
  10247. + depend_t ** possibilities;
  10248. +
  10249. + /* first count the number of ored possibilities for satisfying dependency */
  10250. + src = depend_str;
  10251. + while(*src)
  10252. + if(*src++ == '|')
  10253. + num_of_ors++;
  10254. +
  10255. + compound_depend->type = DEPEND;
  10256. +
  10257. + compound_depend->possibility_count = num_of_ors + 1;
  10258. + possibilities = (depend_t **)malloc(sizeof(depend_t *) * (num_of_ors + 1));
  10259. + if (!possibilities)
  10260. + return -ENOMEM;
  10261. + compound_depend->possibilities = possibilities;
  10262. +
  10263. + src = depend_str;
  10264. + for(i = 0; i < num_of_ors + 1; i++){
  10265. + possibilities[i] = depend_init();
  10266. + if (!possibilities[i])
  10267. + return -ENOMEM;
  10268. + /* gobble up just the name first */
  10269. + dest = buffer;
  10270. + while(*src &&
  10271. + !isspace(*src) &&
  10272. + (*src != '(') &&
  10273. + (*src != '*') &&
  10274. + (*src != '|'))
  10275. + *dest++ = *src++;
  10276. + *dest = '\0';
  10277. + pkg_name = trim_alloc(buffer);
  10278. + if (pkg_name == NULL )
  10279. + return -ENOMEM;
  10280. +
  10281. + /* now look at possible version info */
  10282. +
  10283. + /* skip to next chars */
  10284. + if(isspace(*src))
  10285. + while(*src && isspace(*src)) src++;
  10286. +
  10287. + /* extract constraint and version */
  10288. + if(*src == '('){
  10289. + src++;
  10290. + if(!strncmp(src, "<<", 2)){
  10291. + possibilities[i]->constraint = EARLIER;
  10292. + src += 2;
  10293. + }
  10294. + else if(!strncmp(src, "<=", 2)){
  10295. + possibilities[i]->constraint = EARLIER_EQUAL;
  10296. + src += 2;
  10297. + }
  10298. + else if(!strncmp(src, ">=", 2)){
  10299. + possibilities[i]->constraint = LATER_EQUAL;
  10300. + src += 2;
  10301. + }
  10302. + else if(!strncmp(src, ">>", 2)){
  10303. + possibilities[i]->constraint = LATER;
  10304. + src += 2;
  10305. + }
  10306. + else if(!strncmp(src, "=", 1)){
  10307. + possibilities[i]->constraint = EQUAL;
  10308. + src++;
  10309. + }
  10310. + /* should these be here to support deprecated designations; dpkg does */
  10311. + else if(!strncmp(src, "<", 1)){
  10312. + possibilities[i]->constraint = EARLIER_EQUAL;
  10313. + src++;
  10314. + }
  10315. + else if(!strncmp(src, ">", 1)){
  10316. + possibilities[i]->constraint = LATER_EQUAL;
  10317. + src++;
  10318. + }
  10319. +
  10320. + /* now we have any constraint, pass space to version string */
  10321. + while(isspace(*src)) src++;
  10322. +
  10323. + /* this would be the version string */
  10324. + dest = buffer;
  10325. + while(*src && *src != ')')
  10326. + *dest++ = *src++;
  10327. + *dest = '\0';
  10328. +
  10329. + possibilities[i]->version = trim_alloc(buffer);
  10330. + /* fprintf(stderr, "let's print the depends version string:");
  10331. + fprintf(stderr, "version %s\n", possibilities[i]->version);*/
  10332. + if (possibilities[i]->version == NULL )
  10333. + return -ENOMEM;
  10334. +
  10335. +
  10336. + }
  10337. + /* hook up the dependency to its abstract pkg */
  10338. + possibilities[i]->pkg = ensure_abstract_pkg_by_name(hash, pkg_name);
  10339. +
  10340. + free(pkg_name);
  10341. +
  10342. + /* now get past the ) and any possible | chars */
  10343. + while(*src &&
  10344. + (isspace(*src) ||
  10345. + (*src == ')') ||
  10346. + (*src == '|')))
  10347. + src++;
  10348. + if (*src == '*')
  10349. + {
  10350. + compound_depend->type = GREEDY_DEPEND;
  10351. + src++;
  10352. + }
  10353. + }
  10354. +
  10355. + return 0;
  10356. +}
  10357. diff -Nur busybox-1.12.1.orig/archival/libipkg/pkg_depends.h busybox-1.12.1/archival/libipkg/pkg_depends.h
  10358. --- busybox-1.12.1.orig/archival/libipkg/pkg_depends.h 1970-01-01 01:00:00.000000000 +0100
  10359. +++ busybox-1.12.1/archival/libipkg/pkg_depends.h 2008-10-23 15:05:54.000000000 +0200
  10360. @@ -0,0 +1,105 @@
  10361. +/* pkg_depends.h - the itsy package management system
  10362. +
  10363. + Steven M. Ayer
  10364. +
  10365. + Copyright (C) 2002 Compaq Computer Corporation
  10366. +
  10367. + This program is free software; you can redistribute it and/or
  10368. + modify it under the terms of the GNU General Public License as
  10369. + published by the Free Software Foundation; either version 2, or (at
  10370. + your option) any later version.
  10371. +
  10372. + This program is distributed in the hope that it will be useful, but
  10373. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10374. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10375. + General Public License for more details.
  10376. +*/
  10377. +
  10378. +#ifndef PKG_DEPENDS_H
  10379. +#define PKG_DEPENDS_H
  10380. +
  10381. +#include "pkg.h"
  10382. +#include "pkg_hash.h"
  10383. +
  10384. +enum depend_type {
  10385. + PREDEPEND,
  10386. + DEPEND,
  10387. + CONFLICTS,
  10388. + GREEDY_DEPEND,
  10389. + RECOMMEND,
  10390. + SUGGEST
  10391. +};
  10392. +typedef enum depend_type depend_type_t;
  10393. +
  10394. +enum version_constraint {
  10395. + NONE,
  10396. + EARLIER,
  10397. + EARLIER_EQUAL,
  10398. + EQUAL,
  10399. + LATER_EQUAL,
  10400. + LATER
  10401. +};
  10402. +typedef enum version_constraint version_constraint_t;
  10403. +
  10404. +struct depend{
  10405. + version_constraint_t constraint;
  10406. + char * version;
  10407. + abstract_pkg_t * pkg;
  10408. +};
  10409. +typedef struct depend depend_t;
  10410. +
  10411. +struct compound_depend{
  10412. + depend_type_t type;
  10413. + int possibility_count;
  10414. + struct depend ** possibilities;
  10415. +};
  10416. +typedef struct compound_depend compound_depend_t;
  10417. +
  10418. +#include "hash_table.h"
  10419. +
  10420. +int buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
  10421. +int buildConflicts(hash_table_t * hash, pkg_t * pkg);
  10422. +int buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
  10423. +int buildDepends(hash_table_t * hash, pkg_t * pkg);
  10424. +
  10425. +/**
  10426. + * pkg_has_common_provides returns 1 if pkg and replacee both provide
  10427. + * the same abstract package and 0 otherwise.
  10428. + */
  10429. +int pkg_has_common_provides(pkg_t *pkg, pkg_t *replacee);
  10430. +
  10431. +/**
  10432. + * pkg_provides returns 1 if pkg->provides contains providee and 0
  10433. + * otherwise.
  10434. + */
  10435. +int pkg_provides_abstract(pkg_t *pkg, abstract_pkg_t *providee);
  10436. +
  10437. +/**
  10438. + * pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0
  10439. + * otherwise.
  10440. + */
  10441. +int pkg_replaces(pkg_t *pkg, pkg_t *replacee);
  10442. +
  10443. +/**
  10444. + * pkg_conflicts_abstract returns 1 if pkg->conflicts contains conflictee provides and 0
  10445. + * otherwise.
  10446. + */
  10447. +int pkg_conflicts_abstract(pkg_t *pkg, abstract_pkg_t *conflicts);
  10448. +
  10449. +/**
  10450. + * pkg_conflicts returns 1 if pkg->conflicts contains one of conflictee's provides and 0
  10451. + * otherwise.
  10452. + */
  10453. +int pkg_conflicts(pkg_t *pkg, pkg_t *conflicts);
  10454. +
  10455. +char *pkg_depend_str(pkg_t *pkg, int index_);
  10456. +void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg);
  10457. +void freeDepends(pkg_t *pkg);
  10458. +void printDepends(pkg_t * pkg);
  10459. +int version_constraints_satisfied(depend_t * depends, pkg_t * pkg);
  10460. +int pkg_hash_fetch_unsatisfied_dependencies(ipkg_conf_t *conf, pkg_t * pkg, pkg_vec_t *depends, char *** unresolved);
  10461. +pkg_vec_t * pkg_hash_fetch_conflicts(pkg_t * pkg);
  10462. +int pkg_dependence_satisfiable(depend_t *depend);
  10463. +int pkg_dependence_satisfied(depend_t *depend);
  10464. +
  10465. +#endif
  10466. diff -Nur busybox-1.12.1.orig/archival/libipkg/pkg_dest.c busybox-1.12.1/archival/libipkg/pkg_dest.c
  10467. --- busybox-1.12.1.orig/archival/libipkg/pkg_dest.c 1970-01-01 01:00:00.000000000 +0100
  10468. +++ busybox-1.12.1/archival/libipkg/pkg_dest.c 2008-10-23 11:41:37.000000000 +0200
  10469. @@ -0,0 +1,92 @@
  10470. +/* pkg_dest.c - the itsy package management system
  10471. +
  10472. + Carl D. Worth
  10473. +
  10474. + Copyright (C) 2001 University of Southern California
  10475. +
  10476. + This program is free software; you can redistribute it and/or
  10477. + modify it under the terms of the GNU General Public License as
  10478. + published by the Free Software Foundation; either version 2, or (at
  10479. + your option) any later version.
  10480. +
  10481. + This program is distributed in the hope that it will be useful, but
  10482. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10483. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10484. + General Public License for more details.
  10485. +*/
  10486. +
  10487. +#include "ipkg.h"
  10488. +
  10489. +#include "pkg_dest.h"
  10490. +#include "file_util.h"
  10491. +#include "str_util.h"
  10492. +#include "sprintf_alloc.h"
  10493. +
  10494. +int pkg_dest_init(pkg_dest_t *dest, const char *name, const char *root_dir,const char * lists_dir)
  10495. +{
  10496. + dest->name = strdup(name);
  10497. +
  10498. + /* Guarantee that dest->root_dir ends with a '/' */
  10499. + if (str_ends_with(root_dir, "/")) {
  10500. + dest->root_dir = strdup(root_dir);
  10501. + } else {
  10502. + sprintf_alloc(&dest->root_dir, "%s/", root_dir);
  10503. + }
  10504. + file_mkdir_hier(dest->root_dir, 0755);
  10505. +
  10506. + sprintf_alloc(&dest->ipkg_dir, "%s%s",
  10507. + dest->root_dir, IPKG_STATE_DIR_PREFIX);
  10508. + file_mkdir_hier(dest->ipkg_dir, 0755);
  10509. +
  10510. + if (str_starts_with (lists_dir, "/"))
  10511. + sprintf_alloc(&dest->lists_dir, "%s", lists_dir);
  10512. + else
  10513. + sprintf_alloc(&dest->lists_dir, "/%s", lists_dir);
  10514. +
  10515. + file_mkdir_hier(dest->lists_dir, 0755);
  10516. +
  10517. + sprintf_alloc(&dest->info_dir, "%s/%s",
  10518. + dest->ipkg_dir, IPKG_INFO_DIR_SUFFIX);
  10519. + file_mkdir_hier(dest->info_dir, 0755);
  10520. +
  10521. + sprintf_alloc(&dest->status_file_name, "%s/%s",
  10522. + dest->ipkg_dir, IPKG_STATUS_FILE_SUFFIX);
  10523. +
  10524. + sprintf_alloc(&dest->status_file_tmp_name, "%s/%s.tmp",
  10525. + dest->ipkg_dir, IPKG_STATUS_FILE_SUFFIX);
  10526. +
  10527. + dest->status_file = NULL;
  10528. +
  10529. + return 0;
  10530. +}
  10531. +
  10532. +void pkg_dest_deinit(pkg_dest_t *dest)
  10533. +{
  10534. + free(dest->name);
  10535. + dest->name = NULL;
  10536. +
  10537. + free(dest->root_dir);
  10538. + dest->root_dir = NULL;
  10539. +
  10540. + free(dest->ipkg_dir);
  10541. + dest->ipkg_dir = NULL;
  10542. +
  10543. + free(dest->lists_dir);
  10544. + dest->lists_dir = NULL;
  10545. +
  10546. + free(dest->info_dir);
  10547. + dest->info_dir = NULL;
  10548. +
  10549. + free(dest->status_file_name);
  10550. + dest->status_file_name = NULL;
  10551. +
  10552. + free(dest->status_file_tmp_name);
  10553. + dest->status_file_tmp_name = NULL;
  10554. +
  10555. + if (dest->status_file) {
  10556. + fclose(dest->status_file);
  10557. + }
  10558. + dest->status_file = NULL;
  10559. +
  10560. + dest->root_dir = NULL;
  10561. +}
  10562. diff -Nur busybox-1.12.1.orig/archival/libipkg/pkg_dest.h busybox-1.12.1/archival/libipkg/pkg_dest.h
  10563. --- busybox-1.12.1.orig/archival/libipkg/pkg_dest.h 1970-01-01 01:00:00.000000000 +0100
  10564. +++ busybox-1.12.1/archival/libipkg/pkg_dest.h 2008-10-23 11:41:37.000000000 +0200
  10565. @@ -0,0 +1,38 @@
  10566. +/* pkg_dest.h - the itsy package management system
  10567. +
  10568. + Carl D. Worth
  10569. +
  10570. + Copyright (C) 2001 University of Southern California
  10571. +
  10572. + This program is free software; you can redistribute it and/or
  10573. + modify it under the terms of the GNU General Public License as
  10574. + published by the Free Software Foundation; either version 2, or (at
  10575. + your option) any later version.
  10576. +
  10577. + This program is distributed in the hope that it will be useful, but
  10578. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10579. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10580. + General Public License for more details.
  10581. +*/
  10582. +
  10583. +#ifndef PKG_DEST_H
  10584. +#define PKG_DEST_H
  10585. +
  10586. +typedef struct pkg_dest pkg_dest_t;
  10587. +struct pkg_dest
  10588. +{
  10589. + char *name;
  10590. + char *root_dir;
  10591. + char *ipkg_dir;
  10592. + char *lists_dir;
  10593. + char *info_dir;
  10594. + char *status_file_name;
  10595. + char *status_file_tmp_name;
  10596. + FILE *status_file;
  10597. +};
  10598. +
  10599. +int pkg_dest_init(pkg_dest_t *dest, const char *name, const char *root_dir,const char *lists_dir);
  10600. +void pkg_dest_deinit(pkg_dest_t *dest);
  10601. +
  10602. +#endif
  10603. +
  10604. diff -Nur busybox-1.12.1.orig/archival/libipkg/pkg_dest_list.c busybox-1.12.1/archival/libipkg/pkg_dest_list.c
  10605. --- busybox-1.12.1.orig/archival/libipkg/pkg_dest_list.c 1970-01-01 01:00:00.000000000 +0100
  10606. +++ busybox-1.12.1/archival/libipkg/pkg_dest_list.c 2008-10-23 11:41:37.000000000 +0200
  10607. @@ -0,0 +1,85 @@
  10608. +/* pkg_dest_list.c - the itsy package management system
  10609. +
  10610. + Carl D. Worth
  10611. +
  10612. + Copyright (C) 2001 University of Southern California
  10613. +
  10614. + This program is free software; you can redistribute it and/or
  10615. + modify it under the terms of the GNU General Public License as
  10616. + published by the Free Software Foundation; either version 2, or (at
  10617. + your option) any later version.
  10618. +
  10619. + This program is distributed in the hope that it will be useful, but
  10620. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10621. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10622. + General Public License for more details.
  10623. +*/
  10624. +
  10625. +#include "ipkg.h"
  10626. +
  10627. +#include "pkg_dest.h"
  10628. +#include "void_list.h"
  10629. +#include "pkg_dest_list.h"
  10630. +
  10631. +int pkg_dest_list_elt_init(pkg_dest_list_elt_t *elt, pkg_dest_t *data)
  10632. +{
  10633. + return void_list_elt_init((void_list_elt_t *) elt, data);
  10634. +}
  10635. +
  10636. +void pkg_dest_list_elt_deinit(pkg_dest_list_elt_t *elt)
  10637. +{
  10638. + void_list_elt_deinit((void_list_elt_t *) elt);
  10639. +}
  10640. +
  10641. +int pkg_dest_list_init(pkg_dest_list_t *list)
  10642. +{
  10643. + return void_list_init((void_list_t *) list);
  10644. +}
  10645. +
  10646. +void pkg_dest_list_deinit(pkg_dest_list_t *list)
  10647. +{
  10648. + pkg_dest_list_elt_t *iter;
  10649. + pkg_dest_t *pkg_dest;
  10650. +
  10651. + for (iter = list->head; iter; iter = iter->next) {
  10652. + pkg_dest = iter->data;
  10653. + pkg_dest_deinit(pkg_dest);
  10654. +
  10655. + /* malloced in pkg_dest_list_append */
  10656. + free(pkg_dest);
  10657. + iter->data = NULL;
  10658. + }
  10659. + void_list_deinit((void_list_t *) list);
  10660. +}
  10661. +
  10662. +pkg_dest_t *pkg_dest_list_append(pkg_dest_list_t *list, const char *name,
  10663. + const char *root_dir,const char *lists_dir)
  10664. +{
  10665. + int err;
  10666. + pkg_dest_t *pkg_dest;
  10667. +
  10668. + /* freed in plg_dest_list_deinit */
  10669. + pkg_dest = malloc(sizeof(pkg_dest_t));
  10670. + if (pkg_dest == NULL) {
  10671. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10672. + return NULL;
  10673. + }
  10674. +
  10675. + pkg_dest_init(pkg_dest, name, root_dir,lists_dir);
  10676. + err = void_list_append((void_list_t *) list, pkg_dest);
  10677. + if (err) {
  10678. + return NULL;
  10679. + }
  10680. +
  10681. + return pkg_dest;
  10682. +}
  10683. +
  10684. +int pkg_dest_list_push(pkg_dest_list_t *list, pkg_dest_t *data)
  10685. +{
  10686. + return void_list_push((void_list_t *) list, data);
  10687. +}
  10688. +
  10689. +pkg_dest_list_elt_t *pkg_dest_list_pop(pkg_dest_list_t *list)
  10690. +{
  10691. + return (pkg_dest_list_elt_t *) void_list_pop((void_list_t *) list);
  10692. +}
  10693. diff -Nur busybox-1.12.1.orig/archival/libipkg/pkg_dest_list.h busybox-1.12.1/archival/libipkg/pkg_dest_list.h
  10694. --- busybox-1.12.1.orig/archival/libipkg/pkg_dest_list.h 1970-01-01 01:00:00.000000000 +0100
  10695. +++ busybox-1.12.1/archival/libipkg/pkg_dest_list.h 2008-10-23 11:41:37.000000000 +0200
  10696. @@ -0,0 +1,50 @@
  10697. +/* pkg_dest_list.h - the itsy package management system
  10698. +
  10699. + Carl D. Worth
  10700. +
  10701. + Copyright (C) 2001 University of Southern California
  10702. +
  10703. + This program is free software; you can redistribute it and/or
  10704. + modify it under the terms of the GNU General Public License as
  10705. + published by the Free Software Foundation; either version 2, or (at
  10706. + your option) any later version.
  10707. +
  10708. + This program is distributed in the hope that it will be useful, but
  10709. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10710. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10711. + General Public License for more details.
  10712. +*/
  10713. +
  10714. +#ifndef PKG_DEST_LIST_H
  10715. +#define PKG_DEST_LIST_H
  10716. +
  10717. +#include "pkg_dest.h"
  10718. +
  10719. +typedef struct pkg_dest_list_elt pkg_dest_list_elt_t;
  10720. +struct pkg_dest_list_elt
  10721. +{
  10722. + pkg_dest_list_elt_t *next;
  10723. + pkg_dest_t *data;
  10724. +};
  10725. +
  10726. +typedef struct pkg_dest_list pkg_dest_list_t;
  10727. +struct pkg_dest_list
  10728. +{
  10729. + pkg_dest_list_elt_t pre_head;
  10730. + pkg_dest_list_elt_t *head;
  10731. + pkg_dest_list_elt_t *tail;
  10732. +};
  10733. +
  10734. +int pkg_dest_list_elt_init(pkg_dest_list_elt_t *elt, pkg_dest_t *data);
  10735. +void pkg_dest_list_elt_deinit(pkg_dest_list_elt_t *elt);
  10736. +
  10737. +int pkg_dest_list_init(pkg_dest_list_t *list);
  10738. +void pkg_dest_list_deinit(pkg_dest_list_t *list);
  10739. +
  10740. +pkg_dest_t *pkg_dest_list_append(pkg_dest_list_t *list, const char *name,
  10741. + const char *root_dir,const char* lists_dir);
  10742. +int pkg_dest_list_push(pkg_dest_list_t *list, pkg_dest_t *data);
  10743. +pkg_dest_list_elt_t *pkg_dest_list_pop(pkg_dest_list_t *list);
  10744. +
  10745. +#endif
  10746. +
  10747. diff -Nur busybox-1.12.1.orig/archival/libipkg/pkg_extract.c busybox-1.12.1/archival/libipkg/pkg_extract.c
  10748. --- busybox-1.12.1.orig/archival/libipkg/pkg_extract.c 1970-01-01 01:00:00.000000000 +0100
  10749. +++ busybox-1.12.1/archival/libipkg/pkg_extract.c 2008-10-23 15:21:22.000000000 +0200
  10750. @@ -0,0 +1,225 @@
  10751. +/* pkg_extract.c - the itsy package management system
  10752. +
  10753. + Carl D. Worth
  10754. +
  10755. + Copyright (C) 2001 University of Southern California
  10756. +
  10757. + This program is free software; you can redistribute it and/or
  10758. + modify it under the terms of the GNU General Public License as
  10759. + published by the Free Software Foundation; either version 2, or (at
  10760. + your option) any later version.
  10761. +
  10762. + This program is distributed in the hope that it will be useful, but
  10763. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10764. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10765. + General Public License for more details.
  10766. +*/
  10767. +
  10768. +#include "ipkg.h"
  10769. +#include <errno.h>
  10770. +#include <fcntl.h>
  10771. +#include <stdio.h>
  10772. +
  10773. +#include "pkg_extract.h"
  10774. +
  10775. +#include "libbb.h"
  10776. +#include "file_util.h"
  10777. +#include "sprintf_alloc.h"
  10778. +#include "unarchive.h"
  10779. +
  10780. +#define IPKG_CONTROL_ARCHIVE "control.tar.gz"
  10781. +#define IPKG_DATA_ARCHIVE "data.tar.gz"
  10782. +#define IPKG_CONTROL_FILE "control"
  10783. +
  10784. +static void extract_ipkg_file_to_dir(pkg_t *pkg, const char *dir, const char *filename)
  10785. +{
  10786. + archive_handle_t *archive;
  10787. + char *path;
  10788. +
  10789. + sprintf_alloc(&path, "%s/", dir);
  10790. + archive = init_handle();
  10791. + archive->src_fd = xopen(pkg->local_filename, O_RDONLY);
  10792. + archive->filter = filter_accept_list;
  10793. + llist_add_to(&(archive->accept), (char *)filename);
  10794. + archive->buffer = path;
  10795. + archive->action_data = data_extract_all_prefix;
  10796. + archive->ah_flags |= ARCHIVE_EXTRACT_UNCONDITIONAL;
  10797. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  10798. + close(archive->src_fd);
  10799. + free(archive->accept);
  10800. + free(archive);
  10801. + free(path);
  10802. +}
  10803. +
  10804. +static void FAST_FUNC data_extract_file_name_to_buffer(archive_handle_t *archive)
  10805. +{
  10806. + unsigned int size = strlen(archive->file_header->name) + 2;
  10807. +
  10808. + if (archive->buffer == NULL) {
  10809. + archive->buffer = xmalloc(size);
  10810. + strcpy(archive->buffer, archive->file_header->name);
  10811. + } else {
  10812. + size += strlen(archive->buffer);
  10813. + archive->buffer = xrealloc(archive->buffer, size);
  10814. + strcat(archive->buffer, archive->file_header->name);
  10815. + }
  10816. + strcat(archive->buffer, "\n");
  10817. + data_skip(archive);
  10818. +}
  10819. +
  10820. +int pkg_extract_control_file_to_stream(pkg_t *pkg, FILE *stream)
  10821. +{
  10822. + archive_handle_t *archive;
  10823. + char *name;
  10824. + const char *filename = "./" IPKG_CONTROL_FILE;
  10825. +
  10826. + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_CONTROL_ARCHIVE);
  10827. + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_CONTROL_ARCHIVE);
  10828. + archive = init_handle();
  10829. + archive->src_fd = xopen(name, O_RDONLY);
  10830. + archive->filter = filter_accept_list;
  10831. + llist_add_to(&(archive->accept), (char *)filename);
  10832. + archive->action_data = data_extract_to_buffer;
  10833. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  10834. + close(archive->src_fd);
  10835. + fputs(archive->buffer, stream);
  10836. + free(archive->buffer);
  10837. + free(archive->accept);
  10838. + free(archive);
  10839. + free(name);
  10840. +
  10841. + return 0;
  10842. +}
  10843. +
  10844. +int pkg_extract_control_files_to_dir(pkg_t *pkg, const char *dir)
  10845. +{
  10846. + return pkg_extract_control_files_to_dir_with_prefix(pkg, dir, "");
  10847. +}
  10848. +
  10849. +int pkg_extract_control_files_to_dir_with_prefix(pkg_t *pkg, const char *dir, const char *prefix)
  10850. +{
  10851. + archive_handle_t *archive;
  10852. + char *name;
  10853. + char *path;
  10854. +
  10855. + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_CONTROL_ARCHIVE);
  10856. + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_CONTROL_ARCHIVE);
  10857. + sprintf_alloc(&path, "%s/%s", dir, prefix);
  10858. + archive = init_handle();
  10859. + archive->src_fd = xopen(name, O_RDONLY);
  10860. + archive->filter = filter_accept_all;
  10861. + archive->buffer = path;
  10862. + archive->action_data = data_extract_all_prefix;
  10863. + archive->ah_flags |= ARCHIVE_CREATE_LEADING_DIRS | ARCHIVE_PRESERVE_DATE | ARCHIVE_EXTRACT_UNCONDITIONAL;
  10864. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  10865. + close(archive->src_fd);
  10866. + free(archive);
  10867. + free(path);
  10868. + free(name);
  10869. +
  10870. + return 0;
  10871. +}
  10872. +
  10873. +int pkg_extract_data_files_to_dir(pkg_t *pkg, const char *dir)
  10874. +{
  10875. + archive_handle_t *archive;
  10876. + char *name;
  10877. + char *path;
  10878. +
  10879. + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_DATA_ARCHIVE);
  10880. + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_DATA_ARCHIVE);
  10881. + sprintf_alloc(&path, "%s/", dir);
  10882. + archive = init_handle();
  10883. + archive->src_fd = xopen(name, O_RDONLY);
  10884. + archive->filter = filter_accept_all;
  10885. + archive->buffer = path;
  10886. + archive->action_data = data_extract_all_prefix;
  10887. + archive->ah_flags |= ARCHIVE_CREATE_LEADING_DIRS | ARCHIVE_PRESERVE_DATE | ARCHIVE_EXTRACT_UNCONDITIONAL;
  10888. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  10889. + close(archive->src_fd);
  10890. + free(archive);
  10891. + free(path);
  10892. + free(name);
  10893. +
  10894. + return 0;
  10895. +}
  10896. +
  10897. +int pkg_extract_data_file_names_to_file(pkg_t *pkg, const char *file_name)
  10898. +{
  10899. + int err=0;
  10900. + char *line, *data_file;
  10901. + FILE *file;
  10902. + FILE *tmp;
  10903. +
  10904. + file = fopen(file_name, "w");
  10905. + if (file == NULL) {
  10906. + fprintf(stderr, "%s: ERROR: Failed to open %s for writing.\n",
  10907. + __FUNCTION__, file_name);
  10908. + return EINVAL;
  10909. + }
  10910. +
  10911. + tmp = tmpfile();
  10912. + if (pkg->installed_files) {
  10913. + str_list_elt_t *elt;
  10914. + for (elt = pkg->installed_files->head; elt; elt = elt->next) {
  10915. + fprintf(file, "%s\n", elt->data);
  10916. + }
  10917. + } else {
  10918. + err = pkg_extract_data_file_names_to_stream(pkg, tmp);
  10919. + if (err) {
  10920. + fclose(file);
  10921. + fclose(tmp);
  10922. + return err;
  10923. + }
  10924. +
  10925. + /* Fixup data file names by removing the initial '.' */
  10926. + rewind(tmp);
  10927. + while (1) {
  10928. + line = file_read_line_alloc(tmp);
  10929. + if (line == NULL) {
  10930. + break;
  10931. + }
  10932. +
  10933. + data_file = line;
  10934. + if (*data_file == '.') {
  10935. + data_file++;
  10936. + }
  10937. +
  10938. + if (*data_file != '/') {
  10939. + fputs("/", file);
  10940. + }
  10941. +
  10942. + /* I have no idea why, but this is what dpkg does */
  10943. + if (strcmp(data_file, "/\n") == 0) {
  10944. + fputs("/.\n", file);
  10945. + } else {
  10946. + fputs(data_file, file);
  10947. + }
  10948. + }
  10949. + }
  10950. + fclose(tmp);
  10951. + fclose(file);
  10952. +
  10953. + return err;
  10954. +}
  10955. +
  10956. +int pkg_extract_data_file_names_to_stream(pkg_t *pkg, FILE *file)
  10957. +{
  10958. + archive_handle_t *archive;
  10959. + char *name;
  10960. +
  10961. + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_DATA_ARCHIVE);
  10962. + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_DATA_ARCHIVE);
  10963. + archive = init_handle();
  10964. + archive->src_fd = xopen(name, O_RDONLY);
  10965. + archive->filter = filter_accept_all;
  10966. + archive->action_data = data_extract_file_name_to_buffer;
  10967. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  10968. + close(archive->src_fd);
  10969. + fputs(archive->buffer, file);
  10970. + free(archive->buffer);
  10971. + free(archive);
  10972. + free(name);
  10973. +
  10974. + return 0;
  10975. +}
  10976. diff -Nur busybox-1.12.1.orig/archival/libipkg/pkg_extract.h busybox-1.12.1/archival/libipkg/pkg_extract.h
  10977. --- busybox-1.12.1.orig/archival/libipkg/pkg_extract.h 1970-01-01 01:00:00.000000000 +0100
  10978. +++ busybox-1.12.1/archival/libipkg/pkg_extract.h 2008-10-23 11:41:37.000000000 +0200
  10979. @@ -0,0 +1,32 @@
  10980. +/* pkg_extract.c - the itsy package management system
  10981. +
  10982. + Carl D. Worth
  10983. +
  10984. + Copyright (C) 2001 University of Southern California
  10985. +
  10986. + This program is free software; you can redistribute it and/or
  10987. + modify it under the terms of the GNU General Public License as
  10988. + published by the Free Software Foundation; either version 2, or (at
  10989. + your option) any later version.
  10990. +
  10991. + This program is distributed in the hope that it will be useful, but
  10992. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10993. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10994. + General Public License for more details.
  10995. +*/
  10996. +
  10997. +#ifndef PKG_EXTRACT_H
  10998. +#define PKG_EXTRACT_H
  10999. +
  11000. +#include "pkg.h"
  11001. +
  11002. +int pkg_extract_control_file_to_stream(pkg_t *pkg, FILE *stream);
  11003. +int pkg_extract_control_files_to_dir(pkg_t *pkg, const char *dir);
  11004. +int pkg_extract_control_files_to_dir_with_prefix(pkg_t *pkg,
  11005. + const char *dir,
  11006. + const char *prefix);
  11007. +int pkg_extract_data_files_to_dir(pkg_t *pkg, const char *dir);
  11008. +int pkg_extract_data_file_names_to_file(pkg_t *pkg, const char *file_name);
  11009. +int pkg_extract_data_file_names_to_stream(pkg_t *pkg, FILE *file);
  11010. +
  11011. +#endif
  11012. diff -Nur busybox-1.12.1.orig/archival/libipkg/pkg.h busybox-1.12.1/archival/libipkg/pkg.h
  11013. --- busybox-1.12.1.orig/archival/libipkg/pkg.h 1970-01-01 01:00:00.000000000 +0100
  11014. +++ busybox-1.12.1/archival/libipkg/pkg.h 2008-10-23 15:27:11.000000000 +0200
  11015. @@ -0,0 +1,229 @@
  11016. +/* pkg.h - the itsy package management system
  11017. +
  11018. + Carl D. Worth
  11019. +
  11020. + Copyright (C) 2001 University of Southern California
  11021. +
  11022. + This program is free software; you can redistribute it and/or
  11023. + modify it under the terms of the GNU General Public License as
  11024. + published by the Free Software Foundation; either version 2, or (at
  11025. + your option) any later version.
  11026. +
  11027. + This program is distributed in the hope that it will be useful, but
  11028. + WITHOUT ANY WARRANTY; without even the implied warranty of
  11029. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11030. + General Public License for more details.
  11031. +*/
  11032. +
  11033. +#ifndef PKG_H
  11034. +#define PKG_H
  11035. +
  11036. +#include <sys/types.h>
  11037. +#include <sys/stat.h>
  11038. +#include <unistd.h>
  11039. +
  11040. +#include "pkg_vec.h"
  11041. +#include "str_list.h"
  11042. +#include "pkg_src.h"
  11043. +#include "pkg_dest.h"
  11044. +#include "ipkg_conf.h"
  11045. +#include "conffile_list.h"
  11046. +
  11047. +struct ipkg_conf;
  11048. +
  11049. +/* I think "Size" is currently the shortest field name */
  11050. +#define PKG_MINIMUM_FIELD_NAME_LEN 4
  11051. +
  11052. +enum pkg_state_want
  11053. +{
  11054. + SW_UNKNOWN = 1,
  11055. + SW_INSTALL,
  11056. + SW_DEINSTALL,
  11057. + SW_PURGE,
  11058. + SW_LAST_STATE_WANT
  11059. +};
  11060. +typedef enum pkg_state_want pkg_state_want_t;
  11061. +
  11062. +enum pkg_state_flag
  11063. +{
  11064. + SF_OK = 0,
  11065. + SF_REINSTREQ = 1,
  11066. + SF_HOLD = 2, /* do not upgrade version */
  11067. + SF_REPLACE = 4, /* replace this package */
  11068. + SF_NOPRUNE = 8, /* do not remove obsolete files */
  11069. + SF_PREFER = 16, /* prefer this version */
  11070. + SF_OBSOLETE = 32, /* old package in upgrade pair */
  11071. + SF_MARKED = 64, /* temporary mark */
  11072. + SF_FILELIST_CHANGED = 128, /* needs filelist written */
  11073. + SF_USER = 256,
  11074. + SF_LAST_STATE_FLAG
  11075. +};
  11076. +typedef enum pkg_state_flag pkg_state_flag_t;
  11077. +#define SF_NONVOLATILE_FLAGS (SF_HOLD|SF_NOPRUNE|SF_PREFER|SF_OBSOLETE|SF_USER)
  11078. +
  11079. +enum pkg_state_status
  11080. +{
  11081. + SS_NOT_INSTALLED = 1,
  11082. + SS_UNPACKED,
  11083. + SS_HALF_CONFIGURED,
  11084. + SS_INSTALLED,
  11085. + SS_HALF_INSTALLED,
  11086. + SS_CONFIG_FILES,
  11087. + SS_POST_INST_FAILED,
  11088. + SS_REMOVAL_FAILED,
  11089. + SS_LAST_STATE_STATUS
  11090. +};
  11091. +typedef enum pkg_state_status pkg_state_status_t;
  11092. +
  11093. +struct abstract_pkg{
  11094. + char * name;
  11095. + int dependencies_checked;
  11096. + pkg_vec_t * pkgs;
  11097. + pkg_state_status_t state_status;
  11098. + pkg_state_flag_t state_flag;
  11099. + struct abstract_pkg ** depended_upon_by; /* @@@@ this should be abstract_pkg_vec_t -Jamey */
  11100. + abstract_pkg_vec_t * provided_by;
  11101. + abstract_pkg_vec_t * replaced_by;
  11102. +};
  11103. +
  11104. +#include "pkg_depends.h"
  11105. +
  11106. +/* XXX: CLEANUP: I'd like to clean up pkg_t in several ways:
  11107. +
  11108. + The 3 version fields should go into a single version struct. (This
  11109. + is especially important since, currently, pkg->version can easily
  11110. + be mistaken for pkg_verson_str_alloc(pkg) although they are very
  11111. + distinct. This has been the source of multiple bugs.
  11112. +
  11113. + The 3 state fields could possibly also go into their own struct.
  11114. +
  11115. + All fields which deal with lists of packages, (Depends,
  11116. + Pre-Depends, Provides, Suggests, Recommends, Enhances), should each
  11117. + be handled by a single struct in pkg_t
  11118. +
  11119. + All string fields for which there is a small set of possible
  11120. + values, (section, maintainer, architecture, maybe version?), that
  11121. + are reused among different packages -- for all such packages we
  11122. + should move from "char *"s to some atom datatype to share data
  11123. + storage and use less memory. We might even do reference counting,
  11124. + but probably not since most often we only create new pkg_t structs,
  11125. + we don't often free them. */
  11126. +struct pkg
  11127. +{
  11128. + char *name;
  11129. + unsigned long epoch;
  11130. + char *version;
  11131. + char *revision;
  11132. + char *familiar_revision;
  11133. + pkg_src_t *src;
  11134. + pkg_dest_t *dest;
  11135. + char *architecture;
  11136. + char *section;
  11137. + char *maintainer;
  11138. + char *description;
  11139. + pkg_state_want_t state_want;
  11140. + pkg_state_flag_t state_flag;
  11141. + pkg_state_status_t state_status;
  11142. + char **depends_str;
  11143. + int depends_count;
  11144. + char **pre_depends_str;
  11145. + int pre_depends_count;
  11146. + char **recommends_str;
  11147. + int recommends_count;
  11148. + char **suggests_str;
  11149. + int suggests_count;
  11150. + compound_depend_t * depends;
  11151. +
  11152. + /* Abhaya: new conflicts */
  11153. + char **conflicts_str;
  11154. + compound_depend_t * conflicts;
  11155. + int conflicts_count;
  11156. +
  11157. + char **replaces_str;
  11158. + int replaces_count;
  11159. + abstract_pkg_t ** replaces;
  11160. +
  11161. + char **provides_str;
  11162. + int provides_count;
  11163. + abstract_pkg_t ** provides;
  11164. +
  11165. + abstract_pkg_t *parent;
  11166. +
  11167. + pkg_t *old_pkg; /* during upgrade, points from installee to previously installed */
  11168. +
  11169. + char *filename;
  11170. + char *local_filename;
  11171. + char *url;
  11172. + char *tmp_unpack_dir;
  11173. + char *md5sum;
  11174. + char *size;
  11175. + char *installed_size;
  11176. + char *priority;
  11177. + char *source;
  11178. + conffile_list_t conffiles;
  11179. + time_t installed_time;
  11180. + /* As pointer for lazy evaluation */
  11181. + str_list_t *installed_files;
  11182. + /* XXX: CLEANUP: I'd like to perhaps come up with a better
  11183. + mechanism to avoid the problem here, (which is that the
  11184. + installed_files list was being freed from an inner loop while
  11185. + still being used within an outer loop. */
  11186. + int installed_files_ref_cnt;
  11187. + int essential;
  11188. + int arch_priority;
  11189. +/* Adding this flag, to "force" ipkg to choose a "provided_by_hand" package, if there are multiple choice */
  11190. + int provided_by_hand;
  11191. +};
  11192. +
  11193. +pkg_t *pkg_new(void);
  11194. +int pkg_init(pkg_t *pkg);
  11195. +void pkg_deinit(pkg_t *pkg);
  11196. +int pkg_init_from_file(pkg_t *pkg, const char *filename);
  11197. +abstract_pkg_t *abstract_pkg_new(void);
  11198. +int abstract_pkg_init(abstract_pkg_t *ab_pkg);
  11199. +
  11200. +/*
  11201. + * merges fields from newpkg into oldpkg.
  11202. + * Forcibly sets oldpkg state_status, state_want and state_flags if set_status is nonzero
  11203. + */
  11204. +int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status);
  11205. +
  11206. +char *pkg_version_str_alloc(pkg_t *pkg);
  11207. +
  11208. +int pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg);
  11209. +int pkg_name_version_and_architecture_compare(pkg_t *a, pkg_t *b);
  11210. +int abstract_pkg_name_compare(abstract_pkg_t *a, abstract_pkg_t *b);
  11211. +
  11212. +char * pkg_formatted_info(pkg_t *pkg );
  11213. +char * pkg_formatted_field(pkg_t *pkg, const char *field );
  11214. +
  11215. +void set_flags_from_control(ipkg_conf_t *conf, pkg_t *pkg);
  11216. +
  11217. +void pkg_print_info(pkg_t *pkg, FILE *file);
  11218. +void pkg_print_status(pkg_t * pkg, FILE * file);
  11219. +void pkg_print_field(pkg_t *pkg, FILE *file, const char *field);
  11220. +str_list_t *pkg_get_installed_files(pkg_t *pkg);
  11221. +int pkg_free_installed_files(pkg_t *pkg);
  11222. +int pkg_remove_installed_files_list(ipkg_conf_t *conf, pkg_t *pkg);
  11223. +conffile_t *pkg_get_conffile(pkg_t *pkg, const char *file_name);
  11224. +int pkg_run_script(struct ipkg_conf *conf, pkg_t *pkg,
  11225. + const char *script, const char *args);
  11226. +
  11227. +/* enum mappings */
  11228. +char *pkg_state_want_to_str(pkg_state_want_t sw);
  11229. +pkg_state_want_t pkg_state_want_from_str(char *str);
  11230. +char *pkg_state_flag_to_str(pkg_state_flag_t sf);
  11231. +pkg_state_flag_t pkg_state_flag_from_str(char *str);
  11232. +char *pkg_state_status_to_str(pkg_state_status_t ss);
  11233. +pkg_state_status_t pkg_state_status_from_str(char *str);
  11234. +
  11235. +int pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op);
  11236. +
  11237. +int pkg_arch_supported(ipkg_conf_t *conf, pkg_t *pkg);
  11238. +int pkg_info_preinstall_check(ipkg_conf_t *conf);
  11239. +int pkg_free_installed_files(pkg_t *pkg);
  11240. +
  11241. +int pkg_write_filelist(ipkg_conf_t *conf, pkg_t *pkg);
  11242. +int pkg_write_changed_filelists(ipkg_conf_t *conf);
  11243. +
  11244. +#endif
  11245. diff -Nur busybox-1.12.1.orig/archival/libipkg/pkg_hash.c busybox-1.12.1/archival/libipkg/pkg_hash.c
  11246. --- busybox-1.12.1.orig/archival/libipkg/pkg_hash.c 1970-01-01 01:00:00.000000000 +0100
  11247. +++ busybox-1.12.1/archival/libipkg/pkg_hash.c 2008-10-23 16:21:09.000000000 +0200
  11248. @@ -0,0 +1,623 @@
  11249. +/* ipkg_hash.c - the itsy package management system
  11250. +
  11251. + Steven M. Ayer
  11252. +
  11253. + Copyright (C) 2002 Compaq Computer Corporation
  11254. +
  11255. + This program is free software; you can redistribute it and/or
  11256. + modify it under the terms of the GNU General Public License as
  11257. + published by the Free Software Foundation; either version 2, or (at
  11258. + your option) any later version.
  11259. +
  11260. + This program is distributed in the hope that it will be useful, but
  11261. + WITHOUT ANY WARRANTY; without even the implied warranty of
  11262. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11263. + General Public License for more details.
  11264. +*/
  11265. +
  11266. +#include "ipkg.h"
  11267. +#include <errno.h>
  11268. +#include <ctype.h>
  11269. +#include <stdlib.h>
  11270. +#include <string.h>
  11271. +
  11272. +#include "hash_table.h"
  11273. +#include "pkg.h"
  11274. +#include "ipkg_message.h"
  11275. +#include "pkg_vec.h"
  11276. +#include "pkg_hash.h"
  11277. +#include "pkg_parse.h"
  11278. +#include "ipkg_utils.h"
  11279. +
  11280. +static abstract_pkg_t * add_new_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name);
  11281. +
  11282. +/*
  11283. + * this will talk to both feeds-lists files and installed status files
  11284. + * example api:
  11285. + *
  11286. + * hash_table_t hash;
  11287. + * pkg_hash_init(name, &hash, 1000);
  11288. + * pkg_hash_add_from_file(<feed filename>);
  11289. + *
  11290. + * the query function is just there as a shell to prove to me that this
  11291. + * sort of works, but isn't far from doing something useful
  11292. + *
  11293. + * -sma, 12/21/01
  11294. + * modified: CDW 3 Jan. 2002
  11295. + */
  11296. +
  11297. +
  11298. +
  11299. +int pkg_hash_init(const char *name, hash_table_t *hash, int len)
  11300. +{
  11301. + return hash_table_init(name, hash, len);
  11302. +}
  11303. +
  11304. +void pkg_hash_deinit(hash_table_t *hash)
  11305. +{
  11306. + hash_table_deinit(hash);
  11307. +}
  11308. +
  11309. +
  11310. +/* Find the default arch for a given package status file if none is given. */
  11311. +static char *pkg_get_default_arch(ipkg_conf_t *conf)
  11312. +{
  11313. + nv_pair_list_elt_t *l;
  11314. + const char *def_arch = HOST_CPU_STR; /* Default arch */
  11315. + int def_prio = 0; /* Other archs override this */
  11316. +
  11317. + l = conf->arch_list.head;
  11318. +
  11319. + while (l) {
  11320. + nv_pair_t *nv = l->data;
  11321. + int priority = strtol(nv->value, NULL, 0);
  11322. +
  11323. + /* Check if this arch has higher priority, and is valid */
  11324. + if ((priority > def_prio) &&
  11325. + (strcmp(nv->name, "all")) && (strcmp(nv->name, "noarch"))) {
  11326. + /* Our new default */
  11327. + def_prio = priority;
  11328. + def_arch = nv->name;
  11329. + }
  11330. + l = l->next;
  11331. + }
  11332. +
  11333. + return strdup(def_arch);
  11334. +}
  11335. +
  11336. +int pkg_hash_add_from_file(ipkg_conf_t *conf, const char *file_name,
  11337. + pkg_src_t *src, pkg_dest_t *dest, int is_status_file)
  11338. +{
  11339. + hash_table_t *hash = &conf->pkg_hash;
  11340. + char **raw;
  11341. + char **raw_start;
  11342. + pkg_t *pkg;
  11343. +
  11344. + raw = raw_start = read_raw_pkgs_from_file(file_name);
  11345. + if (!raw)
  11346. + return -ENOMEM;
  11347. +
  11348. + while(*raw){ /* don't worry, we'll increment raw in the parsing function */
  11349. + pkg = pkg_new();
  11350. + if (!pkg)
  11351. + return -ENOMEM;
  11352. +
  11353. + if (pkg_parse_raw(pkg, &raw, src, dest) == 0) {
  11354. + if (!pkg->architecture) {
  11355. + char *version_str = pkg_version_str_alloc(pkg);
  11356. + pkg->architecture = pkg_get_default_arch(conf);
  11357. + ipkg_message(conf, IPKG_ERROR, "Package %s version %s has no architecture specified, defaulting to %s.\n",
  11358. + pkg->name, version_str, pkg->architecture);
  11359. + free(version_str);
  11360. + }
  11361. + hash_insert_pkg(hash, pkg, is_status_file,conf);
  11362. + } else {
  11363. + free(pkg);
  11364. + }
  11365. + }
  11366. +
  11367. + /* XXX: CLEANUP: I'd like a cleaner interface for cleaning up
  11368. + memory after read_raw_pkgs_from_file */
  11369. + raw = raw_start;
  11370. + while (*raw) {
  11371. + free(*raw++);
  11372. + }
  11373. + free(raw_start);
  11374. + return 0;
  11375. +}
  11376. +
  11377. +abstract_pkg_t * abstract_pkg_fetch_by_name(hash_table_t * hash, const char * pkg_name)
  11378. +{
  11379. + return (abstract_pkg_t *)hash_table_get(hash, pkg_name);
  11380. +}
  11381. +
  11382. +abstract_pkg_vec_t *pkg_hash_fetch_all_installation_candidates(hash_table_t *hash, const char *name)
  11383. +{
  11384. + abstract_pkg_t *apkg = abstract_pkg_fetch_by_name(hash, name);
  11385. + if (apkg)
  11386. + return NULL;
  11387. + return apkg->provided_by;
  11388. +}
  11389. +
  11390. +
  11391. +pkg_t *pkg_hash_fetch_best_installation_candidate(ipkg_conf_t *conf, abstract_pkg_t *apkg,
  11392. + int (*constraint_fcn)(pkg_t *pkg, void *cdata), void *cdata, int quiet)
  11393. +{
  11394. + int i;
  11395. + int nprovides = 0;
  11396. + int nmatching = 0;
  11397. + pkg_vec_t *matching_pkgs = pkg_vec_alloc();
  11398. + abstract_pkg_vec_t *matching_apkgs = abstract_pkg_vec_alloc();
  11399. + abstract_pkg_vec_t *provided_apkg_vec;
  11400. + abstract_pkg_t **provided_apkgs;
  11401. + abstract_pkg_vec_t *providers = abstract_pkg_vec_alloc();
  11402. + pkg_t *latest_installed_parent = NULL;
  11403. + pkg_t *latest_matching = NULL;
  11404. + pkg_t *held_pkg = NULL;
  11405. + pkg_t *good_pkg_by_name = NULL;
  11406. +
  11407. + if (matching_apkgs == NULL || providers == NULL ||
  11408. + apkg == NULL || apkg->provided_by == NULL || (apkg->provided_by->len == 0))
  11409. + return NULL;
  11410. +
  11411. + ipkg_message(conf, IPKG_DEBUG, "best installation candidate for %s\n", apkg->name);
  11412. +
  11413. + provided_apkg_vec = apkg->provided_by;
  11414. + nprovides = provided_apkg_vec->len;
  11415. + provided_apkgs = provided_apkg_vec->pkgs;
  11416. + if (nprovides > 1)
  11417. + ipkg_message(conf, IPKG_DEBUG, " apkg=%s nprovides=%d\n", apkg->name, nprovides);
  11418. +
  11419. + /* accumulate all the providers */
  11420. + for (i = 0; i < nprovides; i++) {
  11421. + abstract_pkg_t *provider_apkg = provided_apkgs[i];
  11422. + ipkg_message(conf, IPKG_DEBUG, " adding %s to providers\n", provider_apkg->name);
  11423. + abstract_pkg_vec_insert(providers, provider_apkg);
  11424. + }
  11425. + nprovides = providers->len;
  11426. +
  11427. + for (i = 0; i < nprovides; i++) {
  11428. + abstract_pkg_t *provider_apkg = abstract_pkg_vec_get(providers, i);
  11429. + abstract_pkg_t *replacement_apkg = NULL;
  11430. + pkg_vec_t *vec;
  11431. +
  11432. + if (provider_apkg->replaced_by && provider_apkg->replaced_by->len) {
  11433. + replacement_apkg = provider_apkg->replaced_by->pkgs[0];
  11434. + if (provider_apkg->replaced_by->len > 1) {
  11435. + ipkg_message(conf, IPKG_NOTICE, "Multiple replacers for %s, using first one (%s)\n",
  11436. + provider_apkg->name, replacement_apkg->name);
  11437. + }
  11438. + }
  11439. +
  11440. + if (replacement_apkg)
  11441. + ipkg_message(conf, IPKG_DEBUG, " replacement_apkg=%s for provider_apkg=%s\n",
  11442. + replacement_apkg->name, provider_apkg->name);
  11443. +
  11444. + if (replacement_apkg && (replacement_apkg != provider_apkg)) {
  11445. + if (abstract_pkg_vec_contains(providers, replacement_apkg))
  11446. + continue;
  11447. + else
  11448. + provider_apkg = replacement_apkg;
  11449. + }
  11450. +
  11451. + if (!(vec = provider_apkg->pkgs)) {
  11452. + ipkg_message(conf, IPKG_DEBUG, " no pkgs for provider_apkg %s\n", provider_apkg->name);
  11453. + continue;
  11454. + }
  11455. +
  11456. +
  11457. + /* now check for supported architecture */
  11458. + {
  11459. + int max_count = 0;
  11460. + int j;
  11461. +
  11462. + /* count packages matching max arch priority and keep track of last one */
  11463. + for (j = 0; j < vec->len; j++) {
  11464. + pkg_t *maybe = vec->pkgs[j];
  11465. + ipkg_message(conf, IPKG_DEBUG, " %s arch=%s arch_priority=%d version=%s \n",
  11466. + maybe->name, maybe->architecture, maybe->arch_priority, maybe->version);
  11467. + if (maybe->arch_priority > 0) {
  11468. + max_count++;
  11469. + abstract_pkg_vec_insert(matching_apkgs, maybe->parent);
  11470. + pkg_vec_insert(matching_pkgs, maybe);
  11471. + }
  11472. + }
  11473. + }
  11474. + }
  11475. +
  11476. + if (matching_pkgs->len > 1)
  11477. + pkg_vec_sort(matching_pkgs, pkg_name_version_and_architecture_compare);
  11478. + if (matching_apkgs->len > 1)
  11479. + abstract_pkg_vec_sort(matching_pkgs, abstract_pkg_name_compare);
  11480. +
  11481. +/* Here it is usefull, if ( matching_apkgs->len > 1 ), to test if one of this matching packages has the same name of the
  11482. + needed package. In this case, I would return it for install, otherwise I will continue with the procedure */
  11483. +/* The problem is what to do when there are more than a mathing package, with the same name and several version ?
  11484. + Until now I always got the latest, but that breaks the downgrade option.
  11485. + If I stop at the first one, I would probably miss the new ones
  11486. + Maybe the way is to have some kind of flag somewhere, to see if the package been asked to install is from a file,
  11487. + or from a Packages feed.
  11488. + 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*/
  11489. +/*Pigi*/
  11490. +
  11491. + for (i = 0; i < matching_pkgs->len; i++) {
  11492. + pkg_t *matching = matching_pkgs->pkgs[i];
  11493. + if (constraint_fcn(matching, cdata)) { /* We found it */
  11494. + ipkg_message(conf, IPKG_DEBUG, " Found a valid candidate for the install: %s %s \n", matching->name, matching->version) ;
  11495. + good_pkg_by_name = matching;
  11496. + if ( matching->provided_by_hand == 1 ) /* It has been provided by hand, so it is what user want */
  11497. + break;
  11498. + }
  11499. + }
  11500. +
  11501. +
  11502. + for (i = 0; i < matching_pkgs->len; i++) {
  11503. + pkg_t *matching = matching_pkgs->pkgs[i];
  11504. + latest_matching = matching;
  11505. + if (matching->parent->state_status == SS_INSTALLED || matching->parent->state_status == SS_UNPACKED)
  11506. + latest_installed_parent = matching;
  11507. + if (matching->state_flag & (SF_HOLD|SF_PREFER)) {
  11508. + if (held_pkg)
  11509. + ipkg_message(conf, IPKG_ERROR, "Multiple packages (%s and %s) providing same name marked HOLD or PREFER. Using latest.\n",
  11510. + held_pkg->name, matching->name);
  11511. + held_pkg = matching;
  11512. + }
  11513. + }
  11514. +
  11515. + if (!good_pkg_by_name && !held_pkg && !latest_installed_parent && matching_apkgs->len > 1 && !quiet) {
  11516. + ipkg_message(conf, IPKG_ERROR, "Package=%s, %d matching providers\n",
  11517. + apkg->name, matching_apkgs->len);
  11518. + for (i = 0; i < matching_apkgs->len; i++) {
  11519. + abstract_pkg_t *matching = matching_apkgs->pkgs[i];
  11520. + ipkg_message(conf, IPKG_ERROR, " %s\n", matching->name);
  11521. + }
  11522. + ipkg_message(conf, IPKG_ERROR, "Please select one with ipkg install or ipkg flag prefer\n");
  11523. + }
  11524. +
  11525. + if (matching_apkgs->len > 1 && conf->verbosity > 1) {
  11526. + ipkg_message(conf, IPKG_NOTICE, "%s: for apkg=%s, %d matching pkgs\n",
  11527. + __FUNCTION__, apkg->name, matching_pkgs->len);
  11528. + for (i = 0; i < matching_pkgs->len; i++) {
  11529. + pkg_t *matching = matching_pkgs->pkgs[i];
  11530. + ipkg_message(conf, IPKG_INFO, " %s %s %s\n",
  11531. + matching->name, matching->version, matching->architecture);
  11532. + }
  11533. + }
  11534. +
  11535. + nmatching = matching_apkgs->len;
  11536. +
  11537. + pkg_vec_free(matching_pkgs);
  11538. + abstract_pkg_vec_free(matching_apkgs);
  11539. + abstract_pkg_vec_free(providers);
  11540. +
  11541. + if (good_pkg_by_name) { /* We found a good candidate, we will install it */
  11542. + return good_pkg_by_name;
  11543. + }
  11544. + if (held_pkg) {
  11545. + ipkg_message(conf, IPKG_INFO, " using held package %s\n", held_pkg->name);
  11546. + return held_pkg;
  11547. + }
  11548. + if (latest_installed_parent) {
  11549. + ipkg_message(conf, IPKG_INFO, " using latest version of installed package %s\n", latest_installed_parent->name);
  11550. + return latest_installed_parent;
  11551. + }
  11552. + if (nmatching > 1) {
  11553. + ipkg_message(conf, IPKG_INFO, " no matching pkg out of matching_apkgs=%d\n", nmatching);
  11554. + return NULL;
  11555. + }
  11556. + if (latest_matching) {
  11557. + ipkg_message(conf, IPKG_INFO, " using latest matching %s %s %s\n",
  11558. + latest_matching->name, latest_matching->version, latest_matching->architecture);
  11559. + return latest_matching;
  11560. + }
  11561. + return NULL;
  11562. +}
  11563. +
  11564. +static int pkg_name_constraint_fcn(pkg_t *pkg, void *cdata)
  11565. +{
  11566. + const char *name = (const char *)cdata;
  11567. + if (strcmp(pkg->name, name) == 0)
  11568. + return 1;
  11569. + else
  11570. + return 0;
  11571. +}
  11572. +
  11573. +pkg_t *pkg_hash_fetch_best_installation_candidate_by_name(ipkg_conf_t *conf, const char *name)
  11574. +{
  11575. + hash_table_t *hash = &conf->pkg_hash;
  11576. + abstract_pkg_t *apkg = NULL;
  11577. +
  11578. + if (!(apkg = abstract_pkg_fetch_by_name(hash, name)))
  11579. + return NULL;
  11580. +
  11581. + return pkg_hash_fetch_best_installation_candidate(conf, apkg, pkg_name_constraint_fcn, apkg->name, 0);
  11582. +}
  11583. +
  11584. +
  11585. +pkg_t * pkg_hash_fetch_by_name_version(hash_table_t *hash,
  11586. + const char *pkg_name,
  11587. + const char * version)
  11588. +{
  11589. + pkg_vec_t * vec;
  11590. + register int i;
  11591. + char *version_str = NULL;
  11592. +
  11593. + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name)))
  11594. + return NULL;
  11595. +
  11596. + for(i = 0; i < vec->len; i++) {
  11597. + version_str = pkg_version_str_alloc(vec->pkgs[i]);
  11598. + if(!strcmp(version_str, version)) {
  11599. + free(version_str);
  11600. + break;
  11601. + }
  11602. + free(version_str);
  11603. + }
  11604. +
  11605. + if(i == vec->len)
  11606. + return NULL;
  11607. +
  11608. + return vec->pkgs[i];
  11609. +}
  11610. +
  11611. +pkg_t *pkg_hash_fetch_installed_by_name_dest(hash_table_t *hash,
  11612. + const char *pkg_name,
  11613. + pkg_dest_t *dest)
  11614. +{
  11615. + pkg_vec_t * vec;
  11616. + register int i;
  11617. +
  11618. + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name))) {
  11619. + return NULL;
  11620. + }
  11621. +
  11622. + for(i = 0; i < vec->len; i++)
  11623. + if((vec->pkgs[i]->state_status == SS_INSTALLED || vec->pkgs[i]->state_status == SS_UNPACKED) && vec->pkgs[i]->dest == dest) {
  11624. + return vec->pkgs[i];
  11625. + }
  11626. + return NULL;
  11627. +}
  11628. +
  11629. +pkg_t *pkg_hash_fetch_installed_by_name(hash_table_t *hash,
  11630. + const char *pkg_name)
  11631. +{
  11632. + pkg_vec_t * vec;
  11633. + register int i;
  11634. +
  11635. + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name))){
  11636. + return NULL;
  11637. + }
  11638. +
  11639. + for(i = 0; i < vec->len; i++)
  11640. + if (vec->pkgs[i]->state_status == SS_INSTALLED || vec->pkgs[i]->state_status == SS_UNPACKED){
  11641. + return vec->pkgs[i];
  11642. + }
  11643. +
  11644. + return NULL;
  11645. +}
  11646. +
  11647. +pkg_vec_t *pkg_vec_fetch_by_name(hash_table_t *hash, const char *pkg_name)
  11648. +{
  11649. + abstract_pkg_t * ab_pkg;
  11650. +
  11651. + if(!(ab_pkg = abstract_pkg_fetch_by_name(hash, pkg_name))){
  11652. + return NULL;
  11653. + }
  11654. +
  11655. + if (ab_pkg->pkgs) {
  11656. + return ab_pkg->pkgs;
  11657. + } else if (ab_pkg->provided_by) {
  11658. + abstract_pkg_t *abpkg = abstract_pkg_vec_get(ab_pkg->provided_by, 0);
  11659. + if (abpkg != NULL){
  11660. + return abpkg->pkgs;
  11661. + } else {
  11662. + return ab_pkg->pkgs;
  11663. + }
  11664. + } else {
  11665. + return NULL;
  11666. + }
  11667. +}
  11668. +
  11669. +static int pkg_compare_names(const void *p1, const void *p2)
  11670. +{
  11671. + const pkg_t *pkg1 = *(const pkg_t **)p1;
  11672. + const pkg_t *pkg2 = *(const pkg_t **)p2;
  11673. + if (pkg1->name == NULL)
  11674. + return 1;
  11675. + if (pkg2->name == NULL)
  11676. + return -1;
  11677. + return(strcmp(pkg1->name, pkg2->name));
  11678. +}
  11679. +
  11680. +
  11681. +static void pkg_hash_fetch_available_helper(const char *pkg_name, void *entry, void *data)
  11682. +{
  11683. + int j;
  11684. + const char *name;
  11685. + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
  11686. + pkg_vec_t *all = (pkg_vec_t *)data;
  11687. + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
  11688. + name = pkg_name;
  11689. + if (pkg_vec) {
  11690. + for (j = 0; j < pkg_vec->len; j++) {
  11691. + pkg_t *pkg = pkg_vec->pkgs[j];
  11692. + pkg_vec_insert(all, pkg);
  11693. + }
  11694. + }
  11695. +}
  11696. +
  11697. +void pkg_hash_fetch_available(hash_table_t *hash, pkg_vec_t *all)
  11698. +{
  11699. + hash_table_foreach(hash, pkg_hash_fetch_available_helper, all);
  11700. + qsort(all->pkgs, all->len, sizeof(pkg_t *), pkg_compare_names);
  11701. +}
  11702. +
  11703. +static void pkg_hash_fetch_all_installed_helper(const char *pkg_name, void *entry, void *data)
  11704. +{
  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. + int j;
  11710. + name = pkg_name;
  11711. + if (pkg_vec) {
  11712. + for (j = 0; j < pkg_vec->len; j++) {
  11713. + pkg_t *pkg = pkg_vec->pkgs[j];
  11714. + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) {
  11715. + pkg_vec_insert(all, pkg);
  11716. + }
  11717. + }
  11718. + }
  11719. +}
  11720. +void pkg_hash_fetch_all_installed(hash_table_t *hash, pkg_vec_t *all)
  11721. +{
  11722. + hash_table_foreach(hash, pkg_hash_fetch_all_installed_helper, all);
  11723. + qsort(all->pkgs, all->len, sizeof(void*), pkg_compare_names);
  11724. +}
  11725. +
  11726. +static void pkg_hash_dump_helper(const char *pkg_name, void *entry, void *data)
  11727. +{
  11728. + int i;
  11729. + pkg_t *pkg;
  11730. + const char *name;
  11731. + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
  11732. + ipkg_conf_t *conf = (ipkg_conf_t *)data;
  11733. + abstract_pkg_t ** dependents = ab_pkg->depended_upon_by;
  11734. + name = pkg_name;
  11735. + fprintf(stdout, "%s\n", ab_pkg->name);
  11736. + i = 0;
  11737. + if (dependents != NULL)
  11738. + while (dependents [i] != NULL)
  11739. + printf ("\tdepended upon by - %s\n", dependents [i ++]->name);
  11740. + dependents = ab_pkg->provided_by->pkgs;
  11741. + i = 0;
  11742. + if (dependents != NULL)
  11743. + while (dependents [i] != NULL && i < ab_pkg->provided_by->len)
  11744. + printf ("\tprovided by - %s\n", dependents [i ++]->name);
  11745. + pkg = pkg_hash_fetch_best_installation_candidate_by_name (conf, ab_pkg->name);
  11746. + if (pkg) {
  11747. + i = 0;
  11748. + while (i < pkg->depends_count)
  11749. + printf ("\tdepends on - %s\n", pkg->depends_str [i ++]);
  11750. + }
  11751. +}
  11752. +void pkg_hash_dump(hash_table_t *hash, void *data)
  11753. +{
  11754. +
  11755. + printf ("\n\n+=+%s+=+\n\n", __FUNCTION__);
  11756. + hash_table_foreach(hash, pkg_hash_dump_helper, data);
  11757. + printf ("\n+=+%s+=+\n\n", __FUNCTION__);
  11758. +}
  11759. +
  11760. +abstract_pkg_t * ensure_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name)
  11761. +{
  11762. + abstract_pkg_t * ab_pkg;
  11763. +
  11764. + if(!(ab_pkg = abstract_pkg_fetch_by_name(hash, pkg_name)))
  11765. + ab_pkg = add_new_abstract_pkg_by_name(hash, pkg_name);
  11766. +
  11767. + return ab_pkg;
  11768. +}
  11769. +
  11770. +pkg_t *hash_insert_pkg(hash_table_t *hash, pkg_t *pkg, int set_status,ipkg_conf_t *conf)
  11771. +{
  11772. + abstract_pkg_t * ab_pkg;
  11773. + int arch_priority;
  11774. +
  11775. + if(!pkg)
  11776. + return pkg;
  11777. +
  11778. + arch_priority = pkg->arch_priority;
  11779. +
  11780. + if (buildDepends(hash, pkg)<0){
  11781. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  11782. + return NULL;
  11783. + }
  11784. + ab_pkg = ensure_abstract_pkg_by_name(hash, pkg->name);
  11785. +
  11786. + if (set_status) {
  11787. + if (pkg->state_status == SS_INSTALLED) {
  11788. + ab_pkg->state_status = SS_INSTALLED;
  11789. + } else if (pkg->state_status == SS_UNPACKED) {
  11790. + ab_pkg->state_status = SS_UNPACKED;
  11791. + }
  11792. + }
  11793. +
  11794. + if(!ab_pkg->pkgs)
  11795. + ab_pkg->pkgs = pkg_vec_alloc();
  11796. +
  11797. + /* pkg_vec_insert_merge might munge package, but it returns an unmunged pkg */
  11798. + pkg = pkg_vec_insert_merge(ab_pkg->pkgs, pkg, set_status,conf );
  11799. + pkg->parent = ab_pkg;
  11800. +
  11801. + if (buildProvides(hash, ab_pkg, pkg)<0){
  11802. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  11803. + return NULL;
  11804. + }
  11805. + /* need to build the conflicts graph before replaces for correct calculation of replaced_by relation */
  11806. + if (buildConflicts(hash, pkg)<0){
  11807. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  11808. + return NULL;
  11809. + }
  11810. + if (buildReplaces(hash, ab_pkg, pkg)<0) {
  11811. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  11812. + return NULL;
  11813. + }
  11814. +
  11815. + buildDependedUponBy(pkg, ab_pkg);
  11816. + return pkg;
  11817. +}
  11818. +
  11819. +/*
  11820. + * this will assume that we've already determined that
  11821. + * the abstract pkg doesn't exist, 'cause we should know these things...
  11822. + */
  11823. +static abstract_pkg_t * add_new_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name)
  11824. +{
  11825. + abstract_pkg_t * ab_pkg;
  11826. +
  11827. + ab_pkg = abstract_pkg_new();
  11828. + if (ab_pkg == NULL) { return NULL; }
  11829. +
  11830. + ab_pkg->name = strdup(pkg_name);
  11831. + hash_table_insert(hash, pkg_name, ab_pkg);
  11832. +
  11833. + return ab_pkg;
  11834. +}
  11835. +
  11836. +
  11837. +pkg_t *file_hash_get_file_owner(ipkg_conf_t *conf, const char *file_name)
  11838. +{
  11839. + hash_table_t *file_hash = &conf->file_hash;
  11840. +
  11841. + return hash_table_get(file_hash, file_name);
  11842. +}
  11843. +
  11844. +int file_hash_set_file_owner(ipkg_conf_t *conf, const char *file_name, pkg_t *owning_pkg)
  11845. +{
  11846. + hash_table_t *file_hash = &conf->file_hash;
  11847. + pkg_t *old_owning_pkg = hash_table_get(file_hash, file_name);
  11848. + int file_name_len = strlen(file_name);
  11849. +
  11850. + if (file_name[file_name_len -1] == '/')
  11851. + return 0;
  11852. +
  11853. + if (conf->offline_root) {
  11854. + int len = strlen(conf->offline_root);
  11855. + if (strncmp(file_name, conf->offline_root, len) == 0) {
  11856. + file_name += len;
  11857. + }
  11858. + }
  11859. +
  11860. + // ipkg_message(conf, IPKG_DEBUG2, "owning_pkg=%s filename=%s\n", owning_pkg->name, file_name);
  11861. + hash_table_insert(file_hash, file_name, owning_pkg);
  11862. + if (old_owning_pkg) {
  11863. + str_list_remove_elt(old_owning_pkg->installed_files, file_name);
  11864. + /* mark this package to have its filelist written */
  11865. + old_owning_pkg->state_flag |= SF_FILELIST_CHANGED;
  11866. + owning_pkg->state_flag |= SF_FILELIST_CHANGED;
  11867. + }
  11868. + return 0;
  11869. +}
  11870. +
  11871. +
  11872. diff -Nur busybox-1.12.1.orig/archival/libipkg/pkg_hash.h busybox-1.12.1/archival/libipkg/pkg_hash.h
  11873. --- busybox-1.12.1.orig/archival/libipkg/pkg_hash.h 1970-01-01 01:00:00.000000000 +0100
  11874. +++ busybox-1.12.1/archival/libipkg/pkg_hash.h 2008-10-23 11:41:37.000000000 +0200
  11875. @@ -0,0 +1,61 @@
  11876. +/* pkg_hash.h - the itsy package management system
  11877. +
  11878. + Steven M. Ayer
  11879. +
  11880. + Copyright (C) 2002 Compaq Computer Corporation
  11881. +
  11882. + This program is free software; you can redistribute it and/or
  11883. + modify it under the terms of the GNU General Public License as
  11884. + published by the Free Software Foundation; either version 2, or (at
  11885. + your option) any later version.
  11886. +
  11887. + This program is distributed in the hope that it will be useful, but
  11888. + WITHOUT ANY WARRANTY; without even the implied warranty of
  11889. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11890. + General Public License for more details.
  11891. +*/
  11892. +
  11893. +#ifndef PKG_HASH_H
  11894. +#define PKG_HASH_H
  11895. +
  11896. +#include "pkg.h"
  11897. +#include "pkg_vec.h"
  11898. +#include "hash_table.h"
  11899. +
  11900. +
  11901. +int pkg_hash_init(const char *name, hash_table_t *hash, int len);
  11902. +void pkg_hash_deinit(hash_table_t *hash);
  11903. +void pkg_hash_map(hash_table_t *hash, void (*f)(void *data, void *entry), void *data);
  11904. +
  11905. +void pkg_hash_dump(hash_table_t *hash, void *data);
  11906. +void pkg_hash_fetch_available(hash_table_t *hash, pkg_vec_t *available);
  11907. +
  11908. +int pkg_hash_add_from_file(ipkg_conf_t *conf, const char *file_name,
  11909. + pkg_src_t *src, pkg_dest_t *dest, int is_status_file);
  11910. +pkg_t *hash_insert_pkg(hash_table_t *hash, pkg_t *pkg, int set_status,ipkg_conf_t *conf);
  11911. +
  11912. +abstract_pkg_t * ensure_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name);
  11913. +abstract_pkg_t * abstract_pkg_fetch_by_name(hash_table_t * hash, const char * pkg_name);
  11914. +pkg_vec_t *pkg_hash_fetch_by_name(hash_table_t *hash, const char *pkg_name);
  11915. +void pkg_hash_fetch_all_installed(hash_table_t *hash, pkg_vec_t *installed);
  11916. +pkg_t * pkg_hash_fetch_by_name_version(hash_table_t *hash,
  11917. + const char *pkg_name,
  11918. + const char * version);
  11919. +abstract_pkg_vec_t *pkg_hash_fetch_all_installation_candidates(hash_table_t *hash, const char *name);
  11920. +pkg_t *pkg_hash_fetch_best_installation_candidate(ipkg_conf_t *conf, abstract_pkg_t *apkg,
  11921. + int (*constraint_fcn)(pkg_t *pkg, void *data), void *cdata, int quiet);
  11922. +pkg_t *pkg_hash_fetch_best_installation_candidate_by_name(ipkg_conf_t *conf, const char *name);
  11923. +pkg_t *pkg_hash_fetch_installed_by_name(hash_table_t *hash,
  11924. + const char *pkg_name);
  11925. +pkg_t *pkg_hash_fetch_installed_by_name_dest(hash_table_t *hash,
  11926. + const char *pkg_name,
  11927. + pkg_dest_t *dest);
  11928. +
  11929. +pkg_t *file_hash_get_file_owner(ipkg_conf_t *conf, const char *file_name);
  11930. +int file_hash_set_file_owner(ipkg_conf_t *conf, const char *file_name, pkg_t *pkg);
  11931. +
  11932. +/* XXX: shouldn't this go in pkg_vec.[ch]? */
  11933. +pkg_vec_t *pkg_vec_fetch_by_name(hash_table_t *hash, const char *pkg_name);
  11934. +
  11935. +#endif
  11936. +
  11937. diff -Nur busybox-1.12.1.orig/archival/libipkg/pkg_parse.c busybox-1.12.1/archival/libipkg/pkg_parse.c
  11938. --- busybox-1.12.1.orig/archival/libipkg/pkg_parse.c 1970-01-01 01:00:00.000000000 +0100
  11939. +++ busybox-1.12.1/archival/libipkg/pkg_parse.c 2008-10-23 15:49:10.000000000 +0200
  11940. @@ -0,0 +1,368 @@
  11941. +/* pkg_parse.c - the itsy package management system
  11942. +
  11943. + Steven M. Ayer
  11944. +
  11945. + Copyright (C) 2002 Compaq Computer Corporation
  11946. +
  11947. + This program is free software; you can redistribute it and/or
  11948. + modify it under the terms of the GNU General Public License as
  11949. + published by the Free Software Foundation; either version 2, or (at
  11950. + your option) any later version.
  11951. +
  11952. + This program is distributed in the hope that it will be useful, but
  11953. + WITHOUT ANY WARRANTY; without even the implied warranty of
  11954. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11955. + General Public License for more details.
  11956. +*/
  11957. +
  11958. +#include "ipkg.h"
  11959. +#include <errno.h>
  11960. +#include <ctype.h>
  11961. +
  11962. +#include "pkg.h"
  11963. +#include "ipkg_utils.h"
  11964. +#include "pkg_parse.h"
  11965. +
  11966. +int alterProvidesLine(char *raw, char *temp);
  11967. +
  11968. +int isGenericFieldType(char * type, char * line)
  11969. +{
  11970. + if(!strncmp(line, type, strlen(type)))
  11971. + return 1;
  11972. + return 0;
  11973. +}
  11974. +
  11975. +char * parseGenericFieldType(char * type, char * raw)
  11976. +{
  11977. + char * field_value = raw + (strlen(type) + 1);
  11978. + return trim_alloc(field_value);
  11979. +}
  11980. +
  11981. +void parseStatus(pkg_t *pkg, char * raw)
  11982. +{
  11983. + char sw_str[64], sf_str[64], ss_str[64];
  11984. +
  11985. + sscanf(raw, "Status: %s %s %s", sw_str, sf_str, ss_str);
  11986. + pkg->state_want = pkg_state_want_from_str(sw_str);
  11987. + pkg->state_flag = pkg_state_flag_from_str(sf_str);
  11988. + pkg->state_status = pkg_state_status_from_str(ss_str);
  11989. +}
  11990. +
  11991. +char ** parseDependsString(char * raw, int * depends_count)
  11992. +{
  11993. + char ** depends = NULL;
  11994. + int line_count = 0;
  11995. + char buff[2048], * dest;
  11996. +
  11997. + while(raw && *raw && !isspace(*raw)) {
  11998. + raw++;
  11999. + }
  12000. +
  12001. + if(line_is_blank(raw)){
  12002. + *depends_count = line_count;
  12003. + return NULL;
  12004. + }
  12005. + while(raw && *raw){
  12006. + depends = (char **)realloc(depends, sizeof(char *) * (line_count + 1));
  12007. +
  12008. + while(isspace(*raw)) raw++;
  12009. +
  12010. + dest = buff;
  12011. + while((*raw != ',') && *raw)
  12012. + *dest++ = *raw++;
  12013. +
  12014. + *dest = '\0';
  12015. + depends[line_count] = trim_alloc(buff);
  12016. + if(depends[line_count] ==NULL)
  12017. + return NULL;
  12018. + line_count++;
  12019. + if(*raw == ',')
  12020. + raw++;
  12021. + }
  12022. + *depends_count = line_count;
  12023. + return depends;
  12024. +}
  12025. +
  12026. +void parseConffiles(pkg_t * pkg, char * raw)
  12027. +{
  12028. + char file_name[1048], md5sum[1048]; /* please tell me there aren't any longer that 1k */
  12029. +
  12030. + if(!strncmp(raw, "Conffiles:", 10))
  12031. + raw += strlen("Conffiles:");
  12032. +
  12033. + while(*raw && (sscanf(raw, "%s%s", file_name, md5sum) == 2)){
  12034. + conffile_list_append(&pkg->conffiles, file_name, md5sum);
  12035. + /* fprintf(stderr, "%s %s ", file_name, md5sum);*/
  12036. + while (*raw && isspace(*raw)) {
  12037. + raw++;
  12038. + }
  12039. + raw += strlen(file_name);
  12040. + while (*raw && isspace(*raw)) {
  12041. + raw++;
  12042. + }
  12043. + raw += strlen(md5sum);
  12044. + }
  12045. +}
  12046. +
  12047. +int parseVersion(pkg_t *pkg, char *raw)
  12048. +{
  12049. + char *colon, *eepochcolon;
  12050. +#ifdef USE_DEBVERSION
  12051. + char *hyphen;
  12052. +#endif
  12053. + unsigned long epoch;
  12054. +
  12055. + if (!*raw) {
  12056. + fprintf(stderr, "%s: ERROR: version string is empty", __FUNCTION__);
  12057. + return EINVAL;
  12058. + }
  12059. +
  12060. + if (strncmp(raw, "Version:", 8) == 0) {
  12061. + raw += 8;
  12062. + }
  12063. + while (*raw && isspace(*raw)) {
  12064. + raw++;
  12065. + }
  12066. +
  12067. + colon= strchr(raw,':');
  12068. + if (colon) {
  12069. + epoch= strtoul(raw,&eepochcolon,10);
  12070. + if (colon != eepochcolon) {
  12071. + fprintf(stderr, "%s: ERROR: epoch in version is not number", __FUNCTION__);
  12072. + return EINVAL;
  12073. + }
  12074. + if (!*++colon) {
  12075. + fprintf(stderr, "%s: ERROR: nothing after colon in version number", __FUNCTION__);
  12076. + return EINVAL;
  12077. + }
  12078. + raw= colon;
  12079. + pkg->epoch= epoch;
  12080. + } else {
  12081. + pkg->epoch= 0;
  12082. + }
  12083. +
  12084. + pkg->revision = (char *)"";
  12085. + pkg->familiar_revision = (char *)"";
  12086. +
  12087. + pkg->version= malloc(strlen(raw)+1);
  12088. + if ( pkg->version == NULL ) {
  12089. + fprintf(stderr, "%s: out of memory \n", __FUNCTION__);
  12090. + return ENOMEM;
  12091. + }
  12092. + strcpy(pkg->version, raw);
  12093. +
  12094. +#ifdef USE_DEBVERSION
  12095. + hyphen= strrchr(pkg->version,'-');
  12096. +
  12097. + if (hyphen) {
  12098. + *hyphen++= 0;
  12099. + if (strncmp("fam", hyphen, 3) == 0) {
  12100. + pkg->familiar_revision=hyphen+3;
  12101. + hyphen= strrchr(pkg->version,'-');
  12102. + if (hyphen) {
  12103. + *hyphen++= 0;
  12104. + pkg->revision = hyphen;
  12105. + }
  12106. + } else {
  12107. + pkg->revision = hyphen;
  12108. + }
  12109. + }
  12110. +#endif
  12111. +
  12112. +/*
  12113. + fprintf(stderr,"Parsed version: %lu, %s, %s, %s\n",
  12114. + pkg->epoch,
  12115. + pkg->version,
  12116. + pkg->revision,
  12117. + pkg->familiar_revision);
  12118. +*/
  12119. +
  12120. + return 0;
  12121. +}
  12122. +
  12123. +
  12124. +/* This code is needed to insert in first position the keyword for the aligning bug */
  12125. +
  12126. +int alterProvidesLine(char *raw, char *temp)
  12127. +{
  12128. +
  12129. +
  12130. + if (!*raw) {
  12131. + fprintf(stderr, "%s: ERROR: Provides string is empty", __FUNCTION__);
  12132. + return -EINVAL;
  12133. + }
  12134. +
  12135. + if ( temp == NULL ) {
  12136. + fprintf(stderr, "%s: out of memory \n", __FUNCTION__);
  12137. + return -ENOMEM;
  12138. + }
  12139. +
  12140. + if (strncmp(raw, "Provides:", 9) == 0) {
  12141. + raw += 9;
  12142. + }
  12143. + while (*raw && isspace(*raw)) {
  12144. + raw++;
  12145. + }
  12146. +
  12147. + snprintf ( temp, 35, "Provides: ipkg_internal_use_only, "); /* First part of the line */
  12148. + while (*raw) {
  12149. + strncat( temp, raw++, 1);
  12150. + }
  12151. + return 0;
  12152. +
  12153. +}
  12154. +
  12155. +/* Some random thoughts from Carl:
  12156. +
  12157. + This function could be considerably simplified if we just kept
  12158. + an array of all the generic string-valued field names, and looped
  12159. + through those looking for a match. Also, these fields could perhaps
  12160. + be stored in the package as an array as well, (or, probably better,
  12161. + as an nv_pair_list_t).
  12162. +
  12163. + Fields which require special parsing or storage, (such as Depends:
  12164. + and Status:) could be handled as they are now.
  12165. +*/
  12166. +/* XXX: FEATURE: The Suggests: field needs to be changed from a string
  12167. + to a dependency list. And, since we already have
  12168. + Depends/Pre-Depends and need to add Conflicts, Recommends, and
  12169. + Enhances, perhaps we could generalize all of these and save some
  12170. + code duplication.
  12171. +*/
  12172. +int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest)
  12173. +{
  12174. + int reading_conffiles, reading_description;
  12175. + int pkg_false_provides=1;
  12176. + char ** lines;
  12177. + char * provide=NULL;
  12178. +
  12179. + pkg->src = src;
  12180. + pkg->dest = dest;
  12181. +
  12182. + reading_conffiles = reading_description = 0;
  12183. +
  12184. + for (lines = *raw; *lines; lines++) {
  12185. + /* fprintf(stderr, "PARSING %s\n", *lines);*/
  12186. + if(isGenericFieldType((char *)"Package:", *lines))
  12187. + pkg->name = parseGenericFieldType((char *)"Package", *lines);
  12188. + else if(isGenericFieldType((char *)"Architecture:", *lines))
  12189. + pkg->architecture = parseGenericFieldType((char *)"Architecture", *lines);
  12190. + else if(isGenericFieldType((char *)"Filename:", *lines))
  12191. + pkg->filename = parseGenericFieldType((char *)"Filename", *lines);
  12192. + else if(isGenericFieldType((char *)"Section:", *lines))
  12193. + pkg->section = parseGenericFieldType((char *)"Section", *lines);
  12194. + else if(isGenericFieldType((char *)"MD5sum:", *lines))
  12195. + pkg->md5sum = parseGenericFieldType((char *)"MD5sum", *lines);
  12196. + /* The old ipkg wrote out status files with the wrong case for MD5sum,
  12197. + let's parse it either way */
  12198. + else if(isGenericFieldType((char *)"MD5Sum:", *lines))
  12199. + pkg->md5sum = parseGenericFieldType((char *)"MD5Sum", *lines);
  12200. + else if(isGenericFieldType((char *)"Size:", *lines))
  12201. + pkg->size = parseGenericFieldType((char *)"Size", *lines);
  12202. + else if(isGenericFieldType((char *)"Source:", *lines))
  12203. + pkg->source = parseGenericFieldType((char *)"Source", *lines);
  12204. + else if(isGenericFieldType((char *)"Installed-Size:", *lines))
  12205. + pkg->installed_size = parseGenericFieldType((char *)"Installed-Size", *lines);
  12206. + else if(isGenericFieldType((char *)"Installed-Time:", *lines)) {
  12207. + char *time_str = parseGenericFieldType((char *)"Installed-Time", *lines);
  12208. + pkg->installed_time = strtoul(time_str, NULL, 0);
  12209. + } else if(isGenericFieldType((char *)"Priority:", *lines))
  12210. + pkg->priority = parseGenericFieldType((char *)"Priority", *lines);
  12211. + else if(isGenericFieldType((char *)"Essential:", *lines)) {
  12212. + char *essential_value;
  12213. + essential_value = parseGenericFieldType((char *)"Essential", *lines);
  12214. + if (strcmp(essential_value, "yes") == 0) {
  12215. + pkg->essential = 1;
  12216. + }
  12217. + free(essential_value);
  12218. + }
  12219. + else if(isGenericFieldType((char *)"Status", *lines))
  12220. + parseStatus(pkg, *lines);
  12221. + else if(isGenericFieldType((char *)"Version", *lines))
  12222. + parseVersion(pkg, *lines);
  12223. + else if(isGenericFieldType((char *)"Maintainer", *lines))
  12224. + pkg->maintainer = parseGenericFieldType((char *)"Maintainer", *lines);
  12225. + else if(isGenericFieldType((char *)"Conffiles", *lines)){
  12226. + parseConffiles(pkg, *lines);
  12227. + reading_conffiles = 1;
  12228. + }
  12229. + else if(isGenericFieldType((char *)"Description", *lines)) {
  12230. + pkg->description = parseGenericFieldType((char *)"Description", *lines);
  12231. + reading_conffiles = 0;
  12232. + reading_description = 1;
  12233. + }
  12234. +
  12235. + else if(isGenericFieldType((char *)"Provides", *lines)){
  12236. +/* Here we add the internal_use to align the off by one problem between provides_str and provides */
  12237. + provide = (char * ) malloc(strlen(*lines)+ 35 ); /* Preparing the space for the new ipkg_internal_use_only */
  12238. + if ( alterProvidesLine(*lines,provide) ){
  12239. + return EINVAL;
  12240. + }
  12241. + pkg->provides_str = parseDependsString( provide, &pkg->provides_count);
  12242. +/* Let's try to hack a bit here.
  12243. + The idea is that if a package has no Provides, we would add one generic, to permit the check of dependencies
  12244. + in alot of other places. We will remove it before writing down the status database */
  12245. + pkg_false_provides=0;
  12246. + free(provide);
  12247. + }
  12248. +
  12249. + else if(isGenericFieldType((char *)"Depends", *lines))
  12250. + pkg->depends_str = parseDependsString(*lines, &pkg->depends_count);
  12251. + else if(isGenericFieldType((char *)"Pre-Depends", *lines))
  12252. + pkg->pre_depends_str = parseDependsString(*lines, &pkg->pre_depends_count);
  12253. + else if(isGenericFieldType((char *)"Recommends", *lines))
  12254. + pkg->recommends_str = parseDependsString(*lines, &pkg->recommends_count);
  12255. + else if(isGenericFieldType((char *)"Suggests", *lines))
  12256. + pkg->suggests_str = parseDependsString(*lines, &pkg->suggests_count);
  12257. + /* Abhaya: support for conflicts */
  12258. + else if(isGenericFieldType((char *)"Conflicts", *lines))
  12259. + pkg->conflicts_str = parseDependsString(*lines, &pkg->conflicts_count);
  12260. + else if(isGenericFieldType((char *)"Replaces", *lines))
  12261. + pkg->replaces_str = parseDependsString(*lines, &pkg->replaces_count);
  12262. + else if(line_is_blank(*lines)) {
  12263. + lines++;
  12264. + break;
  12265. + }
  12266. + else if(**lines == ' '){
  12267. + if(reading_description) {
  12268. + /* we already know it's not blank, so the rest of description */
  12269. + pkg->description = realloc(pkg->description,
  12270. + strlen(pkg->description)
  12271. + + 1 + strlen(*lines) + 1);
  12272. + strcat(pkg->description, "\n");
  12273. + strcat(pkg->description, (*lines));
  12274. + }
  12275. + else if(reading_conffiles)
  12276. + parseConffiles(pkg, *lines);
  12277. + }
  12278. + }
  12279. + *raw = lines;
  12280. +/* If the ipk has not a Provides line, we insert our false line */
  12281. + if ( pkg_false_provides==1)
  12282. + pkg->provides_str = parseDependsString ((char *)"Provides: ipkg_internal_use_only ", &pkg->provides_count);
  12283. +
  12284. + if (pkg->name) {
  12285. + return 0;
  12286. + } else {
  12287. + return EINVAL;
  12288. + }
  12289. +}
  12290. +
  12291. +int pkg_valorize_other_field(pkg_t *pkg, char ***raw)
  12292. +{
  12293. + char ** lines;
  12294. +
  12295. + for (lines = *raw; *lines; lines++) {
  12296. + if(isGenericFieldType((char *)"Essential:", *lines)) {
  12297. + char *essential_value;
  12298. + essential_value = parseGenericFieldType((char *)"Essential", *lines);
  12299. + if (strcmp(essential_value, "yes") == 0) {
  12300. + pkg->essential = 1;
  12301. + }
  12302. + free(essential_value);
  12303. + }
  12304. + }
  12305. + *raw = lines;
  12306. +
  12307. + return 0;
  12308. +}
  12309. diff -Nur busybox-1.12.1.orig/archival/libipkg/pkg_parse.h busybox-1.12.1/archival/libipkg/pkg_parse.h
  12310. --- busybox-1.12.1.orig/archival/libipkg/pkg_parse.h 1970-01-01 01:00:00.000000000 +0100
  12311. +++ busybox-1.12.1/archival/libipkg/pkg_parse.h 2008-10-23 11:41:37.000000000 +0200
  12312. @@ -0,0 +1,31 @@
  12313. +/* pkg_parse.h - the itsy package management system
  12314. +
  12315. + Steven M. Ayer
  12316. +
  12317. + Copyright (C) 2002 Compaq Computer Corporation
  12318. +
  12319. + This program is free software; you can redistribute it and/or
  12320. + modify it under the terms of the GNU General Public License as
  12321. + published by the Free Software Foundation; either version 2, or (at
  12322. + your option) any later version.
  12323. +
  12324. + This program is distributed in the hope that it will be useful, but
  12325. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12326. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12327. + General Public License for more details.
  12328. +*/
  12329. +
  12330. +#ifndef PKG_PARSE_H
  12331. +#define PKG_PARSE_H
  12332. +
  12333. +int isGenericFieldType(char * type, char * line);
  12334. +char * parseGenericFieldType(char * type, char * raw);
  12335. +void parseStatus(pkg_t *pkg, char * raw);
  12336. +int parseVersion(pkg_t *pkg, char *raw);
  12337. +char ** parseDependsString(char * raw, int * depends_count);
  12338. +int parseVersion(pkg_t *pkg, char *raw);
  12339. +void parseConffiles(pkg_t * pkg, char * raw);
  12340. +int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest);
  12341. +int pkg_valorize_other_field(pkg_t *pkg, char ***raw);
  12342. +
  12343. +#endif
  12344. diff -Nur busybox-1.12.1.orig/archival/libipkg/pkg_src.c busybox-1.12.1/archival/libipkg/pkg_src.c
  12345. --- busybox-1.12.1.orig/archival/libipkg/pkg_src.c 1970-01-01 01:00:00.000000000 +0100
  12346. +++ busybox-1.12.1/archival/libipkg/pkg_src.c 2008-10-23 11:41:37.000000000 +0200
  12347. @@ -0,0 +1,43 @@
  12348. +/* pkg_src.c - the itsy package management system
  12349. +
  12350. + Carl D. Worth
  12351. +
  12352. + Copyright (C) 2001 University of Southern California
  12353. +
  12354. + This program is free software; you can redistribute it and/or
  12355. + modify it under the terms of the GNU General Public License as
  12356. + published by the Free Software Foundation; either version 2, or (at
  12357. + your option) any later version.
  12358. +
  12359. + This program is distributed in the hope that it will be useful, but
  12360. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12361. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12362. + General Public License for more details.
  12363. +*/
  12364. +
  12365. +#include "ipkg.h"
  12366. +
  12367. +#include "pkg_src.h"
  12368. +#include "str_util.h"
  12369. +
  12370. +int pkg_src_init(pkg_src_t *src, const char *name, const char *base_url, const char *extra_data, int gzip)
  12371. +{
  12372. + src->gzip = gzip;
  12373. + src->name = str_dup_safe (name);
  12374. + src->value = str_dup_safe (base_url);
  12375. + if (extra_data)
  12376. + src->extra_data = str_dup_safe (extra_data);
  12377. + else
  12378. + src->extra_data = NULL;
  12379. + return 0;
  12380. +}
  12381. +
  12382. +void pkg_src_deinit(pkg_src_t *src)
  12383. +{
  12384. + free (src->name);
  12385. + free (src->value);
  12386. + if (src->extra_data)
  12387. + free (src->extra_data);
  12388. +}
  12389. +
  12390. +
  12391. diff -Nur busybox-1.12.1.orig/archival/libipkg/pkg_src.h busybox-1.12.1/archival/libipkg/pkg_src.h
  12392. --- busybox-1.12.1.orig/archival/libipkg/pkg_src.h 1970-01-01 01:00:00.000000000 +0100
  12393. +++ busybox-1.12.1/archival/libipkg/pkg_src.h 2008-10-23 11:41:37.000000000 +0200
  12394. @@ -0,0 +1,34 @@
  12395. +/* pkg_src.h - the itsy package management system
  12396. +
  12397. + Carl D. Worth
  12398. +
  12399. + Copyright (C) 2001 University of Southern California
  12400. +
  12401. + This program is free software; you can redistribute it and/or
  12402. + modify it under the terms of the GNU General Public License as
  12403. + published by the Free Software Foundation; either version 2, or (at
  12404. + your option) any later version.
  12405. +
  12406. + This program is distributed in the hope that it will be useful, but
  12407. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12408. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12409. + General Public License for more details.
  12410. +*/
  12411. +
  12412. +#ifndef PKG_SRC_H
  12413. +#define PKG_SRC_H
  12414. +
  12415. +#include "nv_pair.h"
  12416. +
  12417. +typedef struct
  12418. +{
  12419. + char *name;
  12420. + char *value;
  12421. + char *extra_data;
  12422. + int gzip;
  12423. +} pkg_src_t;
  12424. +
  12425. +int pkg_src_init(pkg_src_t *src, const char *name, const char *base_url, const char *extra_data, int gzip);
  12426. +void pkg_src_deinit(pkg_src_t *src);
  12427. +
  12428. +#endif
  12429. diff -Nur busybox-1.12.1.orig/archival/libipkg/pkg_src_list.c busybox-1.12.1/archival/libipkg/pkg_src_list.c
  12430. --- busybox-1.12.1.orig/archival/libipkg/pkg_src_list.c 1970-01-01 01:00:00.000000000 +0100
  12431. +++ busybox-1.12.1/archival/libipkg/pkg_src_list.c 2008-10-23 11:41:37.000000000 +0200
  12432. @@ -0,0 +1,75 @@
  12433. +/* pkg_src_list.c - the itsy package management system
  12434. +
  12435. + Carl D. Worth
  12436. +
  12437. + Copyright (C) 2001 University of Southern California
  12438. +
  12439. + This program is free software; you can redistribute it and/or
  12440. + modify it under the terms of the GNU General Public License as
  12441. + published by the Free Software Foundation; either version 2, or (at
  12442. + your option) any later version.
  12443. +
  12444. + This program is distributed in the hope that it will be useful, but
  12445. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12446. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12447. + General Public License for more details.
  12448. +*/
  12449. +
  12450. +#include "ipkg.h"
  12451. +
  12452. +#include "pkg_src_list.h"
  12453. +#include "void_list.h"
  12454. +
  12455. +int pkg_src_list_init(pkg_src_list_t *list)
  12456. +{
  12457. + return void_list_init((void_list_t *) list);
  12458. +}
  12459. +
  12460. +void pkg_src_list_deinit(pkg_src_list_t *list)
  12461. +{
  12462. + pkg_src_list_elt_t *iter;
  12463. + pkg_src_t *pkg_src;
  12464. +
  12465. + for (iter = list->head; iter; iter = iter->next) {
  12466. + pkg_src = iter->data;
  12467. + pkg_src_deinit(pkg_src);
  12468. +
  12469. + /* malloced in pkg_src_list_append */
  12470. + free(pkg_src);
  12471. + iter->data = NULL;
  12472. + }
  12473. + void_list_deinit((void_list_t *) list);
  12474. +}
  12475. +
  12476. +pkg_src_t *pkg_src_list_append(pkg_src_list_t *list,
  12477. + const char *name, const char *base_url, const char *extra_data,
  12478. + int gzip)
  12479. +{
  12480. + int err;
  12481. +
  12482. + /* freed in pkg_src_list_deinit */
  12483. + pkg_src_t *pkg_src = malloc(sizeof(pkg_src_t));
  12484. +
  12485. + if (pkg_src == NULL) {
  12486. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  12487. + return NULL;
  12488. + }
  12489. + pkg_src_init(pkg_src, name, base_url, extra_data, gzip);
  12490. +
  12491. + err = void_list_append((void_list_t *) list, pkg_src);
  12492. + if (err) {
  12493. + return NULL;
  12494. + }
  12495. +
  12496. + return pkg_src;
  12497. +}
  12498. +
  12499. +int pkg_src_list_push(pkg_src_list_t *list, pkg_src_t *data)
  12500. +{
  12501. + return void_list_push((void_list_t *) list, data);
  12502. +}
  12503. +
  12504. +pkg_src_list_elt_t *pkg_src_list_pop(pkg_src_list_t *list)
  12505. +{
  12506. + return (pkg_src_list_elt_t *) void_list_pop((void_list_t *) list);
  12507. +}
  12508. diff -Nur busybox-1.12.1.orig/archival/libipkg/pkg_src_list.h busybox-1.12.1/archival/libipkg/pkg_src_list.h
  12509. --- busybox-1.12.1.orig/archival/libipkg/pkg_src_list.h 1970-01-01 01:00:00.000000000 +0100
  12510. +++ busybox-1.12.1/archival/libipkg/pkg_src_list.h 2008-10-23 11:41:37.000000000 +0200
  12511. @@ -0,0 +1,57 @@
  12512. +/* pkg_src_list.h - the itsy package management system
  12513. +
  12514. + Carl D. Worth
  12515. +
  12516. + Copyright (C) 2001 University of Southern California
  12517. +
  12518. + This program is free software; you can redistribute it and/or
  12519. + modify it under the terms of the GNU General Public License as
  12520. + published by the Free Software Foundation; either version 2, or (at
  12521. + your option) any later version.
  12522. +
  12523. + This program is distributed in the hope that it will be useful, but
  12524. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12525. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12526. + General Public License for more details.
  12527. +*/
  12528. +
  12529. +#ifndef PKG_SRC_LIST_H
  12530. +#define PKG_SRC_LIST_H
  12531. +
  12532. +#include "pkg_src.h"
  12533. +
  12534. +typedef struct pkg_src_list_elt pkg_src_list_elt_t;
  12535. +struct pkg_src_list_elt
  12536. +{
  12537. + pkg_src_list_elt_t *next;
  12538. + pkg_src_t *data;
  12539. +};
  12540. +
  12541. +typedef struct pkg_src_list pkg_src_list_t;
  12542. +struct pkg_src_list
  12543. +{
  12544. + pkg_src_list_elt_t pre_head;
  12545. + pkg_src_list_elt_t *head;
  12546. + pkg_src_list_elt_t *tail;
  12547. +};
  12548. +
  12549. +static inline int pkg_src_list_empty(pkg_src_list_t *list)
  12550. +{
  12551. + if (list->head == NULL)
  12552. + return 1;
  12553. + else
  12554. + return 0;
  12555. +}
  12556. +
  12557. +int pkg_src_list_elt_init(pkg_src_list_elt_t *elt, nv_pair_t *data);
  12558. +void pkg_src_list_elt_deinit(pkg_src_list_elt_t *elt);
  12559. +
  12560. +int pkg_src_list_init(pkg_src_list_t *list);
  12561. +void pkg_src_list_deinit(pkg_src_list_t *list);
  12562. +
  12563. +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);
  12564. +int pkg_src_list_push(pkg_src_list_t *list, pkg_src_t *data);
  12565. +pkg_src_list_elt_t *pkg_src_list_pop(pkg_src_list_t *list);
  12566. +
  12567. +#endif
  12568. +
  12569. diff -Nur busybox-1.12.1.orig/archival/libipkg/pkg_vec.c busybox-1.12.1/archival/libipkg/pkg_vec.c
  12570. --- busybox-1.12.1.orig/archival/libipkg/pkg_vec.c 1970-01-01 01:00:00.000000000 +0100
  12571. +++ busybox-1.12.1/archival/libipkg/pkg_vec.c 2008-10-23 13:09:31.000000000 +0200
  12572. @@ -0,0 +1,231 @@
  12573. +/* pkg_vec.c - the itsy package management system
  12574. +
  12575. + Steven M. Ayer
  12576. +
  12577. + Copyright (C) 2002 Compaq Computer Corporation
  12578. +
  12579. + This program is free software; you can redistribute it and/or
  12580. + modify it under the terms of the GNU General Public License as
  12581. + published by the Free Software Foundation; either version 2, or (at
  12582. + your option) any later version.
  12583. +
  12584. + This program is distributed in the hope that it will be useful, but
  12585. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12586. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12587. + General Public License for more details.
  12588. +*/
  12589. +
  12590. +#include <stdlib.h>
  12591. +#include <fnmatch.h>
  12592. +#include "libbb.h"
  12593. +#include "xregex.h"
  12594. +#include "ipkg.h"
  12595. +#include "pkg.h"
  12596. +
  12597. +pkg_vec_t * pkg_vec_alloc(void)
  12598. +{
  12599. + pkg_vec_t * vec = (pkg_vec_t *)malloc(sizeof(pkg_vec_t));
  12600. + if (!vec) {
  12601. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  12602. + return NULL;
  12603. + }
  12604. + vec->pkgs = NULL;
  12605. + vec->len = 0;
  12606. +
  12607. + return vec;
  12608. +}
  12609. +
  12610. +void pkg_vec_free(pkg_vec_t *vec)
  12611. +{
  12612. + free(vec->pkgs);
  12613. + free(vec);
  12614. +}
  12615. +
  12616. +/*
  12617. + * assumption: all names in a vector are identical
  12618. + * assumption: all version strings are trimmed,
  12619. + * so identical versions have identical version strings,
  12620. + * implying identical packages; let's marry these
  12621. + */
  12622. +pkg_t *pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status,ipkg_conf_t *conf)
  12623. +{
  12624. + int i;
  12625. + int found = 0;
  12626. +
  12627. + /* look for a duplicate pkg by name, version, and architecture */
  12628. + for (i = 0; i < vec->len; i++){
  12629. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Found pkg=%s version=%s arch=%s cmp=%s version=%s arch=%s \n",
  12630. + __FUNCTION__, pkg->name, pkg->version, pkg->architecture,
  12631. + vec->pkgs[i]->name, vec->pkgs[i]->version,vec->pkgs[i]->architecture );
  12632. + if ((strcmp(pkg->name, vec->pkgs[i]->name) == 0)
  12633. + && (pkg_compare_versions(pkg, vec->pkgs[i]) == 0)
  12634. + && (strcmp(pkg->architecture, vec->pkgs[i]->architecture) == 0)) {
  12635. + found = 1;
  12636. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Found duplicate for pkg=%s version=%s arch=%s\n",
  12637. + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
  12638. + break;
  12639. + }
  12640. + }
  12641. +
  12642. + /* we didn't find one, add it */
  12643. + if (!found){
  12644. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Adding new pkg=%s version=%s arch=%s\n",
  12645. + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
  12646. +
  12647. + vec->pkgs = (pkg_t **)realloc(vec->pkgs, (vec->len + 1) * sizeof(pkg_t *));
  12648. + vec->pkgs[vec->len] = pkg;
  12649. + vec->len++;
  12650. + return pkg;
  12651. + }
  12652. + /* update the one that we have */
  12653. + else {
  12654. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. calling pkg_merge for pkg=%s version=%s arch=%s",
  12655. + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
  12656. + if (set_status) {
  12657. + /* this is from the status file, so need to merge with existing database */
  12658. + ipkg_message(conf, IPKG_DEBUG2, " with set_status\n");
  12659. + pkg_merge(vec->pkgs[i], pkg, set_status);
  12660. + /* XXX: CLEANUP: It's not so polite to free something here
  12661. + that was passed in from above. */
  12662. + pkg_deinit(pkg);
  12663. + free(pkg);
  12664. + } else {
  12665. + ipkg_message(conf, IPKG_DEBUG2, " WITHOUT set_status\n");
  12666. + /* just overwrite the old one */
  12667. + pkg_deinit(vec->pkgs[i]);
  12668. + free(vec->pkgs[i]);
  12669. + vec->pkgs[i] = pkg;
  12670. + }
  12671. + return vec->pkgs[i];
  12672. + }
  12673. +}
  12674. +
  12675. +void pkg_vec_insert(pkg_vec_t *vec, const pkg_t *pkg)
  12676. +{
  12677. + int i;
  12678. + int found = 0;
  12679. +
  12680. + /* look for a duplicate pkg by name, version, and architecture */
  12681. + for (i = 0; i < vec->len; i++)
  12682. + if ((strcmp(pkg->name, vec->pkgs[i]->name) == 0)
  12683. + && (pkg_compare_versions(pkg, vec->pkgs[i]) == 0)
  12684. + && (strcmp(pkg->architecture, vec->pkgs[i]->name) == 0)) {
  12685. + found = 1;
  12686. + break;
  12687. + }
  12688. +
  12689. + /* we didn't find one, add it */
  12690. + if(!found){
  12691. + vec->pkgs = (pkg_t **)realloc(vec->pkgs, (vec->len + 1) * sizeof(pkg_t *));
  12692. + *(const pkg_t **)&vec->pkgs[vec->len] = pkg;
  12693. + vec->len++;
  12694. + }
  12695. +}
  12696. +
  12697. +int pkg_vec_contains(pkg_vec_t *vec, pkg_t *apkg)
  12698. +{
  12699. + int i;
  12700. + for (i = 0; i < vec->len; i++)
  12701. + if (vec->pkgs[i] == apkg)
  12702. + return 1;
  12703. + return 0;
  12704. +}
  12705. +
  12706. +typedef int (*compare_fcn_t)(const void *, const void *);
  12707. +void pkg_vec_sort(pkg_vec_t *vec, int (*compar)(pkg_t *, pkg_t *))
  12708. +{
  12709. + qsort(vec->pkgs, vec->len, sizeof(pkg_t *), (compare_fcn_t)compar);
  12710. +}
  12711. +
  12712. +int pkg_vec_clear_marks(pkg_vec_t *vec)
  12713. +{
  12714. + int npkgs = vec->len;
  12715. + int i;
  12716. + for (i = 0; i < npkgs; i++) {
  12717. + pkg_t *pkg = vec->pkgs[i];
  12718. + pkg->state_flag &= ~SF_MARKED;
  12719. + }
  12720. + return 0;
  12721. +}
  12722. +
  12723. +int pkg_vec_mark_if_matches(pkg_vec_t *vec, const char *pattern)
  12724. +{
  12725. + int matching_count = 0;
  12726. + pkg_t **pkgs = vec->pkgs;
  12727. + int npkgs = vec->len;
  12728. + int i;
  12729. + for (i = 0; i < npkgs; i++) {
  12730. + pkg_t *pkg = pkgs[i];
  12731. + if (fnmatch(pattern, pkg->name, 0)==0) {
  12732. + pkg->state_flag |= SF_MARKED;
  12733. + matching_count++;
  12734. + }
  12735. + }
  12736. + return matching_count;
  12737. +}
  12738. +
  12739. +
  12740. +abstract_pkg_vec_t * abstract_pkg_vec_alloc(void)
  12741. +{
  12742. + abstract_pkg_vec_t * vec ;
  12743. + vec = (abstract_pkg_vec_t *)malloc(sizeof(abstract_pkg_vec_t));
  12744. + if (!vec) {
  12745. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  12746. + return NULL;
  12747. + }
  12748. + vec->pkgs = NULL;
  12749. + vec->len = 0;
  12750. +
  12751. + return vec;
  12752. +}
  12753. +
  12754. +void abstract_pkg_vec_free(abstract_pkg_vec_t *vec)
  12755. +{
  12756. + free(vec->pkgs);
  12757. + free(vec);
  12758. +}
  12759. +
  12760. +/*
  12761. + * assumption: all names in a vector are unique
  12762. + */
  12763. +void abstract_pkg_vec_insert(abstract_pkg_vec_t *vec, abstract_pkg_t *pkg)
  12764. +{
  12765. + int i;
  12766. +
  12767. + /* look for a duplicate pkg by name */
  12768. + for(i = 0; i < vec->len; i++)
  12769. + if (strcmp(pkg->name, vec->pkgs[i]->name) == 0)
  12770. + break;
  12771. +
  12772. + /* we didn't find one, add it */
  12773. + if(i == vec->len){
  12774. + vec->pkgs =
  12775. + (abstract_pkg_t **)
  12776. + realloc(vec->pkgs, (vec->len + 1) * sizeof(abstract_pkg_t *));
  12777. + vec->pkgs[vec->len] = pkg;
  12778. + vec->len++;
  12779. + }
  12780. +}
  12781. +
  12782. +abstract_pkg_t * abstract_pkg_vec_get(abstract_pkg_vec_t *vec, int i)
  12783. +{
  12784. + if (vec->len > i)
  12785. + return vec->pkgs[i];
  12786. + else
  12787. + return NULL;
  12788. +}
  12789. +
  12790. +int abstract_pkg_vec_contains(abstract_pkg_vec_t *vec, abstract_pkg_t *apkg)
  12791. +{
  12792. + int i;
  12793. + for (i = 0; i < vec->len; i++)
  12794. + if (vec->pkgs[i] == apkg)
  12795. + return 1;
  12796. + return 0;
  12797. +}
  12798. +
  12799. +void abstract_pkg_vec_sort(pkg_vec_t *vec, int (*compar)(abstract_pkg_t *, abstract_pkg_t *))
  12800. +{
  12801. + qsort(vec->pkgs, vec->len, sizeof(pkg_t *), (compare_fcn_t)compar);
  12802. +}
  12803. +
  12804. diff -Nur busybox-1.12.1.orig/archival/libipkg/pkg_vec.h busybox-1.12.1/archival/libipkg/pkg_vec.h
  12805. --- busybox-1.12.1.orig/archival/libipkg/pkg_vec.h 1970-01-01 01:00:00.000000000 +0100
  12806. +++ busybox-1.12.1/archival/libipkg/pkg_vec.h 2008-10-23 11:41:37.000000000 +0200
  12807. @@ -0,0 +1,62 @@
  12808. +/* pkg_vec.h - the itsy package management system
  12809. +
  12810. + Steven M. Ayer
  12811. +
  12812. + Copyright (C) 2002 Compaq Computer Corporation
  12813. +
  12814. + This program is free software; you can redistribute it and/or
  12815. + modify it under the terms of the GNU General Public License as
  12816. + published by the Free Software Foundation; either version 2, or (at
  12817. + your option) any later version.
  12818. +
  12819. + This program is distributed in the hope that it will be useful, but
  12820. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12821. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12822. + General Public License for more details.
  12823. +*/
  12824. +
  12825. +#ifndef PKG_VEC_H
  12826. +#define PKG_VEC_H
  12827. +
  12828. +typedef struct pkg pkg_t;
  12829. +typedef struct abstract_pkg abstract_pkg_t;
  12830. +
  12831. +struct pkg_vec
  12832. +{
  12833. + pkg_t **pkgs;
  12834. + int len;
  12835. +};
  12836. +typedef struct pkg_vec pkg_vec_t;
  12837. +
  12838. +struct abstract_pkg_vec
  12839. +{
  12840. + abstract_pkg_t **pkgs;
  12841. + int len;
  12842. +};
  12843. +typedef struct abstract_pkg_vec abstract_pkg_vec_t;
  12844. +
  12845. +
  12846. +pkg_vec_t * pkg_vec_alloc(void);
  12847. +void pkg_vec_free(pkg_vec_t *vec);
  12848. +void marry_two_packages(pkg_t * newpkg, pkg_t * oldpkg);
  12849. +
  12850. +void pkg_vec_add(pkg_vec_t *vec, pkg_t *pkg);
  12851. +/* pkg_vec_insert_merge: might munge pkg.
  12852. +* returns the pkg that is in the pkg graph */
  12853. +pkg_t *pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status, ipkg_conf_t *conf);
  12854. +/* this one never munges pkg */
  12855. +void pkg_vec_insert(pkg_vec_t *vec, const pkg_t *pkg);
  12856. +int pkg_vec_contains(pkg_vec_t *vec, pkg_t *apkg);
  12857. +void pkg_vec_sort(pkg_vec_t *vec, int (*compar)(pkg_t *, pkg_t *));
  12858. +
  12859. +int pkg_vec_clear_marks(pkg_vec_t *vec);
  12860. +int pkg_vec_mark_if_matches(pkg_vec_t *vec, const char *pattern);
  12861. +
  12862. +abstract_pkg_vec_t * abstract_pkg_vec_alloc(void);
  12863. +void abstract_pkg_vec_free(abstract_pkg_vec_t *vec);
  12864. +void abstract_pkg_vec_insert(abstract_pkg_vec_t *vec, abstract_pkg_t *pkg);
  12865. +abstract_pkg_t * abstract_pkg_vec_get(abstract_pkg_vec_t *vec, int i);
  12866. +int abstract_pkg_vec_contains(abstract_pkg_vec_t *vec, abstract_pkg_t *apkg);
  12867. +void abstract_pkg_vec_sort(pkg_vec_t *vec, int (*compar)(abstract_pkg_t *, abstract_pkg_t *));
  12868. +#endif
  12869. +
  12870. diff -Nur busybox-1.12.1.orig/archival/libipkg/sprintf_alloc.h busybox-1.12.1/archival/libipkg/sprintf_alloc.h
  12871. --- busybox-1.12.1.orig/archival/libipkg/sprintf_alloc.h 1970-01-01 01:00:00.000000000 +0100
  12872. +++ busybox-1.12.1/archival/libipkg/sprintf_alloc.h 2008-10-23 11:41:37.000000000 +0200
  12873. @@ -0,0 +1,25 @@
  12874. +/* sprintf_alloca.c -- like sprintf with memory allocation
  12875. +
  12876. + Carl D. Worth
  12877. +
  12878. + Copyright (C) 2001 University of Southern California
  12879. +
  12880. + This program is free software; you can redistribute it and/or modify
  12881. + it under the terms of the GNU General Public License as published by
  12882. + the Free Software Foundation; either version 2, or (at your option)
  12883. + any later version.
  12884. +
  12885. + This program is distributed in the hope that it will be useful,
  12886. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  12887. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12888. + GNU General Public License for more details.
  12889. +*/
  12890. +
  12891. +#ifndef SPRINTF_ALLOC_H
  12892. +#define SPRINTF_ALLOC_H
  12893. +
  12894. +#include "libbb.h"
  12895. +
  12896. +#define sprintf_alloc(str, fmt, args...) *str = xasprintf(fmt, ## args)
  12897. +
  12898. +#endif
  12899. diff -Nur busybox-1.12.1.orig/archival/libipkg/str_list.c busybox-1.12.1/archival/libipkg/str_list.c
  12900. --- busybox-1.12.1.orig/archival/libipkg/str_list.c 1970-01-01 01:00:00.000000000 +0100
  12901. +++ busybox-1.12.1/archival/libipkg/str_list.c 2008-10-23 15:53:09.000000000 +0200
  12902. @@ -0,0 +1,76 @@
  12903. +/* str_list.c - the itsy package management system
  12904. +
  12905. + Carl D. Worth
  12906. +
  12907. + Copyright (C) 2001 University of Southern California
  12908. +
  12909. + This program is free software; you can redistribute it and/or
  12910. + modify it under the terms of the GNU General Public License as
  12911. + published by the Free Software Foundation; either version 2, or (at
  12912. + your option) any later version.
  12913. +
  12914. + This program is distributed in the hope that it will be useful, but
  12915. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12916. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12917. + General Public License for more details.
  12918. +*/
  12919. +
  12920. +#include "ipkg.h"
  12921. +
  12922. +#include "str_list.h"
  12923. +
  12924. +int str_list_elt_init(str_list_elt_t *elt, char *data)
  12925. +{
  12926. + return void_list_elt_init((void_list_elt_t *) elt, data);
  12927. +}
  12928. +
  12929. +void str_list_elt_deinit(str_list_elt_t *elt)
  12930. +{
  12931. + void_list_elt_deinit((void_list_elt_t *) elt);
  12932. +}
  12933. +
  12934. +str_list_t *str_list_alloc(void)
  12935. +{
  12936. + str_list_t *list = (str_list_t *)malloc(sizeof(str_list_t));
  12937. + if (list)
  12938. + str_list_init(list);
  12939. + return list;
  12940. +}
  12941. +
  12942. +int str_list_init(str_list_t *list)
  12943. +{
  12944. + return void_list_init((void_list_t *) list);
  12945. +}
  12946. +
  12947. +void str_list_deinit(str_list_t *list)
  12948. +{
  12949. + void_list_deinit((void_list_t *) list);
  12950. +}
  12951. +
  12952. +int str_list_append(str_list_t *list, char *data)
  12953. +{
  12954. + return void_list_append((void_list_t *) list, data);
  12955. +}
  12956. +
  12957. +int str_list_push(str_list_t *list, char *data)
  12958. +{
  12959. + return void_list_push((void_list_t *) list, data);
  12960. +}
  12961. +
  12962. +str_list_elt_t *str_list_pop(str_list_t *list)
  12963. +{
  12964. + return (str_list_elt_t *) void_list_pop((void_list_t *) list);
  12965. +}
  12966. +
  12967. +str_list_elt_t *str_list_remove(str_list_t *list, str_list_elt_t **iter)
  12968. +{
  12969. + return (str_list_elt_t *) void_list_remove((void_list_t *) list,
  12970. + (void_list_elt_t **) iter);
  12971. +}
  12972. +
  12973. +char *str_list_remove_elt(str_list_t *list, const char *target_str)
  12974. +{
  12975. + return (char *)void_list_remove_elt((void_list_t *) list,
  12976. + (void *)target_str,
  12977. + (void_list_cmp_t)strcmp);
  12978. +}
  12979. diff -Nur busybox-1.12.1.orig/archival/libipkg/str_list.h busybox-1.12.1/archival/libipkg/str_list.h
  12980. --- busybox-1.12.1.orig/archival/libipkg/str_list.h 1970-01-01 01:00:00.000000000 +0100
  12981. +++ busybox-1.12.1/archival/libipkg/str_list.h 2008-10-23 11:41:37.000000000 +0200
  12982. @@ -0,0 +1,51 @@
  12983. +/* str_list.h - the itsy package management system
  12984. +
  12985. + Carl D. Worth
  12986. +
  12987. + Copyright (C) 2001 University of Southern California
  12988. +
  12989. + This program is free software; you can redistribute it and/or
  12990. + modify it under the terms of the GNU General Public License as
  12991. + published by the Free Software Foundation; either version 2, or (at
  12992. + your option) any later version.
  12993. +
  12994. + This program is distributed in the hope that it will be useful, but
  12995. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12996. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12997. + General Public License for more details.
  12998. +*/
  12999. +
  13000. +#ifndef STR_LIST_H
  13001. +#define STR_LIST_H
  13002. +
  13003. +#include "void_list.h"
  13004. +
  13005. +typedef struct str_list_elt str_list_elt_t;
  13006. +struct str_list_elt
  13007. +{
  13008. + str_list_elt_t *next;
  13009. + char *data;
  13010. +};
  13011. +
  13012. +typedef struct xstr_list str_list_t;
  13013. +struct xstr_list
  13014. +{
  13015. + str_list_elt_t pre_head;
  13016. + str_list_elt_t *head;
  13017. + str_list_elt_t *tail;
  13018. +};
  13019. +
  13020. +int str_list_elt_init(str_list_elt_t *elt, char *data);
  13021. +void str_list_elt_deinit(str_list_elt_t *elt);
  13022. +
  13023. +str_list_t *str_list_alloc(void);
  13024. +int str_list_init(str_list_t *list);
  13025. +void str_list_deinit(str_list_t *list);
  13026. +
  13027. +int str_list_append(str_list_t *list, char *data);
  13028. +int str_list_push(str_list_t *list, char *data);
  13029. +str_list_elt_t *str_list_pop(str_list_t *list);
  13030. +str_list_elt_t *str_list_remove(str_list_t *list, str_list_elt_t **iter);
  13031. +char *str_list_remove_elt(str_list_t *list, const char *target_str);
  13032. +
  13033. +#endif
  13034. diff -Nur busybox-1.12.1.orig/archival/libipkg/str_util.c busybox-1.12.1/archival/libipkg/str_util.c
  13035. --- busybox-1.12.1.orig/archival/libipkg/str_util.c 1970-01-01 01:00:00.000000000 +0100
  13036. +++ busybox-1.12.1/archival/libipkg/str_util.c 2008-10-23 16:01:50.000000000 +0200
  13037. @@ -0,0 +1,69 @@
  13038. +/* str_utils.c - the itsy package management system
  13039. +
  13040. + Carl D. Worth
  13041. +
  13042. + Copyright (C) 2001 University of Southern California
  13043. +
  13044. + This program is free software; you can redistribute it and/or
  13045. + modify it under the terms of the GNU General Public License as
  13046. + published by the Free Software Foundation; either version 2, or (at
  13047. + your option) any later version.
  13048. +
  13049. + This program is distributed in the hope that it will be useful, but
  13050. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13051. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13052. + General Public License for more details.
  13053. +*/
  13054. +
  13055. +#include "ipkg.h"
  13056. +
  13057. +int str_starts_with(const char *str, const char *prefix);
  13058. +int str_ends_with(const char *str, const char *suffix);
  13059. +int str_chomp(char *str);
  13060. +int str_toupper(char *str);
  13061. +char *str_dup_safe(const char *str);
  13062. +
  13063. +int str_starts_with(const char *str, const char *prefix)
  13064. +{
  13065. + return (strncmp(str, prefix, strlen(prefix)) == 0);
  13066. +}
  13067. +
  13068. +int str_ends_with(const char *str, const char *suffix)
  13069. +{
  13070. + int suffix_len;
  13071. + int str_len;
  13072. +
  13073. + str_len = strlen(str);
  13074. + suffix_len = strlen(suffix);
  13075. +
  13076. + if (str_len < suffix_len) {
  13077. + return 0;
  13078. + }
  13079. +
  13080. + return (strcmp(str + str_len - suffix_len, suffix) == 0);
  13081. +}
  13082. +
  13083. +int str_chomp(char *str)
  13084. +{
  13085. + if (str[strlen(str) - 1] == '\n') {
  13086. + str[strlen(str) - 1] = '\0';
  13087. + return 1;
  13088. + }
  13089. + return 0;
  13090. +}
  13091. +
  13092. +int str_toupper(char *str)
  13093. +{
  13094. + while (*str) {
  13095. + *str = toupper(*str);
  13096. + str++;
  13097. + }
  13098. +
  13099. + return 0;
  13100. +}
  13101. +
  13102. +char *str_dup_safe(const char *str)
  13103. +{
  13104. + return str ? strdup(str) : NULL;
  13105. +}
  13106. +
  13107. diff -Nur busybox-1.12.1.orig/archival/libipkg/str_util.h busybox-1.12.1/archival/libipkg/str_util.h
  13108. --- busybox-1.12.1.orig/archival/libipkg/str_util.h 1970-01-01 01:00:00.000000000 +0100
  13109. +++ busybox-1.12.1/archival/libipkg/str_util.h 2008-10-23 11:41:37.000000000 +0200
  13110. @@ -0,0 +1,27 @@
  13111. +/* str_utils.h - the itsy package management system
  13112. +
  13113. + Carl D. Worth
  13114. +
  13115. + Copyright (C) 2001 University of Southern California
  13116. +
  13117. + This program is free software; you can redistribute it and/or
  13118. + modify it under the terms of the GNU General Public License as
  13119. + published by the Free Software Foundation; either version 2, or (at
  13120. + your option) any later version.
  13121. +
  13122. + This program is distributed in the hope that it will be useful, but
  13123. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13124. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13125. + General Public License for more details.
  13126. +*/
  13127. +
  13128. +#ifndef STR_UTILS_H
  13129. +#define STR_UTILS_H
  13130. +
  13131. +int str_starts_with(const char *str, const char *prefix);
  13132. +int str_ends_with(const char *str, const char *suffix);
  13133. +int str_chomp(char *str);
  13134. +int str_toupper(char *str);
  13135. +char *str_dup_safe(const char *str);
  13136. +
  13137. +#endif
  13138. diff -Nur busybox-1.12.1.orig/archival/libipkg/user.c busybox-1.12.1/archival/libipkg/user.c
  13139. --- busybox-1.12.1.orig/archival/libipkg/user.c 1970-01-01 01:00:00.000000000 +0100
  13140. +++ busybox-1.12.1/archival/libipkg/user.c 2008-10-23 16:02:33.000000000 +0200
  13141. @@ -0,0 +1,61 @@
  13142. +/* user.c - the itsy package management system
  13143. +
  13144. + Jamey Hicks
  13145. +
  13146. + Copyright (C) 2002 Hewlett Packard Company
  13147. + Copyright (C) 2001 University of Southern California
  13148. +
  13149. + This program is free software; you can redistribute it and/or
  13150. + modify it under the terms of the GNU General Public License as
  13151. + published by the Free Software Foundation; either version 2, or (at
  13152. + your option) any later version.
  13153. +
  13154. + This program is distributed in the hope that it will be useful, but
  13155. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13156. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13157. + General Public License for more details.
  13158. +*/
  13159. +
  13160. +#include <stdio.h>
  13161. +#include <stdarg.h>
  13162. +#include "libbb.h"
  13163. +#include "file_util.h"
  13164. +#include "str_util.h"
  13165. +#ifdef IPKG_LIB
  13166. +#include "libipkg.h"
  13167. +#endif
  13168. +
  13169. +char *get_user_response(const char *format, ...);
  13170. +
  13171. +
  13172. +#ifdef IPKG_LIB
  13173. +static char *question = NULL;
  13174. +static int question_len = 255;
  13175. +#endif
  13176. +char *get_user_response(const char *format, ...)
  13177. +{
  13178. + int len = question_len;
  13179. + va_list ap;
  13180. + char *response;
  13181. + va_start(ap, format);
  13182. +
  13183. +#ifndef IPKG_LIB
  13184. + vprintf(format, ap);
  13185. + do {
  13186. + response = file_read_line_alloc(stdin);
  13187. + } while (response == NULL);
  13188. +#else
  13189. + do {
  13190. + if (question == NULL || len > question_len) {
  13191. + question = realloc(question, len + 1);
  13192. + question_len = len;
  13193. + }
  13194. + len = vsnprintf(question,question_len,format,ap);
  13195. + } while (len > question_len);
  13196. + response = strdup(ipkg_cb_response(question));
  13197. +#endif
  13198. + str_chomp(response);
  13199. + str_tolower(response);
  13200. +
  13201. + return response;
  13202. +}
  13203. diff -Nur busybox-1.12.1.orig/archival/libipkg/user.h busybox-1.12.1/archival/libipkg/user.h
  13204. --- busybox-1.12.1.orig/archival/libipkg/user.h 1970-01-01 01:00:00.000000000 +0100
  13205. +++ busybox-1.12.1/archival/libipkg/user.h 2008-10-23 11:41:37.000000000 +0200
  13206. @@ -0,0 +1,23 @@
  13207. +/* user.c - the itsy package management system
  13208. +
  13209. + Jamey Hicks
  13210. +
  13211. + Copyright (C) 2002 Hewlett Packard Company
  13212. + Copyright (C) 2001 University of Southern California
  13213. +
  13214. + This program is free software; you can redistribute it and/or
  13215. + modify it under the terms of the GNU General Public License as
  13216. + published by the Free Software Foundation; either version 2, or (at
  13217. + your option) any later version.
  13218. +
  13219. + This program is distributed in the hope that it will be useful, but
  13220. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13221. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13222. + General Public License for more details.
  13223. +*/
  13224. +
  13225. +#include <stdio.h>
  13226. +#include <stdarg.h>
  13227. +
  13228. +char *get_user_response(const char *format, ...);
  13229. +
  13230. diff -Nur busybox-1.12.1.orig/archival/libipkg/void_list.c busybox-1.12.1/archival/libipkg/void_list.c
  13231. --- busybox-1.12.1.orig/archival/libipkg/void_list.c 1970-01-01 01:00:00.000000000 +0100
  13232. +++ busybox-1.12.1/archival/libipkg/void_list.c 2008-10-23 11:41:37.000000000 +0200
  13233. @@ -0,0 +1,194 @@
  13234. +/* void_list.c - the itsy package management system
  13235. +
  13236. + Carl D. Worth
  13237. +
  13238. + Copyright (C) 2001 University of Southern California
  13239. +
  13240. + This program is free software; you can redistribute it and/or
  13241. + modify it under the terms of the GNU General Public License as
  13242. + published by the Free Software Foundation; either version 2, or (at
  13243. + your option) any later version.
  13244. +
  13245. + This program is distributed in the hope that it will be useful, but
  13246. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13247. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13248. + General Public License for more details.
  13249. +*/
  13250. +
  13251. +#include "ipkg.h"
  13252. +#include <errno.h>
  13253. +
  13254. +#include "void_list.h"
  13255. +
  13256. +int void_list_elt_init(void_list_elt_t *elt, void *data)
  13257. +{
  13258. + elt->next = NULL;
  13259. + elt->data = data;
  13260. +
  13261. + return 0;
  13262. +}
  13263. +
  13264. +void void_list_elt_deinit(void_list_elt_t *elt)
  13265. +{
  13266. + void_list_elt_init(elt, NULL);
  13267. +}
  13268. +
  13269. +int void_list_init(void_list_t *list)
  13270. +{
  13271. + void_list_elt_init(&list->pre_head, NULL);
  13272. + list->head = NULL;
  13273. + list->pre_head.next = list->head;
  13274. + list->tail = NULL;
  13275. +
  13276. + return 0;
  13277. +}
  13278. +
  13279. +void void_list_deinit(void_list_t *list)
  13280. +{
  13281. + void_list_elt_t *elt;
  13282. +
  13283. + while (list->head) {
  13284. + elt = void_list_pop(list);
  13285. + void_list_elt_deinit(elt);
  13286. + /* malloced in void_list_append */
  13287. + free(elt);
  13288. + }
  13289. +}
  13290. +
  13291. +int void_list_append(void_list_t *list, void *data)
  13292. +{
  13293. + void_list_elt_t *elt;
  13294. +
  13295. + /* freed in void_list_deinit */
  13296. + elt = malloc(sizeof(void_list_elt_t));
  13297. + if (elt == NULL) {
  13298. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  13299. + return ENOMEM;
  13300. + }
  13301. +
  13302. + void_list_elt_init(elt, data);
  13303. +
  13304. + if (list->tail) {
  13305. + list->tail->next = elt;
  13306. + list->tail = elt;
  13307. + } else {
  13308. + list->head = elt;
  13309. + list->pre_head.next = list->head;
  13310. + list->tail = elt;
  13311. + }
  13312. +
  13313. + return 0;
  13314. +}
  13315. +
  13316. +int void_list_push(void_list_t *list, void *data)
  13317. +{
  13318. + void_list_elt_t *elt;
  13319. +
  13320. + elt = malloc(sizeof(void_list_elt_t));
  13321. + if (elt == NULL) {
  13322. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  13323. + return ENOMEM;
  13324. + }
  13325. +
  13326. + void_list_elt_init(elt, data);
  13327. +
  13328. + elt->next = list->head;
  13329. + list->head->next = elt;
  13330. + if (list->tail == NULL) {
  13331. + list->tail = list->head;
  13332. + }
  13333. +
  13334. + return 0;
  13335. +}
  13336. +
  13337. +void_list_elt_t *void_list_pop(void_list_t *list)
  13338. +{
  13339. + void_list_elt_t *elt;
  13340. +
  13341. + elt = list->head;
  13342. +
  13343. + if (list->head) {
  13344. + list->head = list->head->next;
  13345. + list->pre_head.next = list->head;
  13346. + if (list->head == NULL) {
  13347. + list->tail = NULL;
  13348. + }
  13349. + }
  13350. +
  13351. + return elt;
  13352. +}
  13353. +
  13354. +void *void_list_remove(void_list_t *list, void_list_elt_t **iter)
  13355. +{
  13356. + void_list_elt_t *prior;
  13357. + void_list_elt_t *old_elt;
  13358. + void *old_data;
  13359. +
  13360. + old_elt = *iter;
  13361. + old_data = old_elt->data;
  13362. +
  13363. + if (old_elt == list->head) {
  13364. + prior = &list->pre_head;
  13365. + void_list_pop(list);
  13366. + } else {
  13367. + for (prior = list->head; prior; prior = prior->next) {
  13368. + if (prior->next == old_elt) {
  13369. + break;
  13370. + }
  13371. + }
  13372. + if (prior == NULL || prior->next != old_elt) {
  13373. + fprintf(stderr, "%s: ERROR: element not found in list\n", __FUNCTION__);
  13374. + return NULL;
  13375. + }
  13376. + prior->next = old_elt->next;
  13377. +
  13378. + if (old_elt == list->tail) {
  13379. + list->tail = prior;
  13380. + }
  13381. + }
  13382. +
  13383. + void_list_elt_deinit(old_elt);
  13384. + *iter = prior;
  13385. +
  13386. + return old_data;
  13387. +}
  13388. +
  13389. +/* remove element containing elt data, using cmp(elt->data, target_data) == 0. */
  13390. +void *void_list_remove_elt(void_list_t *list, const void *target_data, void_list_cmp_t cmp)
  13391. +{
  13392. + void_list_elt_t *prior;
  13393. + void_list_elt_t *old_elt = NULL;
  13394. + void *old_data = NULL;
  13395. +
  13396. + /* first element */
  13397. + if (list->head && list->head->data && (cmp(list->head->data, target_data) == 0)) {
  13398. + old_elt = list->head;
  13399. + old_data = list->head->data;
  13400. + void_list_pop(list);
  13401. + } else {
  13402. + int found = 0;
  13403. + for (prior = list->head; prior && prior->next; prior = prior->next) {
  13404. + if (prior->next->data && (cmp(prior->next->data, target_data) == 0)) {
  13405. + old_elt = prior->next;
  13406. + old_data = old_elt->data;
  13407. + found = 1;
  13408. + break;
  13409. + }
  13410. + }
  13411. + if (!found) {
  13412. + return NULL;
  13413. + }
  13414. + prior->next = old_elt->next;
  13415. +
  13416. + if (old_elt == list->tail) {
  13417. + list->tail = prior;
  13418. + }
  13419. + }
  13420. + if (old_elt)
  13421. + void_list_elt_deinit(old_elt);
  13422. +
  13423. + if (old_data)
  13424. + return old_data;
  13425. + else
  13426. + return NULL;
  13427. +}
  13428. diff -Nur busybox-1.12.1.orig/archival/libipkg/void_list.h busybox-1.12.1/archival/libipkg/void_list.h
  13429. --- busybox-1.12.1.orig/archival/libipkg/void_list.h 1970-01-01 01:00:00.000000000 +0100
  13430. +++ busybox-1.12.1/archival/libipkg/void_list.h 2008-10-23 11:41:37.000000000 +0200
  13431. @@ -0,0 +1,59 @@
  13432. +/* void_list.h - the itsy package management system
  13433. +
  13434. + Carl D. Worth
  13435. +
  13436. + Copyright (C) 2001 University of Southern California
  13437. +
  13438. + This program is free software; you can redistribute it and/or
  13439. + modify it under the terms of the GNU General Public License as
  13440. + published by the Free Software Foundation; either version 2, or (at
  13441. + your option) any later version.
  13442. +
  13443. + This program is distributed in the hope that it will be useful, but
  13444. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13445. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13446. + General Public License for more details.
  13447. +*/
  13448. +
  13449. +#ifndef VOID_LIST_H
  13450. +#define VOID_LIST_H
  13451. +
  13452. +typedef struct void_list_elt void_list_elt_t;
  13453. +struct void_list_elt
  13454. +{
  13455. + void_list_elt_t *next;
  13456. + void *data;
  13457. +};
  13458. +
  13459. +typedef struct void_list void_list_t;
  13460. +struct void_list
  13461. +{
  13462. + void_list_elt_t pre_head;
  13463. + void_list_elt_t *head;
  13464. + void_list_elt_t *tail;
  13465. +};
  13466. +
  13467. +static inline int void_list_empty(void_list_t *list)
  13468. +{
  13469. + if (list->head == NULL)
  13470. + return 1;
  13471. + else
  13472. + return 0;
  13473. +}
  13474. +
  13475. +int void_list_elt_init(void_list_elt_t *elt, void *data);
  13476. +void void_list_elt_deinit(void_list_elt_t *elt);
  13477. +
  13478. +int void_list_init(void_list_t *list);
  13479. +void void_list_deinit(void_list_t *list);
  13480. +
  13481. +int void_list_append(void_list_t *list, void *data);
  13482. +int void_list_push(void_list_t *list, void *data);
  13483. +void_list_elt_t *void_list_pop(void_list_t *list);
  13484. +
  13485. +void *void_list_remove(void_list_t *list, void_list_elt_t **iter);
  13486. +/* remove element containing elt data, using cmp(elt->data, target_data) == 0. */
  13487. +typedef int (*void_list_cmp_t)(const void *, const void *);
  13488. +void *void_list_remove_elt(void_list_t *list, const void *target_data, void_list_cmp_t cmp);
  13489. +
  13490. +#endif
  13491. diff -Nur busybox-1.12.1.orig/archival/libipkg/xsystem.c busybox-1.12.1/archival/libipkg/xsystem.c
  13492. --- busybox-1.12.1.orig/archival/libipkg/xsystem.c 1970-01-01 01:00:00.000000000 +0100
  13493. +++ busybox-1.12.1/archival/libipkg/xsystem.c 2008-10-23 11:41:37.000000000 +0200
  13494. @@ -0,0 +1,64 @@
  13495. +/* xsystem.c - system(3) with error messages
  13496. +
  13497. + Carl D. Worth
  13498. +
  13499. + Copyright (C) 2001 University of Southern California
  13500. +
  13501. + This program is free software; you can redistribute it and/or
  13502. + modify it under the terms of the GNU General Public License as
  13503. + published by the Free Software Foundation; either version 2, or (at
  13504. + your option) any later version.
  13505. +
  13506. + This program is distributed in the hope that it will be useful, but
  13507. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13508. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13509. + General Public License for more details.
  13510. +*/
  13511. +
  13512. +#include "ipkg.h"
  13513. +#include <sys/wait.h>
  13514. +
  13515. +#include "xsystem.h"
  13516. +
  13517. +/* XXX: FEATURE: I shouldn't actually use system(3) at all. I don't
  13518. + really need the /bin/sh invocation which takes resources and
  13519. + introduces security problems. I should switch all of this to a sort
  13520. + of execl() or execv() interface/implementation.
  13521. +*/
  13522. +
  13523. +/* Like system(3), but with error messages printed if the fork fails
  13524. + or if the child process dies due to an uncaught signal. Also, the
  13525. + return value is a bit simpler:
  13526. +
  13527. + -1 if there was any problem
  13528. + Otherwise, the 8-bit return value of the program ala WEXITSTATUS
  13529. + as defined in <sys/wait.h>.
  13530. +*/
  13531. +int xsystem(const char *cmd)
  13532. +{
  13533. + int err;
  13534. +
  13535. + err = system(cmd);
  13536. +
  13537. + if (err == -1) {
  13538. + fprintf(stderr, "%s: ERROR: fork failed before execution: `%s'\n",
  13539. + __FUNCTION__, cmd);
  13540. + return -1;
  13541. + }
  13542. +
  13543. + if (WIFSIGNALED(err)) {
  13544. + fprintf(stderr, "%s: ERROR: Child process died due to signal %d: `%s'\n",
  13545. + __FUNCTION__, WTERMSIG(err), cmd);
  13546. + return -1;
  13547. + }
  13548. +
  13549. + if (WIFEXITED(err)) {
  13550. + /* Normal child exit */
  13551. + return WEXITSTATUS(err);
  13552. + }
  13553. +
  13554. + fprintf(stderr, "%s: ERROR: Received unintelligible return value from system: %d",
  13555. + __FUNCTION__, err);
  13556. + return -1;
  13557. +}
  13558. +
  13559. diff -Nur busybox-1.12.1.orig/archival/libipkg/xsystem.h busybox-1.12.1/archival/libipkg/xsystem.h
  13560. --- busybox-1.12.1.orig/archival/libipkg/xsystem.h 1970-01-01 01:00:00.000000000 +0100
  13561. +++ busybox-1.12.1/archival/libipkg/xsystem.h 2008-10-23 11:41:37.000000000 +0200
  13562. @@ -0,0 +1,34 @@
  13563. +/* xsystem.h - system(3) with error messages
  13564. +
  13565. + Carl D. Worth
  13566. +
  13567. + Copyright (C) 2001 University of Southern California
  13568. +
  13569. + This program is free software; you can redistribute it and/or
  13570. + modify it under the terms of the GNU General Public License as
  13571. + published by the Free Software Foundation; either version 2, or (at
  13572. + your option) any later version.
  13573. +
  13574. + This program is distributed in the hope that it will be useful, but
  13575. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13576. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13577. + General Public License for more details.
  13578. +*/
  13579. +
  13580. +#ifndef XSYSTEM_H
  13581. +#define XSYSTEM_H
  13582. +
  13583. +#include <stdlib.h>
  13584. +
  13585. +/* Like system(3), but with error messages printed if the fork fails
  13586. + or if the child process dies due to an uncaught signal. Also, the
  13587. + return value is a bit simpler:
  13588. +
  13589. + -1 if there was any problem
  13590. + Otherwise, the 8-bit return value of the program ala WEXITSTATUS
  13591. + as defined in <sys/wait.h>.
  13592. +*/
  13593. +int xsystem(const char *cmd);
  13594. +
  13595. +#endif
  13596. +
  13597. diff -Nur busybox-1.12.1.orig/archival/libunarchive/data_extract_all.c busybox-1.12.1/archival/libunarchive/data_extract_all.c
  13598. --- busybox-1.12.1.orig/archival/libunarchive/data_extract_all.c 2008-09-28 20:04:15.000000000 +0200
  13599. +++ busybox-1.12.1/archival/libunarchive/data_extract_all.c 2008-10-23 11:53:34.000000000 +0200
  13600. @@ -144,3 +144,16 @@
  13601. }
  13602. }
  13603. }
  13604. +
  13605. +extern void FAST_FUNC data_extract_all_prefix(archive_handle_t *archive_handle)
  13606. +{
  13607. + char *name_ptr = archive_handle->file_header->name;
  13608. +
  13609. + name_ptr += strspn(name_ptr, "./");
  13610. + if (name_ptr[0] != '\0') {
  13611. + archive_handle->file_header->name = xmalloc(strlen(archive_handle->buffer) + 1 + strlen(name_ptr) + 1);
  13612. + strcpy(archive_handle->file_header->name, archive_handle->buffer);
  13613. + strcat(archive_handle->file_header->name, name_ptr);
  13614. + data_extract_all(archive_handle);
  13615. + }
  13616. +}
  13617. diff -Nur busybox-1.12.1.orig/archival/libunarchive/Kbuild busybox-1.12.1/archival/libunarchive/Kbuild
  13618. --- busybox-1.12.1.orig/archival/libunarchive/Kbuild 2008-09-28 20:04:15.000000000 +0200
  13619. +++ busybox-1.12.1/archival/libunarchive/Kbuild 2008-10-23 16:28:14.000000000 +0200
  13620. @@ -39,6 +39,7 @@
  13621. lib-$(CONFIG_DPKG) += $(DPKG_FILES)
  13622. lib-$(CONFIG_DPKG_DEB) += $(DPKG_FILES)
  13623. lib-$(CONFIG_GUNZIP) += decompress_unzip.o
  13624. +lib-$(CONFIG_IPKG) += open_transformer.o get_header_tar.o get_header_tar_gz.o
  13625. lib-$(CONFIG_RPM2CPIO) += decompress_unzip.o get_header_cpio.o
  13626. lib-$(CONFIG_RPM) += open_transformer.o decompress_unzip.o get_header_cpio.o
  13627. lib-$(CONFIG_TAR) += get_header_tar.o
  13628. diff -Nur busybox-1.12.1.orig/coreutils/md5_sha1_sum.c busybox-1.12.1/coreutils/md5_sha1_sum.c
  13629. --- busybox-1.12.1.orig/coreutils/md5_sha1_sum.c 2008-09-28 20:04:18.000000000 +0200
  13630. +++ busybox-1.12.1/coreutils/md5_sha1_sum.c 2008-10-23 11:41:37.000000000 +0200
  13631. @@ -8,14 +8,12 @@
  13632. #include "libbb.h"
  13633. -typedef enum { HASH_SHA1, HASH_MD5 } hash_algo_t;
  13634. -
  13635. #define FLAG_SILENT 1
  13636. #define FLAG_CHECK 2
  13637. #define FLAG_WARN 4
  13638. /* This might be useful elsewhere */
  13639. -static unsigned char *hash_bin_to_hex(unsigned char *hash_value,
  13640. +unsigned char *hash_bin_to_hex(unsigned char *hash_value,
  13641. unsigned hash_length)
  13642. {
  13643. /* xzalloc zero-terminates */
  13644. @@ -24,7 +22,7 @@
  13645. return (unsigned char *)hex_value;
  13646. }
  13647. -static uint8_t *hash_file(const char *filename, hash_algo_t hash_algo)
  13648. +uint8_t *hash_file(const char *filename, hash_algo_t hash_algo)
  13649. {
  13650. int src_fd, hash_len, count;
  13651. union _ctx_ {
  13652. diff -Nur busybox-1.12.1.orig/include/applets.h busybox-1.12.1/include/applets.h
  13653. --- busybox-1.12.1.orig/include/applets.h 2008-09-28 20:04:26.000000000 +0200
  13654. +++ busybox-1.12.1/include/applets.h 2008-10-23 11:41:37.000000000 +0200
  13655. @@ -202,6 +202,7 @@
  13656. USE_IPCALC(APPLET(ipcalc, _BB_DIR_BIN, _BB_SUID_NEVER))
  13657. USE_IPCRM(APPLET(ipcrm, _BB_DIR_USR_BIN, _BB_SUID_ALWAYS))
  13658. USE_IPCS(APPLET(ipcs, _BB_DIR_USR_BIN, _BB_SUID_ALWAYS))
  13659. +USE_IPKG(APPLET(ipkg, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
  13660. USE_IPLINK(APPLET(iplink, _BB_DIR_BIN, _BB_SUID_NEVER))
  13661. USE_IPROUTE(APPLET(iproute, _BB_DIR_BIN, _BB_SUID_NEVER))
  13662. USE_IPRULE(APPLET(iprule, _BB_DIR_BIN, _BB_SUID_NEVER))
  13663. diff -Nur busybox-1.12.1.orig/include/libbb.h busybox-1.12.1/include/libbb.h
  13664. --- busybox-1.12.1.orig/include/libbb.h 2008-09-28 20:04:26.000000000 +0200
  13665. +++ busybox-1.12.1/include/libbb.h 2008-10-23 11:47:15.000000000 +0200
  13666. @@ -1264,6 +1264,7 @@
  13667. extern const char bb_uuenc_tbl_std[];
  13668. void bb_uuencode(char *store, const void *s, int length, const char *tbl) FAST_FUNC;
  13669. +typedef enum { HASH_SHA1, HASH_MD5 } hash_algo_t;
  13670. typedef struct sha1_ctx_t {
  13671. uint32_t count[2];
  13672. uint32_t hash[5];
  13673. @@ -1272,6 +1273,8 @@
  13674. void sha1_begin(sha1_ctx_t *ctx) FAST_FUNC;
  13675. void sha1_hash(const void *data, size_t length, sha1_ctx_t *ctx) FAST_FUNC;
  13676. void *sha1_end(void *resbuf, sha1_ctx_t *ctx) FAST_FUNC;
  13677. +unsigned char *hash_bin_to_hex(unsigned char *hash_value, unsigned hash_length);
  13678. +uint8_t *hash_file(const char *filename, hash_algo_t hash_algo);
  13679. typedef struct md5_ctx_t {
  13680. uint32_t A;
  13681. diff -Nur busybox-1.12.1.orig/include/unarchive.h busybox-1.12.1/include/unarchive.h
  13682. --- busybox-1.12.1.orig/include/unarchive.h 2008-09-28 20:04:26.000000000 +0200
  13683. +++ busybox-1.12.1/include/unarchive.h 2008-10-23 11:48:04.000000000 +0200
  13684. @@ -88,6 +88,7 @@
  13685. extern void data_skip(archive_handle_t *archive_handle) FAST_FUNC;
  13686. extern void data_extract_all(archive_handle_t *archive_handle) FAST_FUNC;
  13687. +extern void data_extract_all_prefix(archive_handle_t *archive_handle) FAST_FUNC;
  13688. extern void data_extract_to_stdout(archive_handle_t *archive_handle) FAST_FUNC;
  13689. extern void data_extract_to_buffer(archive_handle_t *archive_handle) FAST_FUNC;
  13690. diff -Nur busybox-1.12.1.orig/include/usage.h busybox-1.12.1/include/usage.h
  13691. --- busybox-1.12.1.orig/include/usage.h 2008-09-28 20:04:26.000000000 +0200
  13692. +++ busybox-1.12.1/include/usage.h 2008-10-23 11:41:37.000000000 +0200
  13693. @@ -1419,6 +1419,82 @@
  13694. "$ ls -la /tmp/busybox*\n" \
  13695. "-rw-rw-r-- 1 andersen andersen 554058 Apr 14 17:49 /tmp/busybox.tar.gz\n"
  13696. +#define ipkg_trivial_usage \
  13697. + "[options]... sub-command [arguments]..."
  13698. +#define ipkg_full_usage \
  13699. + "ipkg is an utility to install, remove and manage .ipk packages.\n" \
  13700. + "\n" \
  13701. + "Sub-commands:\n" \
  13702. + "\nPackage Manipulation:\n" \
  13703. + "\tupdate Update list of available packages\n" \
  13704. + "\tupgrade Upgrade all installed packages to latest version\n" \
  13705. + "\tinstall <pkg> Download and install <pkg> (and dependencies)\n" \
  13706. + "\tinstall <file.ipk> Install package <file.ipk>\n" \
  13707. + "\tconfigure [<pkg>] Configure unpacked packages\n" \
  13708. + "\tremove <pkg|regexp> Remove package <pkg|packages following regexp>\n" \
  13709. + "\tflag <flag> <pkg> ... Flag package(s) <pkg>\n" \
  13710. + "\t <flag>=hold|noprune|user|ok|installed|unpacked (one per invocation) \n" \
  13711. + "\n" \
  13712. + "Informational Commands:\n" \
  13713. + "\tlist List available packages and descriptions\n" \
  13714. + "\tlist_installed List all and only the installed packages and description \n" \
  13715. + "\tfiles <pkg> List all files belonging to <pkg>\n" \
  13716. + "\tsearch <file|regexp> Search for a package providing <file>\n" \
  13717. + "\tinfo [pkg|regexp [<field>]] Display all/some info fields for <pkg> or all\n" \
  13718. + "\tstatus [pkg|regexp [<field>]] Display all/some status fields for <pkg> or all\n" \
  13719. + "\tdownload <pkg> Download <pkg> to current directory.\n" \
  13720. + "\tcompare_versions <v1> <op> <v2>\n" \
  13721. + "\t compare versions using <= < > >= = << >>\n" \
  13722. + "\tprint_architecture prints the architecture.\n" \
  13723. + "\tprint_installation_architecture\n" \
  13724. + "\twhatdepends [-A] [pkgname|pat]+\n" \
  13725. + "\twhatdependsrec [-A] [pkgname|pat]+\n" \
  13726. + "\twhatprovides [-A] [pkgname|pat]+\n" \
  13727. + "\twhatconflicts [-A] [pkgname|pat]+\n" \
  13728. + "\twhatreplaces [-A] [pkgname|pat]+\n" \
  13729. + "\t prints the installation architecture.\n" \
  13730. + "\n" \
  13731. + "\nOptions:\n" \
  13732. + "\t-A Query all packages with whatdepends, whatprovides, whatreplaces, whatconflicts\n" \
  13733. + "\t-V <level> Set verbosity level to <level>. If no value is\n" \
  13734. + "\t--verbosity <level> provided increase verbosity by one. Verbosity levels:\n" \
  13735. + "\t 0 errors only\n" \
  13736. + "\t 1 normal messages (default)\n" \
  13737. + "\t 2 informative messages\n" \
  13738. + "\t 3 debug output\n" \
  13739. + "\t-f <conf_file> Use <conf_file> as the ipkg configuration file\n" \
  13740. + "\t-conf <conf_file> Default configuration file location\n" \
  13741. + " is /etc/ipkg.conf\n" \
  13742. + "\t-d <dest_name> Use <dest_name> as the the root directory for\n" \
  13743. + "\t-dest <dest_name> package installation, removal, upgrading.\n" \
  13744. + " <dest_name> should be a defined dest name from\n" \
  13745. + " the configuration file, (but can also be a\n" \
  13746. + " directory name in a pinch).\n" \
  13747. + "\t-o <offline_root> Use <offline_root> as the root directory for\n" \
  13748. + "\t-offline <offline_root> offline installation of packages.\n" \
  13749. + "\t-verbose_wget more wget messages\n" \
  13750. + "\n" \
  13751. + "Force Options (use when ipkg is too smart for its own good):\n" \
  13752. + "\t-force-depends Make dependency checks warnings instead of errors\n" \
  13753. + "\t Install/remove package in spite of failed dependences\n" \
  13754. + "\t-force-defaults Use default options for questions asked by ipkg.\n" \
  13755. + " (no prompts). Note that this will not prevent\n" \
  13756. + " package installation scripts from prompting.\n" \
  13757. + "\t-force-reinstall Allow ipkg to reinstall a package.\n" \
  13758. + "\t-force-overwrite Allow ipkg to overwrite files from another package during an install.\n" \
  13759. + "\t-force-downgrade Allow ipkg to downgrade packages.\n" \
  13760. + "\t-force_space Install even if there does not seem to be enough space.\n" \
  13761. + "\t-noaction No action -- test only\n" \
  13762. + "\t-nodeps Do not follow dependences\n" \
  13763. + "\t-force-removal-of-dependent-packages\n" \
  13764. + "\t-recursive Allow ipkg to remove package and all that depend on it.\n" \
  13765. + "\t-test No action -- test only\n" \
  13766. + "\t-t Specify tmp-dir.\n" \
  13767. + "\t--tmp-dir Specify tmp-dir.\n" \
  13768. + "\n" \
  13769. + "\tregexp could be something like 'pkgname*' '*file*' or similar\n" \
  13770. + "\teg: ipkg info 'libstd*' or ipkg search '*libop*' or ipkg remove 'libncur*'\n"
  13771. +
  13772. #define halt_trivial_usage \
  13773. "[-d delay] [-n] [-f]"
  13774. #define halt_full_usage "\n\n" \
  13775. diff -Nur busybox-1.12.1.orig/Makefile busybox-1.12.1/Makefile
  13776. --- busybox-1.12.1.orig/Makefile 2008-09-28 20:04:30.000000000 +0200
  13777. +++ busybox-1.12.1/Makefile 2008-10-23 11:41:37.000000000 +0200
  13778. @@ -444,6 +444,7 @@
  13779. libs-y := \
  13780. archival/ \
  13781. + archival/libipkg/ \
  13782. archival/libunarchive/ \
  13783. console-tools/ \
  13784. coreutils/ \